2
0

api.c 3.7 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706557075570855709557105571155712557135571455715557165571755718557195572055721557225572355724557255572655727557285572955730557315573255733557345573555736557375573855739557405574155742557435574455745557465574755748557495575055751557525575355754557555575655757557585575955760557615576255763557645576555766557675576855769557705577155772557735577455775557765577755778557795578055781557825578355784557855578655787557885578955790557915579255793557945579555796557975579855799558005580155802558035580455805558065580755808558095581055811558125581355814558155581655817558185581955820558215582255823558245582555826558275582855829558305583155832558335583455835558365583755838558395584055841558425584355844558455584655847558485584955850558515585255853558545585555856558575585855859558605586155862558635586455865558665586755868558695587055871558725587355874558755587655877558785587955880558815588255883558845588555886558875588855889558905589155892558935589455895558965589755898558995590055901559025590355904559055590655907559085590955910559115591255913559145591555916559175591855919559205592155922559235592455925559265592755928559295593055931559325593355934559355593655937559385593955940559415594255943559445594555946559475594855949559505595155952559535595455955559565595755958559595596055961559625596355964559655596655967559685596955970559715597255973559745597555976559775597855979559805598155982559835598455985559865598755988559895599055991559925599355994559955599655997559985599956000560015600256003560045600556006560075600856009560105601156012560135601456015560165601756018560195602056021560225602356024560255602656027560285602956030560315603256033560345603556036560375603856039560405604156042560435604456045560465604756048560495605056051560525605356054560555605656057560585605956060560615606256063560645606556066560675606856069560705607156072560735607456075560765607756078560795608056081560825608356084560855608656087560885608956090560915609256093560945609556096560975609856099561005610156102561035610456105561065610756108561095611056111561125611356114561155611656117561185611956120561215612256123561245612556126561275612856129561305613156132561335613456135561365613756138561395614056141561425614356144561455614656147561485614956150561515615256153561545615556156561575615856159561605616156162561635616456165561665616756168561695617056171561725617356174561755617656177561785617956180561815618256183561845618556186561875618856189561905619156192561935619456195561965619756198561995620056201562025620356204562055620656207562085620956210562115621256213562145621556216562175621856219562205622156222562235622456225562265622756228562295623056231562325623356234562355623656237562385623956240562415624256243562445624556246562475624856249562505625156252562535625456255562565625756258562595626056261562625626356264562655626656267562685626956270562715627256273562745627556276562775627856279562805628156282562835628456285562865628756288562895629056291562925629356294562955629656297562985629956300563015630256303563045630556306563075630856309563105631156312563135631456315563165631756318563195632056321563225632356324563255632656327563285632956330563315633256333563345633556336563375633856339563405634156342563435634456345563465634756348563495635056351563525635356354563555635656357563585635956360563615636256363563645636556366563675636856369563705637156372563735637456375563765637756378563795638056381563825638356384563855638656387563885638956390563915639256393563945639556396563975639856399564005640156402564035640456405564065640756408564095641056411564125641356414564155641656417564185641956420564215642256423564245642556426564275642856429564305643156432564335643456435564365643756438564395644056441564425644356444564455644656447564485644956450564515645256453564545645556456564575645856459564605646156462564635646456465564665646756468564695647056471564725647356474564755647656477564785647956480564815648256483564845648556486564875648856489564905649156492564935649456495564965649756498564995650056501565025650356504565055650656507565085650956510565115651256513565145651556516565175651856519565205652156522565235652456525565265652756528565295653056531565325653356534565355653656537565385653956540565415654256543565445654556546565475654856549565505655156552565535655456555565565655756558565595656056561565625656356564565655656656567565685656956570565715657256573565745657556576565775657856579565805658156582565835658456585565865658756588565895659056591565925659356594565955659656597565985659956600566015660256603566045660556606566075660856609566105661156612566135661456615566165661756618566195662056621566225662356624566255662656627566285662956630566315663256633566345663556636566375663856639566405664156642566435664456645566465664756648566495665056651566525665356654566555665656657566585665956660566615666256663566645666556666566675666856669566705667156672566735667456675566765667756678566795668056681566825668356684566855668656687566885668956690566915669256693566945669556696566975669856699567005670156702567035670456705567065670756708567095671056711567125671356714567155671656717567185671956720567215672256723567245672556726567275672856729567305673156732567335673456735567365673756738567395674056741567425674356744567455674656747567485674956750567515675256753567545675556756567575675856759567605676156762567635676456765567665676756768567695677056771567725677356774567755677656777567785677956780567815678256783567845678556786567875678856789567905679156792567935679456795567965679756798567995680056801568025680356804568055680656807568085680956810568115681256813568145681556816568175681856819568205682156822568235682456825568265682756828568295683056831568325683356834568355683656837568385683956840568415684256843568445684556846568475684856849568505685156852568535685456855568565685756858568595686056861568625686356864568655686656867568685686956870568715687256873568745687556876568775687856879568805688156882568835688456885568865688756888568895689056891568925689356894568955689656897568985689956900569015690256903569045690556906569075690856909569105691156912569135691456915569165691756918569195692056921569225692356924569255692656927569285692956930569315693256933569345693556936569375693856939569405694156942569435694456945569465694756948569495695056951569525695356954569555695656957569585695956960569615696256963569645696556966569675696856969569705697156972569735697456975569765697756978569795698056981569825698356984569855698656987569885698956990569915699256993569945699556996569975699856999570005700157002570035700457005570065700757008570095701057011570125701357014570155701657017570185701957020570215702257023570245702557026570275702857029570305703157032570335703457035570365703757038570395704057041570425704357044570455704657047570485704957050570515705257053570545705557056570575705857059570605706157062570635706457065570665706757068570695707057071570725707357074570755707657077570785707957080570815708257083570845708557086570875708857089570905709157092570935709457095570965709757098570995710057101571025710357104571055710657107571085710957110571115711257113571145711557116571175711857119571205712157122571235712457125571265712757128571295713057131571325713357134571355713657137571385713957140571415714257143571445714557146571475714857149571505715157152571535715457155571565715757158571595716057161571625716357164571655716657167571685716957170571715717257173571745717557176571775717857179571805718157182571835718457185571865718757188571895719057191571925719357194571955719657197571985719957200572015720257203572045720557206572075720857209572105721157212572135721457215572165721757218572195722057221572225722357224572255722657227572285722957230572315723257233572345723557236572375723857239572405724157242572435724457245572465724757248572495725057251572525725357254572555725657257572585725957260572615726257263572645726557266572675726857269572705727157272572735727457275572765727757278572795728057281572825728357284572855728657287572885728957290572915729257293572945729557296572975729857299573005730157302573035730457305573065730757308573095731057311573125731357314573155731657317573185731957320573215732257323573245732557326573275732857329573305733157332573335733457335573365733757338573395734057341573425734357344573455734657347573485734957350573515735257353573545735557356573575735857359573605736157362573635736457365573665736757368573695737057371573725737357374573755737657377573785737957380573815738257383573845738557386573875738857389573905739157392573935739457395573965739757398573995740057401574025740357404574055740657407574085740957410574115741257413574145741557416574175741857419574205742157422574235742457425574265742757428574295743057431574325743357434574355743657437574385743957440574415744257443574445744557446574475744857449574505745157452574535745457455574565745757458574595746057461574625746357464574655746657467574685746957470574715747257473574745747557476574775747857479574805748157482574835748457485574865748757488574895749057491574925749357494574955749657497574985749957500575015750257503575045750557506575075750857509575105751157512575135751457515575165751757518575195752057521575225752357524575255752657527575285752957530575315753257533575345753557536575375753857539575405754157542575435754457545575465754757548575495755057551575525755357554575555755657557575585755957560575615756257563575645756557566575675756857569575705757157572575735757457575575765757757578575795758057581575825758357584575855758657587575885758957590575915759257593575945759557596575975759857599576005760157602576035760457605576065760757608576095761057611576125761357614576155761657617576185761957620576215762257623576245762557626576275762857629576305763157632576335763457635576365763757638576395764057641576425764357644576455764657647576485764957650576515765257653576545765557656576575765857659576605766157662576635766457665576665766757668576695767057671576725767357674576755767657677576785767957680576815768257683576845768557686576875768857689576905769157692576935769457695576965769757698576995770057701577025770357704577055770657707577085770957710577115771257713577145771557716577175771857719577205772157722577235772457725577265772757728577295773057731577325773357734577355773657737577385773957740577415774257743577445774557746577475774857749577505775157752577535775457755577565775757758577595776057761577625776357764577655776657767577685776957770577715777257773577745777557776577775777857779577805778157782577835778457785577865778757788577895779057791577925779357794577955779657797577985779957800578015780257803578045780557806578075780857809578105781157812578135781457815578165781757818578195782057821578225782357824578255782657827578285782957830578315783257833578345783557836578375783857839578405784157842578435784457845578465784757848578495785057851578525785357854578555785657857578585785957860578615786257863578645786557866578675786857869578705787157872578735787457875578765787757878578795788057881578825788357884578855788657887578885788957890578915789257893578945789557896578975789857899579005790157902579035790457905579065790757908579095791057911579125791357914579155791657917579185791957920579215792257923579245792557926579275792857929579305793157932579335793457935579365793757938579395794057941579425794357944579455794657947579485794957950579515795257953579545795557956579575795857959579605796157962579635796457965579665796757968579695797057971579725797357974579755797657977579785797957980579815798257983579845798557986579875798857989579905799157992579935799457995579965799757998579995800058001580025800358004580055800658007580085800958010580115801258013580145801558016580175801858019580205802158022580235802458025580265802758028580295803058031580325803358034580355803658037580385803958040580415804258043580445804558046580475804858049580505805158052580535805458055580565805758058580595806058061580625806358064580655806658067580685806958070580715807258073580745807558076580775807858079580805808158082580835808458085580865808758088580895809058091580925809358094580955809658097580985809958100581015810258103581045810558106581075810858109581105811158112581135811458115581165811758118581195812058121581225812358124581255812658127581285812958130581315813258133581345813558136581375813858139581405814158142581435814458145581465814758148581495815058151581525815358154581555815658157581585815958160581615816258163581645816558166581675816858169581705817158172581735817458175581765817758178581795818058181581825818358184581855818658187581885818958190581915819258193581945819558196581975819858199582005820158202582035820458205582065820758208582095821058211582125821358214582155821658217582185821958220582215822258223582245822558226582275822858229582305823158232582335823458235582365823758238582395824058241582425824358244582455824658247582485824958250582515825258253582545825558256582575825858259582605826158262582635826458265582665826758268582695827058271582725827358274582755827658277582785827958280582815828258283582845828558286582875828858289582905829158292582935829458295582965829758298582995830058301583025830358304583055830658307583085830958310583115831258313583145831558316583175831858319583205832158322583235832458325583265832758328583295833058331583325833358334583355833658337583385833958340583415834258343583445834558346583475834858349583505835158352583535835458355583565835758358583595836058361583625836358364583655836658367583685836958370583715837258373583745837558376583775837858379583805838158382583835838458385583865838758388583895839058391583925839358394583955839658397583985839958400584015840258403584045840558406584075840858409584105841158412584135841458415584165841758418584195842058421584225842358424584255842658427584285842958430584315843258433584345843558436584375843858439584405844158442584435844458445584465844758448584495845058451584525845358454584555845658457584585845958460584615846258463584645846558466584675846858469584705847158472584735847458475584765847758478584795848058481584825848358484584855848658487584885848958490584915849258493584945849558496584975849858499585005850158502585035850458505585065850758508585095851058511585125851358514585155851658517585185851958520585215852258523585245852558526585275852858529585305853158532585335853458535585365853758538585395854058541585425854358544585455854658547585485854958550585515855258553585545855558556585575855858559585605856158562585635856458565585665856758568585695857058571585725857358574585755857658577585785857958580585815858258583585845858558586585875858858589585905859158592585935859458595585965859758598585995860058601586025860358604586055860658607586085860958610586115861258613586145861558616586175861858619586205862158622586235862458625586265862758628586295863058631586325863358634586355863658637586385863958640586415864258643586445864558646586475864858649586505865158652586535865458655586565865758658586595866058661586625866358664586655866658667586685866958670586715867258673586745867558676586775867858679586805868158682586835868458685586865868758688586895869058691586925869358694586955869658697586985869958700587015870258703587045870558706587075870858709587105871158712587135871458715587165871758718587195872058721587225872358724587255872658727587285872958730587315873258733587345873558736587375873858739587405874158742587435874458745587465874758748587495875058751587525875358754587555875658757587585875958760587615876258763587645876558766587675876858769587705877158772587735877458775587765877758778587795878058781587825878358784587855878658787587885878958790587915879258793587945879558796587975879858799588005880158802588035880458805588065880758808588095881058811588125881358814588155881658817588185881958820588215882258823588245882558826588275882858829588305883158832588335883458835588365883758838588395884058841588425884358844588455884658847588485884958850588515885258853588545885558856588575885858859588605886158862588635886458865588665886758868588695887058871588725887358874588755887658877588785887958880588815888258883588845888558886588875888858889588905889158892588935889458895588965889758898588995890058901589025890358904589055890658907589085890958910589115891258913589145891558916589175891858919589205892158922589235892458925589265892758928589295893058931589325893358934589355893658937589385893958940589415894258943589445894558946589475894858949589505895158952589535895458955589565895758958589595896058961589625896358964589655896658967589685896958970589715897258973589745897558976589775897858979589805898158982589835898458985589865898758988589895899058991589925899358994589955899658997589985899959000590015900259003590045900559006590075900859009590105901159012590135901459015590165901759018590195902059021590225902359024590255902659027590285902959030590315903259033590345903559036590375903859039590405904159042590435904459045590465904759048590495905059051590525905359054590555905659057590585905959060590615906259063590645906559066590675906859069590705907159072590735907459075590765907759078590795908059081590825908359084590855908659087590885908959090590915909259093590945909559096590975909859099591005910159102591035910459105591065910759108591095911059111591125911359114591155911659117591185911959120591215912259123591245912559126591275912859129591305913159132591335913459135591365913759138591395914059141591425914359144591455914659147591485914959150591515915259153591545915559156591575915859159591605916159162591635916459165591665916759168591695917059171591725917359174591755917659177591785917959180591815918259183591845918559186591875918859189591905919159192591935919459195591965919759198591995920059201592025920359204592055920659207592085920959210592115921259213592145921559216592175921859219592205922159222592235922459225592265922759228592295923059231592325923359234592355923659237592385923959240592415924259243592445924559246592475924859249592505925159252592535925459255592565925759258592595926059261592625926359264592655926659267592685926959270592715927259273592745927559276592775927859279592805928159282592835928459285592865928759288592895929059291592925929359294592955929659297592985929959300593015930259303593045930559306593075930859309593105931159312593135931459315593165931759318593195932059321593225932359324593255932659327593285932959330593315933259333593345933559336593375933859339593405934159342593435934459345593465934759348593495935059351593525935359354593555935659357593585935959360593615936259363593645936559366593675936859369593705937159372593735937459375593765937759378593795938059381593825938359384593855938659387593885938959390593915939259393593945939559396593975939859399594005940159402594035940459405594065940759408594095941059411594125941359414594155941659417594185941959420594215942259423594245942559426594275942859429594305943159432594335943459435594365943759438594395944059441594425944359444594455944659447594485944959450594515945259453594545945559456594575945859459594605946159462594635946459465594665946759468594695947059471594725947359474594755947659477594785947959480594815948259483594845948559486594875948859489594905949159492594935949459495594965949759498594995950059501595025950359504595055950659507595085950959510595115951259513595145951559516595175951859519595205952159522595235952459525595265952759528595295953059531595325953359534595355953659537595385953959540595415954259543595445954559546595475954859549595505955159552595535955459555595565955759558595595956059561595625956359564595655956659567595685956959570595715957259573595745957559576595775957859579595805958159582595835958459585595865958759588595895959059591595925959359594595955959659597595985959959600596015960259603596045960559606596075960859609596105961159612596135961459615596165961759618596195962059621596225962359624596255962659627596285962959630596315963259633596345963559636596375963859639596405964159642596435964459645596465964759648596495965059651596525965359654596555965659657596585965959660596615966259663596645966559666596675966859669596705967159672596735967459675596765967759678596795968059681596825968359684596855968659687596885968959690596915969259693596945969559696596975969859699597005970159702597035970459705597065970759708597095971059711597125971359714597155971659717597185971959720597215972259723597245972559726597275972859729597305973159732597335973459735597365973759738597395974059741597425974359744597455974659747597485974959750597515975259753597545975559756597575975859759597605976159762597635976459765597665976759768597695977059771597725977359774597755977659777597785977959780597815978259783597845978559786597875978859789597905979159792597935979459795597965979759798597995980059801598025980359804598055980659807598085980959810598115981259813598145981559816598175981859819598205982159822598235982459825598265982759828598295983059831598325983359834598355983659837598385983959840598415984259843598445984559846598475984859849598505985159852598535985459855598565985759858598595986059861598625986359864598655986659867598685986959870598715987259873598745987559876598775987859879598805988159882598835988459885598865988759888598895989059891598925989359894598955989659897598985989959900599015990259903599045990559906599075990859909599105991159912599135991459915599165991759918599195992059921599225992359924599255992659927599285992959930599315993259933599345993559936599375993859939599405994159942599435994459945599465994759948599495995059951599525995359954599555995659957599585995959960599615996259963599645996559966599675996859969599705997159972599735997459975599765997759978599795998059981599825998359984599855998659987599885998959990599915999259993599945999559996599975999859999600006000160002600036000460005600066000760008600096001060011600126001360014600156001660017600186001960020600216002260023600246002560026600276002860029600306003160032600336003460035600366003760038600396004060041600426004360044600456004660047600486004960050600516005260053600546005560056600576005860059600606006160062600636006460065600666006760068600696007060071600726007360074600756007660077600786007960080600816008260083600846008560086600876008860089600906009160092600936009460095600966009760098600996010060101601026010360104601056010660107601086010960110601116011260113601146011560116601176011860119601206012160122601236012460125601266012760128601296013060131601326013360134601356013660137601386013960140601416014260143601446014560146601476014860149601506015160152601536015460155601566015760158601596016060161601626016360164601656016660167601686016960170601716017260173601746017560176601776017860179601806018160182601836018460185601866018760188601896019060191601926019360194601956019660197601986019960200602016020260203602046020560206602076020860209602106021160212602136021460215602166021760218602196022060221602226022360224602256022660227602286022960230602316023260233602346023560236602376023860239602406024160242602436024460245602466024760248602496025060251602526025360254602556025660257602586025960260602616026260263602646026560266602676026860269602706027160272602736027460275602766027760278602796028060281602826028360284602856028660287602886028960290602916029260293602946029560296602976029860299603006030160302603036030460305603066030760308603096031060311603126031360314603156031660317603186031960320603216032260323603246032560326603276032860329603306033160332603336033460335603366033760338603396034060341603426034360344603456034660347603486034960350603516035260353603546035560356603576035860359603606036160362603636036460365603666036760368603696037060371603726037360374603756037660377603786037960380603816038260383603846038560386603876038860389603906039160392603936039460395603966039760398603996040060401604026040360404604056040660407604086040960410604116041260413604146041560416604176041860419604206042160422604236042460425604266042760428604296043060431604326043360434604356043660437604386043960440604416044260443604446044560446604476044860449604506045160452604536045460455604566045760458604596046060461604626046360464604656046660467604686046960470604716047260473604746047560476604776047860479604806048160482604836048460485604866048760488604896049060491604926049360494604956049660497604986049960500605016050260503605046050560506605076050860509605106051160512605136051460515605166051760518605196052060521605226052360524605256052660527605286052960530605316053260533605346053560536605376053860539605406054160542605436054460545605466054760548605496055060551605526055360554605556055660557605586055960560605616056260563605646056560566605676056860569605706057160572605736057460575605766057760578605796058060581605826058360584605856058660587605886058960590605916059260593605946059560596605976059860599606006060160602606036060460605606066060760608606096061060611606126061360614606156061660617606186061960620606216062260623606246062560626606276062860629606306063160632606336063460635606366063760638606396064060641606426064360644606456064660647606486064960650606516065260653606546065560656606576065860659606606066160662606636066460665606666066760668606696067060671606726067360674606756067660677606786067960680606816068260683606846068560686606876068860689606906069160692606936069460695606966069760698606996070060701607026070360704607056070660707607086070960710607116071260713607146071560716607176071860719607206072160722607236072460725607266072760728607296073060731607326073360734607356073660737607386073960740607416074260743607446074560746607476074860749607506075160752607536075460755607566075760758607596076060761607626076360764607656076660767607686076960770607716077260773607746077560776607776077860779607806078160782607836078460785607866078760788607896079060791607926079360794607956079660797607986079960800608016080260803608046080560806608076080860809608106081160812608136081460815608166081760818608196082060821608226082360824608256082660827608286082960830608316083260833608346083560836608376083860839608406084160842608436084460845608466084760848608496085060851608526085360854608556085660857608586085960860608616086260863608646086560866608676086860869608706087160872608736087460875608766087760878608796088060881608826088360884608856088660887608886088960890608916089260893608946089560896608976089860899609006090160902609036090460905609066090760908609096091060911609126091360914609156091660917609186091960920609216092260923609246092560926609276092860929609306093160932609336093460935609366093760938609396094060941609426094360944609456094660947609486094960950609516095260953609546095560956609576095860959609606096160962609636096460965609666096760968609696097060971609726097360974609756097660977609786097960980609816098260983609846098560986609876098860989609906099160992609936099460995609966099760998609996100061001610026100361004610056100661007610086100961010610116101261013610146101561016610176101861019610206102161022610236102461025610266102761028610296103061031610326103361034610356103661037610386103961040610416104261043610446104561046610476104861049610506105161052610536105461055610566105761058610596106061061610626106361064610656106661067610686106961070610716107261073610746107561076610776107861079610806108161082610836108461085610866108761088610896109061091610926109361094610956109661097610986109961100611016110261103611046110561106611076110861109611106111161112611136111461115611166111761118611196112061121611226112361124611256112661127611286112961130611316113261133611346113561136611376113861139611406114161142611436114461145611466114761148611496115061151611526115361154611556115661157611586115961160611616116261163611646116561166611676116861169611706117161172611736117461175611766117761178611796118061181611826118361184611856118661187611886118961190611916119261193611946119561196611976119861199612006120161202612036120461205612066120761208612096121061211612126121361214612156121661217612186121961220612216122261223612246122561226612276122861229612306123161232612336123461235612366123761238612396124061241612426124361244612456124661247612486124961250612516125261253612546125561256612576125861259612606126161262612636126461265612666126761268612696127061271612726127361274612756127661277612786127961280612816128261283612846128561286612876128861289612906129161292612936129461295612966129761298612996130061301613026130361304613056130661307613086130961310613116131261313613146131561316613176131861319613206132161322613236132461325613266132761328613296133061331613326133361334613356133661337613386133961340613416134261343613446134561346613476134861349613506135161352613536135461355613566135761358613596136061361613626136361364613656136661367613686136961370613716137261373613746137561376613776137861379613806138161382613836138461385613866138761388613896139061391613926139361394613956139661397613986139961400614016140261403614046140561406614076140861409614106141161412614136141461415614166141761418614196142061421614226142361424614256142661427614286142961430614316143261433614346143561436614376143861439614406144161442614436144461445614466144761448614496145061451614526145361454614556145661457614586145961460614616146261463614646146561466614676146861469614706147161472614736147461475614766147761478614796148061481614826148361484614856148661487614886148961490614916149261493614946149561496614976149861499615006150161502615036150461505615066150761508615096151061511615126151361514615156151661517615186151961520615216152261523615246152561526615276152861529615306153161532615336153461535615366153761538615396154061541615426154361544615456154661547615486154961550615516155261553615546155561556615576155861559615606156161562615636156461565615666156761568615696157061571615726157361574615756157661577615786157961580615816158261583615846158561586615876158861589615906159161592615936159461595615966159761598615996160061601616026160361604616056160661607616086160961610616116161261613616146161561616616176161861619616206162161622616236162461625616266162761628616296163061631616326163361634616356163661637616386163961640616416164261643616446164561646616476164861649616506165161652616536165461655616566165761658616596166061661616626166361664616656166661667616686166961670616716167261673616746167561676616776167861679616806168161682616836168461685616866168761688616896169061691616926169361694616956169661697616986169961700617016170261703617046170561706617076170861709617106171161712617136171461715617166171761718617196172061721617226172361724617256172661727617286172961730617316173261733617346173561736617376173861739617406174161742617436174461745617466174761748617496175061751617526175361754617556175661757617586175961760617616176261763617646176561766617676176861769617706177161772617736177461775617766177761778617796178061781617826178361784617856178661787617886178961790617916179261793617946179561796617976179861799618006180161802618036180461805618066180761808618096181061811618126181361814618156181661817618186181961820618216182261823618246182561826618276182861829618306183161832618336183461835618366183761838618396184061841618426184361844618456184661847618486184961850618516185261853618546185561856618576185861859618606186161862618636186461865618666186761868618696187061871618726187361874618756187661877618786187961880618816188261883618846188561886618876188861889618906189161892618936189461895618966189761898618996190061901619026190361904619056190661907619086190961910619116191261913619146191561916619176191861919619206192161922619236192461925619266192761928619296193061931619326193361934619356193661937619386193961940619416194261943619446194561946619476194861949619506195161952619536195461955619566195761958619596196061961619626196361964619656196661967619686196961970619716197261973619746197561976619776197861979619806198161982619836198461985619866198761988619896199061991619926199361994619956199661997619986199962000620016200262003620046200562006620076200862009620106201162012620136201462015620166201762018620196202062021620226202362024620256202662027620286202962030620316203262033620346203562036620376203862039620406204162042620436204462045620466204762048620496205062051620526205362054620556205662057620586205962060620616206262063620646206562066620676206862069620706207162072620736207462075620766207762078620796208062081620826208362084620856208662087620886208962090620916209262093620946209562096620976209862099621006210162102621036210462105621066210762108621096211062111621126211362114621156211662117621186211962120621216212262123621246212562126621276212862129621306213162132621336213462135621366213762138621396214062141621426214362144621456214662147621486214962150621516215262153621546215562156621576215862159621606216162162621636216462165621666216762168621696217062171621726217362174621756217662177621786217962180621816218262183621846218562186621876218862189621906219162192621936219462195621966219762198621996220062201622026220362204622056220662207622086220962210622116221262213622146221562216622176221862219622206222162222622236222462225622266222762228622296223062231622326223362234622356223662237622386223962240622416224262243622446224562246622476224862249622506225162252622536225462255622566225762258622596226062261622626226362264622656226662267622686226962270622716227262273622746227562276622776227862279622806228162282622836228462285622866228762288622896229062291622926229362294622956229662297622986229962300623016230262303623046230562306623076230862309623106231162312623136231462315623166231762318623196232062321623226232362324623256232662327623286232962330623316233262333623346233562336623376233862339623406234162342623436234462345623466234762348623496235062351623526235362354623556235662357623586235962360623616236262363623646236562366623676236862369623706237162372623736237462375623766237762378623796238062381623826238362384623856238662387623886238962390623916239262393623946239562396623976239862399624006240162402624036240462405624066240762408624096241062411624126241362414624156241662417624186241962420624216242262423624246242562426624276242862429624306243162432624336243462435624366243762438624396244062441624426244362444624456244662447624486244962450624516245262453624546245562456624576245862459624606246162462624636246462465624666246762468624696247062471624726247362474624756247662477624786247962480624816248262483624846248562486624876248862489624906249162492624936249462495624966249762498624996250062501625026250362504625056250662507625086250962510625116251262513625146251562516625176251862519625206252162522625236252462525625266252762528625296253062531625326253362534625356253662537625386253962540625416254262543625446254562546625476254862549625506255162552625536255462555625566255762558625596256062561625626256362564625656256662567625686256962570625716257262573625746257562576625776257862579625806258162582625836258462585625866258762588625896259062591625926259362594625956259662597625986259962600626016260262603626046260562606626076260862609626106261162612626136261462615626166261762618626196262062621626226262362624626256262662627626286262962630626316263262633626346263562636626376263862639626406264162642626436264462645626466264762648626496265062651626526265362654626556265662657626586265962660626616266262663626646266562666626676266862669626706267162672626736267462675626766267762678626796268062681626826268362684626856268662687626886268962690626916269262693626946269562696626976269862699627006270162702627036270462705627066270762708627096271062711627126271362714627156271662717627186271962720627216272262723627246272562726627276272862729627306273162732627336273462735627366273762738627396274062741627426274362744627456274662747627486274962750627516275262753627546275562756627576275862759627606276162762627636276462765627666276762768627696277062771627726277362774627756277662777627786277962780627816278262783627846278562786627876278862789627906279162792627936279462795627966279762798627996280062801628026280362804628056280662807628086280962810628116281262813628146281562816628176281862819628206282162822628236282462825628266282762828628296283062831628326283362834628356283662837628386283962840628416284262843628446284562846628476284862849628506285162852628536285462855628566285762858628596286062861628626286362864628656286662867628686286962870628716287262873628746287562876628776287862879628806288162882628836288462885628866288762888628896289062891628926289362894628956289662897628986289962900629016290262903629046290562906629076290862909629106291162912629136291462915629166291762918629196292062921629226292362924629256292662927629286292962930629316293262933629346293562936629376293862939629406294162942629436294462945629466294762948629496295062951629526295362954629556295662957629586295962960629616296262963629646296562966629676296862969629706297162972629736297462975629766297762978629796298062981629826298362984629856298662987629886298962990629916299262993629946299562996629976299862999630006300163002630036300463005630066300763008630096301063011630126301363014630156301663017630186301963020630216302263023630246302563026630276302863029630306303163032630336303463035630366303763038630396304063041630426304363044630456304663047630486304963050630516305263053630546305563056630576305863059630606306163062630636306463065630666306763068630696307063071630726307363074630756307663077630786307963080630816308263083630846308563086630876308863089630906309163092630936309463095630966309763098630996310063101631026310363104631056310663107631086310963110631116311263113631146311563116631176311863119631206312163122631236312463125631266312763128631296313063131631326313363134631356313663137631386313963140631416314263143631446314563146631476314863149631506315163152631536315463155631566315763158631596316063161631626316363164631656316663167631686316963170631716317263173631746317563176631776317863179631806318163182631836318463185631866318763188631896319063191631926319363194631956319663197631986319963200632016320263203632046320563206632076320863209632106321163212632136321463215632166321763218632196322063221632226322363224632256322663227632286322963230632316323263233632346323563236632376323863239632406324163242632436324463245632466324763248632496325063251632526325363254632556325663257632586325963260632616326263263632646326563266632676326863269632706327163272632736327463275632766327763278632796328063281632826328363284632856328663287632886328963290632916329263293632946329563296632976329863299633006330163302633036330463305633066330763308633096331063311633126331363314633156331663317633186331963320633216332263323633246332563326633276332863329633306333163332633336333463335633366333763338633396334063341633426334363344633456334663347633486334963350633516335263353633546335563356633576335863359633606336163362633636336463365633666336763368633696337063371633726337363374633756337663377633786337963380633816338263383633846338563386633876338863389633906339163392633936339463395633966339763398633996340063401634026340363404634056340663407634086340963410634116341263413634146341563416634176341863419634206342163422634236342463425634266342763428634296343063431634326343363434634356343663437634386343963440634416344263443634446344563446634476344863449634506345163452634536345463455634566345763458634596346063461634626346363464634656346663467634686346963470634716347263473634746347563476634776347863479634806348163482634836348463485634866348763488634896349063491634926349363494634956349663497634986349963500635016350263503635046350563506635076350863509635106351163512635136351463515635166351763518635196352063521635226352363524635256352663527635286352963530635316353263533635346353563536635376353863539635406354163542635436354463545635466354763548635496355063551635526355363554635556355663557635586355963560635616356263563635646356563566635676356863569635706357163572635736357463575635766357763578635796358063581635826358363584635856358663587635886358963590635916359263593635946359563596635976359863599636006360163602636036360463605636066360763608636096361063611636126361363614636156361663617636186361963620636216362263623636246362563626636276362863629636306363163632636336363463635636366363763638636396364063641636426364363644636456364663647636486364963650636516365263653636546365563656636576365863659636606366163662636636366463665636666366763668636696367063671636726367363674636756367663677636786367963680636816368263683636846368563686636876368863689636906369163692636936369463695636966369763698636996370063701637026370363704637056370663707637086370963710637116371263713637146371563716637176371863719637206372163722637236372463725637266372763728637296373063731637326373363734637356373663737637386373963740637416374263743637446374563746637476374863749637506375163752637536375463755637566375763758637596376063761637626376363764637656376663767637686376963770637716377263773637746377563776637776377863779637806378163782637836378463785637866378763788637896379063791637926379363794637956379663797637986379963800638016380263803638046380563806638076380863809638106381163812638136381463815638166381763818638196382063821638226382363824638256382663827638286382963830638316383263833638346383563836638376383863839638406384163842638436384463845638466384763848638496385063851638526385363854638556385663857638586385963860638616386263863638646386563866638676386863869638706387163872638736387463875638766387763878638796388063881638826388363884638856388663887638886388963890638916389263893638946389563896638976389863899639006390163902639036390463905639066390763908639096391063911639126391363914639156391663917639186391963920639216392263923639246392563926639276392863929639306393163932639336393463935639366393763938639396394063941639426394363944639456394663947639486394963950639516395263953639546395563956639576395863959639606396163962639636396463965639666396763968639696397063971639726397363974639756397663977639786397963980639816398263983639846398563986639876398863989639906399163992639936399463995639966399763998639996400064001640026400364004640056400664007640086400964010640116401264013640146401564016640176401864019640206402164022640236402464025640266402764028640296403064031640326403364034640356403664037640386403964040640416404264043640446404564046640476404864049640506405164052640536405464055640566405764058640596406064061640626406364064640656406664067640686406964070640716407264073640746407564076640776407864079640806408164082640836408464085640866408764088640896409064091640926409364094640956409664097640986409964100641016410264103641046410564106641076410864109641106411164112641136411464115641166411764118641196412064121641226412364124641256412664127641286412964130641316413264133641346413564136641376413864139641406414164142641436414464145641466414764148641496415064151641526415364154641556415664157641586415964160641616416264163641646416564166641676416864169641706417164172641736417464175641766417764178641796418064181641826418364184641856418664187641886418964190641916419264193641946419564196641976419864199642006420164202642036420464205642066420764208642096421064211642126421364214642156421664217642186421964220642216422264223642246422564226642276422864229642306423164232642336423464235642366423764238642396424064241642426424364244642456424664247642486424964250642516425264253642546425564256642576425864259642606426164262642636426464265642666426764268642696427064271642726427364274642756427664277642786427964280642816428264283642846428564286642876428864289642906429164292642936429464295642966429764298642996430064301643026430364304643056430664307643086430964310643116431264313643146431564316643176431864319643206432164322643236432464325643266432764328643296433064331643326433364334643356433664337643386433964340643416434264343643446434564346643476434864349643506435164352643536435464355643566435764358643596436064361643626436364364643656436664367643686436964370643716437264373643746437564376643776437864379643806438164382643836438464385643866438764388643896439064391643926439364394643956439664397643986439964400644016440264403644046440564406644076440864409644106441164412644136441464415644166441764418644196442064421644226442364424644256442664427644286442964430644316443264433644346443564436644376443864439644406444164442644436444464445644466444764448644496445064451644526445364454644556445664457644586445964460644616446264463644646446564466644676446864469644706447164472644736447464475644766447764478644796448064481644826448364484644856448664487644886448964490644916449264493644946449564496644976449864499645006450164502645036450464505645066450764508645096451064511645126451364514645156451664517645186451964520645216452264523645246452564526645276452864529645306453164532645336453464535645366453764538645396454064541645426454364544645456454664547645486454964550645516455264553645546455564556645576455864559645606456164562645636456464565645666456764568645696457064571645726457364574645756457664577645786457964580645816458264583645846458564586645876458864589645906459164592645936459464595645966459764598645996460064601646026460364604646056460664607646086460964610646116461264613646146461564616646176461864619646206462164622646236462464625646266462764628646296463064631646326463364634646356463664637646386463964640646416464264643646446464564646646476464864649646506465164652646536465464655646566465764658646596466064661646626466364664646656466664667646686466964670646716467264673646746467564676646776467864679646806468164682646836468464685646866468764688646896469064691646926469364694646956469664697646986469964700647016470264703647046470564706647076470864709647106471164712647136471464715647166471764718647196472064721647226472364724647256472664727647286472964730647316473264733647346473564736647376473864739647406474164742647436474464745647466474764748647496475064751647526475364754647556475664757647586475964760647616476264763647646476564766647676476864769647706477164772647736477464775647766477764778647796478064781647826478364784647856478664787647886478964790647916479264793647946479564796647976479864799648006480164802648036480464805648066480764808648096481064811648126481364814648156481664817648186481964820648216482264823648246482564826648276482864829648306483164832648336483464835648366483764838648396484064841648426484364844648456484664847648486484964850648516485264853648546485564856648576485864859648606486164862648636486464865648666486764868648696487064871648726487364874648756487664877648786487964880648816488264883648846488564886648876488864889648906489164892648936489464895648966489764898648996490064901649026490364904649056490664907649086490964910649116491264913649146491564916649176491864919649206492164922649236492464925649266492764928649296493064931649326493364934649356493664937649386493964940649416494264943649446494564946649476494864949649506495164952649536495464955649566495764958649596496064961649626496364964649656496664967649686496964970649716497264973649746497564976649776497864979649806498164982649836498464985649866498764988649896499064991649926499364994649956499664997649986499965000650016500265003650046500565006650076500865009650106501165012650136501465015650166501765018650196502065021650226502365024650256502665027650286502965030650316503265033650346503565036650376503865039650406504165042650436504465045650466504765048650496505065051650526505365054650556505665057650586505965060650616506265063650646506565066650676506865069650706507165072650736507465075650766507765078650796508065081650826508365084650856508665087650886508965090650916509265093650946509565096650976509865099651006510165102651036510465105651066510765108651096511065111651126511365114651156511665117651186511965120651216512265123651246512565126651276512865129651306513165132651336513465135651366513765138651396514065141651426514365144651456514665147651486514965150651516515265153651546515565156651576515865159651606516165162651636516465165651666516765168651696517065171651726517365174651756517665177651786517965180651816518265183651846518565186651876518865189651906519165192651936519465195651966519765198651996520065201652026520365204652056520665207652086520965210652116521265213652146521565216652176521865219652206522165222652236522465225652266522765228652296523065231652326523365234652356523665237652386523965240652416524265243652446524565246652476524865249652506525165252652536525465255652566525765258652596526065261652626526365264652656526665267652686526965270652716527265273652746527565276652776527865279652806528165282652836528465285652866528765288652896529065291652926529365294652956529665297652986529965300653016530265303653046530565306653076530865309653106531165312653136531465315653166531765318653196532065321653226532365324653256532665327653286532965330653316533265333653346533565336653376533865339653406534165342653436534465345653466534765348653496535065351653526535365354653556535665357653586535965360653616536265363653646536565366653676536865369653706537165372653736537465375653766537765378653796538065381653826538365384653856538665387653886538965390653916539265393653946539565396653976539865399654006540165402654036540465405654066540765408654096541065411654126541365414654156541665417654186541965420654216542265423654246542565426654276542865429654306543165432654336543465435654366543765438654396544065441654426544365444654456544665447654486544965450654516545265453654546545565456654576545865459654606546165462654636546465465654666546765468654696547065471654726547365474654756547665477654786547965480654816548265483654846548565486654876548865489654906549165492654936549465495654966549765498654996550065501655026550365504655056550665507655086550965510655116551265513655146551565516655176551865519655206552165522655236552465525655266552765528655296553065531655326553365534655356553665537655386553965540655416554265543655446554565546655476554865549655506555165552655536555465555655566555765558655596556065561655626556365564655656556665567655686556965570655716557265573655746557565576655776557865579655806558165582655836558465585655866558765588655896559065591655926559365594655956559665597655986559965600656016560265603656046560565606656076560865609656106561165612656136561465615656166561765618656196562065621656226562365624656256562665627656286562965630656316563265633656346563565636656376563865639656406564165642656436564465645656466564765648656496565065651656526565365654656556565665657656586565965660656616566265663656646566565666656676566865669656706567165672656736567465675656766567765678656796568065681656826568365684656856568665687656886568965690656916569265693656946569565696656976569865699657006570165702657036570465705657066570765708657096571065711657126571365714657156571665717657186571965720657216572265723657246572565726657276572865729657306573165732657336573465735657366573765738657396574065741657426574365744657456574665747657486574965750657516575265753657546575565756657576575865759657606576165762657636576465765657666576765768657696577065771657726577365774657756577665777657786577965780657816578265783657846578565786657876578865789657906579165792657936579465795657966579765798657996580065801658026580365804658056580665807658086580965810658116581265813658146581565816658176581865819658206582165822658236582465825658266582765828658296583065831658326583365834658356583665837658386583965840658416584265843658446584565846658476584865849658506585165852658536585465855658566585765858658596586065861658626586365864658656586665867658686586965870658716587265873658746587565876658776587865879658806588165882658836588465885658866588765888658896589065891658926589365894658956589665897658986589965900659016590265903659046590565906659076590865909659106591165912659136591465915659166591765918659196592065921659226592365924659256592665927659286592965930659316593265933659346593565936659376593865939659406594165942659436594465945659466594765948659496595065951659526595365954659556595665957659586595965960659616596265963659646596565966659676596865969659706597165972659736597465975659766597765978659796598065981659826598365984659856598665987659886598965990659916599265993659946599565996659976599865999660006600166002660036600466005660066600766008660096601066011660126601366014660156601666017660186601966020660216602266023660246602566026660276602866029660306603166032660336603466035660366603766038660396604066041660426604366044660456604666047660486604966050660516605266053660546605566056660576605866059660606606166062660636606466065660666606766068660696607066071660726607366074660756607666077660786607966080660816608266083660846608566086660876608866089660906609166092660936609466095660966609766098660996610066101661026610366104661056610666107661086610966110661116611266113661146611566116661176611866119661206612166122661236612466125661266612766128661296613066131661326613366134661356613666137661386613966140661416614266143661446614566146661476614866149661506615166152661536615466155661566615766158661596616066161661626616366164661656616666167661686616966170661716617266173661746617566176661776617866179661806618166182661836618466185661866618766188661896619066191661926619366194661956619666197661986619966200662016620266203662046620566206662076620866209662106621166212662136621466215662166621766218662196622066221662226622366224662256622666227662286622966230662316623266233662346623566236662376623866239662406624166242662436624466245662466624766248662496625066251662526625366254662556625666257662586625966260662616626266263662646626566266662676626866269662706627166272662736627466275662766627766278662796628066281662826628366284662856628666287662886628966290662916629266293662946629566296662976629866299663006630166302663036630466305663066630766308663096631066311663126631366314663156631666317663186631966320663216632266323663246632566326663276632866329663306633166332663336633466335663366633766338663396634066341663426634366344663456634666347663486634966350663516635266353663546635566356663576635866359663606636166362663636636466365663666636766368663696637066371663726637366374663756637666377663786637966380663816638266383663846638566386663876638866389663906639166392663936639466395663966639766398663996640066401664026640366404664056640666407664086640966410664116641266413664146641566416664176641866419664206642166422664236642466425664266642766428664296643066431664326643366434664356643666437664386643966440664416644266443664446644566446664476644866449664506645166452664536645466455664566645766458664596646066461664626646366464664656646666467664686646966470664716647266473664746647566476664776647866479664806648166482664836648466485664866648766488664896649066491664926649366494664956649666497664986649966500665016650266503665046650566506665076650866509665106651166512665136651466515665166651766518665196652066521665226652366524665256652666527665286652966530665316653266533665346653566536665376653866539665406654166542665436654466545665466654766548665496655066551665526655366554665556655666557665586655966560665616656266563665646656566566665676656866569665706657166572665736657466575665766657766578665796658066581665826658366584665856658666587665886658966590665916659266593665946659566596665976659866599666006660166602666036660466605666066660766608666096661066611666126661366614666156661666617666186661966620666216662266623666246662566626666276662866629666306663166632666336663466635666366663766638666396664066641666426664366644666456664666647666486664966650666516665266653666546665566656666576665866659666606666166662666636666466665666666666766668666696667066671666726667366674666756667666677666786667966680666816668266683666846668566686666876668866689666906669166692666936669466695666966669766698666996670066701667026670366704667056670666707667086670966710667116671266713667146671566716667176671866719667206672166722667236672466725667266672766728667296673066731667326673366734667356673666737667386673966740667416674266743667446674566746667476674866749667506675166752667536675466755667566675766758667596676066761667626676366764667656676666767667686676966770667716677266773667746677566776667776677866779667806678166782667836678466785667866678766788667896679066791667926679366794667956679666797667986679966800668016680266803668046680566806668076680866809668106681166812668136681466815668166681766818668196682066821668226682366824668256682666827668286682966830668316683266833668346683566836668376683866839668406684166842668436684466845668466684766848668496685066851668526685366854668556685666857668586685966860668616686266863668646686566866668676686866869668706687166872668736687466875668766687766878668796688066881668826688366884668856688666887668886688966890668916689266893668946689566896668976689866899669006690166902669036690466905669066690766908669096691066911669126691366914669156691666917669186691966920669216692266923669246692566926669276692866929669306693166932669336693466935669366693766938669396694066941669426694366944669456694666947669486694966950669516695266953669546695566956669576695866959669606696166962669636696466965669666696766968669696697066971669726697366974669756697666977669786697966980669816698266983669846698566986669876698866989669906699166992669936699466995669966699766998669996700067001670026700367004670056700667007670086700967010670116701267013670146701567016670176701867019670206702167022670236702467025670266702767028670296703067031670326703367034670356703667037670386703967040670416704267043670446704567046670476704867049670506705167052670536705467055670566705767058670596706067061670626706367064670656706667067670686706967070670716707267073670746707567076670776707867079670806708167082670836708467085670866708767088670896709067091670926709367094670956709667097670986709967100671016710267103671046710567106671076710867109671106711167112671136711467115671166711767118671196712067121671226712367124671256712667127671286712967130671316713267133671346713567136671376713867139671406714167142671436714467145671466714767148671496715067151671526715367154671556715667157671586715967160671616716267163671646716567166671676716867169671706717167172671736717467175671766717767178671796718067181671826718367184671856718667187671886718967190671916719267193671946719567196671976719867199672006720167202672036720467205672066720767208672096721067211672126721367214672156721667217672186721967220672216722267223672246722567226672276722867229672306723167232672336723467235672366723767238672396724067241672426724367244672456724667247672486724967250672516725267253672546725567256672576725867259672606726167262672636726467265672666726767268672696727067271672726727367274672756727667277672786727967280672816728267283672846728567286672876728867289672906729167292672936729467295672966729767298672996730067301673026730367304673056730667307673086730967310673116731267313673146731567316673176731867319673206732167322673236732467325673266732767328673296733067331673326733367334673356733667337673386733967340673416734267343673446734567346673476734867349673506735167352673536735467355673566735767358673596736067361673626736367364673656736667367673686736967370673716737267373673746737567376673776737867379673806738167382673836738467385673866738767388673896739067391673926739367394673956739667397673986739967400674016740267403674046740567406674076740867409674106741167412674136741467415674166741767418674196742067421674226742367424674256742667427674286742967430674316743267433674346743567436674376743867439674406744167442674436744467445674466744767448674496745067451674526745367454674556745667457674586745967460674616746267463674646746567466674676746867469674706747167472674736747467475674766747767478674796748067481674826748367484674856748667487674886748967490674916749267493674946749567496674976749867499675006750167502675036750467505675066750767508675096751067511675126751367514675156751667517675186751967520675216752267523675246752567526675276752867529675306753167532675336753467535675366753767538675396754067541675426754367544675456754667547675486754967550675516755267553675546755567556675576755867559675606756167562675636756467565675666756767568675696757067571675726757367574675756757667577675786757967580675816758267583675846758567586675876758867589675906759167592675936759467595675966759767598675996760067601676026760367604676056760667607676086760967610676116761267613676146761567616676176761867619676206762167622676236762467625676266762767628676296763067631676326763367634676356763667637676386763967640676416764267643676446764567646676476764867649676506765167652676536765467655676566765767658676596766067661676626766367664676656766667667676686766967670676716767267673676746767567676676776767867679676806768167682676836768467685676866768767688676896769067691676926769367694676956769667697676986769967700677016770267703677046770567706677076770867709677106771167712677136771467715677166771767718677196772067721677226772367724677256772667727677286772967730677316773267733677346773567736677376773867739677406774167742677436774467745677466774767748677496775067751677526775367754677556775667757677586775967760677616776267763677646776567766677676776867769677706777167772677736777467775677766777767778677796778067781677826778367784677856778667787677886778967790677916779267793677946779567796677976779867799678006780167802678036780467805678066780767808678096781067811678126781367814678156781667817678186781967820678216782267823678246782567826678276782867829678306783167832678336783467835678366783767838678396784067841678426784367844678456784667847678486784967850678516785267853678546785567856678576785867859678606786167862678636786467865678666786767868678696787067871678726787367874678756787667877678786787967880678816788267883678846788567886678876788867889678906789167892678936789467895678966789767898678996790067901679026790367904679056790667907679086790967910679116791267913679146791567916679176791867919679206792167922679236792467925679266792767928679296793067931679326793367934679356793667937679386793967940679416794267943679446794567946679476794867949679506795167952679536795467955679566795767958679596796067961679626796367964679656796667967679686796967970679716797267973679746797567976679776797867979679806798167982679836798467985679866798767988679896799067991679926799367994679956799667997679986799968000680016800268003680046800568006680076800868009680106801168012680136801468015680166801768018680196802068021680226802368024680256802668027680286802968030680316803268033680346803568036680376803868039680406804168042680436804468045680466804768048680496805068051680526805368054680556805668057680586805968060680616806268063680646806568066680676806868069680706807168072680736807468075680766807768078680796808068081680826808368084680856808668087680886808968090680916809268093680946809568096680976809868099681006810168102681036810468105681066810768108681096811068111681126811368114681156811668117681186811968120681216812268123681246812568126681276812868129681306813168132681336813468135681366813768138681396814068141681426814368144681456814668147681486814968150681516815268153681546815568156681576815868159681606816168162681636816468165681666816768168681696817068171681726817368174681756817668177681786817968180681816818268183681846818568186681876818868189681906819168192681936819468195681966819768198681996820068201682026820368204682056820668207682086820968210682116821268213682146821568216682176821868219682206822168222682236822468225682266822768228682296823068231682326823368234682356823668237682386823968240682416824268243682446824568246682476824868249682506825168252682536825468255682566825768258682596826068261682626826368264682656826668267682686826968270682716827268273682746827568276682776827868279682806828168282682836828468285682866828768288682896829068291682926829368294682956829668297682986829968300683016830268303683046830568306683076830868309683106831168312683136831468315683166831768318683196832068321683226832368324683256832668327683286832968330683316833268333683346833568336683376833868339683406834168342683436834468345683466834768348683496835068351683526835368354683556835668357683586835968360683616836268363683646836568366683676836868369683706837168372683736837468375683766837768378683796838068381683826838368384683856838668387683886838968390683916839268393683946839568396683976839868399684006840168402684036840468405684066840768408684096841068411684126841368414684156841668417684186841968420684216842268423684246842568426684276842868429684306843168432684336843468435684366843768438684396844068441684426844368444684456844668447684486844968450684516845268453684546845568456684576845868459684606846168462684636846468465684666846768468684696847068471684726847368474684756847668477684786847968480684816848268483684846848568486684876848868489684906849168492684936849468495684966849768498684996850068501685026850368504685056850668507685086850968510685116851268513685146851568516685176851868519685206852168522685236852468525685266852768528685296853068531685326853368534685356853668537685386853968540685416854268543685446854568546685476854868549685506855168552685536855468555685566855768558685596856068561685626856368564685656856668567685686856968570685716857268573685746857568576685776857868579685806858168582685836858468585685866858768588685896859068591685926859368594685956859668597685986859968600686016860268603686046860568606686076860868609686106861168612686136861468615686166861768618686196862068621686226862368624686256862668627686286862968630686316863268633686346863568636686376863868639686406864168642686436864468645686466864768648686496865068651686526865368654686556865668657686586865968660686616866268663686646866568666686676866868669686706867168672686736867468675686766867768678686796868068681686826868368684686856868668687686886868968690686916869268693686946869568696686976869868699687006870168702687036870468705687066870768708687096871068711687126871368714687156871668717687186871968720687216872268723687246872568726687276872868729687306873168732687336873468735687366873768738687396874068741687426874368744687456874668747687486874968750687516875268753687546875568756687576875868759687606876168762687636876468765687666876768768687696877068771687726877368774687756877668777687786877968780687816878268783687846878568786687876878868789687906879168792687936879468795687966879768798687996880068801688026880368804688056880668807688086880968810688116881268813688146881568816688176881868819688206882168822688236882468825688266882768828688296883068831688326883368834688356883668837688386883968840688416884268843688446884568846688476884868849688506885168852688536885468855688566885768858688596886068861688626886368864688656886668867688686886968870688716887268873688746887568876688776887868879688806888168882688836888468885688866888768888688896889068891688926889368894688956889668897688986889968900689016890268903689046890568906689076890868909689106891168912689136891468915689166891768918689196892068921689226892368924689256892668927689286892968930689316893268933689346893568936689376893868939689406894168942689436894468945689466894768948689496895068951689526895368954689556895668957689586895968960689616896268963689646896568966689676896868969689706897168972689736897468975689766897768978689796898068981689826898368984689856898668987689886898968990689916899268993689946899568996689976899868999690006900169002690036900469005690066900769008690096901069011690126901369014690156901669017690186901969020690216902269023690246902569026690276902869029690306903169032690336903469035690366903769038690396904069041690426904369044690456904669047690486904969050690516905269053690546905569056690576905869059690606906169062690636906469065690666906769068690696907069071690726907369074690756907669077690786907969080690816908269083690846908569086690876908869089690906909169092690936909469095690966909769098690996910069101691026910369104691056910669107691086910969110691116911269113691146911569116691176911869119691206912169122691236912469125691266912769128691296913069131691326913369134691356913669137691386913969140691416914269143691446914569146691476914869149691506915169152691536915469155691566915769158691596916069161691626916369164691656916669167691686916969170691716917269173691746917569176691776917869179691806918169182691836918469185691866918769188691896919069191691926919369194691956919669197691986919969200692016920269203692046920569206692076920869209692106921169212692136921469215692166921769218692196922069221692226922369224692256922669227692286922969230692316923269233692346923569236692376923869239692406924169242692436924469245692466924769248692496925069251692526925369254692556925669257692586925969260692616926269263692646926569266692676926869269692706927169272692736927469275692766927769278692796928069281692826928369284692856928669287692886928969290692916929269293692946929569296692976929869299693006930169302693036930469305693066930769308693096931069311693126931369314693156931669317693186931969320693216932269323693246932569326693276932869329693306933169332693336933469335693366933769338693396934069341693426934369344693456934669347693486934969350693516935269353693546935569356693576935869359693606936169362693636936469365693666936769368693696937069371693726937369374693756937669377693786937969380693816938269383693846938569386693876938869389693906939169392693936939469395693966939769398693996940069401694026940369404694056940669407694086940969410694116941269413694146941569416694176941869419694206942169422694236942469425694266942769428694296943069431694326943369434694356943669437694386943969440694416944269443694446944569446694476944869449694506945169452694536945469455694566945769458694596946069461694626946369464694656946669467694686946969470694716947269473694746947569476694776947869479694806948169482694836948469485694866948769488694896949069491694926949369494694956949669497694986949969500695016950269503695046950569506695076950869509695106951169512695136951469515695166951769518695196952069521695226952369524695256952669527695286952969530695316953269533695346953569536695376953869539695406954169542695436954469545695466954769548695496955069551695526955369554695556955669557695586955969560695616956269563695646956569566695676956869569695706957169572695736957469575695766957769578695796958069581695826958369584695856958669587695886958969590695916959269593695946959569596695976959869599696006960169602696036960469605696066960769608696096961069611696126961369614696156961669617696186961969620696216962269623696246962569626696276962869629696306963169632696336963469635696366963769638696396964069641696426964369644696456964669647696486964969650696516965269653696546965569656696576965869659696606966169662696636966469665696666966769668696696967069671696726967369674696756967669677696786967969680696816968269683696846968569686696876968869689696906969169692696936969469695696966969769698696996970069701697026970369704697056970669707697086970969710697116971269713697146971569716697176971869719697206972169722697236972469725697266972769728697296973069731697326973369734697356973669737697386973969740697416974269743697446974569746697476974869749697506975169752697536975469755697566975769758697596976069761697626976369764697656976669767697686976969770697716977269773697746977569776697776977869779697806978169782697836978469785697866978769788697896979069791697926979369794697956979669797697986979969800698016980269803698046980569806698076980869809698106981169812698136981469815698166981769818698196982069821698226982369824698256982669827698286982969830698316983269833698346983569836698376983869839698406984169842698436984469845698466984769848698496985069851698526985369854698556985669857698586985969860698616986269863698646986569866698676986869869698706987169872698736987469875698766987769878698796988069881698826988369884698856988669887698886988969890698916989269893698946989569896698976989869899699006990169902699036990469905699066990769908699096991069911699126991369914699156991669917699186991969920699216992269923699246992569926699276992869929699306993169932699336993469935699366993769938699396994069941699426994369944699456994669947699486994969950699516995269953699546995569956699576995869959699606996169962699636996469965699666996769968699696997069971699726997369974699756997669977699786997969980699816998269983699846998569986699876998869989699906999169992699936999469995699966999769998699997000070001700027000370004700057000670007700087000970010700117001270013700147001570016700177001870019700207002170022700237002470025700267002770028700297003070031700327003370034700357003670037700387003970040700417004270043700447004570046700477004870049700507005170052700537005470055700567005770058700597006070061700627006370064700657006670067700687006970070700717007270073700747007570076700777007870079700807008170082700837008470085700867008770088700897009070091700927009370094700957009670097700987009970100701017010270103701047010570106701077010870109701107011170112701137011470115701167011770118701197012070121701227012370124701257012670127701287012970130701317013270133701347013570136701377013870139701407014170142701437014470145701467014770148701497015070151701527015370154701557015670157701587015970160701617016270163701647016570166701677016870169701707017170172701737017470175701767017770178701797018070181701827018370184701857018670187701887018970190701917019270193701947019570196701977019870199702007020170202702037020470205702067020770208702097021070211702127021370214702157021670217702187021970220702217022270223702247022570226702277022870229702307023170232702337023470235702367023770238702397024070241702427024370244702457024670247702487024970250702517025270253702547025570256702577025870259702607026170262702637026470265702667026770268702697027070271702727027370274702757027670277702787027970280702817028270283702847028570286702877028870289702907029170292702937029470295702967029770298702997030070301703027030370304703057030670307703087030970310703117031270313703147031570316703177031870319703207032170322703237032470325703267032770328703297033070331703327033370334703357033670337703387033970340703417034270343703447034570346703477034870349703507035170352703537035470355703567035770358703597036070361703627036370364703657036670367703687036970370703717037270373703747037570376703777037870379703807038170382703837038470385703867038770388703897039070391703927039370394703957039670397703987039970400704017040270403704047040570406704077040870409704107041170412704137041470415704167041770418704197042070421704227042370424704257042670427704287042970430704317043270433704347043570436704377043870439704407044170442704437044470445704467044770448704497045070451704527045370454704557045670457704587045970460704617046270463704647046570466704677046870469704707047170472704737047470475704767047770478704797048070481704827048370484704857048670487704887048970490704917049270493704947049570496704977049870499705007050170502705037050470505705067050770508705097051070511705127051370514705157051670517705187051970520705217052270523705247052570526705277052870529705307053170532705337053470535705367053770538705397054070541705427054370544705457054670547705487054970550705517055270553705547055570556705577055870559705607056170562705637056470565705667056770568705697057070571705727057370574705757057670577705787057970580705817058270583705847058570586705877058870589705907059170592705937059470595705967059770598705997060070601706027060370604706057060670607706087060970610706117061270613706147061570616706177061870619706207062170622706237062470625706267062770628706297063070631706327063370634706357063670637706387063970640706417064270643706447064570646706477064870649706507065170652706537065470655706567065770658706597066070661706627066370664706657066670667706687066970670706717067270673706747067570676706777067870679706807068170682706837068470685706867068770688706897069070691706927069370694706957069670697706987069970700707017070270703707047070570706707077070870709707107071170712707137071470715707167071770718707197072070721707227072370724707257072670727707287072970730707317073270733707347073570736707377073870739707407074170742707437074470745707467074770748707497075070751707527075370754707557075670757707587075970760707617076270763707647076570766707677076870769707707077170772707737077470775707767077770778707797078070781707827078370784707857078670787707887078970790707917079270793707947079570796707977079870799708007080170802708037080470805708067080770808708097081070811708127081370814708157081670817708187081970820708217082270823708247082570826708277082870829708307083170832708337083470835708367083770838708397084070841708427084370844708457084670847708487084970850708517085270853708547085570856708577085870859708607086170862708637086470865708667086770868708697087070871708727087370874708757087670877708787087970880708817088270883708847088570886708877088870889708907089170892708937089470895708967089770898708997090070901709027090370904709057090670907709087090970910709117091270913709147091570916709177091870919709207092170922709237092470925709267092770928709297093070931709327093370934709357093670937709387093970940709417094270943709447094570946709477094870949709507095170952709537095470955709567095770958709597096070961709627096370964709657096670967709687096970970709717097270973709747097570976709777097870979709807098170982709837098470985709867098770988709897099070991709927099370994709957099670997709987099971000710017100271003710047100571006710077100871009710107101171012710137101471015710167101771018710197102071021710227102371024710257102671027710287102971030710317103271033710347103571036710377103871039710407104171042710437104471045710467104771048710497105071051710527105371054710557105671057710587105971060710617106271063710647106571066710677106871069710707107171072710737107471075710767107771078710797108071081710827108371084710857108671087710887108971090710917109271093710947109571096710977109871099711007110171102711037110471105711067110771108711097111071111711127111371114711157111671117711187111971120711217112271123711247112571126711277112871129711307113171132711337113471135711367113771138711397114071141711427114371144711457114671147711487114971150711517115271153711547115571156711577115871159711607116171162711637116471165711667116771168711697117071171711727117371174711757117671177711787117971180711817118271183711847118571186711877118871189711907119171192711937119471195711967119771198711997120071201712027120371204712057120671207712087120971210712117121271213712147121571216712177121871219712207122171222712237122471225712267122771228712297123071231712327123371234712357123671237712387123971240712417124271243712447124571246712477124871249712507125171252712537125471255712567125771258712597126071261712627126371264712657126671267712687126971270712717127271273712747127571276712777127871279712807128171282712837128471285712867128771288712897129071291712927129371294712957129671297712987129971300713017130271303713047130571306713077130871309713107131171312713137131471315713167131771318713197132071321713227132371324713257132671327713287132971330713317133271333713347133571336713377133871339713407134171342713437134471345713467134771348713497135071351713527135371354713557135671357713587135971360713617136271363713647136571366713677136871369713707137171372713737137471375713767137771378713797138071381713827138371384713857138671387713887138971390713917139271393713947139571396713977139871399714007140171402714037140471405714067140771408714097141071411714127141371414714157141671417714187141971420714217142271423714247142571426714277142871429714307143171432714337143471435714367143771438714397144071441714427144371444714457144671447714487144971450714517145271453714547145571456714577145871459714607146171462714637146471465714667146771468714697147071471714727147371474714757147671477714787147971480714817148271483714847148571486714877148871489714907149171492714937149471495714967149771498714997150071501715027150371504715057150671507715087150971510715117151271513715147151571516715177151871519715207152171522715237152471525715267152771528715297153071531715327153371534715357153671537715387153971540715417154271543715447154571546715477154871549715507155171552715537155471555715567155771558715597156071561715627156371564715657156671567715687156971570715717157271573715747157571576715777157871579715807158171582715837158471585715867158771588715897159071591715927159371594715957159671597715987159971600716017160271603716047160571606716077160871609716107161171612716137161471615716167161771618716197162071621716227162371624716257162671627716287162971630716317163271633716347163571636716377163871639716407164171642716437164471645716467164771648716497165071651716527165371654716557165671657716587165971660716617166271663716647166571666716677166871669716707167171672716737167471675716767167771678716797168071681716827168371684716857168671687716887168971690716917169271693716947169571696716977169871699717007170171702717037170471705717067170771708717097171071711717127171371714717157171671717717187171971720717217172271723717247172571726717277172871729717307173171732717337173471735717367173771738717397174071741717427174371744717457174671747717487174971750717517175271753717547175571756717577175871759717607176171762717637176471765717667176771768717697177071771717727177371774717757177671777717787177971780717817178271783717847178571786717877178871789717907179171792717937179471795717967179771798717997180071801718027180371804718057180671807718087180971810718117181271813718147181571816718177181871819718207182171822718237182471825718267182771828718297183071831718327183371834718357183671837718387183971840718417184271843718447184571846718477184871849718507185171852718537185471855718567185771858718597186071861718627186371864718657186671867718687186971870718717187271873718747187571876718777187871879718807188171882718837188471885718867188771888718897189071891718927189371894718957189671897718987189971900719017190271903719047190571906719077190871909719107191171912719137191471915719167191771918719197192071921719227192371924719257192671927719287192971930719317193271933719347193571936719377193871939719407194171942719437194471945719467194771948719497195071951719527195371954719557195671957719587195971960719617196271963719647196571966719677196871969719707197171972719737197471975719767197771978719797198071981719827198371984719857198671987719887198971990719917199271993719947199571996719977199871999720007200172002720037200472005720067200772008720097201072011720127201372014720157201672017720187201972020720217202272023720247202572026720277202872029720307203172032720337203472035720367203772038720397204072041720427204372044720457204672047720487204972050720517205272053720547205572056720577205872059720607206172062720637206472065720667206772068720697207072071720727207372074720757207672077720787207972080720817208272083720847208572086720877208872089720907209172092720937209472095720967209772098720997210072101721027210372104721057210672107721087210972110721117211272113721147211572116721177211872119721207212172122721237212472125721267212772128721297213072131721327213372134721357213672137721387213972140721417214272143721447214572146721477214872149721507215172152721537215472155721567215772158721597216072161721627216372164721657216672167721687216972170721717217272173721747217572176721777217872179721807218172182721837218472185721867218772188721897219072191721927219372194721957219672197721987219972200722017220272203722047220572206722077220872209722107221172212722137221472215722167221772218722197222072221722227222372224722257222672227722287222972230722317223272233722347223572236722377223872239722407224172242722437224472245722467224772248722497225072251722527225372254722557225672257722587225972260722617226272263722647226572266722677226872269722707227172272722737227472275722767227772278722797228072281722827228372284722857228672287722887228972290722917229272293722947229572296722977229872299723007230172302723037230472305723067230772308723097231072311723127231372314723157231672317723187231972320723217232272323723247232572326723277232872329723307233172332723337233472335723367233772338723397234072341723427234372344723457234672347723487234972350723517235272353723547235572356723577235872359723607236172362723637236472365723667236772368723697237072371723727237372374723757237672377723787237972380723817238272383723847238572386723877238872389723907239172392723937239472395723967239772398723997240072401724027240372404724057240672407724087240972410724117241272413724147241572416724177241872419724207242172422724237242472425724267242772428724297243072431724327243372434724357243672437724387243972440724417244272443724447244572446724477244872449724507245172452724537245472455724567245772458724597246072461724627246372464724657246672467724687246972470724717247272473724747247572476724777247872479724807248172482724837248472485724867248772488724897249072491724927249372494724957249672497724987249972500725017250272503725047250572506725077250872509725107251172512725137251472515725167251772518725197252072521725227252372524725257252672527725287252972530725317253272533725347253572536725377253872539725407254172542725437254472545725467254772548725497255072551725527255372554725557255672557725587255972560725617256272563725647256572566725677256872569725707257172572725737257472575725767257772578725797258072581725827258372584725857258672587725887258972590725917259272593725947259572596725977259872599726007260172602726037260472605726067260772608726097261072611726127261372614726157261672617726187261972620726217262272623726247262572626726277262872629726307263172632726337263472635726367263772638726397264072641726427264372644726457264672647726487264972650726517265272653726547265572656726577265872659726607266172662726637266472665726667266772668726697267072671726727267372674726757267672677726787267972680726817268272683726847268572686726877268872689726907269172692726937269472695726967269772698726997270072701727027270372704727057270672707727087270972710727117271272713727147271572716727177271872719727207272172722727237272472725727267272772728727297273072731727327273372734727357273672737727387273972740727417274272743727447274572746727477274872749727507275172752727537275472755727567275772758727597276072761727627276372764727657276672767727687276972770727717277272773727747277572776727777277872779727807278172782727837278472785727867278772788727897279072791727927279372794727957279672797727987279972800728017280272803728047280572806728077280872809728107281172812728137281472815728167281772818728197282072821728227282372824728257282672827728287282972830728317283272833728347283572836728377283872839728407284172842728437284472845728467284772848728497285072851728527285372854728557285672857728587285972860728617286272863728647286572866728677286872869728707287172872728737287472875728767287772878728797288072881728827288372884728857288672887728887288972890728917289272893728947289572896728977289872899729007290172902729037290472905729067290772908729097291072911729127291372914729157291672917729187291972920729217292272923729247292572926729277292872929729307293172932729337293472935729367293772938729397294072941729427294372944729457294672947729487294972950729517295272953729547295572956729577295872959729607296172962729637296472965729667296772968729697297072971729727297372974729757297672977729787297972980729817298272983729847298572986729877298872989729907299172992729937299472995729967299772998729997300073001730027300373004730057300673007730087300973010730117301273013730147301573016730177301873019730207302173022730237302473025730267302773028730297303073031730327303373034730357303673037730387303973040730417304273043730447304573046730477304873049730507305173052730537305473055730567305773058730597306073061730627306373064730657306673067730687306973070730717307273073730747307573076730777307873079730807308173082730837308473085730867308773088730897309073091730927309373094730957309673097730987309973100731017310273103731047310573106731077310873109731107311173112731137311473115731167311773118731197312073121731227312373124731257312673127731287312973130731317313273133731347313573136731377313873139731407314173142731437314473145731467314773148731497315073151731527315373154731557315673157731587315973160731617316273163731647316573166731677316873169731707317173172731737317473175731767317773178731797318073181731827318373184731857318673187731887318973190731917319273193731947319573196731977319873199732007320173202732037320473205732067320773208732097321073211732127321373214732157321673217732187321973220732217322273223732247322573226732277322873229732307323173232732337323473235732367323773238732397324073241732427324373244732457324673247732487324973250732517325273253732547325573256732577325873259732607326173262732637326473265732667326773268732697327073271732727327373274732757327673277732787327973280732817328273283732847328573286732877328873289732907329173292732937329473295732967329773298732997330073301733027330373304733057330673307733087330973310733117331273313733147331573316733177331873319733207332173322733237332473325733267332773328733297333073331733327333373334733357333673337733387333973340733417334273343733447334573346733477334873349733507335173352733537335473355733567335773358733597336073361733627336373364733657336673367733687336973370733717337273373733747337573376733777337873379733807338173382733837338473385733867338773388733897339073391733927339373394733957339673397733987339973400734017340273403734047340573406734077340873409734107341173412734137341473415734167341773418734197342073421734227342373424734257342673427734287342973430734317343273433734347343573436734377343873439734407344173442734437344473445734467344773448734497345073451734527345373454734557345673457734587345973460734617346273463734647346573466734677346873469734707347173472734737347473475734767347773478734797348073481734827348373484734857348673487734887348973490734917349273493734947349573496734977349873499735007350173502735037350473505735067350773508735097351073511735127351373514735157351673517735187351973520735217352273523735247352573526735277352873529735307353173532735337353473535735367353773538735397354073541735427354373544735457354673547735487354973550735517355273553735547355573556735577355873559735607356173562735637356473565735667356773568735697357073571735727357373574735757357673577735787357973580735817358273583735847358573586735877358873589735907359173592735937359473595735967359773598735997360073601736027360373604736057360673607736087360973610736117361273613736147361573616736177361873619736207362173622736237362473625736267362773628736297363073631736327363373634736357363673637736387363973640736417364273643736447364573646736477364873649736507365173652736537365473655736567365773658736597366073661736627366373664736657366673667736687366973670736717367273673736747367573676736777367873679736807368173682736837368473685736867368773688736897369073691736927369373694736957369673697736987369973700737017370273703737047370573706737077370873709737107371173712737137371473715737167371773718737197372073721737227372373724737257372673727737287372973730737317373273733737347373573736737377373873739737407374173742737437374473745737467374773748737497375073751737527375373754737557375673757737587375973760737617376273763737647376573766737677376873769737707377173772737737377473775737767377773778737797378073781737827378373784737857378673787737887378973790737917379273793737947379573796737977379873799738007380173802738037380473805738067380773808738097381073811738127381373814738157381673817738187381973820738217382273823738247382573826738277382873829738307383173832738337383473835738367383773838738397384073841738427384373844738457384673847738487384973850738517385273853738547385573856738577385873859738607386173862738637386473865738667386773868738697387073871738727387373874738757387673877738787387973880738817388273883738847388573886738877388873889738907389173892738937389473895738967389773898738997390073901739027390373904739057390673907739087390973910739117391273913739147391573916739177391873919739207392173922739237392473925739267392773928739297393073931739327393373934739357393673937739387393973940739417394273943739447394573946739477394873949739507395173952739537395473955739567395773958739597396073961739627396373964739657396673967739687396973970739717397273973739747397573976739777397873979739807398173982739837398473985739867398773988739897399073991739927399373994739957399673997739987399974000740017400274003740047400574006740077400874009740107401174012740137401474015740167401774018740197402074021740227402374024740257402674027740287402974030740317403274033740347403574036740377403874039740407404174042740437404474045740467404774048740497405074051740527405374054740557405674057740587405974060740617406274063740647406574066740677406874069740707407174072740737407474075740767407774078740797408074081740827408374084740857408674087740887408974090740917409274093740947409574096740977409874099741007410174102741037410474105741067410774108741097411074111741127411374114741157411674117741187411974120741217412274123741247412574126741277412874129741307413174132741337413474135741367413774138741397414074141741427414374144741457414674147741487414974150741517415274153741547415574156741577415874159741607416174162741637416474165741667416774168741697417074171741727417374174741757417674177741787417974180741817418274183741847418574186741877418874189741907419174192741937419474195741967419774198741997420074201742027420374204742057420674207742087420974210742117421274213742147421574216742177421874219742207422174222742237422474225742267422774228742297423074231742327423374234742357423674237742387423974240742417424274243742447424574246742477424874249742507425174252742537425474255742567425774258742597426074261742627426374264742657426674267742687426974270742717427274273742747427574276742777427874279742807428174282742837428474285742867428774288742897429074291742927429374294742957429674297742987429974300743017430274303743047430574306743077430874309743107431174312743137431474315743167431774318743197432074321743227432374324743257432674327743287432974330743317433274333743347433574336743377433874339743407434174342743437434474345743467434774348743497435074351743527435374354743557435674357743587435974360743617436274363743647436574366743677436874369743707437174372743737437474375743767437774378743797438074381743827438374384743857438674387743887438974390743917439274393743947439574396743977439874399744007440174402744037440474405744067440774408744097441074411744127441374414744157441674417744187441974420744217442274423744247442574426744277442874429744307443174432744337443474435744367443774438744397444074441744427444374444744457444674447744487444974450744517445274453744547445574456744577445874459744607446174462744637446474465744667446774468744697447074471744727447374474744757447674477744787447974480744817448274483744847448574486744877448874489744907449174492744937449474495744967449774498744997450074501745027450374504745057450674507745087450974510745117451274513745147451574516745177451874519745207452174522745237452474525745267452774528745297453074531745327453374534745357453674537745387453974540745417454274543745447454574546745477454874549745507455174552745537455474555745567455774558745597456074561745627456374564745657456674567745687456974570745717457274573745747457574576745777457874579745807458174582745837458474585745867458774588745897459074591745927459374594745957459674597745987459974600746017460274603746047460574606746077460874609746107461174612746137461474615746167461774618746197462074621746227462374624746257462674627746287462974630746317463274633746347463574636746377463874639746407464174642746437464474645746467464774648746497465074651746527465374654746557465674657746587465974660746617466274663746647466574666746677466874669746707467174672746737467474675746767467774678746797468074681746827468374684746857468674687746887468974690746917469274693746947469574696746977469874699747007470174702747037470474705747067470774708747097471074711747127471374714747157471674717747187471974720747217472274723747247472574726747277472874729747307473174732747337473474735747367473774738747397474074741747427474374744747457474674747747487474974750747517475274753747547475574756747577475874759747607476174762747637476474765747667476774768747697477074771747727477374774747757477674777747787477974780747817478274783747847478574786747877478874789747907479174792747937479474795747967479774798747997480074801748027480374804748057480674807748087480974810748117481274813748147481574816748177481874819748207482174822748237482474825748267482774828748297483074831748327483374834748357483674837748387483974840748417484274843748447484574846748477484874849748507485174852748537485474855748567485774858748597486074861748627486374864748657486674867748687486974870748717487274873748747487574876748777487874879748807488174882748837488474885748867488774888748897489074891748927489374894748957489674897748987489974900749017490274903749047490574906749077490874909749107491174912749137491474915749167491774918749197492074921749227492374924749257492674927749287492974930749317493274933749347493574936749377493874939749407494174942749437494474945749467494774948749497495074951749527495374954749557495674957749587495974960749617496274963749647496574966749677496874969749707497174972749737497474975749767497774978749797498074981749827498374984749857498674987749887498974990749917499274993749947499574996749977499874999750007500175002750037500475005750067500775008750097501075011750127501375014750157501675017750187501975020750217502275023750247502575026750277502875029750307503175032750337503475035750367503775038750397504075041750427504375044750457504675047750487504975050750517505275053750547505575056750577505875059750607506175062750637506475065750667506775068750697507075071750727507375074750757507675077750787507975080750817508275083750847508575086750877508875089750907509175092750937509475095750967509775098750997510075101751027510375104751057510675107751087510975110751117511275113751147511575116751177511875119751207512175122751237512475125751267512775128751297513075131751327513375134751357513675137751387513975140751417514275143751447514575146751477514875149751507515175152751537515475155751567515775158751597516075161751627516375164751657516675167751687516975170751717517275173751747517575176751777517875179751807518175182751837518475185751867518775188751897519075191751927519375194751957519675197751987519975200752017520275203752047520575206752077520875209752107521175212752137521475215752167521775218752197522075221752227522375224752257522675227752287522975230752317523275233752347523575236752377523875239752407524175242752437524475245752467524775248752497525075251752527525375254752557525675257752587525975260752617526275263752647526575266752677526875269752707527175272752737527475275752767527775278752797528075281752827528375284752857528675287752887528975290752917529275293752947529575296752977529875299753007530175302753037530475305753067530775308753097531075311753127531375314753157531675317753187531975320753217532275323753247532575326753277532875329753307533175332753337533475335753367533775338753397534075341753427534375344753457534675347753487534975350753517535275353753547535575356753577535875359753607536175362753637536475365753667536775368753697537075371753727537375374753757537675377753787537975380753817538275383753847538575386753877538875389753907539175392753937539475395753967539775398753997540075401754027540375404754057540675407754087540975410754117541275413754147541575416754177541875419754207542175422754237542475425754267542775428754297543075431754327543375434754357543675437754387543975440754417544275443754447544575446754477544875449754507545175452754537545475455754567545775458754597546075461754627546375464754657546675467754687546975470754717547275473754747547575476754777547875479754807548175482754837548475485754867548775488754897549075491754927549375494754957549675497754987549975500755017550275503755047550575506755077550875509755107551175512755137551475515755167551775518755197552075521755227552375524755257552675527755287552975530755317553275533755347553575536755377553875539755407554175542755437554475545755467554775548755497555075551755527555375554755557555675557755587555975560755617556275563755647556575566755677556875569755707557175572755737557475575755767557775578755797558075581755827558375584755857558675587755887558975590755917559275593755947559575596755977559875599756007560175602756037560475605756067560775608756097561075611756127561375614756157561675617756187561975620756217562275623756247562575626756277562875629756307563175632756337563475635756367563775638756397564075641756427564375644756457564675647756487564975650756517565275653756547565575656756577565875659756607566175662756637566475665756667566775668756697567075671756727567375674756757567675677756787567975680756817568275683756847568575686756877568875689756907569175692756937569475695756967569775698756997570075701757027570375704757057570675707757087570975710757117571275713757147571575716757177571875719757207572175722757237572475725757267572775728757297573075731757327573375734757357573675737757387573975740757417574275743757447574575746757477574875749757507575175752757537575475755757567575775758757597576075761757627576375764757657576675767757687576975770757717577275773757747577575776757777577875779757807578175782757837578475785757867578775788757897579075791757927579375794757957579675797757987579975800758017580275803758047580575806758077580875809758107581175812758137581475815758167581775818758197582075821758227582375824758257582675827758287582975830758317583275833758347583575836758377583875839758407584175842758437584475845758467584775848758497585075851758527585375854758557585675857758587585975860758617586275863758647586575866758677586875869758707587175872758737587475875758767587775878758797588075881758827588375884758857588675887758887588975890758917589275893758947589575896758977589875899759007590175902759037590475905759067590775908759097591075911759127591375914759157591675917759187591975920759217592275923759247592575926759277592875929759307593175932759337593475935759367593775938759397594075941759427594375944759457594675947759487594975950759517595275953759547595575956759577595875959759607596175962759637596475965759667596775968759697597075971759727597375974759757597675977759787597975980759817598275983759847598575986759877598875989759907599175992759937599475995759967599775998759997600076001760027600376004760057600676007760087600976010760117601276013760147601576016760177601876019760207602176022760237602476025760267602776028760297603076031760327603376034760357603676037760387603976040760417604276043760447604576046760477604876049760507605176052760537605476055760567605776058760597606076061760627606376064760657606676067760687606976070760717607276073760747607576076760777607876079760807608176082760837608476085760867608776088760897609076091760927609376094760957609676097760987609976100761017610276103761047610576106761077610876109761107611176112761137611476115761167611776118761197612076121761227612376124761257612676127761287612976130761317613276133761347613576136761377613876139761407614176142761437614476145761467614776148761497615076151761527615376154761557615676157761587615976160761617616276163761647616576166761677616876169761707617176172761737617476175761767617776178761797618076181761827618376184761857618676187761887618976190761917619276193761947619576196761977619876199762007620176202762037620476205762067620776208762097621076211762127621376214762157621676217762187621976220762217622276223762247622576226762277622876229762307623176232762337623476235762367623776238762397624076241762427624376244762457624676247762487624976250762517625276253762547625576256762577625876259762607626176262762637626476265762667626776268762697627076271762727627376274762757627676277762787627976280762817628276283762847628576286762877628876289762907629176292762937629476295762967629776298762997630076301763027630376304763057630676307763087630976310763117631276313763147631576316763177631876319763207632176322763237632476325763267632776328763297633076331763327633376334763357633676337763387633976340763417634276343763447634576346763477634876349763507635176352763537635476355763567635776358763597636076361763627636376364763657636676367763687636976370763717637276373763747637576376763777637876379763807638176382763837638476385763867638776388763897639076391763927639376394763957639676397763987639976400764017640276403764047640576406764077640876409764107641176412764137641476415764167641776418764197642076421764227642376424764257642676427764287642976430764317643276433764347643576436764377643876439764407644176442764437644476445764467644776448764497645076451764527645376454764557645676457764587645976460764617646276463764647646576466764677646876469764707647176472764737647476475764767647776478764797648076481764827648376484764857648676487764887648976490764917649276493764947649576496764977649876499765007650176502765037650476505765067650776508765097651076511765127651376514765157651676517765187651976520765217652276523765247652576526765277652876529765307653176532765337653476535765367653776538765397654076541765427654376544765457654676547765487654976550765517655276553765547655576556765577655876559765607656176562765637656476565765667656776568765697657076571765727657376574765757657676577765787657976580765817658276583765847658576586765877658876589765907659176592765937659476595765967659776598765997660076601766027660376604766057660676607766087660976610766117661276613766147661576616766177661876619766207662176622766237662476625766267662776628766297663076631766327663376634766357663676637766387663976640766417664276643766447664576646766477664876649766507665176652766537665476655766567665776658766597666076661766627666376664766657666676667766687666976670766717667276673766747667576676766777667876679766807668176682766837668476685766867668776688766897669076691766927669376694766957669676697766987669976700767017670276703767047670576706767077670876709767107671176712767137671476715767167671776718767197672076721767227672376724767257672676727767287672976730767317673276733767347673576736767377673876739767407674176742767437674476745767467674776748767497675076751767527675376754767557675676757767587675976760767617676276763767647676576766767677676876769767707677176772767737677476775767767677776778767797678076781767827678376784767857678676787767887678976790767917679276793767947679576796767977679876799768007680176802768037680476805768067680776808768097681076811768127681376814768157681676817768187681976820768217682276823768247682576826768277682876829768307683176832768337683476835768367683776838768397684076841768427684376844768457684676847768487684976850768517685276853768547685576856768577685876859768607686176862768637686476865768667686776868768697687076871768727687376874768757687676877768787687976880768817688276883768847688576886768877688876889768907689176892768937689476895768967689776898768997690076901769027690376904769057690676907769087690976910769117691276913769147691576916769177691876919769207692176922769237692476925769267692776928769297693076931769327693376934769357693676937769387693976940769417694276943769447694576946769477694876949769507695176952769537695476955769567695776958769597696076961769627696376964769657696676967769687696976970769717697276973769747697576976769777697876979769807698176982769837698476985769867698776988769897699076991769927699376994769957699676997769987699977000770017700277003770047700577006770077700877009770107701177012770137701477015770167701777018770197702077021770227702377024770257702677027770287702977030770317703277033770347703577036770377703877039770407704177042770437704477045770467704777048770497705077051770527705377054770557705677057770587705977060770617706277063770647706577066770677706877069770707707177072770737707477075770767707777078770797708077081770827708377084770857708677087770887708977090770917709277093770947709577096770977709877099771007710177102771037710477105771067710777108771097711077111771127711377114771157711677117771187711977120771217712277123771247712577126771277712877129771307713177132771337713477135771367713777138771397714077141771427714377144771457714677147771487714977150771517715277153771547715577156771577715877159771607716177162771637716477165771667716777168771697717077171771727717377174771757717677177771787717977180771817718277183771847718577186771877718877189771907719177192771937719477195771967719777198771997720077201772027720377204772057720677207772087720977210772117721277213772147721577216772177721877219772207722177222772237722477225772267722777228772297723077231772327723377234772357723677237772387723977240772417724277243772447724577246772477724877249772507725177252772537725477255772567725777258772597726077261772627726377264772657726677267772687726977270772717727277273772747727577276772777727877279772807728177282772837728477285772867728777288772897729077291772927729377294772957729677297772987729977300773017730277303773047730577306773077730877309773107731177312773137731477315773167731777318773197732077321773227732377324773257732677327773287732977330773317733277333773347733577336773377733877339773407734177342773437734477345773467734777348773497735077351773527735377354773557735677357773587735977360773617736277363773647736577366773677736877369773707737177372773737737477375773767737777378773797738077381773827738377384773857738677387773887738977390773917739277393773947739577396773977739877399774007740177402774037740477405774067740777408774097741077411774127741377414774157741677417774187741977420774217742277423774247742577426774277742877429774307743177432774337743477435774367743777438774397744077441774427744377444774457744677447774487744977450774517745277453774547745577456774577745877459774607746177462774637746477465774667746777468774697747077471774727747377474774757747677477774787747977480774817748277483774847748577486774877748877489774907749177492774937749477495774967749777498774997750077501775027750377504775057750677507775087750977510775117751277513775147751577516775177751877519775207752177522775237752477525775267752777528775297753077531775327753377534775357753677537775387753977540775417754277543775447754577546775477754877549775507755177552775537755477555775567755777558775597756077561775627756377564775657756677567775687756977570775717757277573775747757577576775777757877579775807758177582775837758477585775867758777588775897759077591775927759377594775957759677597775987759977600776017760277603776047760577606776077760877609776107761177612776137761477615776167761777618776197762077621776227762377624776257762677627776287762977630776317763277633776347763577636776377763877639776407764177642776437764477645776467764777648776497765077651776527765377654776557765677657776587765977660776617766277663776647766577666776677766877669776707767177672776737767477675776767767777678776797768077681776827768377684776857768677687776887768977690776917769277693776947769577696776977769877699777007770177702777037770477705777067770777708777097771077711777127771377714777157771677717777187771977720777217772277723777247772577726777277772877729777307773177732777337773477735777367773777738777397774077741777427774377744777457774677747777487774977750777517775277753777547775577756777577775877759777607776177762777637776477765777667776777768777697777077771777727777377774777757777677777777787777977780777817778277783777847778577786777877778877789777907779177792777937779477795777967779777798777997780077801778027780377804778057780677807778087780977810778117781277813778147781577816778177781877819778207782177822778237782477825778267782777828778297783077831778327783377834778357783677837778387783977840778417784277843778447784577846778477784877849778507785177852778537785477855778567785777858778597786077861778627786377864778657786677867778687786977870778717787277873778747787577876778777787877879778807788177882778837788477885778867788777888778897789077891778927789377894778957789677897778987789977900779017790277903779047790577906779077790877909779107791177912779137791477915779167791777918779197792077921779227792377924779257792677927779287792977930779317793277933779347793577936779377793877939779407794177942779437794477945779467794777948779497795077951779527795377954779557795677957779587795977960779617796277963779647796577966779677796877969779707797177972779737797477975779767797777978779797798077981779827798377984779857798677987779887798977990779917799277993779947799577996779977799877999780007800178002780037800478005780067800778008780097801078011780127801378014780157801678017780187801978020780217802278023780247802578026780277802878029780307803178032780337803478035780367803778038780397804078041780427804378044780457804678047780487804978050780517805278053780547805578056780577805878059780607806178062780637806478065780667806778068780697807078071780727807378074780757807678077780787807978080780817808278083780847808578086780877808878089780907809178092780937809478095780967809778098780997810078101781027810378104781057810678107781087810978110781117811278113781147811578116781177811878119781207812178122781237812478125781267812778128781297813078131781327813378134781357813678137781387813978140781417814278143781447814578146781477814878149781507815178152781537815478155781567815778158781597816078161781627816378164781657816678167781687816978170781717817278173781747817578176781777817878179781807818178182781837818478185781867818778188781897819078191781927819378194781957819678197781987819978200782017820278203782047820578206782077820878209782107821178212782137821478215782167821778218782197822078221782227822378224782257822678227782287822978230782317823278233782347823578236782377823878239782407824178242782437824478245782467824778248782497825078251782527825378254782557825678257782587825978260782617826278263782647826578266782677826878269782707827178272782737827478275782767827778278782797828078281782827828378284782857828678287782887828978290782917829278293782947829578296782977829878299783007830178302783037830478305783067830778308783097831078311783127831378314783157831678317783187831978320783217832278323783247832578326783277832878329783307833178332783337833478335783367833778338783397834078341783427834378344783457834678347783487834978350783517835278353783547835578356783577835878359783607836178362783637836478365783667836778368783697837078371783727837378374783757837678377783787837978380783817838278383783847838578386783877838878389783907839178392783937839478395783967839778398783997840078401784027840378404784057840678407784087840978410784117841278413784147841578416784177841878419784207842178422784237842478425784267842778428784297843078431784327843378434784357843678437784387843978440784417844278443784447844578446784477844878449784507845178452784537845478455784567845778458784597846078461784627846378464784657846678467784687846978470784717847278473784747847578476784777847878479784807848178482784837848478485784867848778488784897849078491784927849378494784957849678497784987849978500785017850278503785047850578506785077850878509785107851178512785137851478515785167851778518785197852078521785227852378524785257852678527785287852978530785317853278533785347853578536785377853878539785407854178542785437854478545785467854778548785497855078551785527855378554785557855678557785587855978560785617856278563785647856578566785677856878569785707857178572785737857478575785767857778578785797858078581785827858378584785857858678587785887858978590785917859278593785947859578596785977859878599786007860178602786037860478605786067860778608786097861078611786127861378614786157861678617786187861978620786217862278623786247862578626786277862878629786307863178632786337863478635786367863778638786397864078641786427864378644786457864678647786487864978650786517865278653786547865578656786577865878659786607866178662786637866478665786667866778668786697867078671786727867378674786757867678677786787867978680786817868278683786847868578686786877868878689786907869178692786937869478695786967869778698786997870078701787027870378704787057870678707787087870978710787117871278713787147871578716787177871878719787207872178722787237872478725787267872778728787297873078731787327873378734787357873678737787387873978740787417874278743787447874578746787477874878749787507875178752787537875478755787567875778758787597876078761787627876378764787657876678767787687876978770787717877278773787747877578776787777877878779787807878178782787837878478785787867878778788787897879078791787927879378794787957879678797787987879978800788017880278803788047880578806788077880878809788107881178812788137881478815788167881778818788197882078821788227882378824788257882678827788287882978830788317883278833788347883578836788377883878839788407884178842788437884478845788467884778848788497885078851788527885378854788557885678857788587885978860788617886278863788647886578866788677886878869788707887178872788737887478875788767887778878788797888078881788827888378884788857888678887788887888978890788917889278893788947889578896788977889878899789007890178902789037890478905789067890778908789097891078911789127891378914789157891678917789187891978920789217892278923789247892578926789277892878929789307893178932789337893478935789367893778938789397894078941789427894378944789457894678947789487894978950789517895278953789547895578956789577895878959789607896178962789637896478965789667896778968789697897078971789727897378974789757897678977789787897978980789817898278983789847898578986789877898878989789907899178992789937899478995789967899778998789997900079001790027900379004790057900679007790087900979010790117901279013790147901579016790177901879019790207902179022790237902479025790267902779028790297903079031790327903379034790357903679037790387903979040790417904279043790447904579046790477904879049790507905179052790537905479055790567905779058790597906079061790627906379064790657906679067790687906979070790717907279073790747907579076790777907879079790807908179082790837908479085790867908779088790897909079091790927909379094790957909679097790987909979100791017910279103791047910579106791077910879109791107911179112791137911479115791167911779118791197912079121791227912379124791257912679127791287912979130791317913279133791347913579136791377913879139791407914179142791437914479145791467914779148791497915079151791527915379154791557915679157791587915979160791617916279163791647916579166791677916879169791707917179172791737917479175791767917779178791797918079181791827918379184791857918679187791887918979190791917919279193791947919579196791977919879199792007920179202792037920479205792067920779208792097921079211792127921379214792157921679217792187921979220792217922279223792247922579226792277922879229792307923179232792337923479235792367923779238792397924079241792427924379244792457924679247792487924979250792517925279253792547925579256792577925879259792607926179262792637926479265792667926779268792697927079271792727927379274792757927679277792787927979280792817928279283792847928579286792877928879289792907929179292792937929479295792967929779298792997930079301793027930379304793057930679307793087930979310793117931279313793147931579316793177931879319793207932179322793237932479325793267932779328793297933079331793327933379334793357933679337793387933979340793417934279343793447934579346793477934879349793507935179352793537935479355793567935779358793597936079361793627936379364793657936679367793687936979370793717937279373793747937579376793777937879379793807938179382793837938479385793867938779388793897939079391793927939379394793957939679397793987939979400794017940279403794047940579406794077940879409794107941179412794137941479415794167941779418794197942079421794227942379424794257942679427794287942979430794317943279433794347943579436794377943879439794407944179442794437944479445794467944779448794497945079451794527945379454794557945679457794587945979460794617946279463794647946579466794677946879469794707947179472794737947479475794767947779478794797948079481794827948379484794857948679487794887948979490794917949279493794947949579496794977949879499795007950179502795037950479505795067950779508795097951079511795127951379514795157951679517795187951979520795217952279523795247952579526795277952879529795307953179532795337953479535795367953779538795397954079541795427954379544795457954679547795487954979550795517955279553795547955579556795577955879559795607956179562795637956479565795667956779568795697957079571795727957379574795757957679577795787957979580795817958279583795847958579586795877958879589795907959179592795937959479595795967959779598795997960079601796027960379604796057960679607796087960979610796117961279613796147961579616796177961879619796207962179622796237962479625796267962779628796297963079631796327963379634796357963679637796387963979640796417964279643796447964579646796477964879649796507965179652796537965479655796567965779658796597966079661796627966379664796657966679667796687966979670796717967279673796747967579676796777967879679796807968179682796837968479685796867968779688796897969079691796927969379694796957969679697796987969979700797017970279703797047970579706797077970879709797107971179712797137971479715797167971779718797197972079721797227972379724797257972679727797287972979730797317973279733797347973579736797377973879739797407974179742797437974479745797467974779748797497975079751797527975379754797557975679757797587975979760797617976279763797647976579766797677976879769797707977179772797737977479775797767977779778797797978079781797827978379784797857978679787797887978979790797917979279793797947979579796797977979879799798007980179802798037980479805798067980779808798097981079811798127981379814798157981679817798187981979820798217982279823798247982579826798277982879829798307983179832798337983479835798367983779838798397984079841798427984379844798457984679847798487984979850798517985279853798547985579856798577985879859798607986179862798637986479865798667986779868798697987079871798727987379874798757987679877798787987979880798817988279883798847988579886798877988879889798907989179892798937989479895798967989779898798997990079901799027990379904799057990679907799087990979910799117991279913799147991579916799177991879919799207992179922799237992479925799267992779928799297993079931799327993379934799357993679937799387993979940799417994279943799447994579946799477994879949799507995179952799537995479955799567995779958799597996079961799627996379964799657996679967799687996979970799717997279973799747997579976799777997879979799807998179982799837998479985799867998779988799897999079991799927999379994799957999679997799987999980000800018000280003800048000580006800078000880009800108001180012800138001480015800168001780018800198002080021800228002380024800258002680027800288002980030800318003280033800348003580036800378003880039800408004180042800438004480045800468004780048800498005080051800528005380054800558005680057800588005980060800618006280063800648006580066800678006880069800708007180072800738007480075800768007780078800798008080081800828008380084800858008680087800888008980090800918009280093800948009580096800978009880099801008010180102801038010480105801068010780108801098011080111801128011380114801158011680117801188011980120801218012280123801248012580126801278012880129801308013180132801338013480135801368013780138801398014080141801428014380144801458014680147801488014980150801518015280153801548015580156801578015880159801608016180162801638016480165801668016780168801698017080171801728017380174801758017680177801788017980180801818018280183801848018580186801878018880189801908019180192801938019480195801968019780198801998020080201802028020380204802058020680207802088020980210802118021280213802148021580216802178021880219802208022180222802238022480225802268022780228802298023080231802328023380234802358023680237802388023980240802418024280243802448024580246802478024880249802508025180252802538025480255802568025780258802598026080261802628026380264802658026680267802688026980270802718027280273802748027580276802778027880279802808028180282802838028480285802868028780288802898029080291802928029380294802958029680297802988029980300803018030280303803048030580306803078030880309803108031180312803138031480315803168031780318803198032080321803228032380324803258032680327803288032980330803318033280333803348033580336803378033880339803408034180342803438034480345803468034780348803498035080351803528035380354803558035680357803588035980360803618036280363803648036580366803678036880369803708037180372803738037480375803768037780378803798038080381803828038380384803858038680387803888038980390803918039280393803948039580396803978039880399804008040180402804038040480405804068040780408804098041080411804128041380414804158041680417804188041980420804218042280423804248042580426804278042880429804308043180432804338043480435804368043780438804398044080441804428044380444804458044680447804488044980450804518045280453804548045580456804578045880459804608046180462804638046480465804668046780468804698047080471804728047380474804758047680477804788047980480804818048280483804848048580486804878048880489804908049180492804938049480495804968049780498804998050080501805028050380504805058050680507805088050980510805118051280513805148051580516805178051880519805208052180522805238052480525805268052780528805298053080531805328053380534805358053680537805388053980540805418054280543805448054580546805478054880549805508055180552805538055480555805568055780558805598056080561805628056380564805658056680567805688056980570805718057280573805748057580576805778057880579805808058180582805838058480585805868058780588805898059080591805928059380594805958059680597805988059980600806018060280603806048060580606806078060880609806108061180612806138061480615806168061780618806198062080621806228062380624806258062680627806288062980630806318063280633806348063580636806378063880639806408064180642806438064480645806468064780648806498065080651806528065380654806558065680657806588065980660806618066280663806648066580666806678066880669806708067180672806738067480675806768067780678806798068080681806828068380684806858068680687806888068980690806918069280693806948069580696806978069880699807008070180702807038070480705807068070780708807098071080711807128071380714807158071680717807188071980720807218072280723807248072580726807278072880729807308073180732807338073480735807368073780738807398074080741807428074380744807458074680747807488074980750807518075280753807548075580756807578075880759807608076180762807638076480765807668076780768807698077080771807728077380774807758077680777807788077980780807818078280783807848078580786807878078880789807908079180792807938079480795807968079780798807998080080801808028080380804808058080680807808088080980810808118081280813808148081580816808178081880819808208082180822808238082480825808268082780828808298083080831808328083380834808358083680837808388083980840808418084280843808448084580846808478084880849808508085180852808538085480855808568085780858808598086080861808628086380864808658086680867808688086980870808718087280873808748087580876808778087880879808808088180882808838088480885808868088780888808898089080891808928089380894808958089680897808988089980900809018090280903809048090580906809078090880909809108091180912809138091480915809168091780918809198092080921809228092380924809258092680927809288092980930809318093280933809348093580936809378093880939809408094180942809438094480945809468094780948809498095080951809528095380954809558095680957809588095980960809618096280963809648096580966809678096880969809708097180972809738097480975809768097780978809798098080981809828098380984809858098680987809888098980990809918099280993809948099580996809978099880999810008100181002810038100481005810068100781008810098101081011810128101381014810158101681017810188101981020810218102281023810248102581026810278102881029810308103181032810338103481035810368103781038810398104081041810428104381044810458104681047810488104981050810518105281053810548105581056810578105881059810608106181062810638106481065810668106781068810698107081071810728107381074810758107681077810788107981080810818108281083810848108581086810878108881089810908109181092810938109481095810968109781098810998110081101811028110381104811058110681107811088110981110811118111281113811148111581116811178111881119811208112181122811238112481125811268112781128811298113081131811328113381134811358113681137811388113981140811418114281143811448114581146811478114881149811508115181152811538115481155811568115781158811598116081161811628116381164811658116681167811688116981170811718117281173811748117581176811778117881179811808118181182811838118481185811868118781188811898119081191811928119381194811958119681197811988119981200812018120281203812048120581206812078120881209812108121181212812138121481215812168121781218812198122081221812228122381224812258122681227812288122981230812318123281233812348123581236812378123881239812408124181242812438124481245812468124781248812498125081251812528125381254812558125681257812588125981260812618126281263812648126581266812678126881269812708127181272812738127481275812768127781278812798128081281812828128381284812858128681287812888128981290812918129281293812948129581296812978129881299813008130181302813038130481305813068130781308813098131081311813128131381314813158131681317813188131981320813218132281323813248132581326813278132881329813308133181332813338133481335813368133781338813398134081341813428134381344813458134681347813488134981350813518135281353813548135581356813578135881359813608136181362813638136481365813668136781368813698137081371813728137381374813758137681377813788137981380813818138281383813848138581386813878138881389813908139181392813938139481395813968139781398813998140081401814028140381404814058140681407814088140981410814118141281413814148141581416814178141881419814208142181422814238142481425814268142781428814298143081431814328143381434814358143681437814388143981440814418144281443814448144581446814478144881449814508145181452814538145481455814568145781458814598146081461814628146381464814658146681467814688146981470814718147281473814748147581476814778147881479814808148181482814838148481485814868148781488814898149081491814928149381494814958149681497814988149981500815018150281503815048150581506815078150881509815108151181512815138151481515815168151781518815198152081521815228152381524815258152681527815288152981530815318153281533815348153581536815378153881539815408154181542815438154481545815468154781548815498155081551815528155381554815558155681557815588155981560815618156281563815648156581566815678156881569815708157181572815738157481575815768157781578815798158081581815828158381584815858158681587815888158981590815918159281593815948159581596815978159881599816008160181602816038160481605816068160781608816098161081611816128161381614816158161681617816188161981620816218162281623816248162581626816278162881629816308163181632816338163481635816368163781638816398164081641816428164381644816458164681647816488164981650816518165281653816548165581656816578165881659816608166181662816638166481665816668166781668816698167081671816728167381674816758167681677816788167981680816818168281683816848168581686816878168881689816908169181692816938169481695816968169781698816998170081701817028170381704817058170681707817088170981710817118171281713817148171581716817178171881719817208172181722817238172481725817268172781728817298173081731817328173381734817358173681737817388173981740817418174281743817448174581746817478174881749817508175181752817538175481755817568175781758817598176081761817628176381764817658176681767817688176981770817718177281773817748177581776817778177881779817808178181782817838178481785817868178781788817898179081791817928179381794817958179681797817988179981800818018180281803818048180581806818078180881809818108181181812818138181481815818168181781818818198182081821818228182381824818258182681827818288182981830818318183281833818348183581836818378183881839818408184181842818438184481845818468184781848818498185081851818528185381854818558185681857818588185981860818618186281863818648186581866818678186881869818708187181872818738187481875818768187781878818798188081881818828188381884818858188681887818888188981890818918189281893818948189581896818978189881899819008190181902819038190481905819068190781908819098191081911819128191381914819158191681917819188191981920819218192281923819248192581926819278192881929819308193181932819338193481935819368193781938819398194081941819428194381944819458194681947819488194981950819518195281953819548195581956819578195881959819608196181962819638196481965819668196781968819698197081971819728197381974819758197681977819788197981980819818198281983819848198581986819878198881989819908199181992819938199481995819968199781998819998200082001820028200382004820058200682007820088200982010820118201282013820148201582016820178201882019820208202182022820238202482025820268202782028820298203082031820328203382034820358203682037820388203982040820418204282043820448204582046820478204882049820508205182052820538205482055820568205782058820598206082061820628206382064820658206682067820688206982070820718207282073820748207582076820778207882079820808208182082820838208482085820868208782088820898209082091820928209382094820958209682097820988209982100821018210282103821048210582106821078210882109821108211182112821138211482115821168211782118821198212082121821228212382124821258212682127821288212982130821318213282133821348213582136821378213882139821408214182142821438214482145821468214782148821498215082151821528215382154821558215682157821588215982160821618216282163821648216582166821678216882169821708217182172821738217482175821768217782178821798218082181821828218382184821858218682187821888218982190821918219282193821948219582196821978219882199822008220182202822038220482205822068220782208822098221082211822128221382214822158221682217822188221982220822218222282223822248222582226822278222882229822308223182232822338223482235822368223782238822398224082241822428224382244822458224682247822488224982250822518225282253822548225582256822578225882259822608226182262822638226482265822668226782268822698227082271822728227382274822758227682277822788227982280822818228282283822848228582286822878228882289822908229182292822938229482295822968229782298822998230082301823028230382304823058230682307823088230982310823118231282313823148231582316823178231882319823208232182322823238232482325823268232782328823298233082331823328233382334823358233682337823388233982340823418234282343823448234582346823478234882349823508235182352823538235482355823568235782358823598236082361823628236382364823658236682367823688236982370823718237282373823748237582376823778237882379823808238182382823838238482385823868238782388823898239082391823928239382394823958239682397823988239982400824018240282403824048240582406824078240882409824108241182412824138241482415824168241782418824198242082421824228242382424824258242682427824288242982430824318243282433824348243582436824378243882439824408244182442824438244482445824468244782448824498245082451824528245382454824558245682457824588245982460824618246282463824648246582466824678246882469824708247182472824738247482475824768247782478824798248082481824828248382484824858248682487824888248982490824918249282493824948249582496824978249882499825008250182502825038250482505825068250782508825098251082511825128251382514825158251682517825188251982520825218252282523825248252582526825278252882529825308253182532825338253482535825368253782538825398254082541825428254382544825458254682547825488254982550825518255282553825548255582556825578255882559825608256182562825638256482565825668256782568825698257082571825728257382574825758257682577825788257982580825818258282583825848258582586825878258882589825908259182592825938259482595825968259782598825998260082601826028260382604826058260682607826088260982610826118261282613826148261582616826178261882619826208262182622826238262482625826268262782628826298263082631826328263382634826358263682637826388263982640826418264282643826448264582646826478264882649826508265182652826538265482655826568265782658826598266082661826628266382664826658266682667826688266982670826718267282673826748267582676826778267882679826808268182682826838268482685826868268782688826898269082691826928269382694826958269682697826988269982700827018270282703827048270582706827078270882709827108271182712827138271482715827168271782718827198272082721827228272382724827258272682727827288272982730827318273282733827348273582736827378273882739827408274182742827438274482745827468274782748827498275082751827528275382754827558275682757827588275982760827618276282763827648276582766827678276882769827708277182772827738277482775827768277782778827798278082781827828278382784827858278682787827888278982790827918279282793827948279582796827978279882799828008280182802828038280482805828068280782808828098281082811828128281382814828158281682817828188281982820828218282282823828248282582826828278282882829828308283182832828338283482835828368283782838828398284082841828428284382844828458284682847828488284982850828518285282853828548285582856828578285882859828608286182862828638286482865828668286782868828698287082871828728287382874828758287682877828788287982880828818288282883828848288582886828878288882889828908289182892828938289482895828968289782898828998290082901829028290382904829058290682907829088290982910829118291282913829148291582916829178291882919829208292182922829238292482925829268292782928829298293082931829328293382934829358293682937829388293982940829418294282943829448294582946829478294882949829508295182952829538295482955829568295782958829598296082961829628296382964829658296682967829688296982970829718297282973829748297582976829778297882979829808298182982829838298482985829868298782988829898299082991829928299382994829958299682997829988299983000830018300283003830048300583006830078300883009830108301183012830138301483015830168301783018830198302083021830228302383024830258302683027830288302983030830318303283033830348303583036830378303883039830408304183042830438304483045830468304783048830498305083051830528305383054830558305683057830588305983060830618306283063830648306583066830678306883069830708307183072830738307483075830768307783078830798308083081830828308383084830858308683087830888308983090830918309283093830948309583096830978309883099831008310183102831038310483105831068310783108831098311083111831128311383114831158311683117831188311983120831218312283123831248312583126831278312883129831308313183132831338313483135831368313783138831398314083141831428314383144831458314683147831488314983150831518315283153831548315583156831578315883159831608316183162831638316483165831668316783168831698317083171831728317383174831758317683177831788317983180831818318283183831848318583186831878318883189831908319183192831938319483195831968319783198831998320083201832028320383204832058320683207832088320983210832118321283213832148321583216832178321883219832208322183222832238322483225832268322783228832298323083231832328323383234832358323683237832388323983240832418324283243832448324583246832478324883249832508325183252832538325483255832568325783258832598326083261832628326383264832658326683267832688326983270832718327283273832748327583276832778327883279832808328183282832838328483285832868328783288832898329083291832928329383294832958329683297832988329983300833018330283303833048330583306833078330883309833108331183312833138331483315833168331783318833198332083321833228332383324833258332683327833288332983330833318333283333833348333583336833378333883339833408334183342833438334483345833468334783348833498335083351833528335383354833558335683357833588335983360833618336283363833648336583366833678336883369833708337183372833738337483375833768337783378833798338083381833828338383384833858338683387833888338983390833918339283393833948339583396833978339883399834008340183402834038340483405834068340783408834098341083411834128341383414834158341683417834188341983420834218342283423834248342583426834278342883429834308343183432834338343483435834368343783438834398344083441834428344383444834458344683447834488344983450834518345283453834548345583456834578345883459834608346183462834638346483465834668346783468834698347083471834728347383474834758347683477834788347983480834818348283483834848348583486834878348883489834908349183492834938349483495834968349783498834998350083501835028350383504835058350683507835088350983510835118351283513835148351583516835178351883519835208352183522835238352483525835268352783528835298353083531835328353383534835358353683537835388353983540835418354283543835448354583546835478354883549835508355183552835538355483555835568355783558835598356083561835628356383564835658356683567835688356983570835718357283573835748357583576835778357883579835808358183582835838358483585835868358783588835898359083591835928359383594835958359683597835988359983600836018360283603836048360583606836078360883609836108361183612836138361483615836168361783618836198362083621836228362383624836258362683627836288362983630836318363283633836348363583636836378363883639836408364183642836438364483645836468364783648836498365083651836528365383654836558365683657836588365983660836618366283663836648366583666836678366883669836708367183672836738367483675836768367783678836798368083681836828368383684836858368683687836888368983690836918369283693836948369583696836978369883699837008370183702837038370483705837068370783708837098371083711837128371383714837158371683717837188371983720837218372283723837248372583726837278372883729837308373183732837338373483735837368373783738837398374083741837428374383744837458374683747837488374983750837518375283753837548375583756837578375883759837608376183762837638376483765837668376783768837698377083771837728377383774837758377683777837788377983780837818378283783837848378583786837878378883789837908379183792837938379483795837968379783798837998380083801838028380383804838058380683807838088380983810838118381283813838148381583816838178381883819838208382183822838238382483825838268382783828838298383083831838328383383834838358383683837838388383983840838418384283843838448384583846838478384883849838508385183852838538385483855838568385783858838598386083861838628386383864838658386683867838688386983870838718387283873838748387583876838778387883879838808388183882838838388483885838868388783888838898389083891838928389383894838958389683897838988389983900839018390283903839048390583906839078390883909839108391183912839138391483915839168391783918839198392083921839228392383924839258392683927839288392983930839318393283933839348393583936839378393883939839408394183942839438394483945839468394783948839498395083951839528395383954839558395683957839588395983960839618396283963839648396583966839678396883969839708397183972839738397483975839768397783978839798398083981839828398383984839858398683987839888398983990839918399283993839948399583996839978399883999840008400184002840038400484005840068400784008840098401084011840128401384014840158401684017840188401984020840218402284023840248402584026840278402884029840308403184032840338403484035840368403784038840398404084041840428404384044840458404684047840488404984050840518405284053840548405584056840578405884059840608406184062840638406484065840668406784068840698407084071840728407384074840758407684077840788407984080840818408284083840848408584086840878408884089840908409184092840938409484095840968409784098840998410084101841028410384104841058410684107841088410984110841118411284113841148411584116841178411884119841208412184122841238412484125841268412784128841298413084131841328413384134841358413684137841388413984140841418414284143841448414584146841478414884149841508415184152841538415484155841568415784158841598416084161841628416384164841658416684167841688416984170841718417284173841748417584176841778417884179841808418184182841838418484185841868418784188841898419084191841928419384194841958419684197841988419984200842018420284203842048420584206842078420884209842108421184212842138421484215842168421784218842198422084221842228422384224842258422684227842288422984230842318423284233842348423584236842378423884239842408424184242842438424484245842468424784248842498425084251842528425384254842558425684257842588425984260842618426284263842648426584266842678426884269842708427184272842738427484275842768427784278842798428084281842828428384284842858428684287842888428984290842918429284293842948429584296842978429884299843008430184302843038430484305843068430784308843098431084311843128431384314843158431684317843188431984320843218432284323843248432584326843278432884329843308433184332843338433484335843368433784338843398434084341843428434384344843458434684347843488434984350843518435284353843548435584356843578435884359843608436184362843638436484365843668436784368843698437084371843728437384374843758437684377843788437984380843818438284383843848438584386843878438884389843908439184392843938439484395843968439784398843998440084401844028440384404844058440684407844088440984410844118441284413844148441584416844178441884419844208442184422844238442484425844268442784428844298443084431844328443384434844358443684437844388443984440844418444284443844448444584446844478444884449844508445184452844538445484455844568445784458844598446084461844628446384464844658446684467844688446984470844718447284473844748447584476844778447884479844808448184482844838448484485844868448784488844898449084491844928449384494844958449684497844988449984500845018450284503845048450584506845078450884509845108451184512845138451484515845168451784518845198452084521845228452384524845258452684527845288452984530845318453284533845348453584536845378453884539845408454184542845438454484545845468454784548845498455084551845528455384554845558455684557845588455984560845618456284563845648456584566845678456884569845708457184572845738457484575845768457784578845798458084581845828458384584845858458684587845888458984590845918459284593845948459584596845978459884599846008460184602846038460484605846068460784608846098461084611846128461384614846158461684617846188461984620846218462284623846248462584626846278462884629846308463184632846338463484635846368463784638846398464084641846428464384644846458464684647846488464984650846518465284653846548465584656846578465884659846608466184662846638466484665846668466784668846698467084671846728467384674846758467684677846788467984680846818468284683846848468584686846878468884689846908469184692846938469484695846968469784698846998470084701847028470384704847058470684707847088470984710847118471284713847148471584716847178471884719847208472184722847238472484725847268472784728847298473084731847328473384734847358473684737847388473984740847418474284743847448474584746847478474884749847508475184752847538475484755847568475784758847598476084761847628476384764847658476684767847688476984770847718477284773847748477584776847778477884779847808478184782847838478484785847868478784788847898479084791847928479384794847958479684797847988479984800848018480284803848048480584806848078480884809848108481184812848138481484815848168481784818848198482084821848228482384824848258482684827848288482984830848318483284833848348483584836848378483884839848408484184842848438484484845848468484784848848498485084851848528485384854848558485684857848588485984860848618486284863848648486584866848678486884869848708487184872848738487484875848768487784878848798488084881848828488384884848858488684887848888488984890848918489284893848948489584896848978489884899849008490184902849038490484905849068490784908849098491084911849128491384914849158491684917849188491984920849218492284923849248492584926849278492884929849308493184932849338493484935849368493784938849398494084941849428494384944849458494684947849488494984950849518495284953849548495584956849578495884959849608496184962849638496484965849668496784968849698497084971849728497384974849758497684977849788497984980849818498284983849848498584986849878498884989849908499184992849938499484995849968499784998849998500085001850028500385004850058500685007850088500985010850118501285013850148501585016850178501885019850208502185022850238502485025850268502785028850298503085031850328503385034850358503685037850388503985040850418504285043850448504585046850478504885049850508505185052850538505485055850568505785058850598506085061850628506385064850658506685067850688506985070850718507285073850748507585076850778507885079850808508185082850838508485085850868508785088850898509085091850928509385094850958509685097850988509985100851018510285103851048510585106851078510885109851108511185112851138511485115851168511785118851198512085121851228512385124851258512685127851288512985130851318513285133851348513585136851378513885139851408514185142851438514485145851468514785148851498515085151851528515385154851558515685157851588515985160851618516285163851648516585166851678516885169851708517185172851738517485175851768517785178851798518085181851828518385184851858518685187851888518985190851918519285193851948519585196851978519885199852008520185202852038520485205852068520785208852098521085211852128521385214852158521685217852188521985220852218522285223852248522585226852278522885229852308523185232852338523485235852368523785238852398524085241852428524385244852458524685247852488524985250852518525285253852548525585256852578525885259852608526185262852638526485265852668526785268852698527085271852728527385274852758527685277852788527985280852818528285283852848528585286852878528885289852908529185292852938529485295852968529785298852998530085301853028530385304853058530685307853088530985310853118531285313853148531585316853178531885319853208532185322853238532485325853268532785328853298533085331853328533385334853358533685337853388533985340853418534285343853448534585346853478534885349853508535185352853538535485355853568535785358853598536085361853628536385364853658536685367853688536985370853718537285373853748537585376853778537885379853808538185382853838538485385853868538785388853898539085391853928539385394853958539685397853988539985400854018540285403854048540585406854078540885409854108541185412854138541485415854168541785418854198542085421854228542385424854258542685427854288542985430854318543285433854348543585436854378543885439854408544185442854438544485445854468544785448854498545085451854528545385454854558545685457854588545985460854618546285463854648546585466854678546885469854708547185472854738547485475854768547785478854798548085481854828548385484854858548685487854888548985490854918549285493854948549585496854978549885499855008550185502855038550485505855068550785508855098551085511855128551385514855158551685517855188551985520855218552285523855248552585526855278552885529855308553185532855338553485535855368553785538855398554085541855428554385544855458554685547855488554985550855518555285553855548555585556855578555885559855608556185562855638556485565855668556785568855698557085571855728557385574855758557685577855788557985580855818558285583855848558585586855878558885589855908559185592855938559485595855968559785598855998560085601856028560385604856058560685607856088560985610856118561285613856148561585616856178561885619856208562185622856238562485625856268562785628856298563085631856328563385634856358563685637856388563985640856418564285643856448564585646856478564885649856508565185652856538565485655856568565785658856598566085661856628566385664856658566685667856688566985670856718567285673856748567585676856778567885679856808568185682856838568485685856868568785688856898569085691856928569385694856958569685697856988569985700857018570285703857048570585706857078570885709857108571185712857138571485715857168571785718857198572085721857228572385724857258572685727857288572985730857318573285733857348573585736857378573885739857408574185742857438574485745857468574785748857498575085751857528575385754857558575685757857588575985760857618576285763857648576585766857678576885769857708577185772857738577485775857768577785778857798578085781857828578385784857858578685787857888578985790857918579285793857948579585796857978579885799858008580185802858038580485805858068580785808858098581085811858128581385814858158581685817858188581985820858218582285823858248582585826858278582885829858308583185832858338583485835858368583785838858398584085841858428584385844858458584685847858488584985850858518585285853858548585585856858578585885859858608586185862858638586485865858668586785868858698587085871858728587385874858758587685877858788587985880858818588285883858848588585886858878588885889858908589185892858938589485895858968589785898858998590085901859028590385904859058590685907859088590985910859118591285913859148591585916859178591885919859208592185922859238592485925859268592785928859298593085931859328593385934859358593685937859388593985940859418594285943859448594585946859478594885949859508595185952859538595485955859568595785958859598596085961859628596385964859658596685967859688596985970859718597285973859748597585976859778597885979859808598185982859838598485985859868598785988859898599085991859928599385994859958599685997859988599986000860018600286003860048600586006860078600886009860108601186012860138601486015860168601786018860198602086021860228602386024860258602686027860288602986030860318603286033860348603586036860378603886039860408604186042860438604486045860468604786048860498605086051860528605386054860558605686057860588605986060860618606286063860648606586066860678606886069860708607186072860738607486075860768607786078860798608086081860828608386084860858608686087860888608986090860918609286093860948609586096860978609886099861008610186102861038610486105861068610786108861098611086111861128611386114861158611686117861188611986120861218612286123861248612586126861278612886129861308613186132861338613486135861368613786138861398614086141861428614386144861458614686147861488614986150861518615286153861548615586156861578615886159861608616186162861638616486165861668616786168861698617086171861728617386174861758617686177861788617986180861818618286183861848618586186861878618886189861908619186192861938619486195861968619786198861998620086201862028620386204862058620686207862088620986210862118621286213862148621586216862178621886219862208622186222862238622486225862268622786228862298623086231862328623386234862358623686237862388623986240862418624286243862448624586246862478624886249862508625186252862538625486255862568625786258862598626086261862628626386264862658626686267862688626986270862718627286273862748627586276862778627886279862808628186282862838628486285862868628786288862898629086291862928629386294862958629686297862988629986300863018630286303863048630586306863078630886309863108631186312863138631486315863168631786318863198632086321863228632386324863258632686327863288632986330863318633286333863348633586336863378633886339863408634186342863438634486345863468634786348863498635086351863528635386354863558635686357863588635986360863618636286363863648636586366863678636886369863708637186372863738637486375863768637786378863798638086381863828638386384863858638686387863888638986390863918639286393863948639586396863978639886399864008640186402864038640486405864068640786408864098641086411864128641386414864158641686417864188641986420864218642286423864248642586426864278642886429864308643186432864338643486435864368643786438864398644086441864428644386444864458644686447864488644986450864518645286453864548645586456864578645886459864608646186462864638646486465864668646786468864698647086471864728647386474864758647686477864788647986480864818648286483864848648586486864878648886489864908649186492864938649486495864968649786498864998650086501865028650386504865058650686507865088650986510865118651286513865148651586516865178651886519865208652186522865238652486525865268652786528865298653086531865328653386534865358653686537865388653986540865418654286543865448654586546865478654886549865508655186552865538655486555865568655786558865598656086561865628656386564865658656686567865688656986570865718657286573865748657586576865778657886579865808658186582865838658486585865868658786588865898659086591865928659386594865958659686597865988659986600866018660286603866048660586606866078660886609866108661186612866138661486615866168661786618866198662086621866228662386624866258662686627866288662986630866318663286633866348663586636866378663886639866408664186642866438664486645866468664786648866498665086651866528665386654866558665686657866588665986660866618666286663866648666586666866678666886669866708667186672866738667486675866768667786678866798668086681866828668386684866858668686687866888668986690866918669286693866948669586696866978669886699867008670186702867038670486705867068670786708867098671086711867128671386714867158671686717867188671986720867218672286723867248672586726867278672886729867308673186732867338673486735867368673786738867398674086741867428674386744867458674686747867488674986750867518675286753867548675586756867578675886759867608676186762867638676486765867668676786768867698677086771867728677386774867758677686777867788677986780867818678286783867848678586786867878678886789867908679186792867938679486795867968679786798867998680086801868028680386804868058680686807868088680986810868118681286813868148681586816868178681886819868208682186822868238682486825868268682786828868298683086831868328683386834868358683686837868388683986840868418684286843868448684586846868478684886849868508685186852868538685486855868568685786858868598686086861868628686386864868658686686867868688686986870868718687286873868748687586876868778687886879868808688186882868838688486885868868688786888868898689086891868928689386894868958689686897868988689986900869018690286903869048690586906869078690886909869108691186912869138691486915869168691786918869198692086921869228692386924869258692686927869288692986930869318693286933869348693586936869378693886939869408694186942869438694486945869468694786948869498695086951869528695386954869558695686957869588695986960869618696286963869648696586966869678696886969869708697186972869738697486975869768697786978869798698086981869828698386984869858698686987869888698986990869918699286993869948699586996869978699886999870008700187002870038700487005870068700787008870098701087011870128701387014870158701687017870188701987020870218702287023870248702587026870278702887029870308703187032870338703487035870368703787038870398704087041870428704387044870458704687047870488704987050870518705287053870548705587056870578705887059870608706187062870638706487065870668706787068870698707087071870728707387074870758707687077870788707987080870818708287083870848708587086870878708887089870908709187092870938709487095870968709787098870998710087101871028710387104871058710687107871088710987110871118711287113871148711587116871178711887119871208712187122871238712487125871268712787128871298713087131871328713387134871358713687137871388713987140871418714287143871448714587146871478714887149871508715187152871538715487155871568715787158871598716087161871628716387164871658716687167871688716987170871718717287173871748717587176871778717887179871808718187182871838718487185871868718787188871898719087191871928719387194871958719687197871988719987200872018720287203872048720587206872078720887209872108721187212872138721487215872168721787218872198722087221872228722387224872258722687227872288722987230872318723287233872348723587236872378723887239872408724187242872438724487245872468724787248872498725087251872528725387254872558725687257872588725987260872618726287263872648726587266872678726887269872708727187272872738727487275872768727787278872798728087281872828728387284872858728687287872888728987290872918729287293872948729587296872978729887299873008730187302873038730487305873068730787308873098731087311873128731387314873158731687317873188731987320873218732287323873248732587326873278732887329873308733187332873338733487335873368733787338873398734087341873428734387344873458734687347873488734987350873518735287353873548735587356873578735887359873608736187362873638736487365873668736787368873698737087371873728737387374873758737687377873788737987380873818738287383873848738587386873878738887389873908739187392873938739487395873968739787398873998740087401874028740387404874058740687407874088740987410874118741287413874148741587416874178741887419874208742187422874238742487425874268742787428874298743087431874328743387434874358743687437874388743987440874418744287443874448744587446874478744887449874508745187452874538745487455874568745787458874598746087461874628746387464874658746687467874688746987470874718747287473874748747587476874778747887479874808748187482874838748487485874868748787488874898749087491874928749387494874958749687497874988749987500875018750287503875048750587506875078750887509875108751187512875138751487515875168751787518875198752087521875228752387524875258752687527875288752987530875318753287533875348753587536875378753887539875408754187542875438754487545875468754787548875498755087551875528755387554875558755687557875588755987560875618756287563875648756587566875678756887569875708757187572875738757487575875768757787578875798758087581875828758387584875858758687587875888758987590875918759287593875948759587596875978759887599876008760187602876038760487605876068760787608876098761087611876128761387614876158761687617876188761987620876218762287623876248762587626876278762887629876308763187632876338763487635876368763787638876398764087641876428764387644876458764687647876488764987650876518765287653876548765587656876578765887659876608766187662876638766487665876668766787668876698767087671876728767387674876758767687677876788767987680876818768287683876848768587686876878768887689876908769187692876938769487695876968769787698876998770087701877028770387704877058770687707877088770987710877118771287713877148771587716877178771887719877208772187722877238772487725877268772787728877298773087731877328773387734877358773687737877388773987740877418774287743877448774587746877478774887749877508775187752877538775487755877568775787758877598776087761877628776387764877658776687767877688776987770877718777287773877748777587776877778777887779877808778187782877838778487785877868778787788877898779087791877928779387794877958779687797877988779987800878018780287803878048780587806878078780887809878108781187812878138781487815878168781787818878198782087821878228782387824878258782687827878288782987830878318783287833878348783587836878378783887839878408784187842878438784487845878468784787848878498785087851878528785387854878558785687857878588785987860878618786287863878648786587866878678786887869878708787187872878738787487875878768787787878878798788087881878828788387884878858788687887878888788987890878918789287893878948789587896878978789887899879008790187902879038790487905879068790787908879098791087911879128791387914879158791687917879188791987920879218792287923879248792587926879278792887929879308793187932879338793487935879368793787938879398794087941879428794387944879458794687947879488794987950879518795287953879548795587956879578795887959879608796187962879638796487965879668796787968879698797087971879728797387974879758797687977879788797987980879818798287983879848798587986879878798887989879908799187992879938799487995879968799787998879998800088001880028800388004880058800688007880088800988010880118801288013880148801588016880178801888019880208802188022880238802488025880268802788028880298803088031880328803388034880358803688037880388803988040880418804288043880448804588046880478804888049880508805188052880538805488055880568805788058880598806088061880628806388064880658806688067880688806988070880718807288073880748807588076880778807888079880808808188082880838808488085880868808788088880898809088091880928809388094880958809688097880988809988100881018810288103881048810588106881078810888109881108811188112881138811488115881168811788118881198812088121881228812388124881258812688127881288812988130881318813288133881348813588136881378813888139881408814188142881438814488145881468814788148881498815088151881528815388154881558815688157881588815988160881618816288163881648816588166881678816888169881708817188172881738817488175881768817788178881798818088181881828818388184881858818688187881888818988190881918819288193881948819588196881978819888199882008820188202882038820488205882068820788208882098821088211882128821388214882158821688217882188821988220882218822288223882248822588226882278822888229882308823188232882338823488235882368823788238882398824088241882428824388244882458824688247882488824988250882518825288253882548825588256882578825888259882608826188262882638826488265882668826788268882698827088271882728827388274882758827688277882788827988280882818828288283882848828588286882878828888289882908829188292882938829488295882968829788298882998830088301883028830388304883058830688307883088830988310883118831288313883148831588316883178831888319883208832188322883238832488325883268832788328883298833088331883328833388334883358833688337883388833988340883418834288343883448834588346883478834888349883508835188352883538835488355883568835788358883598836088361883628836388364883658836688367883688836988370883718837288373883748837588376883778837888379883808838188382883838838488385883868838788388883898839088391883928839388394883958839688397883988839988400884018840288403884048840588406884078840888409884108841188412884138841488415884168841788418884198842088421884228842388424884258842688427884288842988430884318843288433884348843588436884378843888439884408844188442884438844488445884468844788448884498845088451884528845388454884558845688457884588845988460884618846288463884648846588466884678846888469884708847188472884738847488475884768847788478884798848088481884828848388484884858848688487884888848988490884918849288493884948849588496884978849888499885008850188502885038850488505885068850788508885098851088511885128851388514885158851688517885188851988520885218852288523885248852588526885278852888529885308853188532885338853488535885368853788538885398854088541885428854388544885458854688547885488854988550885518855288553885548855588556885578855888559885608856188562885638856488565885668856788568885698857088571885728857388574885758857688577885788857988580885818858288583885848858588586885878858888589885908859188592885938859488595885968859788598885998860088601886028860388604886058860688607886088860988610886118861288613886148861588616886178861888619886208862188622886238862488625886268862788628886298863088631886328863388634886358863688637886388863988640886418864288643886448864588646886478864888649886508865188652886538865488655886568865788658886598866088661886628866388664886658866688667886688866988670886718867288673886748867588676886778867888679886808868188682886838868488685886868868788688886898869088691886928869388694886958869688697886988869988700887018870288703887048870588706887078870888709887108871188712887138871488715887168871788718887198872088721887228872388724887258872688727887288872988730887318873288733887348873588736887378873888739887408874188742887438874488745887468874788748887498875088751887528875388754887558875688757887588875988760887618876288763887648876588766887678876888769887708877188772887738877488775887768877788778887798878088781887828878388784887858878688787887888878988790887918879288793887948879588796887978879888799888008880188802888038880488805888068880788808888098881088811888128881388814888158881688817888188881988820888218882288823888248882588826888278882888829888308883188832888338883488835888368883788838888398884088841888428884388844888458884688847888488884988850888518885288853888548885588856888578885888859888608886188862888638886488865888668886788868888698887088871888728887388874888758887688877888788887988880888818888288883888848888588886888878888888889888908889188892888938889488895888968889788898888998890088901889028890388904889058890688907889088890988910889118891288913889148891588916889178891888919889208892188922889238892488925889268892788928889298893088931889328893388934889358893688937889388893988940889418894288943889448894588946889478894888949889508895188952889538895488955889568895788958889598896088961889628896388964889658896688967889688896988970889718897288973889748897588976889778897888979889808898188982889838898488985889868898788988889898899088991889928899388994889958899688997889988899989000890018900289003890048900589006890078900889009890108901189012890138901489015890168901789018890198902089021890228902389024890258902689027890288902989030890318903289033890348903589036890378903889039890408904189042890438904489045890468904789048890498905089051890528905389054890558905689057890588905989060890618906289063890648906589066890678906889069890708907189072890738907489075890768907789078890798908089081890828908389084890858908689087890888908989090890918909289093890948909589096890978909889099891008910189102891038910489105891068910789108891098911089111891128911389114891158911689117891188911989120891218912289123891248912589126891278912889129891308913189132891338913489135891368913789138891398914089141891428914389144891458914689147891488914989150891518915289153891548915589156891578915889159891608916189162891638916489165891668916789168891698917089171891728917389174891758917689177891788917989180891818918289183891848918589186891878918889189891908919189192891938919489195891968919789198891998920089201892028920389204892058920689207892088920989210892118921289213892148921589216892178921889219892208922189222892238922489225892268922789228892298923089231892328923389234892358923689237892388923989240892418924289243892448924589246892478924889249892508925189252892538925489255892568925789258892598926089261892628926389264892658926689267892688926989270892718927289273892748927589276892778927889279892808928189282892838928489285892868928789288892898929089291892928929389294892958929689297892988929989300893018930289303893048930589306893078930889309893108931189312893138931489315893168931789318893198932089321893228932389324893258932689327893288932989330893318933289333893348933589336893378933889339893408934189342893438934489345893468934789348893498935089351893528935389354893558935689357893588935989360893618936289363893648936589366893678936889369893708937189372893738937489375893768937789378893798938089381893828938389384893858938689387893888938989390893918939289393893948939589396893978939889399894008940189402894038940489405894068940789408894098941089411894128941389414894158941689417894188941989420894218942289423894248942589426894278942889429894308943189432894338943489435894368943789438894398944089441894428944389444894458944689447894488944989450894518945289453894548945589456894578945889459894608946189462894638946489465894668946789468894698947089471894728947389474894758947689477894788947989480894818948289483894848948589486894878948889489894908949189492894938949489495894968949789498894998950089501895028950389504895058950689507895088950989510895118951289513895148951589516895178951889519895208952189522895238952489525895268952789528895298953089531895328953389534895358953689537895388953989540895418954289543895448954589546895478954889549895508955189552895538955489555895568955789558895598956089561895628956389564895658956689567895688956989570895718957289573895748957589576895778957889579895808958189582895838958489585895868958789588895898959089591895928959389594895958959689597895988959989600896018960289603896048960589606896078960889609896108961189612896138961489615896168961789618896198962089621896228962389624896258962689627896288962989630896318963289633896348963589636896378963889639896408964189642896438964489645896468964789648896498965089651896528965389654896558965689657896588965989660896618966289663896648966589666896678966889669896708967189672896738967489675896768967789678896798968089681896828968389684896858968689687896888968989690896918969289693896948969589696896978969889699897008970189702897038970489705897068970789708897098971089711897128971389714897158971689717897188971989720897218972289723897248972589726897278972889729897308973189732897338973489735897368973789738897398974089741897428974389744897458974689747897488974989750897518975289753897548975589756897578975889759897608976189762897638976489765897668976789768897698977089771897728977389774897758977689777897788977989780897818978289783897848978589786897878978889789897908979189792897938979489795897968979789798897998980089801898028980389804898058980689807898088980989810898118981289813898148981589816898178981889819898208982189822898238982489825898268982789828898298983089831898328983389834898358983689837898388983989840898418984289843898448984589846898478984889849898508985189852898538985489855898568985789858898598986089861898628986389864898658986689867898688986989870898718987289873898748987589876898778987889879898808988189882898838988489885898868988789888898898989089891898928989389894898958989689897898988989989900899018990289903899048990589906899078990889909899108991189912899138991489915899168991789918899198992089921899228992389924899258992689927899288992989930899318993289933899348993589936899378993889939899408994189942899438994489945899468994789948899498995089951899528995389954899558995689957899588995989960899618996289963899648996589966899678996889969899708997189972899738997489975899768997789978899798998089981899828998389984899858998689987899888998989990899918999289993899948999589996899978999889999900009000190002900039000490005900069000790008900099001090011900129001390014900159001690017900189001990020900219002290023900249002590026900279002890029900309003190032900339003490035900369003790038900399004090041900429004390044900459004690047900489004990050900519005290053900549005590056900579005890059900609006190062900639006490065900669006790068900699007090071900729007390074900759007690077900789007990080900819008290083900849008590086900879008890089900909009190092900939009490095900969009790098900999010090101901029010390104901059010690107901089010990110901119011290113901149011590116901179011890119901209012190122901239012490125901269012790128901299013090131901329013390134901359013690137901389013990140901419014290143901449014590146901479014890149901509015190152901539015490155901569015790158901599016090161901629016390164901659016690167901689016990170901719017290173901749017590176901779017890179901809018190182901839018490185901869018790188901899019090191901929019390194901959019690197901989019990200902019020290203902049020590206902079020890209902109021190212902139021490215902169021790218902199022090221902229022390224902259022690227902289022990230902319023290233902349023590236902379023890239902409024190242902439024490245902469024790248902499025090251902529025390254902559025690257902589025990260902619026290263902649026590266902679026890269902709027190272902739027490275902769027790278902799028090281902829028390284902859028690287902889028990290902919029290293902949029590296902979029890299903009030190302903039030490305903069030790308903099031090311903129031390314903159031690317903189031990320903219032290323903249032590326903279032890329903309033190332903339033490335903369033790338903399034090341903429034390344903459034690347903489034990350903519035290353903549035590356903579035890359903609036190362903639036490365903669036790368903699037090371903729037390374903759037690377903789037990380903819038290383903849038590386903879038890389903909039190392903939039490395903969039790398903999040090401904029040390404904059040690407904089040990410904119041290413904149041590416904179041890419904209042190422904239042490425904269042790428904299043090431904329043390434904359043690437904389043990440904419044290443904449044590446904479044890449904509045190452904539045490455904569045790458904599046090461904629046390464904659046690467904689046990470904719047290473904749047590476904779047890479904809048190482904839048490485904869048790488904899049090491904929049390494904959049690497904989049990500905019050290503905049050590506905079050890509905109051190512905139051490515905169051790518905199052090521905229052390524905259052690527905289052990530905319053290533905349053590536905379053890539905409054190542905439054490545905469054790548905499055090551905529055390554905559055690557905589055990560905619056290563905649056590566905679056890569905709057190572905739057490575905769057790578905799058090581905829058390584905859058690587905889058990590905919059290593905949059590596905979059890599906009060190602906039060490605906069060790608906099061090611906129061390614906159061690617906189061990620906219062290623906249062590626906279062890629906309063190632906339063490635906369063790638906399064090641906429064390644906459064690647906489064990650906519065290653906549065590656906579065890659906609066190662906639066490665906669066790668906699067090671906729067390674906759067690677906789067990680906819068290683906849068590686906879068890689906909069190692906939069490695906969069790698906999070090701907029070390704907059070690707907089070990710907119071290713907149071590716907179071890719907209072190722907239072490725907269072790728907299073090731907329073390734907359073690737907389073990740907419074290743907449074590746907479074890749907509075190752907539075490755907569075790758907599076090761907629076390764907659076690767907689076990770907719077290773907749077590776907779077890779907809078190782907839078490785907869078790788907899079090791907929079390794907959079690797907989079990800908019080290803908049080590806908079080890809908109081190812908139081490815908169081790818908199082090821908229082390824908259082690827908289082990830908319083290833908349083590836908379083890839908409084190842908439084490845908469084790848908499085090851908529085390854908559085690857908589085990860908619086290863908649086590866908679086890869908709087190872908739087490875908769087790878908799088090881908829088390884908859088690887908889088990890908919089290893908949089590896908979089890899909009090190902909039090490905909069090790908909099091090911909129091390914909159091690917909189091990920909219092290923909249092590926909279092890929909309093190932909339093490935909369093790938909399094090941909429094390944909459094690947909489094990950909519095290953909549095590956909579095890959909609096190962909639096490965909669096790968909699097090971909729097390974909759097690977909789097990980909819098290983909849098590986909879098890989909909099190992909939099490995909969099790998909999100091001910029100391004910059100691007910089100991010910119101291013910149101591016910179101891019910209102191022910239102491025910269102791028910299103091031910329103391034910359103691037910389103991040910419104291043910449104591046910479104891049910509105191052910539105491055910569105791058910599106091061910629106391064910659106691067910689106991070910719107291073910749107591076910779107891079910809108191082910839108491085910869108791088910899109091091910929109391094910959109691097910989109991100911019110291103911049110591106911079110891109911109111191112911139111491115911169111791118911199112091121911229112391124911259112691127911289112991130911319113291133911349113591136911379113891139911409114191142911439114491145911469114791148911499115091151911529115391154911559115691157911589115991160911619116291163911649116591166911679116891169911709117191172911739117491175911769117791178911799118091181911829118391184911859118691187911889118991190911919119291193911949119591196911979119891199912009120191202912039120491205912069120791208912099121091211912129121391214912159121691217912189121991220912219122291223912249122591226912279122891229912309123191232912339123491235912369123791238912399124091241912429124391244912459124691247912489124991250912519125291253912549125591256912579125891259912609126191262912639126491265912669126791268912699127091271912729127391274912759127691277912789127991280912819128291283912849128591286912879128891289912909129191292912939129491295912969129791298912999130091301913029130391304913059130691307913089130991310913119131291313913149131591316913179131891319913209132191322913239132491325913269132791328913299133091331913329133391334913359133691337913389133991340913419134291343913449134591346913479134891349913509135191352913539135491355913569135791358913599136091361913629136391364913659136691367913689136991370913719137291373913749137591376913779137891379913809138191382913839138491385913869138791388913899139091391913929139391394913959139691397913989139991400914019140291403914049140591406914079140891409914109141191412914139141491415914169141791418914199142091421914229142391424914259142691427914289142991430914319143291433914349143591436914379143891439914409144191442914439144491445914469144791448914499145091451914529145391454914559145691457914589145991460914619146291463914649146591466914679146891469914709147191472914739147491475914769147791478914799148091481914829148391484914859148691487914889148991490914919149291493914949149591496914979149891499915009150191502915039150491505915069150791508915099151091511915129151391514915159151691517915189151991520915219152291523915249152591526915279152891529915309153191532915339153491535915369153791538915399154091541915429154391544915459154691547915489154991550915519155291553915549155591556915579155891559915609156191562915639156491565915669156791568915699157091571915729157391574915759157691577915789157991580915819158291583915849158591586915879158891589915909159191592915939159491595915969159791598915999160091601916029160391604916059160691607916089160991610916119161291613916149161591616916179161891619916209162191622916239162491625916269162791628916299163091631916329163391634916359163691637916389163991640916419164291643916449164591646916479164891649916509165191652916539165491655916569165791658916599166091661916629166391664916659166691667916689166991670916719167291673916749167591676916779167891679916809168191682916839168491685916869168791688916899169091691916929169391694916959169691697916989169991700917019170291703917049170591706917079170891709917109171191712917139171491715917169171791718917199172091721917229172391724917259172691727917289172991730917319173291733917349173591736917379173891739917409174191742917439174491745917469174791748917499175091751917529175391754917559175691757917589175991760917619176291763917649176591766917679176891769917709177191772917739177491775917769177791778917799178091781917829178391784917859178691787917889178991790917919179291793917949179591796917979179891799918009180191802918039180491805918069180791808918099181091811918129181391814918159181691817918189181991820918219182291823918249182591826918279182891829918309183191832918339183491835918369183791838918399184091841918429184391844918459184691847918489184991850918519185291853918549185591856918579185891859918609186191862918639186491865918669186791868918699187091871918729187391874918759187691877918789187991880918819188291883918849188591886918879188891889918909189191892918939189491895918969189791898918999190091901919029190391904919059190691907919089190991910919119191291913919149191591916919179191891919919209192191922919239192491925919269192791928919299193091931919329193391934919359193691937919389193991940919419194291943919449194591946919479194891949919509195191952919539195491955919569195791958919599196091961919629196391964919659196691967919689196991970919719197291973919749197591976919779197891979919809198191982919839198491985919869198791988919899199091991919929199391994919959199691997919989199992000920019200292003920049200592006920079200892009920109201192012920139201492015920169201792018920199202092021920229202392024920259202692027920289202992030920319203292033920349203592036920379203892039920409204192042920439204492045920469204792048920499205092051920529205392054920559205692057920589205992060920619206292063920649206592066920679206892069920709207192072920739207492075920769207792078920799208092081920829208392084920859208692087920889208992090920919209292093920949209592096920979209892099921009210192102921039210492105921069210792108921099211092111921129211392114921159211692117921189211992120921219212292123921249212592126921279212892129921309213192132921339213492135921369213792138921399214092141921429214392144921459214692147921489214992150921519215292153921549215592156921579215892159921609216192162921639216492165921669216792168921699217092171921729217392174921759217692177921789217992180921819218292183921849218592186921879218892189921909219192192921939219492195921969219792198921999220092201922029220392204922059220692207922089220992210922119221292213922149221592216922179221892219922209222192222922239222492225922269222792228922299223092231922329223392234922359223692237922389223992240922419224292243922449224592246922479224892249922509225192252922539225492255922569225792258922599226092261922629226392264922659226692267922689226992270922719227292273922749227592276922779227892279922809228192282922839228492285922869228792288922899229092291922929229392294922959229692297922989229992300923019230292303923049230592306923079230892309923109231192312923139231492315923169231792318923199232092321923229232392324923259232692327923289232992330923319233292333923349233592336923379233892339923409234192342923439234492345923469234792348923499235092351923529235392354923559235692357923589235992360923619236292363923649236592366923679236892369923709237192372923739237492375923769237792378923799238092381923829238392384923859238692387923889238992390923919239292393923949239592396923979239892399924009240192402924039240492405924069240792408924099241092411924129241392414924159241692417924189241992420924219242292423924249242592426924279242892429924309243192432924339243492435924369243792438924399244092441924429244392444924459244692447924489244992450924519245292453924549245592456924579245892459924609246192462924639246492465924669246792468924699247092471924729247392474924759247692477924789247992480924819248292483924849248592486924879248892489924909249192492924939249492495924969249792498924999250092501925029250392504925059250692507925089250992510925119251292513925149251592516925179251892519925209252192522925239252492525925269252792528925299253092531925329253392534925359253692537925389253992540925419254292543925449254592546925479254892549925509255192552925539255492555925569255792558925599256092561925629256392564925659256692567925689256992570925719257292573925749257592576925779257892579925809258192582925839258492585925869258792588925899259092591925929259392594925959259692597925989259992600926019260292603926049260592606926079260892609926109261192612926139261492615926169261792618926199262092621926229262392624926259262692627926289262992630926319263292633926349263592636926379263892639926409264192642926439264492645926469264792648926499265092651926529265392654926559265692657926589265992660926619266292663926649266592666926679266892669926709267192672926739267492675926769267792678926799268092681926829268392684926859268692687926889268992690926919269292693926949269592696926979269892699927009270192702927039270492705927069270792708927099271092711927129271392714927159271692717927189271992720927219272292723927249272592726927279272892729927309273192732927339273492735927369273792738927399274092741927429274392744927459274692747927489274992750927519275292753927549275592756927579275892759927609276192762927639276492765927669276792768927699277092771927729277392774927759277692777927789277992780927819278292783927849278592786927879278892789927909279192792927939279492795927969279792798927999280092801928029280392804928059280692807928089280992810928119281292813928149281592816928179281892819928209282192822928239282492825928269282792828928299283092831928329283392834928359283692837928389283992840928419284292843928449284592846928479284892849928509285192852928539285492855928569285792858928599286092861928629286392864928659286692867928689286992870928719287292873928749287592876928779287892879928809288192882928839288492885928869288792888928899289092891928929289392894928959289692897928989289992900929019290292903929049290592906929079290892909929109291192912929139291492915929169291792918929199292092921929229292392924929259292692927929289292992930929319293292933929349293592936929379293892939929409294192942929439294492945929469294792948929499295092951929529295392954929559295692957929589295992960929619296292963929649296592966929679296892969929709297192972929739297492975929769297792978929799298092981929829298392984929859298692987929889298992990929919299292993929949299592996929979299892999930009300193002930039300493005930069300793008930099301093011930129301393014930159301693017930189301993020930219302293023930249302593026930279302893029930309303193032930339303493035930369303793038930399304093041930429304393044930459304693047930489304993050930519305293053930549305593056930579305893059930609306193062930639306493065930669306793068930699307093071930729307393074930759307693077930789307993080930819308293083930849308593086930879308893089930909309193092930939309493095930969309793098930999310093101931029310393104931059310693107931089310993110931119311293113931149311593116931179311893119931209312193122931239312493125931269312793128931299313093131931329313393134931359313693137931389313993140931419314293143931449314593146931479314893149931509315193152931539315493155931569315793158931599316093161931629316393164931659316693167931689316993170931719317293173931749317593176931779317893179931809318193182931839318493185931869318793188931899319093191931929319393194931959319693197931989319993200932019320293203932049320593206932079320893209932109321193212932139321493215932169321793218932199322093221932229322393224932259322693227932289322993230932319323293233932349323593236932379323893239932409324193242932439324493245932469324793248932499325093251932529325393254932559325693257932589325993260932619326293263932649326593266932679326893269932709327193272932739327493275932769327793278932799328093281932829328393284932859328693287932889328993290932919329293293932949329593296932979329893299933009330193302933039330493305933069330793308933099331093311933129331393314933159331693317933189331993320933219332293323933249332593326933279332893329933309333193332933339333493335933369333793338933399334093341933429334393344933459334693347933489334993350933519335293353933549335593356933579335893359933609336193362933639336493365933669336793368933699337093371933729337393374933759337693377933789337993380933819338293383933849338593386933879338893389933909339193392933939339493395933969339793398933999340093401934029340393404934059340693407934089340993410934119341293413934149341593416934179341893419934209342193422934239342493425934269342793428934299343093431934329343393434934359343693437934389343993440934419344293443934449344593446934479344893449934509345193452934539345493455934569345793458934599346093461934629346393464934659346693467934689346993470934719347293473934749347593476934779347893479934809348193482934839348493485934869348793488934899349093491934929349393494934959349693497934989349993500935019350293503935049350593506935079350893509935109351193512935139351493515935169351793518935199352093521935229352393524935259352693527935289352993530935319353293533935349353593536935379353893539935409354193542935439354493545935469354793548935499355093551935529355393554935559355693557935589355993560935619356293563935649356593566935679356893569935709357193572935739357493575935769357793578935799358093581935829358393584935859358693587935889358993590935919359293593935949359593596935979359893599936009360193602936039360493605936069360793608936099361093611936129361393614936159361693617936189361993620936219362293623936249362593626936279362893629936309363193632936339363493635936369363793638936399364093641936429364393644936459364693647936489364993650936519365293653936549365593656936579365893659936609366193662936639366493665936669366793668936699367093671936729367393674936759367693677936789367993680936819368293683936849368593686936879368893689936909369193692936939369493695936969369793698936999370093701937029370393704937059370693707937089370993710937119371293713937149371593716937179371893719937209372193722937239372493725937269372793728937299373093731937329373393734937359373693737937389373993740937419374293743937449374593746937479374893749937509375193752937539375493755937569375793758937599376093761937629376393764937659376693767937689376993770937719377293773937749377593776937779377893779937809378193782937839378493785937869378793788937899379093791937929379393794937959379693797937989379993800938019380293803938049380593806938079380893809938109381193812938139381493815938169381793818938199382093821938229382393824938259382693827938289382993830938319383293833938349383593836938379383893839938409384193842938439384493845938469384793848938499385093851938529385393854938559385693857938589385993860938619386293863938649386593866938679386893869938709387193872938739387493875938769387793878938799388093881938829388393884938859388693887938889388993890938919389293893938949389593896938979389893899939009390193902939039390493905939069390793908939099391093911939129391393914939159391693917939189391993920939219392293923939249392593926939279392893929939309393193932939339393493935939369393793938939399394093941939429394393944939459394693947939489394993950939519395293953939549395593956939579395893959939609396193962939639396493965939669396793968939699397093971939729397393974939759397693977939789397993980939819398293983939849398593986939879398893989939909399193992939939399493995939969399793998939999400094001940029400394004940059400694007940089400994010940119401294013940149401594016940179401894019940209402194022940239402494025940269402794028940299403094031940329403394034940359403694037940389403994040940419404294043940449404594046940479404894049940509405194052940539405494055940569405794058940599406094061940629406394064940659406694067940689406994070940719407294073940749407594076940779407894079940809408194082940839408494085940869408794088940899409094091940929409394094940959409694097940989409994100941019410294103941049410594106941079410894109941109411194112941139411494115941169411794118941199412094121941229412394124941259412694127941289412994130941319413294133941349413594136941379413894139941409414194142941439414494145941469414794148941499415094151941529415394154941559415694157941589415994160941619416294163941649416594166941679416894169941709417194172941739417494175941769417794178941799418094181941829418394184941859418694187941889418994190941919419294193941949419594196941979419894199942009420194202942039420494205942069420794208942099421094211942129421394214942159421694217942189421994220942219422294223942249422594226942279422894229942309423194232942339423494235942369423794238942399424094241942429424394244942459424694247942489424994250942519425294253942549425594256942579425894259942609426194262942639426494265942669426794268942699427094271942729427394274942759427694277942789427994280942819428294283942849428594286942879428894289942909429194292942939429494295942969429794298942999430094301943029430394304943059430694307943089430994310943119431294313943149431594316943179431894319943209432194322943239432494325943269432794328943299433094331943329433394334943359433694337943389433994340943419434294343943449434594346943479434894349943509435194352943539435494355943569435794358943599436094361943629436394364943659436694367943689436994370943719437294373943749437594376943779437894379943809438194382943839438494385943869438794388943899439094391943929439394394943959439694397943989439994400944019440294403944049440594406944079440894409944109441194412944139441494415944169441794418944199442094421944229442394424944259442694427944289442994430944319443294433944349443594436944379443894439944409444194442944439444494445944469444794448944499445094451944529445394454944559445694457944589445994460944619446294463944649446594466944679446894469944709447194472944739447494475944769447794478944799448094481944829448394484944859448694487944889448994490944919449294493944949449594496944979449894499945009450194502945039450494505945069450794508945099451094511945129451394514945159451694517945189451994520945219452294523945249452594526945279452894529945309453194532945339453494535945369453794538945399454094541945429454394544945459454694547945489454994550945519455294553945549455594556945579455894559945609456194562945639456494565945669456794568945699457094571945729457394574945759457694577945789457994580945819458294583945849458594586945879458894589945909459194592945939459494595945969459794598945999460094601946029460394604946059460694607946089460994610946119461294613946149461594616946179461894619946209462194622946239462494625946269462794628946299463094631946329463394634946359463694637946389463994640946419464294643946449464594646946479464894649946509465194652946539465494655946569465794658946599466094661946629466394664946659466694667946689466994670946719467294673946749467594676946779467894679946809468194682946839468494685946869468794688946899469094691946929469394694946959469694697946989469994700947019470294703947049470594706947079470894709947109471194712947139471494715947169471794718947199472094721947229472394724947259472694727947289472994730947319473294733947349473594736947379473894739947409474194742947439474494745947469474794748947499475094751947529475394754947559475694757947589475994760947619476294763947649476594766947679476894769947709477194772947739477494775947769477794778947799478094781947829478394784947859478694787947889478994790947919479294793947949479594796947979479894799948009480194802948039480494805948069480794808948099481094811948129481394814948159481694817948189481994820948219482294823948249482594826948279482894829948309483194832948339483494835948369483794838948399484094841948429484394844948459484694847948489484994850948519485294853948549485594856948579485894859948609486194862948639486494865948669486794868948699487094871948729487394874948759487694877948789487994880948819488294883948849488594886948879488894889948909489194892948939489494895948969489794898948999490094901949029490394904949059490694907949089490994910949119491294913949149491594916949179491894919949209492194922949239492494925949269492794928949299493094931949329493394934949359493694937949389493994940949419494294943949449494594946949479494894949949509495194952949539495494955949569495794958949599496094961949629496394964949659496694967949689496994970949719497294973949749497594976949779497894979949809498194982949839498494985949869498794988949899499094991949929499394994949959499694997949989499995000950019500295003950049500595006950079500895009950109501195012950139501495015950169501795018950199502095021950229502395024950259502695027950289502995030950319503295033950349503595036950379503895039950409504195042950439504495045950469504795048950499505095051950529505395054950559505695057950589505995060950619506295063950649506595066950679506895069950709507195072950739507495075950769507795078950799508095081950829508395084950859508695087950889508995090950919509295093950949509595096950979509895099951009510195102951039510495105951069510795108951099511095111951129511395114951159511695117951189511995120951219512295123951249512595126951279512895129951309513195132951339513495135951369513795138951399514095141951429514395144951459514695147951489514995150951519515295153951549515595156951579515895159951609516195162951639516495165951669516795168951699517095171951729517395174951759517695177951789517995180951819518295183951849518595186951879518895189951909519195192951939519495195951969519795198951999520095201952029520395204952059520695207952089520995210952119521295213952149521595216952179521895219952209522195222952239522495225952269522795228952299523095231952329523395234952359523695237952389523995240952419524295243952449524595246952479524895249952509525195252952539525495255952569525795258952599526095261952629526395264952659526695267952689526995270952719527295273952749527595276952779527895279952809528195282952839528495285952869528795288952899529095291952929529395294952959529695297952989529995300953019530295303953049530595306953079530895309953109531195312953139531495315953169531795318953199532095321953229532395324953259532695327953289532995330953319533295333953349533595336953379533895339953409534195342953439534495345953469534795348953499535095351953529535395354953559535695357953589535995360953619536295363953649536595366953679536895369953709537195372953739537495375953769537795378953799538095381953829538395384953859538695387953889538995390953919539295393953949539595396953979539895399954009540195402954039540495405954069540795408954099541095411954129541395414954159541695417954189541995420954219542295423954249542595426954279542895429954309543195432954339543495435954369543795438954399544095441954429544395444954459544695447954489544995450954519545295453954549545595456954579545895459954609546195462954639546495465954669546795468954699547095471954729547395474954759547695477954789547995480954819548295483954849548595486954879548895489954909549195492954939549495495954969549795498954999550095501955029550395504955059550695507955089550995510955119551295513955149551595516955179551895519955209552195522955239552495525955269552795528955299553095531955329553395534955359553695537955389553995540955419554295543955449554595546955479554895549955509555195552955539555495555955569555795558955599556095561955629556395564955659556695567955689556995570955719557295573955749557595576955779557895579955809558195582955839558495585955869558795588955899559095591955929559395594955959559695597955989559995600956019560295603956049560595606956079560895609956109561195612956139561495615956169561795618956199562095621956229562395624956259562695627956289562995630956319563295633956349563595636956379563895639956409564195642956439564495645956469564795648956499565095651956529565395654956559565695657956589565995660956619566295663956649566595666956679566895669956709567195672956739567495675956769567795678956799568095681956829568395684956859568695687956889568995690956919569295693956949569595696956979569895699957009570195702957039570495705957069570795708957099571095711957129571395714957159571695717957189571995720957219572295723957249572595726957279572895729957309573195732957339573495735957369573795738957399574095741957429574395744957459574695747957489574995750957519575295753957549575595756957579575895759957609576195762957639576495765957669576795768957699577095771957729577395774957759577695777957789577995780957819578295783957849578595786957879578895789957909579195792957939579495795957969579795798957999580095801958029580395804958059580695807958089580995810958119581295813958149581595816958179581895819958209582195822958239582495825958269582795828958299583095831958329583395834958359583695837958389583995840958419584295843958449584595846958479584895849958509585195852958539585495855958569585795858958599586095861958629586395864958659586695867958689586995870958719587295873958749587595876958779587895879958809588195882958839588495885958869588795888958899589095891958929589395894958959589695897958989589995900959019590295903959049590595906959079590895909959109591195912959139591495915959169591795918959199592095921959229592395924959259592695927959289592995930959319593295933959349593595936959379593895939959409594195942959439594495945959469594795948959499595095951959529595395954959559595695957959589595995960959619596295963959649596595966959679596895969959709597195972959739597495975959769597795978959799598095981959829598395984959859598695987959889598995990959919599295993959949599595996959979599895999960009600196002960039600496005960069600796008960099601096011960129601396014960159601696017960189601996020960219602296023960249602596026960279602896029960309603196032960339603496035960369603796038960399604096041960429604396044960459604696047960489604996050960519605296053960549605596056960579605896059960609606196062960639606496065960669606796068960699607096071960729607396074960759607696077960789607996080960819608296083960849608596086960879608896089960909609196092960939609496095960969609796098960999610096101961029610396104961059610696107961089610996110961119611296113961149611596116961179611896119961209612196122961239612496125961269612796128961299613096131961329613396134961359613696137961389613996140961419614296143961449614596146961479614896149961509615196152961539615496155961569615796158961599616096161961629616396164961659616696167961689616996170961719617296173961749617596176961779617896179961809618196182961839618496185961869618796188961899619096191961929619396194961959619696197961989619996200962019620296203962049620596206962079620896209962109621196212962139621496215962169621796218962199622096221962229622396224962259622696227962289622996230962319623296233962349623596236962379623896239962409624196242962439624496245962469624796248962499625096251962529625396254962559625696257962589625996260962619626296263962649626596266962679626896269962709627196272962739627496275962769627796278962799628096281962829628396284962859628696287962889628996290962919629296293962949629596296962979629896299963009630196302963039630496305963069630796308963099631096311963129631396314963159631696317963189631996320963219632296323963249632596326963279632896329963309633196332963339633496335963369633796338963399634096341963429634396344963459634696347963489634996350963519635296353963549635596356963579635896359963609636196362963639636496365963669636796368963699637096371963729637396374963759637696377963789637996380963819638296383963849638596386963879638896389963909639196392963939639496395963969639796398963999640096401964029640396404964059640696407964089640996410964119641296413964149641596416964179641896419964209642196422964239642496425964269642796428964299643096431964329643396434964359643696437964389643996440964419644296443964449644596446964479644896449964509645196452964539645496455964569645796458964599646096461964629646396464964659646696467964689646996470964719647296473964749647596476964779647896479964809648196482964839648496485964869648796488964899649096491964929649396494964959649696497964989649996500965019650296503965049650596506965079650896509965109651196512965139651496515965169651796518965199652096521965229652396524965259652696527965289652996530965319653296533965349653596536965379653896539965409654196542965439654496545965469654796548965499655096551965529655396554965559655696557965589655996560965619656296563965649656596566965679656896569965709657196572965739657496575965769657796578965799658096581965829658396584965859658696587965889658996590965919659296593965949659596596965979659896599966009660196602966039660496605966069660796608966099661096611966129661396614966159661696617966189661996620966219662296623966249662596626966279662896629966309663196632966339663496635966369663796638966399664096641966429664396644966459664696647966489664996650966519665296653966549665596656966579665896659966609666196662966639666496665966669666796668966699667096671966729667396674966759667696677966789667996680966819668296683966849668596686966879668896689966909669196692966939669496695966969669796698966999670096701967029670396704967059670696707967089670996710967119671296713967149671596716967179671896719967209672196722967239672496725967269672796728967299673096731967329673396734967359673696737967389673996740967419674296743967449674596746967479674896749967509675196752967539675496755967569675796758967599676096761967629676396764967659676696767967689676996770967719677296773967749677596776967779677896779967809678196782967839678496785967869678796788967899679096791967929679396794967959679696797967989679996800968019680296803968049680596806968079680896809968109681196812968139681496815968169681796818968199682096821968229682396824968259682696827968289682996830968319683296833968349683596836968379683896839968409684196842968439684496845968469684796848968499685096851968529685396854968559685696857968589685996860968619686296863968649686596866968679686896869968709687196872968739687496875968769687796878968799688096881968829688396884968859688696887968889688996890968919689296893968949689596896968979689896899969009690196902969039690496905969069690796908969099691096911969129691396914969159691696917969189691996920969219692296923969249692596926969279692896929969309693196932969339693496935969369693796938969399694096941969429694396944969459694696947969489694996950969519695296953969549695596956969579695896959969609696196962969639696496965969669696796968969699697096971969729697396974969759697696977969789697996980969819698296983969849698596986969879698896989969909699196992969939699496995969969699796998969999700097001970029700397004970059700697007970089700997010970119701297013970149701597016970179701897019970209702197022970239702497025970269702797028970299703097031970329703397034970359703697037970389703997040970419704297043970449704597046970479704897049970509705197052970539705497055970569705797058970599706097061970629706397064970659706697067970689706997070970719707297073970749707597076970779707897079970809708197082970839708497085970869708797088970899709097091970929709397094970959709697097970989709997100971019710297103971049710597106971079710897109971109711197112971139711497115971169711797118971199712097121971229712397124971259712697127971289712997130971319713297133971349713597136971379713897139971409714197142971439714497145971469714797148971499715097151971529715397154971559715697157971589715997160971619716297163971649716597166971679716897169971709717197172971739717497175971769717797178971799718097181971829718397184971859718697187971889718997190971919719297193971949719597196971979719897199972009720197202972039720497205972069720797208972099721097211972129721397214972159721697217972189721997220972219722297223972249722597226972279722897229972309723197232972339723497235972369723797238972399724097241972429724397244972459724697247972489724997250972519725297253972549725597256972579725897259972609726197262972639726497265972669726797268972699727097271972729727397274972759727697277972789727997280972819728297283972849728597286972879728897289972909729197292972939729497295972969729797298972999730097301973029730397304973059730697307973089730997310973119731297313973149731597316973179731897319973209732197322973239732497325973269732797328973299733097331973329733397334973359733697337973389733997340973419734297343973449734597346973479734897349973509735197352973539735497355973569735797358973599736097361973629736397364973659736697367973689736997370973719737297373973749737597376973779737897379973809738197382973839738497385973869738797388973899739097391973929739397394973959739697397973989739997400974019740297403974049740597406974079740897409974109741197412974139741497415974169741797418974199742097421974229742397424974259742697427974289742997430974319743297433974349743597436974379743897439974409744197442974439744497445974469744797448974499745097451974529745397454974559745697457974589745997460974619746297463974649746597466974679746897469974709747197472974739747497475974769747797478974799748097481974829748397484974859748697487974889748997490974919749297493974949749597496974979749897499975009750197502975039750497505975069750797508975099751097511975129751397514975159751697517975189751997520975219752297523975249752597526975279752897529975309753197532975339753497535975369753797538975399754097541975429754397544975459754697547975489754997550975519755297553975549755597556975579755897559975609756197562975639756497565975669756797568975699757097571975729757397574975759757697577975789757997580975819758297583975849758597586975879758897589975909759197592975939759497595975969759797598975999760097601976029760397604976059760697607976089760997610976119761297613976149761597616976179761897619976209762197622976239762497625976269762797628976299763097631976329763397634976359763697637976389763997640976419764297643976449764597646976479764897649976509765197652976539765497655976569765797658976599766097661976629766397664976659766697667976689766997670976719767297673976749767597676976779767897679976809768197682976839768497685976869768797688976899769097691976929769397694976959769697697976989769997700977019770297703977049770597706977079770897709977109771197712977139771497715977169771797718977199772097721977229772397724977259772697727977289772997730977319773297733977349773597736977379773897739977409774197742977439774497745977469774797748977499775097751977529775397754977559775697757977589775997760977619776297763977649776597766977679776897769977709777197772977739777497775977769777797778977799778097781977829778397784977859778697787977889778997790977919779297793977949779597796977979779897799978009780197802978039780497805978069780797808978099781097811978129781397814978159781697817978189781997820978219782297823978249782597826978279782897829978309783197832978339783497835978369783797838978399784097841978429784397844978459784697847978489784997850978519785297853978549785597856978579785897859978609786197862978639786497865978669786797868978699787097871978729787397874978759787697877978789787997880978819788297883978849788597886978879788897889978909789197892978939789497895978969789797898978999790097901979029790397904979059790697907979089790997910979119791297913979149791597916979179791897919979209792197922979239792497925979269792797928979299793097931979329793397934979359793697937979389793997940979419794297943979449794597946979479794897949979509795197952979539795497955979569795797958979599796097961979629796397964979659796697967979689796997970979719797297973979749797597976979779797897979979809798197982979839798497985979869798797988979899799097991979929799397994979959799697997979989799998000980019800298003980049800598006980079800898009980109801198012980139801498015980169801798018980199802098021980229802398024980259802698027980289802998030980319803298033980349803598036980379803898039980409804198042980439804498045980469804798048980499805098051980529805398054980559805698057980589805998060980619806298063980649806598066980679806898069980709807198072980739807498075980769807798078980799808098081980829808398084980859808698087980889808998090980919809298093980949809598096980979809898099981009810198102981039810498105981069810798108981099811098111981129811398114981159811698117981189811998120981219812298123
  1. /* api.c API unit tests
  2. *
  3. * Copyright (C) 2006-2024 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. /* For AES-CBC, input lengths can optionally be validated to be a
  22. * multiple of the block size, by defining WOLFSSL_AES_CBC_LENGTH_CHECKS,
  23. * also available via the configure option --enable-aescbc-length-checks.
  24. */
  25. /*----------------------------------------------------------------------------*
  26. | Includes
  27. *----------------------------------------------------------------------------*/
  28. #ifdef HAVE_CONFIG_H
  29. #include <config.h>
  30. #endif
  31. #include <wolfssl/wolfcrypt/settings.h>
  32. #undef TEST_OPENSSL_COEXIST /* can't use this option with this example */
  33. #include <wolfssl/wolfcrypt/logging.h>
  34. #include <wolfssl/wolfcrypt/hash.h>
  35. #if defined(WOLFSSL_STATIC_MEMORY)
  36. #include <wolfssl/wolfcrypt/memory.h>
  37. #endif
  38. #ifdef WOLFSSL_ASNC_CRYPT
  39. #include <wolfssl/wolfcrypt/async.h>
  40. #endif
  41. #ifdef HAVE_ECC
  42. #include <wolfssl/wolfcrypt/ecc.h> /* wc_ecc_fp_free */
  43. #ifdef WOLFSSL_SM2
  44. #include <wolfssl/wolfcrypt/sm2.h>
  45. #endif
  46. #endif
  47. #ifndef NO_ASN
  48. #include <wolfssl/wolfcrypt/asn_public.h>
  49. #endif
  50. #include <stdlib.h>
  51. #include <wolfssl/ssl.h> /* compatibility layer */
  52. #include <wolfssl/error-ssl.h>
  53. #include <wolfssl/test.h>
  54. #include <tests/unit.h>
  55. #include <tests/utils.h>
  56. /* for testing compatibility layer callbacks */
  57. #include "examples/server/server.h"
  58. #ifndef NO_MD5
  59. #include <wolfssl/wolfcrypt/md5.h>
  60. #endif
  61. #ifndef NO_SHA
  62. #include <wolfssl/wolfcrypt/sha.h>
  63. #endif
  64. #ifndef NO_SHA256
  65. #include <wolfssl/wolfcrypt/sha256.h>
  66. #endif
  67. #ifdef WOLFSSL_SHA512
  68. #include <wolfssl/wolfcrypt/sha512.h>
  69. #endif
  70. #ifdef WOLFSSL_SHA384
  71. #include <wolfssl/wolfcrypt/sha512.h>
  72. #endif
  73. #ifdef WOLFSSL_SHA3
  74. #include <wolfssl/wolfcrypt/sha3.h>
  75. #endif
  76. #ifdef WOLFSSL_SM3
  77. #include <wolfssl/wolfcrypt/sm3.h>
  78. #endif
  79. #ifndef NO_AES
  80. #include <wolfssl/wolfcrypt/aes.h>
  81. #ifdef HAVE_AES_DECRYPT
  82. #include <wolfssl/wolfcrypt/wc_encrypt.h>
  83. #endif
  84. #endif
  85. #ifdef WOLFSSL_SM4
  86. #include <wolfssl/wolfcrypt/sm4.h>
  87. #endif
  88. #ifdef WOLFSSL_RIPEMD
  89. #include <wolfssl/wolfcrypt/ripemd.h>
  90. #endif
  91. #ifndef NO_DES3
  92. #include <wolfssl/wolfcrypt/des3.h>
  93. #include <wolfssl/wolfcrypt/wc_encrypt.h>
  94. #endif
  95. #ifdef WC_RC2
  96. #include <wolfssl/wolfcrypt/rc2.h>
  97. #endif
  98. #ifndef NO_HMAC
  99. #include <wolfssl/wolfcrypt/hmac.h>
  100. #endif
  101. #ifdef HAVE_CHACHA
  102. #include <wolfssl/wolfcrypt/chacha.h>
  103. #endif
  104. #ifdef HAVE_POLY1305
  105. #include <wolfssl/wolfcrypt/poly1305.h>
  106. #endif
  107. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  108. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  109. #endif
  110. #ifdef HAVE_CAMELLIA
  111. #include <wolfssl/wolfcrypt/camellia.h>
  112. #endif
  113. #ifndef NO_RC4
  114. #include <wolfssl/wolfcrypt/arc4.h>
  115. #endif
  116. #ifdef HAVE_BLAKE2
  117. #include <wolfssl/wolfcrypt/blake2.h>
  118. #endif
  119. #ifndef NO_RSA
  120. #include <wolfssl/wolfcrypt/rsa.h>
  121. #endif
  122. #ifndef NO_SIG_WRAPPER
  123. #include <wolfssl/wolfcrypt/signature.h>
  124. #endif
  125. #ifdef HAVE_AESCCM
  126. #include <wolfssl/wolfcrypt/aes.h>
  127. #endif
  128. #ifdef HAVE_PKCS7
  129. #include <wolfssl/wolfcrypt/pkcs7.h>
  130. #include <wolfssl/wolfcrypt/asn.h>
  131. #ifdef HAVE_LIBZ
  132. #include <wolfssl/wolfcrypt/compress.h>
  133. #endif
  134. #endif
  135. #ifdef WOLFSSL_SMALL_CERT_VERIFY
  136. #include <wolfssl/wolfcrypt/asn.h>
  137. #endif
  138. #ifndef NO_DSA
  139. #include <wolfssl/wolfcrypt/dsa.h>
  140. #endif
  141. #ifdef WOLFSSL_CMAC
  142. #include <wolfssl/wolfcrypt/cmac.h>
  143. #endif
  144. #ifdef HAVE_ED25519
  145. #include <wolfssl/wolfcrypt/ed25519.h>
  146. #endif
  147. #ifdef HAVE_CURVE25519
  148. #include <wolfssl/wolfcrypt/curve25519.h>
  149. #endif
  150. #ifdef HAVE_ED448
  151. #include <wolfssl/wolfcrypt/ed448.h>
  152. #endif
  153. #ifdef HAVE_CURVE448
  154. #include <wolfssl/wolfcrypt/curve448.h>
  155. #endif
  156. #ifdef WOLFSSL_HAVE_KYBER
  157. #include <wolfssl/wolfcrypt/kyber.h>
  158. #ifdef WOLFSSL_WC_KYBER
  159. #include <wolfssl/wolfcrypt/wc_kyber.h>
  160. #endif
  161. #endif
  162. #ifdef HAVE_DILITHIUM
  163. #include <wolfssl/wolfcrypt/dilithium.h>
  164. #endif
  165. #ifdef HAVE_PKCS12
  166. #include <wolfssl/wolfcrypt/pkcs12.h>
  167. #endif
  168. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  169. defined(OPENSSL_ALL)
  170. #include <wolfssl/openssl/ssl.h>
  171. #ifndef NO_ASN
  172. /* for ASN_COMMON_NAME DN_tags enum */
  173. #include <wolfssl/wolfcrypt/asn.h>
  174. #endif
  175. #ifdef HAVE_OCSP
  176. #include <wolfssl/openssl/ocsp.h>
  177. #endif
  178. #endif
  179. #ifdef OPENSSL_EXTRA
  180. #include <wolfssl/openssl/cmac.h>
  181. #include <wolfssl/openssl/x509v3.h>
  182. #include <wolfssl/openssl/asn1.h>
  183. #include <wolfssl/openssl/crypto.h>
  184. #include <wolfssl/openssl/pkcs12.h>
  185. #include <wolfssl/openssl/evp.h>
  186. #include <wolfssl/openssl/dh.h>
  187. #include <wolfssl/openssl/bn.h>
  188. #include <wolfssl/openssl/buffer.h>
  189. #include <wolfssl/openssl/pem.h>
  190. #include <wolfssl/openssl/ec.h>
  191. #include <wolfssl/openssl/ecdh.h>
  192. #include <wolfssl/openssl/engine.h>
  193. #include <wolfssl/openssl/hmac.h>
  194. #include <wolfssl/openssl/objects.h>
  195. #include <wolfssl/openssl/rand.h>
  196. #include <wolfssl/openssl/modes.h>
  197. #include <wolfssl/openssl/fips_rand.h>
  198. #include <wolfssl/openssl/kdf.h>
  199. #ifdef OPENSSL_ALL
  200. #include <wolfssl/openssl/txt_db.h>
  201. #include <wolfssl/openssl/lhash.h>
  202. #endif
  203. #ifndef NO_AES
  204. #include <wolfssl/openssl/aes.h>
  205. #endif
  206. #ifndef NO_DES3
  207. #include <wolfssl/openssl/des.h>
  208. #endif
  209. #ifndef NO_RC4
  210. #include <wolfssl/openssl/rc4.h>
  211. #endif
  212. #ifdef HAVE_ECC
  213. #include <wolfssl/openssl/ecdsa.h>
  214. #endif
  215. #ifdef HAVE_PKCS7
  216. #include <wolfssl/openssl/pkcs7.h>
  217. #endif
  218. #ifdef HAVE_CURVE25519
  219. #include <wolfssl/openssl/ec25519.h>
  220. #endif
  221. #ifdef HAVE_ED25519
  222. #include <wolfssl/openssl/ed25519.h>
  223. #endif
  224. #ifdef HAVE_CURVE448
  225. #include <wolfssl/openssl/ec448.h>
  226. #endif
  227. #ifdef HAVE_ED448
  228. #include <wolfssl/openssl/ed448.h>
  229. #endif
  230. #endif /* OPENSSL_EXTRA */
  231. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) && \
  232. !defined(NO_SHA256) && !defined(RC_NO_RNG)
  233. #include <wolfssl/wolfcrypt/srp.h>
  234. #endif
  235. #if (defined(SESSION_CERTS) && defined(TEST_PEER_CERT_CHAIN)) || \
  236. defined(HAVE_SESSION_TICKET) || (defined(OPENSSL_EXTRA) && \
  237. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)) || \
  238. defined(WOLFSSL_TEST_STATIC_BUILD) || defined(WOLFSSL_DTLS) || \
  239. defined(HAVE_ECH) || defined(HAVE_EX_DATA) || !defined(NO_SESSION_CACHE) \
  240. || !defined(WOLFSSL_NO_TLS12) || defined(WOLFSSL_TLS13)
  241. /* for testing SSL_get_peer_cert_chain, or SESSION_TICKET_HINT_DEFAULT,
  242. * for setting authKeyIdSrc in WOLFSSL_X509, or testing DTLS sequence
  243. * number tracking */
  244. #include "wolfssl/internal.h"
  245. #endif
  246. /* force enable test buffers */
  247. #ifndef USE_CERT_BUFFERS_2048
  248. #define USE_CERT_BUFFERS_2048
  249. #endif
  250. #ifndef USE_CERT_BUFFERS_256
  251. #define USE_CERT_BUFFERS_256
  252. #endif
  253. #include <wolfssl/certs_test.h>
  254. /* include misc.c here regardless of NO_INLINE, because misc.c implementations
  255. * have default (hidden) visibility, and in the absence of visibility, it's
  256. * benign to mask out the library implementation.
  257. */
  258. #define WOLFSSL_MISC_INCLUDED
  259. #include <wolfcrypt/src/misc.c>
  260. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  261. !defined(NO_RSA) && !defined(SINGLE_THREADED) && \
  262. !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT)
  263. #define HAVE_IO_TESTS_DEPENDENCIES
  264. #endif
  265. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  266. !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT) && \
  267. !defined(WOLFSSL_TIRTOS)
  268. #define HAVE_SSL_MEMIO_TESTS_DEPENDENCIES
  269. #endif
  270. #if !defined(NO_RSA) && !defined(NO_SHA) && !defined(NO_FILESYSTEM) && \
  271. !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \
  272. !defined(WOLFSSL_NO_CLIENT_AUTH))
  273. #define HAVE_CERT_CHAIN_VALIDATION
  274. #endif
  275. #ifndef WOLFSSL_HAVE_ECC_KEY_GET_PRIV
  276. /* FIPS build has replaced ecc.h. */
  277. #define wc_ecc_key_get_priv(key) (&((key)->k))
  278. #define WOLFSSL_HAVE_ECC_KEY_GET_PRIV
  279. #endif
  280. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY)
  281. #if (defined(HAVE_ECC) && !defined(ALT_ECC_SIZE)) || defined(SESSION_CERTS)
  282. #ifdef OPENSSL_EXTRA
  283. #define TEST_TLS_STATIC_MEMSZ (400000)
  284. #else
  285. #define TEST_TLS_STATIC_MEMSZ (320000)
  286. #endif
  287. #else
  288. #define TEST_TLS_STATIC_MEMSZ (80000)
  289. #endif
  290. #endif
  291. #ifdef HAVE_ECC
  292. #ifndef ECC_ASN963_MAX_BUF_SZ
  293. #define ECC_ASN963_MAX_BUF_SZ 133
  294. #endif
  295. #ifndef ECC_PRIV_KEY_BUF
  296. #define ECC_PRIV_KEY_BUF 66 /* For non user defined curves. */
  297. #endif
  298. /* ecc key sizes: 14, 16, 20, 24, 28, 30, 32, 40, 48, 64 */
  299. /* logic to choose right key ECC size */
  300. #if (defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 112
  301. #define KEY14 14
  302. #else
  303. #define KEY14 32
  304. #endif
  305. #if (defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 128
  306. #define KEY16 16
  307. #else
  308. #define KEY16 32
  309. #endif
  310. #if (defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 160
  311. #define KEY20 20
  312. #else
  313. #define KEY20 32
  314. #endif
  315. #if (defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 192
  316. #define KEY24 24
  317. #else
  318. #define KEY24 32
  319. #endif
  320. #if defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)
  321. #define KEY28 28
  322. #else
  323. #define KEY28 32
  324. #endif
  325. #if defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)
  326. #define KEY30 30
  327. #else
  328. #define KEY30 32
  329. #endif
  330. #define KEY32 32
  331. #if defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)
  332. #define KEY40 40
  333. #else
  334. #define KEY40 32
  335. #endif
  336. #if defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)
  337. #define KEY48 48
  338. #else
  339. #define KEY48 32
  340. #endif
  341. #if defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)
  342. #define KEY64 64
  343. #else
  344. #define KEY64 32
  345. #endif
  346. #if !defined(HAVE_COMP_KEY)
  347. #if !defined(NOCOMP)
  348. #define NOCOMP 0
  349. #endif
  350. #else
  351. #if !defined(COMP)
  352. #define COMP 1
  353. #endif
  354. #endif
  355. #if !defined(DER_SZ)
  356. #define DER_SZ(ks) ((ks) * 2 + 1)
  357. #endif
  358. #endif /* HAVE_ECC */
  359. #ifndef NO_DSA
  360. #ifndef DSA_SIG_SIZE
  361. #define DSA_SIG_SIZE 40
  362. #endif
  363. #ifndef MAX_DSA_PARAM_SIZE
  364. #define MAX_DSA_PARAM_SIZE 256
  365. #endif
  366. #endif
  367. #ifndef NO_RSA
  368. #define GEN_BUF 294
  369. #endif
  370. #ifndef ONEK_BUF
  371. #define ONEK_BUF 1024
  372. #endif
  373. #ifndef TWOK_BUF
  374. #define TWOK_BUF 2048
  375. #endif
  376. #ifndef FOURK_BUF
  377. #define FOURK_BUF 4096
  378. #endif
  379. #ifndef HEAP_HINT
  380. #define HEAP_HINT NULL
  381. #endif
  382. typedef struct testVector {
  383. const char* input;
  384. const char* output;
  385. size_t inLen;
  386. size_t outLen;
  387. } testVector;
  388. #if defined(HAVE_PKCS7)
  389. typedef struct {
  390. const byte* content;
  391. word32 contentSz;
  392. int contentOID;
  393. int encryptOID;
  394. int keyWrapOID;
  395. int keyAgreeOID;
  396. byte* cert;
  397. size_t certSz;
  398. byte* privateKey;
  399. word32 privateKeySz;
  400. } pkcs7EnvelopedVector;
  401. #ifndef NO_PKCS7_ENCRYPTED_DATA
  402. typedef struct {
  403. const byte* content;
  404. word32 contentSz;
  405. int contentOID;
  406. int encryptOID;
  407. byte* encryptionKey;
  408. word32 encryptionKeySz;
  409. } pkcs7EncryptedVector;
  410. #endif
  411. #endif /* HAVE_PKCS7 */
  412. typedef int (*ctx_cb)(WOLFSSL_CTX* ctx);
  413. typedef int (*ssl_cb)(WOLFSSL* ssl);
  414. typedef int (*test_cbType)(WOLFSSL_CTX *ctx, WOLFSSL *ssl);
  415. typedef int (*hs_cb)(WOLFSSL_CTX **ctx, WOLFSSL **ssl);
  416. typedef struct test_ssl_cbf {
  417. method_provider method;
  418. ctx_cb ctx_ready;
  419. ssl_cb ssl_ready;
  420. ssl_cb on_result;
  421. ctx_cb on_ctx_cleanup;
  422. ssl_cb on_cleanup;
  423. hs_cb on_handshake;
  424. WOLFSSL_CTX* ctx;
  425. const char* caPemFile;
  426. const char* certPemFile;
  427. const char* keyPemFile;
  428. const char* crlPemFile;
  429. #ifdef WOLFSSL_STATIC_MEMORY
  430. byte* mem;
  431. word32 memSz;
  432. wolfSSL_method_func method_ex;
  433. #endif
  434. int devId;
  435. int return_code;
  436. int last_err;
  437. unsigned char isSharedCtx:1;
  438. unsigned char loadToSSL:1;
  439. unsigned char ticNoInit:1;
  440. unsigned char doUdp:1;
  441. } test_ssl_cbf;
  442. #define TEST_SSL_MEMIO_BUF_SZ (64 * 1024)
  443. typedef struct test_ssl_memio_ctx {
  444. WOLFSSL_CTX* s_ctx;
  445. WOLFSSL_CTX* c_ctx;
  446. WOLFSSL* s_ssl;
  447. WOLFSSL* c_ssl;
  448. const char* c_ciphers;
  449. const char* s_ciphers;
  450. char* c_msg;
  451. int c_msglen;
  452. char* s_msg;
  453. int s_msglen;
  454. test_ssl_cbf s_cb;
  455. test_ssl_cbf c_cb;
  456. byte c_buff[TEST_SSL_MEMIO_BUF_SZ];
  457. int c_len;
  458. byte s_buff[TEST_SSL_MEMIO_BUF_SZ];
  459. int s_len;
  460. } test_ssl_memio_ctx;
  461. int test_wolfSSL_client_server_nofail_memio(test_ssl_cbf* client_cb,
  462. test_ssl_cbf* server_cb, test_cbType client_on_handshake);
  463. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  464. const char* currentTestName;
  465. char tmpDirName[16];
  466. int tmpDirNameSet = 0;
  467. #endif
  468. /*----------------------------------------------------------------------------*
  469. | Constants
  470. *----------------------------------------------------------------------------*/
  471. /* Returns the result based on whether check is true.
  472. *
  473. * @param [in] check Condition for success.
  474. * @return When condition is true: TEST_SUCCESS.
  475. * @return When condition is false: TEST_FAIL.
  476. */
  477. #ifdef DEBUG_WOLFSSL_VERBOSE
  478. #define XSTRINGIFY(s) STRINGIFY(s)
  479. #define STRINGIFY(s) #s
  480. #define TEST_RES_CHECK(check) ({ \
  481. int _ret = (check) ? TEST_SUCCESS : TEST_FAIL; \
  482. if (_ret == TEST_FAIL) { \
  483. fprintf(stderr, " check \"%s\" at %d ", \
  484. XSTRINGIFY(check), __LINE__); \
  485. } \
  486. _ret; })
  487. #else
  488. #define TEST_RES_CHECK(check) \
  489. ((check) ? TEST_SUCCESS : TEST_FAIL)
  490. #endif /* DEBUG_WOLFSSL_VERBOSE */
  491. #define TEST_STRING "Everyone gets Friday off."
  492. #define TEST_STRING_SZ 25
  493. #ifndef NO_RSA
  494. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  495. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  496. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  497. #define TEST_RSA_BITS 1024
  498. #else
  499. #define TEST_RSA_BITS 2048
  500. #endif
  501. #define TEST_RSA_BYTES (TEST_RSA_BITS/8)
  502. #endif /* !NO_RSA */
  503. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  504. (!defined(NO_WOLFSSL_SERVER) || !defined(NO_WOLFSSL_CLIENT))
  505. static const char* bogusFile =
  506. #ifdef _WIN32
  507. "NUL"
  508. #else
  509. "/dev/null"
  510. #endif
  511. ;
  512. #endif /* !NO_FILESYSTEM && !NO_CERTS && (!NO_WOLFSSL_SERVER || !NO_WOLFSSL_CLIENT) */
  513. enum {
  514. TESTING_RSA = 1,
  515. TESTING_ECC = 2
  516. };
  517. #ifdef WOLFSSL_QNX_CAAM
  518. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  519. static int testDevId = WOLFSSL_CAAM_DEVID;
  520. #else
  521. static int testDevId = INVALID_DEVID;
  522. #endif
  523. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  524. !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT)
  525. /* This set of memio functions allows for more fine tuned control of the TLS
  526. * connection operations. For new tests, try to use ssl_memio first. */
  527. /* To dump the memory in gdb use
  528. * dump memory client.bin test_ctx.c_buff test_ctx.c_buff+test_ctx.c_len
  529. * dump memory server.bin test_ctx.s_buff test_ctx.s_buff+test_ctx.s_len
  530. * This can be imported into Wireshark by transforming the file with
  531. * od -Ax -tx1 -v client.bin > client.bin.hex
  532. * od -Ax -tx1 -v server.bin > server.bin.hex
  533. * And then loading test_output.dump.hex into Wireshark using the
  534. * "Import from Hex Dump..." option ion and selecting the TCP
  535. * encapsulation option.
  536. */
  537. #define HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES
  538. static WC_INLINE int test_memio_write_cb(WOLFSSL *ssl, char *data, int sz,
  539. void *ctx)
  540. {
  541. struct test_memio_ctx *test_ctx;
  542. byte *buf;
  543. int *len;
  544. test_ctx = (struct test_memio_ctx*)ctx;
  545. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  546. buf = test_ctx->c_buff;
  547. len = &test_ctx->c_len;
  548. }
  549. else {
  550. buf = test_ctx->s_buff;
  551. len = &test_ctx->s_len;
  552. }
  553. if ((unsigned)(*len + sz) > TEST_MEMIO_BUF_SZ)
  554. return WOLFSSL_CBIO_ERR_WANT_WRITE;
  555. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  556. {
  557. char dump_file_name[64];
  558. WOLFSSL_BIO *dump_file;
  559. sprintf(dump_file_name, "%s/%s.dump", tmpDirName, currentTestName);
  560. dump_file = wolfSSL_BIO_new_file(dump_file_name, "a");
  561. if (dump_file != NULL) {
  562. (void)wolfSSL_BIO_write(dump_file, data, sz);
  563. wolfSSL_BIO_free(dump_file);
  564. }
  565. }
  566. #endif
  567. XMEMCPY(buf + *len, data, (size_t)sz);
  568. *len += sz;
  569. return sz;
  570. }
  571. static WC_INLINE int test_memio_read_cb(WOLFSSL *ssl, char *data, int sz,
  572. void *ctx)
  573. {
  574. struct test_memio_ctx *test_ctx;
  575. int read_sz;
  576. byte *buf;
  577. int *len;
  578. test_ctx = (struct test_memio_ctx*)ctx;
  579. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  580. buf = test_ctx->s_buff;
  581. len = &test_ctx->s_len;
  582. }
  583. else {
  584. buf = test_ctx->c_buff;
  585. len = &test_ctx->c_len;
  586. }
  587. if (*len == 0)
  588. return WOLFSSL_CBIO_ERR_WANT_READ;
  589. read_sz = sz < *len ? sz : *len;
  590. XMEMCPY(data, buf, (size_t)read_sz);
  591. XMEMMOVE(buf, buf + read_sz,(size_t) (*len - read_sz));
  592. *len -= read_sz;
  593. return read_sz;
  594. }
  595. int test_memio_do_handshake(WOLFSSL *ssl_c, WOLFSSL *ssl_s,
  596. int max_rounds, int *rounds)
  597. {
  598. byte handshake_complete = 0, hs_c = 0, hs_s = 0;
  599. int ret, err;
  600. if (rounds != NULL)
  601. *rounds = 0;
  602. while (!handshake_complete && max_rounds > 0) {
  603. if (!hs_c) {
  604. wolfSSL_SetLoggingPrefix("client");
  605. ret = wolfSSL_connect(ssl_c);
  606. wolfSSL_SetLoggingPrefix(NULL);
  607. if (ret == WOLFSSL_SUCCESS) {
  608. hs_c = 1;
  609. }
  610. else {
  611. err = wolfSSL_get_error(ssl_c, ret);
  612. if (err != WOLFSSL_ERROR_WANT_READ &&
  613. err != WOLFSSL_ERROR_WANT_WRITE)
  614. return -1;
  615. }
  616. }
  617. if (!hs_s) {
  618. wolfSSL_SetLoggingPrefix("server");
  619. ret = wolfSSL_accept(ssl_s);
  620. wolfSSL_SetLoggingPrefix(NULL);
  621. if (ret == WOLFSSL_SUCCESS) {
  622. hs_s = 1;
  623. }
  624. else {
  625. err = wolfSSL_get_error(ssl_s, ret);
  626. if (err != WOLFSSL_ERROR_WANT_READ &&
  627. err != WOLFSSL_ERROR_WANT_WRITE)
  628. return -1;
  629. }
  630. }
  631. handshake_complete = hs_c && hs_s;
  632. max_rounds--;
  633. if (rounds != NULL)
  634. *rounds = *rounds + 1;
  635. }
  636. if (!handshake_complete)
  637. return -1;
  638. return 0;
  639. }
  640. int test_memio_setup_ex(struct test_memio_ctx *ctx,
  641. WOLFSSL_CTX **ctx_c, WOLFSSL_CTX **ctx_s, WOLFSSL **ssl_c, WOLFSSL **ssl_s,
  642. method_provider method_c, method_provider method_s,
  643. byte *caCert, int caCertSz, byte *serverCert, int serverCertSz,
  644. byte *serverKey, int serverKeySz)
  645. {
  646. int ret;
  647. (void)caCert;
  648. (void)caCertSz;
  649. (void)serverCert;
  650. (void)serverCertSz;
  651. (void)serverKey;
  652. (void)serverKeySz;
  653. if (ctx_c != NULL && *ctx_c == NULL) {
  654. *ctx_c = wolfSSL_CTX_new(method_c());
  655. if (*ctx_c == NULL)
  656. return -1;
  657. #ifndef NO_CERTS
  658. if (caCert == NULL) {
  659. ret = wolfSSL_CTX_load_verify_locations(*ctx_c, caCertFile, 0);
  660. }
  661. else {
  662. ret = wolfSSL_CTX_load_verify_buffer(*ctx_c, caCert, (long)caCertSz,
  663. WOLFSSL_FILETYPE_ASN1);
  664. }
  665. if (ret != WOLFSSL_SUCCESS)
  666. return -1;
  667. #endif /* NO_CERTS */
  668. wolfSSL_SetIORecv(*ctx_c, test_memio_read_cb);
  669. wolfSSL_SetIOSend(*ctx_c, test_memio_write_cb);
  670. if (ctx->c_ciphers != NULL) {
  671. ret = wolfSSL_CTX_set_cipher_list(*ctx_c, ctx->c_ciphers);
  672. if (ret != WOLFSSL_SUCCESS)
  673. return -1;
  674. }
  675. }
  676. if (ctx_s != NULL && *ctx_s == NULL) {
  677. *ctx_s = wolfSSL_CTX_new(method_s());
  678. if (*ctx_s == NULL)
  679. return -1;
  680. #ifndef NO_CERTS
  681. if (serverKey == NULL) {
  682. ret = wolfSSL_CTX_use_PrivateKey_file(*ctx_s, svrKeyFile,
  683. WOLFSSL_FILETYPE_PEM);
  684. }
  685. else {
  686. ret = wolfSSL_CTX_use_PrivateKey_buffer(*ctx_s, serverKey,
  687. (long)serverKeySz, WOLFSSL_FILETYPE_ASN1);
  688. }
  689. if (ret != WOLFSSL_SUCCESS)
  690. return- -1;
  691. if (serverCert == NULL) {
  692. ret = wolfSSL_CTX_use_certificate_file(*ctx_s, svrCertFile,
  693. WOLFSSL_FILETYPE_PEM);
  694. }
  695. else {
  696. ret = wolfSSL_CTX_use_certificate_chain_buffer_format(*ctx_s,
  697. serverCert, (long)serverCertSz, WOLFSSL_FILETYPE_ASN1);
  698. }
  699. if (ret != WOLFSSL_SUCCESS)
  700. return -1;
  701. #endif /* NO_CERTS */
  702. wolfSSL_SetIORecv(*ctx_s, test_memio_read_cb);
  703. wolfSSL_SetIOSend(*ctx_s, test_memio_write_cb);
  704. if (ctx->s_ciphers != NULL) {
  705. ret = wolfSSL_CTX_set_cipher_list(*ctx_s, ctx->s_ciphers);
  706. if (ret != WOLFSSL_SUCCESS)
  707. return -1;
  708. }
  709. }
  710. if (ctx_c != NULL && ssl_c != NULL) {
  711. *ssl_c = wolfSSL_new(*ctx_c);
  712. if (*ssl_c == NULL)
  713. return -1;
  714. wolfSSL_SetIOWriteCtx(*ssl_c, ctx);
  715. wolfSSL_SetIOReadCtx(*ssl_c, ctx);
  716. }
  717. if (ctx_s != NULL && ssl_s != NULL) {
  718. *ssl_s = wolfSSL_new(*ctx_s);
  719. if (*ssl_s == NULL)
  720. return -1;
  721. wolfSSL_SetIOWriteCtx(*ssl_s, ctx);
  722. wolfSSL_SetIOReadCtx(*ssl_s, ctx);
  723. #if !defined(NO_DH)
  724. SetDH(*ssl_s);
  725. #endif
  726. }
  727. return 0;
  728. }
  729. int test_memio_setup(struct test_memio_ctx *ctx,
  730. WOLFSSL_CTX **ctx_c, WOLFSSL_CTX **ctx_s, WOLFSSL **ssl_c, WOLFSSL **ssl_s,
  731. method_provider method_c, method_provider method_s)
  732. {
  733. return test_memio_setup_ex(ctx, ctx_c, ctx_s, ssl_c, ssl_s, method_c,
  734. method_s, NULL, 0, NULL, 0, NULL, 0);
  735. }
  736. #endif
  737. /*----------------------------------------------------------------------------*
  738. | BIO with fixed read/write size
  739. *----------------------------------------------------------------------------*/
  740. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  741. static int wolfssl_bio_s_fixed_mem_write(WOLFSSL_BIO* bio, const char* data,
  742. int len)
  743. {
  744. if ((bio == NULL) || (bio->ptr.mem_buf_data == NULL) || (data == NULL)) {
  745. len = 0;
  746. }
  747. else {
  748. if (bio->wrSz - bio->wrIdx < len) {
  749. len = bio->wrSz - bio->wrIdx;
  750. }
  751. XMEMCPY(bio->ptr.mem_buf_data + bio->wrIdx, data, len);
  752. bio->wrIdx += len;
  753. }
  754. return len;
  755. }
  756. static int wolfssl_bio_s_fixed_mem_read(WOLFSSL_BIO* bio, char* data, int len)
  757. {
  758. if ((bio == NULL) || (bio->ptr.mem_buf_data == NULL) || (data == NULL)) {
  759. len = 0;
  760. }
  761. else {
  762. if (bio->wrSz - bio->rdIdx < len) {
  763. len = bio->wrSz - bio->rdIdx;
  764. }
  765. XMEMCPY(data, bio->ptr.mem_buf_data + bio->rdIdx, len);
  766. bio->rdIdx += len;
  767. }
  768. return len;
  769. }
  770. static WOLFSSL_BIO_METHOD* wolfSSL_BIO_s_fixed_mem(void)
  771. {
  772. static WOLFSSL_BIO_METHOD meth;
  773. meth.type = WOLFSSL_BIO_BIO;
  774. XMEMCPY(meth.name, "Fixed Memory Size", 18);
  775. meth.writeCb = wolfssl_bio_s_fixed_mem_write;
  776. meth.readCb = wolfssl_bio_s_fixed_mem_read;
  777. return &meth;
  778. }
  779. #endif
  780. /*----------------------------------------------------------------------------*
  781. | Setup
  782. *----------------------------------------------------------------------------*/
  783. static int test_wolfSSL_Init(void)
  784. {
  785. EXPECT_DECLS;
  786. ExpectIntEQ(wolfSSL_Init(), WOLFSSL_SUCCESS);
  787. return EXPECT_RESULT();
  788. }
  789. static int test_wolfSSL_Cleanup(void)
  790. {
  791. EXPECT_DECLS;
  792. ExpectIntEQ(wolfSSL_Cleanup(), WOLFSSL_SUCCESS);
  793. return EXPECT_RESULT();
  794. }
  795. /* Initialize the wolfCrypt state.
  796. * POST: 0 success.
  797. */
  798. static int test_wolfCrypt_Init(void)
  799. {
  800. EXPECT_DECLS;
  801. ExpectIntEQ(wolfCrypt_Init(), 0);
  802. return EXPECT_RESULT();
  803. } /* END test_wolfCrypt_Init */
  804. static int test_wolfCrypt_Cleanup(void)
  805. {
  806. EXPECT_DECLS;
  807. ExpectIntEQ(wolfCrypt_Cleanup(), 0);
  808. return EXPECT_RESULT();
  809. }
  810. #ifdef WOLFSSL_STATIC_MEMORY
  811. #define TEST_LSM_STATIC_SIZE 440000
  812. /* Create new bucket list, using the default list, adding
  813. * one dang large buffer size. */
  814. #define TEST_LSM_DEF_BUCKETS (WOLFMEM_DEF_BUCKETS+1)
  815. #define TEST_LSM_BUCKETS WOLFMEM_BUCKETS,(LARGEST_MEM_BUCKET*2)
  816. #define TEST_LSM_DIST WOLFMEM_DIST,1
  817. #endif
  818. static int test_wc_LoadStaticMemory_ex(void)
  819. {
  820. EXPECT_DECLS;
  821. #ifdef WOLFSSL_STATIC_MEMORY
  822. byte staticMemory[TEST_LSM_STATIC_SIZE];
  823. word32 sizeList[TEST_LSM_DEF_BUCKETS] = { TEST_LSM_BUCKETS };
  824. word32 distList[TEST_LSM_DEF_BUCKETS] = { TEST_LSM_DIST };
  825. WOLFSSL_HEAP_HINT* heap;
  826. /* For this test, the size and dist lists will be the ones configured
  827. * for the build, or default. The value of WOLFMEM_DEF_BUCKETS is 9,
  828. * so these lists are 10 long. For most tests, the value of
  829. * WOLFMEM_DEF_BUCKETS is used. There's a test case where one is added
  830. * to that, to make sure the list size is larger than
  831. * WOLFMEM_MAX_BUCKETS. */
  832. /* Pass in zero everything. */
  833. ExpectIntEQ(wc_LoadStaticMemory_ex(NULL, 0, NULL, NULL, NULL, 0, 0, 0),
  834. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  835. /* Set the heap pointer to NULL. */
  836. ExpectIntEQ(wc_LoadStaticMemory_ex(NULL,
  837. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  838. staticMemory, (word32)sizeof(staticMemory),
  839. 0, 1),
  840. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  841. /* Set other pointer values to NULL one at a time. */
  842. heap = NULL;
  843. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  844. WOLFMEM_DEF_BUCKETS, NULL, distList,
  845. staticMemory, (word32)sizeof(staticMemory),
  846. 0, 1),
  847. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  848. heap = NULL;
  849. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  850. WOLFMEM_DEF_BUCKETS, sizeList, NULL,
  851. staticMemory, (word32)sizeof(staticMemory),
  852. 0, 1),
  853. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  854. heap = NULL;
  855. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  856. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  857. NULL, (word32)sizeof(staticMemory),
  858. 0, 1),
  859. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  860. /* Set the size of the static buffer to 0. */
  861. heap = NULL;
  862. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  863. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  864. staticMemory, 0,
  865. 0, 1),
  866. WC_NO_ERR_TRACE(BUFFER_E));
  867. /* Set the size of the static buffer to one less than minimum allowed. */
  868. heap = NULL;
  869. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  870. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  871. staticMemory,
  872. (word32)(sizeof(WOLFSSL_HEAP) + sizeof(WOLFSSL_HEAP_HINT)) - 1,
  873. 0, 1),
  874. WC_NO_ERR_TRACE(BUFFER_E));
  875. /* Set the size of the static buffer to exactly the minimum size. */
  876. heap = NULL;
  877. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  878. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  879. staticMemory,
  880. (word32)(sizeof(WOLFSSL_HEAP) + sizeof(WOLFSSL_HEAP_HINT)),
  881. 0, 1),
  882. 0);
  883. wc_UnloadStaticMemory(heap);
  884. /* Use more buckets than able. Success case. */
  885. heap = NULL;
  886. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  887. WOLFMEM_DEF_BUCKETS*2, sizeList, distList,
  888. staticMemory, (word32)sizeof(staticMemory),
  889. 0, 1),
  890. 0);
  891. wc_UnloadStaticMemory(heap);
  892. /* Success case. */
  893. heap = NULL;
  894. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  895. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  896. staticMemory, (word32)sizeof(staticMemory),
  897. 0, 1),
  898. 0);
  899. wc_UnloadStaticMemory(heap);
  900. #endif /* WOLFSSL_STATIC_MEMORY */
  901. return EXPECT_RESULT();
  902. }
  903. /*----------------------------------------------------------------------------*
  904. | Platform dependent function test
  905. *----------------------------------------------------------------------------*/
  906. static int test_fileAccess(void)
  907. {
  908. EXPECT_DECLS;
  909. #if defined(WOLFSSL_TEST_PLATFORMDEPEND) && !defined(NO_FILESYSTEM)
  910. const char *fname[] = {
  911. svrCertFile, svrKeyFile, caCertFile,
  912. eccCertFile, eccKeyFile, eccRsaCertFile,
  913. cliCertFile, cliCertDerFile, cliKeyFile,
  914. dhParamFile,
  915. cliEccKeyFile, cliEccCertFile, caEccCertFile, edCertFile, edKeyFile,
  916. cliEdCertFile, cliEdKeyFile, caEdCertFile,
  917. NULL
  918. };
  919. const char derfile[] = "./certs/server-cert.der";
  920. XFILE f = XBADFILE;
  921. size_t sz;
  922. byte *buff = NULL;
  923. int i;
  924. ExpectTrue(XFOPEN("badfilename", "rb") == XBADFILE);
  925. for (i=0; EXPECT_SUCCESS() && fname[i] != NULL ; i++) {
  926. ExpectTrue((f = XFOPEN(fname[i], "rb")) != XBADFILE);
  927. XFCLOSE(f);
  928. }
  929. ExpectTrue((f = XFOPEN(derfile, "rb")) != XBADFILE);
  930. ExpectTrue(XFSEEK(f, 0, XSEEK_END) == 0);
  931. ExpectIntGE(sz = (size_t) XFTELL(f), sizeof_server_cert_der_2048);
  932. ExpectTrue(XFSEEK(f, 0, XSEEK_SET) == 0);
  933. ExpectTrue((buff = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE)) != NULL);
  934. ExpectTrue(XFREAD(buff, 1, sz, f) == sz);
  935. ExpectIntEQ(XMEMCMP(server_cert_der_2048, buff, sz), 0);
  936. XFREE(buff, NULL, DYNAMIC_TYPE_FILE);
  937. XFCLOSE(f);
  938. #endif
  939. return EXPECT_RESULT();
  940. }
  941. /*----------------------------------------------------------------------------*
  942. | Method Allocators
  943. *----------------------------------------------------------------------------*/
  944. static int test_wolfSSL_Method_Allocators(void)
  945. {
  946. EXPECT_DECLS;
  947. #define TEST_METHOD_ALLOCATOR(allocator, condition) \
  948. do { \
  949. WOLFSSL_METHOD *method = NULL; \
  950. condition(method = allocator()); \
  951. XFREE(method, 0, DYNAMIC_TYPE_METHOD); \
  952. } while (0)
  953. #define TEST_VALID_METHOD_ALLOCATOR(a) \
  954. TEST_METHOD_ALLOCATOR(a, ExpectNotNull)
  955. #define TEST_INVALID_METHOD_ALLOCATOR(a) \
  956. TEST_METHOD_ALLOCATOR(a, ExpectNull)
  957. #ifndef NO_OLD_TLS
  958. #ifdef WOLFSSL_ALLOW_SSLV3
  959. #ifndef NO_WOLFSSL_SERVER
  960. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv3_server_method);
  961. #endif
  962. #ifndef NO_WOLFSSL_CLIENT
  963. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv3_client_method);
  964. #endif
  965. #endif
  966. #ifdef WOLFSSL_ALLOW_TLSV10
  967. #ifndef NO_WOLFSSL_SERVER
  968. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_server_method);
  969. #endif
  970. #ifndef NO_WOLFSSL_CLIENT
  971. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_client_method);
  972. #endif
  973. #endif
  974. #ifndef NO_WOLFSSL_SERVER
  975. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_1_server_method);
  976. #endif
  977. #ifndef NO_WOLFSSL_CLIENT
  978. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_1_client_method);
  979. #endif
  980. #endif /* !NO_OLD_TLS */
  981. #ifndef WOLFSSL_NO_TLS12
  982. #ifndef NO_WOLFSSL_SERVER
  983. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_2_server_method);
  984. #endif
  985. #ifndef NO_WOLFSSL_CLIENT
  986. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_2_client_method);
  987. #endif
  988. #endif /* !WOLFSSL_NO_TLS12 */
  989. #ifdef WOLFSSL_TLS13
  990. #ifndef NO_WOLFSSL_SERVER
  991. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_3_server_method);
  992. #endif
  993. #ifndef NO_WOLFSSL_CLIENT
  994. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_3_client_method);
  995. #endif
  996. #endif /* WOLFSSL_TLS13 */
  997. #ifndef NO_WOLFSSL_SERVER
  998. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv23_server_method);
  999. #endif
  1000. #ifndef NO_WOLFSSL_CLIENT
  1001. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv23_client_method);
  1002. #endif
  1003. #ifdef WOLFSSL_DTLS
  1004. #ifndef NO_OLD_TLS
  1005. #ifndef NO_WOLFSSL_SERVER
  1006. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_server_method);
  1007. #endif
  1008. #ifndef NO_WOLFSSL_CLIENT
  1009. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_client_method);
  1010. #endif
  1011. #endif
  1012. #ifndef WOLFSSL_NO_TLS12
  1013. #ifndef NO_WOLFSSL_SERVER
  1014. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_2_server_method);
  1015. #endif
  1016. #ifndef NO_WOLFSSL_CLIENT
  1017. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_2_client_method);
  1018. #endif
  1019. #endif
  1020. #endif /* WOLFSSL_DTLS */
  1021. #if !defined(NO_OLD_TLS) && defined(OPENSSL_EXTRA)
  1022. /* Stubs */
  1023. #ifndef NO_WOLFSSL_SERVER
  1024. TEST_INVALID_METHOD_ALLOCATOR(wolfSSLv2_server_method);
  1025. #endif
  1026. #ifndef NO_WOLFSSL_CLIENT
  1027. TEST_INVALID_METHOD_ALLOCATOR(wolfSSLv2_client_method);
  1028. #endif
  1029. #endif
  1030. /* Test Either Method (client or server) */
  1031. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  1032. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv23_method);
  1033. #ifndef NO_OLD_TLS
  1034. #ifdef WOLFSSL_ALLOW_TLSV10
  1035. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_method);
  1036. #endif
  1037. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_1_method);
  1038. #endif /* !NO_OLD_TLS */
  1039. #ifndef WOLFSSL_NO_TLS12
  1040. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_2_method);
  1041. #endif /* !WOLFSSL_NO_TLS12 */
  1042. #ifdef WOLFSSL_TLS13
  1043. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_3_method);
  1044. #endif /* WOLFSSL_TLS13 */
  1045. #ifdef WOLFSSL_DTLS
  1046. TEST_VALID_METHOD_ALLOCATOR(wolfDTLS_method);
  1047. #ifndef NO_OLD_TLS
  1048. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_method);
  1049. #endif /* !NO_OLD_TLS */
  1050. #ifndef WOLFSSL_NO_TLS12
  1051. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_2_method);
  1052. #endif /* !WOLFSSL_NO_TLS12 */
  1053. #ifdef WOLFSSL_DTLS13
  1054. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_3_method);
  1055. #endif /* WOLFSSL_DTLS13 */
  1056. #endif /* WOLFSSL_DTLS */
  1057. #endif /* OPENSSL_EXTRA || WOLFSSL_EITHER_SIDE */
  1058. return EXPECT_RESULT();
  1059. }
  1060. #if defined(WOLFSSL_DUAL_ALG_CERTS) && !defined(NO_FILESYSTEM)
  1061. /*----------------------------------------------------------------------------*
  1062. | Dual algorithm Certificate Tests
  1063. *----------------------------------------------------------------------------*/
  1064. #define LARGE_TEMP_SZ 4096
  1065. /* To better understand this, please see the X9.146 example in wolfssl-examples
  1066. * repo. */
  1067. static int do_dual_alg_root_certgen(byte **out, char *caKeyFile,
  1068. char *sapkiFile, char *altPrivFile)
  1069. {
  1070. EXPECT_DECLS;
  1071. FILE* file = NULL;
  1072. Cert newCert;
  1073. DecodedCert preTBS;
  1074. byte caKeyBuf[LARGE_TEMP_SZ];
  1075. word32 caKeySz = LARGE_TEMP_SZ;
  1076. byte sapkiBuf[LARGE_TEMP_SZ];
  1077. word32 sapkiSz = LARGE_TEMP_SZ;
  1078. byte altPrivBuf[LARGE_TEMP_SZ];
  1079. word32 altPrivSz = LARGE_TEMP_SZ;
  1080. byte altSigAlgBuf[LARGE_TEMP_SZ];
  1081. word32 altSigAlgSz = LARGE_TEMP_SZ;
  1082. byte scratchBuf[LARGE_TEMP_SZ];
  1083. word32 scratchSz = LARGE_TEMP_SZ;
  1084. byte preTbsBuf[LARGE_TEMP_SZ];
  1085. word32 preTbsSz = LARGE_TEMP_SZ;
  1086. byte altSigValBuf[LARGE_TEMP_SZ];
  1087. word32 altSigValSz = LARGE_TEMP_SZ;
  1088. byte *outBuf = NULL;
  1089. word32 outSz = LARGE_TEMP_SZ;
  1090. WC_RNG rng;
  1091. RsaKey caKey;
  1092. ecc_key altCaKey;
  1093. word32 idx = 0;
  1094. XMEMSET(&rng, 0, sizeof(WC_RNG));
  1095. XMEMSET(&caKey, 0, sizeof(RsaKey));
  1096. XMEMSET(&altCaKey, 0, sizeof(ecc_key));
  1097. ExpectNotNull(outBuf = (byte*)XMALLOC(outSz, NULL,
  1098. DYNAMIC_TYPE_TMP_BUFFER));
  1099. ExpectIntEQ(wc_InitRng(&rng), 0);
  1100. XMEMSET(caKeyBuf, 0, caKeySz);
  1101. ExpectNotNull(file = fopen(caKeyFile, "rb"));
  1102. ExpectIntGT(caKeySz = (word32)fread(caKeyBuf, 1, caKeySz, file), 0);
  1103. if (file) {
  1104. fclose(file);
  1105. file = NULL;
  1106. }
  1107. ExpectIntEQ(wc_InitRsaKey_ex(&caKey, NULL, INVALID_DEVID), 0);
  1108. idx = 0;
  1109. ExpectIntEQ(wc_RsaPrivateKeyDecode(caKeyBuf, &idx, &caKey, caKeySz),
  1110. 0);
  1111. XMEMSET(sapkiBuf, 0, sapkiSz);
  1112. ExpectNotNull(file = fopen(sapkiFile, "rb"));
  1113. ExpectIntGT(sapkiSz = (word32)fread(sapkiBuf, 1, sapkiSz, file), 0);
  1114. if (file) {
  1115. fclose(file);
  1116. file = NULL;
  1117. }
  1118. XMEMSET(altPrivBuf, 0, altPrivSz);
  1119. ExpectNotNull(file = fopen(altPrivFile, "rb"));
  1120. ExpectIntGT(altPrivSz = (word32)fread(altPrivBuf, 1, altPrivSz, file), 0);
  1121. if (file) {
  1122. fclose(file);
  1123. file = NULL;
  1124. }
  1125. wc_ecc_init(&altCaKey);
  1126. idx = 0;
  1127. ExpectIntEQ(wc_EccPrivateKeyDecode(altPrivBuf, &idx, &altCaKey,
  1128. (word32)altPrivSz), 0);
  1129. XMEMSET(altSigAlgBuf, 0, altSigAlgSz);
  1130. ExpectIntGT(altSigAlgSz = SetAlgoID(CTC_SHA256wECDSA, altSigAlgBuf,
  1131. oidSigType, 0), 0);
  1132. wc_InitCert(&newCert);
  1133. strncpy(newCert.subject.country, "US", CTC_NAME_SIZE);
  1134. strncpy(newCert.subject.state, "MT", CTC_NAME_SIZE);
  1135. strncpy(newCert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  1136. strncpy(newCert.subject.org, "wolfSSL", CTC_NAME_SIZE);
  1137. strncpy(newCert.subject.unit, "Engineering", CTC_NAME_SIZE);
  1138. strncpy(newCert.subject.commonName, "www.wolfssl.com", CTC_NAME_SIZE);
  1139. strncpy(newCert.subject.email, "root@wolfssl.com", CTC_NAME_SIZE);
  1140. newCert.sigType = CTC_SHA256wRSA;
  1141. newCert.isCA = 1;
  1142. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "1.2.3.4.5",
  1143. (const byte *)"This is NOT a critical extension", 32), 0);
  1144. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.72", sapkiBuf,
  1145. sapkiSz), 0);
  1146. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.73", altSigAlgBuf,
  1147. altSigAlgSz), 0);
  1148. XMEMSET(scratchBuf, 0, scratchSz);
  1149. ExpectIntGT(scratchSz = wc_MakeSelfCert(&newCert, scratchBuf, scratchSz,
  1150. &caKey, &rng), 0);
  1151. wc_InitDecodedCert(&preTBS, scratchBuf, scratchSz, 0);
  1152. ExpectIntEQ(wc_ParseCert(&preTBS, CERT_TYPE, NO_VERIFY, NULL), 0);
  1153. XMEMSET(preTbsBuf, 0, preTbsSz);
  1154. ExpectIntGT(preTbsSz = wc_GeneratePreTBS(&preTBS, preTbsBuf, preTbsSz), 0);
  1155. XMEMSET(altSigValBuf, 0, altSigValSz);
  1156. ExpectIntGT(altSigValSz = wc_MakeSigWithBitStr(altSigValBuf, altSigValSz,
  1157. CTC_SHA256wECDSA, preTbsBuf, preTbsSz, ECC_TYPE, &altCaKey,
  1158. &rng), 0);
  1159. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.74", altSigValBuf,
  1160. altSigValSz), 0);
  1161. /* Finally, generate the new certificate. */
  1162. if (outBuf != NULL) {
  1163. XMEMSET(outBuf, 0, outSz);
  1164. }
  1165. ExpectIntGT(outSz = wc_MakeSelfCert(&newCert, outBuf, outSz, &caKey, &rng),
  1166. 0);
  1167. *out = outBuf;
  1168. wc_FreeRsaKey(&caKey);
  1169. wc_FreeRng(&rng);
  1170. wc_FreeDecodedCert(&preTBS);
  1171. return outSz;
  1172. }
  1173. static int do_dual_alg_server_certgen(byte **out, char *caKeyFile,
  1174. char *sapkiFile, char *altPrivFile,
  1175. char *serverKeyFile,
  1176. byte *caCertBuf, int caCertSz)
  1177. {
  1178. EXPECT_DECLS;
  1179. FILE* file = NULL;
  1180. Cert newCert;
  1181. DecodedCert preTBS;
  1182. byte serverKeyBuf[LARGE_TEMP_SZ];
  1183. word32 serverKeySz = LARGE_TEMP_SZ;
  1184. byte caKeyBuf[LARGE_TEMP_SZ];
  1185. word32 caKeySz = LARGE_TEMP_SZ;
  1186. byte sapkiBuf[LARGE_TEMP_SZ];
  1187. word32 sapkiSz = LARGE_TEMP_SZ;
  1188. byte altPrivBuf[LARGE_TEMP_SZ];
  1189. word32 altPrivSz = LARGE_TEMP_SZ;
  1190. byte altSigAlgBuf[LARGE_TEMP_SZ];
  1191. word32 altSigAlgSz = LARGE_TEMP_SZ;
  1192. byte scratchBuf[LARGE_TEMP_SZ];
  1193. word32 scratchSz = LARGE_TEMP_SZ;
  1194. byte preTbsBuf[LARGE_TEMP_SZ];
  1195. word32 preTbsSz = LARGE_TEMP_SZ;
  1196. byte altSigValBuf[LARGE_TEMP_SZ];
  1197. word32 altSigValSz = LARGE_TEMP_SZ;
  1198. byte *outBuf = NULL;
  1199. word32 outSz = LARGE_TEMP_SZ;
  1200. WC_RNG rng;
  1201. RsaKey caKey;
  1202. RsaKey serverKey;
  1203. ecc_key altCaKey;
  1204. word32 idx = 0;
  1205. XMEMSET(&rng, 0, sizeof(WC_RNG));
  1206. XMEMSET(&caKey, 0, sizeof(RsaKey));
  1207. XMEMSET(&serverKey, 0, sizeof(RsaKey));
  1208. XMEMSET(&altCaKey, 0, sizeof(ecc_key));
  1209. ExpectNotNull(outBuf = (byte*)XMALLOC(outSz, NULL,
  1210. DYNAMIC_TYPE_TMP_BUFFER));
  1211. ExpectIntEQ(wc_InitRng(&rng), 0);
  1212. XMEMSET(serverKeyBuf, 0, serverKeySz);
  1213. ExpectNotNull(file = fopen(serverKeyFile, "rb"));
  1214. ExpectIntGT(serverKeySz = (word32)fread(serverKeyBuf, 1, serverKeySz, file),
  1215. 0);
  1216. if (file) {
  1217. fclose(file);
  1218. file = NULL;
  1219. }
  1220. ExpectIntEQ(wc_InitRsaKey_ex(&serverKey, NULL, INVALID_DEVID), 0);
  1221. idx = 0;
  1222. ExpectIntEQ(wc_RsaPrivateKeyDecode(serverKeyBuf, &idx, &serverKey,
  1223. (word32)serverKeySz), 0);
  1224. XMEMSET(caKeyBuf, 0, caKeySz);
  1225. ExpectNotNull(file = fopen(caKeyFile, "rb"));
  1226. ExpectIntGT(caKeySz = (word32)fread(caKeyBuf, 1, caKeySz, file), 0);
  1227. if (file) {
  1228. fclose(file);
  1229. file = NULL;
  1230. }
  1231. ExpectIntEQ(wc_InitRsaKey_ex(&caKey, NULL, INVALID_DEVID), 0);
  1232. idx = 0;
  1233. ExpectIntEQ(wc_RsaPrivateKeyDecode(caKeyBuf, &idx, &caKey,
  1234. (word32)caKeySz), 0);
  1235. XMEMSET(sapkiBuf, 0, sapkiSz);
  1236. ExpectNotNull(file = fopen(sapkiFile, "rb"));
  1237. ExpectIntGT(sapkiSz = (word32)fread(sapkiBuf, 1, sapkiSz, file), 0);
  1238. if (file) {
  1239. fclose(file);
  1240. file = NULL;
  1241. }
  1242. XMEMSET(altPrivBuf, 0, altPrivSz);
  1243. ExpectNotNull(file = fopen(altPrivFile, "rb"));
  1244. ExpectIntGT(altPrivSz = (word32)fread(altPrivBuf, 1, altPrivSz, file), 0);
  1245. if (file) {
  1246. fclose(file);
  1247. file = NULL;
  1248. }
  1249. wc_ecc_init(&altCaKey);
  1250. idx = 0;
  1251. ExpectIntEQ(wc_EccPrivateKeyDecode(altPrivBuf, &idx, &altCaKey,
  1252. (word32)altPrivSz), 0);
  1253. XMEMSET(altSigAlgBuf, 0, altSigAlgSz);
  1254. ExpectIntGT(altSigAlgSz = SetAlgoID(CTC_SHA256wECDSA, altSigAlgBuf,
  1255. oidSigType, 0), 0);
  1256. wc_InitCert(&newCert);
  1257. strncpy(newCert.subject.country, "US", CTC_NAME_SIZE);
  1258. strncpy(newCert.subject.state, "MT", CTC_NAME_SIZE);
  1259. strncpy(newCert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  1260. strncpy(newCert.subject.org, "wolfSSL", CTC_NAME_SIZE);
  1261. strncpy(newCert.subject.unit, "Engineering", CTC_NAME_SIZE);
  1262. strncpy(newCert.subject.commonName, "www.wolfssl.com", CTC_NAME_SIZE);
  1263. strncpy(newCert.subject.email, "server@wolfssl.com", CTC_NAME_SIZE);
  1264. newCert.sigType = CTC_SHA256wRSA;
  1265. newCert.isCA = 0;
  1266. ExpectIntEQ(wc_SetIssuerBuffer(&newCert, caCertBuf, caCertSz), 0);
  1267. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.72", sapkiBuf,
  1268. sapkiSz), 0);
  1269. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.73", altSigAlgBuf,
  1270. altSigAlgSz), 0);
  1271. XMEMSET(scratchBuf, 0, scratchSz);
  1272. ExpectIntGT(wc_MakeCert(&newCert, scratchBuf, scratchSz, &serverKey, NULL,
  1273. &rng), 0);
  1274. ExpectIntGT(scratchSz = wc_SignCert(newCert.bodySz, newCert.sigType,
  1275. scratchBuf, scratchSz, &caKey, NULL, &rng), 0);
  1276. wc_InitDecodedCert(&preTBS, scratchBuf, scratchSz, 0);
  1277. ExpectIntEQ(wc_ParseCert(&preTBS, CERT_TYPE, NO_VERIFY, NULL), 0);
  1278. XMEMSET(preTbsBuf, 0, preTbsSz);
  1279. ExpectIntGT(preTbsSz = wc_GeneratePreTBS(&preTBS, preTbsBuf, preTbsSz), 0);
  1280. XMEMSET(altSigValBuf, 0, altSigValSz);
  1281. ExpectIntGT(altSigValSz = wc_MakeSigWithBitStr(altSigValBuf, altSigValSz,
  1282. CTC_SHA256wECDSA, preTbsBuf, preTbsSz, ECC_TYPE, &altCaKey,
  1283. &rng), 0);
  1284. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.74",
  1285. altSigValBuf, altSigValSz), 0);
  1286. /* Finally, generate the new certificate. */
  1287. if (outBuf != NULL) {
  1288. XMEMSET(outBuf, 0, outSz);
  1289. }
  1290. ExpectIntGT(wc_MakeCert(&newCert, outBuf, outSz, &serverKey, NULL, &rng),
  1291. 0);
  1292. ExpectIntGT(outSz = wc_SignCert(newCert.bodySz, newCert.sigType, outBuf,
  1293. outSz, &caKey, NULL, &rng), 0);
  1294. *out = outBuf;
  1295. wc_FreeRsaKey(&caKey);
  1296. wc_FreeRsaKey(&serverKey);
  1297. wc_FreeRng(&rng);
  1298. wc_FreeDecodedCert(&preTBS);
  1299. return outSz;
  1300. }
  1301. static int do_dual_alg_tls13_connection(byte *caCert, word32 caCertSz,
  1302. byte *serverCert, word32 serverCertSz,
  1303. byte *serverKey, word32 serverKeySz,
  1304. int negative_test)
  1305. {
  1306. EXPECT_DECLS;
  1307. WOLFSSL_CTX *ctx_c = NULL;
  1308. WOLFSSL_CTX *ctx_s = NULL;
  1309. WOLFSSL *ssl_c = NULL;
  1310. WOLFSSL *ssl_s = NULL;
  1311. struct test_memio_ctx test_ctx;
  1312. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  1313. ExpectIntEQ(test_memio_setup_ex(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  1314. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  1315. caCert, caCertSz, serverCert, serverCertSz,
  1316. serverKey, serverKeySz), 0);
  1317. if (negative_test) {
  1318. ExpectTrue(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0);
  1319. }
  1320. else {
  1321. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  1322. }
  1323. wolfSSL_free(ssl_c);
  1324. wolfSSL_free(ssl_s);
  1325. wolfSSL_CTX_free(ctx_c);
  1326. wolfSSL_CTX_free(ctx_s);
  1327. return EXPECT_RESULT();
  1328. }
  1329. static int test_dual_alg_support(void)
  1330. {
  1331. EXPECT_DECLS;
  1332. /* Root CA and server keys will be the same. This is only appropriate for
  1333. * testing. */
  1334. char keyFile[] = "./certs/ca-key.der";
  1335. char sapkiFile[] = "./certs/ecc-keyPub.der";
  1336. char altPrivFile[] = "./certs/ecc-key.der";
  1337. char wrongPrivFile[] = "./certs/ecc-client-key.der";
  1338. byte *serverKey = NULL;
  1339. size_t serverKeySz = 0;
  1340. byte *root = NULL;
  1341. int rootSz = 0;
  1342. byte *server = NULL;
  1343. int serverSz = 0;
  1344. ExpectIntEQ(load_file(keyFile, &serverKey, &serverKeySz), 0);
  1345. /* Base normal case. */
  1346. if (EXPECT_SUCCESS()) {
  1347. rootSz = do_dual_alg_root_certgen(&root, keyFile, sapkiFile,
  1348. altPrivFile);
  1349. }
  1350. ExpectNotNull(root);
  1351. ExpectIntGT(rootSz, 0);
  1352. if (EXPECT_SUCCESS()) {
  1353. serverSz = do_dual_alg_server_certgen(&server, keyFile, sapkiFile,
  1354. altPrivFile, keyFile, root, rootSz);
  1355. }
  1356. ExpectNotNull(server);
  1357. ExpectIntGT(serverSz, 0);
  1358. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1359. server, serverSz, serverKey, (word32)serverKeySz, 0),
  1360. TEST_SUCCESS);
  1361. XFREE(root, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1362. root = NULL;
  1363. XFREE(server, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1364. server = NULL;
  1365. /* Now we try a negative case. Note that we use wrongPrivFile to generate
  1366. * the alternative signature and then set negative_test to true for the
  1367. * call to do_dual_alg_tls13_connection(). Its expecting a failed connection
  1368. * because the signature won't verify. The exception is if
  1369. * WOLFSSL_TRUST_PEER_CERT is defined. In that case, no verification happens
  1370. * and this is no longer a negative test. */
  1371. if (EXPECT_SUCCESS()) {
  1372. rootSz = do_dual_alg_root_certgen(&root, keyFile, sapkiFile,
  1373. wrongPrivFile);
  1374. }
  1375. ExpectNotNull(root);
  1376. ExpectIntGT(rootSz, 0);
  1377. if (EXPECT_SUCCESS()) {
  1378. serverSz = do_dual_alg_server_certgen(&server, keyFile, sapkiFile,
  1379. wrongPrivFile, keyFile, root, rootSz);
  1380. }
  1381. ExpectNotNull(server);
  1382. ExpectIntGT(serverSz, 0);
  1383. #ifdef WOLFSSL_TRUST_PEER_CERT
  1384. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1385. server, serverSz, serverKey, (word32)serverKeySz, 0),
  1386. TEST_SUCCESS);
  1387. #else
  1388. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1389. server, serverSz, serverKey, (word32)serverKeySz, 1),
  1390. TEST_SUCCESS);
  1391. #endif
  1392. XFREE(root, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1393. XFREE(server, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1394. free(serverKey);
  1395. return EXPECT_RESULT();
  1396. }
  1397. #else
  1398. static int test_dual_alg_support(void)
  1399. {
  1400. return TEST_SKIPPED;
  1401. }
  1402. #endif /* WOLFSSL_DUAL_ALG_CERTS && !NO_FILESYSTEM */
  1403. /*----------------------------------------------------------------------------*
  1404. | Context
  1405. *----------------------------------------------------------------------------*/
  1406. #ifndef NO_WOLFSSL_SERVER
  1407. static int test_wolfSSL_CTX_new(void)
  1408. {
  1409. EXPECT_DECLS;
  1410. WOLFSSL_CTX *ctx;
  1411. WOLFSSL_METHOD* method = NULL;
  1412. ExpectNull(ctx = wolfSSL_CTX_new(NULL));
  1413. ExpectNotNull(method = wolfSSLv23_server_method());
  1414. if (method != NULL)
  1415. ExpectNotNull(ctx = wolfSSL_CTX_new(method));
  1416. wolfSSL_CTX_free(ctx);
  1417. return EXPECT_RESULT();
  1418. }
  1419. #endif
  1420. #if (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  1421. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  1422. static int test_for_double_Free(void)
  1423. {
  1424. EXPECT_DECLS;
  1425. WOLFSSL_CTX* ctx = NULL;
  1426. WOLFSSL* ssl = NULL;
  1427. int skipTest = 0;
  1428. const char* testCertFile;
  1429. const char* testKeyFile;
  1430. char optionsCiphers[] = "RC4-SHA:RC4-MD5:DES-CBC3-SHA:AES128-SHA:AES256-SHA"
  1431. ":NULL-SHA:NULL-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-PSK-AES256-GCM"
  1432. "-SHA384:DHE-PSK-AES128-GCM-SHA256:PSK-AES256-GCM-SHA384:PSK-AES128-GCM-SHA256:"
  1433. "DHE-PSK-AES256-CBC-SHA384:DHE-PSK-AES128-CBC-SHA256:PSK-AES256-CBC-SHA384:PSK-"
  1434. "AES128-CBC-SHA256:PSK-AES128-CBC-SHA:PSK-AES256-CBC-SHA:DHE-PSK-AES128-CCM:DHE"
  1435. "-PSK-AES256-CCM:PSK-AES128-CCM:PSK-AES256-CCM:PSK-AES128-CCM-8:PSK-AES256-CCM-"
  1436. "8:DHE-PSK-NULL-SHA384:DHE-PSK-NULL-SHA256:PSK-NULL-SHA384:PSK-NULL-SHA256:PSK-"
  1437. "NULL-SHA:AES128-CCM-8:AES256-CCM-8:ECDHE-ECDSA-"
  1438. "AES128-CCM:ECDHE-ECDSA-AES128-CCM-8:ECDHE-ECDSA-AES256-CCM-8:ECDHE-RSA-AES128-"
  1439. "SHA:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA:ECDHE-R"
  1440. "SA-RC4-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-RC4-SHA:ECDHE-ECDSA-DES-CBC3-SHA"
  1441. ":AES128-SHA256:AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:ECDH-"
  1442. "RSA-AES128-SHA:ECDH-RSA-AES256-SHA:ECDH-ECDSA-AES128-SHA:ECDH-ECDSA-AES256-SHA"
  1443. ":ECDH-RSA-RC4-SHA:ECDH-RSA-DES-CBC3-SHA:ECDH-ECDSA-RC4-SHA:ECDH-ECDSA-DES-CBC3"
  1444. "-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES"
  1445. "256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-E"
  1446. "CDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDH-RSA-AES128-GCM-SHA25"
  1447. "6:ECDH-RSA-AES256-GCM-SHA384:ECDH-ECDSA-AES128-GCM-SHA256:ECDH-ECDSA-AES256-GC"
  1448. "M-SHA384:CAMELLIA128-SHA:DHE-RSA-CAMELLIA128-SHA:CAMELLIA256-SHA:DHE-RSA-CAMEL"
  1449. "LIA256-SHA:CAMELLIA128-SHA256:DHE-RSA-CAMELLIA128-SHA256:CAMELLIA256-SHA256:DH"
  1450. "E-RSA-CAMELLIA256-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECD"
  1451. "H-RSA-AES128-SHA256:ECDH-ECDSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-ECD"
  1452. "SA-AES256-SHA384:ECDH-RSA-AES256-SHA384:ECDH-ECDSA-AES256-SHA384:ECDHE-RSA-CHA"
  1453. "CHA20-POLY1305:ECDHE-ECDSA-CHACHA20-POLY1305:DHE-RSA-CHACHA20-POLY1305:ECDHE-R"
  1454. "SA-CHACHA20-POLY1305-OLD:ECDHE-ECDSA-CHACHA20-POLY1305-OLD:DHE-RSA-CHACHA20-PO"
  1455. "LY1305-OLD:ECDHE-ECDSA-NULL-SHA:ECDHE-PSK-NULL-SHA256:ECDHE-PSK-A"
  1456. "ES128-CBC-SHA256:PSK-CHACHA20-POLY1305:ECDHE-PSK-CHACHA20-POLY1305:DHE-PSK-CHA"
  1457. "CHA20-POLY1305:EDH-RSA-DES-CBC3-SHA:TLS13-AES128-GCM-SHA256:TLS13-AES256-GCM-S"
  1458. "HA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES128-CCM-SHA256:TLS13-AES128-CCM-"
  1459. "8-SHA256:TLS13-SHA256-SHA256:TLS13-SHA384-SHA384";
  1460. /* OpenVPN uses a "blacklist" method to specify which ciphers NOT to use */
  1461. #ifdef OPENSSL_EXTRA
  1462. char openvpnCiphers[] = "DEFAULT:!EXP:!LOW:!MEDIUM:!kDH:!kECDH:!DSS:!PSK:"
  1463. "!SRP:!kRSA:!aNULL:!eNULL";
  1464. #endif
  1465. #ifndef NO_RSA
  1466. testCertFile = svrCertFile;
  1467. testKeyFile = svrKeyFile;
  1468. #elif defined(HAVE_ECC)
  1469. testCertFile = eccCertFile;
  1470. testKeyFile = eccKeyFile;
  1471. #else
  1472. skipTest = 1;
  1473. #endif
  1474. if (skipTest != 1) {
  1475. #ifndef NO_WOLFSSL_SERVER
  1476. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1477. #else
  1478. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1479. #endif
  1480. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1481. WOLFSSL_FILETYPE_PEM));
  1482. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1483. WOLFSSL_FILETYPE_PEM));
  1484. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1485. /* First test freeing SSL, then CTX */
  1486. wolfSSL_free(ssl);
  1487. ssl = NULL;
  1488. wolfSSL_CTX_free(ctx);
  1489. ctx = NULL;
  1490. #ifndef NO_WOLFSSL_CLIENT
  1491. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1492. #else
  1493. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1494. #endif
  1495. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1496. WOLFSSL_FILETYPE_PEM));
  1497. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1498. WOLFSSL_FILETYPE_PEM));
  1499. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1500. /* Next test freeing CTX then SSL */
  1501. wolfSSL_CTX_free(ctx);
  1502. ctx = NULL;
  1503. wolfSSL_free(ssl);
  1504. ssl = NULL;
  1505. #ifndef NO_WOLFSSL_SERVER
  1506. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1507. #else
  1508. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1509. #endif
  1510. /* Test setting ciphers at ctx level */
  1511. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1512. WOLFSSL_FILETYPE_PEM));
  1513. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1514. WOLFSSL_FILETYPE_PEM));
  1515. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, optionsCiphers));
  1516. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_TLS13) && defined(HAVE_AESGCM) && \
  1517. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  1518. /* only update TLSv13 suites */
  1519. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "TLS13-AES256-GCM-SHA384"));
  1520. #endif
  1521. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(HAVE_AESGCM) && \
  1522. !defined(NO_SHA256) && !defined(WOLFSSL_NO_TLS12) && \
  1523. defined(WOLFSSL_AES_128) && !defined(NO_RSA)
  1524. /* only update pre-TLSv13 suites */
  1525. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx,
  1526. "ECDHE-RSA-AES128-GCM-SHA256"));
  1527. #endif
  1528. #ifdef OPENSSL_EXTRA
  1529. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, openvpnCiphers));
  1530. #endif
  1531. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1532. wolfSSL_CTX_free(ctx);
  1533. ctx = NULL;
  1534. wolfSSL_free(ssl);
  1535. ssl = NULL;
  1536. #ifndef NO_WOLFSSL_CLIENT
  1537. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1538. #else
  1539. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1540. #endif
  1541. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1542. WOLFSSL_FILETYPE_PEM));
  1543. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1544. WOLFSSL_FILETYPE_PEM));
  1545. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1546. /* test setting ciphers at SSL level */
  1547. ExpectTrue(wolfSSL_set_cipher_list(ssl, optionsCiphers));
  1548. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_TLS13) && defined(HAVE_AESGCM) && \
  1549. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  1550. /* only update TLSv13 suites */
  1551. ExpectTrue(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384"));
  1552. #endif
  1553. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(HAVE_AESGCM) && \
  1554. !defined(NO_SHA256) && !defined(WOLFSSL_NO_TLS12) && \
  1555. defined(WOLFSSL_AES_128) && !defined(NO_RSA)
  1556. /* only update pre-TLSv13 suites */
  1557. ExpectTrue(wolfSSL_set_cipher_list(ssl, "ECDHE-RSA-AES128-GCM-SHA256"));
  1558. #endif
  1559. wolfSSL_CTX_free(ctx);
  1560. ctx = NULL;
  1561. wolfSSL_free(ssl);
  1562. ssl = NULL;
  1563. }
  1564. return EXPECT_RESULT();
  1565. }
  1566. #endif
  1567. static int test_wolfSSL_CTX_set_cipher_list_bytes(void)
  1568. {
  1569. EXPECT_DECLS;
  1570. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)) && \
  1571. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  1572. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  1573. const char* testCertFile;
  1574. const char* testKeyFile;
  1575. WOLFSSL_CTX* ctx = NULL;
  1576. WOLFSSL* ssl = NULL;
  1577. const byte cipherList[] =
  1578. {
  1579. /* TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA */ 0x00, 0x16,
  1580. /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA */ 0x00, 0x39,
  1581. /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA */ 0x00, 0x33,
  1582. /* TLS_DH_anon_WITH_AES_128_CBC_SHA */ 0x00, 0x34,
  1583. /* TLS_RSA_WITH_AES_256_CBC_SHA */ 0x00, 0x35,
  1584. /* TLS_RSA_WITH_AES_128_CBC_SHA */ 0x00, 0x2F,
  1585. /* TLS_RSA_WITH_NULL_MD5 */ 0x00, 0x01,
  1586. /* TLS_RSA_WITH_NULL_SHA */ 0x00, 0x02,
  1587. /* TLS_PSK_WITH_AES_256_CBC_SHA */ 0x00, 0x8d,
  1588. /* TLS_PSK_WITH_AES_128_CBC_SHA256 */ 0x00, 0xae,
  1589. /* TLS_PSK_WITH_AES_256_CBC_SHA384 */ 0x00, 0xaf,
  1590. /* TLS_PSK_WITH_AES_128_CBC_SHA */ 0x00, 0x8c,
  1591. /* TLS_PSK_WITH_NULL_SHA256 */ 0x00, 0xb0,
  1592. /* TLS_PSK_WITH_NULL_SHA384 */ 0x00, 0xb1,
  1593. /* TLS_PSK_WITH_NULL_SHA */ 0x00, 0x2c,
  1594. /* SSL_RSA_WITH_RC4_128_SHA */ 0x00, 0x05,
  1595. /* SSL_RSA_WITH_RC4_128_MD5 */ 0x00, 0x04,
  1596. /* SSL_RSA_WITH_3DES_EDE_CBC_SHA */ 0x00, 0x0A,
  1597. /* ECC suites, first byte is 0xC0 (ECC_BYTE) */
  1598. /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x14,
  1599. /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x13,
  1600. /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x0A,
  1601. /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x09,
  1602. /* TLS_ECDHE_RSA_WITH_RC4_128_SHA */ 0xC0, 0x11,
  1603. /* TLS_ECDHE_ECDSA_WITH_RC4_128_SHA */ 0xC0, 0x07,
  1604. /* TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x12,
  1605. /* TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x08,
  1606. /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x27,
  1607. /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256*/ 0xC0, 0x23,
  1608. /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x28,
  1609. /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384*/ 0xC0, 0x24,
  1610. /* TLS_ECDHE_ECDSA_WITH_NULL_SHA */ 0xC0, 0x06,
  1611. /* TLS_ECDHE_PSK_WITH_NULL_SHA256 */ 0xC0, 0x3a,
  1612. /* TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x37,
  1613. /* static ECDH, first byte is 0xC0 (ECC_BYTE) */
  1614. /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x0F,
  1615. /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x0E,
  1616. /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x05,
  1617. /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x04,
  1618. /* TLS_ECDH_RSA_WITH_RC4_128_SHA */ 0xC0, 0x0C,
  1619. /* TLS_ECDH_ECDSA_WITH_RC4_128_SHA */ 0xC0, 0x02,
  1620. /* TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x0D,
  1621. /* TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x03,
  1622. /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x29,
  1623. /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x25,
  1624. /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x2A,
  1625. /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x26,
  1626. /* WDM_WITH_NULL_SHA256 */ 0x00, 0xFE, /* wolfSSL DTLS Multicast */
  1627. /* SHA256 */
  1628. /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 */ 0x00, 0x6b,
  1629. /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 */ 0x00, 0x67,
  1630. /* TLS_RSA_WITH_AES_256_CBC_SHA256 */ 0x00, 0x3d,
  1631. /* TLS_RSA_WITH_AES_128_CBC_SHA256 */ 0x00, 0x3c,
  1632. /* TLS_RSA_WITH_NULL_SHA256 */ 0x00, 0x3b,
  1633. /* TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 */ 0x00, 0xb2,
  1634. /* TLS_DHE_PSK_WITH_NULL_SHA256 */ 0x00, 0xb4,
  1635. /* SHA384 */
  1636. /* TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 */ 0x00, 0xb3,
  1637. /* TLS_DHE_PSK_WITH_NULL_SHA384 */ 0x00, 0xb5,
  1638. /* AES-GCM */
  1639. /* TLS_RSA_WITH_AES_128_GCM_SHA256 */ 0x00, 0x9c,
  1640. /* TLS_RSA_WITH_AES_256_GCM_SHA384 */ 0x00, 0x9d,
  1641. /* TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 */ 0x00, 0x9e,
  1642. /* TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 */ 0x00, 0x9f,
  1643. /* TLS_DH_anon_WITH_AES_256_GCM_SHA384 */ 0x00, 0xa7,
  1644. /* TLS_PSK_WITH_AES_128_GCM_SHA256 */ 0x00, 0xa8,
  1645. /* TLS_PSK_WITH_AES_256_GCM_SHA384 */ 0x00, 0xa9,
  1646. /* TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 */ 0x00, 0xaa,
  1647. /* TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 */ 0x00, 0xab,
  1648. /* ECC AES-GCM, first byte is 0xC0 (ECC_BYTE) */
  1649. /* TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2b,
  1650. /* TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x2c,
  1651. /* TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2d,
  1652. /* TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x2e,
  1653. /* TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2f,
  1654. /* TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x30,
  1655. /* TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x31,
  1656. /* TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x32,
  1657. /* AES-CCM, first byte is 0xC0 but isn't ECC,
  1658. * also, in some of the other AES-CCM suites
  1659. * there will be second byte number conflicts
  1660. * with non-ECC AES-GCM */
  1661. /* TLS_RSA_WITH_AES_128_CCM_8 */ 0xC0, 0xa0,
  1662. /* TLS_RSA_WITH_AES_256_CCM_8 */ 0xC0, 0xa1,
  1663. /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM */ 0xC0, 0xac,
  1664. /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 */ 0xC0, 0xae,
  1665. /* TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 */ 0xC0, 0xaf,
  1666. /* TLS_PSK_WITH_AES_128_CCM */ 0xC0, 0xa4,
  1667. /* TLS_PSK_WITH_AES_256_CCM */ 0xC0, 0xa5,
  1668. /* TLS_PSK_WITH_AES_128_CCM_8 */ 0xC0, 0xa8,
  1669. /* TLS_PSK_WITH_AES_256_CCM_8 */ 0xC0, 0xa9,
  1670. /* TLS_DHE_PSK_WITH_AES_128_CCM */ 0xC0, 0xa6,
  1671. /* TLS_DHE_PSK_WITH_AES_256_CCM */ 0xC0, 0xa7,
  1672. /* Camellia */
  1673. /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA */ 0x00, 0x41,
  1674. /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA */ 0x00, 0x84,
  1675. /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 */ 0x00, 0xba,
  1676. /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 */ 0x00, 0xc0,
  1677. /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA */ 0x00, 0x45,
  1678. /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA */ 0x00, 0x88,
  1679. /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 */ 0x00, 0xbe,
  1680. /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 */ 0x00, 0xc4,
  1681. /* chacha20-poly1305 suites first byte is 0xCC (CHACHA_BYTE) */
  1682. /* TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xa8,
  1683. /* TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xa9,
  1684. /* TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xaa,
  1685. /* TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xac,
  1686. /* TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xab,
  1687. /* TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xad,
  1688. /* chacha20-poly1305 earlier version of nonce and padding (CHACHA_BYTE) */
  1689. /* TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x13,
  1690. /* TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x14,
  1691. /* TLS_DHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x15,
  1692. /* ECDHE_PSK RFC8442, first byte is 0xD0 (ECDHE_PSK_BYTE) */
  1693. /* TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256 */ 0xD0, 0x01,
  1694. /* TLS v1.3 cipher suites */
  1695. /* TLS_AES_128_GCM_SHA256 */ 0x13, 0x01,
  1696. /* TLS_AES_256_GCM_SHA384 */ 0x13, 0x02,
  1697. /* TLS_CHACHA20_POLY1305_SHA256 */ 0x13, 0x03,
  1698. /* TLS_AES_128_CCM_SHA256 */ 0x13, 0x04,
  1699. /* TLS_AES_128_CCM_8_SHA256 */ 0x13, 0x05,
  1700. /* TLS v1.3 Integrity only cipher suites - 0xC0 (ECC) first byte */
  1701. /* TLS_SHA256_SHA256 */ 0xC0, 0xB4,
  1702. /* TLS_SHA384_SHA384 */ 0xC0, 0xB5
  1703. };
  1704. #ifndef NO_RSA
  1705. testCertFile = svrCertFile;
  1706. testKeyFile = svrKeyFile;
  1707. #elif defined(HAVE_ECC)
  1708. testCertFile = eccCertFile;
  1709. testKeyFile = eccKeyFile;
  1710. #endif
  1711. #ifndef NO_WOLFSSL_SERVER
  1712. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1713. #else
  1714. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1715. #endif
  1716. ExpectTrue(wolfSSL_CTX_set_cipher_list_bytes(ctx, &cipherList[0U],
  1717. sizeof(cipherList)));
  1718. wolfSSL_CTX_free(ctx);
  1719. ctx = NULL;
  1720. #ifndef NO_WOLFSSL_SERVER
  1721. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1722. #else
  1723. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1724. #endif
  1725. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1726. WOLFSSL_FILETYPE_PEM));
  1727. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1728. WOLFSSL_FILETYPE_PEM));
  1729. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1730. ExpectTrue(wolfSSL_set_cipher_list_bytes(ssl, &cipherList[0U],
  1731. sizeof(cipherList)));
  1732. wolfSSL_free(ssl);
  1733. wolfSSL_CTX_free(ctx);
  1734. #endif /* (OPENSSL_EXTRA || WOLFSSL_SET_CIPHER_BYTES) &&
  1735. (!NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER) && (!NO_RSA || HAVE_ECC) */
  1736. return EXPECT_RESULT();
  1737. }
  1738. static int test_wolfSSL_CTX_use_certificate(void)
  1739. {
  1740. EXPECT_DECLS;
  1741. #if defined(OPENSSL_EXTRA) || defined(HAVE_LIGHTY) || \
  1742. defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(HAVE_STUNNEL) || \
  1743. defined(WOLFSSL_NGINX) || defined(HAVE_POCO_LIB) || \
  1744. defined(WOLFSSL_HAPROXY)
  1745. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  1746. WOLFSSL_CTX* ctx = NULL;
  1747. X509* x509 = NULL;
  1748. #ifndef NO_WOLFSSL_SERVER
  1749. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1750. #else
  1751. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1752. #endif
  1753. ExpectNotNull(x509 = wolfSSL_X509_new());
  1754. /* Negative tests. */
  1755. ExpectIntEQ(SSL_CTX_use_certificate(NULL, NULL), 0);
  1756. ExpectIntEQ(SSL_CTX_use_certificate(ctx, NULL), 0);
  1757. ExpectIntEQ(SSL_CTX_use_certificate(NULL, x509), 0);
  1758. /* Empty certificate */
  1759. ExpectIntEQ(SSL_CTX_use_certificate(ctx, x509), 0);
  1760. wolfSSL_X509_free(x509);
  1761. wolfSSL_CTX_free(ctx);
  1762. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  1763. #endif
  1764. return EXPECT_RESULT();
  1765. }
  1766. static int test_wolfSSL_CTX_use_certificate_file(void)
  1767. {
  1768. EXPECT_DECLS;
  1769. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER)
  1770. WOLFSSL_CTX *ctx = NULL;
  1771. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1772. /* invalid context */
  1773. ExpectFalse(wolfSSL_CTX_use_certificate_file(NULL, svrCertFile,
  1774. WOLFSSL_FILETYPE_PEM));
  1775. /* invalid cert file */
  1776. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, bogusFile,
  1777. WOLFSSL_FILETYPE_PEM));
  1778. /* invalid cert type */
  1779. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, 9999));
  1780. #ifdef NO_RSA
  1781. /* rsa needed */
  1782. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  1783. WOLFSSL_FILETYPE_PEM));
  1784. #else
  1785. /* success */
  1786. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  1787. WOLFSSL_FILETYPE_PEM));
  1788. #endif
  1789. wolfSSL_CTX_free(ctx);
  1790. #endif
  1791. return EXPECT_RESULT();
  1792. }
  1793. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  1794. static int test_wolfSSL_CTX_use_certificate_ASN1(void)
  1795. {
  1796. EXPECT_DECLS;
  1797. #if !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER) && !defined(NO_ASN)
  1798. WOLFSSL_CTX* ctx = NULL;
  1799. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1800. /* Failure cases. */
  1801. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(NULL, 0, NULL ),
  1802. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1803. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx , 0, NULL ),
  1804. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1805. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(NULL, 0, server_cert_der_2048),
  1806. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1807. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx , 0, server_cert_der_2048),
  1808. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1809. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx, sizeof_server_cert_der_2048,
  1810. server_cert_der_2048), WOLFSSL_SUCCESS);
  1811. wolfSSL_CTX_free(ctx);
  1812. #endif
  1813. return EXPECT_RESULT();
  1814. }
  1815. #endif /* (OPENSSL_ALL || WOLFSSL_ASIO) && !NO_RSA */
  1816. /* Test function for wolfSSL_CTX_use_certificate_buffer. Load cert into
  1817. * context using buffer.
  1818. * PRE: NO_CERTS not defined; USE_CERT_BUFFERS_2048 defined; compile with
  1819. * --enable-testcert flag.
  1820. */
  1821. static int test_wolfSSL_CTX_use_certificate_buffer(void)
  1822. {
  1823. EXPECT_DECLS;
  1824. #if !defined(NO_CERTS) && defined(USE_CERT_BUFFERS_2048) && \
  1825. !defined(NO_RSA) && !defined(NO_WOLFSSL_SERVER)
  1826. WOLFSSL_CTX* ctx = NULL;
  1827. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1828. /* Invalid parameters. */
  1829. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(NULL, NULL, 0,
  1830. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1831. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, NULL, 0,
  1832. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1833. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(NULL, server_cert_der_2048,
  1834. 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1835. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048, 0,
  1836. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1837. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx,
  1838. server_cert_der_2048, sizeof_server_cert_der_2048,
  1839. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1840. wolfSSL_CTX_free(ctx);
  1841. #endif
  1842. return EXPECT_RESULT();
  1843. } /* END test_wolfSSL_CTX_use_certificate_buffer */
  1844. static int test_wolfSSL_use_certificate_buffer(void)
  1845. {
  1846. EXPECT_DECLS;
  1847. #if !defined(NO_CERTS) && defined(USE_CERT_BUFFERS_2048) && \
  1848. !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  1849. WOLFSSL_CTX* ctx = NULL;
  1850. WOLFSSL* ssl = NULL;
  1851. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1852. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1853. /* Invalid parameters. */
  1854. ExpectIntEQ(wolfSSL_use_certificate_buffer(NULL, NULL, 0,
  1855. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1856. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl, NULL, 0,
  1857. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1858. ExpectIntEQ(wolfSSL_use_certificate_buffer(NULL, client_cert_der_2048, 0,
  1859. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1860. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl, client_cert_der_2048, 0,
  1861. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1862. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl,
  1863. client_cert_der_2048, sizeof_client_cert_der_2048,
  1864. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1865. wolfSSL_free(ssl);
  1866. wolfSSL_CTX_free(ctx);
  1867. #endif
  1868. return EXPECT_RESULT();
  1869. }
  1870. static int test_wolfSSL_CTX_use_PrivateKey_file(void)
  1871. {
  1872. EXPECT_DECLS;
  1873. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER)
  1874. WOLFSSL_CTX *ctx = NULL;
  1875. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1876. /* invalid context */
  1877. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(NULL, svrKeyFile,
  1878. WOLFSSL_FILETYPE_PEM));
  1879. /* invalid key file */
  1880. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, bogusFile,
  1881. WOLFSSL_FILETYPE_PEM));
  1882. /* invalid key type */
  1883. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, 9999));
  1884. /* success */
  1885. #ifdef NO_RSA
  1886. /* rsa needed */
  1887. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  1888. WOLFSSL_FILETYPE_PEM));
  1889. #else
  1890. /* success */
  1891. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  1892. WOLFSSL_FILETYPE_PEM));
  1893. #endif
  1894. wolfSSL_CTX_free(ctx);
  1895. #endif
  1896. return EXPECT_RESULT();
  1897. }
  1898. static int test_wolfSSL_CTX_use_RSAPrivateKey_file(void)
  1899. {
  1900. EXPECT_DECLS;
  1901. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1902. !defined(NO_WOLFSSL_SERVER) && defined(OPENSSL_EXTRA)
  1903. WOLFSSL_CTX *ctx = NULL;
  1904. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1905. /* invalid context */
  1906. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(NULL, svrKeyFile,
  1907. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1908. /* invalid key file */
  1909. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, bogusFile,
  1910. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1911. /* invalid key type */
  1912. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile, 9999),
  1913. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1914. /* success */
  1915. #ifdef NO_RSA
  1916. /* rsa needed */
  1917. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile,
  1918. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1919. #else
  1920. /* success */
  1921. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile,
  1922. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1923. #endif
  1924. wolfSSL_CTX_free(ctx);
  1925. #endif
  1926. return EXPECT_RESULT();
  1927. }
  1928. static int test_wolfSSL_use_RSAPrivateKey_file(void)
  1929. {
  1930. EXPECT_DECLS;
  1931. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1932. !defined(NO_WOLFSSL_CLIENT) && defined(OPENSSL_EXTRA)
  1933. WOLFSSL_CTX* ctx = NULL;
  1934. WOLFSSL* ssl = NULL;
  1935. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1936. ExpectNotNull(ssl = SSL_new(ctx));
  1937. /* invalid context */
  1938. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(NULL, svrKeyFile,
  1939. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1940. /* invalid key file */
  1941. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, bogusFile,
  1942. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1943. /* invalid key type */
  1944. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile, 9999),
  1945. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1946. /* success */
  1947. #ifdef NO_RSA
  1948. /* rsa needed */
  1949. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile,
  1950. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1951. #else
  1952. /* success */
  1953. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile,
  1954. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1955. #endif
  1956. wolfSSL_free(ssl);
  1957. wolfSSL_CTX_free(ctx);
  1958. #endif
  1959. return EXPECT_RESULT();
  1960. }
  1961. static int test_wolfSSL_CTX_use_PrivateKey(void)
  1962. {
  1963. EXPECT_DECLS;
  1964. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1965. !defined(NO_WOLFSSL_SERVER) && defined(OPENSSL_EXTRA)
  1966. WOLFSSL_CTX *ctx = NULL;
  1967. WOLFSSL_EVP_PKEY* pkey = NULL;
  1968. const unsigned char* p;
  1969. (void)p;
  1970. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1971. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  1972. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1973. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1974. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1975. /* No data. */
  1976. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1977. wolfSSL_EVP_PKEY_free(pkey);
  1978. pkey = NULL;
  1979. #if defined(USE_CERT_BUFFERS_2048)
  1980. #if !defined(NO_RSA)
  1981. p = client_key_der_2048;
  1982. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &p,
  1983. sizeof_client_key_der_2048));
  1984. #if defined(WOLFSSL_KEY_GEN)
  1985. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  1986. #else
  1987. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1988. #endif
  1989. wolfSSL_EVP_PKEY_free(pkey);
  1990. pkey = NULL;
  1991. #endif
  1992. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH)
  1993. #ifndef NO_DSA
  1994. p = dsa_key_der_2048;
  1995. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_DSA, NULL, &p,
  1996. sizeof_dsa_key_der_2048));
  1997. #if !defined(HAVE_SELFTEST) && (defined(WOLFSSL_KEY_GEN) || \
  1998. defined(WOLFSSL_CERT_GEN))
  1999. /* Not supported in ProcessBuffer. */
  2000. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  2001. #else
  2002. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2003. #endif
  2004. wolfSSL_EVP_PKEY_free(pkey);
  2005. pkey = NULL;
  2006. #endif
  2007. #endif /* WOLFSSL_QT || OPENSSL_ALL || WOLFSSL_OPENSSH */
  2008. #if !defined(NO_DH) && defined(OPENSSL_ALL) && \
  2009. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  2010. p = dh_ffdhe_statickey_der_2048;
  2011. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &p,
  2012. sizeof_dh_ffdhe_statickey_der_2048));
  2013. /* Not supported. */
  2014. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2015. wolfSSL_EVP_PKEY_free(pkey);
  2016. pkey = NULL;
  2017. #endif
  2018. #endif /* USE_CERT_BUFFERS_2048 */
  2019. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  2020. p = ecc_clikey_der_256;
  2021. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &p,
  2022. sizeof_ecc_clikey_der_256));
  2023. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  2024. wolfSSL_EVP_PKEY_free(pkey);
  2025. pkey = NULL;
  2026. #endif
  2027. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,
  2028. (unsigned char*)"01234567012345670123456701234567", 32));
  2029. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2030. wolfSSL_EVP_PKEY_free(pkey);
  2031. pkey = NULL;
  2032. wolfSSL_CTX_free(ctx);
  2033. #endif
  2034. return EXPECT_RESULT();
  2035. }
  2036. /* test both file and buffer versions along with unloading trusted peer certs */
  2037. static int test_wolfSSL_CTX_trust_peer_cert(void)
  2038. {
  2039. EXPECT_DECLS;
  2040. #if !defined(NO_CERTS) && defined(WOLFSSL_TRUST_PEER_CERT) && \
  2041. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_RSA)
  2042. WOLFSSL_CTX *ctx = NULL;
  2043. WOLFSSL* ssl = NULL;
  2044. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  2045. ExpectNotNull(ssl = wolfSSL_new(ctx));
  2046. #if !defined(NO_FILESYSTEM)
  2047. /* invalid file */
  2048. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, NULL,
  2049. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2050. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, bogusFile,
  2051. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2052. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, cliCertFile,
  2053. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2054. /* success */
  2055. ExpectIntEQ(wolfSSL_CTX_trust_peer_cert(ctx, cliCertFile,
  2056. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2057. /* unload cert */
  2058. ExpectIntNE(wolfSSL_CTX_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  2059. ExpectIntEQ(wolfSSL_CTX_Unload_trust_peers(ctx), WOLFSSL_SUCCESS);
  2060. /* invalid file */
  2061. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, NULL,
  2062. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2063. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, bogusFile,
  2064. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2065. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, cliCertFile,
  2066. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2067. /* success */
  2068. ExpectIntEQ(wolfSSL_trust_peer_cert(ssl, cliCertFile,
  2069. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2070. #ifdef WOLFSSL_LOCAL_X509_STORE
  2071. /* unload cert */
  2072. ExpectIntNE(wolfSSL_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  2073. ExpectIntEQ(wolfSSL_Unload_trust_peers(ssl), WOLFSSL_SUCCESS);
  2074. #endif
  2075. #endif
  2076. /* Test of loading certs from buffers */
  2077. /* invalid buffer */
  2078. ExpectIntNE(wolfSSL_CTX_trust_peer_buffer(ctx, NULL, -1,
  2079. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2080. /* success */
  2081. #ifdef USE_CERT_BUFFERS_1024
  2082. ExpectIntEQ(wolfSSL_CTX_trust_peer_buffer(ctx, client_cert_der_1024,
  2083. sizeof_client_cert_der_1024, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2084. #endif
  2085. #ifdef USE_CERT_BUFFERS_2048
  2086. ExpectIntEQ(wolfSSL_CTX_trust_peer_buffer(ctx, client_cert_der_2048,
  2087. sizeof_client_cert_der_2048, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2088. #endif
  2089. /* unload cert */
  2090. ExpectIntNE(wolfSSL_CTX_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  2091. ExpectIntEQ(wolfSSL_CTX_Unload_trust_peers(ctx), WOLFSSL_SUCCESS);
  2092. wolfSSL_free(ssl);
  2093. wolfSSL_CTX_free(ctx);
  2094. #endif
  2095. return EXPECT_RESULT();
  2096. }
  2097. static int test_wolfSSL_CTX_load_verify_locations(void)
  2098. {
  2099. EXPECT_DECLS;
  2100. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT)
  2101. WOLFSSL_CTX *ctx = NULL;
  2102. #ifndef NO_RSA
  2103. WOLFSSL_CERT_MANAGER* cm = NULL;
  2104. #ifdef PERSIST_CERT_CACHE
  2105. int cacheSz = 0;
  2106. unsigned char* cache = NULL;
  2107. int used = 0;
  2108. #ifndef NO_FILESYSTEM
  2109. const char* cacheFile = "./tests/cert_cache.tmp";
  2110. #endif
  2111. int i;
  2112. int t;
  2113. int* p;
  2114. #endif
  2115. #endif
  2116. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS)
  2117. const char* load_certs_path = "./certs/external";
  2118. const char* load_no_certs_path = "./examples";
  2119. const char* load_expired_path = "./certs/test/expired";
  2120. #endif
  2121. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  2122. /* invalid arguments */
  2123. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(NULL, caCertFile, NULL),
  2124. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2125. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, NULL, NULL),
  2126. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2127. /* invalid ca file */
  2128. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, bogusFile, NULL),
  2129. WS_RETURN_CODE(WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE),
  2130. WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  2131. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS) && \
  2132. ((defined(WOLFSSL_QT) || defined(WOLFSSL_IGNORE_BAD_CERT_PATH)) && \
  2133. !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_IGNORE_BAD_PATH_ERR))
  2134. /* invalid path */
  2135. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, NULL, bogusFile),
  2136. WS_RETURN_CODE(WC_NO_ERR_TRACE(BAD_PATH_ERROR),WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  2137. #endif
  2138. #if defined(WOLFSSL_QT) || defined(WOLFSSL_IGNORE_BAD_CERT_PATH)
  2139. /* test ignoring the invalid path */
  2140. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, bogusFile,
  2141. WOLFSSL_LOAD_FLAG_IGNORE_BAD_PATH_ERR), WOLFSSL_SUCCESS);
  2142. #endif
  2143. /* load ca cert */
  2144. #ifdef NO_RSA
  2145. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  2146. WS_RETURN_CODE(WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E),WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  2147. #else /* Skip the following test without RSA certs. */
  2148. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  2149. WOLFSSL_SUCCESS);
  2150. #ifdef PERSIST_CERT_CACHE
  2151. /* Get cert cache size */
  2152. ExpectIntGT(cacheSz = wolfSSL_CTX_get_cert_cache_memsize(ctx), 0);
  2153. ExpectNotNull(cache = (byte*)XMALLOC(cacheSz, NULL,
  2154. DYNAMIC_TYPE_TMP_BUFFER));
  2155. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, -1, NULL),
  2156. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2157. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, NULL, -1, NULL),
  2158. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2159. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, cache, -1, NULL),
  2160. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2161. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, cacheSz, NULL),
  2162. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2163. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, -1, &used),
  2164. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2165. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, cache, cacheSz, &used),
  2166. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2167. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, NULL, cacheSz, &used),
  2168. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2169. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, -1, &used),
  2170. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2171. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz, NULL),
  2172. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2173. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz - 10, &used),
  2174. WC_NO_ERR_TRACE(BUFFER_E));
  2175. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz, &used), 1);
  2176. ExpectIntEQ(cacheSz, used);
  2177. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, NULL, -1),
  2178. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2179. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, NULL, -1),
  2180. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2181. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, cache, -1),
  2182. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2183. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, NULL, cacheSz),
  2184. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2185. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, cache, cacheSz),
  2186. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2187. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, NULL, cacheSz),
  2188. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2189. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, -1),
  2190. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2191. /* Smaller than header. */
  2192. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, 1), WC_NO_ERR_TRACE(BUFFER_E));
  2193. for (i = 1; i < cacheSz; i++) {
  2194. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz - i),
  2195. WC_NO_ERR_TRACE(BUFFER_E));
  2196. }
  2197. if (EXPECT_SUCCESS()) {
  2198. /* Modify header for bad results! */
  2199. p = (int*)cache;
  2200. /* version */
  2201. t = p[0]; p[0] = 0xff;
  2202. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2203. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2204. p[0] = t; p++;
  2205. /* rows */
  2206. t = p[0]; p[0] = 0xff;
  2207. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2208. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2209. p[0] = t; p++;
  2210. /* columns[0] */
  2211. t = p[0]; p[0] = -1;
  2212. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2213. WC_NO_ERR_TRACE(PARSE_ERROR));
  2214. p[0] = t; p += CA_TABLE_SIZE;
  2215. /* signerSz*/
  2216. t = p[0]; p[0] = 0xff;
  2217. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2218. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2219. p[0] = t;
  2220. }
  2221. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz), 1);
  2222. ExpectIntEQ(cacheSz = wolfSSL_CTX_get_cert_cache_memsize(ctx), used);
  2223. #ifndef NO_FILESYSTEM
  2224. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2225. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2226. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(NULL, cacheFile), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2227. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(ctx, cacheFile), 1);
  2228. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2229. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2230. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(NULL, cacheFile), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2231. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, "no-file"),
  2232. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  2233. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, cacheFile), 1);
  2234. /* File contents is not a cache. */
  2235. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, "./certs/ca-cert.pem"),
  2236. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2237. #endif
  2238. XFREE(cache, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  2239. #endif
  2240. /* Test unloading CA's */
  2241. ExpectIntEQ(wolfSSL_CTX_UnloadCAs(ctx), WOLFSSL_SUCCESS);
  2242. #ifdef PERSIST_CERT_CACHE
  2243. /* Verify no certs (result is less than cacheSz) */
  2244. ExpectIntGT(cacheSz, wolfSSL_CTX_get_cert_cache_memsize(ctx));
  2245. #endif
  2246. /* load ca cert again */
  2247. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  2248. WOLFSSL_SUCCESS);
  2249. /* Test getting CERT_MANAGER */
  2250. ExpectNotNull(cm = wolfSSL_CTX_GetCertManager(ctx));
  2251. /* Test unloading CA's using CM */
  2252. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  2253. #ifdef PERSIST_CERT_CACHE
  2254. /* Verify no certs (result is less than cacheSz) */
  2255. ExpectIntGT(cacheSz, wolfSSL_CTX_get_cert_cache_memsize(ctx));
  2256. #endif
  2257. #endif
  2258. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS)
  2259. /* Test loading CA certificates using a path */
  2260. #ifdef NO_RSA
  2261. /* failure here okay since certs in external directory are RSA */
  2262. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2263. WOLFSSL_LOAD_FLAG_PEM_CA_ONLY), WOLFSSL_SUCCESS);
  2264. #else
  2265. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2266. WOLFSSL_LOAD_FLAG_PEM_CA_ONLY), WOLFSSL_SUCCESS);
  2267. #endif
  2268. /* Test loading path with no files */
  2269. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2270. load_no_certs_path, WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2271. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2272. /* Test loading expired CA certificates */
  2273. #ifdef NO_RSA
  2274. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2275. load_expired_path,
  2276. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY | WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2277. WOLFSSL_SUCCESS);
  2278. #else
  2279. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2280. load_expired_path,
  2281. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY | WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2282. WOLFSSL_SUCCESS);
  2283. #endif
  2284. /* Test loading CA certificates and ignoring all errors */
  2285. #ifdef NO_RSA
  2286. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2287. WOLFSSL_LOAD_FLAG_IGNORE_ERR), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2288. #else
  2289. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2290. WOLFSSL_LOAD_FLAG_IGNORE_ERR), WOLFSSL_SUCCESS);
  2291. #endif
  2292. #endif
  2293. wolfSSL_CTX_free(ctx);
  2294. #endif
  2295. return EXPECT_RESULT();
  2296. }
  2297. static int test_wolfSSL_CTX_load_system_CA_certs(void)
  2298. {
  2299. int res = TEST_SKIPPED;
  2300. #if defined(WOLFSSL_SYS_CA_CERTS) && !defined(NO_WOLFSSL_CLIENT) && \
  2301. (!defined(NO_RSA) || defined(HAVE_ECC))
  2302. WOLFSSL_CTX* ctx;
  2303. byte dirValid = 0;
  2304. int ret = 0;
  2305. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  2306. if (ctx == NULL) {
  2307. fprintf(stderr, "wolfSSL_CTX_new failed.\n");
  2308. ret = -1;
  2309. }
  2310. if (ret == 0) {
  2311. #if defined(USE_WINDOWS_API) || defined(__APPLE__)
  2312. dirValid = 1;
  2313. #else
  2314. word32 numDirs;
  2315. const char** caDirs = wolfSSL_get_system_CA_dirs(&numDirs);
  2316. if (caDirs == NULL || numDirs == 0) {
  2317. fprintf(stderr, "wolfSSL_get_system_CA_dirs failed.\n");
  2318. ret = -1;
  2319. }
  2320. else {
  2321. ReadDirCtx dirCtx;
  2322. word32 i;
  2323. for (i = 0; i < numDirs; ++i) {
  2324. if (wc_ReadDirFirst(&dirCtx, caDirs[i], NULL) == 0) {
  2325. /* Directory isn't empty. */
  2326. dirValid = 1;
  2327. wc_ReadDirClose(&dirCtx);
  2328. break;
  2329. }
  2330. }
  2331. }
  2332. #endif
  2333. }
  2334. /*
  2335. * If the directory isn't empty, we should be able to load CA
  2336. * certs from it. On Windows/Mac, we assume the CA cert stores are
  2337. * usable.
  2338. */
  2339. if (ret == 0 && dirValid && wolfSSL_CTX_load_system_CA_certs(ctx) !=
  2340. WOLFSSL_SUCCESS) {
  2341. fprintf(stderr, "wolfSSL_CTX_load_system_CA_certs failed.\n");
  2342. ret = -1;
  2343. }
  2344. #ifdef OPENSSL_EXTRA
  2345. if (ret == 0 &&
  2346. wolfSSL_CTX_set_default_verify_paths(ctx) != WOLFSSL_SUCCESS) {
  2347. fprintf(stderr, "wolfSSL_CTX_set_default_verify_paths failed.\n");
  2348. ret = -1;
  2349. }
  2350. #endif /* OPENSSL_EXTRA */
  2351. wolfSSL_CTX_free(ctx);
  2352. res = TEST_RES_CHECK(ret == 0);
  2353. #endif /* WOLFSSL_SYS_CA_CERTS && !NO_WOLFSSL_CLIENT */
  2354. return res;
  2355. }
  2356. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2357. static int test_cm_load_ca_buffer(const byte* cert_buf, size_t cert_sz,
  2358. int file_type)
  2359. {
  2360. int ret;
  2361. WOLFSSL_CERT_MANAGER* cm;
  2362. cm = wolfSSL_CertManagerNew();
  2363. if (cm == NULL) {
  2364. fprintf(stderr, "test_cm_load_ca failed\n");
  2365. return -1;
  2366. }
  2367. ret = wolfSSL_CertManagerLoadCABuffer(cm, cert_buf, (sword32)cert_sz, file_type);
  2368. wolfSSL_CertManagerFree(cm);
  2369. return ret;
  2370. }
  2371. static int test_cm_load_ca_file(const char* ca_cert_file)
  2372. {
  2373. int ret = 0;
  2374. byte* cert_buf = NULL;
  2375. size_t cert_sz = 0;
  2376. #if defined(WOLFSSL_PEM_TO_DER)
  2377. DerBuffer* pDer = NULL;
  2378. #endif
  2379. ret = load_file(ca_cert_file, &cert_buf, &cert_sz);
  2380. if (ret == 0) {
  2381. /* normal test */
  2382. ret = test_cm_load_ca_buffer(cert_buf, cert_sz, WOLFSSL_FILETYPE_PEM);
  2383. if (ret == WOLFSSL_SUCCESS) {
  2384. /* test including null terminator in length */
  2385. byte* tmp = (byte*)realloc(cert_buf, cert_sz+1);
  2386. if (tmp == NULL) {
  2387. ret = MEMORY_E;
  2388. }
  2389. else {
  2390. cert_buf = tmp;
  2391. cert_buf[cert_sz] = '\0';
  2392. ret = test_cm_load_ca_buffer(cert_buf, cert_sz+1,
  2393. WOLFSSL_FILETYPE_PEM);
  2394. }
  2395. }
  2396. #if defined(WOLFSSL_PEM_TO_DER)
  2397. if (ret == WOLFSSL_SUCCESS) {
  2398. /* test loading DER */
  2399. ret = wc_PemToDer(cert_buf, (sword32)cert_sz, CA_TYPE, &pDer,
  2400. NULL, NULL, NULL);
  2401. if (ret == 0 && pDer != NULL) {
  2402. ret = test_cm_load_ca_buffer(pDer->buffer, pDer->length,
  2403. WOLFSSL_FILETYPE_ASN1);
  2404. wc_FreeDer(&pDer);
  2405. }
  2406. }
  2407. #endif
  2408. }
  2409. free(cert_buf);
  2410. return ret;
  2411. }
  2412. static int test_cm_load_ca_buffer_ex(const byte* cert_buf, size_t cert_sz,
  2413. int file_type, word32 flags)
  2414. {
  2415. int ret;
  2416. WOLFSSL_CERT_MANAGER* cm;
  2417. cm = wolfSSL_CertManagerNew();
  2418. if (cm == NULL) {
  2419. fprintf(stderr, "test_cm_load_ca failed\n");
  2420. return -1;
  2421. }
  2422. ret = wolfSSL_CertManagerLoadCABuffer_ex(cm, cert_buf, (sword32)cert_sz, file_type,
  2423. 0, flags);
  2424. wolfSSL_CertManagerFree(cm);
  2425. return ret;
  2426. }
  2427. static int test_cm_load_ca_file_ex(const char* ca_cert_file, word32 flags)
  2428. {
  2429. int ret = 0;
  2430. byte* cert_buf = NULL;
  2431. size_t cert_sz = 0;
  2432. #if defined(WOLFSSL_PEM_TO_DER)
  2433. DerBuffer* pDer = NULL;
  2434. #endif
  2435. ret = load_file(ca_cert_file, &cert_buf, &cert_sz);
  2436. if (ret == 0) {
  2437. /* normal test */
  2438. ret = test_cm_load_ca_buffer_ex(cert_buf, cert_sz,
  2439. WOLFSSL_FILETYPE_PEM, flags);
  2440. if (ret == WOLFSSL_SUCCESS) {
  2441. /* test including null terminator in length */
  2442. byte* tmp = (byte*)realloc(cert_buf, cert_sz+1);
  2443. if (tmp == NULL) {
  2444. ret = MEMORY_E;
  2445. }
  2446. else {
  2447. cert_buf = tmp;
  2448. cert_buf[cert_sz] = '\0';
  2449. ret = test_cm_load_ca_buffer_ex(cert_buf, cert_sz+1,
  2450. WOLFSSL_FILETYPE_PEM, flags);
  2451. }
  2452. }
  2453. #if defined(WOLFSSL_PEM_TO_DER)
  2454. if (ret == WOLFSSL_SUCCESS) {
  2455. /* test loading DER */
  2456. ret = wc_PemToDer(cert_buf, (sword32)cert_sz, CA_TYPE, &pDer,
  2457. NULL, NULL, NULL);
  2458. if (ret == 0 && pDer != NULL) {
  2459. ret = test_cm_load_ca_buffer_ex(pDer->buffer, pDer->length,
  2460. WOLFSSL_FILETYPE_ASN1, flags);
  2461. wc_FreeDer(&pDer);
  2462. }
  2463. }
  2464. #endif
  2465. }
  2466. free(cert_buf);
  2467. return ret;
  2468. }
  2469. #endif /* !NO_FILESYSTEM && !NO_CERTS */
  2470. static int test_wolfSSL_CertManagerAPI(void)
  2471. {
  2472. EXPECT_DECLS;
  2473. #ifndef NO_CERTS
  2474. WOLFSSL_CERT_MANAGER* cm = NULL;
  2475. unsigned char c;
  2476. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2477. wolfSSL_CertManagerFree(NULL);
  2478. ExpectIntEQ(wolfSSL_CertManager_up_ref(NULL), 0);
  2479. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2480. #ifdef WOLFSSL_TRUST_PEER_CERT
  2481. ExpectIntEQ(wolfSSL_CertManagerUnload_trust_peers(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2482. #endif
  2483. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer_ex(NULL, &c, 1,
  2484. WOLFSSL_FILETYPE_ASN1, 0, 0), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2485. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2486. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, NULL, -1,
  2487. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2488. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, NULL, -1,
  2489. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2490. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, &c, -1,
  2491. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2492. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, NULL, 1,
  2493. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2494. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, &c, 1,
  2495. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2496. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, NULL, 1,
  2497. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2498. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, &c, -1,
  2499. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2500. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, &c, 1, -1),
  2501. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE));
  2502. #endif
  2503. #if !defined(NO_FILESYSTEM)
  2504. {
  2505. const char* ca_cert = "./certs/ca-cert.pem";
  2506. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2507. const char* ca_cert_der = "./certs/ca-cert.der";
  2508. #endif
  2509. const char* ca_path = "./certs";
  2510. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2511. ExpectIntEQ(wolfSSL_CertManagerVerify(NULL, NULL, -1),
  2512. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2513. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, NULL, WOLFSSL_FILETYPE_ASN1),
  2514. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2515. ExpectIntEQ(wolfSSL_CertManagerVerify(NULL, ca_cert,
  2516. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2517. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, ca_cert, -1),
  2518. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE));
  2519. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, "no-file",
  2520. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  2521. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, ca_cert_der,
  2522. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  2523. #endif
  2524. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, NULL, NULL),
  2525. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2526. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, ca_cert, NULL),
  2527. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2528. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, NULL, ca_path),
  2529. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2530. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, ca_cert, ca_path),
  2531. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2532. }
  2533. #endif
  2534. #ifdef OPENSSL_COMPATIBLE_DEFAULTS
  2535. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 0), 1);
  2536. #elif !defined(HAVE_CRL)
  2537. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 0), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2538. #endif
  2539. ExpectIntEQ(wolfSSL_CertManagerDisableCRL(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2540. ExpectIntEQ(wolfSSL_CertManagerDisableCRL(cm), 1);
  2541. #ifdef HAVE_CRL
  2542. /* Test APIs when CRL is disabled. */
  2543. #ifdef HAVE_CRL_IO
  2544. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(cm, NULL), 1);
  2545. #endif
  2546. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  2547. sizeof_server_cert_der_2048), 1);
  2548. ExpectIntEQ(wolfSSL_CertManagerFreeCRL(cm), 1);
  2549. #endif
  2550. /* OCSP */
  2551. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2552. ExpectIntEQ(wolfSSL_CertManagerDisableOCSP(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2553. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2554. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2555. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2556. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2557. #if !defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  2558. !defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  2559. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2560. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2561. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2562. #endif
  2563. #ifdef HAVE_OCSP
  2564. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2565. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2566. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, &c, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2567. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2568. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, &c, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2569. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2570. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, &c, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2571. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(NULL, NULL, 0,
  2572. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2573. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, NULL, 1,
  2574. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2575. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(NULL, &c, 1,
  2576. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2577. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(NULL, NULL),
  2578. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2579. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(NULL, ""),
  2580. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2581. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, NULL), 1);
  2582. ExpectIntEQ(wolfSSL_CertManagerSetOCSP_Cb(NULL, NULL, NULL, NULL),
  2583. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2584. ExpectIntEQ(wolfSSL_CertManagerSetOCSP_Cb(cm, NULL, NULL, NULL), 1);
  2585. ExpectIntEQ(wolfSSL_CertManagerDisableOCSP(cm), 1);
  2586. /* Test APIs when OCSP is disabled. */
  2587. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, &c, 1,
  2588. NULL, NULL, NULL, NULL), 1);
  2589. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, &c, 1), 1);
  2590. #endif
  2591. ExpectIntEQ(wolfSSL_CertManager_up_ref(cm), 1);
  2592. if (EXPECT_SUCCESS()) {
  2593. wolfSSL_CertManagerFree(cm);
  2594. }
  2595. wolfSSL_CertManagerFree(cm);
  2596. cm = NULL;
  2597. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2598. #ifdef HAVE_OCSP
  2599. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, WOLFSSL_OCSP_URL_OVERRIDE |
  2600. WOLFSSL_OCSP_CHECKALL), 1);
  2601. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  2602. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  2603. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2604. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2605. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(cm), 1);
  2606. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2607. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(cm), 1);
  2608. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(cm), 1);
  2609. #endif
  2610. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, ""), 1);
  2611. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, ""), 1);
  2612. #endif
  2613. #ifdef WOLFSSL_TRUST_PEER_CERT
  2614. ExpectIntEQ(wolfSSL_CertManagerUnload_trust_peers(cm), 1);
  2615. #endif
  2616. wolfSSL_CertManagerFree(cm);
  2617. #endif
  2618. return EXPECT_RESULT();
  2619. }
  2620. static int test_wolfSSL_CertManagerLoadCABuffer(void)
  2621. {
  2622. EXPECT_DECLS;
  2623. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2624. const char* ca_cert = "./certs/ca-cert.pem";
  2625. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  2626. int ret;
  2627. ExpectIntLE(ret = test_cm_load_ca_file(ca_cert), 1);
  2628. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2629. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2630. #elif defined(NO_RSA)
  2631. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2632. #else
  2633. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2634. #endif
  2635. ExpectIntLE(ret = test_cm_load_ca_file(ca_expired_cert), 1);
  2636. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2637. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2638. #elif defined(NO_RSA)
  2639. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2640. #elif !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY) && \
  2641. !defined(NO_ASN_TIME)
  2642. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_AFTER_DATE_E));
  2643. #else
  2644. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2645. #endif
  2646. #endif
  2647. return EXPECT_RESULT();
  2648. }
  2649. static int test_wolfSSL_CertManagerLoadCABuffer_ex(void)
  2650. {
  2651. EXPECT_DECLS;
  2652. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2653. const char* ca_cert = "./certs/ca-cert.pem";
  2654. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  2655. int ret;
  2656. ExpectIntLE(ret = test_cm_load_ca_file_ex(ca_cert, WOLFSSL_LOAD_FLAG_NONE),
  2657. 1);
  2658. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2659. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2660. #elif defined(NO_RSA)
  2661. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2662. #else
  2663. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2664. #endif
  2665. ExpectIntLE(ret = test_cm_load_ca_file_ex(ca_expired_cert,
  2666. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), 1);
  2667. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2668. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2669. #elif defined(NO_RSA)
  2670. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2671. #elif !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY) && \
  2672. !defined(NO_ASN_TIME) && defined(WOLFSSL_TRUST_PEER_CERT) && \
  2673. defined(OPENSSL_COMPATIBLE_DEFAULTS)
  2674. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_AFTER_DATE_E));
  2675. #else
  2676. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2677. #endif
  2678. #endif
  2679. return EXPECT_RESULT();
  2680. }
  2681. static int test_wolfSSL_CertManagerGetCerts(void)
  2682. {
  2683. EXPECT_DECLS;
  2684. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  2685. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  2686. defined(WOLFSSL_SIGNER_DER_CERT)
  2687. WOLFSSL_CERT_MANAGER* cm = NULL;
  2688. WOLFSSL_STACK* sk = NULL;
  2689. X509* x509 = NULL;
  2690. X509* cert1 = NULL;
  2691. FILE* file1 = NULL;
  2692. #ifdef DEBUG_WOLFSSL_VERBOSE
  2693. WOLFSSL_BIO* bio = NULL;
  2694. #endif
  2695. int i = 0;
  2696. int ret = 0;
  2697. const byte* der = NULL;
  2698. int derSz = 0;
  2699. ExpectNotNull(file1 = fopen("./certs/ca-cert.pem", "rb"));
  2700. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  2701. if (file1 != NULL) {
  2702. fclose(file1);
  2703. }
  2704. ExpectNull(sk = wolfSSL_CertManagerGetCerts(NULL));
  2705. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2706. ExpectNull(sk = wolfSSL_CertManagerGetCerts(cm));
  2707. ExpectNotNull(der = wolfSSL_X509_get_der(cert1, &derSz));
  2708. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  2709. /* Check that ASN_SELF_SIGNED_E is returned for a self-signed cert for QT
  2710. * and full OpenSSL compatibility */
  2711. ExpectIntEQ(ret = wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2712. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  2713. #else
  2714. ExpectIntEQ(ret = wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2715. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  2716. #endif
  2717. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  2718. "./certs/ca-cert.pem", NULL));
  2719. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(cm));
  2720. for (i = 0; EXPECT_SUCCESS() && i < sk_X509_num(sk); i++) {
  2721. ExpectNotNull(x509 = sk_X509_value(sk, i));
  2722. ExpectIntEQ(0, wolfSSL_X509_cmp(x509, cert1));
  2723. #ifdef DEBUG_WOLFSSL_VERBOSE
  2724. bio = BIO_new(wolfSSL_BIO_s_file());
  2725. if (bio != NULL) {
  2726. BIO_set_fp(bio, stderr, BIO_NOCLOSE);
  2727. X509_print(bio, x509);
  2728. BIO_free(bio);
  2729. }
  2730. #endif /* DEBUG_WOLFSSL_VERBOSE */
  2731. }
  2732. wolfSSL_X509_free(cert1);
  2733. sk_X509_pop_free(sk, NULL);
  2734. wolfSSL_CertManagerFree(cm);
  2735. #endif /* defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  2736. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  2737. defined(WOLFSSL_SIGNER_DER_CERT) */
  2738. return EXPECT_RESULT();
  2739. }
  2740. static int test_wolfSSL_CertManagerSetVerify(void)
  2741. {
  2742. EXPECT_DECLS;
  2743. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2744. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2745. (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH))
  2746. WOLFSSL_CERT_MANAGER* cm = NULL;
  2747. int tmp = myVerifyAction;
  2748. const char* ca_cert = "./certs/ca-cert.pem";
  2749. const char* expiredCert = "./certs/test/expired/expired-cert.pem";
  2750. wolfSSL_CertManagerSetVerify(NULL, NULL);
  2751. wolfSSL_CertManagerSetVerify(NULL, myVerify);
  2752. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2753. wolfSSL_CertManagerSetVerify(cm, myVerify);
  2754. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2755. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL), -1);
  2756. #else
  2757. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL),
  2758. WOLFSSL_SUCCESS);
  2759. #endif
  2760. /* Use the test CB that always accepts certs */
  2761. myVerifyAction = VERIFY_OVERRIDE_ERROR;
  2762. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, expiredCert,
  2763. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2764. #ifdef WOLFSSL_ALWAYS_VERIFY_CB
  2765. {
  2766. const char* verifyCert = "./certs/server-cert.der";
  2767. /* Use the test CB that always fails certs */
  2768. myVerifyAction = VERIFY_FORCE_FAIL;
  2769. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, verifyCert,
  2770. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(VERIFY_CERT_ERROR));
  2771. }
  2772. #endif
  2773. wolfSSL_CertManagerFree(cm);
  2774. myVerifyAction = tmp;
  2775. #endif
  2776. return EXPECT_RESULT();
  2777. }
  2778. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  2779. defined(DEBUG_UNIT_TEST_CERTS)
  2780. /* Used when debugging name constraint tests. Not static to allow use in
  2781. * multiple locations with complex define guards. */
  2782. void DEBUG_WRITE_CERT_X509(WOLFSSL_X509* x509, const char* fileName)
  2783. {
  2784. BIO* out = BIO_new_file(fileName, "wb");
  2785. if (out != NULL) {
  2786. PEM_write_bio_X509(out, x509);
  2787. BIO_free(out);
  2788. }
  2789. }
  2790. void DEBUG_WRITE_DER(const byte* der, int derSz, const char* fileName)
  2791. {
  2792. BIO* out = BIO_new_file(fileName, "wb");
  2793. if (out != NULL) {
  2794. BIO_write(out, der, derSz);
  2795. BIO_free(out);
  2796. }
  2797. }
  2798. #else
  2799. #define DEBUG_WRITE_CERT_X509(x509, fileName) WC_DO_NOTHING
  2800. #define DEBUG_WRITE_DER(der, derSz, fileName) WC_DO_NOTHING
  2801. #endif
  2802. static int test_wolfSSL_CertManagerNameConstraint(void)
  2803. {
  2804. EXPECT_DECLS;
  2805. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2806. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2807. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  2808. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  2809. !defined(NO_SHA256)
  2810. WOLFSSL_CERT_MANAGER* cm = NULL;
  2811. WOLFSSL_EVP_PKEY *priv = NULL;
  2812. WOLFSSL_X509_NAME* name = NULL;
  2813. const char* ca_cert = "./certs/test/cert-ext-nc.der";
  2814. const char* server_cert = "./certs/test/server-goodcn.pem";
  2815. int i = 0;
  2816. static const byte extNameConsOid[] = {85, 29, 30};
  2817. RsaKey key;
  2818. WC_RNG rng;
  2819. byte *der = NULL;
  2820. int derSz = 0;
  2821. word32 idx = 0;
  2822. byte *pt;
  2823. WOLFSSL_X509 *x509 = NULL;
  2824. WOLFSSL_X509 *ca = NULL;
  2825. wc_InitRng(&rng);
  2826. /* load in CA private key for signing */
  2827. ExpectIntEQ(wc_InitRsaKey_ex(&key, HEAP_HINT, testDevId), 0);
  2828. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &key,
  2829. sizeof_server_key_der_2048), 0);
  2830. /* get ca certificate then alter it */
  2831. ExpectNotNull(der =
  2832. (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  2833. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(ca_cert,
  2834. WOLFSSL_FILETYPE_ASN1));
  2835. ExpectNotNull(pt = (byte*)wolfSSL_X509_get_tbs(x509, &derSz));
  2836. if (EXPECT_SUCCESS() && (der != NULL)) {
  2837. XMEMCPY(der, pt, derSz);
  2838. /* find the name constraint extension and alter it */
  2839. pt = der;
  2840. for (i = 0; i < derSz - 3; i++) {
  2841. if (XMEMCMP(pt, extNameConsOid, 3) == 0) {
  2842. pt += 3;
  2843. break;
  2844. }
  2845. pt++;
  2846. }
  2847. ExpectIntNE(i, derSz - 3); /* did not find OID if this case is hit */
  2848. /* go to the length value and set it to 0 */
  2849. while (i < derSz && *pt != 0x81) {
  2850. pt++;
  2851. i++;
  2852. }
  2853. ExpectIntNE(i, derSz); /* did not place to alter */
  2854. pt++;
  2855. *pt = 0x00;
  2856. }
  2857. /* resign the altered certificate */
  2858. ExpectIntGT((derSz = wc_SignCert(derSz, CTC_SHA256wRSA, der,
  2859. FOURK_BUF, &key, NULL, &rng)), 0);
  2860. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2861. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2862. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  2863. wolfSSL_CertManagerFree(cm);
  2864. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2865. wolfSSL_X509_free(x509);
  2866. wc_FreeRsaKey(&key);
  2867. wc_FreeRng(&rng);
  2868. /* add email alt name to satisfy constraint */
  2869. pt = (byte*)server_key_der_2048;
  2870. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  2871. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  2872. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2873. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  2874. WOLFSSL_FILETYPE_ASN1));
  2875. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  2876. DEBUG_WRITE_DER(der, derSz, "ca.der");
  2877. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2878. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2879. /* Good cert test with proper alt email name */
  2880. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2881. WOLFSSL_FILETYPE_PEM));
  2882. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2883. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2884. name = NULL;
  2885. ExpectNotNull(name = X509_NAME_new());
  2886. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2887. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2888. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2889. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2890. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2891. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  2892. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2893. X509_NAME_free(name);
  2894. name = NULL;
  2895. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  2896. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2897. DEBUG_WRITE_CERT_X509(x509, "good-cert.pem");
  2898. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2899. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2900. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2901. wolfSSL_X509_free(x509);
  2902. x509 = NULL;
  2903. /* Cert with bad alt name list */
  2904. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2905. WOLFSSL_FILETYPE_PEM));
  2906. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2907. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2908. name = NULL;
  2909. ExpectNotNull(name = X509_NAME_new());
  2910. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2911. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2912. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2913. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2914. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2915. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  2916. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2917. X509_NAME_free(name);
  2918. wolfSSL_X509_add_altname(x509, "wolfssl@info.com", ASN_RFC822_TYPE);
  2919. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  2920. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2921. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  2922. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2923. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2924. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  2925. wolfSSL_CertManagerFree(cm);
  2926. wolfSSL_X509_free(x509);
  2927. wolfSSL_X509_free(ca);
  2928. wolfSSL_EVP_PKEY_free(priv);
  2929. #endif
  2930. return EXPECT_RESULT();
  2931. }
  2932. static int test_wolfSSL_CertManagerNameConstraint2(void)
  2933. {
  2934. EXPECT_DECLS;
  2935. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2936. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2937. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  2938. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES)
  2939. const char* ca_cert = "./certs/test/cert-ext-ndir.der";
  2940. const char* ca_cert2 = "./certs/test/cert-ext-ndir-exc.der";
  2941. const char* server_cert = "./certs/server-cert.pem";
  2942. WOLFSSL_CERT_MANAGER* cm = NULL;
  2943. WOLFSSL_X509 *x509 = NULL;
  2944. WOLFSSL_X509 *ca = NULL;
  2945. const unsigned char *der = NULL;
  2946. const unsigned char *pt;
  2947. WOLFSSL_EVP_PKEY *priv = NULL;
  2948. WOLFSSL_X509_NAME* name = NULL;
  2949. int derSz = 0;
  2950. /* C=US*/
  2951. char altName[] = {
  2952. 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09,
  2953. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53
  2954. };
  2955. /* C=ID */
  2956. char altNameFail[] = {
  2957. 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09,
  2958. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, 0x44
  2959. };
  2960. /* C=US ST=California*/
  2961. char altNameExc[] = {
  2962. 0x30, 0x22,
  2963. 0x31, 0x0B,
  2964. 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53,
  2965. 0x31, 0x13,
  2966. 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x0A,
  2967. 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61
  2968. };
  2969. /* load in CA private key for signing */
  2970. pt = ca_key_der_2048;
  2971. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &pt,
  2972. sizeof_ca_key_der_2048));
  2973. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2974. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  2975. WOLFSSL_FILETYPE_ASN1));
  2976. ExpectNotNull((der = wolfSSL_X509_get_der(ca, &derSz)));
  2977. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2978. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2979. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2980. WOLFSSL_FILETYPE_PEM));
  2981. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2982. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2983. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2984. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2985. #else
  2986. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2987. #endif
  2988. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2989. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2990. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2991. /* add in matching DIR alt name and resign */
  2992. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  2993. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2994. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2995. #else
  2996. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2997. #endif
  2998. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2999. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3000. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3001. wolfSSL_X509_free(x509);
  3002. x509 = NULL;
  3003. /* check verify fail */
  3004. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3005. WOLFSSL_FILETYPE_PEM));
  3006. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3007. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3008. /* add in miss matching DIR alt name and resign */
  3009. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  3010. ASN_DIR_TYPE);
  3011. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  3012. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  3013. #else
  3014. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  3015. #endif
  3016. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  3017. #ifndef WOLFSSL_NO_ASN_STRICT
  3018. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3019. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3020. #else
  3021. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3022. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3023. #endif
  3024. /* check that it still fails if one bad altname and one good altname is in
  3025. * the certificate */
  3026. wolfSSL_X509_free(x509);
  3027. x509 = NULL;
  3028. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3029. WOLFSSL_FILETYPE_PEM));
  3030. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3031. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3032. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  3033. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  3034. ASN_DIR_TYPE);
  3035. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  3036. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  3037. #else
  3038. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  3039. #endif
  3040. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  3041. #ifndef WOLFSSL_NO_ASN_STRICT
  3042. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3043. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3044. #else
  3045. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3046. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3047. #endif
  3048. /* check it fails with switching position of bad altname */
  3049. wolfSSL_X509_free(x509);
  3050. x509 = NULL;
  3051. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3052. WOLFSSL_FILETYPE_PEM));
  3053. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3054. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3055. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  3056. ASN_DIR_TYPE);
  3057. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  3058. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  3059. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  3060. #else
  3061. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  3062. #endif
  3063. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  3064. #ifndef WOLFSSL_NO_ASN_STRICT
  3065. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3066. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3067. #else
  3068. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3069. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3070. #endif
  3071. wolfSSL_CertManagerFree(cm);
  3072. wolfSSL_X509_free(x509);
  3073. x509 = NULL;
  3074. wolfSSL_X509_free(ca);
  3075. ca = NULL;
  3076. /* now test with excluded name constraint */
  3077. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3078. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert2,
  3079. WOLFSSL_FILETYPE_ASN1));
  3080. ExpectNotNull((der = wolfSSL_X509_get_der(ca, &derSz)));
  3081. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3082. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3083. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3084. WOLFSSL_FILETYPE_PEM));
  3085. wolfSSL_X509_add_altname_ex(x509, altNameExc, sizeof(altNameExc),
  3086. ASN_DIR_TYPE);
  3087. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3088. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3089. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  3090. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  3091. #else
  3092. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  3093. #endif
  3094. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  3095. #ifndef WOLFSSL_NO_ASN_STRICT
  3096. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3097. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3098. #else
  3099. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3100. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3101. #endif
  3102. wolfSSL_CertManagerFree(cm);
  3103. wolfSSL_X509_free(x509);
  3104. wolfSSL_X509_free(ca);
  3105. wolfSSL_EVP_PKEY_free(priv);
  3106. #endif
  3107. return EXPECT_RESULT();
  3108. }
  3109. static int test_wolfSSL_CertManagerNameConstraint3(void)
  3110. {
  3111. EXPECT_DECLS;
  3112. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  3113. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  3114. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  3115. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  3116. !defined(NO_SHA256)
  3117. WOLFSSL_CERT_MANAGER* cm = NULL;
  3118. WOLFSSL_EVP_PKEY *priv = NULL;
  3119. WOLFSSL_X509_NAME* name = NULL;
  3120. const char* ca_cert = "./certs/test/cert-ext-mnc.der";
  3121. const char* server_cert = "./certs/test/server-goodcn.pem";
  3122. byte *der = NULL;
  3123. int derSz = 0;
  3124. byte *pt;
  3125. WOLFSSL_X509 *x509 = NULL;
  3126. WOLFSSL_X509 *ca = NULL;
  3127. pt = (byte*)server_key_der_2048;
  3128. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  3129. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  3130. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3131. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  3132. WOLFSSL_FILETYPE_ASN1));
  3133. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  3134. DEBUG_WRITE_DER(der, derSz, "ca.der");
  3135. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3136. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3137. /* check satisfying .wolfssl.com constraint passes */
  3138. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3139. WOLFSSL_FILETYPE_PEM));
  3140. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3141. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3142. name = NULL;
  3143. ExpectNotNull(name = X509_NAME_new());
  3144. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3145. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3146. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3147. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3148. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  3149. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  3150. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3151. X509_NAME_free(name);
  3152. name = NULL;
  3153. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  3154. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3155. DEBUG_WRITE_CERT_X509(x509, "good-1st-constraint-cert.pem");
  3156. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3157. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3158. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3159. wolfSSL_X509_free(x509);
  3160. x509 = NULL;
  3161. /* check satisfying .random.com constraint passes */
  3162. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3163. WOLFSSL_FILETYPE_PEM));
  3164. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3165. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3166. name = NULL;
  3167. ExpectNotNull(name = X509_NAME_new());
  3168. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3169. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3170. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3171. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3172. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  3173. (byte*)"support@info.example.com", 24, -1, 0), SSL_SUCCESS);
  3174. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3175. X509_NAME_free(name);
  3176. name = NULL;
  3177. wolfSSL_X509_add_altname(x509, "wolfssl@info.example.com", ASN_RFC822_TYPE);
  3178. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3179. DEBUG_WRITE_CERT_X509(x509, "good-2nd-constraint-cert.pem");
  3180. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3181. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3182. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3183. wolfSSL_X509_free(x509);
  3184. x509 = NULL;
  3185. /* check fail case when neither constraint is matched */
  3186. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3187. WOLFSSL_FILETYPE_PEM));
  3188. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3189. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3190. name = NULL;
  3191. ExpectNotNull(name = X509_NAME_new());
  3192. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3193. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3194. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3195. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3196. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  3197. (byte*)"support@info.com", 16, -1, 0), SSL_SUCCESS);
  3198. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3199. X509_NAME_free(name);
  3200. wolfSSL_X509_add_altname(x509, "wolfssl@info.com", ASN_RFC822_TYPE);
  3201. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3202. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  3203. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3204. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3205. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3206. wolfSSL_CertManagerFree(cm);
  3207. wolfSSL_X509_free(x509);
  3208. wolfSSL_X509_free(ca);
  3209. wolfSSL_EVP_PKEY_free(priv);
  3210. #endif
  3211. return EXPECT_RESULT();
  3212. }
  3213. static int test_wolfSSL_CertManagerNameConstraint4(void)
  3214. {
  3215. EXPECT_DECLS;
  3216. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  3217. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  3218. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  3219. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  3220. !defined(NO_SHA256)
  3221. WOLFSSL_CERT_MANAGER* cm = NULL;
  3222. WOLFSSL_EVP_PKEY *priv = NULL;
  3223. WOLFSSL_X509_NAME* name = NULL;
  3224. const char* ca_cert = "./certs/test/cert-ext-ncdns.der";
  3225. const char* server_cert = "./certs/test/server-goodcn.pem";
  3226. byte *der = NULL;
  3227. int derSz;
  3228. byte *pt;
  3229. WOLFSSL_X509 *x509 = NULL;
  3230. WOLFSSL_X509 *ca = NULL;
  3231. pt = (byte*)server_key_der_2048;
  3232. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  3233. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  3234. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3235. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  3236. WOLFSSL_FILETYPE_ASN1));
  3237. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  3238. DEBUG_WRITE_DER(der, derSz, "ca.der");
  3239. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3240. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3241. /* check satisfying wolfssl.com constraint passes */
  3242. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3243. WOLFSSL_FILETYPE_PEM));
  3244. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3245. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3246. name = NULL;
  3247. ExpectNotNull(name = X509_NAME_new());
  3248. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3249. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3250. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3251. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3252. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3253. X509_NAME_free(name);
  3254. name = NULL;
  3255. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3256. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3257. DEBUG_WRITE_CERT_X509(x509, "good-1st-constraint-cert.pem");
  3258. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3259. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3260. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3261. wolfSSL_X509_free(x509);
  3262. x509 = NULL;
  3263. /* check satisfying example.com constraint passes */
  3264. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3265. WOLFSSL_FILETYPE_PEM));
  3266. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3267. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3268. name = NULL;
  3269. ExpectNotNull(name = X509_NAME_new());
  3270. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3271. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3272. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3273. (byte*)"example.com", 11, -1, 0), SSL_SUCCESS);
  3274. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3275. X509_NAME_free(name);
  3276. name = NULL;
  3277. wolfSSL_X509_add_altname(x509, "www.example.com", ASN_DNS_TYPE);
  3278. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3279. DEBUG_WRITE_CERT_X509(x509, "good-2nd-constraint-cert.pem");
  3280. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3281. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3282. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3283. wolfSSL_X509_free(x509);
  3284. x509 = NULL;
  3285. /* check satisfying wolfssl.com constraint passes with list of DNS's */
  3286. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3287. WOLFSSL_FILETYPE_PEM));
  3288. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3289. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3290. name = NULL;
  3291. ExpectNotNull(name = X509_NAME_new());
  3292. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3293. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3294. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3295. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3296. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3297. X509_NAME_free(name);
  3298. name = NULL;
  3299. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3300. wolfSSL_X509_add_altname(x509, "www.info.wolfssl.com", ASN_DNS_TYPE);
  3301. wolfSSL_X509_add_altname(x509, "extra.wolfssl.com", ASN_DNS_TYPE);
  3302. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3303. DEBUG_WRITE_CERT_X509(x509, "good-multiple-constraint-cert.pem");
  3304. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3305. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3306. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3307. wolfSSL_X509_free(x509);
  3308. x509 = NULL;
  3309. /* check fail when one DNS in the list is bad */
  3310. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3311. WOLFSSL_FILETYPE_PEM));
  3312. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3313. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3314. name = NULL;
  3315. ExpectNotNull(name = X509_NAME_new());
  3316. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3317. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3318. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3319. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3320. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3321. X509_NAME_free(name);
  3322. name = NULL;
  3323. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3324. wolfSSL_X509_add_altname(x509, "www.nomatch.com", ASN_DNS_TYPE);
  3325. wolfSSL_X509_add_altname(x509, "www.info.wolfssl.com", ASN_DNS_TYPE);
  3326. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3327. DEBUG_WRITE_CERT_X509(x509, "bad-multiple-constraint-cert.pem");
  3328. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3329. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3330. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3331. wolfSSL_X509_free(x509);
  3332. x509 = NULL;
  3333. /* check fail case when neither constraint is matched */
  3334. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3335. WOLFSSL_FILETYPE_PEM));
  3336. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3337. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3338. name = NULL;
  3339. ExpectNotNull(name = X509_NAME_new());
  3340. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3341. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3342. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3343. (byte*)"common", 6, -1, 0), SSL_SUCCESS);
  3344. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3345. X509_NAME_free(name);
  3346. wolfSSL_X509_add_altname(x509, "www.random.com", ASN_DNS_TYPE);
  3347. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3348. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  3349. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3350. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3351. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3352. wolfSSL_CertManagerFree(cm);
  3353. wolfSSL_X509_free(x509);
  3354. wolfSSL_X509_free(ca);
  3355. wolfSSL_EVP_PKEY_free(priv);
  3356. #endif
  3357. return EXPECT_RESULT();
  3358. }
  3359. static int test_wolfSSL_CertManagerNameConstraint5(void)
  3360. {
  3361. EXPECT_DECLS;
  3362. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  3363. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  3364. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  3365. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  3366. !defined(NO_SHA256)
  3367. WOLFSSL_CERT_MANAGER* cm = NULL;
  3368. WOLFSSL_EVP_PKEY *priv = NULL;
  3369. WOLFSSL_X509_NAME* name = NULL;
  3370. const char* ca_cert = "./certs/test/cert-ext-ncmixed.der";
  3371. const char* server_cert = "./certs/test/server-goodcn.pem";
  3372. byte *der = NULL;
  3373. int derSz;
  3374. byte *pt;
  3375. WOLFSSL_X509 *x509 = NULL;
  3376. WOLFSSL_X509 *ca = NULL;
  3377. pt = (byte*)server_key_der_2048;
  3378. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  3379. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  3380. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3381. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  3382. WOLFSSL_FILETYPE_ASN1));
  3383. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  3384. DEBUG_WRITE_DER(der, derSz, "ca.der");
  3385. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3386. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3387. /* check satisfying wolfssl.com constraint passes */
  3388. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3389. WOLFSSL_FILETYPE_PEM));
  3390. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3391. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3392. name = NULL;
  3393. ExpectNotNull(name = X509_NAME_new());
  3394. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3395. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3396. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3397. (byte*)"example", 7, -1, 0), SSL_SUCCESS);
  3398. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3399. X509_NAME_free(name);
  3400. name = NULL;
  3401. wolfSSL_X509_add_altname(x509, "good.example", ASN_DNS_TYPE);
  3402. wolfSSL_X509_add_altname(x509, "facts@into.wolfssl.com", ASN_RFC822_TYPE);
  3403. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3404. DEBUG_WRITE_CERT_X509(x509, "good-cert.pem");
  3405. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3406. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3407. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3408. wolfSSL_X509_free(x509);
  3409. x509 = NULL;
  3410. /* fail with DNS check because of common name */
  3411. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3412. WOLFSSL_FILETYPE_PEM));
  3413. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3414. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3415. name = NULL;
  3416. ExpectNotNull(name = X509_NAME_new());
  3417. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3418. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3419. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3420. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3421. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3422. X509_NAME_free(name);
  3423. name = NULL;
  3424. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3425. wolfSSL_X509_add_altname(x509, "facts@wolfssl.com", ASN_RFC822_TYPE);
  3426. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3427. DEBUG_WRITE_CERT_X509(x509, "bad-cn-cert.pem");
  3428. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3429. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3430. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3431. wolfSSL_X509_free(x509);
  3432. x509 = NULL;
  3433. /* fail on permitted DNS name constraint */
  3434. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3435. WOLFSSL_FILETYPE_PEM));
  3436. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3437. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3438. name = NULL;
  3439. ExpectNotNull(name = X509_NAME_new());
  3440. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3441. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3442. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3443. X509_NAME_free(name);
  3444. name = NULL;
  3445. wolfSSL_X509_add_altname(x509, "www.example", ASN_DNS_TYPE);
  3446. wolfSSL_X509_add_altname(x509, "www.wolfssl", ASN_DNS_TYPE);
  3447. wolfSSL_X509_add_altname(x509, "info@wolfssl.com", ASN_RFC822_TYPE);
  3448. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3449. DEBUG_WRITE_CERT_X509(x509, "bad-1st-constraint-cert.pem");
  3450. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3451. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3452. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3453. wolfSSL_X509_free(x509);
  3454. x509 = NULL;
  3455. /* fail on permitted email name constraint */
  3456. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3457. WOLFSSL_FILETYPE_PEM));
  3458. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3459. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3460. name = NULL;
  3461. ExpectNotNull(name = X509_NAME_new());
  3462. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3463. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3464. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3465. X509_NAME_free(name);
  3466. name = NULL;
  3467. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3468. wolfSSL_X509_add_altname(x509, "info@wolfssl.com", ASN_RFC822_TYPE);
  3469. wolfSSL_X509_add_altname(x509, "info@example.com", ASN_RFC822_TYPE);
  3470. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3471. DEBUG_WRITE_CERT_X509(x509, "bad-2nd-constraint-cert.pem");
  3472. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3473. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3474. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3475. wolfSSL_X509_free(x509);
  3476. x509 = NULL;
  3477. /* success with empty email name */
  3478. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3479. WOLFSSL_FILETYPE_PEM));
  3480. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3481. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3482. name = NULL;
  3483. ExpectNotNull(name = X509_NAME_new());
  3484. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3485. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3486. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3487. X509_NAME_free(name);
  3488. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3489. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3490. DEBUG_WRITE_CERT_X509(x509, "good-missing-constraint-cert.pem");
  3491. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3492. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3493. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3494. wolfSSL_X509_free(x509);
  3495. wolfSSL_CertManagerFree(cm);
  3496. wolfSSL_X509_free(ca);
  3497. wolfSSL_EVP_PKEY_free(priv);
  3498. #endif
  3499. return EXPECT_RESULT();
  3500. }
  3501. static int test_wolfSSL_CertManagerCRL(void)
  3502. {
  3503. EXPECT_DECLS;
  3504. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && defined(HAVE_CRL) && \
  3505. !defined(NO_RSA)
  3506. const char* ca_cert = "./certs/ca-cert.pem";
  3507. const char* crl1 = "./certs/crl/crl.pem";
  3508. const char* crl2 = "./certs/crl/crl2.pem";
  3509. #ifdef WC_RSA_PSS
  3510. const char* crl_rsapss = "./certs/crl/crl_rsapss.pem";
  3511. const char* ca_rsapss = "./certs/rsapss/ca-rsapss.pem";
  3512. #endif
  3513. const unsigned char crl_buff[] = {
  3514. 0x30, 0x82, 0x02, 0x04, 0x30, 0x81, 0xed, 0x02,
  3515. 0x01, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
  3516. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
  3517. 0x00, 0x30, 0x81, 0x94, 0x31, 0x0b, 0x30, 0x09,
  3518. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  3519. 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  3520. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74,
  3521. 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e, 0x06,
  3522. 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  3523. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x11, 0x30,
  3524. 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08,
  3525. 0x53, 0x61, 0x77, 0x74, 0x6f, 0x6f, 0x74, 0x68,
  3526. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04,
  3527. 0x0b, 0x0c, 0x0a, 0x43, 0x6f, 0x6e, 0x73, 0x75,
  3528. 0x6c, 0x74, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30,
  3529. 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  3530. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66,
  3531. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x31,
  3532. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  3533. 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10,
  3534. 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c,
  3535. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  3536. 0x17, 0x0d, 0x32, 0x32, 0x31, 0x32, 0x31, 0x36,
  3537. 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x17,
  3538. 0x0d, 0x32, 0x35, 0x30, 0x39, 0x31, 0x31, 0x32,
  3539. 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x30, 0x14,
  3540. 0x30, 0x12, 0x02, 0x01, 0x02, 0x17, 0x0d, 0x32,
  3541. 0x32, 0x31, 0x32, 0x31, 0x36, 0x32, 0x31, 0x31,
  3542. 0x37, 0x35, 0x30, 0x5a, 0xa0, 0x0e, 0x30, 0x0c,
  3543. 0x30, 0x0a, 0x06, 0x03, 0x55, 0x1d, 0x14, 0x04,
  3544. 0x03, 0x02, 0x01, 0x02, 0x30, 0x0d, 0x06, 0x09,
  3545. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  3546. 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00,
  3547. 0x39, 0x44, 0xff, 0x39, 0xf4, 0x04, 0x45, 0x79,
  3548. 0x7e, 0x73, 0xe2, 0x42, 0x48, 0xdb, 0x85, 0x66,
  3549. 0xfd, 0x99, 0x76, 0x94, 0x7c, 0xb5, 0x79, 0x5d,
  3550. 0x15, 0x71, 0x36, 0xa9, 0x87, 0xf0, 0x73, 0x05,
  3551. 0x50, 0x08, 0x6b, 0x1c, 0x6e, 0xde, 0x96, 0x45,
  3552. 0x31, 0xc3, 0xc0, 0xba, 0xba, 0xf5, 0x08, 0x1d,
  3553. 0x05, 0x4a, 0x52, 0x39, 0xe9, 0x03, 0xef, 0x59,
  3554. 0xc8, 0x1d, 0x4a, 0xf2, 0x86, 0x05, 0x99, 0x7b,
  3555. 0x4b, 0x74, 0xf6, 0xd3, 0x75, 0x8d, 0xb2, 0x57,
  3556. 0xba, 0xac, 0xa7, 0x11, 0x14, 0xd6, 0x6c, 0x71,
  3557. 0xc4, 0x4c, 0x1c, 0x68, 0xbc, 0x49, 0x78, 0xf0,
  3558. 0xc9, 0x52, 0x8a, 0xe7, 0x8b, 0x54, 0xe6, 0x20,
  3559. 0x58, 0x20, 0x60, 0x66, 0xf5, 0x14, 0xd8, 0xcb,
  3560. 0xff, 0xe0, 0xa0, 0x45, 0xbc, 0xb4, 0x81, 0xad,
  3561. 0x1d, 0xbc, 0xcf, 0xf8, 0x8e, 0xa8, 0x87, 0x24,
  3562. 0x55, 0x99, 0xd9, 0xce, 0x47, 0xf7, 0x5b, 0x4a,
  3563. 0x33, 0x6d, 0xdb, 0xbf, 0x93, 0x64, 0x1a, 0xa6,
  3564. 0x46, 0x5f, 0x27, 0xdc, 0xd8, 0xd4, 0xf9, 0xc2,
  3565. 0x42, 0x2a, 0x7e, 0xb2, 0x7c, 0xdd, 0x98, 0x77,
  3566. 0xf5, 0x88, 0x7d, 0x15, 0x25, 0x08, 0xbc, 0xe0,
  3567. 0xd0, 0x8d, 0xf4, 0xc3, 0xc3, 0x04, 0x41, 0xa4,
  3568. 0xd1, 0xb1, 0x39, 0x4a, 0x6b, 0x2c, 0xb5, 0x2e,
  3569. 0x9a, 0x65, 0x43, 0x0d, 0x0e, 0x73, 0xf4, 0x06,
  3570. 0xe1, 0xb3, 0x49, 0x34, 0x94, 0xb0, 0xb7, 0xff,
  3571. 0xc0, 0x27, 0xc1, 0xb5, 0xea, 0x06, 0xf7, 0x71,
  3572. 0x71, 0x97, 0xbb, 0xbc, 0xc7, 0x1a, 0x9f, 0xeb,
  3573. 0xf6, 0x3d, 0xa5, 0x7b, 0x55, 0xa7, 0xbf, 0xdd,
  3574. 0xd7, 0xee, 0x97, 0xb8, 0x9d, 0xdc, 0xcd, 0xe3,
  3575. 0x06, 0xdb, 0x9a, 0x2c, 0x60, 0xbf, 0x70, 0x84,
  3576. 0xfa, 0x6b, 0x8d, 0x70, 0x7d, 0xde, 0xe8, 0xb7,
  3577. 0xab, 0xb0, 0x38, 0x68, 0x6c, 0xc0, 0xb1, 0xe1,
  3578. 0xba, 0x45, 0xe0, 0xd7, 0x12, 0x3d, 0x71, 0x5b
  3579. };
  3580. WOLFSSL_CERT_MANAGER* cm = NULL;
  3581. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3582. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3583. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), 1);
  3584. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECK), 1);
  3585. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm,
  3586. WOLFSSL_CRL_CHECK | WOLFSSL_CRL_CHECKALL), 1);
  3587. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 16), 1);
  3588. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), 1);
  3589. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3590. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3591. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, server_cert_der_2048, -1),
  3592. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3593. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3594. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, server_cert_der_2048, 1),
  3595. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3596. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3597. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048, -1),
  3598. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3599. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  3600. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  3601. ExpectIntEQ(wolfSSL_CertManagerSetCRL_Cb(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3602. ExpectIntEQ(wolfSSL_CertManagerSetCRL_Cb(cm, NULL), 1);
  3603. #ifdef HAVE_CRL_IO
  3604. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3605. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(cm, NULL), 1);
  3606. #endif
  3607. #ifndef NO_FILESYSTEM
  3608. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(NULL, NULL, WOLFSSL_FILETYPE_ASN1,
  3609. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3610. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(cm, NULL, WOLFSSL_FILETYPE_ASN1,
  3611. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3612. /* -1 seen as !WOLFSSL_FILETYPE_PEM */
  3613. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(cm, "./certs/crl", -1, 0), 1);
  3614. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(NULL, NULL,
  3615. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3616. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, NULL, WOLFSSL_FILETYPE_ASN1),
  3617. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3618. /* -1 seen as !WOLFSSL_FILETYPE_PEM */
  3619. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, "./certs/crl/crl.pem", -1),
  3620. WC_NO_ERR_TRACE(ASN_PARSE_E));
  3621. #endif
  3622. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, NULL, -1,
  3623. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3624. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, NULL, -1,
  3625. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3626. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, crl_buff, -1,
  3627. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3628. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, NULL, 1,
  3629. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3630. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, crl_buff, 1,
  3631. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3632. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, NULL, 1,
  3633. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3634. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, -1,
  3635. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3636. ExpectIntEQ(wolfSSL_CertManagerFreeCRL(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3637. DoExpectIntEQ(wolfSSL_CertManagerFreeCRL(cm), 1);
  3638. ExpectIntEQ(WOLFSSL_SUCCESS,
  3639. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3640. ExpectIntEQ(WOLFSSL_SUCCESS,
  3641. wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0));
  3642. ExpectIntEQ(WOLFSSL_SUCCESS,
  3643. wolfSSL_CertManagerLoadCRL(cm, crl2, WOLFSSL_FILETYPE_PEM, 0));
  3644. wolfSSL_CertManagerFreeCRL(cm);
  3645. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  3646. ExpectIntEQ(WOLFSSL_SUCCESS,
  3647. wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0));
  3648. ExpectIntEQ(WOLFSSL_SUCCESS,
  3649. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3650. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  3651. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(CRL_MISSING));
  3652. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, server_cert_der_2048,
  3653. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(CRL_MISSING));
  3654. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  3655. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, sizeof(crl_buff),
  3656. WOLFSSL_FILETYPE_ASN1), 1);
  3657. #if !defined(NO_FILESYSTEM) && defined(WC_RSA_PSS)
  3658. /* loading should fail without the CA set */
  3659. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crl_rsapss,
  3660. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_CRL_NO_SIGNER_E));
  3661. /* now successfully load the RSA-PSS crl once loading in it's CA */
  3662. ExpectIntEQ(WOLFSSL_SUCCESS,
  3663. wolfSSL_CertManagerLoadCA(cm, ca_rsapss, NULL));
  3664. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crl_rsapss,
  3665. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  3666. #endif
  3667. wolfSSL_CertManagerFree(cm);
  3668. #endif
  3669. return EXPECT_RESULT();
  3670. }
  3671. static int test_wolfSSL_CertManagerCheckOCSPResponse(void)
  3672. {
  3673. EXPECT_DECLS;
  3674. #if defined(HAVE_OCSP) && !defined(NO_RSA) && !defined(NO_SHA)
  3675. /* Need one of these for wolfSSL_OCSP_REQUEST_new. */
  3676. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  3677. defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_APACHE_HTTPD) || \
  3678. defined(HAVE_LIGHTY)
  3679. WOLFSSL_CERT_MANAGER* cm = NULL;
  3680. /* Raw OCSP response bytes captured using the following setup:
  3681. * - Run responder with
  3682. * openssl ocsp -port 9999 -ndays 9999
  3683. * -index certs/ocsp/index-intermediate1-ca-issued-certs.txt
  3684. * -rsigner certs/ocsp/ocsp-responder-cert.pem
  3685. * -rkey certs/ocsp/ocsp-responder-key.pem
  3686. * -CA certs/ocsp/intermediate1-ca-cert.pem
  3687. * - Run client with
  3688. * openssl ocsp -host 127.0.0.1:9999 -respout resp.out
  3689. * -issuer certs/ocsp/intermediate1-ca-cert.pem
  3690. * -cert certs/ocsp/server1-cert.pem
  3691. * -CAfile certs/ocsp/root-ca-cert.pem -noverify
  3692. * - Select the response packet in Wireshark, and export it using
  3693. * "File->Export Packet Dissection->As "C" Arrays". Select "Selected
  3694. * packets only". After importing into the editor, remove the initial
  3695. * ~148 bytes of header, ending with the Content-Length and the \r\n\r\n.
  3696. */
  3697. static const byte response[] = {
  3698. 0x30, 0x82, 0x07, 0x40, /* ....0..@ */
  3699. 0x0a, 0x01, 0x00, 0xa0, 0x82, 0x07, 0x39, 0x30, /* ......90 */
  3700. 0x82, 0x07, 0x35, 0x06, 0x09, 0x2b, 0x06, 0x01, /* ..5..+.. */
  3701. 0x05, 0x05, 0x07, 0x30, 0x01, 0x01, 0x04, 0x82, /* ...0.... */
  3702. 0x07, 0x26, 0x30, 0x82, 0x07, 0x22, 0x30, 0x82, /* .&0.."0. */
  3703. 0x01, 0x40, 0xa1, 0x81, 0xa1, 0x30, 0x81, 0x9e, /* .@...0.. */
  3704. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3705. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, /* ...US1.0 */
  3706. 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, /* ...U.... */
  3707. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, /* Washingt */
  3708. 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, /* on1.0... */
  3709. 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, /* U....Sea */
  3710. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, /* ttle1.0. */
  3711. 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, /* ..U....w */
  3712. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, /* olfSSL1. */
  3713. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, /* 0...U... */
  3714. 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, /* .Enginee */
  3715. 0x72, 0x69, 0x6e, 0x67, 0x31, 0x1f, 0x30, 0x1d, /* ring1.0. */
  3716. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16, 0x77, /* ..U....w */
  3717. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, /* olfSSL O */
  3718. 0x43, 0x53, 0x50, 0x20, 0x52, 0x65, 0x73, 0x70, /* CSP Resp */
  3719. 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, 0x1f, 0x30, /* onder1.0 */
  3720. 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, /* ...*.H.. */
  3721. 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, /* ......in */
  3722. 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73, /* fo@wolfs */
  3723. 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x18, 0x0f, /* sl.com.. */
  3724. 0x32, 0x30, 0x32, 0x33, 0x31, 0x31, 0x30, 0x38, /* 20231108 */
  3725. 0x30, 0x30, 0x32, 0x36, 0x33, 0x37, 0x5a, 0x30, /* 002637Z0 */
  3726. 0x64, 0x30, 0x62, 0x30, 0x3a, 0x30, 0x09, 0x06, /* d0b0:0.. */
  3727. 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, /* .+...... */
  3728. 0x04, 0x14, 0x71, 0x4d, 0x82, 0x23, 0x40, 0x59, /* ..qM.#@Y */
  3729. 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, /* ...7C.1. */
  3730. 0xba, 0xb1, 0x43, 0x18, 0xda, 0x04, 0x04, 0x14, /* ..C..... */
  3731. 0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02, /* ..:.,... */
  3732. 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, /* ..L.*.q. */
  3733. 0x64, 0x44, 0xda, 0x0e, 0x02, 0x01, 0x05, 0x80, /* dD...... */
  3734. 0x00, 0x18, 0x0f, 0x32, 0x30, 0x32, 0x33, 0x31, /* ...20231 */
  3735. 0x31, 0x30, 0x38, 0x30, 0x30, 0x32, 0x36, 0x33, /* 10800263 */
  3736. 0x37, 0x5a, 0xa0, 0x11, 0x18, 0x0f, 0x32, 0x30, /* 7Z....20 */
  3737. 0x35, 0x31, 0x30, 0x33, 0x32, 0x35, 0x30, 0x30, /* 51032500 */
  3738. 0x32, 0x36, 0x33, 0x37, 0x5a, 0xa1, 0x23, 0x30, /* 2637Z.#0 */
  3739. 0x21, 0x30, 0x1f, 0x06, 0x09, 0x2b, 0x06, 0x01, /* !0...+.. */
  3740. 0x05, 0x05, 0x07, 0x30, 0x01, 0x02, 0x04, 0x12, /* ...0.... */
  3741. 0x04, 0x10, 0xdb, 0xbc, 0x2a, 0x76, 0xa0, 0xb4, /* ....*v.. */
  3742. 0x1e, 0x5d, 0xf6, 0x2b, 0x8e, 0x38, 0x62, 0xdb, /* .].+.8b. */
  3743. 0x90, 0xed, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, /* ..0...*. */
  3744. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, /* H....... */
  3745. 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x87, 0xde, /* ........ */
  3746. 0xfb, 0xf9, 0x3a, 0x90, 0x1f, 0x90, 0xde, 0xcf, /* ..:..... */
  3747. 0xfe, 0xad, 0x64, 0x19, 0x34, 0x17, 0xf8, 0x15, /* ..d.4... */
  3748. 0x01, 0x22, 0x5f, 0x67, 0x41, 0xa4, 0x18, 0xf7, /* ."_gA... */
  3749. 0x16, 0xb7, 0xc9, 0xf3, 0xe1, 0x9f, 0xcd, 0x40, /* .......@ */
  3750. 0x56, 0x77, 0x6e, 0x6a, 0xfb, 0x92, 0x6a, 0x6f, /* Vwnj..jo */
  3751. 0x28, 0x3e, 0x22, 0x48, 0xa1, 0xc2, 0xd8, 0x1d, /* (>"H.... */
  3752. 0xc7, 0xe6, 0x78, 0x7f, 0xb6, 0x09, 0xfe, 0x2c, /* ..x...., */
  3753. 0xb5, 0xef, 0x29, 0x7c, 0xc5, 0x51, 0x16, 0x7b, /* ..)|.Q.{ */
  3754. 0x8f, 0xfb, 0x44, 0xa8, 0xcd, 0xf5, 0x5c, 0x0f, /* ..D...\. */
  3755. 0x46, 0x0e, 0xb1, 0xa4, 0xeb, 0x5b, 0xf5, 0x86, /* F....[.. */
  3756. 0x11, 0x0f, 0xcd, 0xe2, 0xe5, 0x3c, 0x91, 0x72, /* .....<.r */
  3757. 0x0d, 0x6a, 0xcb, 0x95, 0x99, 0x39, 0x91, 0x48, /* .j...9.H */
  3758. 0x65, 0x97, 0xb9, 0x78, 0xb5, 0x88, 0x7f, 0x76, /* e..x...v */
  3759. 0xa1, 0x43, 0x2f, 0xf6, 0x1f, 0x49, 0xb7, 0x08, /* .C/..I.. */
  3760. 0x36, 0xe4, 0x2e, 0x34, 0x25, 0xda, 0x16, 0x74, /* 6..4%..t */
  3761. 0x47, 0x62, 0x56, 0xff, 0x2f, 0x02, 0x03, 0x44, /* GbV./..D */
  3762. 0x89, 0x04, 0xe7, 0xb8, 0xde, 0x0a, 0x35, 0x43, /* ......5C */
  3763. 0xae, 0xd7, 0x54, 0xbe, 0xc3, 0x7c, 0x95, 0xa5, /* ..T..|.. */
  3764. 0xc8, 0xe0, 0x2e, 0x52, 0xb6, 0xea, 0x99, 0x45, /* ...R...E */
  3765. 0xfd, 0xda, 0x4b, 0xd5, 0x79, 0x07, 0x64, 0xca, /* ..K.y.d. */
  3766. 0x64, 0xba, 0x52, 0x12, 0x62, 0x8c, 0x08, 0x9a, /* d.R.b... */
  3767. 0x32, 0xeb, 0x85, 0x65, 0x05, 0x39, 0x07, 0x5d, /* 2..e.9.] */
  3768. 0x39, 0x4a, 0xcf, 0xa5, 0x30, 0xf6, 0xd1, 0xf7, /* 9J..0... */
  3769. 0x29, 0xaa, 0x23, 0x42, 0xc6, 0x85, 0x16, 0x7f, /* ).#B.... */
  3770. 0x64, 0x16, 0xb1, 0xb0, 0x5d, 0xcd, 0x88, 0x2d, /* d...]..- */
  3771. 0x06, 0xb0, 0xa9, 0xdf, 0xa3, 0x9f, 0x25, 0x41, /* ......%A */
  3772. 0x89, 0x9a, 0x19, 0xe1, 0xaa, 0xcd, 0xdf, 0x51, /* .......Q */
  3773. 0xcb, 0xa9, 0xc3, 0x7e, 0x27, 0xbc, 0x7d, 0x9b, /* ...~'.}. */
  3774. 0x6f, 0x4d, 0x79, 0x87, 0x09, 0x3f, 0xac, 0xd2, /* oMy..?.. */
  3775. 0x4a, 0x3b, 0xbe, 0xf8, 0x7a, 0xa4, 0x93, 0x45, /* J;..z..E */
  3776. 0x11, 0x64, 0x40, 0xc5, 0x03, 0xc9, 0x24, 0x5b, /* .d@...$[ */
  3777. 0xe9, 0x6d, 0xfc, 0x94, 0x08, 0xbe, 0xa0, 0x82, /* .m...... */
  3778. 0x04, 0xc6, 0x30, 0x82, 0x04, 0xc2, 0x30, 0x82, /* ..0...0. */
  3779. 0x04, 0xbe, 0x30, 0x82, 0x03, 0xa6, 0xa0, 0x03, /* ..0..... */
  3780. 0x02, 0x01, 0x02, 0x02, 0x01, 0x04, 0x30, 0x0d, /* ......0. */
  3781. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, /* ..*.H... */
  3782. 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x81, 0x97, /* .....0.. */
  3783. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3784. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, /* ...US1.0 */
  3785. 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, /* ...U.... */
  3786. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, /* Washingt */
  3787. 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, /* on1.0... */
  3788. 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, /* U....Sea */
  3789. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, /* ttle1.0. */
  3790. 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, /* ..U....w */
  3791. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, /* olfSSL1. */
  3792. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, /* 0...U... */
  3793. 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, /* .Enginee */
  3794. 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16, /* ring1.0. */
  3795. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, /* ..U....w */
  3796. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x72, /* olfSSL r */
  3797. 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f, /* oot CA1. */
  3798. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, /* 0...*.H. */
  3799. 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, /* .......i */
  3800. 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, /* nfo@wolf */
  3801. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, /* ssl.com0 */
  3802. 0x1e, 0x17, 0x0d, 0x32, 0x32, 0x31, 0x32, 0x31, /* ...22121 */
  3803. 0x36, 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, /* 6211750Z */
  3804. 0x17, 0x0d, 0x32, 0x35, 0x30, 0x39, 0x31, 0x31, /* ..250911 */
  3805. 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x30, /* 211750Z0 */
  3806. 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, /* ..1.0... */
  3807. 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, /* U....US1 */
  3808. 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, /* .0...U.. */
  3809. 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, /* ..Washin */
  3810. 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, /* gton1.0. */
  3811. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, /* ..U....S */
  3812. 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, /* eattle1. */
  3813. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, /* 0...U... */
  3814. 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, /* .wolfSSL */
  3815. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3816. 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, /* ...Engin */
  3817. 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x1f, /* eering1. */
  3818. 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, /* 0...U... */
  3819. 0x16, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, /* .wolfSSL */
  3820. 0x20, 0x4f, 0x43, 0x53, 0x50, 0x20, 0x52, 0x65, /* OCSP Re */
  3821. 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, /* sponder1 */
  3822. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, /* .0...*.H */
  3823. 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, /* ........ */
  3824. 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, /* info@wol */
  3825. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, /* fssl.com */
  3826. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, /* 0.."0... */
  3827. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, /* *.H..... */
  3828. 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, /* ........ */
  3829. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, /* 0....... */
  3830. 0x00, 0xb8, 0xba, 0x23, 0xb4, 0xf6, 0xc3, 0x7b, /* ...#...{ */
  3831. 0x14, 0xc3, 0xa4, 0xf5, 0x1d, 0x61, 0xa1, 0xf5, /* .....a.. */
  3832. 0x1e, 0x63, 0xb9, 0x85, 0x23, 0x34, 0x50, 0x6d, /* .c..#4Pm */
  3833. 0xf8, 0x7c, 0xa2, 0x8a, 0x04, 0x8b, 0xd5, 0x75, /* .|.....u */
  3834. 0x5c, 0x2d, 0xf7, 0x63, 0x88, 0xd1, 0x07, 0x7a, /* \-.c...z */
  3835. 0xea, 0x0b, 0x45, 0x35, 0x2b, 0xeb, 0x1f, 0xb1, /* ..E5+... */
  3836. 0x22, 0xb4, 0x94, 0x41, 0x38, 0xe2, 0x9d, 0x74, /* "..A8..t */
  3837. 0xd6, 0x8b, 0x30, 0x22, 0x10, 0x51, 0xc5, 0xdb, /* ..0".Q.. */
  3838. 0xca, 0x3f, 0x46, 0x2b, 0xfe, 0xe5, 0x5a, 0x3f, /* .?F+..Z? */
  3839. 0x41, 0x74, 0x67, 0x75, 0x95, 0xa9, 0x94, 0xd5, /* Atgu.... */
  3840. 0xc3, 0xee, 0x42, 0xf8, 0x8d, 0xeb, 0x92, 0x95, /* ..B..... */
  3841. 0xe1, 0xd9, 0x65, 0xb7, 0x43, 0xc4, 0x18, 0xde, /* ..e.C... */
  3842. 0x16, 0x80, 0x90, 0xce, 0x24, 0x35, 0x21, 0xc4, /* ....$5!. */
  3843. 0x55, 0xac, 0x5a, 0x51, 0xe0, 0x2e, 0x2d, 0xb3, /* U.ZQ..-. */
  3844. 0x0a, 0x5a, 0x4f, 0x4a, 0x73, 0x31, 0x50, 0xee, /* .ZOJs1P. */
  3845. 0x4a, 0x16, 0xbd, 0x39, 0x8b, 0xad, 0x05, 0x48, /* J..9...H */
  3846. 0x87, 0xb1, 0x99, 0xe2, 0x10, 0xa7, 0x06, 0x72, /* .......r */
  3847. 0x67, 0xca, 0x5c, 0xd1, 0x97, 0xbd, 0xc8, 0xf1, /* g.\..... */
  3848. 0x76, 0xf8, 0xe0, 0x4a, 0xec, 0xbc, 0x93, 0xf4, /* v..J.... */
  3849. 0x66, 0x4c, 0x28, 0x71, 0xd1, 0xd8, 0x66, 0x03, /* fL(q..f. */
  3850. 0xb4, 0x90, 0x30, 0xbb, 0x17, 0xb0, 0xfe, 0x97, /* ..0..... */
  3851. 0xf5, 0x1e, 0xe8, 0xc7, 0x5d, 0x9b, 0x8b, 0x11, /* ....]... */
  3852. 0x19, 0x12, 0x3c, 0xab, 0x82, 0x71, 0x78, 0xff, /* ..<..qx. */
  3853. 0xae, 0x3f, 0x32, 0xb2, 0x08, 0x71, 0xb2, 0x1b, /* .?2..q.. */
  3854. 0x8c, 0x27, 0xac, 0x11, 0xb8, 0xd8, 0x43, 0x49, /* .'....CI */
  3855. 0xcf, 0xb0, 0x70, 0xb1, 0xf0, 0x8c, 0xae, 0xda, /* ..p..... */
  3856. 0x24, 0x87, 0x17, 0x3b, 0xd8, 0x04, 0x65, 0x6c, /* $..;..el */
  3857. 0x00, 0x76, 0x50, 0xef, 0x15, 0x08, 0xd7, 0xb4, /* .vP..... */
  3858. 0x73, 0x68, 0x26, 0x14, 0x87, 0x95, 0xc3, 0x5f, /* sh&...._ */
  3859. 0x6e, 0x61, 0xb8, 0x87, 0x84, 0xfa, 0x80, 0x1a, /* na...... */
  3860. 0x0a, 0x8b, 0x98, 0xf3, 0xe3, 0xff, 0x4e, 0x44, /* ......ND */
  3861. 0x1c, 0x65, 0x74, 0x7c, 0x71, 0x54, 0x65, 0xe5, /* .et|qTe. */
  3862. 0x39, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, /* 9....... */
  3863. 0x01, 0x0a, 0x30, 0x82, 0x01, 0x06, 0x30, 0x09, /* ..0...0. */
  3864. 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, /* ..U....0 */
  3865. 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, /* .0...U.. */
  3866. 0x04, 0x16, 0x04, 0x14, 0x32, 0x67, 0xe1, 0xb1, /* ....2g.. */
  3867. 0x79, 0xd2, 0x81, 0xfc, 0x9f, 0x23, 0x0c, 0x70, /* y....#.p */
  3868. 0x40, 0x50, 0xb5, 0x46, 0x56, 0xb8, 0x30, 0x36, /* @P.FV.06 */
  3869. 0x30, 0x81, 0xc4, 0x06, 0x03, 0x55, 0x1d, 0x23, /* 0....U.# */
  3870. 0x04, 0x81, 0xbc, 0x30, 0x81, 0xb9, 0x80, 0x14, /* ...0.... */
  3871. 0x73, 0xb0, 0x1c, 0xa4, 0x2f, 0x82, 0xcb, 0xcf, /* s.../... */
  3872. 0x47, 0xa5, 0x38, 0xd7, 0xb0, 0x04, 0x82, 0x3a, /* G.8....: */
  3873. 0x7e, 0x72, 0x15, 0x21, 0xa1, 0x81, 0x9d, 0xa4, /* ~r.!.... */
  3874. 0x81, 0x9a, 0x30, 0x81, 0x97, 0x31, 0x0b, 0x30, /* ..0..1.0 */
  3875. 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, /* ...U.... */
  3876. 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, /* US1.0... */
  3877. 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, /* U....Was */
  3878. 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, /* hington1 */
  3879. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, /* .0...U.. */
  3880. 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, /* ..Seattl */
  3881. 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, /* e1.0...U */
  3882. 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, /* ....wolf */
  3883. 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, /* SSL1.0.. */
  3884. 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, /* .U....En */
  3885. 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, /* gineerin */
  3886. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, /* g1.0...U */
  3887. 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, /* ....wolf */
  3888. 0x53, 0x53, 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, /* SSL root */
  3889. 0x20, 0x43, 0x41, 0x31, 0x1f, 0x30, 0x1d, 0x06, /* CA1.0.. */
  3890. 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, /* .*.H.... */
  3891. 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, /* ....info */
  3892. 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, /* @wolfssl */
  3893. 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x01, 0x63, 0x30, /* .com..c0 */
  3894. 0x13, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x0c, /* ...U.%.. */
  3895. 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, /* 0...+... */
  3896. 0x05, 0x07, 0x03, 0x09, 0x30, 0x0d, 0x06, 0x09, /* ....0... */
  3897. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, /* *.H..... */
  3898. 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, /* ........ */
  3899. 0x2f, 0xb7, 0x6b, 0xec, 0xb7, 0x12, 0x63, 0xb9, /* /.k...c. */
  3900. 0x57, 0xdc, 0x04, 0x4d, 0x9c, 0x67, 0x74, 0x98, /* W..M.gt. */
  3901. 0x06, 0x28, 0x68, 0x37, 0x34, 0xc2, 0x50, 0xe9, /* .(h74.P. */
  3902. 0x2a, 0xd4, 0x1a, 0xb2, 0x32, 0x1a, 0x9d, 0x2b, /* *...2..+ */
  3903. 0x4f, 0x23, 0x50, 0xea, 0xb4, 0x95, 0x86, 0xc3, /* O#P..... */
  3904. 0xb9, 0x5f, 0x34, 0x3e, 0x99, 0x91, 0xa7, 0x80, /* ._4>.... */
  3905. 0x5f, 0x6e, 0x1b, 0x6e, 0xdb, 0xe9, 0x02, 0x38, /* _n.n...8 */
  3906. 0x6f, 0xdf, 0xc5, 0x9b, 0x0d, 0xa3, 0x1c, 0xa9, /* o....... */
  3907. 0x15, 0x76, 0x16, 0x66, 0xa8, 0x4e, 0xfb, 0xd3, /* .v.f.N.. */
  3908. 0x43, 0x76, 0xf1, 0x72, 0xb7, 0xd1, 0xfa, 0xee, /* Cv.r.... */
  3909. 0x39, 0xa6, 0x96, 0xc1, 0xa2, 0x93, 0xa4, 0x9b, /* 9....... */
  3910. 0x1e, 0x9f, 0xba, 0x71, 0x8f, 0xba, 0xbd, 0x67, /* ...q...g */
  3911. 0x6a, 0xf2, 0x15, 0x5f, 0xf1, 0x64, 0xe7, 0xcf, /* j.._.d.. */
  3912. 0x26, 0xb8, 0x4c, 0xc0, 0xeb, 0x85, 0x04, 0x58, /* &.L....X */
  3913. 0xd9, 0x4a, 0x6b, 0xd9, 0x86, 0xf5, 0x80, 0x21, /* .Jk....! */
  3914. 0xbf, 0x91, 0xc8, 0x4b, 0x9f, 0x04, 0xed, 0x57, /* ...K...W */
  3915. 0x7a, 0xd2, 0x58, 0xac, 0x5b, 0x47, 0xaf, 0x4d, /* z.X.[G.M */
  3916. 0x7f, 0x5b, 0x1d, 0x6d, 0x68, 0x9b, 0x84, 0x98, /* .[.mh... */
  3917. 0x2a, 0x31, 0x02, 0x2c, 0xe9, 0x1b, 0xaf, 0x11, /* *1.,.... */
  3918. 0x0b, 0x78, 0x49, 0xbe, 0x68, 0x68, 0xcb, 0x9c, /* .xI.hh.. */
  3919. 0x41, 0x56, 0xe8, 0xb5, 0x59, 0xda, 0xff, 0xca, /* AV..Y... */
  3920. 0x59, 0x99, 0x17, 0x3e, 0x11, 0x0a, 0x8f, 0x49, /* Y..>...I */
  3921. 0x24, 0x0b, 0x81, 0x42, 0x63, 0xcd, 0x4f, 0xf6, /* $..Bc.O. */
  3922. 0x2b, 0x9d, 0xd1, 0x79, 0x75, 0xd7, 0x4a, 0xcc, /* +..yu.J. */
  3923. 0x4c, 0xb7, 0x2b, 0xd7, 0xe8, 0xe7, 0xd4, 0x48, /* L.+....H */
  3924. 0x3c, 0x14, 0x3b, 0x1c, 0x28, 0xe8, 0x46, 0x7a, /* <.;.(.Fz */
  3925. 0xdc, 0x11, 0x9d, 0x7f, 0x1c, 0xab, 0x10, 0x95, /* ........ */
  3926. 0x17, 0xb2, 0xc7, 0x7a, 0xbb, 0x17, 0x44, 0x59, /* ...z..DY */
  3927. 0x69, 0x8e, 0x16, 0x05, 0x94, 0x8c, 0x88, 0xd9, /* i....... */
  3928. 0xdc, 0x9a, 0xfd, 0xf2, 0x93, 0xbe, 0x68, 0xba, /* ......h. */
  3929. 0x3c, 0xd6, 0x2b, 0x61, 0x3a, 0x8b, 0xf7, 0x66, /* <.+a:..f */
  3930. 0xcb, 0x54, 0xe8, 0xe4, 0xdb, 0x9f, 0xcc, 0x9e /* .T...... */
  3931. };
  3932. OcspEntry entry[1];
  3933. CertStatus status[1];
  3934. OcspRequest* request = NULL;
  3935. #ifndef NO_FILESYSTEM
  3936. const char* ca_cert = "./certs/ca-cert.pem";
  3937. #endif
  3938. byte serial[] = {0x05};
  3939. byte issuerHash[] = {0x71, 0x4d, 0x82, 0x23, 0x40, 0x59, 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, 0xba, 0xb1, 0x43, 0x18, 0xda, 0x04};
  3940. byte issuerKeyHash[] = {0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02, 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, 0x64, 0x44, 0xda, 0x0e};
  3941. XMEMSET(entry, 0, sizeof(OcspEntry));
  3942. XMEMSET(status, 0, sizeof(CertStatus));
  3943. ExpectNotNull(request = wolfSSL_OCSP_REQUEST_new());
  3944. ExpectNotNull(request->serial = (byte*)XMALLOC(sizeof(serial), NULL,
  3945. DYNAMIC_TYPE_OCSP_REQUEST));
  3946. if ((request != NULL) && (request->serial != NULL)) {
  3947. request->serialSz = sizeof(serial);
  3948. XMEMCPY(request->serial, serial, sizeof(serial));
  3949. XMEMCPY(request->issuerHash, issuerHash, sizeof(issuerHash));
  3950. XMEMCPY(request->issuerKeyHash, issuerKeyHash, sizeof(issuerKeyHash));
  3951. }
  3952. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  3953. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, 0), WOLFSSL_SUCCESS);
  3954. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm,
  3955. "./certs/ocsp/intermediate1-ca-cert.pem", NULL), WOLFSSL_SUCCESS);
  3956. /* Response should be valid. */
  3957. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, (byte *)response,
  3958. sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS);
  3959. /* Flip a byte in the request serial number, response should be invalid
  3960. * now. */
  3961. if ((request != NULL) && (request->serial != NULL))
  3962. request->serial[0] ^= request->serial[0];
  3963. ExpectIntNE(wolfSSL_CertManagerCheckOCSPResponse(cm, (byte *)response,
  3964. sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS);
  3965. #ifndef NO_FILESYSTEM
  3966. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, server_cert_der_2048,
  3967. sizeof(server_cert_der_2048)), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  3968. ExpectIntEQ(WOLFSSL_SUCCESS,
  3969. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3970. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, server_cert_der_2048,
  3971. sizeof(server_cert_der_2048)), 1);
  3972. #endif
  3973. wolfSSL_OCSP_REQUEST_free(request);
  3974. wolfSSL_CertManagerFree(cm);
  3975. #endif /* OPENSSL_ALL || WOLFSSL_NGINX || WOLFSSL_HAPROXY ||
  3976. * WOLFSSL_APACHE_HTTPD || HAVE_LIGHTY */
  3977. #endif /* HAVE_OCSP */
  3978. return EXPECT_RESULT();
  3979. }
  3980. static int test_wolfSSL_CheckOCSPResponse(void)
  3981. {
  3982. EXPECT_DECLS;
  3983. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA) && \
  3984. !defined(NO_RSA) && !defined(NO_SHA)
  3985. const char* responseFile = "./certs/ocsp/test-response.der";
  3986. const char* responseMultiFile = "./certs/ocsp/test-multi-response.der";
  3987. const char* responseNoInternFile =
  3988. "./certs/ocsp/test-response-nointern.der";
  3989. const char* caFile = "./certs/ocsp/root-ca-cert.pem";
  3990. OcspResponse* res = NULL;
  3991. byte data[4096];
  3992. const unsigned char* pt;
  3993. int dataSz = 0; /* initialize to mitigate spurious maybe-uninitialized from
  3994. * gcc sanitizer with --enable-heapmath.
  3995. */
  3996. XFILE f = XBADFILE;
  3997. WOLFSSL_OCSP_BASICRESP* bs = NULL;
  3998. WOLFSSL_X509_STORE* st = NULL;
  3999. WOLFSSL_X509* issuer = NULL;
  4000. ExpectTrue((f = XFOPEN(responseFile, "rb")) != XBADFILE);
  4001. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  4002. if (f != XBADFILE) {
  4003. XFCLOSE(f);
  4004. f = XBADFILE;
  4005. }
  4006. pt = data;
  4007. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  4008. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caFile,
  4009. SSL_FILETYPE_PEM));
  4010. ExpectNotNull(st = wolfSSL_X509_STORE_new());
  4011. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(st, issuer), WOLFSSL_SUCCESS);
  4012. ExpectNotNull(bs = wolfSSL_OCSP_response_get1_basic(res));
  4013. ExpectIntEQ(wolfSSL_OCSP_basic_verify(bs, NULL, st, 0), WOLFSSL_SUCCESS);
  4014. wolfSSL_OCSP_BASICRESP_free(bs);
  4015. bs = NULL;
  4016. wolfSSL_OCSP_RESPONSE_free(res);
  4017. res = NULL;
  4018. wolfSSL_X509_STORE_free(st);
  4019. st = NULL;
  4020. wolfSSL_X509_free(issuer);
  4021. issuer = NULL;
  4022. /* check loading a response with optional certs */
  4023. ExpectTrue((f = XFOPEN(responseNoInternFile, "rb")) != XBADFILE);
  4024. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  4025. if (f != XBADFILE)
  4026. XFCLOSE(f);
  4027. f = XBADFILE;
  4028. pt = data;
  4029. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  4030. wolfSSL_OCSP_RESPONSE_free(res);
  4031. res = NULL;
  4032. /* check loading a response with multiple certs */
  4033. {
  4034. WOLFSSL_CERT_MANAGER* cm = NULL;
  4035. OcspEntry *entry = NULL;
  4036. CertStatus* status = NULL;
  4037. OcspRequest* request = NULL;
  4038. byte serial1[] = {0x01};
  4039. byte serial[] = {0x02};
  4040. byte issuerHash[] = {
  4041. 0x44, 0xA8, 0xDB, 0xD1, 0xBC, 0x97, 0x0A, 0x83,
  4042. 0x3B, 0x5B, 0x31, 0x9A, 0x4C, 0xB8, 0xD2, 0x52,
  4043. 0x37, 0x15, 0x8A, 0x88
  4044. };
  4045. byte issuerKeyHash[] = {
  4046. 0x73, 0xB0, 0x1C, 0xA4, 0x2F, 0x82, 0xCB, 0xCF,
  4047. 0x47, 0xA5, 0x38, 0xD7, 0xB0, 0x04, 0x82, 0x3A,
  4048. 0x7E, 0x72, 0x15, 0x21
  4049. };
  4050. ExpectNotNull(entry = (OcspEntry*)XMALLOC(sizeof(OcspEntry), NULL,
  4051. DYNAMIC_TYPE_OPENSSL));
  4052. ExpectNotNull(status = (CertStatus*)XMALLOC(sizeof(CertStatus), NULL,
  4053. DYNAMIC_TYPE_OPENSSL));
  4054. if (entry != NULL)
  4055. XMEMSET(entry, 0, sizeof(OcspEntry));
  4056. if (status != NULL)
  4057. XMEMSET(status, 0, sizeof(CertStatus));
  4058. ExpectNotNull(request = wolfSSL_OCSP_REQUEST_new());
  4059. ExpectNotNull(request->serial = (byte*)XMALLOC(sizeof(serial), NULL,
  4060. DYNAMIC_TYPE_OCSP_REQUEST));
  4061. if (request != NULL && request->serial != NULL) {
  4062. request->serialSz = sizeof(serial);
  4063. XMEMCPY(request->serial, serial, sizeof(serial));
  4064. XMEMCPY(request->issuerHash, issuerHash, sizeof(issuerHash));
  4065. XMEMCPY(request->issuerKeyHash, issuerKeyHash,
  4066. sizeof(issuerKeyHash));
  4067. }
  4068. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  4069. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, 0), WOLFSSL_SUCCESS);
  4070. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, caFile, NULL),
  4071. WOLFSSL_SUCCESS);
  4072. ExpectTrue((f = XFOPEN(responseMultiFile, "rb")) != XBADFILE);
  4073. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  4074. if (f != XBADFILE)
  4075. XFCLOSE(f);
  4076. f = XBADFILE;
  4077. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  4078. dataSz, NULL, status, entry, request), WOLFSSL_SUCCESS);
  4079. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  4080. dataSz, NULL, entry->status, entry, request), WOLFSSL_SUCCESS);
  4081. ExpectNotNull(entry->status);
  4082. if (request != NULL && request->serial != NULL)
  4083. XMEMCPY(request->serial, serial1, sizeof(serial1));
  4084. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  4085. dataSz, NULL, status, entry, request), WOLFSSL_SUCCESS);
  4086. /* store both status's in the entry to check that "next" is not
  4087. * overwritten */
  4088. if (EXPECT_SUCCESS() && status != NULL && entry != NULL) {
  4089. status->next = entry->status;
  4090. entry->status = status;
  4091. }
  4092. if (request != NULL && request->serial != NULL)
  4093. XMEMCPY(request->serial, serial, sizeof(serial));
  4094. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  4095. dataSz, NULL, entry->status, entry, request), WOLFSSL_SUCCESS);
  4096. ExpectNotNull(entry->status->next);
  4097. /* compare the status found */
  4098. ExpectIntEQ(status->serialSz, entry->status->serialSz);
  4099. ExpectIntEQ(XMEMCMP(status->serial, entry->status->serial,
  4100. status->serialSz), 0);
  4101. if (status != NULL && entry != NULL && entry->status != status) {
  4102. XFREE(status, NULL, DYNAMIC_TYPE_OPENSSL);
  4103. }
  4104. wolfSSL_OCSP_CERTID_free(entry);
  4105. wolfSSL_OCSP_REQUEST_free(request);
  4106. wolfSSL_CertManagerFree(cm);
  4107. }
  4108. #if defined(WC_RSA_PSS)
  4109. {
  4110. const char* responsePssFile = "./certs/ocsp/test-response-rsapss.der";
  4111. /* check loading a response with RSA-PSS signature */
  4112. ExpectTrue((f = XFOPEN(responsePssFile, "rb")) != XBADFILE);
  4113. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  4114. if (f != XBADFILE)
  4115. XFCLOSE(f);
  4116. pt = data;
  4117. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  4118. /* try to verify the response */
  4119. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caFile,
  4120. SSL_FILETYPE_PEM));
  4121. ExpectNotNull(st = wolfSSL_X509_STORE_new());
  4122. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(st, issuer), WOLFSSL_SUCCESS);
  4123. ExpectNotNull(bs = wolfSSL_OCSP_response_get1_basic(res));
  4124. ExpectIntEQ(wolfSSL_OCSP_basic_verify(bs, NULL, st, 0),
  4125. WOLFSSL_SUCCESS);
  4126. wolfSSL_OCSP_BASICRESP_free(bs);
  4127. wolfSSL_OCSP_RESPONSE_free(res);
  4128. wolfSSL_X509_STORE_free(st);
  4129. wolfSSL_X509_free(issuer);
  4130. }
  4131. #endif
  4132. #endif /* HAVE_OCSP */
  4133. return EXPECT_RESULT();
  4134. }
  4135. static int test_wolfSSL_FPKI(void)
  4136. {
  4137. EXPECT_DECLS;
  4138. #if defined(WOLFSSL_FPKI) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  4139. XFILE f = XBADFILE;
  4140. const char* fpkiCert = "./certs/fpki-cert.der";
  4141. DecodedCert cert;
  4142. byte buf[4096];
  4143. byte* uuid = NULL;
  4144. byte* fascn = NULL;
  4145. word32 fascnSz;
  4146. word32 uuidSz;
  4147. int bytes = 0;
  4148. ExpectTrue((f = XFOPEN(fpkiCert, "rb")) != XBADFILE);
  4149. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4150. if (f != XBADFILE)
  4151. XFCLOSE(f);
  4152. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4153. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, 0, NULL), 0);
  4154. ExpectIntEQ(wc_GetFASCNFromCert(&cert, NULL, &fascnSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  4155. ExpectNotNull(fascn = (byte*)XMALLOC(fascnSz, NULL,
  4156. DYNAMIC_TYPE_TMP_BUFFER));
  4157. ExpectIntEQ(wc_GetFASCNFromCert(&cert, fascn, &fascnSz), 0);
  4158. XFREE(fascn, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4159. ExpectIntEQ(wc_GetUUIDFromCert(&cert, NULL, &uuidSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  4160. ExpectNotNull(uuid = (byte*)XMALLOC(uuidSz, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  4161. ExpectIntEQ(wc_GetUUIDFromCert(&cert, uuid, &uuidSz), 0);
  4162. XFREE(uuid, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4163. wc_FreeDecodedCert(&cert);
  4164. #endif
  4165. return EXPECT_RESULT();
  4166. }
  4167. /* use RID in confuncture with other names to test parsing of unknown other
  4168. * names */
  4169. static int test_wolfSSL_OtherName(void)
  4170. {
  4171. EXPECT_DECLS;
  4172. #if !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  4173. XFILE f = XBADFILE;
  4174. const char* ridCert = "./certs/rid-cert.der";
  4175. DecodedCert cert;
  4176. byte buf[4096];
  4177. int bytes = 0;
  4178. ExpectTrue((f = XFOPEN(ridCert, "rb")) != XBADFILE);
  4179. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4180. if (f != XBADFILE)
  4181. XFCLOSE(f);
  4182. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4183. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, 0, NULL), 0);
  4184. wc_FreeDecodedCert(&cert);
  4185. #endif
  4186. return EXPECT_RESULT();
  4187. }
  4188. #ifdef HAVE_CERT_CHAIN_VALIDATION
  4189. static int test_wolfSSL_CertRsaPss(void)
  4190. {
  4191. EXPECT_DECLS;
  4192. /* FIPS v2 and below don't support long salts. */
  4193. #if !defined(NO_RSA) && defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM) && \
  4194. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  4195. (HAVE_FIPS_VERSION > 2))) && (!defined(HAVE_SELFTEST) || \
  4196. (defined(HAVE_SELFTEST_VERSION) && (HAVE_SELFTEST_VERSION > 2)))
  4197. XFILE f = XBADFILE;
  4198. const char* rsaPssSha256Cert = "./certs/rsapss/ca-rsapss.der";
  4199. const char* rsaPssRootSha256Cert = "./certs/rsapss/root-rsapss.pem";
  4200. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_PSS_LONG_SALT) && \
  4201. RSA_MAX_SIZE >= 3072
  4202. const char* rsaPssSha384Cert = "./certs/rsapss/ca-3072-rsapss.der";
  4203. #endif
  4204. #if defined(WOLFSSL_SHA384) && RSA_MAX_SIZE >= 3072
  4205. const char* rsaPssRootSha384Cert = "./certs/rsapss/root-3072-rsapss.pem";
  4206. #endif
  4207. DecodedCert cert;
  4208. byte buf[4096];
  4209. int bytes = 0;
  4210. WOLFSSL_CERT_MANAGER* cm = NULL;
  4211. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  4212. ExpectIntEQ(WOLFSSL_SUCCESS,
  4213. wolfSSL_CertManagerLoadCA(cm, rsaPssRootSha256Cert, NULL));
  4214. #if defined(WOLFSSL_SHA384) && RSA_MAX_SIZE >= 3072
  4215. ExpectIntEQ(WOLFSSL_SUCCESS,
  4216. wolfSSL_CertManagerLoadCA(cm, rsaPssRootSha384Cert, NULL));
  4217. #endif
  4218. ExpectTrue((f = XFOPEN(rsaPssSha256Cert, "rb")) != XBADFILE);
  4219. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4220. if (f != XBADFILE) {
  4221. XFCLOSE(f);
  4222. f = XBADFILE;
  4223. }
  4224. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4225. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, VERIFY, cm), 0);
  4226. wc_FreeDecodedCert(&cert);
  4227. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_PSS_LONG_SALT) && \
  4228. RSA_MAX_SIZE >= 3072
  4229. ExpectTrue((f = XFOPEN(rsaPssSha384Cert, "rb")) != XBADFILE);
  4230. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4231. if (f != XBADFILE)
  4232. XFCLOSE(f);
  4233. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4234. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, VERIFY, cm), 0);
  4235. wc_FreeDecodedCert(&cert);
  4236. #endif
  4237. wolfSSL_CertManagerFree(cm);
  4238. #endif
  4239. return EXPECT_RESULT();
  4240. }
  4241. #endif
  4242. static int test_wolfSSL_CTX_load_verify_locations_ex(void)
  4243. {
  4244. EXPECT_DECLS;
  4245. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4246. !defined(NO_WOLFSSL_CLIENT)
  4247. WOLFSSL_CTX* ctx = NULL;
  4248. const char* ca_cert = "./certs/ca-cert.pem";
  4249. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  4250. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4251. /* test good CA */
  4252. ExpectTrue(WOLFSSL_SUCCESS ==
  4253. wolfSSL_CTX_load_verify_locations_ex(ctx, ca_cert, NULL,
  4254. WOLFSSL_LOAD_FLAG_NONE));
  4255. /* test expired CA */
  4256. #if !defined(OPENSSL_COMPATIBLE_DEFAULTS) && !defined(NO_ASN_TIME)
  4257. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4258. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4259. #else
  4260. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4261. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4262. #endif
  4263. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4264. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WOLFSSL_SUCCESS);
  4265. wolfSSL_CTX_free(ctx);
  4266. #endif
  4267. return EXPECT_RESULT();
  4268. }
  4269. static int test_wolfSSL_CTX_load_verify_buffer_ex(void)
  4270. {
  4271. EXPECT_DECLS;
  4272. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  4273. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  4274. WOLFSSL_CTX* ctx;
  4275. const char* ca_expired_cert_file = "./certs/test/expired/expired-ca.der";
  4276. byte ca_expired_cert[TWOK_BUF];
  4277. word32 sizeof_ca_expired_cert = 0;
  4278. XFILE fp = XBADFILE;
  4279. #ifndef NO_WOLFSSL_CLIENT
  4280. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  4281. #else
  4282. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  4283. #endif
  4284. ExpectNotNull(ctx);
  4285. #if defined(USE_CERT_BUFFERS_2048)
  4286. /* test good CA */
  4287. ExpectTrue(WOLFSSL_SUCCESS ==
  4288. wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_cert_der_2048,
  4289. sizeof_ca_cert_der_2048, WOLFSSL_FILETYPE_ASN1, 0,
  4290. WOLFSSL_LOAD_FLAG_NONE));
  4291. #endif
  4292. /* load expired CA */
  4293. XMEMSET(ca_expired_cert, 0, sizeof(ca_expired_cert));
  4294. ExpectTrue((fp = XFOPEN(ca_expired_cert_file, "rb")) != XBADFILE);
  4295. ExpectIntGT(sizeof_ca_expired_cert = (word32)XFREAD(ca_expired_cert, 1,
  4296. sizeof(ca_expired_cert), fp), 0);
  4297. if (fp != XBADFILE)
  4298. XFCLOSE(fp);
  4299. /* test expired CA failure */
  4300. #if !defined(OPENSSL_COMPATIBLE_DEFAULTS) && !defined(NO_ASN_TIME)
  4301. ExpectIntNE(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4302. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4303. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4304. #else
  4305. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4306. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4307. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4308. #endif
  4309. /* test expired CA success */
  4310. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4311. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4312. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WOLFSSL_SUCCESS);
  4313. /* Fail when ctx is NULL. */
  4314. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(NULL, ca_expired_cert,
  4315. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4316. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4317. /* Load as modified cert - bad initial length. */
  4318. ca_expired_cert[2] = 0x7f;
  4319. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4320. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 1,
  4321. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WC_NO_ERR_TRACE(ASN_PARSE_E));
  4322. wolfSSL_CTX_free(ctx);
  4323. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  4324. #endif
  4325. return EXPECT_RESULT();
  4326. }
  4327. static int test_wolfSSL_CTX_load_verify_chain_buffer_format(void)
  4328. {
  4329. EXPECT_DECLS;
  4330. #if !defined(NO_CERTS) && !defined(NO_RSA) && defined(OPENSSL_EXTRA) && \
  4331. defined(USE_CERT_BUFFERS_2048) && (WOLFSSL_MIN_RSA_BITS <= 1024) && \
  4332. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4333. WOLFSSL_CTX* ctx = NULL;
  4334. #ifndef NO_WOLFSSL_CLIENT
  4335. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4336. #else
  4337. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4338. #endif
  4339. /* Public key 140 bytes??? */
  4340. ExpectIntEQ(wolfSSL_CTX_load_verify_chain_buffer_format(ctx,
  4341. ca_cert_chain_der, sizeof_ca_cert_chain_der, WOLFSSL_FILETYPE_ASN1),
  4342. WOLFSSL_SUCCESS);
  4343. wolfSSL_CTX_free(ctx);
  4344. #endif
  4345. return EXPECT_RESULT();
  4346. }
  4347. static int test_wolfSSL_CTX_add1_chain_cert(void)
  4348. {
  4349. EXPECT_DECLS;
  4350. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && defined(OPENSSL_EXTRA) && \
  4351. defined(KEEP_OUR_CERT) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  4352. WOLFSSL_CTX* ctx;
  4353. WOLFSSL* ssl = NULL;
  4354. const char *certChain[] = {
  4355. "./certs/intermediate/client-int-cert.pem",
  4356. "./certs/intermediate/ca-int2-cert.pem",
  4357. "./certs/intermediate/ca-int-cert.pem",
  4358. "./certs/ca-cert.pem",
  4359. NULL
  4360. };
  4361. const char** cert;
  4362. WOLFSSL_X509* x509 = NULL;
  4363. WOLF_STACK_OF(X509)* chain = NULL;
  4364. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4365. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4366. ExpectNotNull(x509 = wolfSSL_X509_new());
  4367. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, x509), 0);
  4368. ExpectIntEQ(SSL_CTX_add0_chain_cert(ctx, x509), 0);
  4369. ExpectIntEQ(SSL_add1_chain_cert(ssl, x509), 0);
  4370. ExpectIntEQ(SSL_add0_chain_cert(ssl, x509), 0);
  4371. wolfSSL_X509_free(x509);
  4372. x509 = NULL;
  4373. for (cert = certChain; EXPECT_SUCCESS() && *cert != NULL; cert++) {
  4374. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(*cert,
  4375. WOLFSSL_FILETYPE_PEM));
  4376. /* Do negative tests once */
  4377. if (cert == certChain) {
  4378. /* Negative tests. */
  4379. ExpectIntEQ(SSL_CTX_add1_chain_cert(NULL, NULL), 0);
  4380. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, NULL), 0);
  4381. ExpectIntEQ(SSL_CTX_add1_chain_cert(NULL, x509), 0);
  4382. ExpectIntEQ(SSL_CTX_add0_chain_cert(NULL, NULL), 0);
  4383. ExpectIntEQ(SSL_CTX_add0_chain_cert(ctx, NULL), 0);
  4384. ExpectIntEQ(SSL_CTX_add0_chain_cert(NULL, x509), 0);
  4385. }
  4386. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, x509), 1);
  4387. X509_free(x509);
  4388. x509 = NULL;
  4389. }
  4390. for (cert = certChain; EXPECT_SUCCESS() && *cert != NULL; cert++) {
  4391. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(*cert,
  4392. WOLFSSL_FILETYPE_PEM));
  4393. /* Do negative tests once */
  4394. if (cert == certChain) {
  4395. /* Negative tests. */
  4396. ExpectIntEQ(SSL_add1_chain_cert(NULL, NULL), 0);
  4397. ExpectIntEQ(SSL_add1_chain_cert(ssl, NULL), 0);
  4398. ExpectIntEQ(SSL_add1_chain_cert(NULL, x509), 0);
  4399. ExpectIntEQ(SSL_add0_chain_cert(NULL, NULL), 0);
  4400. ExpectIntEQ(SSL_add0_chain_cert(ssl, NULL), 0);
  4401. ExpectIntEQ(SSL_add0_chain_cert(NULL, x509), 0);
  4402. }
  4403. ExpectIntEQ(SSL_add1_chain_cert(ssl, x509), 1);
  4404. X509_free(x509);
  4405. x509 = NULL;
  4406. }
  4407. ExpectIntEQ(SSL_CTX_get0_chain_certs(ctx, &chain), 1);
  4408. ExpectIntEQ(sk_X509_num(chain), 3);
  4409. ExpectIntEQ(SSL_get0_chain_certs(ssl, &chain), 1);
  4410. ExpectIntEQ(sk_X509_num(chain), 3);
  4411. SSL_free(ssl);
  4412. SSL_CTX_free(ctx);
  4413. #endif
  4414. return EXPECT_RESULT();
  4415. }
  4416. static int test_wolfSSL_CTX_use_certificate_chain_buffer_format(void)
  4417. {
  4418. EXPECT_DECLS;
  4419. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4420. !defined(NO_WOLFSSL_CLIENT) && defined(USE_CERT_BUFFERS_2048)
  4421. WOLFSSL_CTX* ctx = NULL;
  4422. WOLFSSL* ssl = NULL;
  4423. const char* cert = "./certs/server-cert.pem";
  4424. unsigned char* buf = NULL;
  4425. size_t len;
  4426. ExpectIntEQ(load_file(cert, &buf, &len), 0);
  4427. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4428. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4429. /* Invalid parameters. */
  4430. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(NULL,
  4431. NULL, 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4432. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx,
  4433. NULL, 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  4434. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(NULL,
  4435. server_cert_der_2048, sizeof_server_cert_der_2048,
  4436. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4437. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(NULL, NULL, 0),
  4438. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4439. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx, NULL, 0),
  4440. WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4441. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(NULL, buf, (sword32)len),
  4442. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4443. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(NULL, NULL, 0),
  4444. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4445. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, NULL, 0),
  4446. WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4447. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(NULL, buf, (sword32)len),
  4448. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4449. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx,
  4450. server_cert_der_2048, sizeof_server_cert_der_2048,
  4451. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4452. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx, buf,
  4453. (sword32)len, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4454. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx, buf, (sword32)len),
  4455. WOLFSSL_SUCCESS);
  4456. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx,
  4457. server_cert_der_2048, sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4458. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, buf, (sword32)len),
  4459. WOLFSSL_SUCCESS);
  4460. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, server_cert_der_2048,
  4461. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4462. wolfSSL_free(ssl);
  4463. wolfSSL_CTX_free(ctx);
  4464. if (buf != NULL) {
  4465. free(buf);
  4466. }
  4467. #endif
  4468. return EXPECT_RESULT();
  4469. }
  4470. static int test_wolfSSL_CTX_use_certificate_chain_file_format(void)
  4471. {
  4472. EXPECT_DECLS;
  4473. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4474. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4475. const char* server_chain_der = "./certs/server-cert-chain.der";
  4476. const char* client_single_pem = "./certs/client-cert.pem";
  4477. WOLFSSL_CTX* ctx = NULL;
  4478. (void)server_chain_der;
  4479. (void)client_single_pem;
  4480. (void)ctx;
  4481. #ifndef NO_WOLFSSL_CLIENT
  4482. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4483. #else
  4484. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4485. #endif
  4486. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file_format(ctx,
  4487. server_chain_der, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4488. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file_format(ctx,
  4489. client_single_pem, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4490. wolfSSL_CTX_free(ctx);
  4491. #endif
  4492. return EXPECT_RESULT();
  4493. }
  4494. static int test_wolfSSL_use_certificate_chain_file(void)
  4495. {
  4496. EXPECT_DECLS;
  4497. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4498. !defined(NO_WOLFSSL_CLIENT)
  4499. const char* server_chain_der = "./certs/server-cert-chain.der";
  4500. const char* client_single_pem = "./certs/client-cert.pem";
  4501. WOLFSSL_CTX* ctx = NULL;
  4502. WOLFSSL* ssl = NULL;
  4503. (void)server_chain_der;
  4504. (void)client_single_pem;
  4505. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4506. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4507. /* Invalid parameters. */
  4508. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(NULL, NULL,
  4509. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4510. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl, NULL,
  4511. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4512. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(NULL,
  4513. server_chain_der, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4514. ExpectIntEQ(wolfSSL_use_certificate_chain_file(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4515. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, NULL),
  4516. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4517. ExpectIntEQ(wolfSSL_use_certificate_chain_file(NULL, client_single_pem),
  4518. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4519. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, server_chain_der),
  4520. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4521. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl,
  4522. server_chain_der, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4523. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl,
  4524. client_single_pem, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4525. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, client_single_pem),
  4526. WOLFSSL_SUCCESS);
  4527. wolfSSL_free(ssl);
  4528. wolfSSL_CTX_free(ctx);
  4529. #endif
  4530. return EXPECT_RESULT();
  4531. }
  4532. static int test_wolfSSL_CTX_SetTmpDH_file(void)
  4533. {
  4534. EXPECT_DECLS;
  4535. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_DH) && \
  4536. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4537. WOLFSSL_CTX *ctx = NULL;
  4538. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4539. const char* dsaParamFile = "./certs/dsaparams.pem";
  4540. #endif
  4541. (void)ctx;
  4542. #ifndef NO_WOLFSSL_CLIENT
  4543. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4544. #else
  4545. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4546. #endif
  4547. /* invalid context */
  4548. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(NULL,
  4549. dhParamFile, WOLFSSL_FILETYPE_PEM));
  4550. /* invalid dhParamFile file */
  4551. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx,
  4552. NULL, WOLFSSL_FILETYPE_PEM));
  4553. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx,
  4554. bogusFile, WOLFSSL_FILETYPE_PEM));
  4555. /* success */
  4556. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dhParamFile,
  4557. WOLFSSL_FILETYPE_PEM));
  4558. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4559. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dsaParamFile,
  4560. WOLFSSL_FILETYPE_PEM));
  4561. #endif
  4562. wolfSSL_CTX_free(ctx);
  4563. #endif
  4564. return EXPECT_RESULT();
  4565. }
  4566. static int test_wolfSSL_CTX_SetTmpDH_buffer(void)
  4567. {
  4568. EXPECT_DECLS;
  4569. #if !defined(NO_CERTS) && !defined(NO_DH) && \
  4570. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4571. WOLFSSL_CTX *ctx = NULL;
  4572. #ifndef NO_WOLFSSL_CLIENT
  4573. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4574. #else
  4575. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4576. #endif
  4577. /* invalid context */
  4578. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(NULL,
  4579. dh_key_der_2048, sizeof_dh_key_der_2048,
  4580. WOLFSSL_FILETYPE_ASN1));
  4581. /* invalid dhParamFile file */
  4582. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(NULL, NULL,
  4583. 0, WOLFSSL_FILETYPE_ASN1));
  4584. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx, NULL,
  4585. 0, WOLFSSL_FILETYPE_ASN1));
  4586. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4587. dsa_key_der_2048, sizeof_dsa_key_der_2048,
  4588. WOLFSSL_FILETYPE_ASN1));
  4589. /* invalid file format */
  4590. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4591. dh_key_der_2048, sizeof_dh_key_der_2048, -1));
  4592. /* success */
  4593. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4594. dh_key_der_2048, sizeof_dh_key_der_2048,
  4595. WOLFSSL_FILETYPE_ASN1));
  4596. wolfSSL_CTX_free(ctx);
  4597. #endif
  4598. return EXPECT_RESULT();
  4599. }
  4600. static int test_wolfSSL_CTX_SetMinMaxDhKey_Sz(void)
  4601. {
  4602. EXPECT_DECLS;
  4603. #if !defined(NO_CERTS) && !defined(NO_DH) && \
  4604. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4605. WOLFSSL_CTX *ctx;
  4606. (void)ctx;
  4607. #ifndef NO_WOLFSSL_CLIENT
  4608. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  4609. #else
  4610. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  4611. #endif
  4612. ExpectNotNull(ctx);
  4613. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 3072));
  4614. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_CTX_SetTmpDH_buffer(ctx, dh_key_der_2048,
  4615. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4616. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 2048));
  4617. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4618. dh_key_der_2048, sizeof_dh_key_der_2048,
  4619. WOLFSSL_FILETYPE_ASN1));
  4620. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMaxDhKey_Sz(ctx, 1024));
  4621. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4622. dh_key_der_2048, sizeof_dh_key_der_2048,
  4623. WOLFSSL_FILETYPE_ASN1));
  4624. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMaxDhKey_Sz(ctx, 2048));
  4625. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4626. dh_key_der_2048, sizeof_dh_key_der_2048,
  4627. WOLFSSL_FILETYPE_ASN1));
  4628. wolfSSL_CTX_free(ctx);
  4629. #endif
  4630. return EXPECT_RESULT();
  4631. }
  4632. static int test_wolfSSL_CTX_der_load_verify_locations(void)
  4633. {
  4634. EXPECT_DECLS;
  4635. #if !defined(NO_FILESYSTEM) && defined(WOLFSSL_DER_LOAD) && \
  4636. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4637. WOLFSSL_CTX* ctx = NULL;
  4638. const char* derCert = "./certs/server-cert.der";
  4639. const char* nullPath = NULL;
  4640. const char* invalidPath = "./certs/this-cert-does-not-exist.der";
  4641. const char* emptyPath = "";
  4642. /* der load Case 1 ctx NULL */
  4643. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4644. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4645. #ifndef NO_WOLFSSL_CLIENT
  4646. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4647. #else
  4648. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4649. #endif
  4650. /* Case 2 filePath NULL */
  4651. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, nullPath,
  4652. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4653. /* Case 3 invalid format */
  4654. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4655. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4656. /* Case 4 filePath not valid */
  4657. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, invalidPath,
  4658. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4659. /* Case 5 filePath empty */
  4660. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, emptyPath,
  4661. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4662. #ifndef NO_RSA
  4663. /* Case 6 success case */
  4664. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4665. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4666. #endif
  4667. wolfSSL_CTX_free(ctx);
  4668. #endif
  4669. return EXPECT_RESULT();
  4670. }
  4671. static int test_wolfSSL_CTX_enable_disable(void)
  4672. {
  4673. EXPECT_DECLS;
  4674. #ifndef NO_CERTS
  4675. WOLFSSL_CTX* ctx = NULL;
  4676. #ifdef HAVE_CRL
  4677. ExpectIntEQ(wolfSSL_CTX_DisableCRL(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4678. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4679. #endif
  4680. #ifdef HAVE_OCSP
  4681. ExpectIntEQ(wolfSSL_CTX_DisableOCSP(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4682. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4683. #endif
  4684. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  4685. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  4686. ExpectIntEQ(wolfSSL_CTX_DisableOCSPStapling(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4687. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4688. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4689. ExpectIntEQ(wolfSSL_CTX_EnableOCSPMustStaple(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4690. #endif
  4691. #ifndef NO_WOLFSSL_CLIENT
  4692. #ifdef HAVE_EXTENDED_MASTER
  4693. ExpectIntEQ(wolfSSL_CTX_DisableExtendedMasterSecret(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4694. #endif
  4695. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4696. #ifdef HAVE_EXTENDED_MASTER
  4697. ExpectIntEQ(wolfSSL_CTX_DisableExtendedMasterSecret(ctx), WOLFSSL_SUCCESS);
  4698. #endif
  4699. #elif !defined(NO_WOLFSSL_SERVER)
  4700. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4701. #endif
  4702. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  4703. #ifdef HAVE_CRL
  4704. ExpectIntEQ(wolfSSL_CTX_DisableCRL(ctx), WOLFSSL_SUCCESS);
  4705. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, 0), WOLFSSL_SUCCESS);
  4706. #endif
  4707. #ifdef HAVE_OCSP
  4708. ExpectIntEQ(wolfSSL_CTX_DisableOCSP(ctx), WOLFSSL_SUCCESS);
  4709. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_URL_OVERRIDE),
  4710. WOLFSSL_SUCCESS);
  4711. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_NO_NONCE),
  4712. WOLFSSL_SUCCESS);
  4713. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL),
  4714. WOLFSSL_SUCCESS);
  4715. #endif
  4716. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  4717. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  4718. ExpectIntEQ(wolfSSL_CTX_DisableOCSPStapling(ctx), WOLFSSL_SUCCESS);
  4719. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), WOLFSSL_SUCCESS);
  4720. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WOLFSSL_SUCCESS);
  4721. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WOLFSSL_SUCCESS);
  4722. #endif
  4723. wolfSSL_CTX_free(ctx);
  4724. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  4725. #endif /* NO_CERTS */
  4726. return EXPECT_RESULT();
  4727. }
  4728. static int test_wolfSSL_CTX_ticket_API(void)
  4729. {
  4730. EXPECT_DECLS;
  4731. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER)
  4732. WOLFSSL_CTX* ctx = NULL;
  4733. void *userCtx = (void*)"this is my ctx";
  4734. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4735. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_set_TicketEncCtx(ctx, userCtx));
  4736. ExpectTrue(userCtx == wolfSSL_CTX_get_TicketEncCtx(ctx));
  4737. wolfSSL_CTX_free(ctx);
  4738. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_set_TicketEncCtx(NULL, userCtx));
  4739. ExpectNull(wolfSSL_CTX_get_TicketEncCtx(NULL));
  4740. #endif /* HAVE_SESSION_TICKET && !NO_WOLFSSL_SERVER */
  4741. return EXPECT_RESULT();
  4742. }
  4743. static int test_wolfSSL_set_minmax_proto_version(void)
  4744. {
  4745. EXPECT_DECLS;
  4746. #ifdef OPENSSL_EXTRA
  4747. WOLFSSL_CTX *ctx = NULL;
  4748. WOLFSSL *ssl = NULL;
  4749. (void)ssl;
  4750. #ifndef NO_WOLFSSL_CLIENT
  4751. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4752. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4753. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4754. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4755. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, 0), SSL_SUCCESS);
  4756. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, 0), SSL_SUCCESS);
  4757. ExpectIntEQ(wolfSSL_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4758. ExpectIntEQ(wolfSSL_set_min_proto_version(ssl, 0), SSL_SUCCESS);
  4759. ExpectIntEQ(wolfSSL_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4760. ExpectIntEQ(wolfSSL_set_max_proto_version(ssl, 0), SSL_SUCCESS);
  4761. wolfSSL_free(ssl);
  4762. wolfSSL_CTX_free(ctx);
  4763. ctx = NULL;
  4764. #endif
  4765. #ifndef NO_WOLFSSL_SERVER
  4766. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4767. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4768. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4769. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, 0), SSL_SUCCESS);
  4770. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, 0), SSL_SUCCESS);
  4771. wolfSSL_CTX_free(ctx);
  4772. #endif
  4773. #endif
  4774. return EXPECT_RESULT();
  4775. }
  4776. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_TLS12) && \
  4777. defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  4778. static int test_wolfSSL_CTX_set_max_proto_version_on_result(WOLFSSL* ssl)
  4779. {
  4780. EXPECT_DECLS;
  4781. ExpectStrEQ(wolfSSL_get_version(ssl), "TLSv1.2");
  4782. return EXPECT_RESULT();
  4783. }
  4784. static int test_wolfSSL_CTX_set_max_proto_version_ctx_ready(WOLFSSL_CTX* ctx)
  4785. {
  4786. EXPECT_DECLS;
  4787. /* Set TLS 1.2 */
  4788. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION),
  4789. WOLFSSL_SUCCESS);
  4790. return EXPECT_RESULT();
  4791. }
  4792. /* Test using wolfSSL_CTX_set_max_proto_version to limit the version below
  4793. * what was set at ctx creation. */
  4794. static int test_wolfSSL_CTX_set_max_proto_version(void)
  4795. {
  4796. EXPECT_DECLS;
  4797. test_ssl_cbf client_cbs;
  4798. test_ssl_cbf server_cbs;
  4799. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  4800. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  4801. client_cbs.method = wolfTLS_client_method;
  4802. server_cbs.method = wolfTLS_server_method;
  4803. server_cbs.ctx_ready = test_wolfSSL_CTX_set_max_proto_version_ctx_ready;
  4804. client_cbs.on_result = test_wolfSSL_CTX_set_max_proto_version_on_result;
  4805. server_cbs.on_result = test_wolfSSL_CTX_set_max_proto_version_on_result;
  4806. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  4807. &server_cbs, NULL), TEST_SUCCESS);
  4808. return EXPECT_RESULT();
  4809. }
  4810. #else
  4811. static int test_wolfSSL_CTX_set_max_proto_version(void)
  4812. {
  4813. return TEST_SKIPPED;
  4814. }
  4815. #endif
  4816. /*----------------------------------------------------------------------------*
  4817. | SSL
  4818. *----------------------------------------------------------------------------*/
  4819. static int test_server_wolfSSL_new(void)
  4820. {
  4821. EXPECT_DECLS;
  4822. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4823. !defined(NO_WOLFSSL_SERVER)
  4824. WOLFSSL_CTX *ctx = NULL;
  4825. WOLFSSL_CTX *ctx_nocert = NULL;
  4826. WOLFSSL *ssl = NULL;
  4827. ExpectNotNull(ctx_nocert = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4828. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4829. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  4830. WOLFSSL_FILETYPE_PEM));
  4831. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  4832. WOLFSSL_FILETYPE_PEM));
  4833. /* invalid context */
  4834. ExpectNull(ssl = wolfSSL_new(NULL));
  4835. #if !defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_QT) && \
  4836. !defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_INIT_CTX_KEY)
  4837. ExpectNull(ssl = wolfSSL_new(ctx_nocert));
  4838. #endif
  4839. /* success */
  4840. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4841. wolfSSL_free(ssl);
  4842. wolfSSL_CTX_free(ctx);
  4843. wolfSSL_CTX_free(ctx_nocert);
  4844. #endif
  4845. return EXPECT_RESULT();
  4846. }
  4847. static int test_client_wolfSSL_new(void)
  4848. {
  4849. EXPECT_DECLS;
  4850. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4851. !defined(NO_WOLFSSL_CLIENT)
  4852. WOLFSSL_CTX *ctx = NULL;
  4853. WOLFSSL_CTX *ctx_nocert = NULL;
  4854. WOLFSSL *ssl = NULL;
  4855. ExpectNotNull(ctx_nocert = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4856. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4857. ExpectTrue(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  4858. /* invalid context */
  4859. ExpectNull(ssl = wolfSSL_new(NULL));
  4860. /* success */
  4861. ExpectNotNull(ssl = wolfSSL_new(ctx_nocert));
  4862. wolfSSL_free(ssl);
  4863. ssl = NULL;
  4864. /* success */
  4865. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4866. wolfSSL_free(ssl);
  4867. wolfSSL_CTX_free(ctx);
  4868. wolfSSL_CTX_free(ctx_nocert);
  4869. #endif
  4870. return EXPECT_RESULT();
  4871. }
  4872. static int test_wolfSSL_SetTmpDH_file(void)
  4873. {
  4874. EXPECT_DECLS;
  4875. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_DH) && \
  4876. !defined(NO_WOLFSSL_SERVER)
  4877. WOLFSSL_CTX *ctx = NULL;
  4878. WOLFSSL *ssl = NULL;
  4879. const char* dhX942ParamFile = "./certs/x942dh2048.pem";
  4880. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4881. const char* dsaParamFile = "./certs/dsaparams.pem";
  4882. #endif
  4883. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4884. #ifndef NO_RSA
  4885. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  4886. WOLFSSL_FILETYPE_PEM));
  4887. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  4888. WOLFSSL_FILETYPE_PEM));
  4889. #elif defined(HAVE_ECC)
  4890. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  4891. WOLFSSL_FILETYPE_PEM));
  4892. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  4893. WOLFSSL_FILETYPE_PEM));
  4894. #elif defined(HAVE_ED25519)
  4895. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, edCertFile,
  4896. WOLFSSL_FILETYPE_PEM));
  4897. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, edKeyFile,
  4898. WOLFSSL_FILETYPE_PEM));
  4899. #elif defined(HAVE_ED448)
  4900. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, ed448CertFile,
  4901. WOLFSSL_FILETYPE_PEM));
  4902. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, ed448KeyFile,
  4903. WOLFSSL_FILETYPE_PEM));
  4904. #endif
  4905. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4906. /* invalid ssl */
  4907. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(NULL,
  4908. dhParamFile, WOLFSSL_FILETYPE_PEM));
  4909. /* invalid dhParamFile file */
  4910. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl,
  4911. NULL, WOLFSSL_FILETYPE_PEM));
  4912. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl,
  4913. bogusFile, WOLFSSL_FILETYPE_PEM));
  4914. /* success */
  4915. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl, dhParamFile,
  4916. WOLFSSL_FILETYPE_PEM));
  4917. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl, dhX942ParamFile,
  4918. WOLFSSL_FILETYPE_PEM));
  4919. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4920. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dsaParamFile,
  4921. WOLFSSL_FILETYPE_PEM));
  4922. #endif
  4923. wolfSSL_free(ssl);
  4924. wolfSSL_CTX_free(ctx);
  4925. #endif
  4926. return EXPECT_RESULT();
  4927. }
  4928. static int test_wolfSSL_SetTmpDH_buffer(void)
  4929. {
  4930. EXPECT_DECLS;
  4931. #if !defined(NO_CERTS) && !defined(NO_DH) && !defined(NO_WOLFSSL_SERVER)
  4932. WOLFSSL_CTX *ctx = NULL;
  4933. WOLFSSL *ssl = NULL;
  4934. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4935. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048,
  4936. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4937. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx, server_key_der_2048,
  4938. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4939. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4940. /* invalid ssl */
  4941. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(NULL, dh_key_der_2048,
  4942. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4943. /* invalid dhParamFile file */
  4944. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(NULL, NULL,
  4945. 0, WOLFSSL_FILETYPE_ASN1));
  4946. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, NULL, 0,
  4947. WOLFSSL_FILETYPE_ASN1));
  4948. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dsa_key_der_2048,
  4949. sizeof_dsa_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4950. /* success */
  4951. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4952. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4953. wolfSSL_free(ssl);
  4954. wolfSSL_CTX_free(ctx);
  4955. #endif
  4956. return EXPECT_RESULT();
  4957. }
  4958. static int test_wolfSSL_SetMinMaxDhKey_Sz(void)
  4959. {
  4960. EXPECT_DECLS;
  4961. #if !defined(NO_CERTS) && !defined(NO_DH) && !defined(NO_WOLFSSL_SERVER)
  4962. WOLFSSL_CTX *ctx = NULL;
  4963. WOLFSSL_CTX *ctx2 = NULL;
  4964. WOLFSSL *ssl = NULL;
  4965. WOLFSSL *ssl2 = NULL;
  4966. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4967. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048,
  4968. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4969. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx, server_key_der_2048,
  4970. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4971. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 3072));
  4972. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4973. ExpectNotNull(ctx2 = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4974. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx2, server_cert_der_2048,
  4975. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4976. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx2, server_key_der_2048,
  4977. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4978. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMaxDhKey_Sz(ctx, 1024));
  4979. ExpectNotNull(ssl2 = wolfSSL_new(ctx2));
  4980. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4981. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4982. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMinDhKey_Sz(ssl, 2048));
  4983. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4984. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4985. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMinDhKey_Sz(ssl, 3072));
  4986. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4987. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4988. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl2, dh_key_der_2048,
  4989. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4990. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMaxDhKey_Sz(ssl2, 2048));
  4991. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl2, dh_key_der_2048,
  4992. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4993. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMaxDhKey_Sz(ssl2, 1024));
  4994. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4995. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4996. wolfSSL_free(ssl2);
  4997. wolfSSL_CTX_free(ctx2);
  4998. wolfSSL_free(ssl);
  4999. wolfSSL_CTX_free(ctx);
  5000. #endif
  5001. return EXPECT_RESULT();
  5002. }
  5003. /* Test function for wolfSSL_SetMinVersion. Sets the minimum downgrade version
  5004. * allowed.
  5005. * POST: return 1 on success.
  5006. */
  5007. static int test_wolfSSL_SetMinVersion(void)
  5008. {
  5009. int res = TEST_SKIPPED;
  5010. #ifndef NO_WOLFSSL_CLIENT
  5011. int failFlag = WOLFSSL_SUCCESS;
  5012. WOLFSSL_CTX* ctx = NULL;
  5013. WOLFSSL* ssl = NULL;
  5014. int itr;
  5015. #ifndef NO_OLD_TLS
  5016. const int versions[] = {
  5017. #ifdef WOLFSSL_ALLOW_TLSV10
  5018. WOLFSSL_TLSV1,
  5019. #endif
  5020. WOLFSSL_TLSV1_1,
  5021. WOLFSSL_TLSV1_2};
  5022. #elif !defined(WOLFSSL_NO_TLS12)
  5023. const int versions[] = { WOLFSSL_TLSV1_2 };
  5024. #else
  5025. const int versions[] = { WOLFSSL_TLSV1_3 };
  5026. #endif
  5027. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  5028. ssl = wolfSSL_new(ctx);
  5029. for (itr = 0; itr < (int)(sizeof(versions)/sizeof(int)); itr++) {
  5030. if (wolfSSL_SetMinVersion(ssl, *(versions + itr)) != WOLFSSL_SUCCESS) {
  5031. failFlag = WOLFSSL_FAILURE;
  5032. }
  5033. }
  5034. wolfSSL_free(ssl);
  5035. wolfSSL_CTX_free(ctx);
  5036. res = TEST_RES_CHECK(failFlag == WOLFSSL_SUCCESS);
  5037. #endif
  5038. return res;
  5039. } /* END test_wolfSSL_SetMinVersion */
  5040. #ifdef OPENSSL_EXTRA
  5041. static int test_EC25519(void)
  5042. {
  5043. EXPECT_DECLS;
  5044. #if defined(HAVE_CURVE25519) && defined(WOLFSSL_KEY_GEN)
  5045. byte priv[CURVE25519_KEYSIZE];
  5046. unsigned int privSz = CURVE25519_KEYSIZE;
  5047. byte pub[CURVE25519_KEYSIZE];
  5048. unsigned int pubSz = CURVE25519_KEYSIZE;
  5049. byte priv2[CURVE25519_KEYSIZE];
  5050. unsigned int priv2Sz = CURVE25519_KEYSIZE;
  5051. byte pub2[CURVE25519_KEYSIZE];
  5052. unsigned int pub2Sz = CURVE25519_KEYSIZE;
  5053. byte shared[CURVE25519_KEYSIZE];
  5054. unsigned int sharedSz = CURVE25519_KEYSIZE;
  5055. byte shared2[CURVE25519_KEYSIZE];
  5056. unsigned int shared2Sz = CURVE25519_KEYSIZE;
  5057. /* Bad parameter testing of key generation. */
  5058. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, NULL, NULL, NULL), 0);
  5059. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, &privSz, NULL, &pubSz), 0);
  5060. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5061. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, NULL, pub, &pubSz), 0);
  5062. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5063. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, NULL), 0);
  5064. /* Bad length */
  5065. privSz = 1;
  5066. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  5067. privSz = CURVE25519_KEYSIZE;
  5068. pubSz = 1;
  5069. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  5070. pubSz = CURVE25519_KEYSIZE;
  5071. /* Good case of generating key. */
  5072. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 1);
  5073. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv2, &priv2Sz, pub2, &pub2Sz),
  5074. 1);
  5075. ExpectIntEQ(privSz, CURVE25519_KEYSIZE);
  5076. ExpectIntEQ(pubSz, CURVE25519_KEYSIZE);
  5077. /* Bad parameter testing of shared key. */
  5078. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, NULL, NULL, privSz,
  5079. NULL, pubSz), 0);
  5080. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, NULL, privSz,
  5081. NULL, pubSz), 0);
  5082. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, priv, privSz,
  5083. pub, pubSz), 0);
  5084. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, NULL, privSz,
  5085. pub, pubSz), 0);
  5086. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5087. NULL, pubSz), 0);
  5088. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, priv, privSz,
  5089. pub, pubSz), 0);
  5090. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, NULL, priv, privSz,
  5091. pub, pubSz), 0);
  5092. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, NULL, privSz,
  5093. pub, pubSz), 0);
  5094. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5095. NULL, pubSz), 0);
  5096. /* Bad length. */
  5097. sharedSz = 1;
  5098. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5099. pub, pubSz), 0);
  5100. sharedSz = CURVE25519_KEYSIZE;
  5101. privSz = 1;
  5102. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5103. pub, pubSz), 0);
  5104. privSz = CURVE25519_KEYSIZE;
  5105. pubSz = 1;
  5106. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5107. pub, pubSz), 0);
  5108. pubSz = CURVE25519_KEYSIZE;
  5109. /* Good case of shared key. */
  5110. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5111. pub2, pub2Sz), 1);
  5112. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared2, &shared2Sz, priv2, priv2Sz,
  5113. pub, pubSz), 1);
  5114. ExpectIntEQ(sharedSz, CURVE25519_KEYSIZE);
  5115. ExpectIntEQ(shared2Sz, CURVE25519_KEYSIZE);
  5116. ExpectIntEQ(XMEMCMP(shared, shared2, sharedSz), 0);
  5117. #endif /* HAVE_CURVE25519 && WOLFSSL_KEY_GEN */
  5118. return EXPECT_RESULT();
  5119. }
  5120. static int test_ED25519(void)
  5121. {
  5122. EXPECT_DECLS;
  5123. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  5124. defined(WOLFSSL_KEY_GEN)
  5125. byte priv[ED25519_PRV_KEY_SIZE];
  5126. unsigned int privSz = (unsigned int)sizeof(priv);
  5127. byte pub[ED25519_PUB_KEY_SIZE];
  5128. unsigned int pubSz = (unsigned int)sizeof(pub);
  5129. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_IMPORT)
  5130. const char* msg = TEST_STRING;
  5131. unsigned int msglen = (unsigned int)TEST_STRING_SZ;
  5132. byte sig[ED25519_SIG_SIZE];
  5133. unsigned int sigSz = (unsigned int)sizeof(sig);
  5134. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_IMPORT */
  5135. /* Bad parameter testing of key generation. */
  5136. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, NULL, NULL), 0);
  5137. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, NULL, NULL, NULL), 0);
  5138. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, &privSz, NULL, NULL), 0);
  5139. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, pub, NULL), 0);
  5140. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, NULL, &pubSz), 0);
  5141. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5142. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, NULL, pub, &pubSz), 0);
  5143. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5144. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, NULL), 0);
  5145. /* Bad length. */
  5146. privSz = 1;
  5147. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  5148. privSz = ED25519_PRV_KEY_SIZE;
  5149. pubSz = 1;
  5150. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  5151. pubSz = ED25519_PUB_KEY_SIZE;
  5152. /* Good case of generating key. */
  5153. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz),
  5154. 1);
  5155. ExpectIntEQ(privSz, ED25519_PRV_KEY_SIZE);
  5156. ExpectIntEQ(pubSz, ED25519_PUB_KEY_SIZE);
  5157. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_IMPORT)
  5158. /* Bad parameter testing of signing. */
  5159. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, NULL,
  5160. NULL), 0);
  5161. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, NULL, privSz, NULL,
  5162. NULL), 0);
  5163. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, priv, privSz, NULL,
  5164. NULL), 0);
  5165. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, sig,
  5166. NULL), 0);
  5167. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, NULL,
  5168. &sigSz), 0);
  5169. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, priv, privSz, sig,
  5170. &sigSz), 0);
  5171. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, NULL, privSz, sig,
  5172. &sigSz), 0);
  5173. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, NULL,
  5174. &sigSz), 0);
  5175. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  5176. NULL), 0);
  5177. /* Bad length. */
  5178. privSz = 1;
  5179. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  5180. &sigSz), 0);
  5181. privSz = ED25519_PRV_KEY_SIZE;
  5182. sigSz = 1;
  5183. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  5184. &sigSz), 0);
  5185. sigSz = ED25519_SIG_SIZE;
  5186. /* Good case of signing. */
  5187. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  5188. &sigSz), 1);
  5189. ExpectIntEQ(sigSz, ED25519_SIG_SIZE);
  5190. #ifdef HAVE_ED25519_VERIFY
  5191. /* Bad parameter testing of verification. */
  5192. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, NULL, pubSz, NULL,
  5193. sigSz), 0);
  5194. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, NULL, pubSz, NULL,
  5195. sigSz), 0);
  5196. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, pub, pubSz, NULL,
  5197. sigSz), 0);
  5198. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, NULL, pubSz, sig,
  5199. sigSz), 0);
  5200. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, pub, pubSz, sig,
  5201. sigSz), 0);
  5202. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, NULL, pubSz, sig,
  5203. sigSz), 0);
  5204. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, NULL,
  5205. sigSz), 0);
  5206. /* Bad length. */
  5207. pubSz = 1;
  5208. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5209. sigSz), 0);
  5210. pubSz = ED25519_PUB_KEY_SIZE;
  5211. sigSz = 1;
  5212. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5213. sigSz), 0);
  5214. sigSz = ED25519_SIG_SIZE;
  5215. /* Good case of verification. */
  5216. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5217. sigSz), 1);
  5218. /* Bad signature. */
  5219. if (EXPECT_SUCCESS()) {
  5220. sig[1] ^= 0x80;
  5221. }
  5222. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5223. sigSz), 0);
  5224. #endif /* HAVE_ED25519_VERIFY */
  5225. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_IMPORT */
  5226. #endif /* HAVE_ED25519 && HAVE_ED25519_KEY_EXPORT && WOLFSSL_KEY_GEN */
  5227. return EXPECT_RESULT();
  5228. }
  5229. static int test_EC448(void)
  5230. {
  5231. EXPECT_DECLS;
  5232. #if defined(HAVE_CURVE448) && defined(WOLFSSL_KEY_GEN)
  5233. byte priv[CURVE448_KEY_SIZE];
  5234. unsigned int privSz = CURVE448_KEY_SIZE;
  5235. byte pub[CURVE448_KEY_SIZE];
  5236. unsigned int pubSz = CURVE448_KEY_SIZE;
  5237. byte priv2[CURVE448_KEY_SIZE];
  5238. unsigned int priv2Sz = CURVE448_KEY_SIZE;
  5239. byte pub2[CURVE448_KEY_SIZE];
  5240. unsigned int pub2Sz = CURVE448_KEY_SIZE;
  5241. byte shared[CURVE448_KEY_SIZE];
  5242. unsigned int sharedSz = CURVE448_KEY_SIZE;
  5243. byte shared2[CURVE448_KEY_SIZE];
  5244. unsigned int shared2Sz = CURVE448_KEY_SIZE;
  5245. /* Bad parameter testing of key generation. */
  5246. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, NULL, NULL, NULL), 0);
  5247. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, &privSz, NULL, &pubSz), 0);
  5248. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5249. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, NULL, pub, &pubSz), 0);
  5250. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5251. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, NULL), 0);
  5252. /* Bad length. */
  5253. privSz = 1;
  5254. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5255. privSz = CURVE448_KEY_SIZE;
  5256. pubSz = 1;
  5257. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5258. pubSz = CURVE448_KEY_SIZE;
  5259. /* Good case of generating key. */
  5260. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 1);
  5261. ExpectIntEQ(wolfSSL_EC448_generate_key(priv2, &priv2Sz, pub2, &pub2Sz), 1);
  5262. ExpectIntEQ(privSz, CURVE448_KEY_SIZE);
  5263. ExpectIntEQ(pubSz, CURVE448_KEY_SIZE);
  5264. /* Bad parameter testing of shared key. */
  5265. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, NULL, NULL, privSz,
  5266. NULL, pubSz), 0);
  5267. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, NULL, privSz,
  5268. NULL, pubSz), 0);
  5269. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, priv, privSz,
  5270. pub, pubSz), 0);
  5271. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, NULL, privSz,
  5272. pub, pubSz), 0);
  5273. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5274. NULL, pubSz), 0);
  5275. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, priv, privSz,
  5276. pub, pubSz), 0);
  5277. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, NULL, priv, privSz,
  5278. pub, pubSz), 0);
  5279. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, NULL, privSz,
  5280. pub, pubSz), 0);
  5281. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5282. NULL, pubSz), 0);
  5283. /* Bad length. */
  5284. sharedSz = 1;
  5285. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5286. pub, pubSz), 0);
  5287. sharedSz = CURVE448_KEY_SIZE;
  5288. privSz = 1;
  5289. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5290. pub, pubSz), 0);
  5291. privSz = CURVE448_KEY_SIZE;
  5292. pubSz = 1;
  5293. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5294. pub, pubSz), 0);
  5295. pubSz = CURVE448_KEY_SIZE;
  5296. /* Good case of shared key. */
  5297. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5298. pub2, pub2Sz), 1);
  5299. ExpectIntEQ(wolfSSL_EC448_shared_key(shared2, &shared2Sz, priv2, priv2Sz,
  5300. pub, pubSz), 1);
  5301. ExpectIntEQ(sharedSz, CURVE448_KEY_SIZE);
  5302. ExpectIntEQ(shared2Sz, CURVE448_KEY_SIZE);
  5303. ExpectIntEQ(XMEMCMP(shared, shared2, sharedSz), 0);
  5304. #endif /* HAVE_CURVE448 && WOLFSSL_KEY_GEN */
  5305. return EXPECT_RESULT();
  5306. }
  5307. static int test_ED448(void)
  5308. {
  5309. EXPECT_DECLS;
  5310. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  5311. defined(WOLFSSL_KEY_GEN)
  5312. byte priv[ED448_PRV_KEY_SIZE];
  5313. unsigned int privSz = (unsigned int)sizeof(priv);
  5314. byte pub[ED448_PUB_KEY_SIZE];
  5315. unsigned int pubSz = (unsigned int)sizeof(pub);
  5316. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_IMPORT)
  5317. const char* msg = TEST_STRING;
  5318. unsigned int msglen = (unsigned int)TEST_STRING_SZ;
  5319. byte sig[ED448_SIG_SIZE];
  5320. unsigned int sigSz = (unsigned int)sizeof(sig);
  5321. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_IMPORT */
  5322. /* Bad parameter testing of key generation. */
  5323. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, NULL, NULL), 0);
  5324. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, NULL, NULL, NULL), 0);
  5325. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, &privSz, NULL, NULL), 0);
  5326. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, pub, NULL), 0);
  5327. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, NULL, &pubSz), 0);
  5328. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5329. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, NULL, pub, &pubSz), 0);
  5330. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5331. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, NULL), 0);
  5332. /* Bad length. */
  5333. privSz = 1;
  5334. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5335. privSz = ED448_PRV_KEY_SIZE;
  5336. pubSz = 1;
  5337. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5338. pubSz = ED448_PUB_KEY_SIZE;
  5339. /* Good case of generating key. */
  5340. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 1);
  5341. ExpectIntEQ(privSz, ED448_PRV_KEY_SIZE);
  5342. ExpectIntEQ(pubSz, ED448_PUB_KEY_SIZE);
  5343. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_IMPORT)
  5344. /* Bad parameter testing of signing. */
  5345. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, NULL,
  5346. NULL), 0);
  5347. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, NULL, privSz, NULL,
  5348. NULL), 0);
  5349. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, priv, privSz, NULL,
  5350. NULL), 0);
  5351. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, sig,
  5352. NULL), 0);
  5353. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, NULL,
  5354. &sigSz), 0);
  5355. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, priv, privSz, sig,
  5356. &sigSz), 0);
  5357. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, NULL, privSz, sig,
  5358. &sigSz), 0);
  5359. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, NULL,
  5360. &sigSz), 0);
  5361. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5362. NULL), 0);
  5363. /* Bad length. */
  5364. privSz = 1;
  5365. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5366. &sigSz), 0);
  5367. privSz = ED448_PRV_KEY_SIZE;
  5368. sigSz = 1;
  5369. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5370. &sigSz), 0);
  5371. sigSz = ED448_SIG_SIZE;
  5372. /* Good case of signing. */
  5373. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5374. &sigSz), 1);
  5375. ExpectIntEQ(sigSz, ED448_SIG_SIZE);
  5376. #ifdef HAVE_ED448_VERIFY
  5377. /* Bad parameter testing of verification. */
  5378. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, NULL, pubSz, NULL,
  5379. sigSz), 0);
  5380. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, NULL, pubSz, NULL,
  5381. sigSz), 0);
  5382. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, pub, pubSz, NULL,
  5383. sigSz), 0);
  5384. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, NULL, pubSz, sig,
  5385. sigSz), 0);
  5386. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, pub, pubSz, sig,
  5387. sigSz), 0);
  5388. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, NULL, pubSz, sig,
  5389. sigSz), 0);
  5390. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, NULL,
  5391. sigSz), 0);
  5392. /* Bad length. */
  5393. pubSz = 1;
  5394. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5395. sigSz), 0);
  5396. pubSz = ED448_PUB_KEY_SIZE;
  5397. sigSz = 1;
  5398. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5399. sigSz), 0);
  5400. sigSz = ED448_SIG_SIZE;
  5401. /* Good case of verification. */
  5402. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5403. sigSz), 1);
  5404. /* Bad signature. */
  5405. if (EXPECT_SUCCESS()) {
  5406. sig[1] ^= 0x80;
  5407. }
  5408. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5409. sigSz), 0);
  5410. #endif /* HAVE_ED448_VERIFY */
  5411. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_IMPORT */
  5412. #endif /* HAVE_ED448 && HAVE_ED448_KEY_EXPORT && WOLFSSL_KEY_GEN */
  5413. return EXPECT_RESULT();
  5414. }
  5415. #endif /* OPENSSL_EXTRA */
  5416. #include <wolfssl/openssl/pem.h>
  5417. /*----------------------------------------------------------------------------*
  5418. | EVP
  5419. *----------------------------------------------------------------------------*/
  5420. static int test_wolfSSL_EVP_PKEY_print_public(void)
  5421. {
  5422. EXPECT_DECLS;
  5423. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  5424. WOLFSSL_BIO* rbio = NULL;
  5425. WOLFSSL_BIO* wbio = NULL;
  5426. WOLFSSL_EVP_PKEY* pkey = NULL;
  5427. char line[256] = { 0 };
  5428. char line1[256] = { 0 };
  5429. int i = 0;
  5430. /* test error cases */
  5431. ExpectIntEQ( EVP_PKEY_print_public(NULL,NULL,0,NULL),0L);
  5432. /*
  5433. * test RSA public key print
  5434. * in this test, pass '3' for indent
  5435. */
  5436. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_1024)
  5437. ExpectNotNull(rbio = BIO_new_mem_buf( client_keypub_der_1024,
  5438. sizeof_client_keypub_der_1024));
  5439. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5440. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5441. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,3,NULL),1);
  5442. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5443. strcpy(line1, " RSA Public-Key: (1024 bit)\n");
  5444. ExpectIntEQ(XSTRNCMP(line, line1, XSTRLEN(line1)), 0);
  5445. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5446. strcpy(line1, " Modulus:\n");
  5447. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5448. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5449. strcpy(line1, " 00:bc:73:0e:a8:49:f3:74:a2:a9:ef:18:a5:da:55:\n");
  5450. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5451. /* skip to the end of modulus element*/
  5452. for (i = 0; i < 8 ;i++) {
  5453. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5454. }
  5455. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5456. strcpy(line1, " Exponent: 65537 (0x010001)\n");
  5457. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5458. /* should reach EOF */
  5459. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5460. EVP_PKEY_free(pkey);
  5461. pkey = NULL;
  5462. BIO_free(rbio);
  5463. BIO_free(wbio);
  5464. rbio = NULL;
  5465. wbio = NULL;
  5466. #endif /* !NO_RSA && USE_CERT_BUFFERS_1024*/
  5467. /*
  5468. * test DSA public key print
  5469. */
  5470. #if !defined(NO_DSA) && defined(USE_CERT_BUFFERS_2048)
  5471. ExpectNotNull(rbio = BIO_new_mem_buf( dsa_pub_key_der_2048,
  5472. sizeof_dsa_pub_key_der_2048));
  5473. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5474. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5475. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL),1);
  5476. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5477. strcpy(line1, "DSA Public-Key: (2048 bit)\n");
  5478. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5479. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5480. strcpy(line1, "pub:\n");
  5481. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5482. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5483. strcpy(line1,
  5484. " 00:C2:35:2D:EC:83:83:6C:73:13:9E:52:7C:74:C8:\n");
  5485. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5486. /* skip to the end of pub element*/
  5487. for (i = 0; i < 17 ;i++) {
  5488. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5489. }
  5490. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5491. strcpy(line1, "P:\n");
  5492. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5493. /* skip to the end of P element*/
  5494. for (i = 0; i < 18 ;i++) {
  5495. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5496. }
  5497. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5498. strcpy(line1, "Q:\n");
  5499. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5500. /* skip to the end of Q element*/
  5501. for (i = 0; i < 3 ;i++) {
  5502. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5503. }
  5504. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5505. strcpy(line1, "G:\n");
  5506. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5507. /* skip to the end of G element*/
  5508. for (i = 0; i < 18 ;i++) {
  5509. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5510. }
  5511. /* should reach EOF */
  5512. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5513. EVP_PKEY_free(pkey);
  5514. pkey = NULL;
  5515. BIO_free(rbio);
  5516. BIO_free(wbio);
  5517. rbio = NULL;
  5518. wbio = NULL;
  5519. #endif /* !NO_DSA && USE_CERT_BUFFERS_2048 */
  5520. /*
  5521. * test ECC public key print
  5522. */
  5523. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  5524. ExpectNotNull(rbio = BIO_new_mem_buf( ecc_clikeypub_der_256,
  5525. sizeof_ecc_clikeypub_der_256));
  5526. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5527. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5528. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL),1);
  5529. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5530. strcpy(line1, "Public-Key: (256 bit)\n");
  5531. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5532. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5533. strcpy(line1, "pub:\n");
  5534. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5535. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5536. strcpy(line1,
  5537. " 04:55:BF:F4:0F:44:50:9A:3D:CE:9B:B7:F0:C5:4D:\n");
  5538. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5539. /* skip to the end of pub element*/
  5540. for (i = 0; i < 4 ;i++) {
  5541. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5542. }
  5543. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5544. strcpy(line1, "ASN1 OID: prime256v1\n");
  5545. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5546. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5547. strcpy(line1, "NIST CURVE: P-256\n");
  5548. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5549. /* should reach EOF */
  5550. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5551. EVP_PKEY_free(pkey);
  5552. pkey = NULL;
  5553. BIO_free(rbio);
  5554. BIO_free(wbio);
  5555. rbio = NULL;
  5556. wbio = NULL;
  5557. #endif /* HAVE_ECC && USE_CERT_BUFFERS_256 */
  5558. /*
  5559. * test DH public key print
  5560. */
  5561. #if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048)
  5562. ExpectNotNull(rbio = BIO_new_mem_buf( dh_pub_key_der_2048,
  5563. sizeof_dh_pub_key_der_2048));
  5564. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5565. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5566. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL), 1);
  5567. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5568. strcpy(line1, "DH Public-Key: (2048 bit)\n");
  5569. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5570. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5571. strcpy(line1, "public-key:\n");
  5572. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5573. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5574. strcpy(line1,
  5575. " 34:41:BF:E9:F2:11:BF:05:DB:B2:72:A8:29:CC:BD:\n");
  5576. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5577. /* skip to the end of public-key element*/
  5578. for (i = 0; i < 17 ;i++) {
  5579. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5580. }
  5581. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5582. strcpy(line1, "prime:\n");
  5583. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5584. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5585. strcpy(line1,
  5586. " 00:D3:B2:99:84:5C:0A:4C:E7:37:CC:FC:18:37:01:\n");
  5587. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5588. /* skip to the end of prime element*/
  5589. for (i = 0; i < 17 ;i++) {
  5590. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5591. }
  5592. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5593. strcpy(line1, "generator: 2 (0x02)\n");
  5594. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5595. /* should reach EOF */
  5596. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5597. EVP_PKEY_free(pkey);
  5598. pkey = NULL;
  5599. BIO_free(rbio);
  5600. BIO_free(wbio);
  5601. rbio = NULL;
  5602. wbio = NULL;
  5603. #endif /* WOLFSSL_DH_EXTRA && USE_CERT_BUFFERS_2048 */
  5604. /* to prevent "unused variable" warning */
  5605. (void)pkey;
  5606. (void)wbio;
  5607. (void)rbio;
  5608. (void)line;
  5609. (void)line1;
  5610. (void)i;
  5611. #endif /* OPENSSL_EXTRA */
  5612. return EXPECT_RESULT();
  5613. }
  5614. /* Test functions for base64 encode/decode */
  5615. static int test_wolfSSL_EVP_ENCODE_CTX_new(void)
  5616. {
  5617. EXPECT_DECLS;
  5618. #if defined(OPENSSL_EXTRA) && \
  5619. ( defined(WOLFSSL_BASE64_ENCODE) || defined(WOLFSSL_BASE64_DECODE))
  5620. EVP_ENCODE_CTX* ctx = NULL;
  5621. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5622. ExpectIntEQ(ctx->remaining,0);
  5623. ExpectIntEQ(ctx->data[0],0);
  5624. ExpectIntEQ(ctx->data[sizeof(ctx->data) -1],0);
  5625. EVP_ENCODE_CTX_free(ctx);
  5626. #endif /* OPENSSL_EXTRA && (WOLFSSL_BASE64_ENCODE || WOLFSSL_BASE64_DECODE) */
  5627. return EXPECT_RESULT();
  5628. }
  5629. static int test_wolfSSL_EVP_ENCODE_CTX_free(void)
  5630. {
  5631. EXPECT_DECLS;
  5632. #if defined(OPENSSL_EXTRA) && \
  5633. ( defined(WOLFSSL_BASE64_ENCODE) || defined(WOLFSSL_BASE64_DECODE))
  5634. EVP_ENCODE_CTX* ctx = NULL;
  5635. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5636. EVP_ENCODE_CTX_free(ctx);
  5637. #endif /* OPENSSL_EXTRA && (WOLFSSL_BASE64_ENCODE || WOLFSSL_BASE64_DECODE) */
  5638. return EXPECT_RESULT();
  5639. }
  5640. static int test_wolfSSL_EVP_EncodeInit(void)
  5641. {
  5642. EXPECT_DECLS;
  5643. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5644. EVP_ENCODE_CTX* ctx = NULL;
  5645. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5646. ExpectIntEQ(ctx->remaining, 0);
  5647. ExpectIntEQ(ctx->data[0], 0);
  5648. ExpectIntEQ(ctx->data[sizeof(ctx->data) -1], 0);
  5649. if (ctx != NULL) {
  5650. /* make ctx dirty */
  5651. ctx->remaining = 10;
  5652. XMEMSET(ctx->data, 0x77, sizeof(ctx->data));
  5653. }
  5654. EVP_EncodeInit(ctx);
  5655. ExpectIntEQ(ctx->remaining, 0);
  5656. ExpectIntEQ(ctx->data[0], 0);
  5657. ExpectIntEQ(ctx->data[sizeof(ctx->data) -1], 0);
  5658. EVP_ENCODE_CTX_free(ctx);
  5659. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5660. return EXPECT_RESULT();
  5661. }
  5662. static int test_wolfSSL_EVP_EncodeUpdate(void)
  5663. {
  5664. EXPECT_DECLS;
  5665. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5666. int outl;
  5667. int total;
  5668. const unsigned char plain0[] = {"Th"};
  5669. const unsigned char plain1[] = {"This is a base64 encodeing test."};
  5670. const unsigned char plain2[] = {"This is additional data."};
  5671. const unsigned char encBlock0[] = {"VGg="};
  5672. const unsigned char enc0[] = {"VGg=\n"};
  5673. /* expected encoded result for the first output 64 chars plus trailing LF*/
  5674. const unsigned char enc1[] = {"VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVpbmcgdGVzdC5UaGlzIGlzIGFkZGl0aW9u\n"};
  5675. const unsigned char enc2[] =
  5676. {"VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVpbmcgdGVzdC5UaGlzIGlzIGFkZGl0aW9u\nYWwgZGF0YS4=\n"};
  5677. unsigned char encOutBuff[300];
  5678. EVP_ENCODE_CTX* ctx = NULL;
  5679. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5680. EVP_EncodeInit(ctx);
  5681. /* illegal parameter test */
  5682. ExpectIntEQ(
  5683. EVP_EncodeUpdate(
  5684. NULL, /* pass NULL as ctx */
  5685. encOutBuff,
  5686. &outl,
  5687. plain1,
  5688. sizeof(plain1)-1),
  5689. 0 /* expected result code 0: fail */
  5690. );
  5691. ExpectIntEQ(
  5692. EVP_EncodeUpdate(
  5693. ctx,
  5694. NULL, /* pass NULL as out buff */
  5695. &outl,
  5696. plain1,
  5697. sizeof(plain1)-1),
  5698. 0 /* expected result code 0: fail */
  5699. );
  5700. ExpectIntEQ(
  5701. EVP_EncodeUpdate(
  5702. ctx,
  5703. encOutBuff,
  5704. NULL, /* pass NULL as outl */
  5705. plain1,
  5706. sizeof(plain1)-1),
  5707. 0 /* expected result code 0: fail */
  5708. );
  5709. ExpectIntEQ(
  5710. EVP_EncodeUpdate(
  5711. ctx,
  5712. encOutBuff,
  5713. &outl,
  5714. NULL, /* pass NULL as in */
  5715. sizeof(plain1)-1),
  5716. 0 /* expected result code 0: fail */
  5717. );
  5718. ExpectIntEQ(EVP_EncodeBlock(NULL, NULL, 0), -1);
  5719. /* meaningless parameter test */
  5720. ExpectIntEQ(
  5721. EVP_EncodeUpdate(
  5722. ctx,
  5723. encOutBuff,
  5724. &outl,
  5725. plain1,
  5726. 0), /* pass zero input */
  5727. 1 /* expected result code 1: success */
  5728. );
  5729. /* very small data encoding test */
  5730. EVP_EncodeInit(ctx);
  5731. ExpectIntEQ(
  5732. EVP_EncodeUpdate(
  5733. ctx,
  5734. encOutBuff,
  5735. &outl,
  5736. plain0,
  5737. sizeof(plain0)-1),
  5738. 1 /* expected result code 1: success */
  5739. );
  5740. ExpectIntEQ(outl,0);
  5741. if (EXPECT_SUCCESS()) {
  5742. EVP_EncodeFinal(
  5743. ctx,
  5744. encOutBuff + outl,
  5745. &outl);
  5746. }
  5747. ExpectIntEQ( outl, sizeof(enc0)-1);
  5748. ExpectIntEQ(
  5749. XSTRNCMP(
  5750. (const char*)encOutBuff,
  5751. (const char*)enc0,sizeof(enc0) ),
  5752. 0);
  5753. XMEMSET( encOutBuff,0, sizeof(encOutBuff));
  5754. ExpectIntEQ(EVP_EncodeBlock(encOutBuff, plain0, sizeof(plain0)-1),
  5755. sizeof(encBlock0)-1);
  5756. ExpectStrEQ(encOutBuff, encBlock0);
  5757. /* pass small size( < 48bytes ) input, then make sure they are not
  5758. * encoded and just stored in ctx
  5759. */
  5760. EVP_EncodeInit(ctx);
  5761. total = 0;
  5762. outl = 0;
  5763. XMEMSET( encOutBuff,0, sizeof(encOutBuff));
  5764. ExpectIntEQ(
  5765. EVP_EncodeUpdate(
  5766. ctx,
  5767. encOutBuff, /* buffer for output */
  5768. &outl, /* size of output */
  5769. plain1, /* input */
  5770. sizeof(plain1)-1), /* size of input */
  5771. 1); /* expected result code 1:success */
  5772. total += outl;
  5773. ExpectIntEQ(outl, 0); /* no output expected */
  5774. ExpectIntEQ(ctx->remaining, sizeof(plain1) -1);
  5775. ExpectTrue(
  5776. XSTRNCMP((const char*)(ctx->data),
  5777. (const char*)plain1,
  5778. ctx->remaining) ==0 );
  5779. ExpectTrue(encOutBuff[0] == 0);
  5780. /* call wolfSSL_EVP_EncodeUpdate again to make it encode
  5781. * the stored data and the new input together
  5782. */
  5783. ExpectIntEQ(
  5784. EVP_EncodeUpdate(
  5785. ctx,
  5786. encOutBuff + outl, /* buffer for output */
  5787. &outl, /* size of output */
  5788. plain2, /* additional input */
  5789. sizeof(plain2) -1), /* size of additional input */
  5790. 1); /* expected result code 1:success */
  5791. total += outl;
  5792. ExpectIntNE(outl, 0); /* some output is expected this time*/
  5793. ExpectIntEQ(outl, BASE64_ENCODE_RESULT_BLOCK_SIZE +1); /* 64 bytes and LF */
  5794. ExpectIntEQ(
  5795. XSTRNCMP((const char*)encOutBuff,(const char*)enc1,sizeof(enc1) ),0);
  5796. /* call wolfSSL_EVP_EncodeFinal to flush all the unprocessed input */
  5797. EVP_EncodeFinal(
  5798. ctx,
  5799. encOutBuff + outl,
  5800. &outl);
  5801. total += outl;
  5802. ExpectIntNE(total,0);
  5803. ExpectIntNE(outl,0);
  5804. ExpectIntEQ(XSTRNCMP(
  5805. (const char*)encOutBuff,(const char*)enc2,sizeof(enc2) ),0);
  5806. /* test with illeagal parameters */
  5807. outl = 1;
  5808. EVP_EncodeFinal(NULL, encOutBuff + outl, &outl);
  5809. ExpectIntEQ(outl, 0);
  5810. outl = 1;
  5811. EVP_EncodeFinal(ctx, NULL, &outl);
  5812. ExpectIntEQ(outl, 0);
  5813. EVP_EncodeFinal(ctx, encOutBuff + outl, NULL);
  5814. EVP_EncodeFinal(NULL, NULL, NULL);
  5815. EVP_ENCODE_CTX_free(ctx);
  5816. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5817. return EXPECT_RESULT();
  5818. }
  5819. static int test_wolfSSL_EVP_EncodeFinal(void)
  5820. {
  5821. int res = TEST_SKIPPED;
  5822. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5823. /* tests for wolfSSL_EVP_EncodeFinal are included in
  5824. * test_wolfSSL_EVP_EncodeUpdate
  5825. */
  5826. res = TEST_SUCCESS;
  5827. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5828. return res;
  5829. }
  5830. static int test_wolfSSL_EVP_DecodeInit(void)
  5831. {
  5832. EXPECT_DECLS;
  5833. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  5834. EVP_ENCODE_CTX* ctx = NULL;
  5835. ExpectNotNull( ctx = EVP_ENCODE_CTX_new());
  5836. ExpectIntEQ( ctx->remaining,0);
  5837. ExpectIntEQ( ctx->data[0],0);
  5838. ExpectIntEQ( ctx->data[sizeof(ctx->data) -1],0);
  5839. if (ctx != NULL) {
  5840. /* make ctx dirty */
  5841. ctx->remaining = 10;
  5842. XMEMSET( ctx->data, 0x77, sizeof(ctx->data));
  5843. }
  5844. EVP_DecodeInit(ctx);
  5845. ExpectIntEQ( ctx->remaining,0);
  5846. ExpectIntEQ( ctx->data[0],0);
  5847. ExpectIntEQ( ctx->data[sizeof(ctx->data) -1],0);
  5848. EVP_ENCODE_CTX_free(ctx);
  5849. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  5850. return EXPECT_RESULT();
  5851. }
  5852. static int test_wolfSSL_EVP_DecodeUpdate(void)
  5853. {
  5854. EXPECT_DECLS;
  5855. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  5856. int outl;
  5857. unsigned char decOutBuff[300];
  5858. EVP_ENCODE_CTX* ctx = NULL;
  5859. static const unsigned char enc1[] =
  5860. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg==\n"};
  5861. /* const unsigned char plain1[] =
  5862. {"This is a base64 decoding test."} */
  5863. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5864. EVP_DecodeInit(ctx);
  5865. /* illegal parameter tests */
  5866. /* pass NULL as ctx */
  5867. ExpectIntEQ(
  5868. EVP_DecodeUpdate(
  5869. NULL, /* pass NULL as ctx */
  5870. decOutBuff,
  5871. &outl,
  5872. enc1,
  5873. sizeof(enc1)-1),
  5874. -1 /* expected result code -1: fail */
  5875. );
  5876. ExpectIntEQ( outl, 0);
  5877. /* pass NULL as output */
  5878. ExpectIntEQ(
  5879. EVP_DecodeUpdate(
  5880. ctx,
  5881. NULL, /* pass NULL as out buff */
  5882. &outl,
  5883. enc1,
  5884. sizeof(enc1)-1),
  5885. -1 /* expected result code -1: fail */
  5886. );
  5887. ExpectIntEQ( outl, 0);
  5888. /* pass NULL as outl */
  5889. ExpectIntEQ(
  5890. EVP_DecodeUpdate(
  5891. ctx,
  5892. decOutBuff,
  5893. NULL, /* pass NULL as outl */
  5894. enc1,
  5895. sizeof(enc1)-1),
  5896. -1 /* expected result code -1: fail */
  5897. );
  5898. /* pass NULL as input */
  5899. ExpectIntEQ(
  5900. EVP_DecodeUpdate(
  5901. ctx,
  5902. decOutBuff,
  5903. &outl,
  5904. NULL, /* pass NULL as in */
  5905. sizeof(enc1)-1),
  5906. -1 /* expected result code -1: fail */
  5907. );
  5908. ExpectIntEQ( outl, 0);
  5909. ExpectIntEQ(EVP_DecodeBlock(NULL, NULL, 0), -1);
  5910. /* pass zero length input */
  5911. ExpectIntEQ(
  5912. EVP_DecodeUpdate(
  5913. ctx,
  5914. decOutBuff,
  5915. &outl,
  5916. enc1,
  5917. 0), /* pass zero as input len */
  5918. 1 /* expected result code 1: success */
  5919. );
  5920. /* decode correct base64 string */
  5921. {
  5922. static const unsigned char enc2[] =
  5923. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg==\n"};
  5924. static const unsigned char plain2[] =
  5925. {"This is a base64 decoding test."};
  5926. EVP_EncodeInit(ctx);
  5927. ExpectIntEQ(
  5928. EVP_DecodeUpdate(
  5929. ctx,
  5930. decOutBuff,
  5931. &outl,
  5932. enc2,
  5933. sizeof(enc2)-1),
  5934. 0 /* expected result code 0: success */
  5935. );
  5936. ExpectIntEQ(outl,sizeof(plain2) -1);
  5937. ExpectIntEQ(
  5938. EVP_DecodeFinal(
  5939. ctx,
  5940. decOutBuff + outl,
  5941. &outl),
  5942. 1 /* expected result code 1: success */
  5943. );
  5944. ExpectIntEQ(outl, 0); /* expected DecodeFinal output no data */
  5945. ExpectIntEQ(XSTRNCMP( (const char*)plain2,(const char*)decOutBuff,
  5946. sizeof(plain2) -1 ),0);
  5947. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc2, sizeof(enc2)),
  5948. sizeof(plain2)-1);
  5949. ExpectIntEQ(XSTRNCMP( (const char*)plain2,(const char*)decOutBuff,
  5950. sizeof(plain2) -1 ),0);
  5951. }
  5952. /* decode correct base64 string which does not have '\n' in its last*/
  5953. {
  5954. static const unsigned char enc3[] =
  5955. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg=="}; /* 44 chars */
  5956. static const unsigned char plain3[] =
  5957. {"This is a base64 decoding test."}; /* 31 chars */
  5958. EVP_EncodeInit(ctx);
  5959. ExpectIntEQ(
  5960. EVP_DecodeUpdate(
  5961. ctx,
  5962. decOutBuff,
  5963. &outl,
  5964. enc3,
  5965. sizeof(enc3)-1),
  5966. 0 /* expected result code 0: success */
  5967. );
  5968. ExpectIntEQ(outl,sizeof(plain3)-1); /* 31 chars should be output */
  5969. ExpectIntEQ(XSTRNCMP( (const char*)plain3,(const char*)decOutBuff,
  5970. sizeof(plain3) -1 ),0);
  5971. ExpectIntEQ(
  5972. EVP_DecodeFinal(
  5973. ctx,
  5974. decOutBuff + outl,
  5975. &outl),
  5976. 1 /* expected result code 1: success */
  5977. );
  5978. ExpectIntEQ(outl,0 );
  5979. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc3, sizeof(enc3)-1),
  5980. sizeof(plain3)-1);
  5981. ExpectIntEQ(XSTRNCMP( (const char*)plain3,(const char*)decOutBuff,
  5982. sizeof(plain3) -1 ),0);
  5983. }
  5984. /* decode string which has a padding char ('=') in the illegal position*/
  5985. {
  5986. static const unsigned char enc4[] =
  5987. {"VGhpcyBpcyBhIGJhc2U2N=CBkZWNvZGluZyB0ZXN0Lg==\n"};
  5988. EVP_EncodeInit(ctx);
  5989. ExpectIntEQ(
  5990. EVP_DecodeUpdate(
  5991. ctx,
  5992. decOutBuff,
  5993. &outl,
  5994. enc4,
  5995. sizeof(enc4)-1),
  5996. -1 /* expected result code -1: error */
  5997. );
  5998. ExpectIntEQ(outl,0);
  5999. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc4, sizeof(enc4)-1), -1);
  6000. }
  6001. /* small data decode test */
  6002. {
  6003. static const unsigned char enc00[] = {"VG"};
  6004. static const unsigned char enc01[] = {"g=\n"};
  6005. static const unsigned char plain4[] = {"Th"};
  6006. EVP_EncodeInit(ctx);
  6007. ExpectIntEQ(
  6008. EVP_DecodeUpdate(
  6009. ctx,
  6010. decOutBuff,
  6011. &outl,
  6012. enc00,
  6013. sizeof(enc00)-1),
  6014. 1 /* expected result code 1: success */
  6015. );
  6016. ExpectIntEQ(outl,0);
  6017. ExpectIntEQ(
  6018. EVP_DecodeUpdate(
  6019. ctx,
  6020. decOutBuff + outl,
  6021. &outl,
  6022. enc01,
  6023. sizeof(enc01)-1),
  6024. 0 /* expected result code 0: success */
  6025. );
  6026. ExpectIntEQ(outl,sizeof(plain4)-1);
  6027. /* test with illegal parameters */
  6028. ExpectIntEQ(EVP_DecodeFinal(NULL,decOutBuff + outl,&outl), -1);
  6029. ExpectIntEQ(EVP_DecodeFinal(ctx,NULL,&outl), -1);
  6030. ExpectIntEQ(EVP_DecodeFinal(ctx,decOutBuff + outl, NULL), -1);
  6031. ExpectIntEQ(EVP_DecodeFinal(NULL,NULL, NULL), -1);
  6032. if (EXPECT_SUCCESS()) {
  6033. EVP_DecodeFinal(
  6034. ctx,
  6035. decOutBuff + outl,
  6036. &outl);
  6037. }
  6038. ExpectIntEQ( outl, 0);
  6039. ExpectIntEQ(
  6040. XSTRNCMP(
  6041. (const char*)decOutBuff,
  6042. (const char*)plain4,sizeof(plain4)-1 ),
  6043. 0);
  6044. }
  6045. EVP_ENCODE_CTX_free(ctx);
  6046. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  6047. return EXPECT_RESULT();
  6048. }
  6049. static int test_wolfSSL_EVP_DecodeFinal(void)
  6050. {
  6051. int res = TEST_SKIPPED;
  6052. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  6053. /* tests for wolfSSL_EVP_DecodeFinal are included in
  6054. * test_wolfSSL_EVP_DecodeUpdate
  6055. */
  6056. res = TEST_SUCCESS;
  6057. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  6058. return res;
  6059. }
  6060. /* Test function for wolfSSL_EVP_get_cipherbynid.
  6061. */
  6062. #ifdef OPENSSL_EXTRA
  6063. static int test_wolfSSL_EVP_get_cipherbynid(void)
  6064. {
  6065. EXPECT_DECLS;
  6066. #ifndef NO_AES
  6067. const WOLFSSL_EVP_CIPHER* c;
  6068. c = wolfSSL_EVP_get_cipherbynid(419);
  6069. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  6070. defined(WOLFSSL_AES_128)
  6071. ExpectNotNull(c);
  6072. ExpectNotNull(XSTRCMP("EVP_AES_128_CBC", c));
  6073. #else
  6074. ExpectNull(c);
  6075. #endif
  6076. c = wolfSSL_EVP_get_cipherbynid(423);
  6077. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  6078. defined(WOLFSSL_AES_192)
  6079. ExpectNotNull(c);
  6080. ExpectNotNull(XSTRCMP("EVP_AES_192_CBC", c));
  6081. #else
  6082. ExpectNull(c);
  6083. #endif
  6084. c = wolfSSL_EVP_get_cipherbynid(427);
  6085. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  6086. defined(WOLFSSL_AES_256)
  6087. ExpectNotNull(c);
  6088. ExpectNotNull(XSTRCMP("EVP_AES_256_CBC", c));
  6089. #else
  6090. ExpectNull(c);
  6091. #endif
  6092. c = wolfSSL_EVP_get_cipherbynid(904);
  6093. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_128)
  6094. ExpectNotNull(c);
  6095. ExpectNotNull(XSTRCMP("EVP_AES_128_CTR", c));
  6096. #else
  6097. ExpectNull(c);
  6098. #endif
  6099. c = wolfSSL_EVP_get_cipherbynid(905);
  6100. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_192)
  6101. ExpectNotNull(c);
  6102. ExpectNotNull(XSTRCMP("EVP_AES_192_CTR", c));
  6103. #else
  6104. ExpectNull(c);
  6105. #endif
  6106. c = wolfSSL_EVP_get_cipherbynid(906);
  6107. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_256)
  6108. ExpectNotNull(c);
  6109. ExpectNotNull(XSTRCMP("EVP_AES_256_CTR", c));
  6110. #else
  6111. ExpectNull(c);
  6112. #endif
  6113. c = wolfSSL_EVP_get_cipherbynid(418);
  6114. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_128)
  6115. ExpectNotNull(c);
  6116. ExpectNotNull(XSTRCMP("EVP_AES_128_ECB", c));
  6117. #else
  6118. ExpectNull(c);
  6119. #endif
  6120. c = wolfSSL_EVP_get_cipherbynid(422);
  6121. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_192)
  6122. ExpectNotNull(c);
  6123. ExpectNotNull(XSTRCMP("EVP_AES_192_ECB", c));
  6124. #else
  6125. ExpectNull(c);
  6126. #endif
  6127. c = wolfSSL_EVP_get_cipherbynid(426);
  6128. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  6129. ExpectNotNull(c);
  6130. ExpectNotNull(XSTRCMP("EVP_AES_256_ECB", c));
  6131. #else
  6132. ExpectNull(c);
  6133. #endif
  6134. #endif /* !NO_AES */
  6135. #ifndef NO_DES3
  6136. ExpectNotNull(XSTRCMP("EVP_DES_CBC", wolfSSL_EVP_get_cipherbynid(31)));
  6137. #ifdef WOLFSSL_DES_ECB
  6138. ExpectNotNull(XSTRCMP("EVP_DES_ECB", wolfSSL_EVP_get_cipherbynid(29)));
  6139. #endif
  6140. ExpectNotNull(XSTRCMP("EVP_DES_EDE3_CBC", wolfSSL_EVP_get_cipherbynid(44)));
  6141. #ifdef WOLFSSL_DES_ECB
  6142. ExpectNotNull(XSTRCMP("EVP_DES_EDE3_ECB", wolfSSL_EVP_get_cipherbynid(33)));
  6143. #endif
  6144. #endif /* !NO_DES3 */
  6145. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  6146. ExpectNotNull(XSTRCMP("EVP_CHACHA20_POLY13O5", EVP_get_cipherbynid(1018)));
  6147. #endif
  6148. /* test for nid is out of range */
  6149. ExpectNull(wolfSSL_EVP_get_cipherbynid(1));
  6150. return EXPECT_RESULT();
  6151. }
  6152. static int test_wolfSSL_EVP_CIPHER_CTX(void)
  6153. {
  6154. EXPECT_DECLS;
  6155. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  6156. EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
  6157. const EVP_CIPHER *init = EVP_aes_128_cbc();
  6158. const EVP_CIPHER *test;
  6159. byte key[AES_BLOCK_SIZE] = {0};
  6160. byte iv[AES_BLOCK_SIZE] = {0};
  6161. ExpectNotNull(ctx);
  6162. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  6163. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  6164. test = EVP_CIPHER_CTX_cipher(ctx);
  6165. ExpectTrue(init == test);
  6166. ExpectIntEQ(EVP_CIPHER_nid(test), NID_aes_128_cbc);
  6167. ExpectIntEQ(EVP_CIPHER_CTX_reset(ctx), WOLFSSL_SUCCESS);
  6168. ExpectIntEQ(EVP_CIPHER_CTX_reset(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  6169. EVP_CIPHER_CTX_free(ctx);
  6170. /* test EVP_CIPHER_CTX_cleanup with NULL */
  6171. ExpectIntEQ(EVP_CIPHER_CTX_cleanup(NULL), WOLFSSL_SUCCESS);
  6172. #endif /* !NO_AES && HAVE_AES_CBC && WOLFSSL_AES_128 */
  6173. return EXPECT_RESULT();
  6174. }
  6175. #endif /* OPENSSL_EXTRA */
  6176. /*----------------------------------------------------------------------------*
  6177. | IO
  6178. *----------------------------------------------------------------------------*/
  6179. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) || \
  6180. defined(HAVE_IO_TESTS_DEPENDENCIES)
  6181. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6182. #ifdef WC_SHA512_DIGEST_SIZE
  6183. #define MD_MAX_SIZE WC_SHA512_DIGEST_SIZE
  6184. #else
  6185. #define MD_MAX_SIZE WC_SHA256_DIGEST_SIZE
  6186. #endif
  6187. byte server_side_msg1[MD_MAX_SIZE] = {0};/* msg sent by server */
  6188. byte server_side_msg2[MD_MAX_SIZE] = {0};/* msg received from client */
  6189. byte client_side_msg1[MD_MAX_SIZE] = {0};/* msg sent by client */
  6190. byte client_side_msg2[MD_MAX_SIZE] = {0};/* msg received from server */
  6191. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6192. /* TODO: Expand and enable this when EVP_chacha20_poly1305 is supported */
  6193. #if defined(HAVE_SESSION_TICKET) && defined(OPENSSL_EXTRA) && \
  6194. defined(HAVE_AES_CBC)
  6195. typedef struct openssl_key_ctx {
  6196. byte name[WOLFSSL_TICKET_NAME_SZ]; /* server name */
  6197. byte key[WOLFSSL_TICKET_KEY_SZ]; /* cipher key */
  6198. byte hmacKey[WOLFSSL_TICKET_NAME_SZ]; /* hmac key */
  6199. byte iv[WOLFSSL_TICKET_IV_SZ]; /* cipher iv */
  6200. } openssl_key_ctx;
  6201. static THREAD_LS_T openssl_key_ctx myOpenSSLKey_ctx;
  6202. static THREAD_LS_T WC_RNG myOpenSSLKey_rng;
  6203. static WC_INLINE int OpenSSLTicketInit(void)
  6204. {
  6205. int ret = wc_InitRng(&myOpenSSLKey_rng);
  6206. if (ret != 0) return ret;
  6207. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.name,
  6208. sizeof(myOpenSSLKey_ctx.name));
  6209. if (ret != 0) return ret;
  6210. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.key,
  6211. sizeof(myOpenSSLKey_ctx.key));
  6212. if (ret != 0) return ret;
  6213. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.hmacKey,
  6214. sizeof(myOpenSSLKey_ctx.hmacKey));
  6215. if (ret != 0) return ret;
  6216. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.iv,
  6217. sizeof(myOpenSSLKey_ctx.iv));
  6218. if (ret != 0) return ret;
  6219. return 0;
  6220. }
  6221. static int myTicketEncCbOpenSSL(WOLFSSL* ssl,
  6222. byte name[WOLFSSL_TICKET_NAME_SZ],
  6223. byte iv[WOLFSSL_TICKET_IV_SZ],
  6224. WOLFSSL_EVP_CIPHER_CTX *ectx,
  6225. WOLFSSL_HMAC_CTX *hctx, int enc) {
  6226. (void)ssl;
  6227. if (enc) {
  6228. XMEMCPY(name, myOpenSSLKey_ctx.name, sizeof(myOpenSSLKey_ctx.name));
  6229. XMEMCPY(iv, myOpenSSLKey_ctx.iv, sizeof(myOpenSSLKey_ctx.iv));
  6230. }
  6231. else if (XMEMCMP(name, myOpenSSLKey_ctx.name,
  6232. sizeof(myOpenSSLKey_ctx.name)) != 0 ||
  6233. XMEMCMP(iv, myOpenSSLKey_ctx.iv,
  6234. sizeof(myOpenSSLKey_ctx.iv)) != 0) {
  6235. return 0;
  6236. }
  6237. HMAC_Init_ex(hctx, myOpenSSLKey_ctx.hmacKey, WOLFSSL_TICKET_NAME_SZ, EVP_sha256(), NULL);
  6238. if (enc)
  6239. EVP_EncryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, myOpenSSLKey_ctx.key, iv);
  6240. else
  6241. EVP_DecryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, myOpenSSLKey_ctx.key, iv);
  6242. return 1;
  6243. }
  6244. static WC_INLINE void OpenSSLTicketCleanup(void)
  6245. {
  6246. wc_FreeRng(&myOpenSSLKey_rng);
  6247. }
  6248. #endif
  6249. #endif
  6250. /* helper functions */
  6251. #ifdef HAVE_SSL_MEMIO_TESTS_DEPENDENCIES
  6252. static WC_INLINE int test_ssl_memio_write_cb(WOLFSSL *ssl, char *data, int sz,
  6253. void *ctx)
  6254. {
  6255. struct test_ssl_memio_ctx *test_ctx;
  6256. byte *buf;
  6257. int *len;
  6258. test_ctx = (struct test_ssl_memio_ctx*)ctx;
  6259. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  6260. buf = test_ctx->c_buff;
  6261. len = &test_ctx->c_len;
  6262. }
  6263. else {
  6264. buf = test_ctx->s_buff;
  6265. len = &test_ctx->s_len;
  6266. }
  6267. if ((unsigned)(*len + sz) > TEST_SSL_MEMIO_BUF_SZ)
  6268. return WOLFSSL_CBIO_ERR_WANT_WRITE;
  6269. XMEMCPY(buf + *len, data, sz);
  6270. *len += sz;
  6271. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  6272. {
  6273. /* This can be imported into Wireshark by transforming the file with
  6274. * od -Ax -tx1 -v test_output.dump > test_output.dump.hex
  6275. * And then loading test_output.dump.hex into Wireshark using the
  6276. * "Import from Hex Dump..." option ion and selecting the TCP
  6277. * encapsulation option. */
  6278. char dump_file_name[64];
  6279. WOLFSSL_BIO *dump_file;
  6280. sprintf(dump_file_name, "%s/%s.dump", tmpDirName, currentTestName);
  6281. dump_file = wolfSSL_BIO_new_file(dump_file_name, "a");
  6282. if (dump_file != NULL) {
  6283. (void)wolfSSL_BIO_write(dump_file, data, sz);
  6284. wolfSSL_BIO_free(dump_file);
  6285. }
  6286. }
  6287. #endif
  6288. return sz;
  6289. }
  6290. static WC_INLINE int test_ssl_memio_read_cb(WOLFSSL *ssl, char *data, int sz,
  6291. void *ctx)
  6292. {
  6293. struct test_ssl_memio_ctx *test_ctx;
  6294. int read_sz;
  6295. byte *buf;
  6296. int *len;
  6297. test_ctx = (struct test_ssl_memio_ctx*)ctx;
  6298. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  6299. buf = test_ctx->s_buff;
  6300. len = &test_ctx->s_len;
  6301. }
  6302. else {
  6303. buf = test_ctx->c_buff;
  6304. len = &test_ctx->c_len;
  6305. }
  6306. if (*len == 0)
  6307. return WOLFSSL_CBIO_ERR_WANT_READ;
  6308. read_sz = sz < *len ? sz : *len;
  6309. XMEMCPY(data, buf, read_sz);
  6310. XMEMMOVE(buf, buf + read_sz, *len - read_sz);
  6311. *len -= read_sz;
  6312. return read_sz;
  6313. }
  6314. static WC_INLINE int test_ssl_memio_setup(test_ssl_memio_ctx *ctx)
  6315. {
  6316. EXPECT_DECLS_NO_MSGS(-2000);
  6317. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6318. int c_sharedCtx = 0;
  6319. int s_sharedCtx = 0;
  6320. #endif
  6321. const char* clientCertFile = cliCertFile;
  6322. const char* clientKeyFile = cliKeyFile;
  6323. const char* serverCertFile = svrCertFile;
  6324. const char* serverKeyFile = svrKeyFile;
  6325. /********************************
  6326. * Create WOLFSSL_CTX for client.
  6327. ********************************/
  6328. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6329. if (ctx->c_ctx != NULL) {
  6330. c_sharedCtx = ctx->c_cb.isSharedCtx;
  6331. }
  6332. else
  6333. #endif
  6334. {
  6335. WOLFSSL_METHOD* method = NULL;
  6336. if (ctx->c_cb.method != NULL) {
  6337. method = ctx->c_cb.method();
  6338. }
  6339. else {
  6340. method = wolfSSLv23_client_method();
  6341. }
  6342. ExpectNotNull(ctx->c_ctx = wolfSSL_CTX_new(method));
  6343. }
  6344. wolfSSL_SetIORecv(ctx->c_ctx, test_ssl_memio_read_cb);
  6345. wolfSSL_SetIOSend(ctx->c_ctx, test_ssl_memio_write_cb);
  6346. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6347. wolfSSL_CTX_set_default_passwd_cb(ctx->c_ctx, PasswordCallBack);
  6348. #endif
  6349. if (ctx->c_cb.caPemFile != NULL)
  6350. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->c_ctx,
  6351. ctx->c_cb.caPemFile, 0), WOLFSSL_SUCCESS);
  6352. else
  6353. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->c_ctx,
  6354. caCertFile, 0), WOLFSSL_SUCCESS);
  6355. if (ctx->c_cb.certPemFile != NULL) {
  6356. clientCertFile = ctx->c_cb.certPemFile;
  6357. }
  6358. if (ctx->c_cb.keyPemFile != NULL) {
  6359. clientKeyFile = ctx->c_cb.keyPemFile;
  6360. }
  6361. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6362. if (!c_sharedCtx)
  6363. #endif
  6364. {
  6365. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx->c_ctx,
  6366. clientCertFile), WOLFSSL_SUCCESS);
  6367. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx->c_ctx, clientKeyFile,
  6368. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6369. }
  6370. #ifdef HAVE_CRL
  6371. if (ctx->c_cb.crlPemFile != NULL) {
  6372. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx->c_ctx, WOLFSSL_CRL_CHECKALL),
  6373. WOLFSSL_SUCCESS);
  6374. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx->c_ctx, ctx->c_cb.crlPemFile,
  6375. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6376. }
  6377. #endif
  6378. if (ctx->c_ciphers != NULL) {
  6379. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx->c_ctx, ctx->c_ciphers),
  6380. WOLFSSL_SUCCESS);
  6381. }
  6382. if (ctx->c_cb.ctx_ready != NULL) {
  6383. ExpectIntEQ(ctx->c_cb.ctx_ready(ctx->c_ctx), TEST_SUCCESS);
  6384. }
  6385. /********************************
  6386. * Create WOLFSSL_CTX for server.
  6387. ********************************/
  6388. if (ctx->s_ctx != NULL) {
  6389. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6390. s_sharedCtx = 1;
  6391. #endif
  6392. ctx->s_cb.isSharedCtx = 1;
  6393. }
  6394. else
  6395. {
  6396. WOLFSSL_METHOD* method = NULL;
  6397. if (ctx->s_cb.method != NULL) {
  6398. method = ctx->s_cb.method();
  6399. }
  6400. else {
  6401. method = wolfSSLv23_server_method();
  6402. }
  6403. ExpectNotNull(ctx->s_ctx = wolfSSL_CTX_new(method));
  6404. ctx->s_cb.isSharedCtx = 0;
  6405. }
  6406. if (!ctx->s_cb.ticNoInit && (ctx->s_ctx != NULL)) {
  6407. #if defined(HAVE_SESSION_TICKET) && \
  6408. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6409. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6410. OpenSSLTicketInit();
  6411. wolfSSL_CTX_set_tlsext_ticket_key_cb(ctx->s_ctx, myTicketEncCbOpenSSL);
  6412. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6413. TicketInit();
  6414. wolfSSL_CTX_set_TicketEncCb(ctx->s_ctx, myTicketEncCb);
  6415. #endif
  6416. #endif
  6417. }
  6418. wolfSSL_SetIORecv(ctx->s_ctx, test_ssl_memio_read_cb);
  6419. wolfSSL_SetIOSend(ctx->s_ctx, test_ssl_memio_write_cb);
  6420. wolfSSL_CTX_set_verify(ctx->s_ctx, WOLFSSL_VERIFY_PEER |
  6421. WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  6422. if (ctx->s_cb.caPemFile != NULL)
  6423. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->s_ctx,
  6424. ctx->s_cb.caPemFile, 0), WOLFSSL_SUCCESS);
  6425. else
  6426. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->s_ctx,
  6427. cliCertFile, 0), WOLFSSL_SUCCESS);
  6428. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6429. wolfSSL_CTX_set_default_passwd_cb(ctx->s_ctx, PasswordCallBack);
  6430. #endif
  6431. if (ctx->s_cb.certPemFile != NULL) {
  6432. serverCertFile = ctx->s_cb.certPemFile;
  6433. }
  6434. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6435. if (!s_sharedCtx)
  6436. #endif
  6437. {
  6438. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx->s_ctx,
  6439. serverCertFile), WOLFSSL_SUCCESS);
  6440. }
  6441. if (ctx->s_cb.keyPemFile != NULL) {
  6442. serverKeyFile = ctx->s_cb.keyPemFile;
  6443. }
  6444. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6445. if (!s_sharedCtx)
  6446. #endif
  6447. {
  6448. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx->s_ctx, serverKeyFile,
  6449. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6450. }
  6451. if (ctx->s_ciphers != NULL) {
  6452. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx->s_ctx, ctx->s_ciphers),
  6453. WOLFSSL_SUCCESS);
  6454. }
  6455. if (ctx->s_cb.ctx_ready != NULL) {
  6456. ExpectIntEQ(ctx->s_cb.ctx_ready(ctx->s_ctx), TEST_SUCCESS);
  6457. }
  6458. /****************************
  6459. * Create WOLFSSL for client.
  6460. ****************************/
  6461. ExpectNotNull(ctx->c_ssl = wolfSSL_new(ctx->c_ctx));
  6462. wolfSSL_SetIOWriteCtx(ctx->c_ssl, ctx);
  6463. wolfSSL_SetIOReadCtx(ctx->c_ssl, ctx);
  6464. if (0
  6465. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6466. || c_sharedCtx
  6467. #endif
  6468. )
  6469. {
  6470. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ctx->c_ssl,
  6471. clientCertFile), WOLFSSL_SUCCESS);
  6472. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ctx->c_ssl, clientKeyFile,
  6473. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6474. }
  6475. if (ctx->c_cb.ssl_ready != NULL) {
  6476. ExpectIntEQ(ctx->c_cb.ssl_ready(ctx->c_ssl), TEST_SUCCESS);
  6477. }
  6478. /****************************
  6479. * Create WOLFSSL for server.
  6480. ****************************/
  6481. ExpectNotNull(ctx->s_ssl = wolfSSL_new(ctx->s_ctx));
  6482. wolfSSL_SetIOWriteCtx(ctx->s_ssl, ctx);
  6483. wolfSSL_SetIOReadCtx(ctx->s_ssl, ctx);
  6484. if (0
  6485. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6486. || s_sharedCtx
  6487. #endif
  6488. )
  6489. {
  6490. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ctx->s_ssl,
  6491. serverCertFile), WOLFSSL_SUCCESS);
  6492. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ctx->s_ssl, serverKeyFile,
  6493. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6494. }
  6495. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  6496. wolfSSL_SetTmpDH_file(ctx->s_ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  6497. #elif !defined(NO_DH)
  6498. /* will repick suites with DHE, higher priority than PSK */
  6499. SetDH(ctx->s_ssl);
  6500. #endif
  6501. if (ctx->s_cb.ssl_ready != NULL) {
  6502. ExpectIntEQ(ctx->s_cb.ssl_ready(ctx->s_ssl), TEST_SUCCESS);
  6503. }
  6504. return EXPECT_RESULT();
  6505. }
  6506. static int test_ssl_memio_do_handshake(test_ssl_memio_ctx* ctx, int max_rounds,
  6507. int* rounds)
  6508. {
  6509. int handshake_complete = 0;
  6510. int hs_c = 0;
  6511. int hs_s = 0;
  6512. int failing_s = 0;
  6513. int failing_c = 0;
  6514. int ret;
  6515. int err;
  6516. if (rounds != NULL) {
  6517. *rounds = 0;
  6518. }
  6519. while ((!handshake_complete) && (max_rounds > 0)) {
  6520. if (!hs_c) {
  6521. wolfSSL_SetLoggingPrefix("client");
  6522. ret = wolfSSL_connect(ctx->c_ssl);
  6523. wolfSSL_SetLoggingPrefix(NULL);
  6524. if (ret == WOLFSSL_SUCCESS) {
  6525. hs_c = 1;
  6526. }
  6527. else {
  6528. err = wolfSSL_get_error(ctx->c_ssl, ret);
  6529. if (err != WOLFSSL_ERROR_WANT_READ &&
  6530. err != WOLFSSL_ERROR_WANT_WRITE) {
  6531. char buff[WOLFSSL_MAX_ERROR_SZ];
  6532. fprintf(stderr, "error = %d, %s\n", err,
  6533. wolfSSL_ERR_error_string((word32)err, buff));
  6534. failing_c = 1;
  6535. hs_c = 1;
  6536. if (failing_c && failing_s) {
  6537. break;
  6538. }
  6539. }
  6540. }
  6541. }
  6542. if (!hs_s) {
  6543. wolfSSL_SetLoggingPrefix("server");
  6544. ret = wolfSSL_accept(ctx->s_ssl);
  6545. wolfSSL_SetLoggingPrefix(NULL);
  6546. if (ret == WOLFSSL_SUCCESS) {
  6547. hs_s = 1;
  6548. }
  6549. else {
  6550. err = wolfSSL_get_error(ctx->s_ssl, ret);
  6551. if (err != WOLFSSL_ERROR_WANT_READ &&
  6552. err != WOLFSSL_ERROR_WANT_WRITE) {
  6553. char buff[WOLFSSL_MAX_ERROR_SZ];
  6554. fprintf(stderr, "error = %d, %s\n", err,
  6555. wolfSSL_ERR_error_string((word32)err, buff));
  6556. failing_s = 1;
  6557. hs_s = 1;
  6558. if (failing_c && failing_s) {
  6559. break;
  6560. }
  6561. }
  6562. }
  6563. }
  6564. handshake_complete = hs_c && hs_s;
  6565. max_rounds--;
  6566. if (rounds != NULL) {
  6567. *rounds += 1;
  6568. }
  6569. }
  6570. if (!handshake_complete || failing_c || failing_s) {
  6571. return TEST_FAIL;
  6572. }
  6573. return TEST_SUCCESS;
  6574. }
  6575. static int test_ssl_memio_read_write(test_ssl_memio_ctx* ctx)
  6576. {
  6577. EXPECT_DECLS_NO_MSGS(-3000);
  6578. char input[1024];
  6579. int idx = 0;
  6580. const char* msg_c = "hello wolfssl!";
  6581. int msglen_c = (int)XSTRLEN(msg_c);
  6582. const char* msg_s = "I hear you fa shizzle!";
  6583. int msglen_s = (int)XSTRLEN(msg_s);
  6584. if (ctx->c_msg != NULL) {
  6585. msg_c = ctx->c_msg;
  6586. msglen_c = ctx->c_msglen;
  6587. }
  6588. if (ctx->s_msg != NULL) {
  6589. msg_s = ctx->s_msg;
  6590. msglen_s = ctx->s_msglen;
  6591. }
  6592. wolfSSL_SetLoggingPrefix("client");
  6593. ExpectIntEQ(wolfSSL_write(ctx->c_ssl, msg_c, msglen_c), msglen_c);
  6594. wolfSSL_SetLoggingPrefix("server");
  6595. ExpectIntGT(idx = wolfSSL_read(ctx->s_ssl, input, sizeof(input) - 1), 0);
  6596. if (idx >= 0) {
  6597. input[idx] = '\0';
  6598. }
  6599. ExpectIntGT(fprintf(stderr, "Client message: %s\n", input), 0);
  6600. ExpectIntEQ(wolfSSL_write(ctx->s_ssl, msg_s, msglen_s), msglen_s);
  6601. ctx->s_cb.return_code = EXPECT_RESULT();
  6602. wolfSSL_SetLoggingPrefix("client");
  6603. ExpectIntGT(idx = wolfSSL_read(ctx->c_ssl, input, sizeof(input) - 1), 0);
  6604. wolfSSL_SetLoggingPrefix(NULL);
  6605. if (idx >= 0) {
  6606. input[idx] = '\0';
  6607. }
  6608. ExpectIntGT(fprintf(stderr, "Server response: %s\n", input), 0);
  6609. ctx->c_cb.return_code = EXPECT_RESULT();
  6610. if (ctx->c_cb.on_result != NULL) {
  6611. ExpectIntEQ(ctx->c_cb.on_result(ctx->c_ssl), TEST_SUCCESS);
  6612. }
  6613. if (ctx->s_cb.on_result != NULL) {
  6614. ExpectIntEQ(ctx->s_cb.on_result(ctx->s_ssl), TEST_SUCCESS);
  6615. }
  6616. return EXPECT_RESULT();
  6617. }
  6618. static void test_ssl_memio_cleanup(test_ssl_memio_ctx* ctx)
  6619. {
  6620. ctx->c_cb.last_err = wolfSSL_get_error(ctx->c_ssl, 0);
  6621. ctx->s_cb.last_err = wolfSSL_get_error(ctx->s_ssl, 0);
  6622. if (ctx->c_cb.on_cleanup != NULL) {
  6623. ctx->c_cb.on_cleanup(ctx->c_ssl);
  6624. }
  6625. if (ctx->s_cb.on_cleanup != NULL) {
  6626. ctx->s_cb.on_cleanup(ctx->s_ssl);
  6627. }
  6628. wolfSSL_shutdown(ctx->s_ssl);
  6629. wolfSSL_shutdown(ctx->c_ssl);
  6630. wolfSSL_free(ctx->s_ssl);
  6631. wolfSSL_free(ctx->c_ssl);
  6632. if (ctx->c_cb.on_ctx_cleanup != NULL) {
  6633. ctx->c_cb.on_ctx_cleanup(ctx->c_ctx);
  6634. }
  6635. if (!ctx->c_cb.isSharedCtx) {
  6636. wolfSSL_CTX_free(ctx->c_ctx);
  6637. ctx->c_ctx = NULL;
  6638. }
  6639. if (ctx->s_cb.on_ctx_cleanup != NULL) {
  6640. ctx->s_cb.on_ctx_cleanup(ctx->s_ctx);
  6641. }
  6642. if (!ctx->s_cb.isSharedCtx) {
  6643. wolfSSL_CTX_free(ctx->s_ctx);
  6644. ctx->s_ctx = NULL;
  6645. }
  6646. if (!ctx->s_cb.ticNoInit) {
  6647. #if defined(HAVE_SESSION_TICKET) && \
  6648. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6649. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6650. OpenSSLTicketCleanup();
  6651. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6652. TicketCleanup();
  6653. #endif
  6654. #endif
  6655. }
  6656. }
  6657. int test_wolfSSL_client_server_nofail_memio(test_ssl_cbf* client_cb,
  6658. test_ssl_cbf* server_cb, cbType client_on_handshake)
  6659. {
  6660. /* We use EXPECT_DECLS_NO_MSGS() here because this helper routine is used
  6661. * for numerous but varied expected-to-fail scenarios that should not emit
  6662. * error messages on the expected failures. Instead, we return a distinct
  6663. * code for each failure point, allowing the caller to assert on a
  6664. * particular mode of expected failure. On success, the usual TEST_SUCCESS
  6665. * is returned.
  6666. */
  6667. EXPECT_DECLS_NO_MSGS(-1000);
  6668. struct test_ssl_memio_ctx test_ctx;
  6669. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6670. size_t msg_len;
  6671. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6672. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  6673. XMEMCPY(&test_ctx.c_cb, client_cb, sizeof(test_ssl_cbf));
  6674. XMEMCPY(&test_ctx.s_cb, server_cb, sizeof(test_ssl_cbf));
  6675. test_ctx.c_ctx = client_cb->ctx;
  6676. test_ctx.s_ctx = server_cb->ctx;
  6677. test_ctx.c_cb.return_code = EXPECT_FAILURE_CODEPOINT_ID;
  6678. test_ctx.s_cb.return_code = EXPECT_FAILURE_CODEPOINT_ID;
  6679. ExpectIntEQ(test_ssl_memio_setup(&test_ctx), TEST_SUCCESS);
  6680. ExpectIntEQ(test_ssl_memio_do_handshake(&test_ctx, 10, NULL), TEST_SUCCESS);
  6681. if (client_on_handshake != NULL) {
  6682. ExpectIntEQ(client_on_handshake(test_ctx.c_ctx, test_ctx.c_ssl),
  6683. TEST_SUCCESS);
  6684. }
  6685. if (client_cb->on_handshake != NULL) {
  6686. ExpectIntEQ(client_cb->on_handshake(&test_ctx.c_ctx, &test_ctx.c_ssl),
  6687. TEST_SUCCESS);
  6688. }
  6689. if (server_cb->on_handshake != NULL) {
  6690. ExpectIntEQ(server_cb->on_handshake(&test_ctx.s_ctx, &test_ctx.s_ssl),
  6691. TEST_SUCCESS);
  6692. }
  6693. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6694. XMEMSET(server_side_msg2, 0, MD_MAX_SIZE);
  6695. msg_len = wolfSSL_get_peer_finished(test_ctx.s_ssl, server_side_msg2,
  6696. MD_MAX_SIZE);
  6697. ExpectIntGE(msg_len, 0);
  6698. XMEMSET(server_side_msg1, 0, MD_MAX_SIZE);
  6699. msg_len = wolfSSL_get_finished(test_ctx.s_ssl, server_side_msg1,
  6700. MD_MAX_SIZE);
  6701. ExpectIntGE(msg_len, 0);
  6702. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6703. ExpectIntEQ(test_ssl_memio_read_write(&test_ctx), TEST_SUCCESS);
  6704. test_ssl_memio_cleanup(&test_ctx);
  6705. client_cb->return_code = test_ctx.c_cb.return_code;
  6706. client_cb->last_err = test_ctx.c_cb.last_err;
  6707. server_cb->return_code = test_ctx.s_cb.return_code;
  6708. server_cb->last_err = test_ctx.s_cb.last_err;
  6709. return EXPECT_RESULT();
  6710. }
  6711. #endif
  6712. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  6713. #ifdef WOLFSSL_SESSION_EXPORT
  6714. #ifdef WOLFSSL_DTLS
  6715. /* set up function for sending session information */
  6716. static int test_export(WOLFSSL* inSsl, byte* buf, word32 sz, void* userCtx)
  6717. {
  6718. WOLFSSL_CTX* ctx = NULL;
  6719. WOLFSSL* ssl = NULL;
  6720. AssertNotNull(inSsl);
  6721. AssertNotNull(buf);
  6722. AssertIntNE(0, sz);
  6723. /* Set ctx to DTLS 1.2 */
  6724. ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method());
  6725. AssertNotNull(ctx);
  6726. ssl = wolfSSL_new(ctx);
  6727. AssertNotNull(ssl);
  6728. AssertIntGE(wolfSSL_dtls_import(ssl, buf, sz), 0);
  6729. wolfSSL_free(ssl);
  6730. wolfSSL_CTX_free(ctx);
  6731. (void)userCtx;
  6732. return 0;
  6733. }
  6734. #endif
  6735. /* returns negative value on fail and positive (including 0) on success */
  6736. static int nonblocking_accept_read(void* args, WOLFSSL* ssl, SOCKET_T* sockfd)
  6737. {
  6738. int ret, err, loop_count, count, timeout = 10;
  6739. char msg[] = "I hear you fa shizzle!";
  6740. char input[1024];
  6741. loop_count = ((func_args*)args)->argc;
  6742. #ifdef WOLFSSL_ASYNC_CRYPT
  6743. err = 0; /* Reset error */
  6744. #endif
  6745. do {
  6746. #ifdef WOLFSSL_ASYNC_CRYPT
  6747. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  6748. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  6749. if (ret < 0) { break; } else if (ret == 0) { continue; }
  6750. }
  6751. #endif
  6752. ret = wolfSSL_accept(ssl);
  6753. err = wolfSSL_get_error(ssl, 0);
  6754. if (err == WOLFSSL_ERROR_WANT_READ ||
  6755. err == WOLFSSL_ERROR_WANT_WRITE) {
  6756. int select_ret;
  6757. err = WC_PENDING_E;
  6758. select_ret = tcp_select(*sockfd, timeout);
  6759. if (select_ret == TEST_TIMEOUT) {
  6760. return WOLFSSL_FATAL_ERROR;
  6761. }
  6762. }
  6763. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  6764. if (ret != WOLFSSL_SUCCESS) {
  6765. char buff[WOLFSSL_MAX_ERROR_SZ];
  6766. fprintf(stderr, "error = %d, %s\n", err,
  6767. wolfSSL_ERR_error_string(err, buff));
  6768. return ret;
  6769. }
  6770. for (count = 0; count < loop_count; count++) {
  6771. int select_ret;
  6772. select_ret = tcp_select(*sockfd, timeout);
  6773. if (select_ret == TEST_TIMEOUT) {
  6774. ret = WOLFSSL_FATAL_ERROR;
  6775. break;
  6776. }
  6777. do {
  6778. ret = wolfSSL_read(ssl, input, sizeof(input)-1);
  6779. if (ret > 0) {
  6780. input[ret] = '\0';
  6781. fprintf(stderr, "Client message: %s\n", input);
  6782. }
  6783. } while (err == WOLFSSL_ERROR_WANT_READ && ret != WOLFSSL_SUCCESS);
  6784. do {
  6785. if ((ret = wolfSSL_write(ssl, msg, sizeof(msg))) != sizeof(msg)) {
  6786. return WOLFSSL_FATAL_ERROR;
  6787. }
  6788. err = wolfSSL_get_error(ssl, ret);
  6789. } while (err == WOLFSSL_ERROR_WANT_READ && ret != WOLFSSL_SUCCESS);
  6790. }
  6791. return ret;
  6792. }
  6793. #endif /* WOLFSSL_SESSION_EXPORT */
  6794. static THREAD_RETURN WOLFSSL_THREAD test_server_nofail(void* args)
  6795. {
  6796. SOCKET_T sockfd = 0;
  6797. SOCKET_T clientfd = 0;
  6798. word16 port;
  6799. callback_functions* cbf;
  6800. WOLFSSL_CTX* ctx = NULL;
  6801. WOLFSSL* ssl = NULL;
  6802. func_args* opts = (func_args*)args;
  6803. char msg[] = "I hear you fa shizzle!";
  6804. char input[1024];
  6805. int idx;
  6806. int ret, err = 0;
  6807. int sharedCtx = 0;
  6808. int doUdp = 0;
  6809. SOCKADDR_IN_T cliAddr;
  6810. socklen_t cliLen;
  6811. const char* certFile = svrCertFile;
  6812. const char* keyFile = svrKeyFile;
  6813. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6814. size_t msg_len = 0;
  6815. #endif
  6816. wolfSSL_SetLoggingPrefix("server");
  6817. #ifdef WOLFSSL_TIRTOS
  6818. fdOpenSession(Task_self());
  6819. #endif
  6820. opts->return_code = TEST_FAIL;
  6821. cbf = opts->callbacks;
  6822. if (cbf != NULL && cbf->ctx) {
  6823. ctx = cbf->ctx;
  6824. sharedCtx = 1;
  6825. }
  6826. else
  6827. {
  6828. WOLFSSL_METHOD* method = NULL;
  6829. if (cbf != NULL && cbf->method != NULL) {
  6830. method = cbf->method();
  6831. }
  6832. else {
  6833. method = wolfSSLv23_server_method();
  6834. }
  6835. ctx = wolfSSL_CTX_new(method);
  6836. }
  6837. if (ctx == NULL) {
  6838. /* Release the wait for TCP ready. */
  6839. signal_ready(opts->signal);
  6840. goto done;
  6841. }
  6842. if (cbf == NULL || !cbf->ticNoInit) {
  6843. #if defined(HAVE_SESSION_TICKET) && \
  6844. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6845. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6846. OpenSSLTicketInit();
  6847. wolfSSL_CTX_set_tlsext_ticket_key_cb(ctx, myTicketEncCbOpenSSL);
  6848. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6849. TicketInit();
  6850. wolfSSL_CTX_set_TicketEncCb(ctx, myTicketEncCb);
  6851. #endif
  6852. #endif
  6853. }
  6854. #if defined(USE_WINDOWS_API)
  6855. port = opts->signal->port;
  6856. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  6857. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  6858. /* Let tcp_listen assign port */
  6859. port = 0;
  6860. #else
  6861. /* Use default port */
  6862. port = wolfSSLPort;
  6863. #endif
  6864. if (cbf != NULL)
  6865. doUdp = cbf->doUdp;
  6866. /* do it here to detect failure */
  6867. tcp_accept(
  6868. &sockfd, &clientfd, opts, port, 0, doUdp, 0, 0, 1, 0, 0);
  6869. if (doUdp) {
  6870. cliLen = sizeof(cliAddr);
  6871. idx = (int)recvfrom(sockfd, input, sizeof(input), MSG_PEEK,
  6872. (struct sockaddr*)&cliAddr, &cliLen);
  6873. AssertIntGT(idx, 0);
  6874. }
  6875. else {
  6876. CloseSocket(sockfd);
  6877. }
  6878. wolfSSL_CTX_set_verify(ctx,
  6879. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  6880. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6881. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  6882. #endif
  6883. if (wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0)
  6884. != WOLFSSL_SUCCESS) {
  6885. /*err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  6886. goto done;
  6887. }
  6888. if (cbf != NULL && cbf->certPemFile != NULL)
  6889. certFile = cbf->certPemFile;
  6890. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6891. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, certFile,
  6892. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6893. #else
  6894. if (wolfSSL_CTX_use_certificate_file(ctx, certFile,
  6895. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6896. #endif
  6897. /*err_sys("can't load server cert chain file, "
  6898. "Please run from wolfSSL home dir");*/
  6899. goto done;
  6900. }
  6901. if (cbf != NULL && cbf->keyPemFile != NULL)
  6902. keyFile = cbf->keyPemFile;
  6903. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6904. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, keyFile,
  6905. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6906. #else
  6907. if (wolfSSL_CTX_use_PrivateKey_file(ctx, keyFile,
  6908. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6909. #endif
  6910. /*err_sys("can't load server key file, "
  6911. "Please run from wolfSSL home dir");*/
  6912. goto done;
  6913. }
  6914. #ifdef HAVE_CRL
  6915. if (cbf != NULL && cbf->crlPemFile != NULL) {
  6916. if (wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL) != WOLFSSL_SUCCESS)
  6917. goto done;
  6918. if (wolfSSL_CTX_LoadCRLFile(ctx, cbf->crlPemFile, WOLFSSL_FILETYPE_PEM)
  6919. != WOLFSSL_SUCCESS)
  6920. goto done;
  6921. }
  6922. #endif
  6923. /* call ctx setup callback */
  6924. if (cbf != NULL && cbf->ctx_ready != NULL) {
  6925. cbf->ctx_ready(ctx);
  6926. }
  6927. ssl = wolfSSL_new(ctx);
  6928. if (ssl == NULL) {
  6929. goto done;
  6930. }
  6931. if (doUdp) {
  6932. err = wolfSSL_dtls_set_peer(ssl, &cliAddr, cliLen);
  6933. if (err != WOLFSSL_SUCCESS)
  6934. goto done;
  6935. }
  6936. #ifdef WOLFSSL_SESSION_EXPORT
  6937. /* only add in more complex nonblocking case with session export tests */
  6938. if (args && opts->argc > 0) {
  6939. /* set as nonblock and time out for waiting on read/write */
  6940. tcp_set_nonblocking(&clientfd);
  6941. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  6942. }
  6943. #endif
  6944. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6945. if (sharedCtx && wolfSSL_use_certificate_file(ssl, certFile,
  6946. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6947. #else
  6948. if (wolfSSL_use_certificate_file(ssl, certFile,
  6949. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6950. #endif
  6951. /*err_sys("can't load server cert chain file, "
  6952. "Please run from wolfSSL home dir");*/
  6953. goto done;
  6954. }
  6955. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6956. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, keyFile,
  6957. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6958. #else
  6959. if (wolfSSL_use_PrivateKey_file(ssl, keyFile,
  6960. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6961. #endif
  6962. /*err_sys("can't load server key file, "
  6963. "Please run from wolfSSL home dir");*/
  6964. goto done;
  6965. }
  6966. if (wolfSSL_set_fd(ssl, clientfd) != WOLFSSL_SUCCESS) {
  6967. /*err_sys("SSL_set_fd failed");*/
  6968. goto done;
  6969. }
  6970. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  6971. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  6972. #elif !defined(NO_DH)
  6973. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  6974. #endif
  6975. /* call ssl setup callback */
  6976. if (cbf != NULL && cbf->ssl_ready != NULL) {
  6977. cbf->ssl_ready(ssl);
  6978. }
  6979. #ifdef WOLFSSL_SESSION_EXPORT
  6980. /* only add in more complex nonblocking case with session export tests */
  6981. if (opts->argc > 0) {
  6982. ret = nonblocking_accept_read(args, ssl, &clientfd);
  6983. if (ret >= 0) {
  6984. opts->return_code = TEST_SUCCESS;
  6985. }
  6986. #ifdef WOLFSSL_TIRTOS
  6987. Task_yield();
  6988. #endif
  6989. goto done;
  6990. }
  6991. #endif
  6992. #ifdef WOLFSSL_ASYNC_CRYPT
  6993. err = 0; /* Reset error */
  6994. #endif
  6995. do {
  6996. #ifdef WOLFSSL_ASYNC_CRYPT
  6997. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  6998. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  6999. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7000. }
  7001. #endif
  7002. ret = wolfSSL_negotiate(ssl);
  7003. err = wolfSSL_get_error(ssl, 0);
  7004. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7005. if (ret != WOLFSSL_SUCCESS) {
  7006. char buff[WOLFSSL_MAX_ERROR_SZ];
  7007. fprintf(stderr, "error = %d, %s\n", err,
  7008. wolfSSL_ERR_error_string((word32)err, buff));
  7009. /*err_sys("SSL_accept failed");*/
  7010. goto done;
  7011. }
  7012. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  7013. XMEMSET(server_side_msg2, 0, MD_MAX_SIZE);
  7014. msg_len = wolfSSL_get_peer_finished(ssl, server_side_msg2, MD_MAX_SIZE);
  7015. AssertIntGE(msg_len, 0);
  7016. XMEMSET(server_side_msg1, 0, MD_MAX_SIZE);
  7017. msg_len = wolfSSL_get_finished(ssl, server_side_msg1, MD_MAX_SIZE);
  7018. AssertIntGE(msg_len, 0);
  7019. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  7020. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  7021. if (idx > 0) {
  7022. input[idx] = '\0';
  7023. fprintf(stderr, "Client message: %s\n", input);
  7024. }
  7025. else if (idx < 0) {
  7026. goto done;
  7027. }
  7028. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  7029. /*err_sys("SSL_write failed");*/
  7030. goto done;
  7031. }
  7032. if (cbf != NULL && cbf->on_result != NULL)
  7033. cbf->on_result(ssl);
  7034. #ifdef WOLFSSL_TIRTOS
  7035. Task_yield();
  7036. #endif
  7037. opts->return_code = TEST_SUCCESS;
  7038. done:
  7039. if (cbf != NULL)
  7040. cbf->last_err = err;
  7041. if (cbf != NULL && cbf->on_cleanup != NULL)
  7042. cbf->on_cleanup(ssl);
  7043. wolfSSL_shutdown(ssl);
  7044. wolfSSL_free(ssl);
  7045. if (!sharedCtx)
  7046. wolfSSL_CTX_free(ctx);
  7047. CloseSocket(clientfd);
  7048. #ifdef WOLFSSL_TIRTOS
  7049. fdCloseSession(Task_self());
  7050. #endif
  7051. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7052. && defined(HAVE_THREAD_LS)
  7053. wc_ecc_fp_free(); /* free per thread cache */
  7054. #endif
  7055. if (cbf == NULL || !cbf->ticNoInit) {
  7056. #if defined(HAVE_SESSION_TICKET) && \
  7057. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  7058. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  7059. OpenSSLTicketCleanup();
  7060. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  7061. TicketCleanup();
  7062. #endif
  7063. #endif
  7064. }
  7065. wolfSSL_SetLoggingPrefix(NULL);
  7066. WOLFSSL_RETURN_FROM_THREAD(0);
  7067. }
  7068. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  7069. !defined(WOLFSSL_NO_TLS12)
  7070. static THREAD_RETURN WOLFSSL_THREAD test_server_loop(void* args)
  7071. {
  7072. SOCKET_T sockfd;
  7073. SOCKET_T clientfd = -1;
  7074. word16 port;
  7075. callback_functions* cbf;
  7076. WOLFSSL_CTX* ctx = 0;
  7077. WOLFSSL* ssl = 0;
  7078. char msg[] = "I hear you fa shizzle!";
  7079. char input[1024];
  7080. int idx;
  7081. int ret, err = 0;
  7082. int sharedCtx = 0;
  7083. func_args* opts = (func_args*)args;
  7084. int loop_count = opts->argc;
  7085. int count = 0;
  7086. #ifdef WOLFSSL_TIRTOS
  7087. fdOpenSession(Task_self());
  7088. #endif
  7089. opts->return_code = TEST_FAIL;
  7090. cbf = opts->callbacks;
  7091. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7092. if (cbf != NULL && cbf->ctx) {
  7093. ctx = cbf->ctx;
  7094. sharedCtx = 1;
  7095. }
  7096. else
  7097. #endif
  7098. {
  7099. WOLFSSL_METHOD* method = NULL;
  7100. if (cbf != NULL && cbf->method != NULL) {
  7101. method = cbf->method();
  7102. }
  7103. else {
  7104. method = wolfSSLv23_server_method();
  7105. }
  7106. ctx = wolfSSL_CTX_new(method);
  7107. }
  7108. #if defined(USE_WINDOWS_API)
  7109. port = opts->signal->port;
  7110. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  7111. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  7112. /* Let tcp_listen assign port */
  7113. port = 0;
  7114. #else
  7115. /* Use default port */
  7116. port = wolfSSLPort;
  7117. #endif
  7118. wolfSSL_CTX_set_verify(ctx,
  7119. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  7120. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7121. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7122. #endif
  7123. if (wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0)
  7124. != WOLFSSL_SUCCESS) {
  7125. /*err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  7126. /* Release the wait for TCP ready. */
  7127. signal_ready(opts->signal);
  7128. goto done;
  7129. }
  7130. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  7131. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7132. /*err_sys("can't load server cert chain file, "
  7133. "Please run from wolfSSL home dir");*/
  7134. /* Release the wait for TCP ready. */
  7135. signal_ready(opts->signal);
  7136. goto done;
  7137. }
  7138. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  7139. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7140. /*err_sys("can't load server key file, "
  7141. "Please run from wolfSSL home dir");*/
  7142. /* Release the wait for TCP ready. */
  7143. signal_ready(opts->signal);
  7144. goto done;
  7145. }
  7146. /* call ctx setup callback */
  7147. if (cbf != NULL && cbf->ctx_ready != NULL) {
  7148. cbf->ctx_ready(ctx);
  7149. }
  7150. while (count != loop_count) {
  7151. ssl = wolfSSL_new(ctx);
  7152. if (ssl == NULL) {
  7153. signal_ready(opts->signal);
  7154. goto done;
  7155. }
  7156. if (sharedCtx && wolfSSL_use_certificate_file(ssl, svrCertFile,
  7157. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7158. /*err_sys("can't load server cert chain file, "
  7159. "Please run from wolfSSL home dir");*/
  7160. /* Release the wait for TCP ready. */
  7161. signal_ready(opts->signal);
  7162. goto done;
  7163. }
  7164. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, svrKeyFile,
  7165. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7166. /*err_sys("can't load server key file, "
  7167. "Please run from wolfSSL home dir");*/
  7168. /* Release the wait for TCP ready. */
  7169. signal_ready(opts->signal);
  7170. goto done;
  7171. }
  7172. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  7173. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  7174. #elif !defined(NO_DH)
  7175. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  7176. #endif
  7177. /* call ssl setup callback */
  7178. if (cbf != NULL && cbf->ssl_ready != NULL) {
  7179. cbf->ssl_ready(ssl);
  7180. }
  7181. /* do it here to detect failure */
  7182. tcp_accept(&sockfd, &clientfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0,
  7183. 0);
  7184. CloseSocket(sockfd);
  7185. if (wolfSSL_set_fd(ssl, clientfd) != WOLFSSL_SUCCESS) {
  7186. /*err_sys("SSL_set_fd failed");*/
  7187. goto done;
  7188. }
  7189. #ifdef WOLFSSL_ASYNC_CRYPT
  7190. err = 0; /* Reset error */
  7191. #endif
  7192. do {
  7193. #ifdef WOLFSSL_ASYNC_CRYPT
  7194. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7195. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7196. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7197. }
  7198. #endif
  7199. ret = wolfSSL_accept(ssl);
  7200. err = wolfSSL_get_error(ssl, 0);
  7201. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7202. if (ret != WOLFSSL_SUCCESS) {
  7203. char buff[WOLFSSL_MAX_ERROR_SZ];
  7204. fprintf(stderr, "error = %d, %s\n", err,
  7205. wolfSSL_ERR_error_string(err, buff));
  7206. /*err_sys("SSL_accept failed");*/
  7207. goto done;
  7208. }
  7209. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  7210. if (idx > 0) {
  7211. input[idx] = '\0';
  7212. fprintf(stderr, "Client message: %s\n", input);
  7213. }
  7214. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  7215. /*err_sys("SSL_write failed");*/
  7216. goto done;
  7217. }
  7218. /* free ssl for this connection */
  7219. wolfSSL_shutdown(ssl);
  7220. wolfSSL_free(ssl); ssl = NULL;
  7221. CloseSocket(clientfd);
  7222. clientfd = -1;
  7223. count++;
  7224. }
  7225. #ifdef WOLFSSL_TIRTOS
  7226. Task_yield();
  7227. #endif
  7228. opts->return_code = TEST_SUCCESS;
  7229. done:
  7230. if (ssl != NULL) {
  7231. wolfSSL_shutdown(ssl);
  7232. wolfSSL_free(ssl);
  7233. }
  7234. if (!sharedCtx)
  7235. wolfSSL_CTX_free(ctx);
  7236. if (clientfd >= 0)
  7237. CloseSocket(clientfd);
  7238. #ifdef WOLFSSL_TIRTOS
  7239. fdCloseSession(Task_self());
  7240. #endif
  7241. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7242. && defined(HAVE_THREAD_LS)
  7243. wc_ecc_fp_free(); /* free per thread cache */
  7244. #endif
  7245. WOLFSSL_RETURN_FROM_THREAD(0);
  7246. }
  7247. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && !defined(WOLFSSL_TLS13) */
  7248. static int test_client_nofail(void* args, cbType cb)
  7249. {
  7250. #if !defined(NO_WOLFSSL_CLIENT)
  7251. SOCKET_T sockfd = 0;
  7252. callback_functions* cbf;
  7253. WOLFSSL_CTX* ctx = 0;
  7254. WOLFSSL* ssl = 0;
  7255. WOLFSSL_CIPHER* cipher;
  7256. char msg[64] = "hello wolfssl!";
  7257. char reply[1024];
  7258. int input;
  7259. int msgSz = (int)XSTRLEN(msg);
  7260. int ret, err = 0;
  7261. int cipherSuite;
  7262. int sharedCtx = 0;
  7263. int doUdp = 0;
  7264. const char* cipherName1, *cipherName2;
  7265. wolfSSL_SetLoggingPrefix("client");
  7266. #ifdef WOLFSSL_TIRTOS
  7267. fdOpenSession(Task_self());
  7268. #endif
  7269. ((func_args*)args)->return_code = TEST_FAIL;
  7270. cbf = ((func_args*)args)->callbacks;
  7271. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7272. if (cbf != NULL && cbf->ctx) {
  7273. ctx = cbf->ctx;
  7274. sharedCtx = cbf->isSharedCtx;
  7275. }
  7276. else
  7277. #endif
  7278. {
  7279. WOLFSSL_METHOD* method = NULL;
  7280. if (cbf != NULL && cbf->method != NULL) {
  7281. method = cbf->method();
  7282. }
  7283. else {
  7284. method = wolfSSLv23_client_method();
  7285. }
  7286. ctx = wolfSSL_CTX_new(method);
  7287. }
  7288. if (cbf != NULL)
  7289. doUdp = cbf->doUdp;
  7290. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7291. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7292. #endif
  7293. /* Do connect here so server detects failures */
  7294. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7295. doUdp, 0, NULL);
  7296. /* Connect the socket so that we don't have to set the peer later on */
  7297. if (doUdp)
  7298. udp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port);
  7299. if (wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0) != WOLFSSL_SUCCESS)
  7300. {
  7301. /* err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  7302. goto done;
  7303. }
  7304. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7305. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7306. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7307. #else
  7308. if (wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7309. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7310. #endif
  7311. /*err_sys("can't load client cert file, "
  7312. "Please run from wolfSSL home dir");*/
  7313. goto done;
  7314. }
  7315. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7316. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7317. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7318. #else
  7319. if (wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7320. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7321. #endif
  7322. /*err_sys("can't load client key file, "
  7323. "Please run from wolfSSL home dir");*/
  7324. goto done;
  7325. }
  7326. #ifdef HAVE_CRL
  7327. if (cbf != NULL && cbf->crlPemFile != NULL) {
  7328. if (wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL) != WOLFSSL_SUCCESS)
  7329. goto done;
  7330. if (wolfSSL_CTX_LoadCRLFile(ctx, cbf->crlPemFile, WOLFSSL_FILETYPE_PEM)
  7331. != WOLFSSL_SUCCESS)
  7332. goto done;
  7333. }
  7334. #endif
  7335. /* call ctx setup callback */
  7336. if (cbf != NULL && cbf->ctx_ready != NULL) {
  7337. cbf->ctx_ready(ctx);
  7338. }
  7339. ssl = wolfSSL_new(ctx);
  7340. if (ssl == NULL) {
  7341. goto done;
  7342. }
  7343. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7344. if (sharedCtx && wolfSSL_use_certificate_file(ssl, cliCertFile,
  7345. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7346. #else
  7347. if (wolfSSL_use_certificate_file(ssl, cliCertFile,
  7348. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7349. #endif
  7350. /*err_sys("can't load client cert file, "
  7351. "Please run from wolfSSL home dir");*/
  7352. goto done;
  7353. }
  7354. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7355. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7356. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7357. #else
  7358. if (wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7359. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7360. #endif
  7361. /*err_sys("can't load client key file, "
  7362. "Please run from wolfSSL home dir");*/
  7363. goto done;
  7364. }
  7365. if (!doUdp) {
  7366. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7367. /*err_sys("SSL_set_fd failed");*/
  7368. goto done;
  7369. }
  7370. }
  7371. else {
  7372. #ifdef WOLFSSL_DTLS
  7373. if (wolfSSL_set_dtls_fd_connected(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7374. /*err_sys("SSL_set_fd failed");*/
  7375. goto done;
  7376. }
  7377. #else
  7378. goto done;
  7379. #endif
  7380. }
  7381. /* call ssl setup callback */
  7382. if (cbf != NULL && cbf->ssl_ready != NULL) {
  7383. cbf->ssl_ready(ssl);
  7384. }
  7385. #ifdef WOLFSSL_ASYNC_CRYPT
  7386. err = 0; /* Reset error */
  7387. #endif
  7388. do {
  7389. #ifdef WOLFSSL_ASYNC_CRYPT
  7390. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7391. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7392. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7393. }
  7394. #endif
  7395. ret = wolfSSL_negotiate(ssl);
  7396. err = wolfSSL_get_error(ssl, 0);
  7397. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7398. if (ret != WOLFSSL_SUCCESS) {
  7399. char buff[WOLFSSL_MAX_ERROR_SZ];
  7400. fprintf(stderr, "error = %d, %s\n", err,
  7401. wolfSSL_ERR_error_string((word32)err, buff));
  7402. /*err_sys("SSL_connect failed");*/
  7403. goto done;
  7404. }
  7405. /* test the various get cipher methods */
  7406. /* Internal cipher suite names */
  7407. cipherSuite = wolfSSL_get_current_cipher_suite(ssl);
  7408. cipherName1 = wolfSSL_get_cipher_name(ssl);
  7409. cipherName2 = wolfSSL_get_cipher_name_from_suite(
  7410. (byte)(cipherSuite >> 8), cipherSuite & 0xFF);
  7411. AssertStrEQ(cipherName1, cipherName2);
  7412. /* IANA Cipher Suites Names */
  7413. /* Unless WOLFSSL_CIPHER_INTERNALNAME or NO_ERROR_STRINGS,
  7414. then it's the internal cipher suite name */
  7415. cipher = wolfSSL_get_current_cipher(ssl);
  7416. cipherName1 = wolfSSL_CIPHER_get_name(cipher);
  7417. cipherName2 = wolfSSL_get_cipher(ssl);
  7418. AssertStrEQ(cipherName1, cipherName2);
  7419. #if !defined(WOLFSSL_CIPHER_INTERNALNAME) && !defined(NO_ERROR_STRINGS) && \
  7420. !defined(WOLFSSL_QT)
  7421. cipherName1 = wolfSSL_get_cipher_name_iana_from_suite(
  7422. (byte)(cipherSuite >> 8), cipherSuite & 0xFF);
  7423. AssertStrEQ(cipherName1, cipherName2);
  7424. #endif
  7425. if (cb != NULL)
  7426. (cb)(ctx, ssl);
  7427. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7428. /*err_sys("SSL_write failed");*/
  7429. goto done;
  7430. }
  7431. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7432. if (input > 0) {
  7433. reply[input] = '\0';
  7434. fprintf(stderr, "Server response: %s\n", reply);
  7435. }
  7436. if (cbf != NULL && cbf->on_result != NULL)
  7437. cbf->on_result(ssl);
  7438. ((func_args*)args)->return_code = TEST_SUCCESS;
  7439. done:
  7440. if (cbf != NULL)
  7441. cbf->last_err = err;
  7442. if (cbf != NULL && cbf->on_cleanup != NULL)
  7443. cbf->on_cleanup(ssl);
  7444. wolfSSL_free(ssl);
  7445. if (!sharedCtx)
  7446. wolfSSL_CTX_free(ctx);
  7447. CloseSocket(sockfd);
  7448. #ifdef WOLFSSL_TIRTOS
  7449. fdCloseSession(Task_self());
  7450. #endif
  7451. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7452. && defined(HAVE_THREAD_LS)
  7453. wc_ecc_fp_free(); /* free per thread cache */
  7454. #endif
  7455. #else
  7456. (void)args;
  7457. (void)cb;
  7458. #endif /* !NO_WOLFSSL_CLIENT */
  7459. wolfSSL_SetLoggingPrefix(NULL);
  7460. return 0;
  7461. }
  7462. void test_wolfSSL_client_server_nofail_ex(callback_functions* client_cb,
  7463. callback_functions* server_cb, cbType client_on_handshake)
  7464. {
  7465. func_args client_args;
  7466. func_args server_args;
  7467. tcp_ready ready;
  7468. THREAD_TYPE serverThread;
  7469. XMEMSET(&client_args, 0, sizeof(func_args));
  7470. XMEMSET(&server_args, 0, sizeof(func_args));
  7471. #ifdef WOLFSSL_TIRTOS
  7472. fdOpenSession(Task_self());
  7473. #endif
  7474. StartTCP();
  7475. InitTcpReady(&ready);
  7476. #if defined(USE_WINDOWS_API)
  7477. /* use RNG to get random port if using windows */
  7478. ready.port = GetRandomPort();
  7479. #endif
  7480. server_args.signal = &ready;
  7481. server_args.callbacks = server_cb;
  7482. client_args.signal = &ready;
  7483. client_args.callbacks = client_cb;
  7484. start_thread(test_server_nofail, &server_args, &serverThread);
  7485. wait_tcp_ready(&server_args);
  7486. test_client_nofail(&client_args, client_on_handshake);
  7487. join_thread(serverThread);
  7488. client_cb->return_code = client_args.return_code;
  7489. server_cb->return_code = server_args.return_code;
  7490. FreeTcpReady(&ready);
  7491. #ifdef WOLFSSL_TIRTOS
  7492. fdOpenSession(Task_self());
  7493. #endif
  7494. }
  7495. void test_wolfSSL_client_server_nofail(callback_functions* client_cb,
  7496. callback_functions* server_cb)
  7497. {
  7498. test_wolfSSL_client_server_nofail_ex(client_cb, server_cb, NULL);
  7499. }
  7500. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  7501. !defined(WOLFSSL_NO_TLS12) && !defined(NO_WOLFSSL_CLIENT)
  7502. static void test_client_reuse_WOLFSSLobj(void* args, cbType cb,
  7503. void* server_args)
  7504. {
  7505. SOCKET_T sockfd = 0;
  7506. callback_functions* cbf;
  7507. WOLFSSL_CTX* ctx = 0;
  7508. WOLFSSL* ssl = 0;
  7509. WOLFSSL_SESSION* session = NULL;
  7510. char msg[64] = "hello wolfssl!";
  7511. char reply[1024];
  7512. int input;
  7513. int msgSz = (int)XSTRLEN(msg);
  7514. int ret, err = 0;
  7515. int sharedCtx = 0;
  7516. #ifdef WOLFSSL_TIRTOS
  7517. fdOpenSession(Task_self());
  7518. #endif
  7519. ((func_args*)args)->return_code = TEST_FAIL;
  7520. cbf = ((func_args*)args)->callbacks;
  7521. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7522. if (cbf != NULL && cbf->ctx) {
  7523. ctx = cbf->ctx;
  7524. sharedCtx = 1;
  7525. }
  7526. else
  7527. #endif
  7528. {
  7529. WOLFSSL_METHOD* method = NULL;
  7530. if (cbf != NULL && cbf->method != NULL) {
  7531. method = cbf->method();
  7532. }
  7533. else {
  7534. method = wolfSSLv23_client_method();
  7535. }
  7536. ctx = wolfSSL_CTX_new(method);
  7537. }
  7538. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7539. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7540. #endif
  7541. /* Do connect here so server detects failures */
  7542. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7543. 0, 0, NULL);
  7544. if (wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0) !=
  7545. WOLFSSL_SUCCESS) {
  7546. /* err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  7547. goto done;
  7548. }
  7549. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7550. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7551. /*err_sys("can't load client cert file, "
  7552. "Please run from wolfSSL home dir");*/
  7553. goto done;
  7554. }
  7555. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7556. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7557. /*err_sys("can't load client key file, "
  7558. "Please run from wolfSSL home dir");*/
  7559. goto done;
  7560. }
  7561. /* call ctx setup callback */
  7562. if (cbf != NULL && cbf->ctx_ready != NULL) {
  7563. cbf->ctx_ready(ctx);
  7564. }
  7565. ssl = wolfSSL_new(ctx);
  7566. if (ssl == NULL) {
  7567. goto done;
  7568. }
  7569. /* keep handshake resources for re-using WOLFSSL obj */
  7570. wolfSSL_KeepArrays(ssl);
  7571. if (wolfSSL_KeepHandshakeResources(ssl)) {
  7572. /* err_sys("SSL_KeepHandshakeResources failed"); */
  7573. goto done;
  7574. }
  7575. if (sharedCtx && wolfSSL_use_certificate_file(ssl, cliCertFile,
  7576. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7577. /*err_sys("can't load client cert file, "
  7578. "Please run from wolfSSL home dir");*/
  7579. goto done;
  7580. }
  7581. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7582. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7583. /*err_sys("can't load client key file, "
  7584. "Please run from wolfSSL home dir");*/
  7585. goto done;
  7586. }
  7587. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7588. /*err_sys("SSL_set_fd failed");*/
  7589. goto done;
  7590. }
  7591. /* call ssl setup callback */
  7592. if (cbf != NULL && cbf->ssl_ready != NULL) {
  7593. cbf->ssl_ready(ssl);
  7594. }
  7595. #ifdef WOLFSSL_ASYNC_CRYPT
  7596. err = 0; /* Reset error */
  7597. #endif
  7598. do {
  7599. #ifdef WOLFSSL_ASYNC_CRYPT
  7600. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7601. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7602. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7603. }
  7604. #endif
  7605. ret = wolfSSL_connect(ssl);
  7606. err = wolfSSL_get_error(ssl, 0);
  7607. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7608. if (ret != WOLFSSL_SUCCESS) {
  7609. char buff[WOLFSSL_MAX_ERROR_SZ];
  7610. fprintf(stderr, "error = %d, %s\n", err,
  7611. wolfSSL_ERR_error_string(err, buff));
  7612. /*err_sys("SSL_connect failed");*/
  7613. goto done;
  7614. }
  7615. /* Build first session */
  7616. if (cb != NULL)
  7617. cb(ctx, ssl);
  7618. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7619. /*err_sys("SSL_write failed");*/
  7620. goto done;
  7621. }
  7622. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7623. if (input > 0) {
  7624. reply[input] = '\0';
  7625. fprintf(stderr, "Server response: %s\n", reply);
  7626. }
  7627. /* Session Resumption by re-using WOLFSSL object */
  7628. wolfSSL_set_quiet_shutdown(ssl, 1);
  7629. if (wolfSSL_shutdown(ssl) != WOLFSSL_SUCCESS) {
  7630. /* err_sys ("SSL shutdown failed"); */
  7631. goto done;
  7632. }
  7633. session = wolfSSL_get1_session(ssl);
  7634. if (wolfSSL_clear(ssl) != WOLFSSL_SUCCESS) {
  7635. wolfSSL_SESSION_free(session);
  7636. /* err_sys ("SSL_clear failed"); */
  7637. goto done;
  7638. }
  7639. wolfSSL_set_session(ssl, session);
  7640. wolfSSL_SESSION_free(session);
  7641. session = NULL;
  7642. /* close socket once */
  7643. CloseSocket(sockfd);
  7644. sockfd = 0;
  7645. /* wait until server ready */
  7646. wait_tcp_ready((func_args*)server_args);
  7647. fprintf(stderr, "session resumption\n");
  7648. /* Do re-connect */
  7649. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7650. 0, 0, NULL);
  7651. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7652. /*err_sys("SSL_set_fd failed");*/
  7653. goto done;
  7654. }
  7655. #ifdef WOLFSSL_ASYNC_CRYPT
  7656. err = 0; /* Reset error */
  7657. #endif
  7658. do {
  7659. #ifdef WOLFSSL_ASYNC_CRYPT
  7660. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7661. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7662. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7663. }
  7664. #endif
  7665. ret = wolfSSL_connect(ssl);
  7666. err = wolfSSL_get_error(ssl, 0);
  7667. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7668. if (ret != WOLFSSL_SUCCESS) {
  7669. char buff[WOLFSSL_MAX_ERROR_SZ];
  7670. fprintf(stderr, "error = %d, %s\n", err,
  7671. wolfSSL_ERR_error_string(err, buff));
  7672. /*err_sys("SSL_connect failed");*/
  7673. goto done;
  7674. }
  7675. /* Build first session */
  7676. if (cb != NULL)
  7677. cb(ctx, ssl);
  7678. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7679. /*err_sys("SSL_write failed");*/
  7680. goto done;
  7681. }
  7682. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7683. if (input > 0) {
  7684. reply[input] = '\0';
  7685. fprintf(stderr, "Server response: %s\n", reply);
  7686. }
  7687. ((func_args*)args)->return_code = TEST_SUCCESS;
  7688. done:
  7689. wolfSSL_free(ssl);
  7690. if (!sharedCtx)
  7691. wolfSSL_CTX_free(ctx);
  7692. CloseSocket(sockfd);
  7693. #ifdef WOLFSSL_TIRTOS
  7694. fdCloseSession(Task_self());
  7695. #endif
  7696. return;
  7697. }
  7698. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) &&
  7699. !defined(WOLFSSL_TLS13) && !defined(NO_WOLFSSL_CLIENT) */
  7700. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  7701. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)) && \
  7702. defined(HAVE_ALPN) && defined(HAVE_SNI) && \
  7703. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(NO_BIO)
  7704. #define HAVE_ALPN_PROTOS_SUPPORT
  7705. #endif
  7706. /* Generic TLS client / server with callbacks for API unit tests
  7707. * Used by SNI / ALPN / crypto callback helper functions */
  7708. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  7709. (defined(HAVE_SNI) || defined(HAVE_ALPN) || defined(WOLF_CRYPTO_CB) || \
  7710. defined(HAVE_ALPN_PROTOS_SUPPORT)) || defined(WOLFSSL_STATIC_MEMORY)
  7711. #define ENABLE_TLS_CALLBACK_TEST
  7712. #endif
  7713. #if defined(ENABLE_TLS_CALLBACK_TEST) || \
  7714. (defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT))
  7715. /* TLS server for API unit testing - generic */
  7716. static THREAD_RETURN WOLFSSL_THREAD run_wolfssl_server(void* args)
  7717. {
  7718. callback_functions* callbacks = ((func_args*)args)->callbacks;
  7719. WOLFSSL_CTX* ctx = NULL;
  7720. WOLFSSL* ssl = NULL;
  7721. SOCKET_T sfd = 0;
  7722. SOCKET_T cfd = 0;
  7723. word16 port;
  7724. char msg[] = "I hear you fa shizzle!";
  7725. int len = (int) XSTRLEN(msg);
  7726. char input[1024];
  7727. int idx;
  7728. int ret, err = 0;
  7729. ((func_args*)args)->return_code = TEST_FAIL;
  7730. #if defined(USE_WINDOWS_API)
  7731. port = ((func_args*)args)->signal->port;
  7732. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  7733. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  7734. /* Let tcp_listen assign port */
  7735. port = 0;
  7736. #else
  7737. /* Use default port */
  7738. port = wolfSSLPort;
  7739. #endif
  7740. #ifdef WOLFSSL_DTLS
  7741. if (callbacks->method == wolfDTLS_server_method
  7742. #ifdef WOLFSSL_STATIC_MEMORY
  7743. || callbacks->method_ex == wolfDTLS_server_method_ex
  7744. #endif
  7745. #ifndef NO_OLD_TLS
  7746. || callbacks->method == wolfDTLSv1_server_method
  7747. #ifdef WOLFSSL_STATIC_MEMORY
  7748. || callbacks->method_ex == wolfDTLSv1_server_method_ex
  7749. #endif
  7750. #endif
  7751. #ifndef WOLFSSL_NO_TLS12
  7752. || callbacks->method == wolfDTLSv1_2_server_method
  7753. #ifdef WOLFSSL_STATIC_MEMORY
  7754. || callbacks->method_ex == wolfDTLSv1_2_server_method_ex
  7755. #endif
  7756. #endif
  7757. #ifdef WOLFSSL_DTLS13
  7758. || callbacks->method == wolfDTLSv1_3_server_method
  7759. #ifdef WOLFSSL_STATIC_MEMORY
  7760. || callbacks->method_ex == wolfDTLSv1_3_server_method_ex
  7761. #endif
  7762. #endif
  7763. ) {
  7764. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 1, 0, 0, 0, 0, 0);
  7765. }
  7766. else
  7767. #endif
  7768. {
  7769. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  7770. }
  7771. #ifdef WOLFSSL_STATIC_MEMORY
  7772. if (callbacks->method_ex != NULL && callbacks->mem != NULL &&
  7773. callbacks->memSz > 0) {
  7774. ret = wolfSSL_CTX_load_static_memory(&ctx, callbacks->method_ex,
  7775. callbacks->mem, callbacks->memSz, 0, 1);
  7776. if (ret != WOLFSSL_SUCCESS) {
  7777. fprintf(stderr, "CTX static new failed %d\n", ret);
  7778. goto cleanup;
  7779. }
  7780. }
  7781. #else
  7782. ctx = wolfSSL_CTX_new(callbacks->method());
  7783. #endif
  7784. if (ctx == NULL) {
  7785. fprintf(stderr, "CTX new failed\n");
  7786. goto cleanup;
  7787. }
  7788. /* set defaults */
  7789. if (callbacks->caPemFile == NULL)
  7790. callbacks->caPemFile = cliCertFile;
  7791. if (callbacks->certPemFile == NULL)
  7792. callbacks->certPemFile = svrCertFile;
  7793. if (callbacks->keyPemFile == NULL)
  7794. callbacks->keyPemFile = svrKeyFile;
  7795. #ifdef WOLFSSL_TIRTOS
  7796. fdOpenSession(Task_self());
  7797. #endif
  7798. wolfSSL_CTX_SetDevId(ctx, callbacks->devId);
  7799. wolfSSL_CTX_set_verify(ctx,
  7800. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  7801. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7802. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7803. #endif
  7804. #if defined(WOLFSSL_SESSION_EXPORT) && defined(WOLFSSL_DTLS)
  7805. if (callbacks->method == wolfDTLSv1_2_server_method) {
  7806. if (wolfSSL_CTX_dtls_set_export(ctx, test_export) != WOLFSSL_SUCCESS)
  7807. goto cleanup;
  7808. }
  7809. #endif
  7810. if (wolfSSL_CTX_load_verify_locations(ctx, callbacks->caPemFile, 0) !=
  7811. WOLFSSL_SUCCESS) {
  7812. goto cleanup;
  7813. }
  7814. if (wolfSSL_CTX_use_certificate_file(ctx, callbacks->certPemFile,
  7815. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7816. goto cleanup;
  7817. }
  7818. if (wolfSSL_CTX_use_PrivateKey_file(ctx, callbacks->keyPemFile,
  7819. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7820. goto cleanup;
  7821. }
  7822. #ifdef HAVE_CRL
  7823. if (callbacks->crlPemFile != NULL) {
  7824. if (wolfSSL_CTX_LoadCRLFile(ctx, callbacks->crlPemFile,
  7825. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7826. goto cleanup;
  7827. }
  7828. }
  7829. #endif
  7830. if (callbacks->ctx_ready)
  7831. callbacks->ctx_ready(ctx);
  7832. ssl = wolfSSL_new(ctx);
  7833. if (ssl == NULL) {
  7834. fprintf(stderr, "SSL new failed\n");
  7835. goto cleanup;
  7836. }
  7837. if (wolfSSL_dtls(ssl)) {
  7838. SOCKADDR_IN_T cliAddr;
  7839. socklen_t cliLen;
  7840. cliLen = sizeof(cliAddr);
  7841. idx = (int)recvfrom(sfd, input, sizeof(input), MSG_PEEK,
  7842. (struct sockaddr*)&cliAddr, &cliLen);
  7843. if (idx <= 0) {
  7844. goto cleanup;
  7845. }
  7846. wolfSSL_dtls_set_peer(ssl, &cliAddr, cliLen);
  7847. }
  7848. else {
  7849. CloseSocket(sfd);
  7850. }
  7851. if (wolfSSL_set_fd(ssl, cfd) != WOLFSSL_SUCCESS) {
  7852. goto cleanup;
  7853. }
  7854. if (callbacks->loadToSSL) {
  7855. wolfSSL_SetDevId(ssl, callbacks->devId);
  7856. if (wolfSSL_use_certificate_file(ssl, callbacks->certPemFile,
  7857. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7858. goto cleanup;
  7859. }
  7860. if (wolfSSL_use_PrivateKey_file(ssl, callbacks->keyPemFile,
  7861. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7862. goto cleanup;
  7863. }
  7864. }
  7865. #ifdef NO_PSK
  7866. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  7867. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  7868. #elif !defined(NO_DH)
  7869. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  7870. #endif
  7871. #endif
  7872. if (callbacks->ssl_ready)
  7873. callbacks->ssl_ready(ssl);
  7874. #ifdef WOLFSSL_ASYNC_CRYPT
  7875. err = 0; /* Reset error */
  7876. #endif
  7877. do {
  7878. #ifdef WOLFSSL_ASYNC_CRYPT
  7879. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7880. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7881. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7882. }
  7883. #endif
  7884. ret = wolfSSL_accept(ssl);
  7885. err = wolfSSL_get_error(ssl, ret);
  7886. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7887. if (ret != WOLFSSL_SUCCESS) {
  7888. char buff[WOLFSSL_MAX_ERROR_SZ];
  7889. fprintf(stderr, "accept error = %d, %s\n", err,
  7890. wolfSSL_ERR_error_string((word32)err, buff));
  7891. /*err_sys("SSL_accept failed");*/
  7892. }
  7893. else {
  7894. #ifdef WOLFSSL_ASYNC_CRYPT
  7895. err = 0; /* Reset error */
  7896. #endif
  7897. do {
  7898. #ifdef WOLFSSL_ASYNC_CRYPT
  7899. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7900. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7901. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7902. }
  7903. #endif
  7904. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  7905. err = wolfSSL_get_error(ssl, idx);
  7906. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7907. if (idx > 0) {
  7908. input[idx] = 0;
  7909. fprintf(stderr, "Client message: %s\n", input);
  7910. }
  7911. #ifdef WOLFSSL_ASYNC_CRYPT
  7912. err = 0; /* Reset error */
  7913. #endif
  7914. do {
  7915. #ifdef WOLFSSL_ASYNC_CRYPT
  7916. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7917. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7918. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7919. }
  7920. #endif
  7921. ret = wolfSSL_write(ssl, msg, len);
  7922. err = wolfSSL_get_error(ssl, ret);
  7923. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7924. if (len != ret) {
  7925. goto cleanup;
  7926. }
  7927. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(HAVE_IO_POOL) && \
  7928. defined(WOLFSSL_DTLS)
  7929. if (wolfSSL_dtls(ssl)) {
  7930. byte* import;
  7931. word32 sz;
  7932. wolfSSL_dtls_export(ssl, NULL, &sz);
  7933. import = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7934. if (import == NULL) {
  7935. goto cleanup;
  7936. }
  7937. idx = wolfSSL_dtls_export(ssl, import, &sz);
  7938. if (idx < 0) {
  7939. goto cleanup;
  7940. }
  7941. if (wolfSSL_dtls_import(ssl, import, idx) < 0) {
  7942. goto cleanup;
  7943. }
  7944. XFREE(import, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7945. }
  7946. #endif
  7947. #ifdef WOLFSSL_TIRTOS
  7948. Task_yield();
  7949. #endif
  7950. ((func_args*)args)->return_code = TEST_SUCCESS;
  7951. }
  7952. if (callbacks->on_result)
  7953. callbacks->on_result(ssl);
  7954. wolfSSL_shutdown(ssl);
  7955. cleanup:
  7956. wolfSSL_free(ssl);
  7957. wolfSSL_CTX_free(ctx);
  7958. CloseSocket(cfd);
  7959. #ifdef WOLFSSL_TIRTOS
  7960. fdCloseSession(Task_self());
  7961. #endif
  7962. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7963. && defined(HAVE_THREAD_LS)
  7964. wc_ecc_fp_free(); /* free per thread cache */
  7965. #endif
  7966. WOLFSSL_RETURN_FROM_THREAD(0);
  7967. }
  7968. /* TLS Client for API unit testing - generic */
  7969. static void run_wolfssl_client(void* args)
  7970. {
  7971. callback_functions* callbacks = ((func_args*)args)->callbacks;
  7972. WOLFSSL_CTX* ctx = NULL;
  7973. WOLFSSL* ssl = NULL;
  7974. SOCKET_T sfd = 0;
  7975. char msg[] = "hello wolfssl server!";
  7976. int len = (int) XSTRLEN(msg);
  7977. char input[1024];
  7978. int ret, err = 0;
  7979. ((func_args*)args)->return_code = TEST_FAIL;
  7980. /* set defaults */
  7981. if (callbacks->caPemFile == NULL)
  7982. callbacks->caPemFile = caCertFile;
  7983. if (callbacks->certPemFile == NULL)
  7984. callbacks->certPemFile = cliCertFile;
  7985. if (callbacks->keyPemFile == NULL)
  7986. callbacks->keyPemFile = cliKeyFile;
  7987. #ifdef WOLFSSL_STATIC_MEMORY
  7988. if (callbacks->method_ex != NULL && callbacks->mem != NULL &&
  7989. callbacks->memSz > 0) {
  7990. ret = wolfSSL_CTX_load_static_memory(&ctx, callbacks->method_ex,
  7991. callbacks->mem, callbacks->memSz, 0, 1);
  7992. if (ret != WOLFSSL_SUCCESS) {
  7993. fprintf(stderr, "CTX static new failed %d\n", ret);
  7994. goto cleanup;
  7995. }
  7996. }
  7997. #else
  7998. ctx = wolfSSL_CTX_new(callbacks->method());
  7999. #endif
  8000. if (ctx == NULL) {
  8001. fprintf(stderr, "CTX new failed\n");
  8002. goto cleanup;
  8003. }
  8004. #ifdef WOLFSSL_TIRTOS
  8005. fdOpenSession(Task_self());
  8006. #endif
  8007. if (!callbacks->loadToSSL) {
  8008. wolfSSL_CTX_SetDevId(ctx, callbacks->devId);
  8009. }
  8010. #ifdef WOLFSSL_ENCRYPTED_KEYS
  8011. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  8012. #endif
  8013. if (wolfSSL_CTX_load_verify_locations(ctx, callbacks->caPemFile, 0) !=
  8014. WOLFSSL_SUCCESS) {
  8015. goto cleanup;
  8016. }
  8017. if (!callbacks->loadToSSL) {
  8018. if (wolfSSL_CTX_use_certificate_file(ctx, callbacks->certPemFile,
  8019. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8020. goto cleanup;
  8021. }
  8022. if (wolfSSL_CTX_use_PrivateKey_file(ctx, callbacks->keyPemFile,
  8023. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8024. goto cleanup;
  8025. }
  8026. }
  8027. #ifdef HAVE_CRL
  8028. if (callbacks->crlPemFile != NULL) {
  8029. if (wolfSSL_CTX_LoadCRLFile(ctx, callbacks->crlPemFile,
  8030. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8031. goto cleanup;
  8032. }
  8033. }
  8034. #endif
  8035. if (callbacks->ctx_ready)
  8036. callbacks->ctx_ready(ctx);
  8037. ssl = wolfSSL_new(ctx);
  8038. if (wolfSSL_dtls(ssl)) {
  8039. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port,
  8040. 1, 0, ssl);
  8041. }
  8042. else {
  8043. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port,
  8044. 0, 0, ssl);
  8045. }
  8046. if (wolfSSL_set_fd(ssl, sfd) != WOLFSSL_SUCCESS) {
  8047. goto cleanup;
  8048. }
  8049. if (callbacks->loadToSSL) {
  8050. wolfSSL_SetDevId(ssl, callbacks->devId);
  8051. if (wolfSSL_use_certificate_file(ssl, callbacks->certPemFile,
  8052. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8053. goto cleanup;
  8054. }
  8055. if (wolfSSL_use_PrivateKey_file(ssl, callbacks->keyPemFile,
  8056. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8057. goto cleanup;
  8058. }
  8059. }
  8060. if (callbacks->ssl_ready)
  8061. callbacks->ssl_ready(ssl);
  8062. #ifdef WOLFSSL_ASYNC_CRYPT
  8063. err = 0; /* Reset error */
  8064. #endif
  8065. do {
  8066. #ifdef WOLFSSL_ASYNC_CRYPT
  8067. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8068. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  8069. if (ret < 0) { break; } else if (ret == 0) { continue; }
  8070. }
  8071. #endif
  8072. ret = wolfSSL_connect(ssl);
  8073. err = wolfSSL_get_error(ssl, ret);
  8074. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  8075. if (ret != WOLFSSL_SUCCESS) {
  8076. char buff[WOLFSSL_MAX_ERROR_SZ];
  8077. fprintf(stderr, "error = %d, %s\n", err,
  8078. wolfSSL_ERR_error_string((word32)err, buff));
  8079. /*err_sys("SSL_connect failed");*/
  8080. }
  8081. else {
  8082. #ifdef WOLFSSL_ASYNC_CRYPT
  8083. err = 0; /* Reset error */
  8084. #endif
  8085. do {
  8086. #ifdef WOLFSSL_ASYNC_CRYPT
  8087. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8088. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  8089. if (ret < 0) { break; } else if (ret == 0) { continue; }
  8090. }
  8091. #endif
  8092. ret = wolfSSL_write(ssl, msg, len);
  8093. err = wolfSSL_get_error(ssl, ret);
  8094. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  8095. if (len != ret)
  8096. goto cleanup;
  8097. #ifdef WOLFSSL_ASYNC_CRYPT
  8098. err = 0; /* Reset error */
  8099. #endif
  8100. do {
  8101. #ifdef WOLFSSL_ASYNC_CRYPT
  8102. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8103. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  8104. if (ret < 0) { break; } else if (ret == 0) { continue; }
  8105. }
  8106. #endif
  8107. ret = wolfSSL_read(ssl, input, sizeof(input)-1);
  8108. err = wolfSSL_get_error(ssl, ret);
  8109. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  8110. if (ret > 0) {
  8111. input[ret] = '\0'; /* null term */
  8112. fprintf(stderr, "Server response: %s\n", input);
  8113. }
  8114. ((func_args*)args)->return_code = TEST_SUCCESS;
  8115. }
  8116. if (callbacks->on_result)
  8117. callbacks->on_result(ssl);
  8118. cleanup:
  8119. wolfSSL_free(ssl);
  8120. wolfSSL_CTX_free(ctx);
  8121. CloseSocket(sfd);
  8122. #ifdef WOLFSSL_TIRTOS
  8123. fdCloseSession(Task_self());
  8124. #endif
  8125. }
  8126. #endif /* ENABLE_TLS_CALLBACK_TEST */
  8127. static int test_wolfSSL_read_write(void)
  8128. {
  8129. /* The unit testing for read and write shall happen simultaneously, since
  8130. * one can't do anything with one without the other. (Except for a failure
  8131. * test case.) This function will call all the others that will set up,
  8132. * execute, and report their test findings.
  8133. *
  8134. * Set up the success case first. This function will become the template
  8135. * for the other tests. This should eventually be renamed
  8136. *
  8137. * The success case isn't interesting, how can this fail?
  8138. * - Do not give the client context a CA certificate. The connect should
  8139. * fail. Do not need server for this?
  8140. * - Using NULL for the ssl object on server. Do not need client for this.
  8141. * - Using NULL for the ssl object on client. Do not need server for this.
  8142. * - Good ssl objects for client and server. Client write() without server
  8143. * read().
  8144. * - Good ssl objects for client and server. Server write() without client
  8145. * read().
  8146. * - Forgetting the password callback?
  8147. */
  8148. tcp_ready ready;
  8149. func_args client_args;
  8150. func_args server_args;
  8151. THREAD_TYPE serverThread;
  8152. EXPECT_DECLS;
  8153. XMEMSET(&client_args, 0, sizeof(func_args));
  8154. XMEMSET(&server_args, 0, sizeof(func_args));
  8155. #ifdef WOLFSSL_TIRTOS
  8156. fdOpenSession(Task_self());
  8157. #endif
  8158. StartTCP();
  8159. InitTcpReady(&ready);
  8160. #if defined(USE_WINDOWS_API)
  8161. /* use RNG to get random port if using windows */
  8162. ready.port = GetRandomPort();
  8163. #endif
  8164. server_args.signal = &ready;
  8165. client_args.signal = &ready;
  8166. start_thread(test_server_nofail, &server_args, &serverThread);
  8167. wait_tcp_ready(&server_args);
  8168. test_client_nofail(&client_args, NULL);
  8169. join_thread(serverThread);
  8170. ExpectTrue(client_args.return_code);
  8171. ExpectTrue(server_args.return_code);
  8172. FreeTcpReady(&ready);
  8173. #ifdef WOLFSSL_TIRTOS
  8174. fdOpenSession(Task_self());
  8175. #endif
  8176. return EXPECT_RESULT();
  8177. }
  8178. static int test_wolfSSL_reuse_WOLFSSLobj(void)
  8179. {
  8180. EXPECT_DECLS;
  8181. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  8182. !defined(WOLFSSL_NO_TLS12)
  8183. /* The unit test for session resumption by re-using WOLFSSL object.
  8184. * WOLFSSL object is not cleared after first session. It reuse the object
  8185. * for second connection.
  8186. */
  8187. tcp_ready ready;
  8188. func_args client_args;
  8189. func_args server_args;
  8190. THREAD_TYPE serverThread;
  8191. callback_functions client_cbf;
  8192. callback_functions server_cbf;
  8193. XMEMSET(&client_args, 0, sizeof(func_args));
  8194. XMEMSET(&server_args, 0, sizeof(func_args));
  8195. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  8196. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  8197. #ifdef WOLFSSL_TIRTOS
  8198. fdOpenSession(Task_self());
  8199. #endif
  8200. StartTCP();
  8201. InitTcpReady(&ready);
  8202. #if defined(USE_WINDOWS_API)
  8203. /* use RNG to get random port if using windows */
  8204. ready.port = GetRandomPort();
  8205. #endif
  8206. client_cbf.method = wolfTLSv1_2_client_method;
  8207. server_cbf.method = wolfTLSv1_2_server_method;
  8208. client_args.callbacks = &client_cbf;
  8209. server_args.callbacks = &server_cbf;
  8210. server_args.signal = &ready;
  8211. client_args.signal = &ready;
  8212. /* the var is used for loop number */
  8213. server_args.argc = 2;
  8214. start_thread(test_server_loop, &server_args, &serverThread);
  8215. wait_tcp_ready(&server_args);
  8216. test_client_reuse_WOLFSSLobj(&client_args, NULL, &server_args);
  8217. join_thread(serverThread);
  8218. ExpectTrue(client_args.return_code);
  8219. ExpectTrue(server_args.return_code);
  8220. FreeTcpReady(&ready);
  8221. #ifdef WOLFSSL_TIRTOS
  8222. fdOpenSession(Task_self());
  8223. #endif
  8224. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) &&
  8225. * !defined(WOLFSSL_TLS13) */
  8226. return EXPECT_RESULT();
  8227. }
  8228. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8229. static int test_wolfSSL_CTX_verifyDepth_ServerClient_1_ctx_ready(
  8230. WOLFSSL_CTX* ctx)
  8231. {
  8232. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8233. myVerifyAction = VERIFY_USE_PREVERFIY;
  8234. wolfSSL_CTX_set_verify_depth(ctx, 2);
  8235. return TEST_SUCCESS;
  8236. }
  8237. #endif
  8238. static int test_wolfSSL_CTX_verifyDepth_ServerClient_1(void)
  8239. {
  8240. EXPECT_DECLS;
  8241. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8242. test_ssl_cbf client_cbf;
  8243. test_ssl_cbf server_cbf;
  8244. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8245. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8246. #ifdef WOLFSSL_TLS13
  8247. client_cbf.method = wolfTLSv1_3_client_method;
  8248. #endif /* WOLFSSL_TLS13 */
  8249. client_cbf.ctx_ready =
  8250. test_wolfSSL_CTX_verifyDepth_ServerClient_1_ctx_ready;
  8251. /* test case 1 verify depth is equal to peer chain */
  8252. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8253. &server_cbf, NULL), TEST_SUCCESS);
  8254. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8255. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8256. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8257. return EXPECT_RESULT();
  8258. }
  8259. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8260. static int test_wolfSSL_CTX_verifyDepth_ServerClient_2_ctx_ready(
  8261. WOLFSSL_CTX* ctx)
  8262. {
  8263. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8264. myVerifyAction = VERIFY_OVERRIDE_ERROR;
  8265. wolfSSL_CTX_set_verify_depth(ctx, 0);
  8266. return TEST_SUCCESS;
  8267. }
  8268. #endif
  8269. static int test_wolfSSL_CTX_verifyDepth_ServerClient_2(void)
  8270. {
  8271. EXPECT_DECLS;
  8272. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8273. test_ssl_cbf client_cbf;
  8274. test_ssl_cbf server_cbf;
  8275. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8276. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8277. #ifdef WOLFSSL_TLS13
  8278. client_cbf.method = wolfTLSv1_3_client_method;
  8279. #endif /* WOLFSSL_TLS13 */
  8280. client_cbf.ctx_ready =
  8281. test_wolfSSL_CTX_verifyDepth_ServerClient_2_ctx_ready;
  8282. /* test case 2
  8283. * verify depth is zero, number of peer's chain is 2.
  8284. * verify result becomes MAX_CHAIN_ERROR, but it is overridden in
  8285. * callback.
  8286. */
  8287. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8288. &server_cbf, NULL), TEST_SUCCESS);
  8289. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8290. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8291. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8292. return EXPECT_RESULT();
  8293. }
  8294. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8295. static int test_wolfSSL_CTX_verifyDepth_ServerClient_3_ctx_ready(
  8296. WOLFSSL_CTX* ctx)
  8297. {
  8298. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8299. myVerifyAction = VERIFY_USE_PREVERFIY;
  8300. wolfSSL_CTX_set_verify_depth(ctx, 0);
  8301. return TEST_SUCCESS;
  8302. }
  8303. #endif
  8304. static int test_wolfSSL_CTX_verifyDepth_ServerClient_3(void)
  8305. {
  8306. EXPECT_DECLS;
  8307. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8308. test_ssl_cbf client_cbf;
  8309. test_ssl_cbf server_cbf;
  8310. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8311. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8312. #ifdef WOLFSSL_TLS13
  8313. client_cbf.method = wolfTLSv1_3_client_method;
  8314. #endif /* WOLFSSL_TLS13 */
  8315. client_cbf.ctx_ready =
  8316. test_wolfSSL_CTX_verifyDepth_ServerClient_3_ctx_ready;
  8317. /* test case 3
  8318. * verify depth is zero, number of peer's chain is 2
  8319. * verify result becomes MAX_CHAIN_ERRO. call-back returns failure.
  8320. * therefore, handshake becomes failure.
  8321. */
  8322. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8323. &server_cbf, NULL), -1001);
  8324. ExpectIntEQ(client_cbf.return_code, -1000);
  8325. ExpectIntEQ(server_cbf.return_code, -1000);
  8326. ExpectIntEQ(client_cbf.last_err, WC_NO_ERR_TRACE(MAX_CHAIN_ERROR));
  8327. ExpectIntEQ(server_cbf.last_err, WC_NO_ERR_TRACE(FATAL_ERROR));
  8328. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8329. return EXPECT_RESULT();
  8330. }
  8331. #if defined(OPENSSL_ALL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8332. !defined(WOLFSSL_NO_TLS12) && \
  8333. defined(HAVE_ECC) && !defined(NO_AES) && !defined(NO_SHA256)
  8334. static int test_wolfSSL_CTX_set_cipher_list_server_ctx_ready(WOLFSSL_CTX* ctx)
  8335. {
  8336. EXPECT_DECLS;
  8337. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "DEFAULT:!NULL"));
  8338. return EXPECT_RESULT();
  8339. }
  8340. static int test_wolfSSL_CTX_set_cipher_list_client_ctx_ready(WOLFSSL_CTX* ctx)
  8341. {
  8342. EXPECT_DECLS;
  8343. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256"));
  8344. return EXPECT_RESULT();
  8345. }
  8346. #endif
  8347. static int test_wolfSSL_CTX_set_cipher_list(void)
  8348. {
  8349. EXPECT_DECLS;
  8350. #if defined(OPENSSL_ALL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8351. defined(HAVE_ECC) && !defined(NO_AES) && !defined(NO_SHA256)
  8352. #if !defined(WOLFSSL_NO_TLS12)
  8353. WOLFSSL_CTX* ctxClient = NULL;
  8354. WOLFSSL* sslClient = NULL;
  8355. test_ssl_cbf client_cbf;
  8356. test_ssl_cbf server_cbf;
  8357. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8358. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8359. server_cbf.method = wolfTLSv1_2_server_method;
  8360. server_cbf.ctx_ready = test_wolfSSL_CTX_set_cipher_list_server_ctx_ready;
  8361. client_cbf.method = wolfTLSv1_2_client_method;
  8362. client_cbf.ctx_ready = test_wolfSSL_CTX_set_cipher_list_client_ctx_ready;
  8363. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8364. &server_cbf, NULL), TEST_SUCCESS);
  8365. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8366. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8367. /* check with cipher string that has '+' */
  8368. ExpectNotNull((ctxClient = wolfSSL_CTX_new(wolfTLSv1_2_client_method())));
  8369. /* Use trailing : with nothing to test for ASAN */
  8370. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctxClient, "ECDHE+AESGCM:"));
  8371. ExpectNotNull((sslClient = wolfSSL_new(ctxClient)));
  8372. /* check for the existence of an ECDHE ECDSA cipher suite */
  8373. if (EXPECT_SUCCESS()) {
  8374. int i = 0;
  8375. int found = 0;
  8376. const char* suite;
  8377. WOLF_STACK_OF(WOLFSSL_CIPHER)* sk = NULL;
  8378. WOLFSSL_CIPHER* current;
  8379. ExpectNotNull((sk = wolfSSL_get_ciphers_compat(sslClient)));
  8380. do {
  8381. current = wolfSSL_sk_SSL_CIPHER_value(sk, i++);
  8382. if (current) {
  8383. suite = wolfSSL_CIPHER_get_name(current);
  8384. if (suite && XSTRSTR(suite, "ECDSA")) {
  8385. found = 1;
  8386. break;
  8387. }
  8388. }
  8389. } while (current);
  8390. ExpectIntEQ(found, 1);
  8391. }
  8392. wolfSSL_free(sslClient);
  8393. wolfSSL_CTX_free(ctxClient);
  8394. #endif /* !WOLFSSL_NO_TLS12 */
  8395. #endif
  8396. return EXPECT_RESULT();
  8397. }
  8398. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8399. defined(WOLFSSL_HAVE_TLS_UNIQUE)
  8400. static int test_wolfSSL_get_finished_client_on_handshake(WOLFSSL_CTX* ctx,
  8401. WOLFSSL* ssl)
  8402. {
  8403. EXPECT_DECLS;
  8404. size_t msg_len;
  8405. (void)ctx;
  8406. /* get_finished test */
  8407. /* 1. get own sent message */
  8408. XMEMSET(client_side_msg1, 0, MD_MAX_SIZE);
  8409. msg_len = wolfSSL_get_finished(ssl, client_side_msg1, MD_MAX_SIZE);
  8410. ExpectIntGE(msg_len, 0);
  8411. /* 2. get peer message */
  8412. XMEMSET(client_side_msg2, 0, MD_MAX_SIZE);
  8413. msg_len = wolfSSL_get_peer_finished(ssl, client_side_msg2, MD_MAX_SIZE);
  8414. ExpectIntGE(msg_len, 0);
  8415. return EXPECT_RESULT();
  8416. }
  8417. #endif
  8418. static int test_wolfSSL_get_finished(void)
  8419. {
  8420. EXPECT_DECLS;
  8421. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8422. defined(WOLFSSL_HAVE_TLS_UNIQUE)
  8423. test_ssl_cbf client_cbf;
  8424. test_ssl_cbf server_cbf;
  8425. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8426. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8427. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8428. &server_cbf, test_wolfSSL_get_finished_client_on_handshake),
  8429. TEST_SUCCESS);
  8430. /* test received msg vs sent msg */
  8431. ExpectIntEQ(0, XMEMCMP(client_side_msg1, server_side_msg2, MD_MAX_SIZE));
  8432. ExpectIntEQ(0, XMEMCMP(client_side_msg2, server_side_msg1, MD_MAX_SIZE));
  8433. #endif /* HAVE_SSL_MEMIO_TESTS_DEPENDENCIES && WOLFSSL_HAVE_TLS_UNIQUE */
  8434. return EXPECT_RESULT();
  8435. }
  8436. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8437. !defined(SINGLE_THREADED) && defined(WOLFSSL_TLS13) && \
  8438. !defined(NO_SESSION_CACHE)
  8439. /* Sessions to restore/store */
  8440. static WOLFSSL_SESSION* test_wolfSSL_CTX_add_session_client_sess;
  8441. static WOLFSSL_SESSION* test_wolfSSL_CTX_add_session_server_sess;
  8442. static WOLFSSL_CTX* test_wolfSSL_CTX_add_session_server_ctx;
  8443. static void test_wolfSSL_CTX_add_session_ctx_ready(WOLFSSL_CTX* ctx)
  8444. {
  8445. /* Don't store sessions. Lookup is still enabled. */
  8446. AssertIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8447. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8448. #ifdef OPENSSL_EXTRA
  8449. AssertIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8450. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8451. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8452. #endif
  8453. /* Require both peers to provide certs */
  8454. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8455. }
  8456. static void test_wolfSSL_CTX_add_session_on_result(WOLFSSL* ssl)
  8457. {
  8458. WOLFSSL_SESSION** sess;
  8459. if (wolfSSL_is_server(ssl))
  8460. sess = &test_wolfSSL_CTX_add_session_server_sess;
  8461. else
  8462. sess = &test_wolfSSL_CTX_add_session_client_sess;
  8463. if (*sess == NULL) {
  8464. #ifdef NO_SESSION_CACHE_REF
  8465. AssertNotNull(*sess = wolfSSL_get1_session(ssl));
  8466. #else
  8467. /* Test for backwards compatibility */
  8468. if (wolfSSL_is_server(ssl)) {
  8469. AssertNotNull(*sess = wolfSSL_get1_session(ssl));
  8470. }
  8471. else {
  8472. AssertNotNull(*sess = wolfSSL_get_session(ssl));
  8473. }
  8474. #endif
  8475. /* Now save the session in the internal store to make it available
  8476. * for lookup. For TLS 1.3, we can't save the session without
  8477. * WOLFSSL_TICKET_HAVE_ID because there is no way to retrieve the
  8478. * session from cache. */
  8479. if (wolfSSL_is_server(ssl)
  8480. #ifndef WOLFSSL_TICKET_HAVE_ID
  8481. && wolfSSL_version(ssl) != TLS1_3_VERSION
  8482. #endif
  8483. )
  8484. AssertIntEQ(wolfSSL_CTX_add_session(wolfSSL_get_SSL_CTX(ssl),
  8485. *sess), WOLFSSL_SUCCESS);
  8486. }
  8487. else {
  8488. /* If we have a session retrieved then remaining connections should be
  8489. * resuming on that session */
  8490. AssertIntEQ(wolfSSL_session_reused(ssl), 1);
  8491. }
  8492. /* Save CTX to be able to decrypt tickets */
  8493. if (wolfSSL_is_server(ssl) &&
  8494. test_wolfSSL_CTX_add_session_server_ctx == NULL) {
  8495. AssertNotNull(test_wolfSSL_CTX_add_session_server_ctx
  8496. = wolfSSL_get_SSL_CTX(ssl));
  8497. AssertIntEQ(wolfSSL_CTX_up_ref(wolfSSL_get_SSL_CTX(ssl)),
  8498. WOLFSSL_SUCCESS);
  8499. }
  8500. #ifdef SESSION_CERTS
  8501. #ifndef WOLFSSL_TICKET_HAVE_ID
  8502. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8503. wolfSSL_session_reused(ssl))
  8504. #endif
  8505. {
  8506. /* With WOLFSSL_TICKET_HAVE_ID the peer certs should be available
  8507. * for all connections. TLS 1.3 only has tickets so if we don't
  8508. * include the session id in the ticket then the certificates
  8509. * will not be available on resumption. */
  8510. WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl);
  8511. AssertNotNull(peer);
  8512. wolfSSL_X509_free(peer);
  8513. AssertNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8514. #ifdef OPENSSL_EXTRA
  8515. AssertNotNull(SSL_SESSION_get0_peer(*sess));
  8516. #endif
  8517. }
  8518. #endif /* SESSION_CERTS */
  8519. }
  8520. static void test_wolfSSL_CTX_add_session_ssl_ready(WOLFSSL* ssl)
  8521. {
  8522. /* Set the session to reuse for the client */
  8523. AssertIntEQ(wolfSSL_set_session(ssl,
  8524. test_wolfSSL_CTX_add_session_client_sess), WOLFSSL_SUCCESS);
  8525. }
  8526. #endif
  8527. static int test_wolfSSL_CTX_add_session(void)
  8528. {
  8529. EXPECT_DECLS;
  8530. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8531. !defined(SINGLE_THREADED) && defined(WOLFSSL_TLS13) && \
  8532. !defined(NO_SESSION_CACHE)
  8533. tcp_ready ready;
  8534. func_args client_args;
  8535. func_args server_args;
  8536. THREAD_TYPE serverThread;
  8537. callback_functions client_cb;
  8538. callback_functions server_cb;
  8539. method_provider methods[][2] = {
  8540. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  8541. !defined(NO_DES3))
  8542. /* Without AES there are almost no ciphersuites available. This leads
  8543. * to no ciphersuites being available and an error. */
  8544. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method },
  8545. #endif
  8546. #ifndef WOLFSSL_NO_TLS12
  8547. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method },
  8548. #endif
  8549. /* Needs the default ticket callback since it is tied to the
  8550. * connection context and this makes it easy to carry over the ticket
  8551. * crypto context between connections */
  8552. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  8553. defined(HAVE_SESSION_TICKET)
  8554. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method },
  8555. #endif
  8556. };
  8557. const size_t methodsLen = sizeof(methods)/sizeof(*methods);
  8558. size_t i, j;
  8559. for (i = 0; i < methodsLen; i++) {
  8560. /* First run creates a connection while the second+ run will attempt
  8561. * to resume the connection. The trick is that the internal cache
  8562. * is turned off. wolfSSL_CTX_add_session should put the session in
  8563. * the cache anyway. */
  8564. test_wolfSSL_CTX_add_session_client_sess = NULL;
  8565. test_wolfSSL_CTX_add_session_server_sess = NULL;
  8566. test_wolfSSL_CTX_add_session_server_ctx = NULL;
  8567. #ifdef NO_SESSION_CACHE_REF
  8568. for (j = 0; j < 4; j++) {
  8569. #else
  8570. /* The session may be overwritten in this case. Do only one resumption
  8571. * to stop this test from failing intermittently. */
  8572. for (j = 0; j < 2; j++) {
  8573. #endif
  8574. #ifdef WOLFSSL_TIRTOS
  8575. fdOpenSession(Task_self());
  8576. #endif
  8577. StartTCP();
  8578. InitTcpReady(&ready);
  8579. XMEMSET(&client_args, 0, sizeof(func_args));
  8580. XMEMSET(&server_args, 0, sizeof(func_args));
  8581. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  8582. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  8583. client_cb.method = methods[i][0];
  8584. server_cb.method = methods[i][1];
  8585. server_args.signal = &ready;
  8586. server_args.callbacks = &server_cb;
  8587. client_args.signal = &ready;
  8588. client_args.callbacks = &client_cb;
  8589. if (test_wolfSSL_CTX_add_session_server_ctx != NULL) {
  8590. server_cb.ctx = test_wolfSSL_CTX_add_session_server_ctx;
  8591. server_cb.isSharedCtx = 1;
  8592. }
  8593. server_cb.ctx_ready = test_wolfSSL_CTX_add_session_ctx_ready;
  8594. client_cb.ctx_ready = test_wolfSSL_CTX_add_session_ctx_ready;
  8595. if (j != 0)
  8596. client_cb.ssl_ready = test_wolfSSL_CTX_add_session_ssl_ready;
  8597. server_cb.on_result = test_wolfSSL_CTX_add_session_on_result;
  8598. client_cb.on_result = test_wolfSSL_CTX_add_session_on_result;
  8599. server_cb.ticNoInit = 1; /* Use default builtin */
  8600. start_thread(test_server_nofail, &server_args, &serverThread);
  8601. wait_tcp_ready(&server_args);
  8602. test_client_nofail(&client_args, NULL);
  8603. join_thread(serverThread);
  8604. ExpectTrue(client_args.return_code);
  8605. ExpectTrue(server_args.return_code);
  8606. FreeTcpReady(&ready);
  8607. if (EXPECT_FAIL())
  8608. break;
  8609. }
  8610. wolfSSL_SESSION_free(test_wolfSSL_CTX_add_session_client_sess);
  8611. wolfSSL_SESSION_free(test_wolfSSL_CTX_add_session_server_sess);
  8612. wolfSSL_CTX_free(test_wolfSSL_CTX_add_session_server_ctx);
  8613. if (EXPECT_FAIL())
  8614. break;
  8615. }
  8616. #endif
  8617. return EXPECT_RESULT();
  8618. }
  8619. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8620. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  8621. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  8622. defined(HAVE_SESSION_TICKET) && \
  8623. !defined(TITAN_SESSION_CACHE) && \
  8624. !defined(HUGE_SESSION_CACHE) && \
  8625. !defined(BIG_SESSION_CACHE) && \
  8626. !defined(MEDIUM_SESSION_CACHE)
  8627. /* twcase - prefix for test_wolfSSL_CTX_add_session_ext */
  8628. /* Sessions to restore/store */
  8629. static WOLFSSL_SESSION* twcase_server_first_session_ptr;
  8630. static WOLFSSL_SESSION* twcase_client_first_session_ptr;
  8631. static WOLFSSL_CTX* twcase_server_current_ctx_ptr;
  8632. static int twcase_new_session_called = 0;
  8633. static int twcase_remove_session_called = 0;
  8634. static int twcase_get_session_called = 0;
  8635. /* Test default, SESSIONS_PER_ROW*SESSION_ROWS = 3*11, see ssl.c */
  8636. #define SESSION_CACHE_SIZE 33
  8637. typedef struct {
  8638. const byte* key; /* key, altSessionID, session ID, NULL if empty */
  8639. WOLFSSL_SESSION* value;
  8640. } hashTable_entry;
  8641. typedef struct {
  8642. hashTable_entry entries[SESSION_CACHE_SIZE]; /* hash slots */
  8643. size_t capacity; /* size of entries */
  8644. size_t length; /* number of items in the hash table */
  8645. wolfSSL_Mutex htLock; /* lock */
  8646. }hashTable;
  8647. static hashTable server_sessionCache;
  8648. static int twcase_new_sessionCb(WOLFSSL *ssl, WOLFSSL_SESSION *sess)
  8649. {
  8650. int i;
  8651. unsigned int len;
  8652. (void)ssl;
  8653. /*
  8654. * This example uses a hash table.
  8655. * Steps you should take for a non-demo code:
  8656. * - acquire a lock for the file named according to the session id
  8657. * - open the file
  8658. * - encrypt and write the SSL_SESSION object to the file
  8659. * - release the lock
  8660. *
  8661. * Return:
  8662. * 0: The callback does not wish to hold a reference of the sess
  8663. * 1: The callback wants to hold a reference of the sess. The callback is
  8664. * now also responsible for calling wolfSSL_SESSION_free() on sess.
  8665. */
  8666. if (sess == NULL)
  8667. return 0;
  8668. if (wc_LockMutex(&server_sessionCache.htLock) != 0) {
  8669. return 0;
  8670. }
  8671. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8672. if (server_sessionCache.entries[i].value == NULL) {
  8673. server_sessionCache.entries[i].key = SSL_SESSION_get_id(sess, &len);
  8674. server_sessionCache.entries[i].value = sess;
  8675. server_sessionCache.length++;
  8676. break;
  8677. }
  8678. }
  8679. ++twcase_new_session_called;
  8680. wc_UnLockMutex(&server_sessionCache.htLock);
  8681. fprintf(stderr, "\t\ttwcase_new_session_called %d\n",
  8682. twcase_new_session_called);
  8683. return 1;
  8684. }
  8685. static void twcase_remove_sessionCb(WOLFSSL_CTX *ctx, WOLFSSL_SESSION *sess)
  8686. {
  8687. int i;
  8688. (void)ctx;
  8689. (void)sess;
  8690. if (sess == NULL)
  8691. return;
  8692. /*
  8693. * This example uses a hash table.
  8694. * Steps you should take for a non-demo code:
  8695. * - acquire a lock for the file named according to the session id
  8696. * - remove the file
  8697. * - release the lock
  8698. */
  8699. if (wc_LockMutex(&server_sessionCache.htLock) != 0) {
  8700. return;
  8701. }
  8702. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8703. if (server_sessionCache.entries[i].key != NULL &&
  8704. XMEMCMP(server_sessionCache.entries[i].key,
  8705. sess->sessionID, SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) {
  8706. wolfSSL_SESSION_free(server_sessionCache.entries[i].value);
  8707. server_sessionCache.entries[i].value = NULL;
  8708. server_sessionCache.entries[i].key = NULL;
  8709. server_sessionCache.length--;
  8710. break;
  8711. }
  8712. }
  8713. ++twcase_remove_session_called;
  8714. wc_UnLockMutex(&server_sessionCache.htLock);
  8715. fprintf(stderr, "\t\ttwcase_remove_session_called %d\n",
  8716. twcase_remove_session_called);
  8717. }
  8718. static WOLFSSL_SESSION *twcase_get_sessionCb(WOLFSSL *ssl,
  8719. const unsigned char *id, int len, int *ref)
  8720. {
  8721. int i;
  8722. (void)ssl;
  8723. (void)id;
  8724. (void)len;
  8725. /*
  8726. * This example uses a hash table.
  8727. * Steps you should take for a non-demo code:
  8728. * - acquire a lock for the file named according to the session id in the
  8729. * 2nd arg
  8730. * - read and decrypt contents of file and create a new SSL_SESSION
  8731. * - object release the lock
  8732. * - return the new session object
  8733. */
  8734. fprintf(stderr, "\t\ttwcase_get_session_called %d\n",
  8735. ++twcase_get_session_called);
  8736. /* This callback want to retain a copy of the object. If we want wolfSSL to
  8737. * be responsible for the pointer then set to 0. */
  8738. *ref = 1;
  8739. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8740. if (server_sessionCache.entries[i].key != NULL &&
  8741. XMEMCMP(server_sessionCache.entries[i].key, id,
  8742. SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) {
  8743. return server_sessionCache.entries[i].value;
  8744. }
  8745. }
  8746. return NULL;
  8747. }
  8748. static int twcase_get_sessionCb_cleanup(void)
  8749. {
  8750. int i;
  8751. int cnt = 0;
  8752. /* If twcase_get_sessionCb sets *ref = 1, the application is responsible
  8753. * for freeing sessions */
  8754. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8755. if (server_sessionCache.entries[i].value != NULL) {
  8756. wolfSSL_SESSION_free(server_sessionCache.entries[i].value);
  8757. cnt++;
  8758. }
  8759. }
  8760. fprintf(stderr, "\t\ttwcase_get_sessionCb_cleanup freed %d sessions\n",
  8761. cnt);
  8762. return TEST_SUCCESS;
  8763. }
  8764. static int twcase_cache_intOff_extOff(WOLFSSL_CTX* ctx)
  8765. {
  8766. EXPECT_DECLS;
  8767. /* off - Disable internal cache */
  8768. ExpectIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8769. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8770. #ifdef OPENSSL_EXTRA
  8771. ExpectIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8772. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8773. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8774. #endif
  8775. /* off - Do not setup external cache */
  8776. /* Require both peers to provide certs */
  8777. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8778. return EXPECT_RESULT();
  8779. }
  8780. static int twcase_cache_intOn_extOff(WOLFSSL_CTX* ctx)
  8781. {
  8782. /* on - internal cache is on by default */
  8783. /* off - Do not setup external cache */
  8784. /* Require both peers to provide certs */
  8785. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8786. return TEST_SUCCESS;
  8787. }
  8788. static int twcase_cache_intOff_extOn(WOLFSSL_CTX* ctx)
  8789. {
  8790. EXPECT_DECLS;
  8791. /* off - Disable internal cache */
  8792. ExpectIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8793. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8794. #ifdef OPENSSL_EXTRA
  8795. ExpectIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8796. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8797. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8798. #endif
  8799. /* on - Enable external cache */
  8800. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8801. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8802. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8803. /* Require both peers to provide certs */
  8804. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8805. return EXPECT_RESULT();
  8806. }
  8807. static int twcase_cache_intOn_extOn(WOLFSSL_CTX* ctx)
  8808. {
  8809. /* on - internal cache is on by default */
  8810. /* on - Enable external cache */
  8811. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8812. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8813. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8814. /* Require both peers to provide certs */
  8815. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8816. return TEST_SUCCESS;
  8817. }
  8818. static int twcase_cache_intOn_extOn_noTicket(WOLFSSL_CTX* ctx)
  8819. {
  8820. /* on - internal cache is on by default */
  8821. /* on - Enable external cache */
  8822. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8823. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8824. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8825. wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TICKET);
  8826. /* Require both peers to provide certs */
  8827. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8828. return TEST_SUCCESS;
  8829. }
  8830. static int twcase_server_sess_ctx_pre_shutdown(WOLFSSL* ssl)
  8831. {
  8832. EXPECT_DECLS;
  8833. WOLFSSL_SESSION** sess;
  8834. if (wolfSSL_is_server(ssl))
  8835. sess = &twcase_server_first_session_ptr;
  8836. else
  8837. return TEST_SUCCESS;
  8838. if (*sess == NULL) {
  8839. ExpectNotNull(*sess = wolfSSL_get1_session(ssl));
  8840. /* Now save the session in the internal store to make it available
  8841. * for lookup. For TLS 1.3, we can't save the session without
  8842. * WOLFSSL_TICKET_HAVE_ID because there is no way to retrieve the
  8843. * session from cache. */
  8844. if (wolfSSL_is_server(ssl)
  8845. #ifndef WOLFSSL_TICKET_HAVE_ID
  8846. && wolfSSL_version(ssl) != TLS1_3_VERSION
  8847. && wolfSSL_version(ssl) != DTLS1_3_VERSION
  8848. #endif
  8849. ) {
  8850. ExpectIntEQ(wolfSSL_CTX_add_session(wolfSSL_get_SSL_CTX(ssl),
  8851. *sess), WOLFSSL_SUCCESS);
  8852. }
  8853. }
  8854. /* Save CTX to be able to decrypt tickets */
  8855. if (twcase_server_current_ctx_ptr == NULL) {
  8856. ExpectNotNull(twcase_server_current_ctx_ptr = wolfSSL_get_SSL_CTX(ssl));
  8857. ExpectIntEQ(wolfSSL_CTX_up_ref(wolfSSL_get_SSL_CTX(ssl)),
  8858. WOLFSSL_SUCCESS);
  8859. }
  8860. #ifdef SESSION_CERTS
  8861. #ifndef WOLFSSL_TICKET_HAVE_ID
  8862. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8863. wolfSSL_session_reused(ssl))
  8864. #endif
  8865. {
  8866. /* With WOLFSSL_TICKET_HAVE_ID the peer certs should be available
  8867. * for all connections. TLS 1.3 only has tickets so if we don't
  8868. * include the session id in the ticket then the certificates
  8869. * will not be available on resumption. */
  8870. WOLFSSL_X509* peer = NULL;
  8871. ExpectNotNull(peer = wolfSSL_get_peer_certificate(ssl));
  8872. wolfSSL_X509_free(peer);
  8873. ExpectNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8874. }
  8875. #endif
  8876. return EXPECT_RESULT();
  8877. }
  8878. static int twcase_client_sess_ctx_pre_shutdown(WOLFSSL* ssl)
  8879. {
  8880. EXPECT_DECLS;
  8881. WOLFSSL_SESSION** sess;
  8882. sess = &twcase_client_first_session_ptr;
  8883. if (*sess == NULL) {
  8884. ExpectNotNull(*sess = wolfSSL_get1_session(ssl));
  8885. }
  8886. else {
  8887. /* If we have a session retrieved then remaining connections should be
  8888. * resuming on that session */
  8889. ExpectIntEQ(wolfSSL_session_reused(ssl), 1);
  8890. }
  8891. #ifdef SESSION_CERTS
  8892. #ifndef WOLFSSL_TICKET_HAVE_ID
  8893. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8894. wolfSSL_session_reused(ssl))
  8895. #endif
  8896. {
  8897. WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl);
  8898. ExpectNotNull(peer);
  8899. wolfSSL_X509_free(peer);
  8900. ExpectNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8901. #ifdef OPENSSL_EXTRA
  8902. ExpectNotNull(wolfSSL_SESSION_get0_peer(*sess));
  8903. #endif
  8904. }
  8905. #endif
  8906. return EXPECT_RESULT();
  8907. }
  8908. static int twcase_client_set_sess_ssl_ready(WOLFSSL* ssl)
  8909. {
  8910. EXPECT_DECLS;
  8911. /* Set the session to reuse for the client */
  8912. ExpectNotNull(ssl);
  8913. ExpectNotNull(twcase_client_first_session_ptr);
  8914. ExpectIntEQ(wolfSSL_set_session(ssl,twcase_client_first_session_ptr),
  8915. WOLFSSL_SUCCESS);
  8916. return EXPECT_RESULT();
  8917. }
  8918. struct test_add_session_ext_params {
  8919. method_provider client_meth;
  8920. method_provider server_meth;
  8921. const char* tls_version;
  8922. };
  8923. static int test_wolfSSL_CTX_add_session_ext(
  8924. struct test_add_session_ext_params* param)
  8925. {
  8926. EXPECT_DECLS;
  8927. /* Test the default 33 sessions */
  8928. int j;
  8929. /* Clear cache before starting */
  8930. wolfSSL_CTX_flush_sessions(NULL, -1);
  8931. XMEMSET(&server_sessionCache, 0, sizeof(hashTable));
  8932. if (wc_InitMutex(&server_sessionCache.htLock) != 0)
  8933. return BAD_MUTEX_E;
  8934. server_sessionCache.capacity = SESSION_CACHE_SIZE;
  8935. fprintf(stderr, "\tBegin %s\n", param->tls_version);
  8936. for (j = 0; j < 5; j++) {
  8937. int tls13 = XSTRSTR(param->tls_version, "TLSv1_3") != NULL;
  8938. int dtls = XSTRSTR(param->tls_version, "DTLS") != NULL;
  8939. test_ssl_cbf client_cb;
  8940. test_ssl_cbf server_cb;
  8941. (void)dtls;
  8942. /* Test five cache configurations */
  8943. twcase_client_first_session_ptr = NULL;
  8944. twcase_server_first_session_ptr = NULL;
  8945. twcase_server_current_ctx_ptr = NULL;
  8946. twcase_new_session_called = 0;
  8947. twcase_remove_session_called = 0;
  8948. twcase_get_session_called = 0;
  8949. /* connection 1 - first connection */
  8950. fprintf(stderr, "\tconnect: %s: j=%d\n", param->tls_version, j);
  8951. XMEMSET(&client_cb, 0, sizeof(client_cb));
  8952. XMEMSET(&server_cb, 0, sizeof(server_cb));
  8953. client_cb.method = param->client_meth;
  8954. server_cb.method = param->server_meth;
  8955. if (dtls)
  8956. client_cb.doUdp = server_cb.doUdp = 1;
  8957. /* Setup internal and external cache */
  8958. switch (j) {
  8959. case 0:
  8960. /* SSL_OP_NO_TICKET stateful ticket case */
  8961. server_cb.ctx_ready = twcase_cache_intOn_extOn_noTicket;
  8962. break;
  8963. case 1:
  8964. server_cb.ctx_ready = twcase_cache_intOn_extOn;
  8965. break;
  8966. case 2:
  8967. server_cb.ctx_ready = twcase_cache_intOff_extOn;
  8968. break;
  8969. case 3:
  8970. server_cb.ctx_ready = twcase_cache_intOn_extOff;
  8971. break;
  8972. case 4:
  8973. server_cb.ctx_ready = twcase_cache_intOff_extOff;
  8974. break;
  8975. }
  8976. client_cb.ctx_ready = twcase_cache_intOff_extOff;
  8977. /* Add session to internal cache and save SSL session for testing */
  8978. server_cb.on_result = twcase_server_sess_ctx_pre_shutdown;
  8979. /* Save client SSL session for testing */
  8980. client_cb.on_result = twcase_client_sess_ctx_pre_shutdown;
  8981. server_cb.ticNoInit = 1; /* Use default builtin */
  8982. /* Don't free/release ctx */
  8983. server_cb.ctx = twcase_server_current_ctx_ptr;
  8984. server_cb.isSharedCtx = 1;
  8985. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  8986. &server_cb, NULL), TEST_SUCCESS);
  8987. ExpectIntEQ(twcase_get_session_called, 0);
  8988. if (EXPECT_FAIL()) {
  8989. wolfSSL_SESSION_free(twcase_client_first_session_ptr);
  8990. wolfSSL_SESSION_free(twcase_server_first_session_ptr);
  8991. wolfSSL_CTX_free(twcase_server_current_ctx_ptr);
  8992. break;
  8993. }
  8994. switch (j) {
  8995. case 0:
  8996. case 1:
  8997. case 2:
  8998. /* cache cannot be searched with out a connection */
  8999. /* Add a new session */
  9000. ExpectIntEQ(twcase_new_session_called, 1);
  9001. /* In twcase_server_sess_ctx_pre_shutdown
  9002. * wolfSSL_CTX_add_session which evicts the existing session
  9003. * in cache and adds it back in */
  9004. ExpectIntLE(twcase_remove_session_called, 1);
  9005. break;
  9006. case 3:
  9007. case 4:
  9008. /* no external cache */
  9009. ExpectIntEQ(twcase_new_session_called, 0);
  9010. ExpectIntEQ(twcase_remove_session_called, 0);
  9011. break;
  9012. }
  9013. /* connection 2 - session resume */
  9014. fprintf(stderr, "\tresume: %s: j=%d\n", param->tls_version, j);
  9015. twcase_new_session_called = 0;
  9016. twcase_remove_session_called = 0;
  9017. twcase_get_session_called = 0;
  9018. server_cb.on_result = 0;
  9019. client_cb.on_result = 0;
  9020. server_cb.ticNoInit = 1; /* Use default builtin */
  9021. server_cb.ctx = twcase_server_current_ctx_ptr;
  9022. /* try session resumption */
  9023. client_cb.ssl_ready = twcase_client_set_sess_ssl_ready;
  9024. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  9025. &server_cb, NULL), TEST_SUCCESS);
  9026. /* Clear cache before checking */
  9027. wolfSSL_CTX_flush_sessions(NULL, -1);
  9028. switch (j) {
  9029. case 0:
  9030. if (tls13) {
  9031. /* (D)TLSv1.3 stateful case */
  9032. /* cache hit */
  9033. /* DTLS accesses cache once for stateless parsing and
  9034. * once for stateful parsing */
  9035. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  9036. /* (D)TLSv1.3 creates a new ticket,
  9037. * updates both internal and external cache */
  9038. ExpectIntEQ(twcase_new_session_called, 1);
  9039. /* A new session ID is created for a new ticket */
  9040. ExpectIntEQ(twcase_remove_session_called, 2);
  9041. }
  9042. else {
  9043. /* non (D)TLSv1.3 case, no update */
  9044. /* DTLS accesses cache once for stateless parsing and
  9045. * once for stateful parsing */
  9046. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  9047. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  9048. #else
  9049. ExpectIntEQ(twcase_get_session_called, 1);
  9050. #endif
  9051. ExpectIntEQ(twcase_new_session_called, 0);
  9052. /* Called on session added in
  9053. * twcase_server_sess_ctx_pre_shutdown */
  9054. ExpectIntEQ(twcase_remove_session_called, 1);
  9055. }
  9056. break;
  9057. case 1:
  9058. if (tls13) {
  9059. /* (D)TLSv1.3 case */
  9060. /* cache hit */
  9061. ExpectIntEQ(twcase_get_session_called, 1);
  9062. /* (D)TLSv1.3 creates a new ticket,
  9063. * updates both internal and external cache */
  9064. ExpectIntEQ(twcase_new_session_called, 1);
  9065. /* Called on session added in
  9066. * twcase_server_sess_ctx_pre_shutdown and by wolfSSL */
  9067. ExpectIntEQ(twcase_remove_session_called, 1);
  9068. }
  9069. else {
  9070. /* non (D)TLSv1.3 case */
  9071. /* cache hit */
  9072. /* DTLS accesses cache once for stateless parsing and
  9073. * once for stateful parsing */
  9074. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  9075. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  9076. #else
  9077. ExpectIntEQ(twcase_get_session_called, 1);
  9078. #endif
  9079. ExpectIntEQ(twcase_new_session_called, 0);
  9080. /* Called on session added in
  9081. * twcase_server_sess_ctx_pre_shutdown */
  9082. ExpectIntEQ(twcase_remove_session_called, 1);
  9083. }
  9084. break;
  9085. case 2:
  9086. if (tls13) {
  9087. /* (D)TLSv1.3 case */
  9088. /* cache hit */
  9089. ExpectIntEQ(twcase_get_session_called, 1);
  9090. /* (D)TLSv1.3 creates a new ticket,
  9091. * updates both internal and external cache */
  9092. ExpectIntEQ(twcase_new_session_called, 1);
  9093. /* Called on session added in
  9094. * twcase_server_sess_ctx_pre_shutdown and by wolfSSL */
  9095. ExpectIntEQ(twcase_remove_session_called, 1);
  9096. }
  9097. else {
  9098. /* non (D)TLSv1.3 case */
  9099. /* cache hit */
  9100. /* DTLS accesses cache once for stateless parsing and
  9101. * once for stateful parsing */
  9102. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  9103. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  9104. #else
  9105. ExpectIntEQ(twcase_get_session_called, 1);
  9106. #endif
  9107. ExpectIntEQ(twcase_new_session_called, 0);
  9108. /* Called on session added in
  9109. * twcase_server_sess_ctx_pre_shutdown */
  9110. ExpectIntEQ(twcase_remove_session_called, 1);
  9111. }
  9112. break;
  9113. case 3:
  9114. case 4:
  9115. /* no external cache */
  9116. ExpectIntEQ(twcase_get_session_called, 0);
  9117. ExpectIntEQ(twcase_new_session_called, 0);
  9118. ExpectIntEQ(twcase_remove_session_called, 0);
  9119. break;
  9120. }
  9121. wolfSSL_SESSION_free(twcase_client_first_session_ptr);
  9122. wolfSSL_SESSION_free(twcase_server_first_session_ptr);
  9123. wolfSSL_CTX_free(twcase_server_current_ctx_ptr);
  9124. if (EXPECT_FAIL())
  9125. break;
  9126. }
  9127. twcase_get_sessionCb_cleanup();
  9128. XMEMSET(&server_sessionCache.entries, 0,
  9129. sizeof(server_sessionCache.entries));
  9130. fprintf(stderr, "\tEnd %s\n", param->tls_version);
  9131. wc_FreeMutex(&server_sessionCache.htLock);
  9132. return EXPECT_RESULT();
  9133. }
  9134. #endif
  9135. static int test_wolfSSL_CTX_add_session_ext_tls13(void)
  9136. {
  9137. EXPECT_DECLS;
  9138. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9139. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9140. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9141. defined(HAVE_SESSION_TICKET) && \
  9142. !defined(TITAN_SESSION_CACHE) && \
  9143. !defined(HUGE_SESSION_CACHE) && \
  9144. !defined(BIG_SESSION_CACHE) && \
  9145. !defined(MEDIUM_SESSION_CACHE)
  9146. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  9147. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID)
  9148. struct test_add_session_ext_params param[1] = {
  9149. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" }
  9150. };
  9151. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9152. #endif
  9153. #endif
  9154. return EXPECT_RESULT();
  9155. }
  9156. static int test_wolfSSL_CTX_add_session_ext_dtls13(void)
  9157. {
  9158. EXPECT_DECLS;
  9159. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9160. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9161. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9162. defined(HAVE_SESSION_TICKET) && \
  9163. !defined(TITAN_SESSION_CACHE) && \
  9164. !defined(HUGE_SESSION_CACHE) && \
  9165. !defined(BIG_SESSION_CACHE) && \
  9166. !defined(MEDIUM_SESSION_CACHE)
  9167. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  9168. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID)
  9169. #ifdef WOLFSSL_DTLS13
  9170. struct test_add_session_ext_params param[1] = {
  9171. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" }
  9172. };
  9173. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9174. #endif
  9175. #endif
  9176. #endif
  9177. return EXPECT_RESULT();
  9178. }
  9179. static int test_wolfSSL_CTX_add_session_ext_tls12(void)
  9180. {
  9181. EXPECT_DECLS;
  9182. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9183. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9184. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9185. defined(HAVE_SESSION_TICKET) && \
  9186. !defined(TITAN_SESSION_CACHE) && \
  9187. !defined(HUGE_SESSION_CACHE) && \
  9188. !defined(BIG_SESSION_CACHE) && \
  9189. !defined(MEDIUM_SESSION_CACHE)
  9190. #ifndef WOLFSSL_NO_TLS12
  9191. struct test_add_session_ext_params param[1] = {
  9192. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" }
  9193. };
  9194. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9195. #endif
  9196. #endif
  9197. return EXPECT_RESULT();
  9198. }
  9199. static int test_wolfSSL_CTX_add_session_ext_dtls12(void)
  9200. {
  9201. EXPECT_DECLS;
  9202. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9203. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9204. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9205. defined(HAVE_SESSION_TICKET) && \
  9206. !defined(TITAN_SESSION_CACHE) && \
  9207. !defined(HUGE_SESSION_CACHE) && \
  9208. !defined(BIG_SESSION_CACHE) && \
  9209. !defined(MEDIUM_SESSION_CACHE)
  9210. #ifndef WOLFSSL_NO_TLS12
  9211. #ifdef WOLFSSL_DTLS
  9212. struct test_add_session_ext_params param[1] = {
  9213. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" }
  9214. };
  9215. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9216. #endif
  9217. #endif
  9218. #endif
  9219. return EXPECT_RESULT();
  9220. }
  9221. static int test_wolfSSL_CTX_add_session_ext_tls11(void)
  9222. {
  9223. EXPECT_DECLS;
  9224. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9225. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9226. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9227. defined(HAVE_SESSION_TICKET) && \
  9228. !defined(TITAN_SESSION_CACHE) && \
  9229. !defined(HUGE_SESSION_CACHE) && \
  9230. !defined(BIG_SESSION_CACHE) && \
  9231. !defined(MEDIUM_SESSION_CACHE)
  9232. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  9233. !defined(NO_DES3))
  9234. struct test_add_session_ext_params param[1] = {
  9235. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" }
  9236. };
  9237. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9238. #endif
  9239. #endif
  9240. return EXPECT_RESULT();
  9241. }
  9242. static int test_wolfSSL_CTX_add_session_ext_dtls1(void)
  9243. {
  9244. EXPECT_DECLS;
  9245. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9246. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9247. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9248. defined(HAVE_SESSION_TICKET) && \
  9249. !defined(TITAN_SESSION_CACHE) && \
  9250. !defined(HUGE_SESSION_CACHE) && \
  9251. !defined(BIG_SESSION_CACHE) && \
  9252. !defined(MEDIUM_SESSION_CACHE)
  9253. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  9254. !defined(NO_DES3))
  9255. #ifdef WOLFSSL_DTLS
  9256. struct test_add_session_ext_params param[1] = {
  9257. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" }
  9258. };
  9259. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9260. #endif
  9261. #endif
  9262. #endif
  9263. return EXPECT_RESULT();
  9264. }
  9265. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT)
  9266. /* canned export of a session using older version 3 */
  9267. static unsigned char version_3[] = {
  9268. 0xA5, 0xA3, 0x01, 0x88, 0x00, 0x3c, 0x00, 0x01,
  9269. 0x00, 0x00, 0x00, 0x80, 0x0C, 0x00, 0x00, 0x00,
  9270. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
  9271. 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
  9272. 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  9273. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9274. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x30,
  9275. 0x05, 0x09, 0x0A, 0x01, 0x01, 0x00, 0x0D, 0x05,
  9276. 0xFE, 0xFD, 0x01, 0x25, 0x00, 0x00, 0x00, 0x00,
  9277. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9278. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  9279. 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
  9280. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9281. 0x00, 0x06, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00,
  9282. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
  9283. 0x00, 0x06, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00,
  9284. 0x00, 0x30, 0x00, 0x00, 0x00, 0x10, 0x01, 0x01,
  9285. 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  9286. 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3F,
  9287. 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
  9288. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9289. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9290. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9291. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9292. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9293. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9294. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9295. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9296. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9297. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9298. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9299. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x05,
  9300. 0x12, 0xCF, 0x22, 0xA1, 0x9F, 0x1C, 0x39, 0x1D,
  9301. 0x31, 0x11, 0x12, 0x1D, 0x11, 0x18, 0x0D, 0x0B,
  9302. 0xF3, 0xE1, 0x4D, 0xDC, 0xB1, 0xF1, 0x39, 0x98,
  9303. 0x91, 0x6C, 0x48, 0xE5, 0xED, 0x11, 0x12, 0xA0,
  9304. 0x00, 0xF2, 0x25, 0x4C, 0x09, 0x26, 0xD1, 0x74,
  9305. 0xDF, 0x23, 0x40, 0x15, 0x6A, 0x42, 0x2A, 0x26,
  9306. 0xA5, 0xAC, 0x56, 0xD5, 0x4A, 0x20, 0xB7, 0xE9,
  9307. 0xEF, 0xEB, 0xAF, 0xA8, 0x1E, 0x23, 0x7C, 0x04,
  9308. 0xAA, 0xA1, 0x6D, 0x92, 0x79, 0x7B, 0xFA, 0x80,
  9309. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9310. 0x0C, 0x79, 0x7B, 0xFA, 0x80, 0x00, 0x00, 0x00,
  9311. 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA, 0xA1, 0x6D,
  9312. 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9313. 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x04, 0x00,
  9314. 0x10, 0x00, 0x10, 0x08, 0x02, 0x05, 0x08, 0x01,
  9315. 0x30, 0x28, 0x00, 0x00, 0x0F, 0x00, 0x02, 0x00,
  9316. 0x09, 0x31, 0x32, 0x37, 0x2E, 0x30, 0x2E, 0x30,
  9317. 0x2E, 0x31, 0xED, 0x4F
  9318. };
  9319. #endif /* defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) */
  9320. static int test_wolfSSL_dtls_export(void)
  9321. {
  9322. EXPECT_DECLS;
  9323. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT)
  9324. tcp_ready ready;
  9325. func_args client_args;
  9326. func_args server_args;
  9327. THREAD_TYPE serverThread;
  9328. callback_functions server_cbf;
  9329. callback_functions client_cbf;
  9330. #ifdef WOLFSSL_TIRTOS
  9331. fdOpenSession(Task_self());
  9332. #endif
  9333. InitTcpReady(&ready);
  9334. #if defined(USE_WINDOWS_API)
  9335. /* use RNG to get random port if using windows */
  9336. ready.port = GetRandomPort();
  9337. #endif
  9338. /* set using dtls */
  9339. XMEMSET(&client_args, 0, sizeof(func_args));
  9340. XMEMSET(&server_args, 0, sizeof(func_args));
  9341. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9342. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  9343. server_cbf.method = wolfDTLSv1_2_server_method;
  9344. client_cbf.method = wolfDTLSv1_2_client_method;
  9345. server_args.callbacks = &server_cbf;
  9346. client_args.callbacks = &client_cbf;
  9347. server_args.signal = &ready;
  9348. client_args.signal = &ready;
  9349. start_thread(run_wolfssl_server, &server_args, &serverThread);
  9350. wait_tcp_ready(&server_args);
  9351. run_wolfssl_client(&client_args);
  9352. join_thread(serverThread);
  9353. ExpectTrue(client_args.return_code);
  9354. ExpectTrue(server_args.return_code);
  9355. FreeTcpReady(&ready);
  9356. #ifdef WOLFSSL_TIRTOS
  9357. fdOpenSession(Task_self());
  9358. #endif
  9359. if (EXPECT_SUCCESS()) {
  9360. SOCKET_T sockfd = 0;
  9361. WOLFSSL_CTX* ctx = NULL;
  9362. WOLFSSL* ssl = NULL;
  9363. char msg[64] = "hello wolfssl!";
  9364. char reply[1024];
  9365. int msgSz = (int)XSTRLEN(msg);
  9366. byte *session, *window;
  9367. unsigned int sessionSz = 0;
  9368. unsigned int windowSz = 0;
  9369. #ifndef TEST_IPV6
  9370. struct sockaddr_in peerAddr;
  9371. #else
  9372. struct sockaddr_in6 peerAddr;
  9373. #endif /* TEST_IPV6 */
  9374. int i;
  9375. /* Set ctx to DTLS 1.2 */
  9376. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  9377. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9378. /* test importing version 3 */
  9379. ExpectIntGE(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9380. /* test importing bad length and bad version */
  9381. version_3[2] += 1;
  9382. ExpectIntLT(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9383. version_3[2] -= 1; version_3[1] = 0XA0;
  9384. ExpectIntLT(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9385. wolfSSL_free(ssl);
  9386. wolfSSL_CTX_free(ctx);
  9387. /* check storing client state after connection and storing window only */
  9388. #ifdef WOLFSSL_TIRTOS
  9389. fdOpenSession(Task_self());
  9390. #endif
  9391. InitTcpReady(&ready);
  9392. #if defined(USE_WINDOWS_API)
  9393. /* use RNG to get random port if using windows */
  9394. ready.port = GetRandomPort();
  9395. #endif
  9396. /* set using dtls */
  9397. XMEMSET(&server_args, 0, sizeof(func_args));
  9398. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9399. server_cbf.method = wolfDTLSv1_2_server_method;
  9400. server_cbf.doUdp = 1;
  9401. server_args.callbacks = &server_cbf;
  9402. server_args.argc = 3; /* set loop_count to 3 */
  9403. server_args.signal = &ready;
  9404. start_thread(test_server_nofail, &server_args, &serverThread);
  9405. wait_tcp_ready(&server_args);
  9406. /* create and connect with client */
  9407. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  9408. ExpectIntEQ(WOLFSSL_SUCCESS,
  9409. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  9410. ExpectIntEQ(WOLFSSL_SUCCESS,
  9411. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  9412. ExpectIntEQ(WOLFSSL_SUCCESS,
  9413. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  9414. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 1, 0, NULL);
  9415. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9416. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  9417. /* store server information connected too */
  9418. XMEMSET(&peerAddr, 0, sizeof(peerAddr));
  9419. #ifndef TEST_IPV6
  9420. peerAddr.sin_family = AF_INET;
  9421. ExpectIntEQ(XINET_PTON(AF_INET, wolfSSLIP, &peerAddr.sin_addr),1);
  9422. peerAddr.sin_port = XHTONS(server_args.signal->port);
  9423. #else
  9424. peerAddr.sin6_family = AF_INET6;
  9425. ExpectIntEQ(
  9426. XINET_PTON(AF_INET6, wolfSSLIP, &peerAddr.sin6_addr),1);
  9427. peerAddr.sin6_port = XHTONS(server_args.signal->port);
  9428. #endif
  9429. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl, &peerAddr, sizeof(peerAddr)),
  9430. WOLFSSL_SUCCESS);
  9431. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  9432. ExpectIntEQ(wolfSSL_dtls_export(ssl, NULL, &sessionSz), 0);
  9433. session = (byte*)XMALLOC(sessionSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9434. ExpectIntGT(wolfSSL_dtls_export(ssl, session, &sessionSz), 0);
  9435. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9436. ExpectIntGT(wolfSSL_read(ssl, reply, sizeof(reply)), 0);
  9437. ExpectIntEQ(wolfSSL_dtls_export_state_only(ssl, NULL, &windowSz), 0);
  9438. window = (byte*)XMALLOC(windowSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9439. ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, window, &windowSz), 0);
  9440. wolfSSL_free(ssl);
  9441. for (i = 1; EXPECT_SUCCESS() && i < server_args.argc; i++) {
  9442. /* restore state */
  9443. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9444. ExpectIntGT(wolfSSL_dtls_import(ssl, session, sessionSz), 0);
  9445. ExpectIntGT(wolfSSL_dtls_import(ssl, window, windowSz), 0);
  9446. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  9447. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl, &peerAddr, sizeof(peerAddr)),
  9448. WOLFSSL_SUCCESS);
  9449. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9450. ExpectIntGE(wolfSSL_read(ssl, reply, sizeof(reply)), 0);
  9451. ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, window, &windowSz), 0);
  9452. wolfSSL_free(ssl);
  9453. }
  9454. XFREE(session, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9455. XFREE(window, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9456. wolfSSL_CTX_free(ctx);
  9457. fprintf(stderr, "done and waiting for server\n");
  9458. join_thread(serverThread);
  9459. ExpectIntEQ(server_args.return_code, TEST_SUCCESS);
  9460. FreeTcpReady(&ready);
  9461. #ifdef WOLFSSL_TIRTOS
  9462. fdOpenSession(Task_self());
  9463. #endif
  9464. }
  9465. #endif
  9466. return EXPECT_RESULT();
  9467. }
  9468. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_NO_TLS12)
  9469. #ifdef WOLFSSL_TLS13
  9470. static const byte canned_client_tls13_session[] = {
  9471. 0xA7, 0xA4, 0x01, 0x18, 0x00, 0x41, 0x00, 0x00,
  9472. 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
  9473. 0x00, 0x80, 0x00, 0x1C, 0x01, 0x00, 0x00, 0x01,
  9474. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9475. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
  9476. 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9477. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
  9478. 0x01, 0x0A, 0x0F, 0x10, 0x01, 0x02, 0x09, 0x00,
  9479. 0x05, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00,
  9480. 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9481. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9482. 0x01, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00,
  9483. 0x11, 0x01, 0x01, 0x00, 0x20, 0x84, 0x4F, 0x18,
  9484. 0xD8, 0xC1, 0x24, 0xD8, 0xBB, 0x17, 0x9E, 0x31,
  9485. 0xA3, 0xF8, 0xA7, 0x3C, 0xBA, 0xEC, 0xFA, 0xB4,
  9486. 0x7F, 0xC5, 0x78, 0xEB, 0x6D, 0xE3, 0x2B, 0x7B,
  9487. 0x94, 0xBE, 0x20, 0x11, 0x7E, 0x17, 0x10, 0xA7,
  9488. 0x10, 0x19, 0xEC, 0x62, 0xCC, 0xBE, 0xF5, 0x01,
  9489. 0x35, 0x3C, 0xEA, 0xEF, 0x44, 0x3C, 0x40, 0xA2,
  9490. 0xBC, 0x18, 0x43, 0xA1, 0xA1, 0x65, 0x5C, 0x48,
  9491. 0xE2, 0xF9, 0x38, 0xEB, 0x11, 0x10, 0x72, 0x7C,
  9492. 0x78, 0x22, 0x13, 0x3B, 0x19, 0x40, 0xF0, 0x73,
  9493. 0xBE, 0x96, 0x14, 0x78, 0x26, 0xB9, 0x6B, 0x2E,
  9494. 0x72, 0x22, 0x0D, 0x90, 0x94, 0xDD, 0x78, 0x77,
  9495. 0xFC, 0x0C, 0x2E, 0x63, 0x6E, 0xF0, 0x0C, 0x35,
  9496. 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0, 0x6F,
  9497. 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A, 0xA0,
  9498. 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06, 0x00,
  9499. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9500. 0x35, 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0,
  9501. 0x6F, 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A,
  9502. 0xA0, 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06,
  9503. 0x00, 0x10, 0x00, 0x10, 0x00, 0x0C, 0x00, 0x10,
  9504. 0x00, 0x10, 0x07, 0x02, 0x04, 0x00, 0x00, 0x20,
  9505. 0x28, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9506. 0x00, 0x03
  9507. };
  9508. static const byte canned_server_tls13_session[] = {
  9509. 0xA7, 0xA4, 0x01, 0x18, 0x00, 0x41, 0x01, 0x00,
  9510. 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
  9511. 0x00, 0x80, 0x00, 0x1C, 0x01, 0x00, 0x00, 0x00,
  9512. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9513. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9514. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9515. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
  9516. 0x01, 0x0A, 0x0F, 0x10, 0x01, 0x02, 0x00, 0x0F,
  9517. 0x05, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00,
  9518. 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9519. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9520. 0x02, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00,
  9521. 0x11, 0x01, 0x01, 0x00, 0x20, 0x84, 0x4F, 0x18,
  9522. 0xD8, 0xC1, 0x24, 0xD8, 0xBB, 0x17, 0x9E, 0x31,
  9523. 0xA3, 0xF8, 0xA7, 0x3C, 0xBA, 0xEC, 0xFA, 0xB4,
  9524. 0x7F, 0xC5, 0x78, 0xEB, 0x6D, 0xE3, 0x2B, 0x7B,
  9525. 0x94, 0xBE, 0x20, 0x11, 0x7E, 0x17, 0x10, 0xA7,
  9526. 0x10, 0x19, 0xEC, 0x62, 0xCC, 0xBE, 0xF5, 0x01,
  9527. 0x35, 0x3C, 0xEA, 0xEF, 0x44, 0x3C, 0x40, 0xA2,
  9528. 0xBC, 0x18, 0x43, 0xA1, 0xA1, 0x65, 0x5C, 0x48,
  9529. 0xE2, 0xF9, 0x38, 0xEB, 0x11, 0x10, 0x72, 0x7C,
  9530. 0x78, 0x22, 0x13, 0x3B, 0x19, 0x40, 0xF0, 0x73,
  9531. 0xBE, 0x96, 0x14, 0x78, 0x26, 0xB9, 0x6B, 0x2E,
  9532. 0x72, 0x22, 0x0D, 0x90, 0x94, 0xDD, 0x78, 0x77,
  9533. 0xFC, 0x0C, 0x2E, 0x63, 0x6E, 0xF0, 0x0C, 0x35,
  9534. 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0, 0x6F,
  9535. 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A, 0xA0,
  9536. 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06, 0x00,
  9537. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9538. 0xD3, 0xB7, 0xEE, 0x3A, 0xA0, 0x8E, 0xA1, 0x4D,
  9539. 0xC3, 0x2E, 0x5E, 0x06, 0x35, 0x41, 0xCD, 0xF3,
  9540. 0x49, 0x31, 0x08, 0xD0, 0x6F, 0x02, 0x3D, 0xC1,
  9541. 0x00, 0x10, 0x00, 0x10, 0x00, 0x0C, 0x00, 0x10,
  9542. 0x00, 0x10, 0x07, 0x02, 0x04, 0x00, 0x00, 0x20,
  9543. 0x28, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9544. 0x00, 0x04
  9545. };
  9546. #endif /* WOLFSSL_TLS13 */
  9547. static const byte canned_client_session[] = {
  9548. 0xA7, 0xA4, 0x01, 0x40, 0x00, 0x41, 0x00, 0x00,
  9549. 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00,
  9550. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x01,
  9551. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9552. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
  9553. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9554. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
  9555. 0x27, 0x0A, 0x0D, 0x10, 0x01, 0x01, 0x0A, 0x00,
  9556. 0x05, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03, 0x00,
  9557. 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9558. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9559. 0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00,
  9560. 0x0A, 0x01, 0x01, 0x00, 0x20, 0x69, 0x11, 0x6D,
  9561. 0x97, 0x15, 0x6E, 0x52, 0x27, 0xD6, 0x1D, 0x1D,
  9562. 0xF5, 0x0D, 0x59, 0xA5, 0xAC, 0x2E, 0x8C, 0x0E,
  9563. 0xCB, 0x26, 0x1E, 0xE2, 0xCE, 0xBB, 0xCE, 0xE1,
  9564. 0x7D, 0xD7, 0xEF, 0xA5, 0x44, 0x80, 0x2A, 0xDE,
  9565. 0xBB, 0x75, 0xB0, 0x1D, 0x75, 0x17, 0x20, 0x4C,
  9566. 0x08, 0x05, 0x1B, 0xBA, 0x60, 0x1F, 0x6C, 0x91,
  9567. 0x8C, 0xAA, 0xBB, 0xE5, 0xA3, 0x0B, 0x12, 0x3E,
  9568. 0xC0, 0x35, 0x43, 0x1D, 0xE2, 0x10, 0xE2, 0x02,
  9569. 0x92, 0x4B, 0x8F, 0x05, 0xA9, 0x4B, 0xCC, 0x90,
  9570. 0xC3, 0x0E, 0xC2, 0x0F, 0xE9, 0x33, 0x85, 0x9B,
  9571. 0x3C, 0x19, 0x21, 0xD5, 0x62, 0xE5, 0xE1, 0x17,
  9572. 0x8F, 0x8C, 0x19, 0x52, 0xD8, 0x59, 0x10, 0x2D,
  9573. 0x20, 0x6F, 0xBA, 0xC1, 0x1C, 0xD1, 0x82, 0xC7,
  9574. 0x32, 0x1B, 0xBB, 0xCC, 0x30, 0x03, 0xD7, 0x3A,
  9575. 0xC8, 0x18, 0xED, 0x58, 0xC8, 0x11, 0xFE, 0x71,
  9576. 0x9C, 0x71, 0xD8, 0x6B, 0xE0, 0x25, 0x64, 0x00,
  9577. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9578. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9579. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9580. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9581. 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
  9582. 0x00, 0x00, 0x06, 0x01, 0x04, 0x08, 0x01, 0x20,
  9583. 0x28, 0x00, 0x09, 0xE1, 0x50, 0x70, 0x02, 0x2F,
  9584. 0x7E, 0xDA, 0xBD, 0x40, 0xC5, 0x58, 0x87, 0xCE,
  9585. 0x43, 0xF3, 0xC5, 0x8F, 0xA1, 0x59, 0x93, 0xEF,
  9586. 0x7E, 0xD3, 0xD0, 0xB5, 0x87, 0x1D, 0x81, 0x54,
  9587. 0x14, 0x63, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9588. 0x00, 0x03
  9589. };
  9590. static const byte canned_server_session[] = {
  9591. 0xA7, 0xA4, 0x01, 0x40, 0x00, 0x41, 0x00, 0x00,
  9592. 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00,
  9593. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
  9594. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9595. 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  9596. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9597. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
  9598. 0x27, 0x08, 0x0F, 0x10, 0x01, 0x01, 0x00, 0x11,
  9599. 0x05, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03, 0x00,
  9600. 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9601. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9602. 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
  9603. 0x0A, 0x01, 0x01, 0x00, 0x20, 0x69, 0x11, 0x6D,
  9604. 0x97, 0x15, 0x6E, 0x52, 0x27, 0xD6, 0x1D, 0x1D,
  9605. 0xF5, 0x0D, 0x59, 0xA5, 0xAC, 0x2E, 0x8C, 0x0E,
  9606. 0xCB, 0x26, 0x1E, 0xE2, 0xCE, 0xBB, 0xCE, 0xE1,
  9607. 0x7D, 0xD7, 0xEF, 0xA5, 0x44, 0x80, 0x2A, 0xDE,
  9608. 0xBB, 0x75, 0xB0, 0x1D, 0x75, 0x17, 0x20, 0x4C,
  9609. 0x08, 0x05, 0x1B, 0xBA, 0x60, 0x1F, 0x6C, 0x91,
  9610. 0x8C, 0xAA, 0xBB, 0xE5, 0xA3, 0x0B, 0x12, 0x3E,
  9611. 0xC0, 0x35, 0x43, 0x1D, 0xE2, 0x10, 0xE2, 0x02,
  9612. 0x92, 0x4B, 0x8F, 0x05, 0xA9, 0x4B, 0xCC, 0x90,
  9613. 0xC3, 0x0E, 0xC2, 0x0F, 0xE9, 0x33, 0x85, 0x9B,
  9614. 0x3C, 0x19, 0x21, 0xD5, 0x62, 0xE5, 0xE1, 0x17,
  9615. 0x8F, 0x8C, 0x19, 0x52, 0xD8, 0x59, 0x10, 0x2D,
  9616. 0x20, 0x6F, 0xBA, 0xC1, 0x1C, 0xD1, 0x82, 0xC7,
  9617. 0x32, 0x1B, 0xBB, 0xCC, 0x30, 0x03, 0xD7, 0x3A,
  9618. 0xC8, 0x18, 0xED, 0x58, 0xC8, 0x11, 0xFE, 0x71,
  9619. 0x9C, 0x71, 0xD8, 0x6B, 0xE0, 0x25, 0x64, 0x00,
  9620. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9621. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9622. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9623. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9624. 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
  9625. 0x00, 0x00, 0x06, 0x01, 0x04, 0x08, 0x01, 0x20,
  9626. 0x28, 0x00, 0xC5, 0x8F, 0xA1, 0x59, 0x93, 0xEF,
  9627. 0x7E, 0xD3, 0xD0, 0xB5, 0x87, 0x1D, 0x81, 0x54,
  9628. 0x14, 0x63, 0x09, 0xE1, 0x50, 0x70, 0x02, 0x2F,
  9629. 0x7E, 0xDA, 0xBD, 0x40, 0xC5, 0x58, 0x87, 0xCE,
  9630. 0x43, 0xF3, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9631. 0x00, 0x04
  9632. };
  9633. static THREAD_RETURN WOLFSSL_THREAD tls_export_server(void* args)
  9634. {
  9635. SOCKET_T sockfd = 0;
  9636. SOCKET_T clientfd = 0;
  9637. word16 port;
  9638. callback_functions* cbf;
  9639. WOLFSSL_CTX* ctx = 0;
  9640. WOLFSSL* ssl = 0;
  9641. char msg[] = "I hear you fa shizzle!";
  9642. char input[1024];
  9643. int idx;
  9644. #ifdef WOLFSSL_TIRTOS
  9645. fdOpenSession(Task_self());
  9646. #endif
  9647. ((func_args*)args)->return_code = TEST_FAIL;
  9648. cbf = ((func_args*)args)->callbacks;
  9649. #if defined(USE_WINDOWS_API)
  9650. port = ((func_args*)args)->signal->port;
  9651. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  9652. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  9653. /* Let tcp_listen assign port */
  9654. port = 0;
  9655. #else
  9656. /* Use default port */
  9657. port = wolfSSLPort;
  9658. #endif
  9659. /* do it here to detect failure */
  9660. tcp_accept(&sockfd, &clientfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  9661. CloseSocket(sockfd);
  9662. {
  9663. WOLFSSL_METHOD* method = NULL;
  9664. if (cbf != NULL && cbf->method != NULL) {
  9665. method = cbf->method();
  9666. }
  9667. else {
  9668. method = wolfTLSv1_2_server_method();
  9669. }
  9670. ctx = wolfSSL_CTX_new(method);
  9671. }
  9672. if (ctx == NULL) {
  9673. goto done;
  9674. }
  9675. wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256");
  9676. /* call ctx setup callback */
  9677. if (cbf != NULL && cbf->ctx_ready != NULL) {
  9678. cbf->ctx_ready(ctx);
  9679. }
  9680. ssl = wolfSSL_new(ctx);
  9681. if (ssl == NULL) {
  9682. goto done;
  9683. }
  9684. wolfSSL_set_fd(ssl, clientfd);
  9685. /* call ssl setup callback */
  9686. if (cbf != NULL && cbf->ssl_ready != NULL) {
  9687. cbf->ssl_ready(ssl);
  9688. }
  9689. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  9690. if (idx > 0) {
  9691. input[idx] = '\0';
  9692. fprintf(stderr, "Client message export/import: %s\n", input);
  9693. }
  9694. else {
  9695. fprintf(stderr, "ret = %d error = %d\n", idx,
  9696. wolfSSL_get_error(ssl, idx));
  9697. goto done;
  9698. }
  9699. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  9700. /*err_sys("SSL_write failed");*/
  9701. WOLFSSL_RETURN_FROM_THREAD(0);
  9702. }
  9703. #ifdef WOLFSSL_TIRTOS
  9704. Task_yield();
  9705. #endif
  9706. ((func_args*)args)->return_code = TEST_SUCCESS;
  9707. done:
  9708. wolfSSL_shutdown(ssl);
  9709. wolfSSL_free(ssl);
  9710. wolfSSL_CTX_free(ctx);
  9711. CloseSocket(clientfd);
  9712. #ifdef WOLFSSL_TIRTOS
  9713. fdCloseSession(Task_self());
  9714. #endif
  9715. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  9716. && defined(HAVE_THREAD_LS)
  9717. wc_ecc_fp_free(); /* free per thread cache */
  9718. #endif
  9719. #if defined(HAVE_SESSION_TICKET) && \
  9720. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  9721. #if defined(OPENSSL_EXTRA) && defined(HAVE_AESGCM)
  9722. OpenSSLTicketCleanup();
  9723. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  9724. TicketCleanup();
  9725. #endif
  9726. #endif
  9727. WOLFSSL_RETURN_FROM_THREAD(0);
  9728. }
  9729. static void load_tls12_canned_server(WOLFSSL* ssl)
  9730. {
  9731. int clientfd = wolfSSL_get_fd(ssl);
  9732. AssertIntEQ(wolfSSL_tls_import(ssl, canned_server_session,
  9733. sizeof(canned_server_session)), sizeof(canned_server_session));
  9734. wolfSSL_set_fd(ssl, clientfd);
  9735. }
  9736. #ifdef WOLFSSL_TLS13
  9737. static void load_tls13_canned_server(WOLFSSL* ssl)
  9738. {
  9739. int clientfd = wolfSSL_get_fd(ssl);
  9740. AssertIntEQ(wolfSSL_tls_import(ssl, canned_server_tls13_session,
  9741. sizeof(canned_server_tls13_session)),
  9742. sizeof(canned_server_tls13_session));
  9743. wolfSSL_set_fd(ssl, clientfd);
  9744. }
  9745. #endif
  9746. /* v is for version WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  9747. static int test_wolfSSL_tls_export_run(int v)
  9748. {
  9749. EXPECT_DECLS;
  9750. SOCKET_T sockfd = 0;
  9751. WOLFSSL_CTX* ctx = 0;
  9752. WOLFSSL* ssl = 0;
  9753. char msg[64] = "hello wolfssl!";
  9754. char reply[1024];
  9755. word32 replySz;
  9756. int msgSz = (int)XSTRLEN(msg);
  9757. const byte* clientSession = NULL;
  9758. int clientSessionSz = 0;
  9759. tcp_ready ready;
  9760. func_args server_args;
  9761. THREAD_TYPE serverThread;
  9762. callback_functions server_cbf;
  9763. #ifdef WOLFSSL_TIRTOS
  9764. fdOpenSession(Task_self());
  9765. #endif
  9766. InitTcpReady(&ready);
  9767. #if defined(USE_WINDOWS_API)
  9768. /* use RNG to get random port if using windows */
  9769. ready.port = GetRandomPort();
  9770. #endif
  9771. XMEMSET(&server_args, 0, sizeof(func_args));
  9772. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9773. switch (v) {
  9774. case WOLFSSL_TLSV1_2:
  9775. server_cbf.method = wolfTLSv1_2_server_method;
  9776. server_cbf.ssl_ready = load_tls12_canned_server;
  9777. /* setup the client side */
  9778. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  9779. wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256");
  9780. clientSession = canned_client_session;
  9781. clientSessionSz = sizeof(canned_client_session);
  9782. break;
  9783. #ifdef WOLFSSL_TLS13
  9784. case WOLFSSL_TLSV1_3:
  9785. server_cbf.method = wolfTLSv1_3_server_method;
  9786. server_cbf.ssl_ready = load_tls13_canned_server;
  9787. /* setup the client side */
  9788. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  9789. clientSession = canned_client_tls13_session;
  9790. clientSessionSz = sizeof(canned_client_tls13_session);
  9791. break;
  9792. #endif
  9793. }
  9794. server_args.callbacks = &server_cbf;
  9795. server_args.signal = &ready;
  9796. start_thread(tls_export_server, &server_args, &serverThread);
  9797. wait_tcp_ready(&server_args);
  9798. #ifdef WOLFSSL_TIRTOS
  9799. fdOpenSession(Task_self());
  9800. #endif
  9801. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9802. tcp_connect(&sockfd, wolfSSLIP, ready.port, 0, 0, ssl);
  9803. ExpectIntEQ(wolfSSL_tls_import(ssl, clientSession, clientSessionSz),
  9804. clientSessionSz);
  9805. replySz = sizeof(reply);
  9806. ExpectIntGT(wolfSSL_tls_export(ssl, (byte*)reply, &replySz), 0);
  9807. #if !defined(NO_PSK) && defined(HAVE_ANON)
  9808. /* index 20 has is setting if PSK was on and 49 is if anon is allowed */
  9809. ExpectIntEQ(XMEMCMP(reply, clientSession, replySz), 0);
  9810. #endif
  9811. wolfSSL_set_fd(ssl, sockfd);
  9812. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9813. ExpectIntGT(wolfSSL_read(ssl, reply, sizeof(reply)-1), 0);
  9814. wolfSSL_free(ssl);
  9815. wolfSSL_CTX_free(ctx);
  9816. CloseSocket(sockfd);
  9817. #ifdef WOLFSSL_TIRTOS
  9818. fdCloseSession(Task_self());
  9819. #endif
  9820. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  9821. && defined(HAVE_THREAD_LS)
  9822. wc_ecc_fp_free(); /* free per thread cache */
  9823. #endif
  9824. join_thread(serverThread);
  9825. ExpectIntEQ(server_args.return_code, TEST_SUCCESS);
  9826. FreeTcpReady(&ready);
  9827. #ifdef WOLFSSL_TIRTOS
  9828. fdOpenSession(Task_self());
  9829. #endif
  9830. return EXPECT_RESULT();
  9831. }
  9832. #endif
  9833. static int test_wolfSSL_tls_export(void)
  9834. {
  9835. int res = TEST_SKIPPED;
  9836. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_NO_TLS12)
  9837. test_wolfSSL_tls_export_run(WOLFSSL_TLSV1_2);
  9838. #ifdef WOLFSSL_TLS13
  9839. test_wolfSSL_tls_export_run(WOLFSSL_TLSV1_3);
  9840. #endif
  9841. res = TEST_RES_CHECK(1);
  9842. #endif
  9843. return res;
  9844. }
  9845. /*----------------------------------------------------------------------------*
  9846. | TLS extensions tests
  9847. *----------------------------------------------------------------------------*/
  9848. #ifdef ENABLE_TLS_CALLBACK_TEST
  9849. /* Connection test runner - generic */
  9850. static void test_wolfSSL_client_server(callback_functions* client_callbacks,
  9851. callback_functions* server_callbacks)
  9852. {
  9853. tcp_ready ready;
  9854. func_args client_args;
  9855. func_args server_args;
  9856. THREAD_TYPE serverThread;
  9857. XMEMSET(&client_args, 0, sizeof(func_args));
  9858. XMEMSET(&server_args, 0, sizeof(func_args));
  9859. StartTCP();
  9860. client_args.callbacks = client_callbacks;
  9861. server_args.callbacks = server_callbacks;
  9862. #ifdef WOLFSSL_TIRTOS
  9863. fdOpenSession(Task_self());
  9864. #endif
  9865. /* RUN Server side */
  9866. InitTcpReady(&ready);
  9867. #if defined(USE_WINDOWS_API)
  9868. /* use RNG to get random port if using windows */
  9869. ready.port = GetRandomPort();
  9870. #endif
  9871. server_args.signal = &ready;
  9872. client_args.signal = &ready;
  9873. start_thread(run_wolfssl_server, &server_args, &serverThread);
  9874. wait_tcp_ready(&server_args);
  9875. /* RUN Client side */
  9876. run_wolfssl_client(&client_args);
  9877. join_thread(serverThread);
  9878. FreeTcpReady(&ready);
  9879. #ifdef WOLFSSL_TIRTOS
  9880. fdCloseSession(Task_self());
  9881. #endif
  9882. client_callbacks->return_code = client_args.return_code;
  9883. server_callbacks->return_code = server_args.return_code;
  9884. }
  9885. #endif /* ENABLE_TLS_CALLBACK_TEST */
  9886. #ifdef HAVE_SNI
  9887. static int test_wolfSSL_UseSNI_params(void)
  9888. {
  9889. EXPECT_DECLS;
  9890. #if !defined(NO_WOLFSSL_CLIENT)
  9891. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  9892. WOLFSSL *ssl = wolfSSL_new(ctx);
  9893. ExpectNotNull(ctx);
  9894. ExpectNotNull(ssl);
  9895. /* invalid [ctx|ssl] */
  9896. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(NULL, 0, "ctx", 3));
  9897. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( NULL, 0, "ssl", 3));
  9898. /* invalid type */
  9899. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, (byte)-1, "ctx", 3));
  9900. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, (byte)-1, "ssl", 3));
  9901. /* invalid data */
  9902. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, 0, NULL, 3));
  9903. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, 0, NULL, 3));
  9904. /* success case */
  9905. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, 0, "ctx", 3));
  9906. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, 0, "ssl", 3));
  9907. wolfSSL_free(ssl);
  9908. wolfSSL_CTX_free(ctx);
  9909. #endif /* !NO_WOLFSSL_CLIENT */
  9910. return EXPECT_RESULT();
  9911. }
  9912. /* BEGIN of connection tests callbacks */
  9913. static void use_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9914. {
  9915. AssertIntEQ(WOLFSSL_SUCCESS,
  9916. wolfSSL_CTX_UseSNI(ctx, WOLFSSL_SNI_HOST_NAME, "www.wolfssl.com", 15));
  9917. }
  9918. static void use_SNI_at_ssl(WOLFSSL* ssl)
  9919. {
  9920. AssertIntEQ(WOLFSSL_SUCCESS,
  9921. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, "www.wolfssl.com", 15));
  9922. }
  9923. static void different_SNI_at_ssl(WOLFSSL* ssl)
  9924. {
  9925. AssertIntEQ(WOLFSSL_SUCCESS,
  9926. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, "ww2.wolfssl.com", 15));
  9927. }
  9928. static void use_SNI_WITH_CONTINUE_at_ssl(WOLFSSL* ssl)
  9929. {
  9930. use_SNI_at_ssl(ssl);
  9931. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9932. WOLFSSL_SNI_CONTINUE_ON_MISMATCH);
  9933. }
  9934. static void use_SNI_WITH_FAKE_ANSWER_at_ssl(WOLFSSL* ssl)
  9935. {
  9936. use_SNI_at_ssl(ssl);
  9937. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9938. WOLFSSL_SNI_ANSWER_ON_MISMATCH);
  9939. }
  9940. static void use_MANDATORY_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9941. {
  9942. use_SNI_at_ctx(ctx);
  9943. wolfSSL_CTX_SNI_SetOptions(ctx, WOLFSSL_SNI_HOST_NAME,
  9944. WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9945. }
  9946. static void use_MANDATORY_SNI_at_ssl(WOLFSSL* ssl)
  9947. {
  9948. use_SNI_at_ssl(ssl);
  9949. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9950. WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9951. }
  9952. static void use_PSEUDO_MANDATORY_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9953. {
  9954. use_SNI_at_ctx(ctx);
  9955. wolfSSL_CTX_SNI_SetOptions(ctx, WOLFSSL_SNI_HOST_NAME,
  9956. WOLFSSL_SNI_ANSWER_ON_MISMATCH | WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9957. }
  9958. static void verify_UNKNOWN_SNI_on_server(WOLFSSL* ssl)
  9959. {
  9960. AssertIntEQ(WC_NO_ERR_TRACE(UNKNOWN_SNI_HOST_NAME_E),
  9961. wolfSSL_get_error(ssl, 0));
  9962. }
  9963. static void verify_SNI_ABSENT_on_server(WOLFSSL* ssl)
  9964. {
  9965. AssertIntEQ(WC_NO_ERR_TRACE(SNI_ABSENT_ERROR), wolfSSL_get_error(ssl, 0));
  9966. }
  9967. static void verify_SNI_no_matching(WOLFSSL* ssl)
  9968. {
  9969. byte type = WOLFSSL_SNI_HOST_NAME;
  9970. void* request = (void*) &type; /* to be overwritten */
  9971. AssertIntEQ(WOLFSSL_SNI_NO_MATCH, wolfSSL_SNI_Status(ssl, type));
  9972. AssertNotNull(request);
  9973. AssertIntEQ(0, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9974. AssertNull(request);
  9975. }
  9976. static void verify_SNI_real_matching(WOLFSSL* ssl)
  9977. {
  9978. byte type = WOLFSSL_SNI_HOST_NAME;
  9979. void* request = NULL;
  9980. AssertIntEQ(WOLFSSL_SNI_REAL_MATCH, wolfSSL_SNI_Status(ssl, type));
  9981. AssertIntEQ(15, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9982. AssertNotNull(request);
  9983. AssertStrEQ("www.wolfssl.com", (char*)request);
  9984. }
  9985. static void verify_SNI_fake_matching(WOLFSSL* ssl)
  9986. {
  9987. byte type = WOLFSSL_SNI_HOST_NAME;
  9988. void* request = NULL;
  9989. AssertIntEQ(WOLFSSL_SNI_FAKE_MATCH, wolfSSL_SNI_Status(ssl, type));
  9990. AssertIntEQ(15, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9991. AssertNotNull(request);
  9992. AssertStrEQ("ww2.wolfssl.com", (char*)request);
  9993. }
  9994. static void verify_FATAL_ERROR_on_client(WOLFSSL* ssl)
  9995. {
  9996. AssertIntEQ(WC_NO_ERR_TRACE(FATAL_ERROR), wolfSSL_get_error(ssl, 0));
  9997. }
  9998. /* END of connection tests callbacks */
  9999. static int test_wolfSSL_UseSNI_connection(void)
  10000. {
  10001. int res = TEST_SKIPPED;
  10002. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  10003. callback_functions client_cb;
  10004. callback_functions server_cb;
  10005. size_t i;
  10006. #ifdef WOLFSSL_STATIC_MEMORY
  10007. byte cliMem[TEST_TLS_STATIC_MEMSZ];
  10008. byte svrMem[TEST_TLS_STATIC_MEMSZ];
  10009. #endif
  10010. struct {
  10011. method_provider client_meth;
  10012. method_provider server_meth;
  10013. #ifdef WOLFSSL_STATIC_MEMORY
  10014. wolfSSL_method_func client_meth_ex;
  10015. wolfSSL_method_func server_meth_ex;
  10016. #endif
  10017. } methods[] = {
  10018. #if defined(WOLFSSL_NO_TLS12) && !defined(WOLFSSL_TLS13)
  10019. {wolfSSLv23_client_method, wolfSSLv23_server_method
  10020. #ifdef WOLFSSL_STATIC_MEMORY
  10021. ,wolfSSLv23_client_method_ex, wolfSSLv23_server_method_ex
  10022. #endif
  10023. },
  10024. #endif
  10025. #ifndef WOLFSSL_NO_TLS12
  10026. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method
  10027. #ifdef WOLFSSL_STATIC_MEMORY
  10028. ,wolfTLSv1_2_client_method_ex, wolfTLSv1_2_server_method_ex
  10029. #endif
  10030. },
  10031. #endif
  10032. #ifdef WOLFSSL_TLS13
  10033. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method
  10034. #ifdef WOLFSSL_STATIC_MEMORY
  10035. ,wolfTLSv1_3_client_method_ex, wolfTLSv1_3_server_method_ex
  10036. #endif
  10037. },
  10038. #endif
  10039. };
  10040. size_t methodsSz = sizeof(methods) / sizeof(*methods);
  10041. for (i = 0; i < methodsSz; i++) {
  10042. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  10043. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  10044. client_cb.method = methods[i].client_meth;
  10045. server_cb.method = methods[i].server_meth;
  10046. client_cb.devId = testDevId;
  10047. server_cb.devId = testDevId;
  10048. #ifdef WOLFSSL_STATIC_MEMORY
  10049. client_cb.method_ex = methods[i].client_meth_ex;
  10050. server_cb.method_ex = methods[i].server_meth_ex;
  10051. client_cb.mem = cliMem;
  10052. client_cb.memSz = (word32)sizeof(cliMem);
  10053. server_cb.mem = svrMem;
  10054. server_cb.memSz = (word32)sizeof(svrMem);;
  10055. #endif
  10056. /* success case at ctx */
  10057. fprintf(stderr, "\n\tsuccess case at ctx\n");
  10058. client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10059. server_cb.ctx_ready = use_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching;
  10060. test_wolfSSL_client_server(&client_cb, &server_cb);
  10061. /* success case at ssl */
  10062. fprintf(stderr, "\tsuccess case at ssl\n");
  10063. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_SNI_at_ssl; client_cb.on_result = verify_SNI_real_matching;
  10064. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_SNI_real_matching;
  10065. test_wolfSSL_client_server(&client_cb, &server_cb);
  10066. /* default mismatch behavior */
  10067. fprintf(stderr, "\tdefault mismatch behavior\n");
  10068. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = verify_FATAL_ERROR_on_client;
  10069. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_UNKNOWN_SNI_on_server;
  10070. test_wolfSSL_client_server(&client_cb, &server_cb);
  10071. /* continue on mismatch */
  10072. fprintf(stderr, "\tcontinue on mismatch\n");
  10073. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  10074. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_CONTINUE_at_ssl; server_cb.on_result = verify_SNI_no_matching;
  10075. test_wolfSSL_client_server(&client_cb, &server_cb);
  10076. /* fake answer on mismatch */
  10077. fprintf(stderr, "\tfake answer on mismatch\n");
  10078. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  10079. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_FAKE_ANSWER_at_ssl; server_cb.on_result = verify_SNI_fake_matching;
  10080. test_wolfSSL_client_server(&client_cb, &server_cb);
  10081. /* sni abort - success */
  10082. fprintf(stderr, "\tsni abort - success\n");
  10083. client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10084. server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching;
  10085. test_wolfSSL_client_server(&client_cb, &server_cb);
  10086. /* sni abort - abort when absent (ctx) */
  10087. fprintf(stderr, "\tsni abort - abort when absent (ctx)\n");
  10088. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client;
  10089. server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_ABSENT_on_server;
  10090. test_wolfSSL_client_server(&client_cb, &server_cb);
  10091. /* sni abort - abort when absent (ssl) */
  10092. fprintf(stderr, "\tsni abort - abort when absent (ssl)\n");
  10093. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client;
  10094. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_MANDATORY_SNI_at_ssl; server_cb.on_result = verify_SNI_ABSENT_on_server;
  10095. test_wolfSSL_client_server(&client_cb, &server_cb);
  10096. /* sni abort - success when overwritten */
  10097. fprintf(stderr, "\tsni abort - success when overwritten\n");
  10098. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10099. server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_SNI_no_matching;
  10100. test_wolfSSL_client_server(&client_cb, &server_cb);
  10101. /* sni abort - success when allowing mismatches */
  10102. fprintf(stderr, "\tsni abort - success when allowing mismatches\n");
  10103. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  10104. server_cb.ctx_ready = use_PSEUDO_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_fake_matching;
  10105. test_wolfSSL_client_server(&client_cb, &server_cb);
  10106. }
  10107. res = TEST_RES_CHECK(1);
  10108. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  10109. return res;
  10110. }
  10111. static int test_wolfSSL_SNI_GetFromBuffer(void)
  10112. {
  10113. EXPECT_DECLS;
  10114. byte buff[] = { /* www.paypal.com */
  10115. 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0x60, 0x03, 0x03, 0x5c,
  10116. 0xc4, 0xb3, 0x8c, 0x87, 0xef, 0xa4, 0x09, 0xe0, 0x02, 0xab, 0x86, 0xca,
  10117. 0x76, 0xf0, 0x9e, 0x01, 0x65, 0xf6, 0xa6, 0x06, 0x13, 0x1d, 0x0f, 0xa5,
  10118. 0x79, 0xb0, 0xd4, 0x77, 0x22, 0xeb, 0x1a, 0x00, 0x00, 0x16, 0x00, 0x6b,
  10119. 0x00, 0x67, 0x00, 0x39, 0x00, 0x33, 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x35,
  10120. 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x21,
  10121. 0x00, 0x00, 0x00, 0x13, 0x00, 0x11, 0x00, 0x00, 0x0e, 0x77, 0x77, 0x77,
  10122. 0x2e, 0x70, 0x61, 0x79, 0x70, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x00,
  10123. 0x0d, 0x00, 0x06, 0x00, 0x04, 0x04, 0x01, 0x02, 0x01
  10124. };
  10125. byte buff2[] = { /* api.textmate.org */
  10126. 0x16, 0x03, 0x01, 0x00, 0xc6, 0x01, 0x00, 0x00, 0xc2, 0x03, 0x03, 0x52,
  10127. 0x8b, 0x7b, 0xca, 0x69, 0xec, 0x97, 0xd5, 0x08, 0x03, 0x50, 0xfe, 0x3b,
  10128. 0x99, 0xc3, 0x20, 0xce, 0xa5, 0xf6, 0x99, 0xa5, 0x71, 0xf9, 0x57, 0x7f,
  10129. 0x04, 0x38, 0xf6, 0x11, 0x0b, 0xb8, 0xd3, 0x00, 0x00, 0x5e, 0x00, 0xff,
  10130. 0xc0, 0x24, 0xc0, 0x23, 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x07, 0xc0, 0x08,
  10131. 0xc0, 0x28, 0xc0, 0x27, 0xc0, 0x14, 0xc0, 0x13, 0xc0, 0x11, 0xc0, 0x12,
  10132. 0xc0, 0x26, 0xc0, 0x25, 0xc0, 0x2a, 0xc0, 0x29, 0xc0, 0x05, 0xc0, 0x04,
  10133. 0xc0, 0x02, 0xc0, 0x03, 0xc0, 0x0f, 0xc0, 0x0e, 0xc0, 0x0c, 0xc0, 0x0d,
  10134. 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x35,
  10135. 0x00, 0x0a, 0x00, 0x67, 0x00, 0x6b, 0x00, 0x33, 0x00, 0x39, 0x00, 0x16,
  10136. 0x00, 0xaf, 0x00, 0xae, 0x00, 0x8d, 0x00, 0x8c, 0x00, 0x8a, 0x00, 0x8b,
  10137. 0x00, 0xb1, 0x00, 0xb0, 0x00, 0x2c, 0x00, 0x3b, 0x01, 0x00, 0x00, 0x3b,
  10138. 0x00, 0x00, 0x00, 0x15, 0x00, 0x13, 0x00, 0x00, 0x10, 0x61, 0x70, 0x69,
  10139. 0x2e, 0x74, 0x65, 0x78, 0x74, 0x6d, 0x61, 0x74, 0x65, 0x2e, 0x6f, 0x72,
  10140. 0x67, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06, 0x00, 0x17, 0x00, 0x18, 0x00,
  10141. 0x19, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x0d, 0x00, 0x0c, 0x00,
  10142. 0x0a, 0x05, 0x01, 0x04, 0x01, 0x02, 0x01, 0x04, 0x03, 0x02, 0x03
  10143. };
  10144. byte buff3[] = { /* no sni extension */
  10145. 0x16, 0x03, 0x03, 0x00, 0x4d, 0x01, 0x00, 0x00, 0x49, 0x03, 0x03, 0xea,
  10146. 0xa1, 0x9f, 0x60, 0xdd, 0x52, 0x12, 0x13, 0xbd, 0x84, 0x34, 0xd5, 0x1c,
  10147. 0x38, 0x25, 0xa8, 0x97, 0xd2, 0xd5, 0xc6, 0x45, 0xaf, 0x1b, 0x08, 0xe4,
  10148. 0x1e, 0xbb, 0xdf, 0x9d, 0x39, 0xf0, 0x65, 0x00, 0x00, 0x16, 0x00, 0x6b,
  10149. 0x00, 0x67, 0x00, 0x39, 0x00, 0x33, 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x35,
  10150. 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x0a,
  10151. 0x00, 0x0d, 0x00, 0x06, 0x00, 0x04, 0x04, 0x01, 0x02, 0x01
  10152. };
  10153. byte buff4[] = { /* last extension has zero size */
  10154. 0x16, 0x03, 0x01, 0x00, 0xba, 0x01, 0x00, 0x00,
  10155. 0xb6, 0x03, 0x03, 0x83, 0xa3, 0xe6, 0xdc, 0x16, 0xa1, 0x43, 0xe9, 0x45,
  10156. 0x15, 0xbd, 0x64, 0xa9, 0xb6, 0x07, 0xb4, 0x50, 0xc6, 0xdd, 0xff, 0xc2,
  10157. 0xd3, 0x0d, 0x4f, 0x36, 0xb4, 0x41, 0x51, 0x61, 0xc1, 0xa5, 0x9e, 0x00,
  10158. 0x00, 0x28, 0xcc, 0x14, 0xcc, 0x13, 0xc0, 0x2b, 0xc0, 0x2f, 0x00, 0x9e,
  10159. 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x13, 0xc0, 0x14, 0xc0, 0x07, 0xc0, 0x11,
  10160. 0x00, 0x33, 0x00, 0x32, 0x00, 0x39, 0x00, 0x9c, 0x00, 0x2f, 0x00, 0x35,
  10161. 0x00, 0x0a, 0x00, 0x05, 0x00, 0x04, 0x01, 0x00, 0x00, 0x65, 0xff, 0x01,
  10162. 0x00, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06, 0x00, 0x17, 0x00,
  10163. 0x18, 0x00, 0x19, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x23, 0x00,
  10164. 0x00, 0x33, 0x74, 0x00, 0x00, 0x00, 0x10, 0x00, 0x1b, 0x00, 0x19, 0x06,
  10165. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33, 0x08, 0x73, 0x70, 0x64, 0x79, 0x2f,
  10166. 0x33, 0x2e, 0x31, 0x08, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31,
  10167. 0x75, 0x50, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00,
  10168. 0x00, 0x00, 0x0d, 0x00, 0x12, 0x00, 0x10, 0x04, 0x01, 0x05, 0x01, 0x02,
  10169. 0x01, 0x04, 0x03, 0x05, 0x03, 0x02, 0x03, 0x04, 0x02, 0x02, 0x02, 0x00,
  10170. 0x12, 0x00, 0x00
  10171. };
  10172. byte buff5[] = { /* SSL v2.0 client hello */
  10173. 0x00, 0x2b, 0x01, 0x03, 0x01, 0x00, 0x09, 0x00, 0x00,
  10174. /* dummy bytes below, just to pass size check */
  10175. 0xb6, 0x03, 0x03, 0x83, 0xa3, 0xe6, 0xdc, 0x16, 0xa1, 0x43, 0xe9, 0x45,
  10176. 0x15, 0xbd, 0x64, 0xa9, 0xb6, 0x07, 0xb4, 0x50, 0xc6, 0xdd, 0xff, 0xc2,
  10177. 0xd3, 0x0d, 0x4f, 0x36, 0xb4, 0x41, 0x51, 0x61, 0xc1, 0xa5, 0x9e, 0x00,
  10178. };
  10179. byte result[32] = {0};
  10180. word32 length = 32;
  10181. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff4, sizeof(buff4),
  10182. 0, result, &length));
  10183. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff3, sizeof(buff3),
  10184. 0, result, &length));
  10185. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff2, sizeof(buff2),
  10186. 1, result, &length));
  10187. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  10188. 0, result, &length));
  10189. buff[0] = 0x16;
  10190. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  10191. 0, result, &length));
  10192. buff[1] = 0x03;
  10193. ExpectIntEQ(WC_NO_ERR_TRACE(SNI_UNSUPPORTED), wolfSSL_SNI_GetFromBuffer(buff,
  10194. sizeof(buff), 0, result, &length));
  10195. buff[2] = 0x03;
  10196. ExpectIntEQ(WC_NO_ERR_TRACE(INCOMPLETE_DATA), wolfSSL_SNI_GetFromBuffer(buff,
  10197. sizeof(buff), 0, result, &length));
  10198. buff[4] = 0x64;
  10199. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  10200. 0, result, &length));
  10201. if (EXPECT_SUCCESS())
  10202. result[length] = 0;
  10203. ExpectStrEQ("www.paypal.com", (const char*) result);
  10204. length = 32;
  10205. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SNI_GetFromBuffer(buff2, sizeof(buff2),
  10206. 0, result, &length));
  10207. if (EXPECT_SUCCESS())
  10208. result[length] = 0;
  10209. ExpectStrEQ("api.textmate.org", (const char*) result);
  10210. /* SSL v2.0 tests */
  10211. ExpectIntEQ(WC_NO_ERR_TRACE(SNI_UNSUPPORTED), wolfSSL_SNI_GetFromBuffer(buff5,
  10212. sizeof(buff5), 0, result, &length));
  10213. buff5[2] = 0x02;
  10214. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  10215. sizeof(buff5), 0, result, &length));
  10216. buff5[2] = 0x01; buff5[6] = 0x08;
  10217. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  10218. sizeof(buff5), 0, result, &length));
  10219. buff5[6] = 0x09; buff5[8] = 0x01;
  10220. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  10221. sizeof(buff5), 0, result, &length));
  10222. return EXPECT_RESULT();
  10223. }
  10224. #endif /* HAVE_SNI */
  10225. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  10226. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \
  10227. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  10228. /* Dummy peer functions to satisfy the exporter/importer */
  10229. static int test_wolfSSL_dtls_export_peers_get_peer(WOLFSSL* ssl, char* ip,
  10230. int* ipSz, unsigned short* port, int* fam)
  10231. {
  10232. (void)ssl;
  10233. ip[0] = -1;
  10234. *ipSz = 1;
  10235. *port = 1;
  10236. *fam = 2;
  10237. return 1;
  10238. }
  10239. static int test_wolfSSL_dtls_export_peers_set_peer(WOLFSSL* ssl, char* ip,
  10240. int ipSz, unsigned short port, int fam)
  10241. {
  10242. (void)ssl;
  10243. if (ip[0] != -1 || ipSz != 1 || port != 1 || fam != 2)
  10244. return 0;
  10245. return 1;
  10246. }
  10247. static int test_wolfSSL_dtls_export_peers_on_handshake(WOLFSSL_CTX **ctx,
  10248. WOLFSSL **ssl)
  10249. {
  10250. EXPECT_DECLS;
  10251. unsigned char* sessionBuf = NULL;
  10252. unsigned int sessionSz = 0;
  10253. void* ioWriteCtx = wolfSSL_GetIOWriteCtx(*ssl);
  10254. void* ioReadCtx = wolfSSL_GetIOReadCtx(*ssl);
  10255. wolfSSL_CTX_SetIOGetPeer(*ctx, test_wolfSSL_dtls_export_peers_get_peer);
  10256. wolfSSL_CTX_SetIOSetPeer(*ctx, test_wolfSSL_dtls_export_peers_set_peer);
  10257. ExpectIntGE(wolfSSL_dtls_export(*ssl, NULL, &sessionSz), 0);
  10258. ExpectNotNull(sessionBuf =
  10259. (unsigned char*)XMALLOC(sessionSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  10260. ExpectIntGE(wolfSSL_dtls_export(*ssl, sessionBuf, &sessionSz), 0);
  10261. wolfSSL_free(*ssl);
  10262. *ssl = NULL;
  10263. ExpectNotNull(*ssl = wolfSSL_new(*ctx));
  10264. ExpectIntGE(wolfSSL_dtls_import(*ssl, sessionBuf, sessionSz), 0);
  10265. wolfSSL_SetIOWriteCtx(*ssl, ioWriteCtx);
  10266. wolfSSL_SetIOReadCtx(*ssl, ioReadCtx);
  10267. XFREE(sessionBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10268. return EXPECT_RESULT();
  10269. }
  10270. #endif
  10271. static int test_wolfSSL_dtls_export_peers(void)
  10272. {
  10273. EXPECT_DECLS;
  10274. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \
  10275. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  10276. test_ssl_cbf client_cbf;
  10277. test_ssl_cbf server_cbf;
  10278. size_t i, j;
  10279. struct test_params {
  10280. method_provider client_meth;
  10281. method_provider server_meth;
  10282. const char* dtls_version;
  10283. } params[] = {
  10284. #ifndef NO_OLD_TLS
  10285. {wolfDTLSv1_client_method, wolfDTLSv1_server_method, "1.0"},
  10286. #endif
  10287. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "1.2"},
  10288. /* TODO DTLS 1.3 exporting not supported
  10289. #ifdef WOLFSSL_DTLS13
  10290. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "1.3"},
  10291. #endif
  10292. */
  10293. };
  10294. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  10295. for (j = 0; j <= 0b11; j++) {
  10296. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  10297. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  10298. printf("\n\tTesting DTLS %s connection;", params[i].dtls_version);
  10299. client_cbf.method = params[i].client_meth;
  10300. server_cbf.method = params[i].server_meth;
  10301. if (j & 0b01) {
  10302. client_cbf.on_handshake =
  10303. test_wolfSSL_dtls_export_peers_on_handshake;
  10304. printf(" With client export;");
  10305. }
  10306. if (j & 0b10) {
  10307. server_cbf.on_handshake =
  10308. test_wolfSSL_dtls_export_peers_on_handshake;
  10309. printf(" With server export;");
  10310. }
  10311. printf("\n");
  10312. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  10313. &server_cbf, NULL), TEST_SUCCESS);
  10314. if (!EXPECT_SUCCESS())
  10315. break;
  10316. }
  10317. }
  10318. #endif
  10319. return EXPECT_RESULT();
  10320. }
  10321. static int test_wolfSSL_UseTrustedCA(void)
  10322. {
  10323. EXPECT_DECLS;
  10324. #if defined(HAVE_TRUSTED_CA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  10325. && !defined(NO_RSA)
  10326. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10327. WOLFSSL_CTX *ctx = NULL;
  10328. WOLFSSL *ssl = NULL;
  10329. byte id[20];
  10330. #ifndef NO_WOLFSSL_SERVER
  10331. ExpectNotNull((ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())));
  10332. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10333. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10334. #else
  10335. ExpectNotNull((ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())));
  10336. #endif
  10337. ExpectNotNull((ssl = wolfSSL_new(ctx)));
  10338. XMEMSET(id, 0, sizeof(id));
  10339. /* error cases */
  10340. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(NULL, 0, NULL, 0));
  10341. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10342. WOLFSSL_TRUSTED_CA_CERT_SHA1+1, NULL, 0));
  10343. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10344. WOLFSSL_TRUSTED_CA_CERT_SHA1, NULL, 0));
  10345. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10346. WOLFSSL_TRUSTED_CA_CERT_SHA1, id, 5));
  10347. #ifdef NO_SHA
  10348. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10349. WOLFSSL_TRUSTED_CA_KEY_SHA1, id, sizeof(id)));
  10350. #endif
  10351. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10352. WOLFSSL_TRUSTED_CA_X509_NAME, id, 0));
  10353. /* success cases */
  10354. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10355. WOLFSSL_TRUSTED_CA_PRE_AGREED, NULL, 0));
  10356. #ifndef NO_SHA
  10357. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10358. WOLFSSL_TRUSTED_CA_KEY_SHA1, id, sizeof(id)));
  10359. #endif
  10360. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10361. WOLFSSL_TRUSTED_CA_X509_NAME, id, 5));
  10362. wolfSSL_free(ssl);
  10363. wolfSSL_CTX_free(ctx);
  10364. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10365. #endif /* HAVE_TRUSTED_CA */
  10366. return EXPECT_RESULT();
  10367. }
  10368. static int test_wolfSSL_UseMaxFragment(void)
  10369. {
  10370. EXPECT_DECLS;
  10371. #if defined(HAVE_MAX_FRAGMENT) && !defined(NO_CERTS) && \
  10372. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  10373. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10374. #ifndef NO_WOLFSSL_SERVER
  10375. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  10376. #else
  10377. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10378. #endif
  10379. WOLFSSL *ssl = NULL;
  10380. #ifdef OPENSSL_EXTRA
  10381. int (*UseMaxFragment)(SSL *s, unsigned char mode);
  10382. int (*CTX_UseMaxFragment)(SSL_CTX *c, unsigned char mode);
  10383. #else
  10384. int (*UseMaxFragment)(WOLFSSL *s, unsigned char mode);
  10385. int (*CTX_UseMaxFragment)(WOLFSSL_CTX *c, unsigned char mode);
  10386. #endif
  10387. #ifndef NO_WOLFSSL_SERVER
  10388. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10389. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10390. #endif
  10391. ExpectNotNull(ctx);
  10392. ExpectNotNull(ssl = wolfSSL_new(ctx));
  10393. #ifdef OPENSSL_EXTRA
  10394. CTX_UseMaxFragment = SSL_CTX_set_tlsext_max_fragment_length;
  10395. UseMaxFragment = SSL_set_tlsext_max_fragment_length;
  10396. #else
  10397. UseMaxFragment = wolfSSL_UseMaxFragment;
  10398. CTX_UseMaxFragment = wolfSSL_CTX_UseMaxFragment;
  10399. #endif
  10400. /* error cases */
  10401. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(NULL, WOLFSSL_MFL_2_9));
  10402. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment( NULL, WOLFSSL_MFL_2_9));
  10403. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_MIN-1));
  10404. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_MAX+1));
  10405. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment(ssl, WOLFSSL_MFL_MIN-1));
  10406. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment(ssl, WOLFSSL_MFL_MAX+1));
  10407. /* success case */
  10408. #ifdef OPENSSL_EXTRA
  10409. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_8));
  10410. #else
  10411. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_8));
  10412. #endif
  10413. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_9));
  10414. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_10));
  10415. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_11));
  10416. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_12));
  10417. #ifdef OPENSSL_EXTRA
  10418. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_13));
  10419. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), UseMaxFragment( ssl, WOLFSSL_MFL_2_8));
  10420. #else
  10421. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_13));
  10422. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_8));
  10423. #endif
  10424. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_9));
  10425. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_10));
  10426. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_11));
  10427. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_12));
  10428. #ifdef OPENSSL_EXTRA
  10429. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), UseMaxFragment( ssl, WOLFSSL_MFL_2_13));
  10430. #else
  10431. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_13));
  10432. #endif
  10433. wolfSSL_free(ssl);
  10434. wolfSSL_CTX_free(ctx);
  10435. #if defined(OPENSSL_EXTRA) && defined(HAVE_MAX_FRAGMENT) && \
  10436. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  10437. /* check negotiated max fragment size */
  10438. {
  10439. WOLFSSL *ssl_c = NULL;
  10440. WOLFSSL *ssl_s = NULL;
  10441. struct test_memio_ctx test_ctx;
  10442. WOLFSSL_CTX *ctx_c = NULL;
  10443. WOLFSSL_CTX *ctx_s = NULL;
  10444. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  10445. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10446. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10447. ExpectIntEQ(wolfSSL_UseMaxFragment(ssl_c, WOLFSSL_MFL_2_8),
  10448. WOLFSSL_SUCCESS);
  10449. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10450. #ifndef NO_SESSION_CACHE
  10451. ExpectIntEQ(SSL_SESSION_get_max_fragment_length(
  10452. wolfSSL_get_session(ssl_c)), WOLFSSL_MFL_2_8);
  10453. #endif
  10454. wolfSSL_free(ssl_c);
  10455. wolfSSL_free(ssl_s);
  10456. wolfSSL_CTX_free(ctx_c);
  10457. wolfSSL_CTX_free(ctx_s);
  10458. }
  10459. #endif
  10460. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10461. #endif
  10462. return EXPECT_RESULT();
  10463. }
  10464. static int test_wolfSSL_UseTruncatedHMAC(void)
  10465. {
  10466. EXPECT_DECLS;
  10467. #if defined(HAVE_TRUNCATED_HMAC) && !defined(NO_CERTS) && \
  10468. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  10469. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10470. #ifndef NO_WOLFSSL_SERVER
  10471. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  10472. #else
  10473. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10474. #endif
  10475. WOLFSSL *ssl = NULL;
  10476. ExpectNotNull(ctx);
  10477. #ifndef NO_WOLFSSL_SERVER
  10478. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10479. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10480. #endif
  10481. ExpectNotNull(ssl = wolfSSL_new(ctx));
  10482. /* error cases */
  10483. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseTruncatedHMAC(NULL));
  10484. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTruncatedHMAC(NULL));
  10485. /* success case */
  10486. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseTruncatedHMAC(ctx));
  10487. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTruncatedHMAC(ssl));
  10488. wolfSSL_free(ssl);
  10489. wolfSSL_CTX_free(ctx);
  10490. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10491. #endif
  10492. return EXPECT_RESULT();
  10493. }
  10494. static int test_wolfSSL_UseSupportedCurve(void)
  10495. {
  10496. EXPECT_DECLS;
  10497. #if defined(HAVE_SUPPORTED_CURVES) && !defined(NO_WOLFSSL_CLIENT) && \
  10498. !defined(NO_TLS)
  10499. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10500. WOLFSSL *ssl = wolfSSL_new(ctx);
  10501. ExpectNotNull(ctx);
  10502. ExpectNotNull(ssl);
  10503. /* error cases */
  10504. ExpectIntNE(WOLFSSL_SUCCESS,
  10505. wolfSSL_CTX_UseSupportedCurve(NULL, WOLFSSL_ECC_SECP256R1));
  10506. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSupportedCurve(ctx, 0));
  10507. ExpectIntNE(WOLFSSL_SUCCESS,
  10508. wolfSSL_UseSupportedCurve(NULL, WOLFSSL_ECC_SECP256R1));
  10509. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSupportedCurve(ssl, 0));
  10510. /* success case */
  10511. ExpectIntEQ(WOLFSSL_SUCCESS,
  10512. wolfSSL_CTX_UseSupportedCurve(ctx, WOLFSSL_ECC_SECP256R1));
  10513. ExpectIntEQ(WOLFSSL_SUCCESS,
  10514. wolfSSL_UseSupportedCurve(ssl, WOLFSSL_ECC_SECP256R1));
  10515. wolfSSL_free(ssl);
  10516. wolfSSL_CTX_free(ctx);
  10517. #endif
  10518. return EXPECT_RESULT();
  10519. }
  10520. #if defined(HAVE_ALPN) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  10521. static void verify_ALPN_FATAL_ERROR_on_client(WOLFSSL* ssl)
  10522. {
  10523. AssertIntEQ(WC_NO_ERR_TRACE(UNKNOWN_ALPN_PROTOCOL_NAME_E), wolfSSL_get_error(ssl, 0));
  10524. }
  10525. static void use_ALPN_all(WOLFSSL* ssl)
  10526. {
  10527. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10528. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10529. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10530. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10531. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10532. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, alpn_list, sizeof(alpn_list),
  10533. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10534. }
  10535. static void use_ALPN_all_continue(WOLFSSL* ssl)
  10536. {
  10537. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10538. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10539. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10540. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10541. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10542. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, alpn_list, sizeof(alpn_list),
  10543. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10544. }
  10545. static void use_ALPN_one(WOLFSSL* ssl)
  10546. {
  10547. /* spdy/2 */
  10548. char proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10549. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10550. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10551. }
  10552. static void use_ALPN_unknown(WOLFSSL* ssl)
  10553. {
  10554. /* http/2.0 */
  10555. char proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x32, 0x2e, 0x30};
  10556. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10557. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10558. }
  10559. static void use_ALPN_unknown_continue(WOLFSSL* ssl)
  10560. {
  10561. /* http/2.0 */
  10562. char proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x32, 0x2e, 0x30};
  10563. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10564. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10565. }
  10566. static void verify_ALPN_not_matching_spdy3(WOLFSSL* ssl)
  10567. {
  10568. /* spdy/3 */
  10569. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10570. char *proto = NULL;
  10571. word16 protoSz = 0;
  10572. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10573. /* check value */
  10574. AssertIntNE(1, sizeof(nego_proto) == protoSz);
  10575. if (proto) {
  10576. AssertIntNE(0, XMEMCMP(nego_proto, proto, sizeof(nego_proto)));
  10577. }
  10578. }
  10579. static void verify_ALPN_not_matching_continue(WOLFSSL* ssl)
  10580. {
  10581. char *proto = NULL;
  10582. word16 protoSz = 0;
  10583. AssertIntEQ(WC_NO_ERR_TRACE(WOLFSSL_ALPN_NOT_FOUND),
  10584. wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10585. /* check value */
  10586. AssertIntEQ(1, (0 == protoSz));
  10587. AssertIntEQ(1, (NULL == proto));
  10588. }
  10589. static void verify_ALPN_matching_http1(WOLFSSL* ssl)
  10590. {
  10591. /* http/1.1 */
  10592. char nego_proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10593. char *proto;
  10594. word16 protoSz = 0;
  10595. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10596. /* check value */
  10597. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10598. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10599. }
  10600. static void verify_ALPN_matching_spdy2(WOLFSSL* ssl)
  10601. {
  10602. /* spdy/2 */
  10603. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10604. char *proto;
  10605. word16 protoSz = 0;
  10606. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10607. /* check value */
  10608. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10609. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10610. }
  10611. static void verify_ALPN_client_list(WOLFSSL* ssl)
  10612. {
  10613. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10614. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10615. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10616. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10617. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10618. char *clist = NULL;
  10619. word16 clistSz = 0;
  10620. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetPeerProtocol(ssl, &clist,
  10621. &clistSz));
  10622. /* check value */
  10623. AssertIntEQ(1, sizeof(alpn_list) == clistSz);
  10624. AssertIntEQ(0, XMEMCMP(alpn_list, clist, clistSz));
  10625. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_FreePeerProtocol(ssl, &clist));
  10626. }
  10627. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  10628. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)
  10629. /* ALPN select callback, success with spdy/2 */
  10630. static int select_ALPN_spdy2(WOLFSSL *ssl, const unsigned char **out,
  10631. unsigned char *outlen, const unsigned char *in,
  10632. unsigned int inlen, void *arg)
  10633. {
  10634. /* spdy/2 */
  10635. const char proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10636. (void)ssl;
  10637. (void)arg;
  10638. /* adding +1 since LEN byte comes first */
  10639. if (inlen < sizeof(proto) + 1) {
  10640. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10641. }
  10642. if (XMEMCMP(in + 1, proto, sizeof(proto)) == 0) {
  10643. *out = in + 1;
  10644. *outlen = (unsigned char)sizeof(proto);
  10645. return SSL_TLSEXT_ERR_OK;
  10646. }
  10647. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10648. }
  10649. /* ALPN select callback, force failure */
  10650. static int select_ALPN_failure(WOLFSSL *ssl, const unsigned char **out,
  10651. unsigned char *outlen, const unsigned char *in,
  10652. unsigned int inlen, void *arg)
  10653. {
  10654. (void)ssl;
  10655. (void)out;
  10656. (void)outlen;
  10657. (void)in;
  10658. (void)inlen;
  10659. (void)arg;
  10660. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10661. }
  10662. static void use_ALPN_spdy2_callback(WOLFSSL* ssl)
  10663. {
  10664. wolfSSL_set_alpn_select_cb(ssl, select_ALPN_spdy2, NULL);
  10665. }
  10666. static void use_ALPN_failure_callback(WOLFSSL* ssl)
  10667. {
  10668. wolfSSL_set_alpn_select_cb(ssl, select_ALPN_failure, NULL);
  10669. }
  10670. #endif /* OPENSSL_ALL | NGINX | HAPROXY | LIGHTY | QUIC */
  10671. static int test_wolfSSL_UseALPN_connection(void)
  10672. {
  10673. int res = TEST_SKIPPED;
  10674. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  10675. callback_functions client_cb;
  10676. callback_functions server_cb;
  10677. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  10678. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  10679. client_cb.method = wolfSSLv23_client_method;
  10680. server_cb.method = wolfSSLv23_server_method;
  10681. client_cb.devId = testDevId;
  10682. server_cb.devId = testDevId;
  10683. /* success case same list */
  10684. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10685. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_matching_http1;
  10686. test_wolfSSL_client_server(&client_cb, &server_cb);
  10687. /* success case only one for server */
  10688. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10689. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_one; server_cb.on_result = verify_ALPN_matching_spdy2;
  10690. test_wolfSSL_client_server(&client_cb, &server_cb);
  10691. /* success case only one for client */
  10692. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_one; client_cb.on_result = NULL;
  10693. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_matching_spdy2;
  10694. test_wolfSSL_client_server(&client_cb, &server_cb);
  10695. /* success case none for client */
  10696. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10697. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = NULL;
  10698. test_wolfSSL_client_server(&client_cb, &server_cb);
  10699. /* success case mismatch behavior but option 'continue' set */
  10700. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all_continue; client_cb.on_result = verify_ALPN_not_matching_continue;
  10701. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_unknown_continue; server_cb.on_result = NULL;
  10702. test_wolfSSL_client_server(&client_cb, &server_cb);
  10703. /* success case read protocol send by client */
  10704. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10705. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_one; server_cb.on_result = verify_ALPN_client_list;
  10706. test_wolfSSL_client_server(&client_cb, &server_cb);
  10707. /* mismatch behavior with same list
  10708. * the first and only this one must be taken */
  10709. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10710. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_not_matching_spdy3;
  10711. test_wolfSSL_client_server(&client_cb, &server_cb);
  10712. /* default mismatch behavior */
  10713. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10714. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_unknown; server_cb.on_result = verify_ALPN_FATAL_ERROR_on_client;
  10715. test_wolfSSL_client_server(&client_cb, &server_cb);
  10716. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  10717. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)
  10718. /* WOLFSSL-level ALPN select callback tests */
  10719. /* Callback: success (one protocol, spdy/2) */
  10720. client_cb.ctx_ready = NULL;
  10721. client_cb.ssl_ready = use_ALPN_one;
  10722. client_cb.on_result = verify_ALPN_matching_spdy2;
  10723. server_cb.ctx_ready = NULL;
  10724. server_cb.ssl_ready = use_ALPN_spdy2_callback;
  10725. server_cb.on_result = verify_ALPN_matching_spdy2;
  10726. test_wolfSSL_client_server(&client_cb, &server_cb);
  10727. /* Callback: failure (one client protocol, spdy/2) */
  10728. client_cb.ctx_ready = NULL;
  10729. client_cb.ssl_ready = use_ALPN_one;
  10730. client_cb.on_result = NULL;
  10731. server_cb.ctx_ready = NULL;
  10732. server_cb.ssl_ready = use_ALPN_failure_callback;
  10733. server_cb.on_result = verify_ALPN_FATAL_ERROR_on_client;
  10734. test_wolfSSL_client_server(&client_cb, &server_cb);
  10735. #endif /* OPENSSL_ALL | NGINX | HAPROXY | LIGHTY */
  10736. res = TEST_RES_CHECK(1);
  10737. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  10738. return res;
  10739. }
  10740. static int test_wolfSSL_UseALPN_params(void)
  10741. {
  10742. EXPECT_DECLS;
  10743. #ifndef NO_WOLFSSL_CLIENT
  10744. /* "http/1.1" */
  10745. char http1[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10746. /* "spdy/1" */
  10747. char spdy1[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x31};
  10748. /* "spdy/2" */
  10749. char spdy2[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10750. /* "spdy/3" */
  10751. char spdy3[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10752. char buff[256];
  10753. word32 idx;
  10754. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10755. WOLFSSL *ssl = wolfSSL_new(ctx);
  10756. ExpectNotNull(ctx);
  10757. ExpectNotNull(ssl);
  10758. /* error cases */
  10759. ExpectIntNE(WOLFSSL_SUCCESS,
  10760. wolfSSL_UseALPN(NULL, http1, sizeof(http1),
  10761. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10762. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, NULL, 0,
  10763. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10764. /* success case */
  10765. /* http1 only */
  10766. ExpectIntEQ(WOLFSSL_SUCCESS,
  10767. wolfSSL_UseALPN(ssl, http1, sizeof(http1),
  10768. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10769. /* http1, spdy1 */
  10770. XMEMCPY(buff, http1, sizeof(http1));
  10771. idx = sizeof(http1);
  10772. buff[idx++] = ',';
  10773. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10774. idx += sizeof(spdy1);
  10775. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10776. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10777. /* http1, spdy2, spdy1 */
  10778. XMEMCPY(buff, http1, sizeof(http1));
  10779. idx = sizeof(http1);
  10780. buff[idx++] = ',';
  10781. XMEMCPY(buff+idx, spdy2, sizeof(spdy2));
  10782. idx += sizeof(spdy2);
  10783. buff[idx++] = ',';
  10784. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10785. idx += sizeof(spdy1);
  10786. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10787. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10788. /* spdy3, http1, spdy2, spdy1 */
  10789. XMEMCPY(buff, spdy3, sizeof(spdy3));
  10790. idx = sizeof(spdy3);
  10791. buff[idx++] = ',';
  10792. XMEMCPY(buff+idx, http1, sizeof(http1));
  10793. idx += sizeof(http1);
  10794. buff[idx++] = ',';
  10795. XMEMCPY(buff+idx, spdy2, sizeof(spdy2));
  10796. idx += sizeof(spdy2);
  10797. buff[idx++] = ',';
  10798. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10799. idx += sizeof(spdy1);
  10800. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10801. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10802. wolfSSL_free(ssl);
  10803. wolfSSL_CTX_free(ctx);
  10804. #endif
  10805. return EXPECT_RESULT();
  10806. }
  10807. #endif /* HAVE_ALPN */
  10808. #ifdef HAVE_ALPN_PROTOS_SUPPORT
  10809. static void CTX_set_alpn_protos(SSL_CTX *ctx)
  10810. {
  10811. unsigned char p[] = {
  10812. 8, 'h', 't', 't', 'p', '/', '1', '.', '1',
  10813. 6, 's', 'p', 'd', 'y', '/', '2',
  10814. 6, 's', 'p', 'd', 'y', '/', '1',
  10815. };
  10816. unsigned char p_len = sizeof(p);
  10817. int ret;
  10818. ret = SSL_CTX_set_alpn_protos(ctx, p, p_len);
  10819. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  10820. AssertIntEQ(ret, 0);
  10821. #else
  10822. AssertIntEQ(ret, SSL_SUCCESS);
  10823. #endif
  10824. }
  10825. static void set_alpn_protos(SSL* ssl)
  10826. {
  10827. unsigned char p[] = {
  10828. 6, 's', 'p', 'd', 'y', '/', '3',
  10829. 8, 'h', 't', 't', 'p', '/', '1', '.', '1',
  10830. 6, 's', 'p', 'd', 'y', '/', '2',
  10831. 6, 's', 'p', 'd', 'y', '/', '1',
  10832. };
  10833. unsigned char p_len = sizeof(p);
  10834. int ret;
  10835. ret = SSL_set_alpn_protos(ssl, p, p_len);
  10836. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  10837. AssertIntEQ(ret, 0);
  10838. #else
  10839. AssertIntEQ(ret, SSL_SUCCESS);
  10840. #endif
  10841. }
  10842. static void verify_alpn_matching_spdy3(WOLFSSL* ssl)
  10843. {
  10844. /* "spdy/3" */
  10845. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10846. const unsigned char *proto;
  10847. unsigned int protoSz = 0;
  10848. SSL_get0_alpn_selected(ssl, &proto, &protoSz);
  10849. /* check value */
  10850. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10851. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10852. }
  10853. static void verify_alpn_matching_http1(WOLFSSL* ssl)
  10854. {
  10855. /* "http/1.1" */
  10856. char nego_proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10857. const unsigned char *proto;
  10858. unsigned int protoSz = 0;
  10859. SSL_get0_alpn_selected(ssl, &proto, &protoSz);
  10860. /* check value */
  10861. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10862. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10863. }
  10864. static int test_wolfSSL_set_alpn_protos(void)
  10865. {
  10866. int res = TEST_SKIPPED;
  10867. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  10868. callback_functions client_cb;
  10869. callback_functions server_cb;
  10870. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  10871. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  10872. client_cb.method = wolfSSLv23_client_method;
  10873. server_cb.method = wolfSSLv23_server_method;
  10874. client_cb.devId = testDevId;
  10875. server_cb.devId = testDevId;
  10876. /* use CTX_alpn_protos */
  10877. client_cb.ctx_ready = CTX_set_alpn_protos; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10878. server_cb.ctx_ready = CTX_set_alpn_protos; server_cb.ssl_ready = NULL; server_cb.on_result = verify_alpn_matching_http1;
  10879. test_wolfSSL_client_server(&client_cb, &server_cb);
  10880. /* use set_alpn_protos */
  10881. client_cb.ctx_ready = NULL; client_cb.ssl_ready = set_alpn_protos; client_cb.on_result = NULL;
  10882. server_cb.ctx_ready = NULL; server_cb.ssl_ready = set_alpn_protos; server_cb.on_result = verify_alpn_matching_spdy3;
  10883. test_wolfSSL_client_server(&client_cb, &server_cb);
  10884. res = TEST_SUCCESS;
  10885. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  10886. return res;
  10887. }
  10888. #endif /* HAVE_ALPN_PROTOS_SUPPORT */
  10889. static int test_wolfSSL_DisableExtendedMasterSecret(void)
  10890. {
  10891. EXPECT_DECLS;
  10892. #if defined(HAVE_EXTENDED_MASTER) && !defined(NO_WOLFSSL_CLIENT)
  10893. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10894. WOLFSSL *ssl = wolfSSL_new(ctx);
  10895. ExpectNotNull(ctx);
  10896. ExpectNotNull(ssl);
  10897. /* error cases */
  10898. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_DisableExtendedMasterSecret(NULL));
  10899. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_DisableExtendedMasterSecret(NULL));
  10900. /* success cases */
  10901. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_DisableExtendedMasterSecret(ctx));
  10902. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_DisableExtendedMasterSecret(ssl));
  10903. wolfSSL_free(ssl);
  10904. wolfSSL_CTX_free(ctx);
  10905. #endif
  10906. return EXPECT_RESULT();
  10907. }
  10908. static int test_wolfSSL_wolfSSL_UseSecureRenegotiation(void)
  10909. {
  10910. EXPECT_DECLS;
  10911. #if defined(HAVE_SECURE_RENEGOTIATION) && !defined(NO_WOLFSSL_CLIENT)
  10912. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10913. WOLFSSL *ssl = wolfSSL_new(ctx);
  10914. ExpectNotNull(ctx);
  10915. ExpectNotNull(ssl);
  10916. /* error cases */
  10917. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(NULL));
  10918. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(NULL));
  10919. /* success cases */
  10920. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx));
  10921. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl));
  10922. wolfSSL_free(ssl);
  10923. wolfSSL_CTX_free(ctx);
  10924. #endif
  10925. return EXPECT_RESULT();
  10926. }
  10927. /* Test reconnecting with a different ciphersuite after a renegotiation. */
  10928. static int test_wolfSSL_SCR_Reconnect(void)
  10929. {
  10930. EXPECT_DECLS;
  10931. #if defined(HAVE_SECURE_RENEGOTIATION) && \
  10932. defined(BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) && \
  10933. defined(BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256) && \
  10934. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  10935. struct test_memio_ctx test_ctx;
  10936. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  10937. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  10938. byte data;
  10939. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  10940. test_ctx.c_ciphers = "ECDHE-RSA-AES256-GCM-SHA384";
  10941. test_ctx.s_ciphers =
  10942. "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305";
  10943. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10944. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10945. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx_c));
  10946. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx_s));
  10947. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl_c));
  10948. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl_s));
  10949. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10950. /* WOLFSSL_FATAL_ERROR since it will block */
  10951. ExpectIntEQ(wolfSSL_Rehandshake(ssl_s), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  10952. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  10953. WOLFSSL_ERROR_WANT_READ);
  10954. ExpectIntEQ(wolfSSL_read(ssl_c, &data, 1), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  10955. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  10956. WOLFSSL_ERROR_WANT_READ);
  10957. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10958. wolfSSL_free(ssl_c);
  10959. ssl_c = NULL;
  10960. wolfSSL_free(ssl_s);
  10961. ssl_s = NULL;
  10962. wolfSSL_CTX_free(ctx_c);
  10963. ctx_c = NULL;
  10964. test_ctx.c_ciphers = "ECDHE-RSA-CHACHA20-POLY1305";
  10965. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10966. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10967. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10968. wolfSSL_free(ssl_s);
  10969. wolfSSL_free(ssl_c);
  10970. wolfSSL_CTX_free(ctx_s);
  10971. wolfSSL_CTX_free(ctx_c);
  10972. #endif
  10973. return EXPECT_RESULT();
  10974. }
  10975. #if !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_SERVER) && \
  10976. (!defined(NO_RSA) || defined(HAVE_ECC))
  10977. /* Called when writing. */
  10978. static int DummySend(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  10979. {
  10980. (void)ssl;
  10981. (void)buf;
  10982. (void)sz;
  10983. (void)ctx;
  10984. /* Force error return from wolfSSL_accept_TLSv13(). */
  10985. return WANT_WRITE;
  10986. }
  10987. /* Called when reading. */
  10988. static int BufferInfoRecv(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  10989. {
  10990. WOLFSSL_BUFFER_INFO* msg = (WOLFSSL_BUFFER_INFO*)ctx;
  10991. int len = (int)msg->length;
  10992. (void)ssl;
  10993. (void)sz;
  10994. /* Pass back as much of message as will fit in buffer. */
  10995. if (len > sz)
  10996. len = sz;
  10997. XMEMCPY(buf, msg->buffer, len);
  10998. /* Move over returned data. */
  10999. msg->buffer += len;
  11000. msg->length -= (word32)len;
  11001. /* Amount actually copied. */
  11002. return len;
  11003. }
  11004. #endif
  11005. /* Test the detection of duplicate known TLS extensions.
  11006. * Specifically in a ClientHello.
  11007. */
  11008. static int test_tls_ext_duplicate(void)
  11009. {
  11010. EXPECT_DECLS;
  11011. #if !defined(NO_WOLFSSL_SERVER) && (!defined(NO_RSA) || defined(HAVE_ECC)) && \
  11012. !defined(NO_FILESYSTEM)
  11013. const unsigned char clientHelloDupTlsExt[] = {
  11014. 0x16, 0x03, 0x03, 0x00, 0x6a, 0x01, 0x00, 0x00,
  11015. 0x66, 0x03, 0x03, 0xf4, 0x65, 0xbd, 0x22, 0xfe,
  11016. 0x6e, 0xab, 0x66, 0xdd, 0xcf, 0xe9, 0x65, 0x55,
  11017. 0xe8, 0xdf, 0xc3, 0x8e, 0x4b, 0x00, 0xbc, 0xf8,
  11018. 0x23, 0x57, 0x1b, 0xa0, 0xc8, 0xa9, 0xe2, 0x8c,
  11019. 0x91, 0x6e, 0xf9, 0x20, 0xf7, 0x5c, 0xc5, 0x5b,
  11020. 0x75, 0x8c, 0x47, 0x0a, 0x0e, 0xc4, 0x1a, 0xda,
  11021. 0xef, 0x75, 0xe5, 0x21, 0x00, 0x00, 0x00, 0x00,
  11022. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  11023. 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x13, 0x01,
  11024. 0x00, 0x9e, 0x01, 0x00,
  11025. /* Extensions - duplicate signature algorithms. */
  11026. 0x00, 0x19, 0x00, 0x0d,
  11027. 0x00, 0x04, 0x00, 0x02, 0x04, 0x01, 0x00, 0x0d,
  11028. 0x00, 0x04, 0x00, 0x02, 0x04, 0x01,
  11029. /* Supported Versions extension for TLS 1.3. */
  11030. 0x00, 0x2b,
  11031. 0x00, 0x05, 0x04, 0x03, 0x04, 0x03, 0x03
  11032. };
  11033. WOLFSSL_BUFFER_INFO msg;
  11034. const char* testCertFile;
  11035. const char* testKeyFile;
  11036. WOLFSSL_CTX *ctx = NULL;
  11037. WOLFSSL *ssl = NULL;
  11038. #ifndef NO_RSA
  11039. testCertFile = svrCertFile;
  11040. testKeyFile = svrKeyFile;
  11041. #elif defined(HAVE_ECC)
  11042. testCertFile = eccCertFile;
  11043. testKeyFile = eccKeyFile;
  11044. #endif
  11045. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11046. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  11047. WOLFSSL_FILETYPE_PEM));
  11048. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  11049. WOLFSSL_FILETYPE_PEM));
  11050. /* Read from 'msg'. */
  11051. wolfSSL_SetIORecv(ctx, BufferInfoRecv);
  11052. /* No where to send to - dummy sender. */
  11053. wolfSSL_SetIOSend(ctx, DummySend);
  11054. ssl = wolfSSL_new(ctx);
  11055. ExpectNotNull(ssl);
  11056. msg.buffer = (unsigned char*)clientHelloDupTlsExt;
  11057. msg.length = (unsigned int)sizeof(clientHelloDupTlsExt);
  11058. wolfSSL_SetIOReadCtx(ssl, &msg);
  11059. ExpectIntNE(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  11060. /* can return duplicate ext error or socket error if the peer closed down
  11061. * while sending alert */
  11062. if (wolfSSL_get_error(ssl, 0) != WC_NO_ERR_TRACE(SOCKET_ERROR_E)) {
  11063. ExpectIntEQ(wolfSSL_get_error(ssl, 0), WC_NO_ERR_TRACE(DUPLICATE_TLS_EXT_E));
  11064. }
  11065. wolfSSL_free(ssl);
  11066. wolfSSL_CTX_free(ctx);
  11067. #endif
  11068. return EXPECT_RESULT();
  11069. }
  11070. /*----------------------------------------------------------------------------*
  11071. | X509 Tests
  11072. *----------------------------------------------------------------------------*/
  11073. static int test_wolfSSL_X509_NAME_get_entry(void)
  11074. {
  11075. EXPECT_DECLS;
  11076. #if !defined(NO_CERTS) && !defined(NO_RSA)
  11077. #if defined(OPENSSL_ALL) || \
  11078. (defined(OPENSSL_EXTRA) && \
  11079. (defined(KEEP_PEER_CERT) || defined(SESSION_CERTS)))
  11080. /* use openssl like name to test mapping */
  11081. X509_NAME_ENTRY* ne = NULL;
  11082. X509_NAME* name = NULL;
  11083. X509* x509 = NULL;
  11084. #ifndef NO_FILESYSTEM
  11085. ASN1_STRING* asn = NULL;
  11086. char* subCN = NULL;
  11087. #endif
  11088. int idx = 0;
  11089. ASN1_OBJECT *object = NULL;
  11090. #if defined(WOLFSSL_APACHE_HTTPD) || defined(OPENSSL_ALL) || \
  11091. defined(WOLFSSL_NGINX)
  11092. #ifndef NO_BIO
  11093. BIO* bio = NULL;
  11094. #endif
  11095. #endif
  11096. #ifndef NO_FILESYSTEM
  11097. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  11098. WOLFSSL_FILETYPE_PEM));
  11099. ExpectNotNull(name = X509_get_subject_name(x509));
  11100. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  11101. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  11102. ExpectNotNull(asn = X509_NAME_ENTRY_get_data(ne));
  11103. ExpectNotNull(subCN = (char*)ASN1_STRING_data(asn));
  11104. wolfSSL_FreeX509(x509);
  11105. x509 = NULL;
  11106. #endif
  11107. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  11108. WOLFSSL_FILETYPE_PEM));
  11109. ExpectNotNull(name = X509_get_subject_name(x509));
  11110. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  11111. #if defined(WOLFSSL_APACHE_HTTPD) || defined(OPENSSL_ALL) || \
  11112. defined(WOLFSSL_NGINX)
  11113. #ifndef NO_BIO
  11114. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  11115. ExpectIntEQ(X509_NAME_print_ex(bio, name, 4,
  11116. (XN_FLAG_RFC2253 & ~XN_FLAG_DN_REV)), WOLFSSL_SUCCESS);
  11117. ExpectIntEQ(X509_NAME_print_ex_fp(stderr, name, 4,
  11118. (XN_FLAG_RFC2253 & ~XN_FLAG_DN_REV)), WOLFSSL_SUCCESS);
  11119. BIO_free(bio);
  11120. #endif
  11121. #endif
  11122. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  11123. ExpectNotNull(object = X509_NAME_ENTRY_get_object(ne));
  11124. wolfSSL_FreeX509(x509);
  11125. #endif /* OPENSSL_ALL || (OPENSSL_EXTRA && (KEEP_PEER_CERT || SESSION_CERTS) */
  11126. #endif /* !NO_CERTS && !NO_RSA */
  11127. return EXPECT_RESULT();
  11128. }
  11129. /* Testing functions dealing with PKCS12 parsing out X509 certs */
  11130. static int test_wolfSSL_PKCS12(void)
  11131. {
  11132. EXPECT_DECLS;
  11133. /* .p12 file is encrypted with DES3 */
  11134. #ifndef HAVE_FIPS /* Password used in cert "wolfSSL test" is only 12-bytes
  11135. * (96-bit) FIPS mode requires Minimum of 14-byte (112-bit)
  11136. * Password Key
  11137. */
  11138. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3) && !defined(NO_FILESYSTEM) && \
  11139. !defined(NO_STDIO_FILESYSTEM) && \
  11140. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_RSA) && \
  11141. !defined(NO_SHA) && defined(HAVE_PKCS12) && !defined(NO_BIO)
  11142. byte buf[6000];
  11143. char file[] = "./certs/test-servercert.p12";
  11144. char order[] = "./certs/ecc-rsa-server.p12";
  11145. #ifdef WC_RC2
  11146. char rc2p12[] = "./certs/test-servercert-rc2.p12";
  11147. #endif
  11148. char pass[] = "a password";
  11149. const char goodPsw[] = "wolfSSL test";
  11150. const char badPsw[] = "bad";
  11151. #ifdef HAVE_ECC
  11152. WOLFSSL_X509_NAME *subject = NULL;
  11153. WOLFSSL_X509 *x509 = NULL;
  11154. #endif
  11155. XFILE f = XBADFILE;
  11156. int bytes = 0, ret = 0, goodPswLen = 0, badPswLen = 0;
  11157. WOLFSSL_BIO *bio = NULL;
  11158. WOLFSSL_EVP_PKEY *pkey = NULL;
  11159. WC_PKCS12 *pkcs12 = NULL;
  11160. WC_PKCS12 *pkcs12_2 = NULL;
  11161. WOLFSSL_X509 *cert = NULL;
  11162. WOLFSSL_X509 *tmp = NULL;
  11163. WOLF_STACK_OF(WOLFSSL_X509) *ca = NULL;
  11164. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  11165. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  11166. WOLFSSL_CTX *ctx = NULL;
  11167. WOLFSSL *ssl = NULL;
  11168. WOLF_STACK_OF(WOLFSSL_X509) *tmp_ca = NULL;
  11169. #endif
  11170. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  11171. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  11172. if (f != XBADFILE) {
  11173. XFCLOSE(f);
  11174. f = XBADFILE;
  11175. }
  11176. goodPswLen = (int)XSTRLEN(goodPsw);
  11177. badPswLen = (int)XSTRLEN(badPsw);
  11178. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  11179. ExpectIntEQ(BIO_write(bio, buf, bytes), bytes); /* d2i consumes BIO */
  11180. ExpectNotNull(d2i_PKCS12_bio(bio, &pkcs12));
  11181. ExpectNotNull(pkcs12);
  11182. BIO_free(bio);
  11183. bio = NULL;
  11184. /* check verify MAC directly */
  11185. ExpectIntEQ(ret = PKCS12_verify_mac(pkcs12, goodPsw, goodPswLen), 1);
  11186. /* check verify MAC fail case directly */
  11187. ExpectIntEQ(ret = PKCS12_verify_mac(pkcs12, badPsw, badPswLen), 0);
  11188. /* check verify MAC fail case */
  11189. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  11190. ExpectNull(pkey);
  11191. ExpectNull(cert);
  11192. /* check parse with no extra certs kept */
  11193. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  11194. 1);
  11195. ExpectNotNull(pkey);
  11196. ExpectNotNull(cert);
  11197. wolfSSL_EVP_PKEY_free(pkey);
  11198. pkey = NULL;
  11199. wolfSSL_X509_free(cert);
  11200. cert = NULL;
  11201. /* check parse with extra certs kept */
  11202. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11203. 1);
  11204. ExpectNotNull(pkey);
  11205. ExpectNotNull(cert);
  11206. ExpectNotNull(ca);
  11207. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  11208. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  11209. /* Check that SSL_CTX_set0_chain correctly sets the certChain buffer */
  11210. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11211. #if !defined(NO_WOLFSSL_CLIENT) && defined(SESSION_CERTS)
  11212. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11213. #else
  11214. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11215. #endif
  11216. /* Copy stack structure */
  11217. ExpectNotNull(tmp_ca = X509_chain_up_ref(ca));
  11218. ExpectIntEQ(SSL_CTX_set0_chain(ctx, tmp_ca), 1);
  11219. /* CTX now owns the tmp_ca stack structure */
  11220. tmp_ca = NULL;
  11221. ExpectIntEQ(wolfSSL_CTX_get_extra_chain_certs(ctx, &tmp_ca), 1);
  11222. ExpectNotNull(tmp_ca);
  11223. ExpectIntEQ(sk_X509_num(tmp_ca), sk_X509_num(ca));
  11224. /* Check that the main cert is also set */
  11225. ExpectNotNull(SSL_CTX_get0_certificate(ctx));
  11226. ExpectNotNull(ssl = SSL_new(ctx));
  11227. ExpectNotNull(SSL_get_certificate(ssl));
  11228. SSL_free(ssl);
  11229. SSL_CTX_free(ctx);
  11230. ctx = NULL;
  11231. #endif
  11232. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11233. /* should be 2 other certs on stack */
  11234. ExpectNotNull(tmp = sk_X509_pop(ca));
  11235. X509_free(tmp);
  11236. ExpectNotNull(tmp = sk_X509_pop(ca));
  11237. X509_free(tmp);
  11238. ExpectNull(sk_X509_pop(ca));
  11239. EVP_PKEY_free(pkey);
  11240. pkey = NULL;
  11241. X509_free(cert);
  11242. cert = NULL;
  11243. sk_X509_pop_free(ca, X509_free);
  11244. ca = NULL;
  11245. /* check PKCS12_create */
  11246. ExpectNull(PKCS12_create(pass, NULL, NULL, NULL, NULL, -1, -1, -1, -1,0));
  11247. ExpectIntEQ(PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11248. SSL_SUCCESS);
  11249. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, ca,
  11250. -1, -1, 100, -1, 0)));
  11251. EVP_PKEY_free(pkey);
  11252. pkey = NULL;
  11253. X509_free(cert);
  11254. cert = NULL;
  11255. sk_X509_pop_free(ca, NULL);
  11256. ca = NULL;
  11257. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11258. SSL_SUCCESS);
  11259. PKCS12_free(pkcs12_2);
  11260. pkcs12_2 = NULL;
  11261. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, ca,
  11262. NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
  11263. NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
  11264. 2000, 1, 0)));
  11265. EVP_PKEY_free(pkey);
  11266. pkey = NULL;
  11267. X509_free(cert);
  11268. cert = NULL;
  11269. sk_X509_pop_free(ca, NULL);
  11270. ca = NULL;
  11271. /* convert to DER then back and parse */
  11272. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  11273. ExpectIntEQ(i2d_PKCS12_bio(bio, pkcs12_2), SSL_SUCCESS);
  11274. PKCS12_free(pkcs12_2);
  11275. pkcs12_2 = NULL;
  11276. ExpectNotNull(pkcs12_2 = d2i_PKCS12_bio(bio, NULL));
  11277. BIO_free(bio);
  11278. bio = NULL;
  11279. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11280. SSL_SUCCESS);
  11281. /* should be 2 other certs on stack */
  11282. ExpectNotNull(tmp = sk_X509_pop(ca));
  11283. X509_free(tmp);
  11284. ExpectNotNull(tmp = sk_X509_pop(ca));
  11285. X509_free(tmp);
  11286. ExpectNull(sk_X509_pop(ca));
  11287. #ifndef NO_RC4
  11288. PKCS12_free(pkcs12_2);
  11289. pkcs12_2 = NULL;
  11290. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, NULL,
  11291. NID_pbe_WithSHA1And128BitRC4,
  11292. NID_pbe_WithSHA1And128BitRC4,
  11293. 2000, 1, 0)));
  11294. EVP_PKEY_free(pkey);
  11295. pkey = NULL;
  11296. X509_free(cert);
  11297. cert = NULL;
  11298. sk_X509_pop_free(ca, NULL);
  11299. ca = NULL;
  11300. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11301. SSL_SUCCESS);
  11302. #endif /* NO_RC4 */
  11303. EVP_PKEY_free(pkey);
  11304. pkey = NULL;
  11305. X509_free(cert);
  11306. cert = NULL;
  11307. PKCS12_free(pkcs12);
  11308. pkcs12 = NULL;
  11309. PKCS12_free(pkcs12_2);
  11310. pkcs12_2 = NULL;
  11311. sk_X509_pop_free(ca, NULL);
  11312. ca = NULL;
  11313. #ifdef HAVE_ECC
  11314. /* test order of parsing */
  11315. ExpectTrue((f = XFOPEN(order, "rb")) != XBADFILE);
  11316. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  11317. if (f != XBADFILE) {
  11318. XFCLOSE(f);
  11319. f = XBADFILE;
  11320. }
  11321. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  11322. ExpectNotNull(pkcs12 = d2i_PKCS12_bio(bio, NULL));
  11323. ExpectIntEQ((ret = PKCS12_parse(pkcs12, "", &pkey, &cert, &ca)),
  11324. WOLFSSL_SUCCESS);
  11325. /* check use of pkey after parse */
  11326. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  11327. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  11328. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11329. #if !defined(NO_WOLFSSL_CLIENT) && defined(SESSION_CERTS)
  11330. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11331. #else
  11332. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11333. #endif
  11334. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  11335. SSL_CTX_free(ctx);
  11336. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11337. #endif
  11338. ExpectNotNull(pkey);
  11339. ExpectNotNull(cert);
  11340. ExpectNotNull(ca);
  11341. /* compare subject lines of certificates */
  11342. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(cert));
  11343. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccRsaCertFile,
  11344. SSL_FILETYPE_PEM));
  11345. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11346. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11347. X509_free(x509);
  11348. x509 = NULL;
  11349. /* test expected fail case */
  11350. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccCertFile,
  11351. SSL_FILETYPE_PEM));
  11352. ExpectIntNE(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11353. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11354. X509_free(x509);
  11355. x509 = NULL;
  11356. X509_free(cert);
  11357. cert = NULL;
  11358. /* get subject line from ca stack */
  11359. ExpectNotNull(cert = sk_X509_pop(ca));
  11360. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(cert));
  11361. /* compare subject from certificate in ca to expected */
  11362. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccCertFile,
  11363. SSL_FILETYPE_PEM));
  11364. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11365. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11366. /* modify case and compare subject from certificate in ca to expected.
  11367. * The first bit of the name is:
  11368. * /C=US/ST=Washington
  11369. * So we'll change subject->name[1] to 'c' (lower case) */
  11370. if (subject != NULL) {
  11371. subject->name[1] = 'c';
  11372. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11373. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11374. }
  11375. EVP_PKEY_free(pkey);
  11376. pkey = NULL;
  11377. X509_free(x509);
  11378. x509 = NULL;
  11379. X509_free(cert);
  11380. cert = NULL;
  11381. BIO_free(bio);
  11382. bio = NULL;
  11383. PKCS12_free(pkcs12);
  11384. pkcs12 = NULL;
  11385. sk_X509_pop_free(ca, NULL); /* TEST d2i_PKCS12_fp */
  11386. ca = NULL;
  11387. /* test order of parsing */
  11388. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  11389. ExpectNotNull(pkcs12 = d2i_PKCS12_fp(f, NULL));
  11390. if (f != XBADFILE) {
  11391. XFCLOSE(f);
  11392. f = XBADFILE;
  11393. }
  11394. /* check verify MAC fail case */
  11395. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  11396. ExpectNull(pkey);
  11397. ExpectNull(cert);
  11398. /* check parse with no extra certs kept */
  11399. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  11400. 1);
  11401. ExpectNotNull(pkey);
  11402. ExpectNotNull(cert);
  11403. wolfSSL_EVP_PKEY_free(pkey);
  11404. pkey = NULL;
  11405. wolfSSL_X509_free(cert);
  11406. cert = NULL;
  11407. /* check parse with extra certs kept */
  11408. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11409. 1);
  11410. ExpectNotNull(pkey);
  11411. ExpectNotNull(cert);
  11412. ExpectNotNull(ca);
  11413. wolfSSL_EVP_PKEY_free(pkey);
  11414. pkey = NULL;
  11415. wolfSSL_X509_free(cert);
  11416. cert = NULL;
  11417. sk_X509_pop_free(ca, NULL);
  11418. ca = NULL;
  11419. PKCS12_free(pkcs12);
  11420. pkcs12 = NULL;
  11421. #endif /* HAVE_ECC */
  11422. #ifdef WC_RC2
  11423. /* test PKCS#12 with RC2 encryption */
  11424. ExpectTrue((f = XFOPEN(rc2p12, "rb")) != XBADFILE);
  11425. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  11426. if (f != XBADFILE) {
  11427. XFCLOSE(f);
  11428. f = XBADFILE;
  11429. }
  11430. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  11431. ExpectNotNull(pkcs12 = d2i_PKCS12_bio(bio, NULL));
  11432. /* check verify MAC fail case */
  11433. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  11434. ExpectNull(pkey);
  11435. ExpectNull(cert);
  11436. /* check parse with not extra certs kept */
  11437. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  11438. WOLFSSL_SUCCESS);
  11439. ExpectNotNull(pkey);
  11440. ExpectNotNull(cert);
  11441. wolfSSL_EVP_PKEY_free(pkey);
  11442. pkey = NULL;
  11443. wolfSSL_X509_free(cert);
  11444. cert = NULL;
  11445. /* check parse with extra certs kept */
  11446. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11447. WOLFSSL_SUCCESS);
  11448. ExpectNotNull(pkey);
  11449. ExpectNotNull(cert);
  11450. ExpectNotNull(ca);
  11451. wolfSSL_EVP_PKEY_free(pkey);
  11452. wolfSSL_X509_free(cert);
  11453. sk_X509_pop_free(ca, NULL);
  11454. BIO_free(bio);
  11455. bio = NULL;
  11456. PKCS12_free(pkcs12);
  11457. pkcs12 = NULL;
  11458. #endif /* WC_RC2 */
  11459. /* Test i2d_PKCS12_bio */
  11460. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  11461. ExpectNotNull(pkcs12 = d2i_PKCS12_fp(f, NULL));
  11462. if (f != XBADFILE)
  11463. XFCLOSE(f);
  11464. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  11465. ExpectIntEQ(ret = i2d_PKCS12_bio(bio, pkcs12), 1);
  11466. ExpectIntEQ(ret = i2d_PKCS12_bio(NULL, pkcs12), 0);
  11467. ExpectIntEQ(ret = i2d_PKCS12_bio(bio, NULL), 0);
  11468. PKCS12_free(pkcs12);
  11469. BIO_free(bio);
  11470. (void)order;
  11471. #endif /* OPENSSL_EXTRA */
  11472. #endif /* HAVE_FIPS */
  11473. return EXPECT_RESULT();
  11474. }
  11475. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) && \
  11476. defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_DES3) && !defined(NO_PWDBASED) && \
  11477. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_MD5)
  11478. #define TEST_PKCS8_ENC
  11479. #endif
  11480. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) \
  11481. && defined(HAVE_ECC) && defined(WOLFSSL_ENCRYPTED_KEYS)
  11482. /* used to keep track if FailTestCallback was called */
  11483. static int failTestCallbackCalled = 0;
  11484. static WC_INLINE int FailTestCallBack(char* passwd, int sz, int rw, void* userdata)
  11485. {
  11486. (void)passwd;
  11487. (void)sz;
  11488. (void)rw;
  11489. (void)userdata;
  11490. /* mark called, test_wolfSSL_no_password_cb() will check and fail if set */
  11491. failTestCallbackCalled = 1;
  11492. return -1;
  11493. }
  11494. #endif
  11495. static int test_wolfSSL_no_password_cb(void)
  11496. {
  11497. EXPECT_DECLS;
  11498. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) \
  11499. && defined(HAVE_ECC) && defined(WOLFSSL_ENCRYPTED_KEYS)
  11500. WOLFSSL_CTX* ctx = NULL;
  11501. byte buff[FOURK_BUF];
  11502. const char eccPkcs8PrivKeyDerFile[] = "./certs/ecc-privkeyPkcs8.der";
  11503. const char eccPkcs8PrivKeyPemFile[] = "./certs/ecc-privkeyPkcs8.pem";
  11504. XFILE f = XBADFILE;
  11505. int bytes = 0;
  11506. #ifndef NO_WOLFSSL_CLIENT
  11507. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLS_client_method()));
  11508. #else
  11509. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLS_server_method()));
  11510. #endif
  11511. wolfSSL_CTX_set_default_passwd_cb(ctx, FailTestCallBack);
  11512. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyDerFile, "rb")) != XBADFILE);
  11513. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11514. if (f != XBADFILE) {
  11515. XFCLOSE(f);
  11516. f = XBADFILE;
  11517. }
  11518. ExpectIntLE(bytes, sizeof(buff));
  11519. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11520. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11521. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyPemFile, "rb")) != XBADFILE);
  11522. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11523. if (f != XBADFILE)
  11524. XFCLOSE(f);
  11525. ExpectIntLE(bytes, sizeof(buff));
  11526. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11527. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11528. wolfSSL_CTX_free(ctx);
  11529. /* Password callback should not be called by default */
  11530. ExpectIntEQ(failTestCallbackCalled, 0);
  11531. #endif
  11532. return EXPECT_RESULT();
  11533. }
  11534. #ifdef TEST_PKCS8_ENC
  11535. /* for PKCS8 test case */
  11536. static int PKCS8TestCallBack(char* passwd, int sz, int rw, void* userdata)
  11537. {
  11538. int flag = 0;
  11539. (void)rw;
  11540. if (userdata != NULL) {
  11541. flag = *((int*)userdata); /* user set data */
  11542. }
  11543. switch (flag) {
  11544. case 1: /* flag set for specific WOLFSSL_CTX structure, note userdata
  11545. * can be anything the user wishes to be passed to the callback
  11546. * associated with the WOLFSSL_CTX */
  11547. XSTRNCPY(passwd, "yassl123", sz);
  11548. return 8;
  11549. default:
  11550. return BAD_FUNC_ARG;
  11551. }
  11552. }
  11553. #endif /* TEST_PKCS8_ENC */
  11554. /* Testing functions dealing with PKCS8 */
  11555. static int test_wolfSSL_PKCS8(void)
  11556. {
  11557. EXPECT_DECLS;
  11558. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) && \
  11559. !defined(WOLFCRYPT_ONLY)
  11560. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11561. byte buff[FOURK_BUF];
  11562. byte der[FOURK_BUF];
  11563. #ifndef NO_RSA
  11564. const char serverKeyPkcs8PemFile[] = "./certs/server-keyPkcs8.pem";
  11565. const char serverKeyPkcs8DerFile[] = "./certs/server-keyPkcs8.der";
  11566. #endif
  11567. const char eccPkcs8PrivKeyPemFile[] = "./certs/ecc-privkeyPkcs8.pem";
  11568. #ifdef HAVE_ECC
  11569. const char eccPkcs8PrivKeyDerFile[] = "./certs/ecc-privkeyPkcs8.der";
  11570. #endif
  11571. XFILE f = XBADFILE;
  11572. int bytes = 0;
  11573. WOLFSSL_CTX* ctx = NULL;
  11574. #if defined(HAVE_ECC) && !defined(NO_CODING) && !defined(WOLFSSL_NO_PEM)
  11575. int ret;
  11576. ecc_key key;
  11577. word32 x = 0;
  11578. #endif
  11579. #ifdef TEST_PKCS8_ENC
  11580. #if !defined(NO_RSA) && !defined(NO_SHA)
  11581. const char serverKeyPkcs8EncPemFile[] = "./certs/server-keyPkcs8Enc.pem";
  11582. const char serverKeyPkcs8EncDerFile[] = "./certs/server-keyPkcs8Enc.der";
  11583. #endif
  11584. #if defined(HAVE_ECC) && !defined(NO_SHA)
  11585. const char eccPkcs8EncPrivKeyPemFile[] = "./certs/ecc-keyPkcs8Enc.pem";
  11586. const char eccPkcs8EncPrivKeyDerFile[] = "./certs/ecc-keyPkcs8Enc.der";
  11587. #endif
  11588. int flag;
  11589. #endif
  11590. (void)der;
  11591. #ifndef NO_WOLFSSL_CLIENT
  11592. #ifndef WOLFSSL_NO_TLS12
  11593. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  11594. #else
  11595. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  11596. #endif
  11597. #else
  11598. #ifndef WOLFSSL_NO_TLS12
  11599. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  11600. #else
  11601. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  11602. #endif
  11603. #endif
  11604. #ifdef TEST_PKCS8_ENC
  11605. wolfSSL_CTX_set_default_passwd_cb(ctx, PKCS8TestCallBack);
  11606. wolfSSL_CTX_set_default_passwd_cb_userdata(ctx, (void*)&flag);
  11607. flag = 1; /* used by password callback as return code */
  11608. #if !defined(NO_RSA) && !defined(NO_SHA)
  11609. /* test loading PEM PKCS8 encrypted file */
  11610. ExpectTrue((f = XFOPEN(serverKeyPkcs8EncPemFile, "rb")) != XBADFILE);
  11611. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11612. if (f != XBADFILE) {
  11613. XFCLOSE(f);
  11614. f = XBADFILE;
  11615. }
  11616. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11617. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11618. /* this next case should fail because of password callback return code */
  11619. flag = 0; /* used by password callback as return code */
  11620. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11621. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11622. /* decrypt PKCS8 PEM to key in DER format with not using WOLFSSL_CTX */
  11623. ExpectIntGT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11624. "yassl123"), 0);
  11625. /* test that error value is returned with a bad password */
  11626. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11627. "bad"), 0);
  11628. /* test loading PEM PKCS8 encrypted file */
  11629. ExpectTrue((f = XFOPEN(serverKeyPkcs8EncDerFile, "rb")) != XBADFILE);
  11630. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11631. if (f != XBADFILE) {
  11632. XFCLOSE(f);
  11633. f = XBADFILE;
  11634. }
  11635. flag = 1; /* used by password callback as return code */
  11636. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11637. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11638. /* this next case should fail because of password callback return code */
  11639. flag = 0; /* used by password callback as return code */
  11640. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11641. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11642. #endif /* !NO_RSA && !NO_SHA */
  11643. #if defined(HAVE_ECC) && !defined(NO_SHA)
  11644. /* test loading PEM PKCS8 encrypted ECC Key file */
  11645. ExpectTrue((f = XFOPEN(eccPkcs8EncPrivKeyPemFile, "rb")) != XBADFILE);
  11646. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11647. if (f != XBADFILE) {
  11648. XFCLOSE(f);
  11649. f = XBADFILE;
  11650. }
  11651. flag = 1; /* used by password callback as return code */
  11652. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11653. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11654. /* this next case should fail because of password callback return code */
  11655. flag = 0; /* used by password callback as return code */
  11656. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11657. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11658. /* decrypt PKCS8 PEM to key in DER format with not using WOLFSSL_CTX */
  11659. ExpectIntGT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11660. "yassl123"), 0);
  11661. /* test that error value is returned with a bad password */
  11662. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11663. "bad"), 0);
  11664. /* test loading DER PKCS8 encrypted ECC Key file */
  11665. ExpectTrue((f = XFOPEN(eccPkcs8EncPrivKeyDerFile, "rb")) != XBADFILE);
  11666. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11667. if (f != XBADFILE) {
  11668. XFCLOSE(f);
  11669. f = XBADFILE;
  11670. }
  11671. flag = 1; /* used by password callback as return code */
  11672. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11673. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11674. /* this next case should fail because of password callback return code */
  11675. flag = 0; /* used by password callback as return code */
  11676. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11677. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11678. /* leave flag as "okay" */
  11679. flag = 1;
  11680. #endif /* HAVE_ECC && !NO_SHA */
  11681. #endif /* TEST_PKCS8_ENC */
  11682. #ifndef NO_RSA
  11683. /* test loading ASN.1 (DER) PKCS8 private key file (not encrypted) */
  11684. ExpectTrue((f = XFOPEN(serverKeyPkcs8DerFile, "rb")) != XBADFILE);
  11685. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11686. if (f != XBADFILE) {
  11687. XFCLOSE(f);
  11688. f = XBADFILE;
  11689. }
  11690. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11691. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11692. /* test loading PEM PKCS8 private key file (not encrypted) */
  11693. ExpectTrue((f = XFOPEN(serverKeyPkcs8PemFile, "rb")) != XBADFILE);
  11694. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11695. if (f != XBADFILE) {
  11696. XFCLOSE(f);
  11697. f = XBADFILE;
  11698. }
  11699. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11700. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11701. #endif /* !NO_RSA */
  11702. /* Test PKCS8 PEM ECC key no crypt */
  11703. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyPemFile, "rb")) != XBADFILE);
  11704. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11705. if (f != XBADFILE) {
  11706. XFCLOSE(f);
  11707. f = XBADFILE;
  11708. }
  11709. #ifdef HAVE_ECC
  11710. /* Test PKCS8 PEM ECC key no crypt */
  11711. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11712. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11713. #if !defined(NO_CODING) && !defined(WOLFSSL_NO_PEM)
  11714. /* decrypt PKCS8 PEM to key in DER format */
  11715. ExpectIntGT((bytes = wc_KeyPemToDer(buff, bytes, der,
  11716. (word32)sizeof(der), NULL)), 0);
  11717. ret = wc_ecc_init(&key);
  11718. if (ret == 0) {
  11719. ret = wc_EccPrivateKeyDecode(der, &x, &key, (word32)bytes);
  11720. wc_ecc_free(&key);
  11721. }
  11722. ExpectIntEQ(ret, 0);
  11723. #endif
  11724. /* Test PKCS8 DER ECC key no crypt */
  11725. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyDerFile, "rb")) != XBADFILE);
  11726. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11727. if (f != XBADFILE)
  11728. XFCLOSE(f);
  11729. /* Test using a PKCS8 ECC PEM */
  11730. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11731. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11732. #else
  11733. /* if HAVE_ECC is not defined then BEGIN EC PRIVATE KEY is not found */
  11734. ExpectIntEQ((bytes = wc_KeyPemToDer(buff, bytes, der,
  11735. (word32)sizeof(der), NULL)), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  11736. #endif /* HAVE_ECC */
  11737. wolfSSL_CTX_free(ctx);
  11738. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11739. #endif /* !NO_FILESYSTEM && !NO_ASN && HAVE_PKCS8 */
  11740. return EXPECT_RESULT();
  11741. }
  11742. static int test_wolfSSL_PKCS8_ED25519(void)
  11743. {
  11744. EXPECT_DECLS;
  11745. #if !defined(NO_ASN) && defined(HAVE_PKCS8) && defined(HAVE_AES_CBC) && \
  11746. defined(WOLFSSL_ENCRYPTED_KEYS) && defined(HAVE_ED25519) && \
  11747. defined(HAVE_ED25519_KEY_IMPORT)
  11748. const byte encPrivKey[] = \
  11749. "-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
  11750. "MIGbMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAheCGLmWGh7+AICCAAw\n"
  11751. "DAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEC4L5P6GappsTyhOOoQfvh8EQJMX\n"
  11752. "OAdlsYKCOcFo4djg6AI1lRdeBRwVFWkha7gBdoCJOzS8wDvTbYcJMPvANu5ft3nl\n"
  11753. "2L9W4v7swXkV+X+a1ww=\n"
  11754. "-----END ENCRYPTED PRIVATE KEY-----\n";
  11755. const char password[] = "abcdefghijklmnopqrstuvwxyz";
  11756. byte der[FOURK_BUF];
  11757. WOLFSSL_CTX* ctx = NULL;
  11758. int bytes;
  11759. XMEMSET(der, 0, sizeof(der));
  11760. ExpectIntGT((bytes = wc_KeyPemToDer(encPrivKey, sizeof(encPrivKey), der,
  11761. (word32)sizeof(der), password)), 0);
  11762. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11763. #ifndef NO_WOLFSSL_SERVER
  11764. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11765. #else
  11766. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11767. #endif
  11768. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, der, bytes,
  11769. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11770. wolfSSL_CTX_free(ctx);
  11771. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11772. #endif
  11773. return EXPECT_RESULT();
  11774. }
  11775. static int test_wolfSSL_PKCS8_ED448(void)
  11776. {
  11777. EXPECT_DECLS;
  11778. #if !defined(NO_ASN) && defined(HAVE_PKCS8) && defined(HAVE_AES_CBC) && \
  11779. defined(WOLFSSL_ENCRYPTED_KEYS) && defined(HAVE_ED448) && \
  11780. defined(HAVE_ED448_KEY_IMPORT)
  11781. const byte encPrivKey[] = \
  11782. "-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
  11783. "MIGrMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAjSbZKnG4EPggICCAAw\n"
  11784. "DAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEFvCFWBBHBlJBsYleBJlJWcEUNC7\n"
  11785. "Tf5pZviT5Btar4D/MNg6BsQHSDf5KW4ix871EsgDY2Zz+euaoWspiMntz7gU+PQu\n"
  11786. "T/JJcbD2Ly8BbE3l5WHMifAQqNLxJBfXrHkfYtAo\n"
  11787. "-----END ENCRYPTED PRIVATE KEY-----\n";
  11788. const char password[] = "abcdefghijklmnopqrstuvwxyz";
  11789. byte der[FOURK_BUF];
  11790. WOLFSSL_CTX* ctx = NULL;
  11791. int bytes;
  11792. XMEMSET(der, 0, sizeof(der));
  11793. ExpectIntGT((bytes = wc_KeyPemToDer(encPrivKey, sizeof(encPrivKey), der,
  11794. (word32)sizeof(der), password)), 0);
  11795. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11796. #ifndef NO_WOLFSSL_SERVER
  11797. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11798. #else
  11799. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11800. #endif
  11801. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, der, bytes,
  11802. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11803. wolfSSL_CTX_free(ctx);
  11804. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11805. #endif
  11806. return EXPECT_RESULT();
  11807. }
  11808. /* Testing functions dealing with PKCS5 */
  11809. static int test_wolfSSL_PKCS5(void)
  11810. {
  11811. EXPECT_DECLS;
  11812. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA) && !defined(NO_PWDBASED)
  11813. #ifdef HAVE_FIPS /* Password minimum length is 14 (112-bit) in FIPS MODE */
  11814. const char* passwd = "myfipsPa$$W0rd";
  11815. #else
  11816. const char *passwd = "pass1234";
  11817. #endif
  11818. const unsigned char *salt = (unsigned char *)"salt1234";
  11819. unsigned char *out = (unsigned char *)XMALLOC(WC_SHA_DIGEST_SIZE, NULL,
  11820. DYNAMIC_TYPE_TMP_BUFFER);
  11821. int ret = 0;
  11822. ExpectNotNull(out);
  11823. ExpectIntEQ(ret = PKCS5_PBKDF2_HMAC_SHA1(passwd,(int)XSTRLEN(passwd), salt,
  11824. (int)XSTRLEN((const char *) salt), 10, WC_SHA_DIGEST_SIZE,out),
  11825. WOLFSSL_SUCCESS);
  11826. #ifdef WOLFSSL_SHA512
  11827. ExpectIntEQ(ret = PKCS5_PBKDF2_HMAC(passwd,(int)XSTRLEN(passwd), salt,
  11828. (int)XSTRLEN((const char *) salt), 10, wolfSSL_EVP_sha512(),
  11829. WC_SHA_DIGEST_SIZE, out), SSL_SUCCESS);
  11830. #endif
  11831. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  11832. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SHA) */
  11833. return EXPECT_RESULT();
  11834. }
  11835. /* test parsing URI from certificate */
  11836. static int test_wolfSSL_URI(void)
  11837. {
  11838. EXPECT_DECLS;
  11839. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) \
  11840. && (defined(KEEP_PEER_CERT) || defined(SESSION_CERTS) || \
  11841. defined(OPENSSL_EXTRA))
  11842. WOLFSSL_X509* x509 = NULL;
  11843. const char uri[] = "./certs/client-uri-cert.pem";
  11844. const char urn[] = "./certs/client-absolute-urn.pem";
  11845. const char badUri[] = "./certs/client-relative-uri.pem";
  11846. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(uri,
  11847. WOLFSSL_FILETYPE_PEM));
  11848. wolfSSL_FreeX509(x509);
  11849. x509 = NULL;
  11850. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(urn,
  11851. WOLFSSL_FILETYPE_PEM));
  11852. wolfSSL_FreeX509(x509);
  11853. x509 = NULL;
  11854. #if !defined(IGNORE_NAME_CONSTRAINTS) && !defined(WOLFSSL_NO_ASN_STRICT) \
  11855. && !defined(WOLFSSL_FPKI)
  11856. ExpectNull(x509 = wolfSSL_X509_load_certificate_file(badUri,
  11857. WOLFSSL_FILETYPE_PEM));
  11858. #else
  11859. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(badUri,
  11860. WOLFSSL_FILETYPE_PEM));
  11861. #endif
  11862. wolfSSL_FreeX509(x509);
  11863. #endif
  11864. return EXPECT_RESULT();
  11865. }
  11866. static int test_wolfSSL_TBS(void)
  11867. {
  11868. EXPECT_DECLS;
  11869. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) \
  11870. && defined(OPENSSL_EXTRA)
  11871. WOLFSSL_X509* x509 = NULL;
  11872. const unsigned char* tbs;
  11873. int tbsSz;
  11874. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caCertFile,
  11875. WOLFSSL_FILETYPE_PEM));
  11876. ExpectNull(tbs = wolfSSL_X509_get_tbs(NULL, &tbsSz));
  11877. ExpectNull(tbs = wolfSSL_X509_get_tbs(x509, NULL));
  11878. ExpectNotNull(tbs = wolfSSL_X509_get_tbs(x509, &tbsSz));
  11879. ExpectIntEQ(tbsSz, 1003);
  11880. wolfSSL_FreeX509(x509);
  11881. #endif
  11882. return EXPECT_RESULT();
  11883. }
  11884. static int test_wolfSSL_X509_verify(void)
  11885. {
  11886. EXPECT_DECLS;
  11887. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) && \
  11888. defined(OPENSSL_EXTRA)
  11889. WOLFSSL_X509* ca = NULL;
  11890. WOLFSSL_X509* serv = NULL;
  11891. WOLFSSL_EVP_PKEY* pkey = NULL;
  11892. unsigned char buf[2048];
  11893. const unsigned char* pt = NULL;
  11894. int bufSz;
  11895. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(caCertFile,
  11896. WOLFSSL_FILETYPE_PEM));
  11897. ExpectIntNE(wolfSSL_X509_get_pubkey_buffer(NULL, buf, &bufSz),
  11898. WOLFSSL_SUCCESS);
  11899. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(ca, NULL, &bufSz),
  11900. WOLFSSL_SUCCESS);
  11901. ExpectIntEQ(bufSz, 294);
  11902. bufSz = 2048;
  11903. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(ca, buf, &bufSz),
  11904. WOLFSSL_SUCCESS);
  11905. ExpectIntEQ(wolfSSL_X509_get_pubkey_type(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  11906. ExpectIntEQ(wolfSSL_X509_get_pubkey_type(ca), RSAk);
  11907. ExpectNotNull(serv = wolfSSL_X509_load_certificate_file(svrCertFile,
  11908. WOLFSSL_FILETYPE_PEM));
  11909. /* success case */
  11910. pt = buf;
  11911. ExpectNotNull(pkey = wolfSSL_d2i_PUBKEY(NULL, &pt, bufSz));
  11912. ExpectIntEQ(i2d_PUBKEY(pkey, NULL), bufSz);
  11913. ExpectIntEQ(wolfSSL_X509_verify(serv, pkey), WOLFSSL_SUCCESS);
  11914. wolfSSL_EVP_PKEY_free(pkey);
  11915. pkey = NULL;
  11916. /* fail case */
  11917. bufSz = 2048;
  11918. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(serv, buf, &bufSz),
  11919. WOLFSSL_SUCCESS);
  11920. pt = buf;
  11921. ExpectNotNull(pkey = wolfSSL_d2i_PUBKEY(NULL, &pt, bufSz));
  11922. ExpectIntEQ(wolfSSL_X509_verify(serv, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  11923. ExpectIntEQ(wolfSSL_X509_verify(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  11924. ExpectIntEQ(wolfSSL_X509_verify(serv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  11925. wolfSSL_EVP_PKEY_free(pkey);
  11926. wolfSSL_FreeX509(ca);
  11927. wolfSSL_FreeX509(serv);
  11928. #endif
  11929. return EXPECT_RESULT();
  11930. }
  11931. #if defined(WOLFSSL_ACERT) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  11932. !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA)
  11933. /* Given acert file and its pubkey file, read them and then
  11934. * attempt to verify signed acert.
  11935. *
  11936. * If expect_pass is true, then verification should pass.
  11937. * If expect_pass is false, then verification should fail.
  11938. * */
  11939. static int do_acert_verify_test(const char * acert_file,
  11940. const char * pkey_file,
  11941. size_t expect_pass)
  11942. {
  11943. X509_ACERT * x509 = NULL;
  11944. EVP_PKEY * pkey = NULL;
  11945. BIO * bp = NULL;
  11946. int verify_rc = 0;
  11947. /* First read the attribute certificate. */
  11948. bp = BIO_new_file(acert_file, "r");
  11949. if (bp == NULL) {
  11950. return -1;
  11951. }
  11952. x509 = PEM_read_bio_X509_ACERT(bp, NULL, NULL, NULL);
  11953. BIO_free(bp);
  11954. bp = NULL;
  11955. if (x509 == NULL) {
  11956. return -1;
  11957. }
  11958. /* Next read the associated pub key. */
  11959. bp = BIO_new_file(pkey_file, "r");
  11960. if (bp == NULL) {
  11961. X509_ACERT_free(x509);
  11962. x509 = NULL;
  11963. return -1;
  11964. }
  11965. pkey = PEM_read_bio_PUBKEY(bp, &pkey, NULL, NULL);
  11966. BIO_free(bp);
  11967. bp = NULL;
  11968. if (pkey == NULL) {
  11969. X509_ACERT_free(x509);
  11970. x509 = NULL;
  11971. return -1;
  11972. }
  11973. /* Finally, do verification. */
  11974. verify_rc = X509_ACERT_verify(x509, pkey);
  11975. X509_ACERT_free(x509);
  11976. x509 = NULL;
  11977. EVP_PKEY_free(pkey);
  11978. pkey = NULL;
  11979. if (expect_pass && verify_rc != 1) {
  11980. return -1;
  11981. }
  11982. if (!expect_pass && verify_rc == 1) {
  11983. return -1;
  11984. }
  11985. return 0;
  11986. }
  11987. #endif
  11988. static int test_wolfSSL_X509_ACERT_verify(void)
  11989. {
  11990. EXPECT_DECLS;
  11991. #if defined(WOLFSSL_ACERT) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  11992. defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA)
  11993. /* Walk over list of signed ACERTs and their pubkeys.
  11994. * All should load and pass verification. */
  11995. const char * acerts[4] = {"certs/acert/acert.pem",
  11996. "certs/acert/acert_ietf.pem",
  11997. "certs/acert/rsa_pss/acert.pem",
  11998. "certs/acert/rsa_pss/acert_ietf.pem"};
  11999. const char * pkeys[4] = {"certs/acert/acert_pubkey.pem",
  12000. "certs/acert/acert_ietf_pubkey.pem",
  12001. "certs/acert/rsa_pss/acert_pubkey.pem",
  12002. "certs/acert/rsa_pss/acert_ietf_pubkey.pem"};
  12003. int rc = 0;
  12004. size_t i = 0;
  12005. size_t j = 0;
  12006. for (i = 0; i < 4; ++i) {
  12007. for (j = i; j < 4; ++j) {
  12008. rc = do_acert_verify_test(acerts[i], pkeys[j], i == j);
  12009. if (rc) {
  12010. fprintf(stderr, "error: %s: i = %zu, j = %zu, rc = %d\n",
  12011. "do_acert_verify_test", i, j, rc);
  12012. break;
  12013. }
  12014. }
  12015. if (rc) { break; }
  12016. }
  12017. ExpectIntEQ(rc, 0);
  12018. #endif
  12019. return EXPECT_RESULT();
  12020. }
  12021. static int test_wolfSSL_X509_ACERT_misc_api(void)
  12022. {
  12023. EXPECT_DECLS;
  12024. #if defined(WOLFSSL_ACERT) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  12025. !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA)
  12026. const char * acerts[4] = {"certs/acert/acert.pem",
  12027. "certs/acert/acert_ietf.pem",
  12028. "certs/acert/rsa_pss/acert.pem",
  12029. "certs/acert/rsa_pss/acert_ietf.pem"};
  12030. int rc = 0;
  12031. X509_ACERT * x509 = NULL;
  12032. BIO * bp = NULL;
  12033. long ver_long = 0;
  12034. int ver = 0;
  12035. int nid = 0;
  12036. const byte * raw_attr = NULL;
  12037. word32 attr_len = 0;
  12038. size_t i = 0;
  12039. int buf_len = 0;
  12040. byte ietf_serial[] = {0x03, 0xb5, 0x90, 0x59, 0x02,
  12041. 0xa2, 0xaa, 0xb5, 0x40, 0x21,
  12042. 0x44, 0xb8, 0x2c, 0x4f, 0xd9,
  12043. 0x80, 0x1b, 0x5f, 0x57, 0xc2};
  12044. for (i = 0; i < 4; ++i) {
  12045. const char * acert_file = acerts[i];
  12046. int is_rsa_pss = 0;
  12047. int is_ietf_acert = 0;
  12048. byte serial[64];
  12049. int serial_len = sizeof(serial);
  12050. XMEMSET(serial, 0, sizeof(serial));
  12051. is_rsa_pss = XSTRSTR(acert_file, "rsa_pss") != NULL ? 1 : 0;
  12052. is_ietf_acert = XSTRSTR(acert_file, "ietf.pem") != NULL ? 1 : 0;
  12053. /* First read the attribute certificate. */
  12054. bp = BIO_new_file(acert_file, "r");
  12055. ExpectNotNull(bp);
  12056. x509 = PEM_read_bio_X509_ACERT(bp, NULL, NULL, NULL);
  12057. ExpectNotNull(x509);
  12058. /* We're done with the bio for now. */
  12059. if (bp != NULL) {
  12060. BIO_free(bp);
  12061. bp = NULL;
  12062. }
  12063. /* Check version and signature NID. */
  12064. ver_long = X509_ACERT_get_version(x509);
  12065. ExpectIntEQ(ver_long, 1);
  12066. ver = wolfSSL_X509_ACERT_version(x509);
  12067. ExpectIntEQ(ver, 2);
  12068. nid = X509_ACERT_get_signature_nid(x509);
  12069. if (is_rsa_pss) {
  12070. ExpectIntEQ(nid, NID_rsassaPss);
  12071. }
  12072. else {
  12073. ExpectIntEQ(nid, NID_sha256WithRSAEncryption);
  12074. }
  12075. /* Get the serial number buffer.
  12076. * The ietf acert example has a 20 byte serial number. */
  12077. rc = wolfSSL_X509_ACERT_get_serial_number(x509, serial, &serial_len);
  12078. ExpectIntEQ(rc, SSL_SUCCESS);
  12079. if (is_ietf_acert) {
  12080. ExpectIntEQ(serial_len, 20);
  12081. ExpectIntEQ(XMEMCMP(serial, ietf_serial, sizeof(ietf_serial)), 0);
  12082. }
  12083. else {
  12084. ExpectIntEQ(serial_len, 1);
  12085. ExpectTrue(serial[0] == 0x01);
  12086. }
  12087. /* Repeat the same but with null serial buffer. This is ok. */
  12088. rc = wolfSSL_X509_ACERT_get_serial_number(x509, NULL, &serial_len);
  12089. ExpectIntEQ(rc, SSL_SUCCESS);
  12090. if (is_ietf_acert) {
  12091. ExpectIntEQ(serial_len, 20);
  12092. }
  12093. else {
  12094. ExpectIntEQ(serial_len, 1);
  12095. ExpectTrue(serial[0] == 0x01);
  12096. }
  12097. /* Get the attributes buffer. */
  12098. rc = wolfSSL_X509_ACERT_get_attr_buf(x509, &raw_attr, &attr_len);
  12099. ExpectIntEQ(rc, SSL_SUCCESS);
  12100. if (is_ietf_acert) {
  12101. /* This cert has a 65 byte attributes field. */
  12102. ExpectNotNull(raw_attr);
  12103. ExpectIntEQ(attr_len, 65);
  12104. }
  12105. else {
  12106. /* This cert has a 237 byte attributes field. */
  12107. ExpectNotNull(raw_attr);
  12108. ExpectIntEQ(attr_len, 237);
  12109. }
  12110. /* Test printing acert to memory bio. */
  12111. ExpectNotNull(bp = BIO_new(BIO_s_mem()));
  12112. rc = X509_ACERT_print(bp, x509);
  12113. ExpectIntEQ(rc, SSL_SUCCESS);
  12114. /* Now do a bunch of invalid stuff with partially valid inputs. */
  12115. rc = wolfSSL_X509_ACERT_get_attr_buf(x509, &raw_attr, NULL);
  12116. ExpectIntEQ(rc, BAD_FUNC_ARG);
  12117. rc = wolfSSL_X509_ACERT_get_attr_buf(x509, NULL, &attr_len);
  12118. ExpectIntEQ(rc, BAD_FUNC_ARG);
  12119. rc = wolfSSL_X509_ACERT_get_attr_buf(NULL, &raw_attr, &attr_len);
  12120. ExpectIntEQ(rc, BAD_FUNC_ARG);
  12121. ver_long = X509_ACERT_get_version(NULL);
  12122. ExpectIntEQ(ver_long, 0);
  12123. ver = wolfSSL_X509_ACERT_version(NULL);
  12124. ExpectIntEQ(ver, 0);
  12125. rc = wolfSSL_X509_ACERT_get_signature(x509, NULL, NULL);
  12126. ExpectIntEQ(rc, WOLFSSL_FATAL_ERROR);
  12127. rc = wolfSSL_X509_ACERT_get_signature(x509, NULL, &buf_len);
  12128. ExpectIntEQ(rc, SSL_SUCCESS);
  12129. ExpectIntEQ(buf_len, 256);
  12130. rc = wolfSSL_X509_ACERT_get_serial_number(x509, serial, NULL);
  12131. ExpectIntEQ(rc, BAD_FUNC_ARG);
  12132. rc = X509_ACERT_print(bp, NULL);
  12133. ExpectIntEQ(rc, WOLFSSL_FAILURE);
  12134. rc = X509_ACERT_print(NULL, x509);
  12135. ExpectIntEQ(rc, WOLFSSL_FAILURE);
  12136. /* Finally free the acert and bio, we're done with them. */
  12137. if (x509 != NULL) {
  12138. X509_ACERT_free(x509);
  12139. x509 = NULL;
  12140. }
  12141. if (bp != NULL) {
  12142. BIO_free(bp);
  12143. bp = NULL;
  12144. }
  12145. }
  12146. #endif
  12147. return EXPECT_RESULT();
  12148. }
  12149. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  12150. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  12151. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  12152. /* create certificate with version 2 */
  12153. static int test_set_x509_badversion(WOLFSSL_CTX* ctx)
  12154. {
  12155. EXPECT_DECLS;
  12156. WOLFSSL_X509 *x509 = NULL, *x509v2 = NULL;
  12157. WOLFSSL_EVP_PKEY *priv = NULL, *pub = NULL;
  12158. unsigned char *der = NULL, *key = NULL, *pt;
  12159. char *header = NULL, *name = NULL;
  12160. int derSz;
  12161. long keySz;
  12162. XFILE fp = XBADFILE;
  12163. WOLFSSL_ASN1_TIME *notBefore = NULL, *notAfter = NULL;
  12164. time_t t;
  12165. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  12166. WOLFSSL_FILETYPE_PEM));
  12167. ExpectTrue((fp = XFOPEN(cliKeyFile, "rb")) != XBADFILE);
  12168. ExpectIntEQ(wolfSSL_PEM_read(fp, &name, &header, &key, &keySz),
  12169. WOLFSSL_SUCCESS);
  12170. if (fp != XBADFILE)
  12171. XFCLOSE(fp);
  12172. pt = key;
  12173. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  12174. (const unsigned char**)&pt, keySz));
  12175. /* create the version 2 certificate */
  12176. ExpectNotNull(x509v2 = X509_new());
  12177. ExpectIntEQ(wolfSSL_X509_set_version(x509v2, 1), WOLFSSL_SUCCESS);
  12178. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509v2,
  12179. wolfSSL_X509_get_subject_name(x509)), WOLFSSL_SUCCESS);
  12180. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509v2,
  12181. wolfSSL_X509_get_issuer_name(x509)), WOLFSSL_SUCCESS);
  12182. ExpectNotNull(pub = wolfSSL_X509_get_pubkey(x509));
  12183. ExpectIntEQ(X509_set_pubkey(x509v2, pub), WOLFSSL_SUCCESS);
  12184. t = time(NULL);
  12185. ExpectNotNull(notBefore = wolfSSL_ASN1_TIME_adj(NULL, t, 0, 0));
  12186. ExpectNotNull(notAfter = wolfSSL_ASN1_TIME_adj(NULL, t, 365, 0));
  12187. ExpectTrue(wolfSSL_X509_set_notBefore(x509v2, notBefore));
  12188. ExpectTrue(wolfSSL_X509_set_notAfter(x509v2, notAfter));
  12189. ExpectIntGT(wolfSSL_X509_sign(x509v2, priv, EVP_sha256()), 0);
  12190. derSz = wolfSSL_i2d_X509(x509v2, &der);
  12191. ExpectIntGT(derSz, 0);
  12192. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, der, derSz,
  12193. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  12194. /* TODO: Replace with API call */
  12195. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  12196. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12197. XFREE(name, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12198. XFREE(header, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12199. wolfSSL_X509_free(x509);
  12200. wolfSSL_X509_free(x509v2);
  12201. wolfSSL_EVP_PKEY_free(priv);
  12202. wolfSSL_EVP_PKEY_free(pub);
  12203. wolfSSL_ASN1_TIME_free(notBefore);
  12204. wolfSSL_ASN1_TIME_free(notAfter);
  12205. return EXPECT_RESULT();
  12206. }
  12207. /* override certificate version error */
  12208. static int test_override_x509(int preverify, WOLFSSL_X509_STORE_CTX* store)
  12209. {
  12210. EXPECT_DECLS;
  12211. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  12212. ExpectIntEQ(store->error, WC_NO_ERR_TRACE(ASN_VERSION_E));
  12213. #else
  12214. ExpectIntEQ(store->error, 0);
  12215. #endif
  12216. ExpectIntEQ((int)wolfSSL_X509_get_version(store->current_cert), 1);
  12217. (void)preverify;
  12218. return EXPECT_RESULT() == TEST_SUCCESS;
  12219. }
  12220. /* set verify callback that will override bad certificate version */
  12221. static int test_set_override_x509(WOLFSSL_CTX* ctx)
  12222. {
  12223. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, test_override_x509);
  12224. return TEST_SUCCESS;
  12225. }
  12226. #endif
  12227. static int test_wolfSSL_X509_TLS_version_test_1(void)
  12228. {
  12229. EXPECT_DECLS;
  12230. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  12231. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  12232. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  12233. test_ssl_cbf func_cb_client;
  12234. test_ssl_cbf func_cb_server;
  12235. /* test server rejects a client certificate that is not version 3 */
  12236. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  12237. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  12238. func_cb_client.ctx_ready = &test_set_x509_badversion;
  12239. #ifndef WOLFSSL_NO_TLS12
  12240. func_cb_client.method = wolfTLSv1_2_client_method;
  12241. #else
  12242. func_cb_client.method = wolfTLSv1_3_client_method;
  12243. #endif
  12244. #ifndef WOLFSSL_NO_TLS12
  12245. func_cb_server.method = wolfTLSv1_2_server_method;
  12246. #else
  12247. func_cb_server.method = wolfTLSv1_3_server_method;
  12248. #endif
  12249. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  12250. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  12251. &func_cb_server, NULL), -1001);
  12252. #else
  12253. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  12254. &func_cb_server, NULL), TEST_SUCCESS);
  12255. #endif
  12256. #endif
  12257. return EXPECT_RESULT();
  12258. }
  12259. static int test_wolfSSL_X509_TLS_version_test_2(void)
  12260. {
  12261. EXPECT_DECLS;
  12262. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  12263. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  12264. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  12265. test_ssl_cbf func_cb_client;
  12266. test_ssl_cbf func_cb_server;
  12267. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  12268. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  12269. func_cb_client.ctx_ready = &test_set_x509_badversion;
  12270. func_cb_server.ctx_ready = &test_set_override_x509;
  12271. #ifndef WOLFSSL_NO_TLS12
  12272. func_cb_client.method = wolfTLSv1_2_client_method;
  12273. #else
  12274. func_cb_client.method = wolfTLSv1_3_client_method;
  12275. #endif
  12276. #ifndef WOLFSSL_NO_TLS12
  12277. func_cb_server.method = wolfTLSv1_2_server_method;
  12278. #else
  12279. func_cb_server.method = wolfTLSv1_3_server_method;
  12280. #endif
  12281. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  12282. &func_cb_server, NULL), TEST_SUCCESS);
  12283. #endif
  12284. return EXPECT_RESULT();
  12285. }
  12286. /* Testing function wolfSSL_CTX_SetMinVersion; sets the minimum downgrade
  12287. * version allowed.
  12288. * POST: 1 on success.
  12289. */
  12290. static int test_wolfSSL_CTX_SetMinVersion(void)
  12291. {
  12292. int res = TEST_SKIPPED;
  12293. #ifndef NO_WOLFSSL_CLIENT
  12294. int failFlag = WOLFSSL_SUCCESS;
  12295. WOLFSSL_CTX* ctx;
  12296. int itr;
  12297. #ifndef NO_OLD_TLS
  12298. const int versions[] = {
  12299. #ifdef WOLFSSL_ALLOW_TLSV10
  12300. WOLFSSL_TLSV1,
  12301. #endif
  12302. WOLFSSL_TLSV1_1,
  12303. WOLFSSL_TLSV1_2 };
  12304. #elif !defined(WOLFSSL_NO_TLS12)
  12305. const int versions[] = { WOLFSSL_TLSV1_2 };
  12306. #elif defined(WOLFSSL_TLS13)
  12307. const int versions[] = { WOLFSSL_TLSV1_3 };
  12308. #else
  12309. const int versions[0];
  12310. #endif
  12311. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  12312. for (itr = 0; itr < (int)(sizeof(versions)/sizeof(int)); itr++) {
  12313. if (wolfSSL_CTX_SetMinVersion(ctx, *(versions + itr))
  12314. != WOLFSSL_SUCCESS) {
  12315. failFlag = WOLFSSL_FAILURE;
  12316. }
  12317. }
  12318. wolfSSL_CTX_free(ctx);
  12319. res = TEST_RES_CHECK(failFlag == WOLFSSL_SUCCESS);
  12320. #endif
  12321. return res;
  12322. } /* END test_wolfSSL_CTX_SetMinVersion */
  12323. /*----------------------------------------------------------------------------*
  12324. | OCSP Stapling
  12325. *----------------------------------------------------------------------------*/
  12326. /* Testing wolfSSL_UseOCSPStapling function. OCSP stapling eliminates the need
  12327. * need to contact the CA, lowering the cost of cert revocation checking.
  12328. * PRE: HAVE_OCSP and HAVE_CERTIFICATE_STATUS_REQUEST
  12329. * POST: 1 returned for success.
  12330. */
  12331. static int test_wolfSSL_UseOCSPStapling(void)
  12332. {
  12333. EXPECT_DECLS;
  12334. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) && defined(HAVE_OCSP) && \
  12335. !defined(NO_WOLFSSL_CLIENT)
  12336. WOLFSSL_CTX* ctx = NULL;
  12337. WOLFSSL* ssl = NULL;
  12338. #ifndef NO_WOLFSSL_CLIENT
  12339. #ifndef WOLFSSL_NO_TLS12
  12340. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  12341. #else
  12342. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  12343. #endif
  12344. #else
  12345. #ifndef WOLFSSL_NO_TLS12
  12346. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  12347. #else
  12348. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  12349. #endif
  12350. #endif
  12351. ExpectNotNull(ssl = wolfSSL_new(ctx));
  12352. ExpectIntEQ(wolfSSL_UseOCSPStapling(NULL, WOLFSSL_CSR2_OCSP,
  12353. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12354. #ifndef NO_WOLFSSL_CLIENT
  12355. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl, WOLFSSL_CSR2_OCSP,
  12356. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  12357. #else
  12358. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl, WOLFSSL_CSR2_OCSP,
  12359. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12360. #endif
  12361. wolfSSL_free(ssl);
  12362. wolfSSL_CTX_free(ctx);
  12363. #endif
  12364. return EXPECT_RESULT();
  12365. } /* END test_wolfSSL_UseOCSPStapling */
  12366. /* Testing OCSP stapling version 2, wolfSSL_UseOCSPStaplingV2 function. OCSP
  12367. * stapling eliminates the need to contact the CA and lowers cert revocation
  12368. * check.
  12369. * PRE: HAVE_CERTIFICATE_STATUS_REQUEST_V2 and HAVE_OCSP defined.
  12370. */
  12371. static int test_wolfSSL_UseOCSPStaplingV2(void)
  12372. {
  12373. EXPECT_DECLS;
  12374. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) && defined(HAVE_OCSP) && \
  12375. !defined(NO_WOLFSSL_CLIENT)
  12376. WOLFSSL_CTX* ctx = NULL;
  12377. WOLFSSL* ssl = NULL;
  12378. #ifndef NO_WOLFSSL_CLIENT
  12379. #ifndef WOLFSSL_NO_TLS12
  12380. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  12381. #else
  12382. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  12383. #endif
  12384. #else
  12385. #ifndef WOLFSSL_NO_TLS12
  12386. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  12387. #else
  12388. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  12389. #endif
  12390. #endif
  12391. ExpectNotNull(ssl = wolfSSL_new(ctx));
  12392. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(NULL, WOLFSSL_CSR2_OCSP,
  12393. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12394. #ifndef NO_WOLFSSL_CLIENT
  12395. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(ssl, WOLFSSL_CSR2_OCSP,
  12396. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  12397. #else
  12398. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(ssl, WOLFSSL_CSR2_OCSP,
  12399. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12400. #endif
  12401. wolfSSL_free(ssl);
  12402. wolfSSL_CTX_free(ctx);
  12403. #endif
  12404. return EXPECT_RESULT();
  12405. } /* END test_wolfSSL_UseOCSPStaplingV2 */
  12406. /*----------------------------------------------------------------------------*
  12407. | Multicast Tests
  12408. *----------------------------------------------------------------------------*/
  12409. static int test_wolfSSL_mcast(void)
  12410. {
  12411. EXPECT_DECLS;
  12412. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_MULTICAST) && \
  12413. (defined(WOLFSSL_TLS13) || defined(WOLFSSL_SNIFFER))
  12414. WOLFSSL_CTX* ctx = NULL;
  12415. WOLFSSL* ssl = NULL;
  12416. byte preMasterSecret[512];
  12417. byte clientRandom[32];
  12418. byte serverRandom[32];
  12419. byte suite[2] = {0, 0xfe}; /* WDM_WITH_NULL_SHA256 */
  12420. byte buf[256];
  12421. word16 newId;
  12422. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  12423. ExpectIntEQ(wolfSSL_CTX_mcast_set_member_id(ctx, 0), WOLFSSL_SUCCESS);
  12424. ExpectNotNull(ssl = wolfSSL_new(ctx));
  12425. XMEMSET(preMasterSecret, 0x23, sizeof(preMasterSecret));
  12426. XMEMSET(clientRandom, 0xA5, sizeof(clientRandom));
  12427. XMEMSET(serverRandom, 0x5A, sizeof(serverRandom));
  12428. ExpectIntEQ(wolfSSL_set_secret(ssl, 23, preMasterSecret,
  12429. sizeof(preMasterSecret), clientRandom, serverRandom, suite),
  12430. WOLFSSL_SUCCESS);
  12431. ExpectIntLE(wolfSSL_mcast_read(ssl, &newId, buf, sizeof(buf)), 0);
  12432. ExpectIntLE(newId, 100);
  12433. wolfSSL_free(ssl);
  12434. wolfSSL_CTX_free(ctx);
  12435. #endif /* WOLFSSL_DTLS && WOLFSSL_MULTICAST && (WOLFSSL_TLS13 ||
  12436. * WOLFSSL_SNIFFER) */
  12437. return EXPECT_RESULT();
  12438. }
  12439. /*----------------------------------------------------------------------------*
  12440. | Wolfcrypt
  12441. *----------------------------------------------------------------------------*/
  12442. /*
  12443. * Unit test for the wc_InitBlake2b()
  12444. */
  12445. static int test_wc_InitBlake2b(void)
  12446. {
  12447. EXPECT_DECLS;
  12448. #ifdef HAVE_BLAKE2
  12449. Blake2b blake;
  12450. /* Test good arg. */
  12451. ExpectIntEQ(wc_InitBlake2b(&blake, 64), 0);
  12452. /* Test bad arg. */
  12453. ExpectIntEQ(wc_InitBlake2b(NULL, 64), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12454. ExpectIntEQ(wc_InitBlake2b(NULL, 128), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12455. ExpectIntEQ(wc_InitBlake2b(&blake, 128), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12456. ExpectIntEQ(wc_InitBlake2b(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12457. ExpectIntEQ(wc_InitBlake2b(&blake, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12458. #endif
  12459. return EXPECT_RESULT();
  12460. } /* END test_wc_InitBlake2b*/
  12461. /*
  12462. * Unit test for the wc_InitBlake2b_WithKey()
  12463. */
  12464. static int test_wc_InitBlake2b_WithKey(void)
  12465. {
  12466. EXPECT_DECLS;
  12467. #ifdef HAVE_BLAKE2
  12468. Blake2b blake;
  12469. word32 digestSz = BLAKE2B_KEYBYTES;
  12470. byte key[BLAKE2B_KEYBYTES];
  12471. word32 keylen = BLAKE2B_KEYBYTES;
  12472. XMEMSET(key, 0, sizeof(key));
  12473. /* Test good arg. */
  12474. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, key, keylen), 0);
  12475. /* Test bad args. */
  12476. ExpectIntEQ(wc_InitBlake2b_WithKey(NULL, digestSz, key, keylen),
  12477. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12478. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, key, 256),
  12479. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12480. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, NULL, keylen), 0);
  12481. #endif
  12482. return EXPECT_RESULT();
  12483. } /* END wc_InitBlake2b_WithKey*/
  12484. /*
  12485. * Unit test for the wc_InitBlake2s_WithKey()
  12486. */
  12487. static int test_wc_InitBlake2s_WithKey(void)
  12488. {
  12489. EXPECT_DECLS;
  12490. #ifdef HAVE_BLAKE2S
  12491. Blake2s blake;
  12492. word32 digestSz = BLAKE2S_KEYBYTES;
  12493. byte *key = (byte*)"01234567890123456789012345678901";
  12494. word32 keylen = BLAKE2S_KEYBYTES;
  12495. /* Test good arg. */
  12496. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, key, keylen), 0);
  12497. /* Test bad args. */
  12498. ExpectIntEQ(wc_InitBlake2s_WithKey(NULL, digestSz, key, keylen),
  12499. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12500. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, key, 256),
  12501. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12502. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, NULL, keylen), 0);
  12503. #endif
  12504. return EXPECT_RESULT();
  12505. } /* END wc_InitBlake2s_WithKey*/
  12506. /*
  12507. * Unit test for the wc_InitMd5()
  12508. */
  12509. static int test_wc_InitMd5(void)
  12510. {
  12511. EXPECT_DECLS;
  12512. #ifndef NO_MD5
  12513. wc_Md5 md5;
  12514. /* Test good arg. */
  12515. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12516. /* Test bad arg. */
  12517. ExpectIntEQ(wc_InitMd5(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12518. wc_Md5Free(&md5);
  12519. #endif
  12520. return EXPECT_RESULT();
  12521. } /* END test_wc_InitMd5 */
  12522. /*
  12523. * Testing wc_UpdateMd5()
  12524. */
  12525. static int test_wc_Md5Update(void)
  12526. {
  12527. EXPECT_DECLS;
  12528. #ifndef NO_MD5
  12529. wc_Md5 md5;
  12530. byte hash[WC_MD5_DIGEST_SIZE];
  12531. testVector a, b, c;
  12532. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12533. /* Input */
  12534. a.input = "a";
  12535. a.inLen = XSTRLEN(a.input);
  12536. ExpectIntEQ(wc_Md5Update(&md5, (byte*)a.input, (word32)a.inLen), 0);
  12537. ExpectIntEQ(wc_Md5Final(&md5, hash), 0);
  12538. /* Update input. */
  12539. a.input = "abc";
  12540. a.output = "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f"
  12541. "\x72";
  12542. a.inLen = XSTRLEN(a.input);
  12543. a.outLen = XSTRLEN(a.output);
  12544. ExpectIntEQ(wc_Md5Update(&md5, (byte*) a.input, (word32) a.inLen), 0);
  12545. ExpectIntEQ(wc_Md5Final(&md5, hash), 0);
  12546. ExpectIntEQ(XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE), 0);
  12547. /* Pass in bad values. */
  12548. b.input = NULL;
  12549. b.inLen = 0;
  12550. ExpectIntEQ(wc_Md5Update(&md5, (byte*)b.input, (word32)b.inLen), 0);
  12551. c.input = NULL;
  12552. c.inLen = WC_MD5_DIGEST_SIZE;
  12553. ExpectIntEQ(wc_Md5Update(&md5, (byte*)c.input, (word32)c.inLen),
  12554. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12555. ExpectIntEQ(wc_Md5Update(NULL, (byte*)a.input, (word32)a.inLen),
  12556. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12557. wc_Md5Free(&md5);
  12558. #endif
  12559. return EXPECT_RESULT();
  12560. } /* END test_wc_Md5Update() */
  12561. /*
  12562. * Unit test on wc_Md5Final() in wolfcrypt/src/md5.c
  12563. */
  12564. static int test_wc_Md5Final(void)
  12565. {
  12566. EXPECT_DECLS;
  12567. #ifndef NO_MD5
  12568. /* Instantiate */
  12569. wc_Md5 md5;
  12570. byte* hash_test[3];
  12571. byte hash1[WC_MD5_DIGEST_SIZE];
  12572. byte hash2[2*WC_MD5_DIGEST_SIZE];
  12573. byte hash3[5*WC_MD5_DIGEST_SIZE];
  12574. int times, i;
  12575. /* Initialize */
  12576. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12577. hash_test[0] = hash1;
  12578. hash_test[1] = hash2;
  12579. hash_test[2] = hash3;
  12580. times = sizeof(hash_test)/sizeof(byte*);
  12581. for (i = 0; i < times; i++) {
  12582. ExpectIntEQ(wc_Md5Final(&md5, hash_test[i]), 0);
  12583. }
  12584. /* Test bad args. */
  12585. ExpectIntEQ(wc_Md5Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12586. ExpectIntEQ(wc_Md5Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12587. ExpectIntEQ(wc_Md5Final(&md5, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12588. wc_Md5Free(&md5);
  12589. #endif
  12590. return EXPECT_RESULT();
  12591. }
  12592. /*
  12593. * Unit test for the wc_InitSha()
  12594. */
  12595. static int test_wc_InitSha(void)
  12596. {
  12597. EXPECT_DECLS;
  12598. #ifndef NO_SHA
  12599. wc_Sha sha;
  12600. /* Test good arg. */
  12601. ExpectIntEQ(wc_InitSha(&sha), 0);
  12602. /* Test bad arg. */
  12603. ExpectIntEQ(wc_InitSha(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12604. wc_ShaFree(&sha);
  12605. #endif
  12606. return EXPECT_RESULT();
  12607. } /* END test_wc_InitSha */
  12608. /*
  12609. * Tesing wc_ShaUpdate()
  12610. */
  12611. static int test_wc_ShaUpdate(void)
  12612. {
  12613. EXPECT_DECLS;
  12614. #ifndef NO_SHA
  12615. wc_Sha sha;
  12616. byte hash[WC_SHA_DIGEST_SIZE];
  12617. testVector a, b, c;
  12618. ExpectIntEQ(wc_InitSha(&sha), 0);
  12619. /* Input. */
  12620. a.input = "a";
  12621. a.inLen = XSTRLEN(a.input);
  12622. ExpectIntEQ(wc_ShaUpdate(&sha, NULL, 0), 0);
  12623. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, 0), 0);
  12624. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, (word32)a.inLen), 0);
  12625. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  12626. /* Update input. */
  12627. a.input = "abc";
  12628. a.output = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2"
  12629. "\x6C\x9C\xD0\xD8\x9D";
  12630. a.inLen = XSTRLEN(a.input);
  12631. a.outLen = XSTRLEN(a.output);
  12632. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, (word32)a.inLen), 0);
  12633. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  12634. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA_DIGEST_SIZE), 0);
  12635. /* Try passing in bad values. */
  12636. b.input = NULL;
  12637. b.inLen = 0;
  12638. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)b.input, (word32)b.inLen), 0);
  12639. c.input = NULL;
  12640. c.inLen = WC_SHA_DIGEST_SIZE;
  12641. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)c.input, (word32)c.inLen),
  12642. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12643. ExpectIntEQ(wc_ShaUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  12644. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12645. wc_ShaFree(&sha);
  12646. #endif
  12647. return EXPECT_RESULT();
  12648. } /* END test_wc_ShaUpdate() */
  12649. /*
  12650. * Unit test on wc_ShaFinal
  12651. */
  12652. static int test_wc_ShaFinal(void)
  12653. {
  12654. EXPECT_DECLS;
  12655. #ifndef NO_SHA
  12656. wc_Sha sha;
  12657. byte* hash_test[3];
  12658. byte hash1[WC_SHA_DIGEST_SIZE];
  12659. byte hash2[2*WC_SHA_DIGEST_SIZE];
  12660. byte hash3[5*WC_SHA_DIGEST_SIZE];
  12661. int times, i;
  12662. /* Initialize*/
  12663. ExpectIntEQ(wc_InitSha(&sha), 0);
  12664. hash_test[0] = hash1;
  12665. hash_test[1] = hash2;
  12666. hash_test[2] = hash3;
  12667. times = sizeof(hash_test)/sizeof(byte*);
  12668. for (i = 0; i < times; i++) {
  12669. ExpectIntEQ(wc_ShaFinal(&sha, hash_test[i]), 0);
  12670. }
  12671. /* Test bad args. */
  12672. ExpectIntEQ(wc_ShaFinal(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12673. ExpectIntEQ(wc_ShaFinal(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12674. ExpectIntEQ(wc_ShaFinal(&sha, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12675. wc_ShaFree(&sha);
  12676. #endif
  12677. return EXPECT_RESULT();
  12678. } /* END test_wc_ShaFinal */
  12679. /*
  12680. * Unit test for wc_InitSha256()
  12681. */
  12682. static int test_wc_InitSha256(void)
  12683. {
  12684. EXPECT_DECLS;
  12685. #ifndef NO_SHA256
  12686. wc_Sha256 sha256;
  12687. /* Test good arg. */
  12688. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12689. /* Test bad arg. */
  12690. ExpectIntEQ(wc_InitSha256(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12691. wc_Sha256Free(&sha256);
  12692. #endif
  12693. return EXPECT_RESULT();
  12694. } /* END test_wc_InitSha256 */
  12695. /*
  12696. * Unit test for wc_Sha256Update()
  12697. */
  12698. static int test_wc_Sha256Update(void)
  12699. {
  12700. EXPECT_DECLS;
  12701. #ifndef NO_SHA256
  12702. wc_Sha256 sha256;
  12703. byte hash[WC_SHA256_DIGEST_SIZE];
  12704. byte hash_unaligned[WC_SHA256_DIGEST_SIZE+1];
  12705. testVector a, b, c;
  12706. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12707. /* Input. */
  12708. a.input = "a";
  12709. a.inLen = XSTRLEN(a.input);
  12710. ExpectIntEQ(wc_Sha256Update(&sha256, NULL, 0), 0);
  12711. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, 0), 0);
  12712. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, (word32)a.inLen), 0);
  12713. ExpectIntEQ(wc_Sha256Final(&sha256, hash), 0);
  12714. /* Update input. */
  12715. a.input = "abc";
  12716. a.output = "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  12717. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  12718. "\x15\xAD";
  12719. a.inLen = XSTRLEN(a.input);
  12720. a.outLen = XSTRLEN(a.output);
  12721. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, (word32)a.inLen), 0);
  12722. ExpectIntEQ(wc_Sha256Final(&sha256, hash), 0);
  12723. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA256_DIGEST_SIZE), 0);
  12724. /* Unaligned check. */
  12725. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input+1, (word32)a.inLen-1),
  12726. 0);
  12727. ExpectIntEQ(wc_Sha256Final(&sha256, hash_unaligned + 1), 0);
  12728. /* Try passing in bad values */
  12729. b.input = NULL;
  12730. b.inLen = 0;
  12731. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)b.input, (word32)b.inLen), 0);
  12732. c.input = NULL;
  12733. c.inLen = WC_SHA256_DIGEST_SIZE;
  12734. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)c.input, (word32)c.inLen),
  12735. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12736. ExpectIntEQ(wc_Sha256Update(NULL, (byte*)a.input, (word32)a.inLen),
  12737. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12738. wc_Sha256Free(&sha256);
  12739. #endif
  12740. return EXPECT_RESULT();
  12741. } /* END test_wc_Sha256Update */
  12742. /*
  12743. * Unit test function for wc_Sha256Final()
  12744. */
  12745. static int test_wc_Sha256Final(void)
  12746. {
  12747. EXPECT_DECLS;
  12748. #ifndef NO_SHA256
  12749. wc_Sha256 sha256;
  12750. byte* hash_test[3];
  12751. byte hash1[WC_SHA256_DIGEST_SIZE];
  12752. byte hash2[2*WC_SHA256_DIGEST_SIZE];
  12753. byte hash3[5*WC_SHA256_DIGEST_SIZE];
  12754. int times, i;
  12755. /* Initialize */
  12756. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12757. hash_test[0] = hash1;
  12758. hash_test[1] = hash2;
  12759. hash_test[2] = hash3;
  12760. times = sizeof(hash_test) / sizeof(byte*);
  12761. for (i = 0; i < times; i++) {
  12762. ExpectIntEQ(wc_Sha256Final(&sha256, hash_test[i]), 0);
  12763. }
  12764. /* Test bad args. */
  12765. ExpectIntEQ(wc_Sha256Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12766. ExpectIntEQ(wc_Sha256Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12767. ExpectIntEQ(wc_Sha256Final(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12768. wc_Sha256Free(&sha256);
  12769. #endif
  12770. return EXPECT_RESULT();
  12771. } /* END test_wc_Sha256Final */
  12772. /*
  12773. * Unit test function for wc_Sha256FinalRaw()
  12774. */
  12775. static int test_wc_Sha256FinalRaw(void)
  12776. {
  12777. EXPECT_DECLS;
  12778. #if !defined(NO_SHA256) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_DEVCRYPTO) && (!defined(HAVE_FIPS) || \
  12779. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3))) && \
  12780. !defined(WOLFSSL_NO_HASH_RAW)
  12781. wc_Sha256 sha256;
  12782. byte* hash_test[3];
  12783. byte hash1[WC_SHA256_DIGEST_SIZE];
  12784. byte hash2[2*WC_SHA256_DIGEST_SIZE];
  12785. byte hash3[5*WC_SHA256_DIGEST_SIZE];
  12786. int times, i;
  12787. /* Initialize */
  12788. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12789. hash_test[0] = hash1;
  12790. hash_test[1] = hash2;
  12791. hash_test[2] = hash3;
  12792. times = sizeof(hash_test) / sizeof(byte*);
  12793. for (i = 0; i < times; i++) {
  12794. ExpectIntEQ(wc_Sha256FinalRaw(&sha256, hash_test[i]), 0);
  12795. }
  12796. /* Test bad args. */
  12797. ExpectIntEQ(wc_Sha256FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12798. ExpectIntEQ(wc_Sha256FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12799. ExpectIntEQ(wc_Sha256FinalRaw(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12800. wc_Sha256Free(&sha256);
  12801. #endif
  12802. return EXPECT_RESULT();
  12803. } /* END test_wc_Sha256FinalRaw */
  12804. /*
  12805. * Unit test function for wc_Sha256GetFlags()
  12806. */
  12807. static int test_wc_Sha256GetFlags(void)
  12808. {
  12809. EXPECT_DECLS;
  12810. #if !defined(NO_SHA256) && defined(WOLFSSL_HASH_FLAGS)
  12811. wc_Sha256 sha256;
  12812. word32 flags = 0;
  12813. /* Initialize */
  12814. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12815. ExpectIntEQ(wc_Sha256GetFlags(&sha256, &flags), 0);
  12816. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  12817. wc_Sha256Free(&sha256);
  12818. #endif
  12819. return EXPECT_RESULT();
  12820. } /* END test_wc_Sha256GetFlags */
  12821. /*
  12822. * Unit test function for wc_Sha256Free()
  12823. */
  12824. static int test_wc_Sha256Free(void)
  12825. {
  12826. EXPECT_DECLS;
  12827. #ifndef NO_SHA256
  12828. wc_Sha256Free(NULL);
  12829. /* Set result to SUCCESS. */
  12830. ExpectTrue(1);
  12831. #endif
  12832. return EXPECT_RESULT();
  12833. } /* END test_wc_Sha256Free */
  12834. /*
  12835. * Unit test function for wc_Sha256GetHash()
  12836. */
  12837. static int test_wc_Sha256GetHash(void)
  12838. {
  12839. EXPECT_DECLS;
  12840. #ifndef NO_SHA256
  12841. wc_Sha256 sha256;
  12842. byte hash1[WC_SHA256_DIGEST_SIZE];
  12843. /* Initialize */
  12844. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12845. ExpectIntEQ(wc_Sha256GetHash(&sha256, hash1), 0);
  12846. /* test bad arguments*/
  12847. ExpectIntEQ(wc_Sha256GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12848. ExpectIntEQ(wc_Sha256GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12849. ExpectIntEQ(wc_Sha256GetHash(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12850. wc_Sha256Free(&sha256);
  12851. #endif
  12852. return EXPECT_RESULT();
  12853. } /* END test_wc_Sha256GetHash */
  12854. /*
  12855. * Unit test function for wc_Sha256Copy()
  12856. */
  12857. static int test_wc_Sha256Copy(void)
  12858. {
  12859. EXPECT_DECLS;
  12860. #ifndef NO_SHA256
  12861. wc_Sha256 sha256;
  12862. wc_Sha256 temp;
  12863. XMEMSET(&sha256, 0, sizeof(sha256));
  12864. XMEMSET(&temp, 0, sizeof(temp));
  12865. /* Initialize */
  12866. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12867. ExpectIntEQ(wc_InitSha256(&temp), 0);
  12868. ExpectIntEQ(wc_Sha256Copy(&sha256, &temp), 0);
  12869. /* test bad arguments*/
  12870. ExpectIntEQ(wc_Sha256Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12871. ExpectIntEQ(wc_Sha256Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12872. ExpectIntEQ(wc_Sha256Copy(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12873. wc_Sha256Free(&sha256);
  12874. wc_Sha256Free(&temp);
  12875. #endif
  12876. return EXPECT_RESULT();
  12877. } /* END test_wc_Sha256Copy */
  12878. /*
  12879. * Testing wc_InitSha512()
  12880. */
  12881. static int test_wc_InitSha512(void)
  12882. {
  12883. EXPECT_DECLS;
  12884. #ifdef WOLFSSL_SHA512
  12885. wc_Sha512 sha512;
  12886. /* Test good arg. */
  12887. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12888. /* Test bad arg. */
  12889. ExpectIntEQ(wc_InitSha512(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12890. wc_Sha512Free(&sha512);
  12891. #endif
  12892. return EXPECT_RESULT();
  12893. } /* END test_wc_InitSha512 */
  12894. /*
  12895. * wc_Sha512Update() test.
  12896. */
  12897. static int test_wc_Sha512Update(void)
  12898. {
  12899. EXPECT_DECLS;
  12900. #ifdef WOLFSSL_SHA512
  12901. wc_Sha512 sha512;
  12902. byte hash[WC_SHA512_DIGEST_SIZE];
  12903. byte hash_unaligned[WC_SHA512_DIGEST_SIZE + 1];
  12904. testVector a, b, c;
  12905. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12906. /* Input. */
  12907. a.input = "a";
  12908. a.inLen = XSTRLEN(a.input);
  12909. ExpectIntEQ(wc_Sha512Update(&sha512, NULL, 0), 0);
  12910. ExpectIntEQ(wc_Sha512Update(&sha512,(byte*)a.input, 0), 0);
  12911. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)a.input, (word32)a.inLen), 0);
  12912. ExpectIntEQ(wc_Sha512Final(&sha512, hash), 0);
  12913. /* Update input. */
  12914. a.input = "abc";
  12915. a.output = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  12916. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b"
  12917. "\x55\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c"
  12918. "\x23\xa3\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a"
  12919. "\x9a\xc9\x4f\xa5\x4c\xa4\x9f";
  12920. a.inLen = XSTRLEN(a.input);
  12921. a.outLen = XSTRLEN(a.output);
  12922. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*) a.input, (word32) a.inLen), 0);
  12923. ExpectIntEQ(wc_Sha512Final(&sha512, hash), 0);
  12924. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_DIGEST_SIZE), 0);
  12925. /* Unaligned check. */
  12926. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)a.input+1, (word32)a.inLen-1),
  12927. 0);
  12928. ExpectIntEQ(wc_Sha512Final(&sha512, hash_unaligned+1), 0);
  12929. /* Try passing in bad values */
  12930. b.input = NULL;
  12931. b.inLen = 0;
  12932. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)b.input, (word32)b.inLen), 0);
  12933. c.input = NULL;
  12934. c.inLen = WC_SHA512_DIGEST_SIZE;
  12935. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)c.input, (word32)c.inLen),
  12936. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12937. ExpectIntEQ(wc_Sha512Update(NULL, (byte*)a.input, (word32)a.inLen),
  12938. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12939. wc_Sha512Free(&sha512);
  12940. #endif
  12941. return EXPECT_RESULT();
  12942. } /* END test_wc_Sha512Update */
  12943. #ifdef WOLFSSL_SHA512
  12944. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  12945. (!defined(WOLFSSL_NOSHA512_224) || !defined(WOLFSSL_NOSHA512_256))
  12946. /* Performs test for
  12947. * - wc_Sha512Final/wc_Sha512FinalRaw
  12948. * - wc_Sha512_224Final/wc_Sha512_224Final
  12949. * - wc_Sha512_256Final/wc_Sha512_256Final
  12950. * parameter:
  12951. * - type : must be one of WC_HASH_TYPE_SHA512, WC_HASH_TYPE_SHA512_224 or
  12952. * WC_HASH_TYPE_SHA512_256
  12953. * - isRaw: if is non-zero, xxxFinalRaw function will be tested
  12954. *return 0 on success
  12955. */
  12956. static int test_Sha512_Family_Final(int type, int isRaw)
  12957. {
  12958. EXPECT_DECLS;
  12959. wc_Sha512 sha512;
  12960. byte* hash_test[3];
  12961. byte hash1[WC_SHA512_DIGEST_SIZE];
  12962. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  12963. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  12964. int times, i;
  12965. int(*initFp)(wc_Sha512*);
  12966. int(*finalFp)(wc_Sha512*, byte*);
  12967. void(*freeFp)(wc_Sha512*);
  12968. if (type == WC_HASH_TYPE_SHA512) {
  12969. initFp = wc_InitSha512;
  12970. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  12971. !defined(WOLFSSL_NO_HASH_RAW)
  12972. finalFp = (isRaw)? wc_Sha512FinalRaw : wc_Sha512Final;
  12973. #else
  12974. finalFp = (isRaw)? NULL : wc_Sha512Final;
  12975. #endif
  12976. freeFp = wc_Sha512Free;
  12977. }
  12978. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12979. #if !defined(WOLFSSL_NOSHA512_224)
  12980. else if (type == WC_HASH_TYPE_SHA512_224) {
  12981. initFp = wc_InitSha512_224;
  12982. #if !defined(WOLFSSL_NO_HASH_RAW)
  12983. finalFp = (isRaw)? wc_Sha512_224FinalRaw : wc_Sha512_224Final;
  12984. #else
  12985. finalFp = (isRaw)? NULL : wc_Sha512_224Final;
  12986. #endif
  12987. freeFp = wc_Sha512_224Free;
  12988. }
  12989. #endif
  12990. #if !defined(WOLFSSL_NOSHA512_256)
  12991. else if (type == WC_HASH_TYPE_SHA512_256) {
  12992. initFp = wc_InitSha512_256;
  12993. #if !defined(WOLFSSL_NO_HASH_RAW)
  12994. finalFp = (isRaw)? wc_Sha512_256FinalRaw : wc_Sha512_256Final;
  12995. #else
  12996. finalFp = (isRaw)? NULL : wc_Sha512_256Final;
  12997. #endif
  12998. freeFp = wc_Sha512_256Free;
  12999. }
  13000. #endif
  13001. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13002. else
  13003. return TEST_FAIL;
  13004. /* Initialize */
  13005. ExpectIntEQ(initFp(&sha512), 0);
  13006. hash_test[0] = hash1;
  13007. hash_test[1] = hash2;
  13008. hash_test[2] = hash3;
  13009. times = sizeof(hash_test) / sizeof(byte *);
  13010. #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST) || \
  13011. defined(WOLFSSL_NO_HASH_RAW)
  13012. if (finalFp != NULL)
  13013. #endif
  13014. {
  13015. /* Good test args. */
  13016. for (i = 0; i < times; i++) {
  13017. ExpectIntEQ(finalFp(&sha512, hash_test[i]), 0);
  13018. }
  13019. /* Test bad args. */
  13020. ExpectIntEQ(finalFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13021. ExpectIntEQ(finalFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13022. ExpectIntEQ(finalFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13023. }
  13024. freeFp(&sha512);
  13025. return EXPECT_RESULT();
  13026. }
  13027. #endif /* !HAVE_FIPS && !HAVE_SELFTEST &&
  13028. (!WOLFSSL_NOSHA512_224 || !WOLFSSL_NOSHA512_256) */
  13029. #endif /* WOLFSSL_SHA512 */
  13030. /*
  13031. * Unit test function for wc_Sha512Final()
  13032. */
  13033. static int test_wc_Sha512Final(void)
  13034. {
  13035. EXPECT_DECLS;
  13036. #ifdef WOLFSSL_SHA512
  13037. wc_Sha512 sha512;
  13038. byte* hash_test[3];
  13039. byte hash1[WC_SHA512_DIGEST_SIZE];
  13040. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  13041. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  13042. int times, i;
  13043. /* Initialize */
  13044. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13045. hash_test[0] = hash1;
  13046. hash_test[1] = hash2;
  13047. hash_test[2] = hash3;
  13048. times = sizeof(hash_test) / sizeof(byte *);
  13049. for (i = 0; i < times; i++) {
  13050. ExpectIntEQ(wc_Sha512Final(&sha512, hash_test[i]), 0);
  13051. }
  13052. /* Test bad args. */
  13053. ExpectIntEQ(wc_Sha512Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13054. ExpectIntEQ(wc_Sha512Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13055. ExpectIntEQ(wc_Sha512Final(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13056. wc_Sha512Free(&sha512);
  13057. #endif
  13058. return EXPECT_RESULT();
  13059. } /* END test_wc_Sha512Final */
  13060. /*
  13061. * Unit test function for wc_Sha512GetFlags()
  13062. */
  13063. static int test_wc_Sha512GetFlags(void)
  13064. {
  13065. EXPECT_DECLS;
  13066. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_HASH_FLAGS)
  13067. wc_Sha512 sha512;
  13068. word32 flags = 0;
  13069. /* Initialize */
  13070. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13071. ExpectIntEQ(wc_Sha512GetFlags(&sha512, &flags), 0);
  13072. ExpectIntEQ((flags & WC_HASH_FLAG_ISCOPY), 0);
  13073. wc_Sha512Free(&sha512);
  13074. #endif
  13075. return EXPECT_RESULT();
  13076. } /* END test_wc_Sha512GetFlags */
  13077. /*
  13078. * Unit test function for wc_Sha512FinalRaw()
  13079. */
  13080. static int test_wc_Sha512FinalRaw(void)
  13081. {
  13082. EXPECT_DECLS;
  13083. #if (defined(WOLFSSL_SHA512) && !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  13084. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)))) && \
  13085. !defined(WOLFSSL_NO_HASH_RAW)
  13086. wc_Sha512 sha512;
  13087. byte* hash_test[3];
  13088. byte hash1[WC_SHA512_DIGEST_SIZE];
  13089. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  13090. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  13091. int times, i;
  13092. /* Initialize */
  13093. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13094. hash_test[0] = hash1;
  13095. hash_test[1] = hash2;
  13096. hash_test[2] = hash3;
  13097. times = sizeof(hash_test) / sizeof(byte*);
  13098. /* Good test args. */
  13099. for (i = 0; i < times; i++) {
  13100. ExpectIntEQ(wc_Sha512FinalRaw(&sha512, hash_test[i]), 0);
  13101. }
  13102. /* Test bad args. */
  13103. ExpectIntEQ(wc_Sha512FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13104. ExpectIntEQ(wc_Sha512FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13105. ExpectIntEQ(wc_Sha512FinalRaw(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13106. wc_Sha512Free(&sha512);
  13107. #endif
  13108. return EXPECT_RESULT();
  13109. } /* END test_wc_Sha512FinalRaw */
  13110. /*
  13111. * Unit test function for wc_Sha512Free()
  13112. */
  13113. static int test_wc_Sha512Free(void)
  13114. {
  13115. EXPECT_DECLS;
  13116. #ifdef WOLFSSL_SHA512
  13117. wc_Sha512Free(NULL);
  13118. /* Set result to SUCCESS. */
  13119. ExpectTrue(1);
  13120. #endif
  13121. return EXPECT_RESULT();
  13122. } /* END test_wc_Sha512Free */
  13123. #ifdef WOLFSSL_SHA512
  13124. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  13125. (!defined(WOLFSSL_NOSHA512_224) || !defined(WOLFSSL_NOSHA512_256))
  13126. static int test_Sha512_Family_GetHash(int type )
  13127. {
  13128. EXPECT_DECLS;
  13129. int(*initFp)(wc_Sha512*);
  13130. int(*ghashFp)(wc_Sha512*, byte*);
  13131. wc_Sha512 sha512;
  13132. byte hash1[WC_SHA512_DIGEST_SIZE];
  13133. if (type == WC_HASH_TYPE_SHA512) {
  13134. initFp = wc_InitSha512;
  13135. ghashFp = wc_Sha512GetHash;
  13136. }
  13137. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13138. #if !defined(WOLFSSL_NOSHA512_224)
  13139. else if (type == WC_HASH_TYPE_SHA512_224) {
  13140. initFp = wc_InitSha512_224;
  13141. ghashFp = wc_Sha512_224GetHash;
  13142. }
  13143. #endif
  13144. #if !defined(WOLFSSL_NOSHA512_256)
  13145. else if (type == WC_HASH_TYPE_SHA512_256) {
  13146. initFp = wc_InitSha512_256;
  13147. ghashFp = wc_Sha512_256GetHash;
  13148. }
  13149. #endif
  13150. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13151. else {
  13152. initFp = NULL;
  13153. ghashFp = NULL;
  13154. }
  13155. if (initFp == NULL || ghashFp == NULL)
  13156. return TEST_FAIL;
  13157. ExpectIntEQ(initFp(&sha512), 0);
  13158. ExpectIntEQ(ghashFp(&sha512, hash1), 0);
  13159. /* test bad arguments*/
  13160. ExpectIntEQ(ghashFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13161. ExpectIntEQ(ghashFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13162. ExpectIntEQ(ghashFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13163. wc_Sha512Free(&sha512);
  13164. return EXPECT_RESULT();
  13165. }
  13166. #endif /* !HAVE_FIPS && !HAVE_SELFTEST &&
  13167. (!WOLFSSL_NOSHA512_224 || !WOLFSSL_NOSHA512_256) */
  13168. #endif /* WOLFSSL_SHA512 */
  13169. /*
  13170. * Unit test function for wc_Sha512GetHash()
  13171. */
  13172. static int test_wc_Sha512GetHash(void)
  13173. {
  13174. EXPECT_DECLS;
  13175. #ifdef WOLFSSL_SHA512
  13176. wc_Sha512 sha512;
  13177. byte hash1[WC_SHA512_DIGEST_SIZE];
  13178. /* Initialize */
  13179. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13180. ExpectIntEQ(wc_Sha512GetHash(&sha512, hash1), 0);
  13181. /* test bad arguments*/
  13182. ExpectIntEQ(wc_Sha512GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13183. ExpectIntEQ(wc_Sha512GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13184. ExpectIntEQ(wc_Sha512GetHash(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13185. wc_Sha512Free(&sha512);
  13186. #endif
  13187. return EXPECT_RESULT();
  13188. } /* END test_wc_Sha512GetHash */
  13189. /*
  13190. * Unit test function for wc_Sha512Copy()
  13191. */
  13192. static int test_wc_Sha512Copy(void)
  13193. {
  13194. EXPECT_DECLS;
  13195. #ifdef WOLFSSL_SHA512
  13196. wc_Sha512 sha512;
  13197. wc_Sha512 temp;
  13198. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13199. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  13200. /* Initialize */
  13201. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13202. ExpectIntEQ(wc_InitSha512(&temp), 0);
  13203. ExpectIntEQ(wc_Sha512Copy(&sha512, &temp), 0);
  13204. /* test bad arguments*/
  13205. ExpectIntEQ(wc_Sha512Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13206. ExpectIntEQ(wc_Sha512Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13207. ExpectIntEQ(wc_Sha512Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13208. wc_Sha512Free(&sha512);
  13209. wc_Sha512Free(&temp);
  13210. #endif
  13211. return EXPECT_RESULT();
  13212. } /* END test_wc_Sha512Copy */
  13213. static int test_wc_InitSha512_224(void)
  13214. {
  13215. EXPECT_DECLS;
  13216. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13217. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13218. wc_Sha512 sha512;
  13219. /* Test good arg. */
  13220. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13221. /* Test bad arg. */
  13222. ExpectIntEQ(wc_InitSha512_224(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13223. wc_Sha512_224Free(&sha512);
  13224. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  13225. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13226. return EXPECT_RESULT();
  13227. }
  13228. static int test_wc_Sha512_224Update(void)
  13229. {
  13230. EXPECT_DECLS;
  13231. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13232. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13233. wc_Sha512 sha512;
  13234. byte hash[WC_SHA512_DIGEST_SIZE];
  13235. testVector a, c;
  13236. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13237. /* Input. */
  13238. a.input = "a";
  13239. a.inLen = XSTRLEN(a.input);
  13240. ExpectIntEQ(wc_Sha512_224Update(&sha512, NULL, 0), 0);
  13241. ExpectIntEQ(wc_Sha512_224Update(&sha512,(byte*)a.input, 0), 0);
  13242. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*)a.input, (word32)a.inLen),
  13243. 0);
  13244. ExpectIntEQ(wc_Sha512_224Final(&sha512, hash), 0);
  13245. /* Update input. */
  13246. a.input = "abc";
  13247. a.output = "\x46\x34\x27\x0f\x70\x7b\x6a\x54\xda\xae\x75\x30\x46\x08"
  13248. "\x42\xe2\x0e\x37\xed\x26\x5c\xee\xe9\xa4\x3e\x89\x24\xaa";
  13249. a.inLen = XSTRLEN(a.input);
  13250. a.outLen = XSTRLEN(a.output);
  13251. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*) a.input, (word32) a.inLen),
  13252. 0);
  13253. ExpectIntEQ(wc_Sha512_224Final(&sha512, hash), 0);
  13254. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_224_DIGEST_SIZE), 0);
  13255. c.input = NULL;
  13256. c.inLen = WC_SHA512_224_DIGEST_SIZE;
  13257. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*)c.input, (word32)c.inLen),
  13258. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13259. ExpectIntEQ(wc_Sha512_224Update(NULL, (byte*)a.input, (word32)a.inLen),
  13260. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13261. wc_Sha512_224Free(&sha512);
  13262. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  13263. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13264. return EXPECT_RESULT();
  13265. }
  13266. static int test_wc_Sha512_224Final(void)
  13267. {
  13268. EXPECT_DECLS;
  13269. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13270. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13271. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_224, 0),
  13272. TEST_SUCCESS);
  13273. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  13274. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13275. return EXPECT_RESULT();
  13276. }
  13277. static int test_wc_Sha512_224GetFlags(void)
  13278. {
  13279. EXPECT_DECLS;
  13280. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13281. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) && defined(WOLFSSL_HASH_FLAGS)
  13282. wc_Sha512 sha512;
  13283. wc_Sha512 copy;
  13284. word32 flags = 0;
  13285. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13286. XMEMSET(&copy, 0, sizeof(wc_Sha512));
  13287. /* Initialize */
  13288. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13289. ExpectIntEQ(wc_InitSha512_224(&copy), 0);
  13290. ExpectIntEQ(wc_Sha512_224GetFlags(&sha512, &flags), 0);
  13291. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13292. ExpectIntEQ(wc_Sha512_224Copy(&sha512, &copy), 0);
  13293. ExpectIntEQ(wc_Sha512_224GetFlags(&copy, &flags), 0);
  13294. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == WC_HASH_FLAG_ISCOPY);
  13295. wc_Sha512_224Free(&copy);
  13296. wc_Sha512_224Free(&sha512);
  13297. #endif
  13298. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13299. return EXPECT_RESULT();
  13300. }
  13301. static int test_wc_Sha512_224FinalRaw(void)
  13302. {
  13303. EXPECT_DECLS;
  13304. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  13305. defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) && \
  13306. !defined(WOLFSSL_NO_HASH_RAW)
  13307. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_224, 1),
  13308. TEST_SUCCESS);
  13309. #endif
  13310. return EXPECT_RESULT();
  13311. }
  13312. static int test_wc_Sha512_224Free(void)
  13313. {
  13314. EXPECT_DECLS;
  13315. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13316. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13317. wc_Sha512_224Free(NULL);
  13318. /* Set result to SUCCESS. */
  13319. ExpectTrue(1);
  13320. #endif
  13321. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13322. return EXPECT_RESULT();
  13323. }
  13324. static int test_wc_Sha512_224GetHash(void)
  13325. {
  13326. EXPECT_DECLS;
  13327. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13328. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13329. ExpectIntEQ(test_Sha512_Family_GetHash(WC_HASH_TYPE_SHA512_224),
  13330. TEST_SUCCESS);
  13331. #endif
  13332. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13333. return EXPECT_RESULT();
  13334. }
  13335. static int test_wc_Sha512_224Copy(void)
  13336. {
  13337. EXPECT_DECLS;
  13338. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13339. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13340. wc_Sha512 sha512;
  13341. wc_Sha512 temp;
  13342. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13343. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  13344. /* Initialize */
  13345. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13346. ExpectIntEQ(wc_InitSha512_224(&temp), 0);
  13347. ExpectIntEQ(wc_Sha512_224Copy(&sha512, &temp), 0);
  13348. /* test bad arguments*/
  13349. ExpectIntEQ(wc_Sha512_224Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13350. ExpectIntEQ(wc_Sha512_224Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13351. ExpectIntEQ(wc_Sha512_224Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13352. wc_Sha512_224Free(&sha512);
  13353. wc_Sha512_224Free(&temp);
  13354. #endif
  13355. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13356. return EXPECT_RESULT();
  13357. }
  13358. static int test_wc_InitSha512_256(void)
  13359. {
  13360. EXPECT_DECLS;
  13361. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13362. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13363. wc_Sha512 sha512;
  13364. /* Test good arg. */
  13365. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13366. /* Test bad arg. */
  13367. ExpectIntEQ(wc_InitSha512_256(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13368. wc_Sha512_256Free(&sha512);
  13369. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  13370. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13371. return EXPECT_RESULT();
  13372. }
  13373. static int test_wc_Sha512_256Update(void)
  13374. {
  13375. EXPECT_DECLS;
  13376. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13377. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13378. wc_Sha512 sha512;
  13379. byte hash[WC_SHA512_DIGEST_SIZE];
  13380. testVector a, c;
  13381. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13382. /* Input. */
  13383. a.input = "a";
  13384. a.inLen = XSTRLEN(a.input);
  13385. ExpectIntEQ(wc_Sha512_256Update(&sha512, NULL, 0), 0);
  13386. ExpectIntEQ(wc_Sha512_256Update(&sha512,(byte*)a.input, 0), 0);
  13387. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*)a.input, (word32)a.inLen),
  13388. 0);
  13389. ExpectIntEQ(wc_Sha512_256Final(&sha512, hash), 0);
  13390. /* Update input. */
  13391. a.input = "abc";
  13392. a.output = "\x53\x04\x8e\x26\x81\x94\x1e\xf9\x9b\x2e\x29\xb7\x6b\x4c"
  13393. "\x7d\xab\xe4\xc2\xd0\xc6\x34\xfc\x6d\x46\xe0\xe2\xf1\x31"
  13394. "\x07\xe7\xaf\x23";
  13395. a.inLen = XSTRLEN(a.input);
  13396. a.outLen = XSTRLEN(a.output);
  13397. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*) a.input, (word32) a.inLen),
  13398. 0);
  13399. ExpectIntEQ(wc_Sha512_256Final(&sha512, hash), 0);
  13400. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_256_DIGEST_SIZE), 0);
  13401. c.input = NULL;
  13402. c.inLen = WC_SHA512_256_DIGEST_SIZE;
  13403. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*)c.input, (word32)c.inLen),
  13404. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13405. ExpectIntEQ(wc_Sha512_256Update(NULL, (byte*)a.input, (word32)a.inLen),
  13406. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13407. wc_Sha512_256Free(&sha512);
  13408. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  13409. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13410. return EXPECT_RESULT();
  13411. }
  13412. static int test_wc_Sha512_256Final(void)
  13413. {
  13414. EXPECT_DECLS;
  13415. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13416. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13417. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_256, 0),
  13418. TEST_SUCCESS);
  13419. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  13420. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13421. return EXPECT_RESULT();
  13422. }
  13423. static int test_wc_Sha512_256GetFlags(void)
  13424. {
  13425. EXPECT_DECLS;
  13426. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13427. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) && defined(WOLFSSL_HASH_FLAGS)
  13428. wc_Sha512 sha512, copy;
  13429. word32 flags = 0;
  13430. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13431. XMEMSET(&copy, 0, sizeof(wc_Sha512));
  13432. /* Initialize */
  13433. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13434. ExpectIntEQ(wc_InitSha512_256(&copy), 0);
  13435. ExpectIntEQ(wc_Sha512_256GetFlags(&sha512, &flags), 0);
  13436. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13437. ExpectIntEQ(wc_Sha512_256Copy(&sha512, &copy), 0);
  13438. ExpectIntEQ(wc_Sha512_256GetFlags(&copy, &flags), 0);
  13439. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == WC_HASH_FLAG_ISCOPY);
  13440. wc_Sha512_256Free(&sha512);
  13441. #endif
  13442. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13443. return EXPECT_RESULT();
  13444. }
  13445. static int test_wc_Sha512_256FinalRaw(void)
  13446. {
  13447. EXPECT_DECLS;
  13448. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  13449. defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) && \
  13450. !defined(WOLFSSL_NO_HASH_RAW)
  13451. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_256, 1),
  13452. TEST_SUCCESS);
  13453. #endif
  13454. return EXPECT_RESULT();
  13455. }
  13456. static int test_wc_Sha512_256Free(void)
  13457. {
  13458. EXPECT_DECLS;
  13459. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13460. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13461. wc_Sha512_256Free(NULL);
  13462. /* Set result to SUCCESS. */
  13463. ExpectTrue(1);
  13464. #endif
  13465. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13466. return EXPECT_RESULT();
  13467. }
  13468. static int test_wc_Sha512_256GetHash(void)
  13469. {
  13470. EXPECT_DECLS;
  13471. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13472. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13473. ExpectIntEQ(test_Sha512_Family_GetHash(WC_HASH_TYPE_SHA512_256),
  13474. TEST_SUCCESS);
  13475. #endif
  13476. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13477. return EXPECT_RESULT();
  13478. }
  13479. static int test_wc_Sha512_256Copy(void)
  13480. {
  13481. EXPECT_DECLS;
  13482. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13483. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13484. wc_Sha512 sha512;
  13485. wc_Sha512 temp;
  13486. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13487. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  13488. /* Initialize */
  13489. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13490. ExpectIntEQ(wc_InitSha512_256(&temp), 0);
  13491. ExpectIntEQ(wc_Sha512_256Copy(&sha512, &temp), 0);
  13492. /* test bad arguments*/
  13493. ExpectIntEQ(wc_Sha512_256Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13494. ExpectIntEQ(wc_Sha512_256Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13495. ExpectIntEQ(wc_Sha512_256Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13496. wc_Sha512_256Free(&sha512);
  13497. wc_Sha512_256Free(&temp);
  13498. #endif
  13499. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13500. return EXPECT_RESULT();
  13501. }
  13502. /*
  13503. * Testing wc_InitSha384()
  13504. */
  13505. static int test_wc_InitSha384(void)
  13506. {
  13507. EXPECT_DECLS;
  13508. #ifdef WOLFSSL_SHA384
  13509. wc_Sha384 sha384;
  13510. /* Test good arg. */
  13511. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13512. /* Test bad arg. */
  13513. ExpectIntEQ(wc_InitSha384(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13514. wc_Sha384Free(&sha384);
  13515. #endif
  13516. return EXPECT_RESULT();
  13517. } /* END test_wc_InitSha384 */
  13518. /*
  13519. * test wc_Sha384Update()
  13520. */
  13521. static int test_wc_Sha384Update(void)
  13522. {
  13523. EXPECT_DECLS;
  13524. #ifdef WOLFSSL_SHA384
  13525. wc_Sha384 sha384;
  13526. byte hash[WC_SHA384_DIGEST_SIZE];
  13527. testVector a, b, c;
  13528. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13529. /* Input */
  13530. a.input = "a";
  13531. a.inLen = XSTRLEN(a.input);
  13532. ExpectIntEQ(wc_Sha384Update(&sha384, NULL, 0), 0);
  13533. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, 0), 0);
  13534. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, (word32)a.inLen), 0);
  13535. ExpectIntEQ(wc_Sha384Final(&sha384, hash), 0);
  13536. /* Update input. */
  13537. a.input = "abc";
  13538. a.output = "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  13539. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  13540. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  13541. "\xc8\x25\xa7";
  13542. a.inLen = XSTRLEN(a.input);
  13543. a.outLen = XSTRLEN(a.output);
  13544. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, (word32)a.inLen), 0);
  13545. ExpectIntEQ(wc_Sha384Final(&sha384, hash), 0);
  13546. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA384_DIGEST_SIZE), 0);
  13547. /* Pass in bad values. */
  13548. b.input = NULL;
  13549. b.inLen = 0;
  13550. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)b.input, (word32)b.inLen), 0);
  13551. c.input = NULL;
  13552. c.inLen = WC_SHA384_DIGEST_SIZE;
  13553. ExpectIntEQ( wc_Sha384Update(&sha384, (byte*)c.input, (word32)c.inLen),
  13554. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13555. ExpectIntEQ(wc_Sha384Update(NULL, (byte*)a.input, (word32)a.inLen),
  13556. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13557. wc_Sha384Free(&sha384);
  13558. #endif
  13559. return EXPECT_RESULT();
  13560. } /* END test_wc_Sha384Update */
  13561. /*
  13562. * Unit test function for wc_Sha384Final();
  13563. */
  13564. static int test_wc_Sha384Final(void)
  13565. {
  13566. EXPECT_DECLS;
  13567. #ifdef WOLFSSL_SHA384
  13568. wc_Sha384 sha384;
  13569. byte* hash_test[3];
  13570. byte hash1[WC_SHA384_DIGEST_SIZE];
  13571. byte hash2[2*WC_SHA384_DIGEST_SIZE];
  13572. byte hash3[5*WC_SHA384_DIGEST_SIZE];
  13573. int times, i;
  13574. /* Initialize */
  13575. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13576. hash_test[0] = hash1;
  13577. hash_test[1] = hash2;
  13578. hash_test[2] = hash3;
  13579. times = sizeof(hash_test) / sizeof(byte*);
  13580. /* Good test args. */
  13581. for (i = 0; i < times; i++) {
  13582. ExpectIntEQ(wc_Sha384Final(&sha384, hash_test[i]), 0);
  13583. }
  13584. /* Test bad args. */
  13585. ExpectIntEQ(wc_Sha384Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13586. ExpectIntEQ(wc_Sha384Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13587. ExpectIntEQ(wc_Sha384Final(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13588. wc_Sha384Free(&sha384);
  13589. #endif
  13590. return EXPECT_RESULT();
  13591. } /* END test_wc_Sha384Final */
  13592. /*
  13593. * Unit test function for wc_Sha384GetFlags()
  13594. */
  13595. static int test_wc_Sha384GetFlags(void)
  13596. {
  13597. EXPECT_DECLS;
  13598. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_HASH_FLAGS)
  13599. wc_Sha384 sha384;
  13600. word32 flags = 0;
  13601. /* Initialize */
  13602. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13603. ExpectIntEQ(wc_Sha384GetFlags(&sha384, &flags), 0);
  13604. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13605. wc_Sha384Free(&sha384);
  13606. #endif
  13607. return EXPECT_RESULT();
  13608. } /* END test_wc_Sha384GetFlags */
  13609. /*
  13610. * Unit test function for wc_Sha384FinalRaw()
  13611. */
  13612. static int test_wc_Sha384FinalRaw(void)
  13613. {
  13614. EXPECT_DECLS;
  13615. #if (defined(WOLFSSL_SHA384) && !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  13616. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)))) && \
  13617. !defined(WOLFSSL_NO_HASH_RAW)
  13618. wc_Sha384 sha384;
  13619. byte* hash_test[3];
  13620. byte hash1[WC_SHA384_DIGEST_SIZE];
  13621. byte hash2[2*WC_SHA384_DIGEST_SIZE];
  13622. byte hash3[5*WC_SHA384_DIGEST_SIZE];
  13623. int times, i;
  13624. /* Initialize */
  13625. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13626. hash_test[0] = hash1;
  13627. hash_test[1] = hash2;
  13628. hash_test[2] = hash3;
  13629. times = sizeof(hash_test) / sizeof(byte*);
  13630. /* Good test args. */
  13631. for (i = 0; i < times; i++) {
  13632. ExpectIntEQ(wc_Sha384FinalRaw(&sha384, hash_test[i]), 0);
  13633. }
  13634. /* Test bad args. */
  13635. ExpectIntEQ(wc_Sha384FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13636. ExpectIntEQ(wc_Sha384FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13637. ExpectIntEQ(wc_Sha384FinalRaw(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13638. wc_Sha384Free(&sha384);
  13639. #endif
  13640. return EXPECT_RESULT();
  13641. } /* END test_wc_Sha384FinalRaw */
  13642. /*
  13643. * Unit test function for wc_Sha384Free()
  13644. */
  13645. static int test_wc_Sha384Free(void)
  13646. {
  13647. EXPECT_DECLS;
  13648. #ifdef WOLFSSL_SHA384
  13649. wc_Sha384Free(NULL);
  13650. /* Set result to SUCCESS. */
  13651. ExpectTrue(1);
  13652. #endif
  13653. return EXPECT_RESULT();
  13654. } /* END test_wc_Sha384Free */
  13655. /*
  13656. * Unit test function for wc_Sha384GetHash()
  13657. */
  13658. static int test_wc_Sha384GetHash(void)
  13659. {
  13660. EXPECT_DECLS;
  13661. #ifdef WOLFSSL_SHA384
  13662. wc_Sha384 sha384;
  13663. byte hash1[WC_SHA384_DIGEST_SIZE];
  13664. /* Initialize */
  13665. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13666. ExpectIntEQ(wc_Sha384GetHash(&sha384, hash1), 0);
  13667. /* test bad arguments*/
  13668. ExpectIntEQ(wc_Sha384GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13669. ExpectIntEQ(wc_Sha384GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13670. ExpectIntEQ(wc_Sha384GetHash(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13671. wc_Sha384Free(&sha384);
  13672. #endif
  13673. return EXPECT_RESULT();
  13674. } /* END test_wc_Sha384GetHash */
  13675. /*
  13676. * Unit test function for wc_Sha384Copy()
  13677. */
  13678. static int test_wc_Sha384Copy(void)
  13679. {
  13680. EXPECT_DECLS;
  13681. #ifdef WOLFSSL_SHA384
  13682. wc_Sha384 sha384;
  13683. wc_Sha384 temp;
  13684. XMEMSET(&sha384, 0, sizeof(wc_Sha384));
  13685. XMEMSET(&temp, 0, sizeof(wc_Sha384));
  13686. /* Initialize */
  13687. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13688. ExpectIntEQ(wc_InitSha384(&temp), 0);
  13689. ExpectIntEQ(wc_Sha384Copy(&sha384, &temp), 0);
  13690. /* test bad arguments*/
  13691. ExpectIntEQ(wc_Sha384Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13692. ExpectIntEQ(wc_Sha384Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13693. ExpectIntEQ(wc_Sha384Copy(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13694. wc_Sha384Free(&sha384);
  13695. wc_Sha384Free(&temp);
  13696. #endif
  13697. return EXPECT_RESULT();
  13698. } /* END test_wc_Sha384Copy */
  13699. /*
  13700. * Testing wc_InitSha224();
  13701. */
  13702. static int test_wc_InitSha224(void)
  13703. {
  13704. EXPECT_DECLS;
  13705. #ifdef WOLFSSL_SHA224
  13706. wc_Sha224 sha224;
  13707. /* Test good arg. */
  13708. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13709. /* Test bad arg. */
  13710. ExpectIntEQ(wc_InitSha224(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13711. wc_Sha224Free(&sha224);
  13712. #endif
  13713. return EXPECT_RESULT();
  13714. } /* END test_wc_InitSha224 */
  13715. /*
  13716. * Unit test on wc_Sha224Update
  13717. */
  13718. static int test_wc_Sha224Update(void)
  13719. {
  13720. EXPECT_DECLS;
  13721. #ifdef WOLFSSL_SHA224
  13722. wc_Sha224 sha224;
  13723. byte hash[WC_SHA224_DIGEST_SIZE];
  13724. testVector a, b, c;
  13725. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13726. /* Input. */
  13727. a.input = "a";
  13728. a.inLen = XSTRLEN(a.input);
  13729. ExpectIntEQ(wc_Sha224Update(&sha224, NULL, 0), 0);
  13730. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, 0), 0);
  13731. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, (word32)a.inLen), 0);
  13732. ExpectIntEQ(wc_Sha224Final(&sha224, hash), 0);
  13733. /* Update input. */
  13734. a.input = "abc";
  13735. a.output = "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2"
  13736. "\x55\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7";
  13737. a.inLen = XSTRLEN(a.input);
  13738. a.outLen = XSTRLEN(a.output);
  13739. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, (word32)a.inLen), 0);
  13740. ExpectIntEQ(wc_Sha224Final(&sha224, hash), 0);
  13741. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA224_DIGEST_SIZE), 0);
  13742. /* Pass in bad values. */
  13743. b.input = NULL;
  13744. b.inLen = 0;
  13745. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)b.input, (word32)b.inLen), 0);
  13746. c.input = NULL;
  13747. c.inLen = WC_SHA224_DIGEST_SIZE;
  13748. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)c.input, (word32)c.inLen),
  13749. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13750. ExpectIntEQ(wc_Sha224Update(NULL, (byte*)a.input, (word32)a.inLen),
  13751. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13752. wc_Sha224Free(&sha224);
  13753. #endif
  13754. return EXPECT_RESULT();
  13755. } /* END test_wc_Sha224Update */
  13756. /*
  13757. * Unit test for wc_Sha224Final();
  13758. */
  13759. static int test_wc_Sha224Final(void)
  13760. {
  13761. EXPECT_DECLS;
  13762. #ifdef WOLFSSL_SHA224
  13763. wc_Sha224 sha224;
  13764. byte* hash_test[3];
  13765. byte hash1[WC_SHA224_DIGEST_SIZE];
  13766. byte hash2[2*WC_SHA224_DIGEST_SIZE];
  13767. byte hash3[5*WC_SHA224_DIGEST_SIZE];
  13768. int times, i;
  13769. /* Initialize */
  13770. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13771. hash_test[0] = hash1;
  13772. hash_test[1] = hash2;
  13773. hash_test[2] = hash3;
  13774. times = sizeof(hash_test) / sizeof(byte*);
  13775. /* Good test args. */
  13776. /* Testing oversized buffers. */
  13777. for (i = 0; i < times; i++) {
  13778. ExpectIntEQ(wc_Sha224Final(&sha224, hash_test[i]), 0);
  13779. }
  13780. /* Test bad args. */
  13781. ExpectIntEQ(wc_Sha224Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13782. ExpectIntEQ(wc_Sha224Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13783. ExpectIntEQ(wc_Sha224Final(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13784. wc_Sha224Free(&sha224);
  13785. #endif
  13786. return EXPECT_RESULT();
  13787. } /* END test_wc_Sha224Final */
  13788. /*
  13789. * Unit test function for wc_Sha224SetFlags()
  13790. */
  13791. static int test_wc_Sha224SetFlags(void)
  13792. {
  13793. EXPECT_DECLS;
  13794. #if defined(WOLFSSL_SHA224) && defined(WOLFSSL_HASH_FLAGS)
  13795. wc_Sha224 sha224;
  13796. word32 flags = WC_HASH_FLAG_WILLCOPY;
  13797. /* Initialize */
  13798. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13799. ExpectIntEQ(wc_Sha224SetFlags(&sha224, flags), 0);
  13800. flags = 0;
  13801. ExpectIntEQ(wc_Sha224GetFlags(&sha224, &flags), 0);
  13802. ExpectTrue(flags == WC_HASH_FLAG_WILLCOPY);
  13803. wc_Sha224Free(&sha224);
  13804. #endif
  13805. return EXPECT_RESULT();
  13806. } /* END test_wc_Sha224SetFlags */
  13807. /*
  13808. * Unit test function for wc_Sha224GetFlags()
  13809. */
  13810. static int test_wc_Sha224GetFlags(void)
  13811. {
  13812. EXPECT_DECLS;
  13813. #if defined(WOLFSSL_SHA224) && defined(WOLFSSL_HASH_FLAGS)
  13814. wc_Sha224 sha224;
  13815. word32 flags = 0;
  13816. /* Initialize */
  13817. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13818. ExpectIntEQ(wc_Sha224GetFlags(&sha224, &flags), 0);
  13819. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13820. wc_Sha224Free(&sha224);
  13821. #endif
  13822. return EXPECT_RESULT();
  13823. } /* END test_wc_Sha224GetFlags */
  13824. /*
  13825. * Unit test function for wc_Sha224Free()
  13826. */
  13827. static int test_wc_Sha224Free(void)
  13828. {
  13829. EXPECT_DECLS;
  13830. #ifdef WOLFSSL_SHA224
  13831. wc_Sha224Free(NULL);
  13832. /* Set result to SUCCESS. */
  13833. ExpectTrue(1);
  13834. #endif
  13835. return EXPECT_RESULT();
  13836. } /* END test_wc_Sha224Free */
  13837. /*
  13838. * Unit test function for wc_Sha224GetHash()
  13839. */
  13840. static int test_wc_Sha224GetHash(void)
  13841. {
  13842. EXPECT_DECLS;
  13843. #ifdef WOLFSSL_SHA224
  13844. wc_Sha224 sha224;
  13845. byte hash1[WC_SHA224_DIGEST_SIZE];
  13846. /* Initialize */
  13847. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13848. ExpectIntEQ(wc_Sha224GetHash(&sha224, hash1), 0);
  13849. /* test bad arguments*/
  13850. ExpectIntEQ(wc_Sha224GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13851. ExpectIntEQ(wc_Sha224GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13852. ExpectIntEQ(wc_Sha224GetHash(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13853. wc_Sha224Free(&sha224);
  13854. #endif
  13855. return EXPECT_RESULT();
  13856. } /* END test_wc_Sha224GetHash */
  13857. /*
  13858. * Unit test function for wc_Sha224Copy()
  13859. */
  13860. static int test_wc_Sha224Copy(void)
  13861. {
  13862. EXPECT_DECLS;
  13863. #ifdef WOLFSSL_SHA224
  13864. wc_Sha224 sha224;
  13865. wc_Sha224 temp;
  13866. XMEMSET(&sha224, 0, sizeof(wc_Sha224));
  13867. XMEMSET(&temp, 0, sizeof(wc_Sha224));
  13868. /* Initialize */
  13869. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13870. ExpectIntEQ(wc_InitSha224(&temp), 0);
  13871. ExpectIntEQ(wc_Sha224Copy(&sha224, &temp), 0);
  13872. /* test bad arguments*/
  13873. ExpectIntEQ(wc_Sha224Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13874. ExpectIntEQ(wc_Sha224Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13875. ExpectIntEQ(wc_Sha224Copy(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13876. wc_Sha224Free(&sha224);
  13877. wc_Sha224Free(&temp);
  13878. #endif
  13879. return EXPECT_RESULT();
  13880. } /* END test_wc_Sha224Copy */
  13881. /*
  13882. * Testing wc_InitRipeMd()
  13883. */
  13884. static int test_wc_InitRipeMd(void)
  13885. {
  13886. EXPECT_DECLS;
  13887. #ifdef WOLFSSL_RIPEMD
  13888. RipeMd ripemd;
  13889. /* Test good arg. */
  13890. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  13891. /* Test bad arg. */
  13892. ExpectIntEQ(wc_InitRipeMd(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13893. #endif
  13894. return EXPECT_RESULT();
  13895. } /* END test_wc_InitRipeMd */
  13896. /*
  13897. * Testing wc_RipeMdUpdate()
  13898. */
  13899. static int test_wc_RipeMdUpdate(void)
  13900. {
  13901. EXPECT_DECLS;
  13902. #ifdef WOLFSSL_RIPEMD
  13903. RipeMd ripemd;
  13904. byte hash[RIPEMD_DIGEST_SIZE];
  13905. testVector a, b, c;
  13906. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  13907. /* Input */
  13908. a.input = "a";
  13909. a.inLen = XSTRLEN(a.input);
  13910. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)a.input, (word32)a.inLen), 0);
  13911. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash), 0);
  13912. /* Update input. */
  13913. a.input = "abc";
  13914. a.output = "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04\x4a\x8e\x98\xc6"
  13915. "\xb0\x87\xf1\x5a\x0b\xfc";
  13916. a.inLen = XSTRLEN(a.input);
  13917. a.outLen = XSTRLEN(a.output);
  13918. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)a.input, (word32)a.inLen), 0);
  13919. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash), 0);
  13920. ExpectIntEQ(XMEMCMP(hash, a.output, RIPEMD_DIGEST_SIZE), 0);
  13921. /* Pass in bad values. */
  13922. b.input = NULL;
  13923. b.inLen = 0;
  13924. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)b.input, (word32)b.inLen), 0);
  13925. c.input = NULL;
  13926. c.inLen = RIPEMD_DIGEST_SIZE;
  13927. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)c.input, (word32)c.inLen),
  13928. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13929. ExpectIntEQ(wc_RipeMdUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  13930. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13931. #endif
  13932. return EXPECT_RESULT();
  13933. } /* END test_wc_RipeMdUdpate */
  13934. /*
  13935. * Unit test function for wc_RipeMdFinal()
  13936. */
  13937. static int test_wc_RipeMdFinal(void)
  13938. {
  13939. EXPECT_DECLS;
  13940. #ifdef WOLFSSL_RIPEMD
  13941. RipeMd ripemd;
  13942. byte* hash_test[3];
  13943. byte hash1[RIPEMD_DIGEST_SIZE];
  13944. byte hash2[2*RIPEMD_DIGEST_SIZE];
  13945. byte hash3[5*RIPEMD_DIGEST_SIZE];
  13946. int times, i;
  13947. /* Initialize */
  13948. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  13949. hash_test[0] = hash1;
  13950. hash_test[1] = hash2;
  13951. hash_test[2] = hash3;
  13952. times = sizeof(hash_test) / sizeof(byte*);
  13953. /* Testing oversized buffers. */
  13954. for (i = 0; i < times; i++) {
  13955. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash_test[i]), 0);
  13956. }
  13957. /* Test bad args. */
  13958. ExpectIntEQ(wc_RipeMdFinal(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13959. ExpectIntEQ(wc_RipeMdFinal(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13960. ExpectIntEQ(wc_RipeMdFinal(&ripemd, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13961. #endif
  13962. return EXPECT_RESULT();
  13963. } /* END test_wc_RipeMdFinal */
  13964. /*
  13965. * Testing wc_InitSha3_224, wc_InitSha3_256, wc_InitSha3_384, and
  13966. * wc_InitSha3_512
  13967. */
  13968. static int test_wc_InitSha3(void)
  13969. {
  13970. EXPECT_DECLS;
  13971. #if defined(WOLFSSL_SHA3)
  13972. wc_Sha3 sha3;
  13973. (void)sha3;
  13974. #if !defined(WOLFSSL_NOSHA3_224)
  13975. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  13976. /* Test bad args. */
  13977. ExpectIntEQ(wc_InitSha3_224(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13978. wc_Sha3_224_Free(&sha3);
  13979. #endif /* NOSHA3_224 */
  13980. #if !defined(WOLFSSL_NOSHA3_256)
  13981. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  13982. /* Test bad args. */
  13983. ExpectIntEQ(wc_InitSha3_256(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13984. wc_Sha3_256_Free(&sha3);
  13985. #endif /* NOSHA3_256 */
  13986. #if !defined(WOLFSSL_NOSHA3_384)
  13987. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  13988. /* Test bad args. */
  13989. ExpectIntEQ(wc_InitSha3_384(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13990. wc_Sha3_384_Free(&sha3);
  13991. #endif /* NOSHA3_384 */
  13992. #if !defined(WOLFSSL_NOSHA3_512)
  13993. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  13994. /* Test bad args. */
  13995. ExpectIntEQ(wc_InitSha3_512(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13996. wc_Sha3_512_Free(&sha3);
  13997. #endif /* NOSHA3_512 */
  13998. #endif
  13999. return EXPECT_RESULT();
  14000. } /* END test_wc_InitSha3 */
  14001. /*
  14002. * Testing wc_Sha3_Update()
  14003. */
  14004. static int testing_wc_Sha3_Update(void)
  14005. {
  14006. EXPECT_DECLS;
  14007. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_XILINX_CRYPT) && \
  14008. !defined(WOLFSSL_AFALG_XILINX)
  14009. wc_Sha3 sha3;
  14010. byte msg[] = "Everybody's working for the weekend.";
  14011. byte msg2[] = "Everybody gets Friday off.";
  14012. byte msgCmp[] = "\x45\x76\x65\x72\x79\x62\x6f\x64\x79\x27\x73\x20"
  14013. "\x77\x6f\x72\x6b\x69\x6e\x67\x20\x66\x6f\x72\x20\x74"
  14014. "\x68\x65\x20\x77\x65\x65\x6b\x65\x6e\x64\x2e\x45\x76"
  14015. "\x65\x72\x79\x62\x6f\x64\x79\x20\x67\x65\x74\x73\x20"
  14016. "\x46\x72\x69\x64\x61\x79\x20\x6f\x66\x66\x2e";
  14017. word32 msglen = sizeof(msg) - 1;
  14018. word32 msg2len = sizeof(msg2);
  14019. word32 msgCmplen = sizeof(msgCmp);
  14020. #if !defined(WOLFSSL_NOSHA3_224)
  14021. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14022. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg, msglen), 0);
  14023. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  14024. ExpectTrue(sha3.i == msglen);
  14025. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg2, msg2len), 0);
  14026. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  14027. /* Pass bad args. */
  14028. ExpectIntEQ(wc_Sha3_224_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14029. ExpectIntEQ(wc_Sha3_224_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14030. wc_Sha3_224_Free(&sha3);
  14031. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14032. ExpectIntEQ(wc_Sha3_224_Update(&sha3, NULL, 0), 0);
  14033. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg2, msg2len), 0);
  14034. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  14035. wc_Sha3_224_Free(&sha3);
  14036. #endif /* SHA3_224 */
  14037. #if !defined(WOLFSSL_NOSHA3_256)
  14038. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14039. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg, msglen), 0);
  14040. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  14041. ExpectTrue(sha3.i == msglen);
  14042. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg2, msg2len), 0);
  14043. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  14044. /* Pass bad args. */
  14045. ExpectIntEQ(wc_Sha3_256_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14046. ExpectIntEQ(wc_Sha3_256_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14047. wc_Sha3_256_Free(&sha3);
  14048. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14049. ExpectIntEQ(wc_Sha3_256_Update(&sha3, NULL, 0), 0);
  14050. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg2, msg2len), 0);
  14051. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  14052. wc_Sha3_256_Free(&sha3);
  14053. #endif /* SHA3_256 */
  14054. #if !defined(WOLFSSL_NOSHA3_384)
  14055. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14056. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg, msglen), 0);
  14057. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  14058. ExpectTrue(sha3.i == msglen);
  14059. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg2, msg2len), 0);
  14060. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  14061. /* Pass bad args. */
  14062. ExpectIntEQ(wc_Sha3_384_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14063. ExpectIntEQ(wc_Sha3_384_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14064. wc_Sha3_384_Free(&sha3);
  14065. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14066. ExpectIntEQ(wc_Sha3_384_Update(&sha3, NULL, 0), 0);
  14067. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg2, msg2len), 0);
  14068. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  14069. wc_Sha3_384_Free(&sha3);
  14070. #endif /* SHA3_384 */
  14071. #if !defined(WOLFSSL_NOSHA3_512)
  14072. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14073. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg, msglen), 0);
  14074. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  14075. ExpectTrue(sha3.i == msglen);
  14076. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg2, msg2len), 0);
  14077. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  14078. /* Pass bad args. */
  14079. ExpectIntEQ(wc_Sha3_512_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14080. ExpectIntEQ(wc_Sha3_512_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14081. wc_Sha3_512_Free(&sha3);
  14082. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14083. ExpectIntEQ(wc_Sha3_512_Update(&sha3, NULL, 0), 0);
  14084. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg2, msg2len), 0);
  14085. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  14086. wc_Sha3_512_Free(&sha3);
  14087. #endif /* SHA3_512 */
  14088. #endif /* WOLFSSL_SHA3 */
  14089. return EXPECT_RESULT();
  14090. } /* END testing_wc_Sha3_Update */
  14091. /*
  14092. * Testing wc_Sha3_224_Final()
  14093. */
  14094. static int test_wc_Sha3_224_Final(void)
  14095. {
  14096. EXPECT_DECLS;
  14097. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
  14098. wc_Sha3 sha3;
  14099. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14100. "nopnopq";
  14101. const char* expOut = "\x8a\x24\x10\x8b\x15\x4a\xda\x21\xc9\xfd\x55"
  14102. "\x74\x49\x44\x79\xba\x5c\x7e\x7a\xb7\x6e\xf2"
  14103. "\x64\xea\xd0\xfc\xce\x33";
  14104. byte hash[WC_SHA3_224_DIGEST_SIZE];
  14105. byte hashRet[WC_SHA3_224_DIGEST_SIZE];
  14106. /* Init stack variables. */
  14107. XMEMSET(hash, 0, sizeof(hash));
  14108. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14109. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14110. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  14111. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_224_DIGEST_SIZE), 0);
  14112. /* Test bad args. */
  14113. ExpectIntEQ(wc_Sha3_224_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14114. ExpectIntEQ(wc_Sha3_224_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14115. wc_Sha3_224_Free(&sha3);
  14116. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14117. /* Init stack variables. */
  14118. XMEMSET(hash, 0, sizeof(hash));
  14119. XMEMSET(hashRet, 0, sizeof(hashRet));
  14120. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14121. ExpectIntEQ(wc_Sha3_224_GetHash(&sha3, hashRet), 0);
  14122. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  14123. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_224_DIGEST_SIZE), 0);
  14124. /* Test bad args. */
  14125. ExpectIntEQ(wc_Sha3_224_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14126. ExpectIntEQ(wc_Sha3_224_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14127. wc_Sha3_224_Free(&sha3);
  14128. #endif
  14129. return EXPECT_RESULT();
  14130. } /* END test_wc_Sha3_224_Final */
  14131. /*
  14132. * Testing wc_Sha3_256_Final()
  14133. */
  14134. static int test_wc_Sha3_256_Final(void)
  14135. {
  14136. EXPECT_DECLS;
  14137. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  14138. wc_Sha3 sha3;
  14139. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14140. "nopnopq";
  14141. const char* expOut = "\x41\xc0\xdb\xa2\xa9\xd6\x24\x08\x49\x10\x03\x76\xa8"
  14142. "\x23\x5e\x2c\x82\xe1\xb9\x99\x8a\x99\x9e\x21\xdb\x32"
  14143. "\xdd\x97\x49\x6d\x33\x76";
  14144. byte hash[WC_SHA3_256_DIGEST_SIZE];
  14145. byte hashRet[WC_SHA3_256_DIGEST_SIZE];
  14146. /* Init stack variables. */
  14147. XMEMSET(hash, 0, sizeof(hash));
  14148. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14149. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14150. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  14151. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_256_DIGEST_SIZE), 0);
  14152. /* Test bad args. */
  14153. ExpectIntEQ(wc_Sha3_256_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14154. ExpectIntEQ(wc_Sha3_256_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14155. wc_Sha3_256_Free(&sha3);
  14156. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14157. /* Init stack variables. */
  14158. XMEMSET(hash, 0, sizeof(hash));
  14159. XMEMSET(hashRet, 0, sizeof(hashRet));
  14160. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14161. ExpectIntEQ(wc_Sha3_256_GetHash(&sha3, hashRet), 0);
  14162. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  14163. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_256_DIGEST_SIZE), 0);
  14164. /* Test bad args. */
  14165. ExpectIntEQ(wc_Sha3_256_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14166. ExpectIntEQ(wc_Sha3_256_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14167. wc_Sha3_256_Free(&sha3);
  14168. #endif
  14169. return EXPECT_RESULT();
  14170. } /* END test_wc_Sha3_256_Final */
  14171. /*
  14172. * Testing wc_Sha3_384_Final()
  14173. */
  14174. static int test_wc_Sha3_384_Final(void)
  14175. {
  14176. EXPECT_DECLS;
  14177. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384)
  14178. wc_Sha3 sha3;
  14179. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14180. "nopnopq";
  14181. const char* expOut = "\x99\x1c\x66\x57\x55\xeb\x3a\x4b\x6b\xbd\xfb\x75\xc7"
  14182. "\x8a\x49\x2e\x8c\x56\xa2\x2c\x5c\x4d\x7e\x42\x9b\xfd"
  14183. "\xbc\x32\xb9\xd4\xad\x5a\xa0\x4a\x1f\x07\x6e\x62\xfe"
  14184. "\xa1\x9e\xef\x51\xac\xd0\x65\x7c\x22";
  14185. byte hash[WC_SHA3_384_DIGEST_SIZE];
  14186. byte hashRet[WC_SHA3_384_DIGEST_SIZE];
  14187. /* Init stack variables. */
  14188. XMEMSET(hash, 0, sizeof(hash));
  14189. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14190. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14191. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  14192. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_384_DIGEST_SIZE), 0);
  14193. /* Test bad args. */
  14194. ExpectIntEQ(wc_Sha3_384_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14195. ExpectIntEQ(wc_Sha3_384_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14196. wc_Sha3_384_Free(&sha3);
  14197. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14198. /* Init stack variables. */
  14199. XMEMSET(hash, 0, sizeof(hash));
  14200. XMEMSET(hashRet, 0, sizeof(hashRet));
  14201. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14202. ExpectIntEQ(wc_Sha3_384_GetHash(&sha3, hashRet), 0);
  14203. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  14204. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_384_DIGEST_SIZE), 0);
  14205. /* Test bad args. */
  14206. ExpectIntEQ(wc_Sha3_384_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14207. ExpectIntEQ(wc_Sha3_384_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14208. wc_Sha3_384_Free(&sha3);
  14209. #endif
  14210. return EXPECT_RESULT();
  14211. } /* END test_wc_Sha3_384_Final */
  14212. /*
  14213. * Testing wc_Sha3_512_Final()
  14214. */
  14215. static int test_wc_Sha3_512_Final(void)
  14216. {
  14217. EXPECT_DECLS;
  14218. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512) && \
  14219. !defined(WOLFSSL_NOSHA3_384)
  14220. wc_Sha3 sha3;
  14221. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14222. "nopnopq";
  14223. const char* expOut = "\x04\xa3\x71\xe8\x4e\xcf\xb5\xb8\xb7\x7c\xb4\x86\x10"
  14224. "\xfc\xa8\x18\x2d\xd4\x57\xce\x6f\x32\x6a\x0f\xd3\xd7"
  14225. "\xec\x2f\x1e\x91\x63\x6d\xee\x69\x1f\xbe\x0c\x98\x53"
  14226. "\x02\xba\x1b\x0d\x8d\xc7\x8c\x08\x63\x46\xb5\x33\xb4"
  14227. "\x9c\x03\x0d\x99\xa2\x7d\xaf\x11\x39\xd6\xe7\x5e";
  14228. byte hash[WC_SHA3_512_DIGEST_SIZE];
  14229. byte hashRet[WC_SHA3_512_DIGEST_SIZE];
  14230. /* Init stack variables. */
  14231. XMEMSET(hash, 0, sizeof(hash));
  14232. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14233. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14234. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  14235. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_512_DIGEST_SIZE), 0);
  14236. /* Test bad args. */
  14237. ExpectIntEQ(wc_Sha3_512_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14238. ExpectIntEQ(wc_Sha3_512_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14239. wc_Sha3_512_Free(&sha3);
  14240. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14241. /* Init stack variables. */
  14242. XMEMSET(hash, 0, sizeof(hash));
  14243. XMEMSET(hashRet, 0, sizeof(hashRet));
  14244. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14245. ExpectIntEQ(wc_Sha3_512_GetHash(&sha3, hashRet), 0);
  14246. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  14247. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_512_DIGEST_SIZE), 0);
  14248. /* Test bad args. */
  14249. ExpectIntEQ(wc_Sha3_512_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14250. ExpectIntEQ(wc_Sha3_512_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14251. wc_Sha3_512_Free(&sha3);
  14252. #endif
  14253. return EXPECT_RESULT();
  14254. } /* END test_wc_Sha3_512_Final */
  14255. /*
  14256. * Testing wc_Sha3_224_Copy()
  14257. */
  14258. static int test_wc_Sha3_224_Copy(void)
  14259. {
  14260. EXPECT_DECLS;
  14261. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
  14262. wc_Sha3 sha3, sha3Cpy;
  14263. const char* msg = TEST_STRING;
  14264. word32 msglen = (word32)TEST_STRING_SZ;
  14265. byte hash[WC_SHA3_224_DIGEST_SIZE];
  14266. byte hashCpy[WC_SHA3_224_DIGEST_SIZE];
  14267. XMEMSET(hash, 0, sizeof(hash));
  14268. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14269. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14270. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14271. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14272. ExpectIntEQ(wc_InitSha3_224(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14273. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, msglen), 0);
  14274. ExpectIntEQ(wc_Sha3_224_Copy(&sha3Cpy, &sha3), 0);
  14275. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  14276. ExpectIntEQ(wc_Sha3_224_Final(&sha3Cpy, hashCpy), 0);
  14277. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14278. /* Test bad args. */
  14279. ExpectIntEQ(wc_Sha3_224_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14280. ExpectIntEQ(wc_Sha3_224_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14281. wc_Sha3_224_Free(&sha3);
  14282. wc_Sha3_224_Free(&sha3Cpy);
  14283. #endif
  14284. return EXPECT_RESULT();
  14285. } /* END test_wc_Sha3_224_Copy */
  14286. /*
  14287. * Testing wc_Sha3_256_Copy()
  14288. */
  14289. static int test_wc_Sha3_256_Copy(void)
  14290. {
  14291. EXPECT_DECLS;
  14292. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  14293. wc_Sha3 sha3, sha3Cpy;
  14294. const char* msg = TEST_STRING;
  14295. word32 msglen = (word32)TEST_STRING_SZ;
  14296. byte hash[WC_SHA3_256_DIGEST_SIZE];
  14297. byte hashCpy[WC_SHA3_256_DIGEST_SIZE];
  14298. XMEMSET(hash, 0, sizeof(hash));
  14299. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14300. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14301. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14302. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14303. ExpectIntEQ(wc_InitSha3_256(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14304. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, msglen), 0);
  14305. ExpectIntEQ(wc_Sha3_256_Copy(&sha3Cpy, &sha3), 0);
  14306. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  14307. ExpectIntEQ(wc_Sha3_256_Final(&sha3Cpy, hashCpy), 0);
  14308. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14309. /* Test bad args. */
  14310. ExpectIntEQ(wc_Sha3_256_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14311. ExpectIntEQ(wc_Sha3_256_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14312. wc_Sha3_256_Free(&sha3);
  14313. wc_Sha3_256_Free(&sha3Cpy);
  14314. #endif
  14315. return EXPECT_RESULT();
  14316. } /* END test_wc_Sha3_256_Copy */
  14317. /*
  14318. * Testing wc_Sha3_384_Copy()
  14319. */
  14320. static int test_wc_Sha3_384_Copy(void)
  14321. {
  14322. EXPECT_DECLS;
  14323. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384)
  14324. wc_Sha3 sha3, sha3Cpy;
  14325. const char* msg = TEST_STRING;
  14326. word32 msglen = (word32)TEST_STRING_SZ;
  14327. byte hash[WC_SHA3_384_DIGEST_SIZE];
  14328. byte hashCpy[WC_SHA3_384_DIGEST_SIZE];
  14329. XMEMSET(hash, 0, sizeof(hash));
  14330. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14331. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14332. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14333. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14334. ExpectIntEQ(wc_InitSha3_384(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14335. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, msglen), 0);
  14336. ExpectIntEQ(wc_Sha3_384_Copy(&sha3Cpy, &sha3), 0);
  14337. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  14338. ExpectIntEQ(wc_Sha3_384_Final(&sha3Cpy, hashCpy), 0);
  14339. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14340. /* Test bad args. */
  14341. ExpectIntEQ(wc_Sha3_384_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14342. ExpectIntEQ(wc_Sha3_384_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14343. wc_Sha3_384_Free(&sha3);
  14344. wc_Sha3_384_Free(&sha3Cpy);
  14345. #endif
  14346. return EXPECT_RESULT();
  14347. } /* END test_wc_Sha3_384_Copy */
  14348. /*
  14349. * Testing wc_Sha3_512_Copy()
  14350. */
  14351. static int test_wc_Sha3_512_Copy(void)
  14352. {
  14353. EXPECT_DECLS;
  14354. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512)
  14355. wc_Sha3 sha3, sha3Cpy;
  14356. const char* msg = TEST_STRING;
  14357. word32 msglen = (word32)TEST_STRING_SZ;
  14358. byte hash[WC_SHA3_512_DIGEST_SIZE];
  14359. byte hashCpy[WC_SHA3_512_DIGEST_SIZE];
  14360. XMEMSET(hash, 0, sizeof(hash));
  14361. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14362. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14363. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14364. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14365. ExpectIntEQ(wc_InitSha3_512(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14366. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, msglen), 0);
  14367. ExpectIntEQ(wc_Sha3_512_Copy(&sha3Cpy, &sha3), 0);
  14368. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  14369. ExpectIntEQ(wc_Sha3_512_Final(&sha3Cpy, hashCpy), 0);
  14370. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14371. /* Test bad args. */
  14372. ExpectIntEQ(wc_Sha3_512_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14373. ExpectIntEQ(wc_Sha3_512_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14374. wc_Sha3_512_Free(&sha3);
  14375. wc_Sha3_512_Free(&sha3Cpy);
  14376. #endif
  14377. return EXPECT_RESULT();
  14378. } /* END test_wc_Sha3_512_Copy */
  14379. /*
  14380. * Unit test function for wc_Sha3_GetFlags()
  14381. */
  14382. static int test_wc_Sha3_GetFlags(void)
  14383. {
  14384. EXPECT_DECLS;
  14385. #if defined(WOLFSSL_SHA3) && defined(WOLFSSL_HASH_FLAGS)
  14386. wc_Sha3 sha3;
  14387. word32 flags = 0;
  14388. /* Initialize */
  14389. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14390. ExpectIntEQ(wc_Sha3_GetFlags(&sha3, &flags), 0);
  14391. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  14392. wc_Sha3_224_Free(&sha3);
  14393. #endif
  14394. return EXPECT_RESULT();
  14395. } /* END test_wc_Sha3_GetFlags */
  14396. static int test_wc_InitShake256(void)
  14397. {
  14398. EXPECT_DECLS;
  14399. #ifdef WOLFSSL_SHAKE256
  14400. wc_Shake shake;
  14401. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14402. /* Test bad args. */
  14403. ExpectIntEQ(wc_InitShake256(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14404. wc_Shake256_Free(&shake);
  14405. #endif
  14406. return EXPECT_RESULT();
  14407. }
  14408. static int testing_wc_Shake256_Update(void)
  14409. {
  14410. EXPECT_DECLS;
  14411. #ifdef WOLFSSL_SHAKE256
  14412. wc_Shake shake;
  14413. byte msg[] = "Everybody's working for the weekend.";
  14414. byte msg2[] = "Everybody gets Friday off.";
  14415. byte msgCmp[] = "\x45\x76\x65\x72\x79\x62\x6f\x64\x79\x27\x73\x20"
  14416. "\x77\x6f\x72\x6b\x69\x6e\x67\x20\x66\x6f\x72\x20\x74"
  14417. "\x68\x65\x20\x77\x65\x65\x6b\x65\x6e\x64\x2e\x45\x76"
  14418. "\x65\x72\x79\x62\x6f\x64\x79\x20\x67\x65\x74\x73\x20"
  14419. "\x46\x72\x69\x64\x61\x79\x20\x6f\x66\x66\x2e";
  14420. word32 msglen = sizeof(msg) - 1;
  14421. word32 msg2len = sizeof(msg2);
  14422. word32 msgCmplen = sizeof(msgCmp);
  14423. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14424. ExpectIntEQ(wc_Shake256_Update(&shake, msg, msglen), 0);
  14425. ExpectIntEQ(XMEMCMP(msg, shake.t, msglen), 0);
  14426. ExpectTrue(shake.i == msglen);
  14427. ExpectIntEQ(wc_Shake256_Update(&shake, msg2, msg2len), 0);
  14428. ExpectIntEQ(XMEMCMP(shake.t, msgCmp, msgCmplen), 0);
  14429. /* Pass bad args. */
  14430. ExpectIntEQ(wc_Shake256_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14431. ExpectIntEQ(wc_Shake256_Update(&shake, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14432. wc_Shake256_Free(&shake);
  14433. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14434. ExpectIntEQ(wc_Shake256_Update(&shake, NULL, 0), 0);
  14435. ExpectIntEQ(wc_Shake256_Update(&shake, msg2, msg2len), 0);
  14436. ExpectIntEQ(XMEMCMP(msg2, shake.t, msg2len), 0);
  14437. wc_Shake256_Free(&shake);
  14438. #endif /* WOLFSSL_SHAKE256 */
  14439. return EXPECT_RESULT();
  14440. }
  14441. static int test_wc_Shake256_Final(void)
  14442. {
  14443. EXPECT_DECLS;
  14444. #ifdef WOLFSSL_SHAKE256
  14445. wc_Shake shake;
  14446. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14447. "nopnopq";
  14448. const char* expOut = "\x4d\x8c\x2d\xd2\x43\x5a\x01\x28\xee\xfb\xb8\xc3\x6f"
  14449. "\x6f\x87\x13\x3a\x79\x11\xe1\x8d\x97\x9e\xe1\xae\x6b"
  14450. "\xe5\xd4\xfd\x2e\x33\x29\x40\xd8\x68\x8a\x4e\x6a\x59"
  14451. "\xaa\x80\x60\xf1\xf9\xbc\x99\x6c\x05\xac\xa3\xc6\x96"
  14452. "\xa8\xb6\x62\x79\xdc\x67\x2c\x74\x0b\xb2\x24\xec\x37"
  14453. "\xa9\x2b\x65\xdb\x05\x39\xc0\x20\x34\x55\xf5\x1d\x97"
  14454. "\xcc\xe4\xcf\xc4\x91\x27\xd7\x26\x0a\xfc\x67\x3a\xf2"
  14455. "\x08\xba\xf1\x9b\xe2\x12\x33\xf3\xde\xbe\x78\xd0\x67"
  14456. "\x60\xcf\xa5\x51\xee\x1e\x07\x91\x41\xd4";
  14457. byte hash[114];
  14458. /* Init stack variables. */
  14459. XMEMSET(hash, 0, sizeof(hash));
  14460. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14461. ExpectIntEQ(wc_Shake256_Update(&shake, (byte*)msg, (word32)XSTRLEN(msg)),
  14462. 0);
  14463. ExpectIntEQ(wc_Shake256_Final(&shake, hash, (word32)sizeof(hash)), 0);
  14464. ExpectIntEQ(XMEMCMP(expOut, hash, (word32)sizeof(hash)), 0);
  14465. /* Test bad args. */
  14466. ExpectIntEQ(wc_Shake256_Final(NULL, hash, (word32)sizeof(hash)),
  14467. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14468. ExpectIntEQ(wc_Shake256_Final(&shake, NULL, (word32)sizeof(hash)),
  14469. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14470. wc_Shake256_Free(&shake);
  14471. #endif
  14472. return EXPECT_RESULT();
  14473. }
  14474. /*
  14475. * Testing wc_Shake256_Copy()
  14476. */
  14477. static int test_wc_Shake256_Copy(void)
  14478. {
  14479. EXPECT_DECLS;
  14480. #ifdef WOLFSSL_SHAKE256
  14481. wc_Shake shake, shakeCpy;
  14482. const char* msg = TEST_STRING;
  14483. word32 msglen = (word32)TEST_STRING_SZ;
  14484. byte hash[144];
  14485. byte hashCpy[144];
  14486. word32 hashLen = sizeof(hash);
  14487. word32 hashLenCpy = sizeof(hashCpy);
  14488. XMEMSET(hash, 0, sizeof(hash));
  14489. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14490. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14491. ExpectIntEQ(wc_InitShake256(&shakeCpy, HEAP_HINT, testDevId), 0);
  14492. ExpectIntEQ(wc_Shake256_Update(&shake, (byte*)msg, msglen), 0);
  14493. ExpectIntEQ(wc_Shake256_Copy(&shakeCpy, &shake), 0);
  14494. ExpectIntEQ(wc_Shake256_Final(&shake, hash, hashLen), 0);
  14495. ExpectIntEQ(wc_Shake256_Final(&shakeCpy, hashCpy, hashLenCpy), 0);
  14496. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14497. /* Test bad args. */
  14498. ExpectIntEQ(wc_Shake256_Copy(NULL, &shake), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14499. ExpectIntEQ(wc_Shake256_Copy(&shakeCpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14500. wc_Shake256_Free(&shake);
  14501. wc_Shake256_Free(&shakeCpy);
  14502. #endif
  14503. return EXPECT_RESULT();
  14504. } /* END test_wc_Shake256_Copy */
  14505. /*
  14506. * Unit test function for wc_Shake256Hash()
  14507. */
  14508. static int test_wc_Shake256Hash(void)
  14509. {
  14510. EXPECT_DECLS;
  14511. #ifdef WOLFSSL_SHAKE256
  14512. const byte data[] = { /* Hello World */
  14513. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  14514. 0x72,0x6c,0x64
  14515. };
  14516. word32 len = sizeof(data);
  14517. byte hash[144];
  14518. word32 hashLen = sizeof(hash);
  14519. ExpectIntEQ(wc_Shake256Hash(data, len, hash, hashLen), 0);
  14520. #endif
  14521. return EXPECT_RESULT();
  14522. } /* END test_wc_Shake256Hash */
  14523. /*
  14524. * Testing wc_InitSm3(), wc_Sm3Free()
  14525. */
  14526. static int test_wc_InitSm3Free(void)
  14527. {
  14528. EXPECT_DECLS;
  14529. #ifdef WOLFSSL_SM3
  14530. wc_Sm3 sm3;
  14531. /* Invalid Parameters */
  14532. ExpectIntEQ(wc_InitSm3(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14533. /* Valid Parameters */
  14534. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14535. wc_Sm3Free(NULL);
  14536. wc_Sm3Free(&sm3);
  14537. #endif
  14538. return EXPECT_RESULT();
  14539. } /* END test_wc_InitSm3 */
  14540. /*
  14541. * Testing wc_Sm3Update(), wc_Sm3Final()
  14542. */
  14543. static int test_wc_Sm3UpdateFinal(void)
  14544. {
  14545. EXPECT_DECLS;
  14546. #ifdef WOLFSSL_SM3
  14547. wc_Sm3 sm3;
  14548. byte data[WC_SM3_BLOCK_SIZE * 4];
  14549. byte hash[WC_SM3_DIGEST_SIZE];
  14550. byte calcHash[WC_SM3_DIGEST_SIZE];
  14551. byte expHash[WC_SM3_DIGEST_SIZE] = {
  14552. 0x38, 0x48, 0x15, 0xa7, 0x0e, 0xae, 0x0b, 0x27,
  14553. 0x5c, 0xde, 0x9d, 0xa5, 0xd1, 0xa4, 0x30, 0xa1,
  14554. 0xca, 0xd4, 0x54, 0x58, 0x44, 0xa2, 0x96, 0x1b,
  14555. 0xd7, 0x14, 0x80, 0x3f, 0x80, 0x1a, 0x07, 0xb6
  14556. };
  14557. word32 chunk;
  14558. word32 i;
  14559. XMEMSET(data, 0, sizeof(data));
  14560. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14561. /* Invalid Parameters */
  14562. ExpectIntEQ(wc_Sm3Update(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14563. ExpectIntEQ(wc_Sm3Update(&sm3, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14564. ExpectIntEQ(wc_Sm3Update(NULL, data, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14565. /* Valid Parameters */
  14566. ExpectIntEQ(wc_Sm3Update(&sm3, NULL, 0), 0);
  14567. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14568. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14569. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE), 0);
  14570. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE - 2), 0);
  14571. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE * 2), 0);
  14572. /* Ensure too many bytes for lengths. */
  14573. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_PAD_SIZE), 0);
  14574. /* Invalid Parameters */
  14575. ExpectIntEQ(wc_Sm3Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14576. ExpectIntEQ(wc_Sm3Final(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14577. ExpectIntEQ(wc_Sm3Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14578. /* Valid Parameters */
  14579. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14580. ExpectBufEQ(hash, expHash, WC_SM3_DIGEST_SIZE);
  14581. /* Chunk tests. */
  14582. ExpectIntEQ(wc_Sm3Update(&sm3, data, sizeof(data)), 0);
  14583. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14584. for (chunk = 1; chunk <= WC_SM3_BLOCK_SIZE + 1; chunk++) {
  14585. for (i = 0; i + chunk <= (word32)sizeof(data); i += chunk) {
  14586. ExpectIntEQ(wc_Sm3Update(&sm3, data + i, chunk), 0);
  14587. }
  14588. if (i < (word32)sizeof(data)) {
  14589. ExpectIntEQ(wc_Sm3Update(&sm3, data + i, (word32)sizeof(data) - i),
  14590. 0);
  14591. }
  14592. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14593. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14594. }
  14595. /* Not testing when the low 32-bit length overflows. */
  14596. wc_Sm3Free(&sm3);
  14597. #endif
  14598. return EXPECT_RESULT();
  14599. } /* END test_wc_Sm3Update */
  14600. /*
  14601. * Testing wc_Sm3GetHash()
  14602. */
  14603. static int test_wc_Sm3GetHash(void)
  14604. {
  14605. EXPECT_DECLS;
  14606. #ifdef WOLFSSL_SM3
  14607. wc_Sm3 sm3;
  14608. byte hash[WC_SM3_DIGEST_SIZE];
  14609. byte calcHash[WC_SM3_DIGEST_SIZE];
  14610. byte data[WC_SM3_BLOCK_SIZE];
  14611. XMEMSET(data, 0, sizeof(data));
  14612. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14613. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14614. /* Invalid Parameters */
  14615. ExpectIntEQ(wc_Sm3GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14616. ExpectIntEQ(wc_Sm3GetHash(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14617. ExpectIntEQ(wc_Sm3GetHash(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14618. /* Valid Parameters */
  14619. ExpectIntEQ(wc_Sm3GetHash(&sm3, hash), 0);
  14620. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14621. /* With update. */
  14622. ExpectIntEQ(wc_Sm3Update(&sm3, data, sizeof(data)), 0);
  14623. ExpectIntEQ(wc_Sm3GetHash(&sm3, hash), 0);
  14624. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14625. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14626. wc_Sm3Free(&sm3);
  14627. #endif
  14628. return EXPECT_RESULT();
  14629. } /* END test_wc_Sm3Update */
  14630. /*
  14631. * Testing wc_Sm3Copy()
  14632. */
  14633. static int test_wc_Sm3Copy(void)
  14634. {
  14635. EXPECT_DECLS;
  14636. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14637. wc_Sm3 sm3;
  14638. wc_Sm3 sm3Copy;
  14639. byte hash[WC_SM3_DIGEST_SIZE];
  14640. byte hashCopy[WC_SM3_DIGEST_SIZE];
  14641. byte data[WC_SM3_BLOCK_SIZE + 1];
  14642. int i;
  14643. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14644. ExpectIntEQ(wc_InitSm3(&sm3Copy, NULL, INVALID_DEVID), 0);
  14645. /* Invalid Parameters */
  14646. ExpectIntEQ(wc_Sm3Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14647. ExpectIntEQ(wc_Sm3Copy(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14648. ExpectIntEQ(wc_Sm3Copy(NULL, &sm3Copy), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14649. /* Valid Parameters */
  14650. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14651. /* Ensure all parts of data updated during hashing are copied. */
  14652. for (i = 0; i < WC_SM3_BLOCK_SIZE + 1; i++) {
  14653. ExpectIntEQ(wc_Sm3Update(&sm3, data, i), 0);
  14654. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14655. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14656. ExpectIntEQ(wc_Sm3Update(&sm3Copy, data, 1), 0);
  14657. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14658. ExpectIntEQ(wc_Sm3Final(&sm3Copy, hashCopy), 0);
  14659. ExpectBufEQ(hash, hashCopy, WC_SM3_DIGEST_SIZE);
  14660. }
  14661. wc_Sm3Free(&sm3Copy);
  14662. wc_Sm3Free(&sm3);
  14663. #endif
  14664. return EXPECT_RESULT();
  14665. } /* END test_wc_Sm3Copy */
  14666. /*
  14667. * Testing wc_Sm3FinalRaw()
  14668. */
  14669. static int test_wc_Sm3FinalRaw(void)
  14670. {
  14671. EXPECT_DECLS;
  14672. #if defined(WOLFSSL_SM3) && !defined(HAVE_SELFTEST) && \
  14673. !defined(WOLFSSL_DEVCRYPTO) && (!defined(HAVE_FIPS) || \
  14674. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3))) && \
  14675. !defined(WOLFSSL_NO_HASH_RAW)
  14676. wc_Sm3 sm3;
  14677. byte hash1[WC_SM3_DIGEST_SIZE];
  14678. byte hash2[WC_SM3_DIGEST_SIZE];
  14679. byte hash3[WC_SM3_DIGEST_SIZE];
  14680. byte* hash_test[3] = { hash1, hash2, hash3 };
  14681. int times;
  14682. int i;
  14683. XMEMSET(&sm3, 0, sizeof(sm3));
  14684. /* Initialize */
  14685. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14686. /* Invalid Parameters */
  14687. ExpectIntEQ(wc_Sm3FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14688. ExpectIntEQ(wc_Sm3FinalRaw(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14689. ExpectIntEQ(wc_Sm3FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14690. times = sizeof(hash_test) / sizeof(byte*);
  14691. for (i = 0; i < times; i++) {
  14692. ExpectIntEQ(wc_Sm3FinalRaw(&sm3, hash_test[i]), 0);
  14693. }
  14694. wc_Sm3Free(&sm3);
  14695. #endif
  14696. return EXPECT_RESULT();
  14697. } /* END test_wc_Sm3FinalRaw */
  14698. /*
  14699. * Testing wc_Sm3GetFlags, wc_Sm3SetFlags()
  14700. */
  14701. static int test_wc_Sm3GetSetFlags(void)
  14702. {
  14703. EXPECT_DECLS;
  14704. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14705. wc_Sm3 sm3;
  14706. wc_Sm3 sm3Copy;
  14707. word32 flags = 0;
  14708. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14709. ExpectIntEQ(wc_InitSm3(&sm3Copy, NULL, INVALID_DEVID), 0);
  14710. ExpectIntEQ(wc_Sm3GetFlags(NULL, &flags), 0);
  14711. ExpectIntEQ(flags, 0);
  14712. ExpectIntEQ(wc_Sm3SetFlags(NULL, WC_HASH_FLAG_WILLCOPY), 0);
  14713. ExpectIntEQ(wc_Sm3GetFlags(NULL, &flags), 0);
  14714. ExpectIntEQ(flags, 0);
  14715. ExpectIntEQ(wc_Sm3GetFlags(&sm3, &flags), 0);
  14716. ExpectIntEQ(flags, 0);
  14717. ExpectIntEQ(wc_Sm3SetFlags(&sm3, WC_HASH_FLAG_WILLCOPY), 0);
  14718. ExpectIntEQ(wc_Sm3GetFlags(&sm3, &flags), 0);
  14719. ExpectIntEQ(flags, WC_HASH_FLAG_WILLCOPY);
  14720. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14721. ExpectIntEQ(wc_Sm3GetFlags(&sm3Copy, &flags), 0);
  14722. ExpectIntEQ(flags, WC_HASH_FLAG_ISCOPY | WC_HASH_FLAG_WILLCOPY);
  14723. wc_Sm3Free(&sm3Copy);
  14724. wc_Sm3Free(&sm3);
  14725. #endif
  14726. return EXPECT_RESULT();
  14727. } /* END test_wc_Sm3Update */
  14728. /*
  14729. * Testing wc_Sm3Hash()
  14730. */
  14731. static int test_wc_Sm3Hash(void)
  14732. {
  14733. EXPECT_DECLS;
  14734. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14735. byte data[WC_SM3_BLOCK_SIZE];
  14736. byte hash[WC_SM3_DIGEST_SIZE];
  14737. /* Invalid parameters. */
  14738. ExpectIntEQ(wc_Sm3Hash(NULL, sizeof(data), hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14739. ExpectIntEQ(wc_Sm3Hash(data, sizeof(data), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14740. /* Valid parameters. */
  14741. ExpectIntEQ(wc_Sm3Hash(data, sizeof(data), hash), 0);
  14742. #endif
  14743. return EXPECT_RESULT();
  14744. } /* END test_wc_Sm3Hash */
  14745. /*
  14746. * Test function for wc_HmacSetKey
  14747. */
  14748. static int test_wc_Md5HmacSetKey(void)
  14749. {
  14750. EXPECT_DECLS;
  14751. #if !defined(NO_HMAC) && !defined(NO_MD5)
  14752. Hmac hmac;
  14753. int ret, times, itr;
  14754. const char* keys[]=
  14755. {
  14756. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
  14757. #ifndef HAVE_FIPS
  14758. "Jefe", /* smaller than minimum FIPS key size */
  14759. #endif
  14760. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14761. };
  14762. times = sizeof(keys) / sizeof(char*);
  14763. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14764. for (itr = 0; itr < times; itr++) {
  14765. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[itr],
  14766. (word32)XSTRLEN(keys[itr]));
  14767. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5)
  14768. wc_HmacFree(&hmac);
  14769. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14770. #else
  14771. ExpectIntEQ(ret, 0);
  14772. #endif
  14773. }
  14774. /* Bad args. */
  14775. ExpectIntEQ(wc_HmacSetKey(NULL, WC_MD5, (byte*)keys[0],
  14776. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14777. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, NULL, (word32)XSTRLEN(keys[0])),
  14778. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14779. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14780. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14781. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[0], 0);
  14782. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5)
  14783. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14784. #elif defined(HAVE_FIPS)
  14785. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14786. #else
  14787. ExpectIntEQ(ret, 0);
  14788. #endif
  14789. wc_HmacFree(&hmac);
  14790. #endif
  14791. return EXPECT_RESULT();
  14792. } /* END test_wc_Md5HmacSetKey */
  14793. /*
  14794. * testing wc_HmacSetKey() on wc_Sha hash.
  14795. */
  14796. static int test_wc_ShaHmacSetKey(void)
  14797. {
  14798. EXPECT_DECLS;
  14799. #if !defined(NO_HMAC) && !defined(NO_SHA)
  14800. Hmac hmac;
  14801. int ret, times, itr;
  14802. const char* keys[]=
  14803. {
  14804. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14805. "\x0b\x0b\x0b",
  14806. #ifndef HAVE_FIPS
  14807. "Jefe", /* smaller than minimum FIPS key size */
  14808. #endif
  14809. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14810. "\xAA\xAA\xAA"
  14811. };
  14812. times = sizeof(keys) / sizeof(char*);
  14813. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14814. for (itr = 0; itr < times; itr++) {
  14815. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[itr],
  14816. (word32)XSTRLEN(keys[itr])), 0);
  14817. }
  14818. /* Bad args. */
  14819. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA, (byte*)keys[0],
  14820. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14821. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, NULL, (word32)XSTRLEN(keys[0])),
  14822. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14823. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14824. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14825. ret = wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[0], 0);
  14826. #ifdef HAVE_FIPS
  14827. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14828. #else
  14829. ExpectIntEQ(ret, 0);
  14830. #endif
  14831. wc_HmacFree(&hmac);
  14832. #endif
  14833. return EXPECT_RESULT();
  14834. } /* END test_wc_ShaHmacSetKey() */
  14835. /*
  14836. * testing wc_HmacSetKey() on Sha224 hash.
  14837. */
  14838. static int test_wc_Sha224HmacSetKey(void)
  14839. {
  14840. EXPECT_DECLS;
  14841. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  14842. Hmac hmac;
  14843. int ret, times, itr;
  14844. const char* keys[]=
  14845. {
  14846. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14847. "\x0b\x0b\x0b",
  14848. #ifndef HAVE_FIPS
  14849. "Jefe", /* smaller than minimum FIPS key size */
  14850. #endif
  14851. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14852. "\xAA\xAA\xAA"
  14853. };
  14854. times = sizeof(keys) / sizeof(char*);
  14855. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14856. for (itr = 0; itr < times; itr++) {
  14857. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[itr],
  14858. (word32)XSTRLEN(keys[itr])), 0);
  14859. }
  14860. /* Bad args. */
  14861. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA224, (byte*)keys[0],
  14862. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14863. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, NULL, (word32)XSTRLEN(keys[0])),
  14864. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14865. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14866. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14867. ret = wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[0], 0);
  14868. #ifdef HAVE_FIPS
  14869. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14870. #else
  14871. ExpectIntEQ(ret, 0);
  14872. #endif
  14873. wc_HmacFree(&hmac);
  14874. #endif
  14875. return EXPECT_RESULT();
  14876. } /* END test_wc_Sha224HmacSetKey() */
  14877. /*
  14878. * testing wc_HmacSetKey() on Sha256 hash
  14879. */
  14880. static int test_wc_Sha256HmacSetKey(void)
  14881. {
  14882. EXPECT_DECLS;
  14883. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  14884. Hmac hmac;
  14885. int ret, times, itr;
  14886. const char* keys[]=
  14887. {
  14888. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14889. "\x0b\x0b\x0b",
  14890. #ifndef HAVE_FIPS
  14891. "Jefe", /* smaller than minimum FIPS key size */
  14892. #endif
  14893. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14894. "\xAA\xAA\xAA"
  14895. };
  14896. times = sizeof(keys) / sizeof(char*);
  14897. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14898. for (itr = 0; itr < times; itr++) {
  14899. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[itr],
  14900. (word32)XSTRLEN(keys[itr])), 0);
  14901. }
  14902. /* Bad args. */
  14903. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA256, (byte*)keys[0],
  14904. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14905. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, NULL, (word32)XSTRLEN(keys[0])),
  14906. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14907. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14908. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14909. ret = wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[0], 0);
  14910. #ifdef HAVE_FIPS
  14911. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14912. #else
  14913. ExpectIntEQ(ret, 0);
  14914. #endif
  14915. wc_HmacFree(&hmac);
  14916. #endif
  14917. return EXPECT_RESULT();
  14918. } /* END test_wc_Sha256HmacSetKey() */
  14919. /*
  14920. * testing wc_HmacSetKey on Sha384 hash.
  14921. */
  14922. static int test_wc_Sha384HmacSetKey(void)
  14923. {
  14924. EXPECT_DECLS;
  14925. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  14926. Hmac hmac;
  14927. int ret, times, itr;
  14928. const char* keys[]=
  14929. {
  14930. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14931. "\x0b\x0b\x0b",
  14932. #ifndef HAVE_FIPS
  14933. "Jefe", /* smaller than minimum FIPS key size */
  14934. #endif
  14935. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14936. "\xAA\xAA\xAA"
  14937. };
  14938. times = sizeof(keys) / sizeof(char*);
  14939. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14940. for (itr = 0; itr < times; itr++) {
  14941. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[itr],
  14942. (word32)XSTRLEN(keys[itr])), 0);
  14943. }
  14944. /* Bad args. */
  14945. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA384, (byte*)keys[0],
  14946. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14947. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, NULL, (word32)XSTRLEN(keys[0])),
  14948. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14949. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14950. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14951. ret = wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[0], 0);
  14952. #ifdef HAVE_FIPS
  14953. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14954. #else
  14955. ExpectIntEQ(ret, 0);
  14956. #endif
  14957. wc_HmacFree(&hmac);
  14958. #endif
  14959. return EXPECT_RESULT();
  14960. } /* END test_wc_Sha384HmacSetKey() */
  14961. /*
  14962. * testing wc_HmacUpdate on wc_Md5 hash.
  14963. */
  14964. static int test_wc_Md5HmacUpdate(void)
  14965. {
  14966. EXPECT_DECLS;
  14967. #if !defined(NO_HMAC) && !defined(NO_MD5) && !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5))
  14968. Hmac hmac;
  14969. testVector a, b;
  14970. #ifdef HAVE_FIPS
  14971. const char* keys =
  14972. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  14973. #else
  14974. const char* keys = "Jefe";
  14975. #endif
  14976. a.input = "what do ya want for nothing?";
  14977. a.inLen = XSTRLEN(a.input);
  14978. b.input = "Hi There";
  14979. b.inLen = XSTRLEN(b.input);
  14980. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14981. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys,
  14982. (word32)XSTRLEN(keys)), 0);
  14983. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  14984. /* Update Hmac. */
  14985. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14986. /* Test bad args. */
  14987. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  14988. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14989. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14990. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  14991. wc_HmacFree(&hmac);
  14992. #endif
  14993. return EXPECT_RESULT();
  14994. } /* END test_wc_Md5HmacUpdate */
  14995. /*
  14996. * testing wc_HmacUpdate on SHA hash.
  14997. */
  14998. static int test_wc_ShaHmacUpdate(void)
  14999. {
  15000. EXPECT_DECLS;
  15001. #if !defined(NO_HMAC) && !defined(NO_SHA)
  15002. Hmac hmac;
  15003. testVector a, b;
  15004. #ifdef HAVE_FIPS
  15005. const char* keys =
  15006. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15007. #else
  15008. const char* keys = "Jefe";
  15009. #endif
  15010. a.input = "what do ya want for nothing?";
  15011. a.inLen = XSTRLEN(a.input);
  15012. b.input = "Hi There";
  15013. b.inLen = XSTRLEN(b.input);
  15014. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15015. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys,
  15016. (word32)XSTRLEN(keys)), 0);
  15017. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  15018. /* Update Hmac. */
  15019. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15020. /* Test bad args. */
  15021. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  15022. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15023. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15024. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  15025. wc_HmacFree(&hmac);
  15026. #endif
  15027. return EXPECT_RESULT();
  15028. } /* END test_wc_ShaHmacUpdate */
  15029. /*
  15030. * testing wc_HmacUpdate on SHA224 hash.
  15031. */
  15032. static int test_wc_Sha224HmacUpdate(void)
  15033. {
  15034. EXPECT_DECLS;
  15035. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  15036. Hmac hmac;
  15037. testVector a, b;
  15038. #ifdef HAVE_FIPS
  15039. const char* keys =
  15040. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15041. #else
  15042. const char* keys = "Jefe";
  15043. #endif
  15044. a.input = "what do ya want for nothing?";
  15045. a.inLen = XSTRLEN(a.input);
  15046. b.input = "Hi There";
  15047. b.inLen = XSTRLEN(b.input);
  15048. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15049. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys,
  15050. (word32)XSTRLEN(keys)), 0);
  15051. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  15052. /* Update Hmac. */
  15053. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15054. /* Test bad args. */
  15055. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  15056. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15057. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15058. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  15059. wc_HmacFree(&hmac);
  15060. #endif
  15061. return EXPECT_RESULT();
  15062. } /* END test_wc_Sha224HmacUpdate */
  15063. /*
  15064. * testing wc_HmacUpdate on SHA256 hash.
  15065. */
  15066. static int test_wc_Sha256HmacUpdate(void)
  15067. {
  15068. EXPECT_DECLS;
  15069. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  15070. Hmac hmac;
  15071. testVector a, b;
  15072. #ifdef HAVE_FIPS
  15073. const char* keys =
  15074. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15075. #else
  15076. const char* keys = "Jefe";
  15077. #endif
  15078. a.input = "what do ya want for nothing?";
  15079. a.inLen = XSTRLEN(a.input);
  15080. b.input = "Hi There";
  15081. b.inLen = XSTRLEN(b.input);
  15082. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15083. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys,
  15084. (word32)XSTRLEN(keys)), 0);
  15085. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  15086. /* Update Hmac. */
  15087. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15088. /* Test bad args. */
  15089. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  15090. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15091. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15092. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  15093. wc_HmacFree(&hmac);
  15094. #endif
  15095. return EXPECT_RESULT();
  15096. } /* END test_wc_Sha256HmacUpdate */
  15097. /*
  15098. * testing wc_HmacUpdate on SHA384 hash.
  15099. */
  15100. static int test_wc_Sha384HmacUpdate(void)
  15101. {
  15102. EXPECT_DECLS;
  15103. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  15104. Hmac hmac;
  15105. testVector a, b;
  15106. #ifdef HAVE_FIPS
  15107. const char* keys =
  15108. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15109. #else
  15110. const char* keys = "Jefe";
  15111. #endif
  15112. a.input = "what do ya want for nothing?";
  15113. a.inLen = XSTRLEN(a.input);
  15114. b.input = "Hi There";
  15115. b.inLen = XSTRLEN(b.input);
  15116. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15117. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys,
  15118. (word32)XSTRLEN(keys)), 0);
  15119. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  15120. /* Update Hmac. */
  15121. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15122. /* Test bad args. */
  15123. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  15124. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15125. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15126. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  15127. wc_HmacFree(&hmac);
  15128. #endif
  15129. return EXPECT_RESULT();
  15130. } /* END test_wc_Sha384HmacUpdate */
  15131. /*
  15132. * Testing wc_HmacFinal() with MD5
  15133. */
  15134. static int test_wc_Md5HmacFinal(void)
  15135. {
  15136. EXPECT_DECLS;
  15137. #if !defined(NO_HMAC) && !defined(NO_MD5) && !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5))
  15138. Hmac hmac;
  15139. byte hash[WC_MD5_DIGEST_SIZE];
  15140. testVector a;
  15141. const char* key;
  15142. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15143. a.input = "Hi There";
  15144. a.output = "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc"
  15145. "\x9d";
  15146. a.inLen = XSTRLEN(a.input);
  15147. a.outLen = XSTRLEN(a.output);
  15148. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15149. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, (byte*)key, (word32)XSTRLEN(key)),
  15150. 0);
  15151. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15152. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15153. ExpectIntEQ(XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE), 0);
  15154. /* Try bad parameters. */
  15155. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15156. #ifndef HAVE_FIPS
  15157. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15158. #endif
  15159. wc_HmacFree(&hmac);
  15160. #endif
  15161. return EXPECT_RESULT();
  15162. } /* END test_wc_Md5HmacFinal */
  15163. /*
  15164. * Testing wc_HmacFinal() with SHA
  15165. */
  15166. static int test_wc_ShaHmacFinal(void)
  15167. {
  15168. EXPECT_DECLS;
  15169. #if !defined(NO_HMAC) && !defined(NO_SHA)
  15170. Hmac hmac;
  15171. byte hash[WC_SHA_DIGEST_SIZE];
  15172. testVector a;
  15173. const char* key;
  15174. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15175. "\x0b\x0b\x0b";
  15176. a.input = "Hi There";
  15177. a.output = "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c"
  15178. "\x8e\xf1\x46\xbe\x00";
  15179. a.inLen = XSTRLEN(a.input);
  15180. a.outLen = XSTRLEN(a.output);
  15181. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15182. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)key, (word32)XSTRLEN(key)),
  15183. 0);
  15184. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15185. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15186. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA_DIGEST_SIZE), 0);
  15187. /* Try bad parameters. */
  15188. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15189. #ifndef HAVE_FIPS
  15190. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15191. #endif
  15192. wc_HmacFree(&hmac);
  15193. #endif
  15194. return EXPECT_RESULT();
  15195. } /* END test_wc_ShaHmacFinal */
  15196. /*
  15197. * Testing wc_HmacFinal() with SHA224
  15198. */
  15199. static int test_wc_Sha224HmacFinal(void)
  15200. {
  15201. EXPECT_DECLS;
  15202. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  15203. Hmac hmac;
  15204. byte hash[WC_SHA224_DIGEST_SIZE];
  15205. testVector a;
  15206. const char* key;
  15207. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15208. "\x0b\x0b\x0b";
  15209. a.input = "Hi There";
  15210. a.output = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3"
  15211. "\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22";
  15212. a.inLen = XSTRLEN(a.input);
  15213. a.outLen = XSTRLEN(a.output);
  15214. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15215. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)key,
  15216. (word32)XSTRLEN(key)), 0);
  15217. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15218. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15219. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA224_DIGEST_SIZE), 0);
  15220. /* Try bad parameters. */
  15221. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15222. #ifndef HAVE_FIPS
  15223. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15224. #endif
  15225. wc_HmacFree(&hmac);
  15226. #endif
  15227. return EXPECT_RESULT();
  15228. } /* END test_wc_Sha224HmacFinal */
  15229. /*
  15230. * Testing wc_HmacFinal() with SHA256
  15231. */
  15232. static int test_wc_Sha256HmacFinal(void)
  15233. {
  15234. EXPECT_DECLS;
  15235. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  15236. Hmac hmac;
  15237. byte hash[WC_SHA256_DIGEST_SIZE];
  15238. testVector a;
  15239. const char* key;
  15240. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15241. "\x0b\x0b\x0b";
  15242. a.input = "Hi There";
  15243. a.output = "\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1"
  15244. "\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32"
  15245. "\xcf\xf7";
  15246. a.inLen = XSTRLEN(a.input);
  15247. a.outLen = XSTRLEN(a.output);
  15248. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15249. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)key,
  15250. (word32)XSTRLEN(key)), 0);
  15251. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15252. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15253. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA256_DIGEST_SIZE), 0);
  15254. /* Try bad parameters. */
  15255. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15256. #ifndef HAVE_FIPS
  15257. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15258. #endif
  15259. wc_HmacFree(&hmac);
  15260. #endif
  15261. return EXPECT_RESULT();
  15262. } /* END test_wc_Sha256HmacFinal */
  15263. /*
  15264. * Testing wc_HmacFinal() with SHA384
  15265. */
  15266. static int test_wc_Sha384HmacFinal(void)
  15267. {
  15268. EXPECT_DECLS;
  15269. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  15270. Hmac hmac;
  15271. byte hash[WC_SHA384_DIGEST_SIZE];
  15272. testVector a;
  15273. const char* key;
  15274. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15275. "\x0b\x0b\x0b";
  15276. a.input = "Hi There";
  15277. a.output = "\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90"
  15278. "\x7f\x15\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb"
  15279. "\xc5\x9c\xfa\xea\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2"
  15280. "\xfa\x9c\xb6";
  15281. a.inLen = XSTRLEN(a.input);
  15282. a.outLen = XSTRLEN(a.output);
  15283. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15284. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)key,
  15285. (word32)XSTRLEN(key)), 0);
  15286. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15287. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15288. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA384_DIGEST_SIZE), 0);
  15289. /* Try bad parameters. */
  15290. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15291. #ifndef HAVE_FIPS
  15292. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15293. #endif
  15294. wc_HmacFree(&hmac);
  15295. #endif
  15296. return EXPECT_RESULT();
  15297. } /* END test_wc_Sha384HmacFinal */
  15298. /*
  15299. * Testing wc_InitCmac()
  15300. */
  15301. static int test_wc_InitCmac(void)
  15302. {
  15303. EXPECT_DECLS;
  15304. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  15305. Cmac cmac1;
  15306. Cmac cmac2;
  15307. Cmac cmac3;
  15308. /* AES 128 key. */
  15309. byte key1[] = "\x01\x02\x03\x04\x05\x06\x07\x08"
  15310. "\x09\x10\x11\x12\x13\x14\x15\x16";
  15311. /* AES 192 key. */
  15312. byte key2[] = "\x01\x02\x03\x04\x05\x06\x07\x08"
  15313. "\x09\x01\x11\x12\x13\x14\x15\x16"
  15314. "\x01\x02\x03\x04\x05\x06\x07\x08";
  15315. /* AES 256 key. */
  15316. byte key3[] = "\x01\x02\x03\x04\x05\x06\x07\x08"
  15317. "\x09\x01\x11\x12\x13\x14\x15\x16"
  15318. "\x01\x02\x03\x04\x05\x06\x07\x08"
  15319. "\x09\x01\x11\x12\x13\x14\x15\x16";
  15320. word32 key1Sz = (word32)sizeof(key1) - 1;
  15321. word32 key2Sz = (word32)sizeof(key2) - 1;
  15322. word32 key3Sz = (word32)sizeof(key3) - 1;
  15323. int type = WC_CMAC_AES;
  15324. (void)key1;
  15325. (void)key1Sz;
  15326. (void)key2;
  15327. (void)key2Sz;
  15328. XMEMSET(&cmac1, 0, sizeof(Cmac));
  15329. XMEMSET(&cmac2, 0, sizeof(Cmac));
  15330. XMEMSET(&cmac3, 0, sizeof(Cmac));
  15331. #ifdef WOLFSSL_AES_128
  15332. ExpectIntEQ(wc_InitCmac(&cmac1, key1, key1Sz, type, NULL), 0);
  15333. #endif
  15334. #ifdef WOLFSSL_AES_192
  15335. wc_AesFree(&cmac1.aes);
  15336. ExpectIntEQ(wc_InitCmac(&cmac2, key2, key2Sz, type, NULL), 0);
  15337. #endif
  15338. #ifdef WOLFSSL_AES_256
  15339. wc_AesFree(&cmac2.aes);
  15340. ExpectIntEQ(wc_InitCmac(&cmac3, key3, key3Sz, type, NULL), 0);
  15341. #endif
  15342. wc_AesFree(&cmac3.aes);
  15343. /* Test bad args. */
  15344. ExpectIntEQ(wc_InitCmac(NULL, key3, key3Sz, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15345. ExpectIntEQ(wc_InitCmac(&cmac3, NULL, key3Sz, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15346. ExpectIntEQ(wc_InitCmac(&cmac3, key3, 0, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15347. ExpectIntEQ(wc_InitCmac(&cmac3, key3, key3Sz, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15348. #endif
  15349. return EXPECT_RESULT();
  15350. } /* END test_wc_InitCmac */
  15351. /*
  15352. * Testing wc_CmacUpdate()
  15353. */
  15354. static int test_wc_CmacUpdate(void)
  15355. {
  15356. EXPECT_DECLS;
  15357. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  15358. Cmac cmac;
  15359. byte key[] = {
  15360. 0x64, 0x4c, 0xbf, 0x12, 0x85, 0x9d, 0xf0, 0x55,
  15361. 0x7e, 0xa9, 0x1f, 0x08, 0xe0, 0x51, 0xff, 0x27
  15362. };
  15363. byte in[] = "\xe2\xb4\xb6\xf9\x48\x44\x02\x64"
  15364. "\x5c\x47\x80\x9e\xd5\xa8\x3a\x17"
  15365. "\xb3\x78\xcf\x85\x22\x41\x74\xd9"
  15366. "\xa0\x97\x39\x71\x62\xf1\x8e\x8f"
  15367. "\xf4";
  15368. word32 inSz = (word32)sizeof(in) - 1;
  15369. word32 keySz = (word32)sizeof(key);
  15370. int type = WC_CMAC_AES;
  15371. XMEMSET(&cmac, 0, sizeof(Cmac));
  15372. ExpectIntEQ(wc_InitCmac(&cmac, key, keySz, type, NULL), 0);
  15373. ExpectIntEQ(wc_CmacUpdate(&cmac, in, inSz), 0);
  15374. /* Test bad args. */
  15375. ExpectIntEQ(wc_CmacUpdate(NULL, in, inSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15376. ExpectIntEQ(wc_CmacUpdate(&cmac, NULL, 30), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15377. wc_AesFree(&cmac.aes);
  15378. #endif
  15379. return EXPECT_RESULT();
  15380. } /* END test_wc_CmacUpdate */
  15381. /*
  15382. * Testing wc_CmacFinal()
  15383. */
  15384. static int test_wc_CmacFinal(void)
  15385. {
  15386. EXPECT_DECLS;
  15387. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  15388. Cmac cmac;
  15389. byte key[] = {
  15390. 0x64, 0x4c, 0xbf, 0x12, 0x85, 0x9d, 0xf0, 0x55,
  15391. 0x7e, 0xa9, 0x1f, 0x08, 0xe0, 0x51, 0xff, 0x27
  15392. };
  15393. byte msg[] = {
  15394. 0xe2, 0xb4, 0xb6, 0xf9, 0x48, 0x44, 0x02, 0x64,
  15395. 0x5c, 0x47, 0x80, 0x9e, 0xd5, 0xa8, 0x3a, 0x17,
  15396. 0xb3, 0x78, 0xcf, 0x85, 0x22, 0x41, 0x74, 0xd9,
  15397. 0xa0, 0x97, 0x39, 0x71, 0x62, 0xf1, 0x8e, 0x8f,
  15398. 0xf4
  15399. };
  15400. /* Test vectors from CMACGenAES128.rsp from
  15401. * http://csrc.nist.gov/groups/STM/cavp/block-cipher-modes.html#cmac
  15402. * Per RFC4493 truncation of lsb is possible.
  15403. */
  15404. byte expMac[] = {
  15405. 0x4e, 0x6e, 0xc5, 0x6f, 0xf9, 0x5d, 0x0e, 0xae,
  15406. 0x1c, 0xf8, 0x3e, 0xfc, 0xf4, 0x4b, 0xeb
  15407. };
  15408. byte mac[AES_BLOCK_SIZE];
  15409. word32 msgSz = (word32)sizeof(msg);
  15410. word32 keySz = (word32)sizeof(key);
  15411. word32 macSz = sizeof(mac);
  15412. word32 badMacSz = 17;
  15413. int expMacSz = sizeof(expMac);
  15414. int type = WC_CMAC_AES;
  15415. XMEMSET(&cmac, 0, sizeof(Cmac));
  15416. XMEMSET(mac, 0, macSz);
  15417. ExpectIntEQ(wc_InitCmac(&cmac, key, keySz, type, NULL), 0);
  15418. ExpectIntEQ(wc_CmacUpdate(&cmac, msg, msgSz), 0);
  15419. #if (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  15420. /* Pass in bad args. */
  15421. ExpectIntEQ(wc_CmacFinalNoFree(NULL, mac, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15422. ExpectIntEQ(wc_CmacFinalNoFree(&cmac, NULL, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15423. ExpectIntEQ(wc_CmacFinalNoFree(&cmac, mac, &badMacSz), WC_NO_ERR_TRACE(BUFFER_E));
  15424. /* For the last call, use the API with implicit wc_CmacFree(). */
  15425. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &macSz), 0);
  15426. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  15427. #else /* !HAVE_FIPS || FIPS>=5.3 */
  15428. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &macSz), 0);
  15429. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  15430. /* Pass in bad args. */
  15431. ExpectIntEQ(wc_CmacFinal(NULL, mac, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15432. ExpectIntEQ(wc_CmacFinal(&cmac, NULL, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15433. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &badMacSz), WC_NO_ERR_TRACE(BUFFER_E));
  15434. #endif /* !HAVE_FIPS || FIPS>=5.3 */
  15435. #endif
  15436. return EXPECT_RESULT();
  15437. } /* END test_wc_CmacFinal */
  15438. /*
  15439. * Testing wc_AesCmacGenerate() && wc_AesCmacVerify()
  15440. */
  15441. static int test_wc_AesCmacGenerate(void)
  15442. {
  15443. EXPECT_DECLS;
  15444. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  15445. byte key[] = {
  15446. 0x26, 0xef, 0x8b, 0x40, 0x34, 0x11, 0x7d, 0x9e,
  15447. 0xbe, 0xc0, 0xc7, 0xfc, 0x31, 0x08, 0x54, 0x69
  15448. };
  15449. byte msg[] = "\x18\x90\x49\xef\xfd\x7c\xf9\xc8"
  15450. "\xf3\x59\x65\xbc\xb0\x97\x8f\xd4";
  15451. byte expMac[] = "\x29\x5f\x2f\x71\xfc\x58\xe6\xf6"
  15452. "\x3d\x32\x65\x4c\x66\x23\xc5";
  15453. byte mac[AES_BLOCK_SIZE];
  15454. word32 keySz = sizeof(key);
  15455. word32 macSz = sizeof(mac);
  15456. word32 msgSz = sizeof(msg) - 1;
  15457. word32 expMacSz = sizeof(expMac) - 1;
  15458. XMEMSET(mac, 0, macSz);
  15459. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, key, keySz), 0);
  15460. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  15461. /* Pass in bad args. */
  15462. ExpectIntEQ(wc_AesCmacGenerate(NULL, &macSz, msg, msgSz, key, keySz),
  15463. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15464. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, NULL, keySz),
  15465. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15466. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, key, 0),
  15467. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15468. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, NULL, msgSz, key, keySz),
  15469. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15470. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, key, keySz), 0);
  15471. /* Test bad args. */
  15472. ExpectIntEQ(wc_AesCmacVerify(NULL, macSz, msg, msgSz, key, keySz),
  15473. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15474. ExpectIntEQ(wc_AesCmacVerify(mac, 0, msg, msgSz, key, keySz),
  15475. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15476. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, NULL, keySz),
  15477. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15478. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, key, 0),
  15479. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15480. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, NULL, msgSz, key, keySz),
  15481. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15482. #endif
  15483. return EXPECT_RESULT();
  15484. } /* END test_wc_AesCmacGenerate */
  15485. /*
  15486. * Testing streaming AES-GCM API.
  15487. */
  15488. static int test_wc_AesGcmStream(void)
  15489. {
  15490. EXPECT_DECLS;
  15491. #if !defined(NO_AES) && defined(WOLFSSL_AES_128) && defined(HAVE_AESGCM) && \
  15492. defined(WOLFSSL_AESGCM_STREAM)
  15493. int i;
  15494. WC_RNG rng[1];
  15495. Aes aesEnc[1];
  15496. Aes aesDec[1];
  15497. byte tag[AES_BLOCK_SIZE];
  15498. byte in[AES_BLOCK_SIZE * 3 + 2] = { 0, };
  15499. byte out[AES_BLOCK_SIZE * 3 + 2];
  15500. byte plain[AES_BLOCK_SIZE * 3 + 2];
  15501. byte aad[AES_BLOCK_SIZE * 3 + 2] = { 0, };
  15502. byte key[AES_128_KEY_SIZE] = { 0, };
  15503. byte iv[AES_IV_SIZE] = { 1, };
  15504. byte ivOut[AES_IV_SIZE];
  15505. static const byte expTagAAD1[AES_BLOCK_SIZE] = {
  15506. 0x6c, 0x35, 0xe6, 0x7f, 0x59, 0x9e, 0xa9, 0x2f,
  15507. 0x27, 0x2d, 0x5f, 0x8e, 0x7e, 0x42, 0xd3, 0x05
  15508. };
  15509. static const byte expTagPlain1[AES_BLOCK_SIZE] = {
  15510. 0x24, 0xba, 0x57, 0x95, 0xd0, 0x27, 0x9e, 0x78,
  15511. 0x3a, 0x88, 0x4c, 0x0a, 0x5d, 0x50, 0x23, 0xd1
  15512. };
  15513. static const byte expTag[AES_BLOCK_SIZE] = {
  15514. 0x22, 0x91, 0x70, 0xad, 0x42, 0xc3, 0xad, 0x96,
  15515. 0xe0, 0x31, 0x57, 0x60, 0xb7, 0x92, 0xa3, 0x6d
  15516. };
  15517. XMEMSET(&rng, 0, sizeof(WC_RNG));
  15518. XMEMSET(&aesEnc, 0, sizeof(Aes));
  15519. XMEMSET(&aesDec, 0, sizeof(Aes));
  15520. /* Create a random for generating IV/nonce. */
  15521. ExpectIntEQ(wc_InitRng(rng), 0);
  15522. /* Initialize data structures. */
  15523. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15524. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15525. /* BadParameters to streaming init. */
  15526. ExpectIntEQ(wc_AesGcmEncryptInit(NULL, NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15527. ExpectIntEQ(wc_AesGcmDecryptInit(NULL, NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15528. ExpectIntEQ(wc_AesGcmDecryptInit(aesEnc, NULL, AES_128_KEY_SIZE, NULL, 0),
  15529. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15530. ExpectIntEQ(wc_AesGcmDecryptInit(aesEnc, NULL, 0, NULL, GCM_NONCE_MID_SZ),
  15531. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15532. /* Bad parameters to encrypt update. */
  15533. ExpectIntEQ(wc_AesGcmEncryptUpdate(NULL, NULL, NULL, 0, NULL, 0),
  15534. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15535. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 1, NULL, 0),
  15536. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15537. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, in, 1, NULL, 0),
  15538. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15539. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, NULL, 1, NULL, 0),
  15540. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15541. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, NULL, 1),
  15542. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15543. /* Bad parameters to decrypt update. */
  15544. ExpectIntEQ(wc_AesGcmDecryptUpdate(NULL, NULL, NULL, 0, NULL, 0),
  15545. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15546. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 1, NULL, 0),
  15547. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15548. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, in, 1, NULL, 0),
  15549. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15550. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, out, NULL, 1, NULL, 0),
  15551. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15552. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, NULL, 1),
  15553. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15554. /* Bad parameters to encrypt final. */
  15555. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15556. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15557. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, NULL, AES_BLOCK_SIZE),
  15558. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15559. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15560. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, NULL, AES_BLOCK_SIZE),
  15561. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15562. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE + 1),
  15563. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15564. /* Bad parameters to decrypt final. */
  15565. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15566. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15567. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, NULL, AES_BLOCK_SIZE),
  15568. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15569. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15570. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, NULL, AES_BLOCK_SIZE),
  15571. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15572. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE + 1),
  15573. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15574. /* Check calling final before setting key fails. */
  15575. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_KEY));
  15576. ExpectIntEQ(wc_AesGcmEncryptFinal(aesDec, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_KEY));
  15577. /* Check calling update before setting key else fails. */
  15578. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1),
  15579. WC_NO_ERR_TRACE(MISSING_KEY));
  15580. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1),
  15581. WC_NO_ERR_TRACE(MISSING_KEY));
  15582. /* Set key but not IV. */
  15583. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), NULL, 0), 0);
  15584. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), NULL, 0), 0);
  15585. /* Check calling final before setting IV fails. */
  15586. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_IV));
  15587. ExpectIntEQ(wc_AesGcmEncryptFinal(aesDec, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_IV));
  15588. /* Check calling update before setting IV else fails. */
  15589. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1),
  15590. WC_NO_ERR_TRACE(MISSING_IV));
  15591. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1),
  15592. WC_NO_ERR_TRACE(MISSING_IV));
  15593. /* Set IV using fixed part IV and external IV APIs. */
  15594. ExpectIntEQ(wc_AesGcmSetIV(aesEnc, GCM_NONCE_MID_SZ, iv, AES_IV_FIXED_SZ,
  15595. rng), 0);
  15596. ExpectIntEQ(wc_AesGcmEncryptInit_ex(aesEnc, NULL, 0, ivOut,
  15597. GCM_NONCE_MID_SZ), 0);
  15598. ExpectIntEQ(wc_AesGcmSetExtIV(aesDec, ivOut, GCM_NONCE_MID_SZ), 0);
  15599. ExpectIntEQ(wc_AesGcmInit(aesDec, NULL, 0, NULL, 0), 0);
  15600. /* Encrypt and decrypt data. */
  15601. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, 1, aad, 1), 0);
  15602. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, 1, aad, 1), 0);
  15603. ExpectIntEQ(XMEMCMP(plain, in, 1), 0);
  15604. /* Finalize and check tag matches. */
  15605. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15606. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15607. /* Set key and IV through streaming init API. */
  15608. wc_AesFree(aesEnc);
  15609. wc_AesFree(aesDec);
  15610. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15611. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15612. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15613. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15614. /* Encrypt/decrypt one block and AAD of one block. */
  15615. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, AES_BLOCK_SIZE, aad,
  15616. AES_BLOCK_SIZE), 0);
  15617. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, AES_BLOCK_SIZE, aad,
  15618. AES_BLOCK_SIZE), 0);
  15619. ExpectIntEQ(XMEMCMP(plain, in, AES_BLOCK_SIZE), 0);
  15620. /* Finalize and check tag matches. */
  15621. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15622. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15623. /* Set key and IV through streaming init API. */
  15624. wc_AesFree(aesEnc);
  15625. wc_AesFree(aesDec);
  15626. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15627. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15628. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15629. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15630. /* No data to encrypt/decrypt one byte of AAD. */
  15631. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1), 0);
  15632. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1), 0);
  15633. /* Finalize and check tag matches. */
  15634. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15635. ExpectIntEQ(XMEMCMP(tag, expTagAAD1, AES_BLOCK_SIZE), 0);
  15636. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15637. /* Set key and IV through streaming init API. */
  15638. wc_AesFree(aesEnc);
  15639. wc_AesFree(aesDec);
  15640. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15641. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15642. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15643. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15644. /* Encrypt/decrypt one byte and no AAD. */
  15645. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, 1, NULL, 0), 0);
  15646. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, 1, NULL, 0), 0);
  15647. ExpectIntEQ(XMEMCMP(plain, in, 1), 0);
  15648. /* Finalize and check tag matches. */
  15649. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15650. ExpectIntEQ(XMEMCMP(tag, expTagPlain1, AES_BLOCK_SIZE), 0);
  15651. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15652. /* Set key and IV through streaming init API. */
  15653. wc_AesFree(aesEnc);
  15654. wc_AesFree(aesDec);
  15655. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15656. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15657. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15658. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15659. /* Encryption AES is one byte at a time */
  15660. for (i = 0; i < (int)sizeof(aad); i++) {
  15661. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad + i, 1),
  15662. 0);
  15663. }
  15664. for (i = 0; i < (int)sizeof(in); i++) {
  15665. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out + i, in + i, 1, NULL, 0),
  15666. 0);
  15667. }
  15668. /* Decryption AES is two bytes at a time */
  15669. for (i = 0; i < (int)sizeof(aad); i += 2) {
  15670. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad + i, 2),
  15671. 0);
  15672. }
  15673. for (i = 0; i < (int)sizeof(aad); i += 2) {
  15674. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain + i, out + i, 2, NULL,
  15675. 0), 0);
  15676. }
  15677. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  15678. /* Finalize and check tag matches. */
  15679. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15680. ExpectIntEQ(XMEMCMP(tag, expTag, AES_BLOCK_SIZE), 0);
  15681. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15682. /* Check streaming encryption can be decrypted with one shot. */
  15683. wc_AesFree(aesDec);
  15684. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15685. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15686. ExpectIntEQ(wc_AesGcmSetKey(aesDec, key, sizeof(key)), 0);
  15687. ExpectIntEQ(wc_AesGcmDecrypt(aesDec, plain, out, sizeof(in), iv,
  15688. AES_IV_SIZE, tag, AES_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15689. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  15690. wc_AesFree(aesEnc);
  15691. wc_AesFree(aesDec);
  15692. wc_FreeRng(rng);
  15693. #endif
  15694. return EXPECT_RESULT();
  15695. } /* END test_wc_AesGcmStream */
  15696. /*
  15697. * Testing streaming SM4 API.
  15698. */
  15699. static int test_wc_Sm4(void)
  15700. {
  15701. int res = TEST_SKIPPED;
  15702. #ifdef WOLFSSL_SM4
  15703. EXPECT_DECLS;
  15704. wc_Sm4 sm4;
  15705. #if defined(WOLFSSL_SM4_ECB) || defined(WOLFSSL_SM4_CBC) || \
  15706. defined(WOLFSSL_SM4_CTR) || defined(WOLFSSL_SM4_CCM)
  15707. unsigned char key[SM4_KEY_SIZE];
  15708. #endif
  15709. #if defined(WOLFSSL_SM4_CBC) || defined(WOLFSSL_SM4_CTR)
  15710. unsigned char iv[SM4_IV_SIZE];
  15711. #endif
  15712. /* Invalid parameters - wc_Sm4Init */
  15713. ExpectIntEQ(wc_Sm4Init(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15714. /* Valid cases - wc_Sm4Init */
  15715. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15716. #if defined(WOLFSSL_SM4_ECB) || defined(WOLFSSL_SM4_CBC) || \
  15717. defined(WOLFSSL_SM4_CTR) || defined(WOLFSSL_SM4_CCM)
  15718. XMEMSET(key, 0, sizeof(key));
  15719. /* Invalid parameters - wc_Sm4SetKey. */
  15720. ExpectIntEQ(wc_Sm4SetKey(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15721. ExpectIntEQ(wc_Sm4SetKey(&sm4, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15722. ExpectIntEQ(wc_Sm4SetKey(NULL, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15723. ExpectIntEQ(wc_Sm4SetKey(NULL, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15724. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15725. ExpectIntEQ(wc_Sm4SetKey(&sm4, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15726. ExpectIntEQ(wc_Sm4SetKey(NULL, key, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15727. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE-1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15728. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE+1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15729. /* Valid cases - wc_Sm4SetKey. */
  15730. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15731. #endif
  15732. #if defined(WOLFSSL_SM4_CBC) || defined(WOLFSSL_SM4_CTR)
  15733. XMEMSET(iv, 0, sizeof(iv));
  15734. /* Invalid parameters - wc_Sm4SetIV. */
  15735. ExpectIntEQ(wc_Sm4SetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15736. ExpectIntEQ(wc_Sm4SetIV(&sm4, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15737. ExpectIntEQ(wc_Sm4SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15738. /* Valid cases - wc_Sm4SetIV. */
  15739. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15740. #endif
  15741. /* Valid cases - wc_Sm4Free */
  15742. wc_Sm4Free(NULL);
  15743. wc_Sm4Free(&sm4);
  15744. res = EXPECT_RESULT();
  15745. #endif
  15746. return res;
  15747. } /* END test_wc_Sm4 */
  15748. /*
  15749. * Testing block based SM4-ECB API.
  15750. */
  15751. static int test_wc_Sm4Ecb(void)
  15752. {
  15753. int res = TEST_SKIPPED;
  15754. #ifdef WOLFSSL_SM4_ECB
  15755. EXPECT_DECLS;
  15756. wc_Sm4 sm4;
  15757. unsigned char key[SM4_KEY_SIZE];
  15758. unsigned char in[SM4_BLOCK_SIZE * 2];
  15759. unsigned char out[SM4_BLOCK_SIZE * 2];
  15760. unsigned char out2[SM4_BLOCK_SIZE];
  15761. XMEMSET(key, 0, sizeof(key));
  15762. XMEMSET(in, 0, sizeof(in));
  15763. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15764. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15765. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15766. /* Tested in test_wc_Sm4. */
  15767. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15768. /* Invalid parameters - wc_Sm4EcbEncrypt. */
  15769. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15770. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15771. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15772. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15773. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15774. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15775. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15776. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15777. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15778. /* Valid cases - wc_Sm4EcbEncrypt. */
  15779. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 0), 0);
  15780. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15781. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15782. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15783. /* In and out are same pointer. */
  15784. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15785. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15786. /* Invalid parameters - wc_Sm4EcbDecrypt. */
  15787. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15788. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15789. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15790. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15791. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15792. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15793. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15794. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15795. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15796. /* Valid cases - wc_Sm4EcbDecrypt. */
  15797. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 0), 0);
  15798. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15799. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15800. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15801. /* In and out are same pointer. */
  15802. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15803. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15804. wc_Sm4Free(&sm4);
  15805. res = EXPECT_RESULT();
  15806. #endif
  15807. return res;
  15808. } /* END test_wc_Sm4Ecb */
  15809. /*
  15810. * Testing block based SM4-CBC API.
  15811. */
  15812. static int test_wc_Sm4Cbc(void)
  15813. {
  15814. int res = TEST_SKIPPED;
  15815. #ifdef WOLFSSL_SM4_CBC
  15816. EXPECT_DECLS;
  15817. wc_Sm4 sm4;
  15818. unsigned char key[SM4_KEY_SIZE];
  15819. unsigned char iv[SM4_IV_SIZE];
  15820. unsigned char in[SM4_BLOCK_SIZE * 2];
  15821. unsigned char out[SM4_BLOCK_SIZE * 2];
  15822. unsigned char out2[SM4_BLOCK_SIZE];
  15823. XMEMSET(key, 0, sizeof(key));
  15824. XMEMSET(iv, 0, sizeof(iv));
  15825. XMEMSET(in, 0, sizeof(in));
  15826. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15827. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15828. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15829. /* Tested in test_wc_Sm4. */
  15830. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15831. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  15832. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  15833. /* Tested in test_wc_Sm4. */
  15834. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15835. /* Invalid parameters - wc_Sm4CbcEncrypt. */
  15836. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15837. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15838. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15839. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15840. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15841. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15842. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15843. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15844. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15845. /* Valid cases - wc_Sm4CbcEncrypt. */
  15846. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), 0);
  15847. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15848. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15849. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15850. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15851. /* In and out are same pointer. */
  15852. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15853. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15854. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15855. /* Invalid parameters - wc_Sm4CbcDecrypt. */
  15856. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15857. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15858. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15859. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15860. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15861. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15862. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15863. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15864. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15865. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15866. /* Valid cases - wc_Sm4CbcDecrypt. */
  15867. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), 0);
  15868. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15869. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15870. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15871. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15872. /* In and out are same pointer. */
  15873. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15874. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15875. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15876. wc_Sm4Free(&sm4);
  15877. res = EXPECT_RESULT();
  15878. #endif
  15879. return res;
  15880. } /* END test_wc_Sm4Cbc */
  15881. /*
  15882. * Testing streaming SM4-CTR API.
  15883. */
  15884. static int test_wc_Sm4Ctr(void)
  15885. {
  15886. int res = TEST_SKIPPED;
  15887. #ifdef WOLFSSL_SM4_CTR
  15888. EXPECT_DECLS;
  15889. wc_Sm4 sm4;
  15890. unsigned char key[SM4_KEY_SIZE];
  15891. unsigned char iv[SM4_IV_SIZE];
  15892. unsigned char in[SM4_BLOCK_SIZE * 4];
  15893. unsigned char out[SM4_BLOCK_SIZE * 4];
  15894. unsigned char out2[SM4_BLOCK_SIZE * 4];
  15895. word32 chunk;
  15896. word32 i;
  15897. XMEMSET(key, 0, sizeof(key));
  15898. XMEMSET(iv, 0, sizeof(iv));
  15899. XMEMSET(in, 0, sizeof(in));
  15900. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15901. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15902. /* Tested in test_wc_Sm4. */
  15903. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15904. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  15905. /* Tested in test_wc_Sm4. */
  15906. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15907. /* Invalid parameters - wc_Sm4CtrEncrypt. */
  15908. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15909. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15910. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15911. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15912. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15913. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15914. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15915. /* Valid cases - wc_Sm4CtrEncrypt. */
  15916. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), 0);
  15917. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, 1), 0);
  15918. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15919. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 2), 0);
  15920. ExpectIntEQ(XMEMCMP(out, out2, 1), 0);
  15921. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15922. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15923. ExpectIntEQ(XMEMCMP(out2, out, 2), 0);
  15924. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15925. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15926. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15927. /* In and out are same pointer. Also check encrypt of cipher text produces
  15928. * plaintext.
  15929. */
  15930. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15931. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, out, SM4_BLOCK_SIZE * 2), 0);
  15932. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15933. /* Chunking tests. */
  15934. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15935. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, (word32)sizeof(in)), 0);
  15936. for (chunk = 1; chunk <= SM4_BLOCK_SIZE + 1; chunk++) {
  15937. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15938. for (i = 0; i + chunk <= (word32)sizeof(in); i += chunk) {
  15939. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out + i, in + i, chunk), 0);
  15940. }
  15941. if (i < (word32)sizeof(in)) {
  15942. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out + i, in + i,
  15943. (word32)sizeof(in) - i), 0);
  15944. }
  15945. ExpectIntEQ(XMEMCMP(out, out2, (word32)sizeof(out)), 0);
  15946. }
  15947. for (i = 0; i < (word32)sizeof(iv); i++) {
  15948. iv[i] = 0xff;
  15949. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15950. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15951. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15952. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, out, SM4_BLOCK_SIZE * 2), 0);
  15953. ExpectIntEQ(XMEMCMP(out2, in, SM4_BLOCK_SIZE * 2), 0);
  15954. }
  15955. wc_Sm4Free(&sm4);
  15956. res = EXPECT_RESULT();
  15957. #endif
  15958. return res;
  15959. } /* END test_wc_Sm4Ctr */
  15960. /*
  15961. * Testing stream SM4-GCM API.
  15962. */
  15963. static int test_wc_Sm4Gcm(void)
  15964. {
  15965. int res = TEST_SKIPPED;
  15966. #ifdef WOLFSSL_SM4_GCM
  15967. EXPECT_DECLS;
  15968. wc_Sm4 sm4;
  15969. unsigned char key[SM4_KEY_SIZE];
  15970. unsigned char nonce[GCM_NONCE_MAX_SZ];
  15971. unsigned char in[SM4_BLOCK_SIZE * 2];
  15972. unsigned char in2[SM4_BLOCK_SIZE * 2];
  15973. unsigned char out[SM4_BLOCK_SIZE * 2];
  15974. unsigned char out2[SM4_BLOCK_SIZE * 2];
  15975. unsigned char dec[SM4_BLOCK_SIZE * 2];
  15976. unsigned char tag[SM4_BLOCK_SIZE];
  15977. unsigned char aad[SM4_BLOCK_SIZE * 2];
  15978. word32 i;
  15979. XMEMSET(key, 0, sizeof(key));
  15980. XMEMSET(nonce, 0, sizeof(nonce));
  15981. XMEMSET(in, 0, sizeof(in));
  15982. XMEMSET(in2, 0, sizeof(in2));
  15983. XMEMSET(aad, 0, sizeof(aad));
  15984. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15985. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 0, nonce, GCM_NONCE_MID_SZ, tag,
  15986. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  15987. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 0, nonce, GCM_NONCE_MID_SZ, tag,
  15988. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  15989. /* Invalid parameters - wc_Sm4GcmSetKey. */
  15990. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15991. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15992. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15993. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15994. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15995. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15996. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, key, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15997. /* Valid parameters - wc_Sm4GcmSetKey. */
  15998. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15999. /* Invalid parameters - wc_Sm4GcmEncrypt. */
  16000. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16001. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16002. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16003. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16004. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  16005. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16006. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  16007. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16008. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  16009. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16010. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  16011. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16012. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16013. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16014. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, in, 1, nonce, GCM_NONCE_MID_SZ,
  16015. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16016. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  16017. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16018. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, NULL, GCM_NONCE_MID_SZ, tag,
  16019. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16020. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, 0, tag,
  16021. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16022. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ,
  16023. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16024. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16025. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16026. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16027. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16028. /* Invalid parameters - wc_Sm4GcmDecrypt. */
  16029. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16030. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16031. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16032. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16033. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  16034. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16035. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  16036. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16037. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  16038. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16039. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  16040. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16041. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16042. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16043. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, in, 1, nonce, GCM_NONCE_MID_SZ,
  16044. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16045. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  16046. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16047. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, NULL, GCM_NONCE_MID_SZ, tag,
  16048. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16049. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, 0, tag,
  16050. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16051. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ,
  16052. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16053. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16054. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16055. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16056. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16057. /* Valid cases - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  16058. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  16059. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16060. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  16061. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16062. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  16063. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16064. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  16065. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16066. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16067. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16068. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16069. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16070. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16071. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16072. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16073. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16074. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  16075. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16076. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  16077. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16078. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16079. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16080. ExpectIntEQ(XMEMCMP(in2, out, SM4_BLOCK_SIZE * 2), 0);
  16081. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16082. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16083. ExpectIntEQ(XMEMCMP(in2, in, SM4_BLOCK_SIZE * 2), 0);
  16084. /* Check vald values of nonce - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  16085. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16086. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16087. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16088. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16089. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  16090. GCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16091. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  16092. GCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16093. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  16094. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)),
  16095. WC_NO_ERR_TRACE(SM4_GCM_AUTH_E));
  16096. /* Check valid values of tag size - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  16097. for (i = WOLFSSL_MIN_AUTH_TAG_SZ; i < SM4_BLOCK_SIZE; i++) {
  16098. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16099. GCM_NONCE_MID_SZ, tag, i, aad, sizeof(aad)), 0);
  16100. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16101. GCM_NONCE_MID_SZ, tag, i, aad, sizeof(aad)), 0);
  16102. }
  16103. /* Check different in/out sizes. */
  16104. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 0, nonce,
  16105. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16106. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 0, nonce,
  16107. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16108. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce,
  16109. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16110. for (i = 2; i <= SM4_BLOCK_SIZE * 2; i++) {
  16111. XMEMCPY(out2, out, i - 1);
  16112. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, i, nonce, GCM_NONCE_MID_SZ,
  16113. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16114. ExpectIntEQ(XMEMCMP(out, out2, i - 1), 0);
  16115. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, dec, out, i, nonce, GCM_NONCE_MID_SZ,
  16116. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16117. ExpectIntEQ(XMEMCMP(in, dec, i), 0);
  16118. }
  16119. /* Force the counter to roll over in first byte. */
  16120. {
  16121. static unsigned char largeIn[256 * SM4_BLOCK_SIZE];
  16122. static unsigned char largeOut[256 * SM4_BLOCK_SIZE];
  16123. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, largeOut, largeIn, sizeof(largeIn),
  16124. nonce, GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16125. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, largeOut, largeOut, sizeof(largeIn),
  16126. nonce, GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16127. ExpectIntEQ(XMEMCMP(largeOut, largeIn, sizeof(largeIn)), 0);
  16128. }
  16129. wc_Sm4Free(&sm4);
  16130. res = EXPECT_RESULT();
  16131. #endif
  16132. return res;
  16133. } /* END test_wc_Sm4Gcm */
  16134. /*
  16135. * Testing stream SM4-CCM API.
  16136. */
  16137. static int test_wc_Sm4Ccm(void)
  16138. {
  16139. int res = TEST_SKIPPED;
  16140. #ifdef WOLFSSL_SM4_CCM
  16141. EXPECT_DECLS;
  16142. wc_Sm4 sm4;
  16143. unsigned char key[SM4_KEY_SIZE];
  16144. unsigned char nonce[CCM_NONCE_MAX_SZ];
  16145. unsigned char in[SM4_BLOCK_SIZE * 2];
  16146. unsigned char in2[SM4_BLOCK_SIZE * 2];
  16147. unsigned char out[SM4_BLOCK_SIZE * 2];
  16148. unsigned char out2[SM4_BLOCK_SIZE * 2];
  16149. unsigned char dec[SM4_BLOCK_SIZE * 2];
  16150. unsigned char tag[SM4_BLOCK_SIZE];
  16151. unsigned char aad[SM4_BLOCK_SIZE * 2];
  16152. word32 i;
  16153. XMEMSET(key, 0, sizeof(key));
  16154. XMEMSET(nonce, 0, sizeof(nonce));
  16155. XMEMSET(in, 0, sizeof(in));
  16156. XMEMSET(in2, 0, sizeof(in2));
  16157. XMEMSET(aad, 0, sizeof(aad));
  16158. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  16159. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 0, nonce, CCM_NONCE_MAX_SZ, tag,
  16160. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  16161. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 0, nonce, CCM_NONCE_MAX_SZ, tag,
  16162. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  16163. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  16164. /* Invalid parameters - wc_Sm4CcmEncrypt. */
  16165. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16166. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16167. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16168. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16169. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  16170. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16171. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  16172. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16173. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  16174. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16175. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  16176. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16177. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16178. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16179. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, in, 1, nonce, CCM_NONCE_MAX_SZ,
  16180. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16181. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  16182. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16183. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, NULL, CCM_NONCE_MAX_SZ, tag,
  16184. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16185. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, 0, tag,
  16186. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16187. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ,
  16188. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16189. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16190. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16191. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16192. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16193. /* Invalid parameters - wc_Sm4CcmDecrypt. */
  16194. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16195. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16196. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16197. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16198. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  16199. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16200. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  16201. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16202. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  16203. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16204. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  16205. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16206. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16207. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16208. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, in, 1, nonce, CCM_NONCE_MAX_SZ,
  16209. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16210. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  16211. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16212. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, NULL, CCM_NONCE_MAX_SZ, tag,
  16213. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16214. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, 0, tag,
  16215. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16216. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ,
  16217. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16218. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16219. WOLFSSL_MIN_AUTH_TAG_SZ - 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16220. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16221. SM4_BLOCK_SIZE + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16222. /* Valid cases - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  16223. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  16224. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16225. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  16226. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16227. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  16228. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16229. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  16230. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16231. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16232. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16233. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16234. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16235. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16236. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16237. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16238. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16239. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  16240. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16241. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  16242. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16243. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16244. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16245. ExpectIntEQ(XMEMCMP(in2, out, SM4_BLOCK_SIZE * 2), 0);
  16246. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16247. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16248. ExpectIntEQ(XMEMCMP(in2, in, SM4_BLOCK_SIZE * 2), 0);
  16249. /* Check vald values of nonce - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  16250. for (i = CCM_NONCE_MIN_SZ; i <= CCM_NONCE_MAX_SZ; i++) {
  16251. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16252. i, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16253. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16254. i, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16255. }
  16256. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16257. CCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)),
  16258. WC_NO_ERR_TRACE(SM4_CCM_AUTH_E));
  16259. /* Check invalid values of tag size - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  16260. for (i = 0; i < 4; i++) {
  16261. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16262. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16263. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16264. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16265. }
  16266. /* Odd values in range 4..SM4_BLOCK_SIZE. */
  16267. for (i = 2; i < SM4_BLOCK_SIZE / 2; i++) {
  16268. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16269. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16270. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16271. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16272. }
  16273. /* Check valid values of tag size - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt.
  16274. * Even values in range 4..SM4_BLOCK_SIZE.
  16275. */
  16276. for (i = 2; i < SM4_BLOCK_SIZE / 2; i++) {
  16277. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16278. CCM_NONCE_MAX_SZ, tag, i * 2, aad, sizeof(aad)), 0);
  16279. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16280. CCM_NONCE_MAX_SZ, tag, i * 2, aad, sizeof(aad)), 0);
  16281. }
  16282. /* Check different in/out sizes. */
  16283. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 0, nonce,
  16284. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16285. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 0, nonce,
  16286. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16287. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce,
  16288. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16289. for (i = 2; i <= SM4_BLOCK_SIZE * 2; i++) {
  16290. XMEMCPY(out2, out, i - 1);
  16291. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, i, nonce, CCM_NONCE_MAX_SZ,
  16292. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16293. ExpectIntEQ(XMEMCMP(out, out2, i - 1), 0);
  16294. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, dec, out, i, nonce, CCM_NONCE_MAX_SZ,
  16295. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16296. ExpectIntEQ(XMEMCMP(in, dec, i), 0);
  16297. }
  16298. /* Force the counter to roll over in first byte. */
  16299. {
  16300. static unsigned char largeIn[256 * SM4_BLOCK_SIZE];
  16301. static unsigned char largeOut[256 * SM4_BLOCK_SIZE];
  16302. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, largeOut, largeIn, sizeof(largeIn),
  16303. nonce, CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16304. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, largeOut, largeOut, sizeof(largeIn),
  16305. nonce, CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16306. ExpectIntEQ(XMEMCMP(largeOut, largeIn, sizeof(largeIn)), 0);
  16307. }
  16308. wc_Sm4Free(&sm4);
  16309. res = EXPECT_RESULT();
  16310. #endif
  16311. return res;
  16312. } /* END test_wc_Sm4Ccm */
  16313. /*
  16314. * unit test for wc_Des3_SetIV()
  16315. */
  16316. static int test_wc_Des3_SetIV(void)
  16317. {
  16318. EXPECT_DECLS;
  16319. #ifndef NO_DES3
  16320. Des3 des;
  16321. const byte key[] = {
  16322. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16323. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16324. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16325. };
  16326. const byte iv[] = {
  16327. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16328. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16329. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16330. };
  16331. XMEMSET(&des, 0, sizeof(Des3));
  16332. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16333. /* DES_ENCRYPTION or DES_DECRYPTION */
  16334. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16335. ExpectIntEQ(XMEMCMP(iv, des.reg, DES_BLOCK_SIZE), 0);
  16336. #ifndef HAVE_FIPS /* no sanity checks with FIPS wrapper */
  16337. /* Test explicitly wc_Des3_SetIV() */
  16338. ExpectIntEQ(wc_Des3_SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16339. ExpectIntEQ(wc_Des3_SetIV(&des, NULL), 0);
  16340. #endif
  16341. wc_Des3Free(&des);
  16342. #endif
  16343. return EXPECT_RESULT();
  16344. } /* END test_wc_Des3_SetIV */
  16345. /*
  16346. * unit test for wc_Des3_SetKey()
  16347. */
  16348. static int test_wc_Des3_SetKey(void)
  16349. {
  16350. EXPECT_DECLS;
  16351. #ifndef NO_DES3
  16352. Des3 des;
  16353. const byte key[] = {
  16354. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16355. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16356. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16357. };
  16358. const byte iv[] = {
  16359. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16360. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16361. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16362. };
  16363. XMEMSET(&des, 0, sizeof(Des3));
  16364. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16365. /* DES_ENCRYPTION or DES_DECRYPTION */
  16366. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16367. ExpectIntEQ(XMEMCMP(iv, des.reg, DES_BLOCK_SIZE), 0);
  16368. /* Test bad args. */
  16369. ExpectIntEQ(wc_Des3_SetKey(NULL, key, iv, DES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16370. ExpectIntEQ(wc_Des3_SetKey(&des, NULL, iv, DES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16371. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16372. /* Default case. Should return 0. */
  16373. ExpectIntEQ(wc_Des3_SetKey(&des, key, NULL, DES_ENCRYPTION), 0);
  16374. wc_Des3Free(&des);
  16375. #endif
  16376. return EXPECT_RESULT();
  16377. } /* END test_wc_Des3_SetKey */
  16378. /*
  16379. * Test function for wc_Des3_CbcEncrypt and wc_Des3_CbcDecrypt
  16380. */
  16381. static int test_wc_Des3_CbcEncryptDecrypt(void)
  16382. {
  16383. EXPECT_DECLS;
  16384. #ifndef NO_DES3
  16385. Des3 des;
  16386. byte cipher[24];
  16387. byte plain[24];
  16388. const byte key[] = {
  16389. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16390. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16391. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16392. };
  16393. const byte iv[] = {
  16394. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16395. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16396. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16397. };
  16398. const byte vector[] = { /* "Now is the time for all " w/o trailing 0 */
  16399. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16400. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16401. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16402. };
  16403. XMEMSET(&des, 0, sizeof(Des3));
  16404. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16405. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16406. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, cipher, vector, 24), 0);
  16407. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_DECRYPTION), 0);
  16408. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, plain, cipher, 24), 0);
  16409. ExpectIntEQ(XMEMCMP(plain, vector, 24), 0);
  16410. /* Pass in bad args. */
  16411. ExpectIntEQ(wc_Des3_CbcEncrypt(NULL, cipher, vector, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16412. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, NULL, vector, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16413. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, cipher, NULL, sizeof(vector)),
  16414. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16415. ExpectIntEQ(wc_Des3_CbcDecrypt(NULL, plain, cipher, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16416. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, NULL, cipher, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16417. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, plain, NULL, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16418. wc_Des3Free(&des);
  16419. #endif
  16420. return EXPECT_RESULT();
  16421. } /* END wc_Des3_CbcEncrypt */
  16422. /*
  16423. * Unit test for wc_Des3_CbcEncryptWithKey and wc_Des3_CbcDecryptWithKey
  16424. */
  16425. static int test_wc_Des3_CbcEncryptDecryptWithKey(void)
  16426. {
  16427. EXPECT_DECLS;
  16428. #ifndef NO_DES3
  16429. word32 vectorSz, cipherSz;
  16430. byte cipher[24];
  16431. byte plain[24];
  16432. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  16433. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16434. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16435. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16436. };
  16437. byte key[] = {
  16438. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16439. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16440. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16441. };
  16442. byte iv[] = {
  16443. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16444. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16445. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16446. };
  16447. vectorSz = sizeof(byte) * 24;
  16448. cipherSz = sizeof(byte) * 24;
  16449. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, key, iv),
  16450. 0);
  16451. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, key, iv), 0);
  16452. ExpectIntEQ(XMEMCMP(plain, vector, 24), 0);
  16453. /* pass in bad args. */
  16454. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(NULL, vector, vectorSz, key, iv),
  16455. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16456. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, NULL, vectorSz, key, iv),
  16457. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16458. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, NULL, iv),
  16459. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16460. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, key, NULL),
  16461. 0);
  16462. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(NULL, cipher, cipherSz, key, iv),
  16463. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16464. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, NULL, cipherSz, key, iv),
  16465. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16466. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, NULL, iv),
  16467. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16468. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, key, NULL),
  16469. 0);
  16470. #endif
  16471. return EXPECT_RESULT();
  16472. } /* END test_wc_Des3_CbcEncryptDecryptWithKey */
  16473. /*
  16474. * Unit test for wc_Des3_EcbEncrypt
  16475. */
  16476. static int test_wc_Des3_EcbEncrypt(void)
  16477. {
  16478. EXPECT_DECLS;
  16479. #if !defined(NO_DES3) && defined(WOLFSSL_DES_ECB)
  16480. Des3 des;
  16481. byte cipher[24];
  16482. word32 cipherSz = sizeof(cipher);
  16483. const byte key[] = {
  16484. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16485. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16486. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16487. };
  16488. const byte iv[] = {
  16489. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16490. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16491. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16492. };
  16493. const byte vector[] = { /* "Now is the time for all " w/o trailing 0 */
  16494. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16495. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16496. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16497. };
  16498. XMEMSET(&des, 0, sizeof(Des3));
  16499. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16500. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16501. /* Bad Cases */
  16502. ExpectIntEQ(wc_Des3_EcbEncrypt(NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16503. ExpectIntEQ(wc_Des3_EcbEncrypt(NULL, cipher, vector, cipherSz),
  16504. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16505. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, 0, vector, cipherSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16506. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, NULL, cipherSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16507. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, vector, 0), 0);
  16508. /* Good Cases */
  16509. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, vector, cipherSz), 0);
  16510. wc_Des3Free(&des);
  16511. #endif
  16512. return EXPECT_RESULT();
  16513. } /* END test_wc_Des3_EcbEncrypt */
  16514. /*
  16515. * Testing wc_Chacha_SetKey() and wc_Chacha_SetIV()
  16516. */
  16517. static int test_wc_Chacha_SetKey(void)
  16518. {
  16519. EXPECT_DECLS;
  16520. #ifdef HAVE_CHACHA
  16521. ChaCha ctx;
  16522. const byte key[] = {
  16523. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16524. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16525. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16526. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16527. };
  16528. word32 keySz = (word32)(sizeof(key)/sizeof(byte));
  16529. byte cipher[128];
  16530. XMEMSET(cipher, 0, sizeof(cipher));
  16531. ExpectIntEQ(wc_Chacha_SetKey(&ctx, key, keySz), 0);
  16532. /* Test bad args. */
  16533. ExpectIntEQ(wc_Chacha_SetKey(NULL, key, keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16534. ExpectIntEQ(wc_Chacha_SetKey(&ctx, key, 18), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16535. ExpectIntEQ(wc_Chacha_SetIV(&ctx, cipher, 0), 0);
  16536. /* Test bad args. */
  16537. ExpectIntEQ(wc_Chacha_SetIV(NULL, cipher, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16538. #endif
  16539. return EXPECT_RESULT();
  16540. } /* END test_wc_Chacha_SetKey */
  16541. /*
  16542. * unit test for wc_Poly1305SetKey()
  16543. */
  16544. static int test_wc_Poly1305SetKey(void)
  16545. {
  16546. EXPECT_DECLS;
  16547. #ifdef HAVE_POLY1305
  16548. Poly1305 ctx;
  16549. const byte key[] =
  16550. {
  16551. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16552. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16553. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16554. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16555. };
  16556. word32 keySz = (word32)(sizeof(key)/sizeof(byte));
  16557. ExpectIntEQ(wc_Poly1305SetKey(&ctx, key, keySz), 0);
  16558. /* Test bad args. */
  16559. ExpectIntEQ(wc_Poly1305SetKey(NULL, key,keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16560. ExpectIntEQ(wc_Poly1305SetKey(&ctx, NULL, keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16561. ExpectIntEQ(wc_Poly1305SetKey(&ctx, key, 18), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16562. #endif
  16563. return EXPECT_RESULT();
  16564. } /* END test_wc_Poly1305_SetKey() */
  16565. /*
  16566. * Testing wc_Chacha_Process()
  16567. */
  16568. static int test_wc_Chacha_Process(void)
  16569. {
  16570. EXPECT_DECLS;
  16571. #ifdef HAVE_CHACHA
  16572. ChaCha enc, dec;
  16573. byte cipher[128];
  16574. byte plain[128];
  16575. const byte key[] =
  16576. {
  16577. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16578. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16579. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16580. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16581. };
  16582. const char* input = "Everybody gets Friday off.";
  16583. word32 keySz = sizeof(key)/sizeof(byte);
  16584. unsigned long int inlen = XSTRLEN(input);
  16585. /* Initialize stack variables. */
  16586. XMEMSET(cipher, 0, 128);
  16587. XMEMSET(plain, 0, 128);
  16588. ExpectIntEQ(wc_Chacha_SetKey(&enc, key, keySz), 0);
  16589. ExpectIntEQ(wc_Chacha_SetKey(&dec, key, keySz), 0);
  16590. ExpectIntEQ(wc_Chacha_SetIV(&enc, cipher, 0), 0);
  16591. ExpectIntEQ(wc_Chacha_SetIV(&dec, cipher, 0), 0);
  16592. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, (byte*)input, (word32)inlen),
  16593. 0);
  16594. ExpectIntEQ(wc_Chacha_Process(&dec, plain, cipher, (word32)inlen), 0);
  16595. ExpectIntEQ(XMEMCMP(input, plain, inlen), 0);
  16596. #if !defined(USE_INTEL_CHACHA_SPEEDUP) && !defined(WOLFSSL_ARMASM)
  16597. /* test checking and using leftovers, currently just in C code */
  16598. ExpectIntEQ(wc_Chacha_SetIV(&enc, cipher, 0), 0);
  16599. ExpectIntEQ(wc_Chacha_SetIV(&dec, cipher, 0), 0);
  16600. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, (byte*)input,
  16601. (word32)inlen - 2), 0);
  16602. ExpectIntEQ(wc_Chacha_Process(&enc, cipher + (inlen - 2),
  16603. (byte*)input + (inlen - 2), 2), 0);
  16604. ExpectIntEQ(wc_Chacha_Process(&dec, plain, (byte*)cipher,
  16605. (word32)inlen - 2), 0);
  16606. ExpectIntEQ(wc_Chacha_Process(&dec, cipher + (inlen - 2),
  16607. (byte*)input + (inlen - 2), 2), 0);
  16608. ExpectIntEQ(XMEMCMP(input, plain, inlen), 0);
  16609. /* check edge cases with counter increment */
  16610. {
  16611. /* expected results collected from wolfSSL 4.3.0 encrypted in one call*/
  16612. const byte expected[] = {
  16613. 0x54,0xB1,0xE2,0xD4,0xA2,0x4D,0x52,0x5F,
  16614. 0x42,0x04,0x89,0x7C,0x6E,0x2D,0xFC,0x2D,
  16615. 0x10,0x25,0xB6,0x92,0x71,0xD5,0xC3,0x20,
  16616. 0xE3,0x0E,0xEC,0xF4,0xD8,0x10,0x70,0x29,
  16617. 0x2D,0x4C,0x2A,0x56,0x21,0xE1,0xC7,0x37,
  16618. 0x0B,0x86,0xF5,0x02,0x8C,0xB8,0xB8,0x38,
  16619. 0x41,0xFD,0xDF,0xD9,0xC3,0xE6,0xC8,0x88,
  16620. 0x06,0x82,0xD4,0x80,0x6A,0x50,0x69,0xD5,
  16621. 0xB9,0xB0,0x2F,0x44,0x36,0x5D,0xDA,0x5E,
  16622. 0xDE,0xF6,0xF5,0xFC,0x44,0xDC,0x07,0x51,
  16623. 0xA7,0x32,0x42,0xDB,0xCC,0xBD,0xE2,0xE5,
  16624. 0x0B,0xB1,0x14,0xFF,0x12,0x80,0x16,0x43,
  16625. 0xE7,0x40,0xD5,0xEA,0xC7,0x3F,0x69,0x07,
  16626. 0x64,0xD4,0x86,0x6C,0xE2,0x1F,0x8F,0x6E,
  16627. 0x35,0x41,0xE7,0xD3,0xB5,0x5D,0xD6,0xD4,
  16628. 0x9F,0x00,0xA9,0xAE,0x3D,0x28,0xA5,0x37,
  16629. 0x80,0x3D,0x11,0x25,0xE2,0xB6,0x99,0xD9,
  16630. 0x9B,0x98,0xE9,0x37,0xB9,0xF8,0xA0,0x04,
  16631. 0xDF,0x13,0x49,0x3F,0x19,0x6A,0x45,0x06,
  16632. 0x21,0xB4,0xC7,0x3B,0x49,0x45,0xB4,0xC8,
  16633. 0x03,0x5B,0x43,0x89,0xBD,0xB3,0x96,0x4B,
  16634. 0x17,0x6F,0x85,0xC6,0xCF,0xA6,0x05,0x35,
  16635. 0x1E,0x25,0x03,0xBB,0x55,0x0A,0xD5,0x54,
  16636. 0x41,0xEA,0xEB,0x50,0x40,0x1B,0x43,0x19,
  16637. 0x59,0x1B,0x0E,0x12,0x3E,0xA2,0x71,0xC3,
  16638. 0x1A,0xA7,0x11,0x50,0x43,0x9D,0x56,0x3B,
  16639. 0x63,0x2F,0x63,0xF1,0x8D,0xAE,0xF3,0x23,
  16640. 0xFA,0x1E,0xD8,0x6A,0xE1,0xB2,0x4B,0xF3,
  16641. 0xB9,0x13,0x7A,0x72,0x2B,0x6D,0xCC,0x41,
  16642. 0x1C,0x69,0x7C,0xCD,0x43,0x6F,0xE4,0xE2,
  16643. 0x38,0x99,0xFB,0xC3,0x38,0x92,0x62,0x35,
  16644. 0xC0,0x1D,0x60,0xE4,0x4B,0xDD,0x0C,0x14
  16645. };
  16646. const byte iv2[] = {
  16647. 0x9D,0xED,0xE7,0x0F,0xEC,0x81,0x51,0xD9,
  16648. 0x77,0x39,0x71,0xA6,0x21,0xDF,0xB8,0x93
  16649. };
  16650. byte input2[256];
  16651. int i;
  16652. for (i = 0; i < 256; i++)
  16653. input2[i] = (byte)i;
  16654. ExpectIntEQ(wc_Chacha_SetIV(&enc, iv2, 0), 0);
  16655. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2, 64), 0);
  16656. ExpectIntEQ(XMEMCMP(expected, cipher, 64), 0);
  16657. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 64, 128), 0);
  16658. ExpectIntEQ(XMEMCMP(expected + 64, cipher, 128), 0);
  16659. /* partial */
  16660. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 192, 32), 0);
  16661. ExpectIntEQ(XMEMCMP(expected + 192, cipher, 32), 0);
  16662. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 224, 32), 0);
  16663. ExpectIntEQ(XMEMCMP(expected + 224, cipher, 32), 0);
  16664. }
  16665. #endif
  16666. /* Test bad args. */
  16667. ExpectIntEQ(wc_Chacha_Process(NULL, cipher, (byte*)input, (word32)inlen),
  16668. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16669. #endif
  16670. return EXPECT_RESULT();
  16671. } /* END test_wc_Chacha_Process */
  16672. /*
  16673. * Testing wc_ChaCha20Poly1305_Encrypt() and wc_ChaCha20Poly1305_Decrypt()
  16674. */
  16675. static int test_wc_ChaCha20Poly1305_aead(void)
  16676. {
  16677. EXPECT_DECLS;
  16678. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  16679. const byte key[] = {
  16680. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  16681. 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  16682. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
  16683. 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  16684. };
  16685. const byte plaintext[] = {
  16686. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61,
  16687. 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
  16688. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20,
  16689. 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
  16690. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39,
  16691. 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,
  16692. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66,
  16693. 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f,
  16694. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20,
  16695. 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20,
  16696. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75,
  16697. 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73,
  16698. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f,
  16699. 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69,
  16700. 0x74, 0x2e
  16701. };
  16702. const byte iv[] = {
  16703. 0x07, 0x00, 0x00, 0x00, 0x40, 0x41, 0x42, 0x43,
  16704. 0x44, 0x45, 0x46, 0x47
  16705. };
  16706. const byte aad[] = { /* additional data */
  16707. 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3,
  16708. 0xc4, 0xc5, 0xc6, 0xc7
  16709. };
  16710. const byte cipher[] = { /* expected output from operation */
  16711. 0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb,
  16712. 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2,
  16713. 0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe,
  16714. 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6,
  16715. 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12,
  16716. 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b,
  16717. 0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29,
  16718. 0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36,
  16719. 0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c,
  16720. 0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58,
  16721. 0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94,
  16722. 0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc,
  16723. 0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d,
  16724. 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b,
  16725. 0x61, 0x16
  16726. };
  16727. const byte authTag[] = { /* expected output from operation */
  16728. 0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a,
  16729. 0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91
  16730. };
  16731. byte generatedCiphertext[272];
  16732. byte generatedPlaintext[272];
  16733. byte generatedAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  16734. /* Initialize stack variables. */
  16735. XMEMSET(generatedCiphertext, 0, 272);
  16736. XMEMSET(generatedPlaintext, 0, 272);
  16737. /* Test Encrypt */
  16738. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16739. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16740. 0);
  16741. ExpectIntEQ(XMEMCMP(generatedCiphertext, cipher,
  16742. sizeof(cipher)/sizeof(byte)), 0);
  16743. /* Test bad args. */
  16744. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(NULL, iv, aad, sizeof(aad),
  16745. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16746. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16747. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, NULL, aad, sizeof(aad),
  16748. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16749. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16750. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad), NULL,
  16751. sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16752. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16753. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16754. NULL, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16755. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16756. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16757. plaintext, sizeof(plaintext), NULL, generatedAuthTag), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16758. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16759. plaintext, sizeof(plaintext), generatedCiphertext, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16760. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16761. sizeof(cipher), authTag, generatedPlaintext), 0);
  16762. ExpectIntEQ(XMEMCMP(generatedPlaintext, plaintext,
  16763. sizeof(plaintext)/sizeof(byte)), 0);
  16764. /* Test bad args. */
  16765. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(NULL, iv, aad, sizeof(aad), cipher,
  16766. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16767. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, NULL, aad, sizeof(aad),
  16768. cipher, sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16769. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), NULL,
  16770. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16771. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16772. sizeof(cipher), NULL, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16773. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16774. sizeof(cipher), authTag, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16775. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), NULL,
  16776. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16777. #endif
  16778. return EXPECT_RESULT();
  16779. } /* END test_wc_ChaCha20Poly1305_aead */
  16780. /*
  16781. * Testing function for wc_Rc2SetKey().
  16782. */
  16783. static int test_wc_Rc2SetKey(void)
  16784. {
  16785. EXPECT_DECLS;
  16786. #ifdef WC_RC2
  16787. Rc2 rc2;
  16788. byte key40[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
  16789. byte iv[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  16790. /* valid key and IV */
  16791. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32) sizeof(key40) / sizeof(byte),
  16792. iv, 40), 0);
  16793. /* valid key, no IV */
  16794. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32) sizeof(key40) / sizeof(byte),
  16795. NULL, 40), 0);
  16796. /* bad arguments */
  16797. /* null Rc2 struct */
  16798. ExpectIntEQ(wc_Rc2SetKey(NULL, key40, (word32) sizeof(key40) / sizeof(byte),
  16799. iv, 40), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16800. /* null key */
  16801. ExpectIntEQ(wc_Rc2SetKey(&rc2, NULL, (word32) sizeof(key40) / sizeof(byte),
  16802. iv, 40), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16803. /* key size == 0 */
  16804. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, 0, iv, 40), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16805. /* key size > 128 */
  16806. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, 129, iv, 40), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16807. /* effective bits == 0 */
  16808. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32)sizeof(key40) / sizeof(byte),
  16809. iv, 0), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16810. /* effective bits > 1024 */
  16811. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32)sizeof(key40) / sizeof(byte),
  16812. iv, 1025), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16813. #endif
  16814. return EXPECT_RESULT();
  16815. } /* END test_wc_Rc2SetKey */
  16816. /*
  16817. * Testing function for wc_Rc2SetIV().
  16818. */
  16819. static int test_wc_Rc2SetIV(void)
  16820. {
  16821. EXPECT_DECLS;
  16822. #ifdef WC_RC2
  16823. Rc2 rc2;
  16824. byte iv[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  16825. /* valid IV */
  16826. ExpectIntEQ(wc_Rc2SetIV(&rc2, iv), 0);
  16827. /* valid NULL IV */
  16828. ExpectIntEQ(wc_Rc2SetIV(&rc2, NULL), 0);
  16829. /* bad arguments */
  16830. ExpectIntEQ(wc_Rc2SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16831. ExpectIntEQ(wc_Rc2SetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16832. #endif
  16833. return EXPECT_RESULT();
  16834. } /* END test_wc_Rc2SetIV */
  16835. /*
  16836. * Testing function for wc_Rc2EcbEncrypt() and wc_Rc2EcbDecrypt().
  16837. */
  16838. static int test_wc_Rc2EcbEncryptDecrypt(void)
  16839. {
  16840. EXPECT_DECLS;
  16841. #ifdef WC_RC2
  16842. Rc2 rc2;
  16843. int effectiveKeyBits = 63;
  16844. byte cipher[RC2_BLOCK_SIZE];
  16845. byte plain[RC2_BLOCK_SIZE];
  16846. byte key[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  16847. byte input[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  16848. byte output[] = { 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff };
  16849. XMEMSET(cipher, 0, sizeof(cipher));
  16850. XMEMSET(plain, 0, sizeof(plain));
  16851. ExpectIntEQ(wc_Rc2SetKey(&rc2, key, (word32) sizeof(key) / sizeof(byte),
  16852. NULL, effectiveKeyBits), 0);
  16853. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, input, RC2_BLOCK_SIZE), 0);
  16854. ExpectIntEQ(XMEMCMP(cipher, output, RC2_BLOCK_SIZE), 0);
  16855. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, cipher, RC2_BLOCK_SIZE), 0);
  16856. ExpectIntEQ(XMEMCMP(plain, input, RC2_BLOCK_SIZE), 0);
  16857. /* Rc2EcbEncrypt bad arguments */
  16858. /* null Rc2 struct */
  16859. ExpectIntEQ(wc_Rc2EcbEncrypt(NULL, cipher, input, RC2_BLOCK_SIZE),
  16860. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16861. /* null out buffer */
  16862. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, NULL, input, RC2_BLOCK_SIZE),
  16863. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16864. /* null input buffer */
  16865. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, NULL, RC2_BLOCK_SIZE),
  16866. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16867. /* output buffer sz != RC2_BLOCK_SIZE (8) */
  16868. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, input, 7), WC_NO_ERR_TRACE(BUFFER_E));
  16869. /* Rc2EcbDecrypt bad arguments */
  16870. /* null Rc2 struct */
  16871. ExpectIntEQ(wc_Rc2EcbDecrypt(NULL, plain, output, RC2_BLOCK_SIZE),
  16872. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16873. /* null out buffer */
  16874. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, NULL, output, RC2_BLOCK_SIZE),
  16875. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16876. /* null input buffer */
  16877. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, NULL, RC2_BLOCK_SIZE),
  16878. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16879. /* output buffer sz != RC2_BLOCK_SIZE (8) */
  16880. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, output, 7), WC_NO_ERR_TRACE(BUFFER_E));
  16881. #endif
  16882. return EXPECT_RESULT();
  16883. } /* END test_wc_Rc2EcbEncryptDecrypt */
  16884. /*
  16885. * Testing function for wc_Rc2CbcEncrypt() and wc_Rc2CbcDecrypt().
  16886. */
  16887. static int test_wc_Rc2CbcEncryptDecrypt(void)
  16888. {
  16889. EXPECT_DECLS;
  16890. #ifdef WC_RC2
  16891. Rc2 rc2;
  16892. int effectiveKeyBits = 63;
  16893. byte cipher[RC2_BLOCK_SIZE*2];
  16894. byte plain[RC2_BLOCK_SIZE*2];
  16895. /* vector taken from test.c */
  16896. byte key[] = {
  16897. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  16898. };
  16899. byte iv[] = {
  16900. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  16901. };
  16902. byte input[] = {
  16903. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  16904. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  16905. };
  16906. byte output[] = {
  16907. 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff,
  16908. 0xf0, 0x51, 0x77, 0x8b, 0x65, 0xdb, 0x13, 0x57
  16909. };
  16910. XMEMSET(cipher, 0, sizeof(cipher));
  16911. XMEMSET(plain, 0, sizeof(plain));
  16912. ExpectIntEQ(wc_Rc2SetKey(&rc2, key, (word32) sizeof(key) / sizeof(byte),
  16913. iv, effectiveKeyBits), 0);
  16914. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, cipher, input, sizeof(input)), 0);
  16915. ExpectIntEQ(XMEMCMP(cipher, output, sizeof(output)), 0);
  16916. /* reset IV for decrypt */
  16917. ExpectIntEQ(wc_Rc2SetIV(&rc2, iv), 0);
  16918. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, cipher, sizeof(cipher)), 0);
  16919. ExpectIntEQ(XMEMCMP(plain, input, sizeof(input)), 0);
  16920. /* Rc2CbcEncrypt bad arguments */
  16921. /* null Rc2 struct */
  16922. ExpectIntEQ(wc_Rc2CbcEncrypt(NULL, cipher, input, sizeof(input)),
  16923. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16924. /* null out buffer */
  16925. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, NULL, input, sizeof(input)),
  16926. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16927. /* null input buffer */
  16928. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, cipher, NULL, sizeof(input)),
  16929. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16930. /* Rc2CbcDecrypt bad arguments */
  16931. /* in size is 0 */
  16932. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, output, 0), 0);
  16933. /* null Rc2 struct */
  16934. ExpectIntEQ(wc_Rc2CbcDecrypt(NULL, plain, output, sizeof(output)),
  16935. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16936. /* null out buffer */
  16937. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, NULL, output, sizeof(output)),
  16938. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16939. /* null input buffer */
  16940. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, NULL, sizeof(output)),
  16941. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16942. #endif
  16943. return EXPECT_RESULT();
  16944. } /* END test_wc_Rc2CbcEncryptDecrypt */
  16945. /*
  16946. * Testing function for wc_AesSetIV
  16947. */
  16948. static int test_wc_AesSetIV(void)
  16949. {
  16950. int res = TEST_SKIPPED;
  16951. #if !defined(NO_AES) && defined(WOLFSSL_AES_128)
  16952. Aes aes;
  16953. int ret = 0;
  16954. byte key16[] =
  16955. {
  16956. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16957. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16958. };
  16959. byte iv1[] = "1234567890abcdef";
  16960. byte iv2[] = "0987654321fedcba";
  16961. ret = wc_AesInit(&aes, NULL, INVALID_DEVID);
  16962. if (ret != 0)
  16963. return ret;
  16964. ret = wc_AesSetKey(&aes, key16, (word32) sizeof(key16) / sizeof(byte),
  16965. iv1, AES_ENCRYPTION);
  16966. if (ret == 0) {
  16967. ret = wc_AesSetIV(&aes, iv2);
  16968. }
  16969. /* Test bad args. */
  16970. if (ret == 0) {
  16971. ret = wc_AesSetIV(NULL, iv1);
  16972. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  16973. /* NULL iv should return 0. */
  16974. ret = wc_AesSetIV(&aes, NULL);
  16975. }
  16976. else {
  16977. ret = WOLFSSL_FATAL_ERROR;
  16978. }
  16979. }
  16980. wc_AesFree(&aes);
  16981. res = TEST_RES_CHECK(ret == 0);
  16982. #endif
  16983. return res;
  16984. } /* test_wc_AesSetIV */
  16985. /*
  16986. * Testing function for wc_AesSetKey().
  16987. */
  16988. static int test_wc_AesSetKey(void)
  16989. {
  16990. EXPECT_DECLS;
  16991. #ifndef NO_AES
  16992. Aes aes;
  16993. byte key16[] = {
  16994. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16995. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16996. };
  16997. #ifdef WOLFSSL_AES_192
  16998. byte key24[] = {
  16999. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17000. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17001. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17002. };
  17003. #endif
  17004. #ifdef WOLFSSL_AES_256
  17005. byte key32[] = {
  17006. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17007. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17008. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17009. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17010. };
  17011. #endif
  17012. byte badKey16[] = {
  17013. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17014. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  17015. };
  17016. byte iv[] = "1234567890abcdef";
  17017. XMEMSET(&aes, 0, sizeof(Aes));
  17018. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17019. #ifdef WOLFSSL_AES_128
  17020. ExpectIntEQ(wc_AesSetKey(&aes, key16, (word32)sizeof(key16) / sizeof(byte),
  17021. iv, AES_ENCRYPTION), 0);
  17022. #endif
  17023. #ifdef WOLFSSL_AES_192
  17024. ExpectIntEQ(wc_AesSetKey(&aes, key24, (word32)sizeof(key24) / sizeof(byte),
  17025. iv, AES_ENCRYPTION), 0);
  17026. #endif
  17027. #ifdef WOLFSSL_AES_256
  17028. ExpectIntEQ(wc_AesSetKey(&aes, key32, (word32)sizeof(key32) / sizeof(byte),
  17029. iv, AES_ENCRYPTION), 0);
  17030. #endif
  17031. /* Pass in bad args. */
  17032. ExpectIntEQ(wc_AesSetKey(NULL, key16, (word32)sizeof(key16) / sizeof(byte),
  17033. iv, AES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17034. ExpectIntEQ(wc_AesSetKey(&aes, badKey16,
  17035. (word32)sizeof(badKey16) / sizeof(byte), iv, AES_ENCRYPTION),
  17036. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17037. wc_AesFree(&aes);
  17038. #endif
  17039. return EXPECT_RESULT();
  17040. } /* END test_wc_AesSetKey */
  17041. /*
  17042. * test function for wc_AesCbcEncrypt(), wc_AesCbcDecrypt(),
  17043. * and wc_AesCbcDecryptWithKey()
  17044. */
  17045. static int test_wc_AesCbcEncryptDecrypt(void)
  17046. {
  17047. EXPECT_DECLS;
  17048. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(HAVE_AES_DECRYPT)&& \
  17049. defined(WOLFSSL_AES_256)
  17050. Aes aes;
  17051. byte key32[] = {
  17052. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17053. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17054. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17055. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17056. };
  17057. byte vector[] = { /* Now is the time for all good men w/o trailing 0 */
  17058. 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
  17059. 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20,
  17060. 0x66, 0x6f, 0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20,
  17061. 0x67, 0x6f, 0x6f, 0x64, 0x20, 0x6d, 0x65, 0x6e
  17062. };
  17063. byte iv[] = "1234567890abcdef";
  17064. byte enc[sizeof(vector)];
  17065. byte dec[sizeof(vector)];
  17066. byte dec2[sizeof(vector)];
  17067. /* Init stack variables. */
  17068. XMEMSET(&aes, 0, sizeof(Aes));
  17069. XMEMSET(enc, 0, sizeof(enc));
  17070. XMEMSET(dec, 0, sizeof(vector));
  17071. XMEMSET(dec2, 0, sizeof(vector));
  17072. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17073. ExpectIntEQ(wc_AesSetKey(&aes, key32, AES_BLOCK_SIZE * 2, iv,
  17074. AES_ENCRYPTION), 0);
  17075. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, sizeof(vector)), 0);
  17076. /* Re init for decrypt and set flag. */
  17077. ExpectIntEQ(wc_AesSetKey(&aes, key32, AES_BLOCK_SIZE * 2, iv,
  17078. AES_DECRYPTION), 0);
  17079. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, sizeof(vector)), 0);
  17080. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  17081. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE, key32,
  17082. sizeof(key32)/sizeof(byte), iv), 0);
  17083. ExpectIntEQ(XMEMCMP(vector, dec2, AES_BLOCK_SIZE), 0);
  17084. /* Pass in bad args */
  17085. ExpectIntEQ(wc_AesCbcEncrypt(NULL, enc, vector, sizeof(vector)),
  17086. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17087. ExpectIntEQ(wc_AesCbcEncrypt(&aes, NULL, vector, sizeof(vector)),
  17088. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17089. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, NULL, sizeof(vector)),
  17090. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17091. #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
  17092. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, sizeof(vector) - 1),
  17093. WC_NO_ERR_TRACE(BAD_LENGTH_E));
  17094. #endif
  17095. #if defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  17096. (HAVE_FIPS_VERSION == 2) && defined(WOLFSSL_AESNI)
  17097. fprintf(stderr, "Zero length inputs not supported with AESNI in FIPS "
  17098. "mode (v2), skip test");
  17099. #else
  17100. /* Test passing in size of 0 */
  17101. XMEMSET(enc, 0, sizeof(enc));
  17102. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, 0), 0);
  17103. /* Check enc was not modified */
  17104. {
  17105. int i;
  17106. for (i = 0; i < (int)sizeof(enc); i++)
  17107. ExpectIntEQ(enc[i], 0);
  17108. }
  17109. #endif
  17110. ExpectIntEQ(wc_AesCbcDecrypt(NULL, dec, enc, AES_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17111. ExpectIntEQ(wc_AesCbcDecrypt(&aes, NULL, enc, AES_BLOCK_SIZE),
  17112. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17113. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, NULL, AES_BLOCK_SIZE),
  17114. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17115. #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
  17116. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, AES_BLOCK_SIZE * 2 - 1),
  17117. WC_NO_ERR_TRACE(BAD_LENGTH_E));
  17118. #else
  17119. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, AES_BLOCK_SIZE * 2 - 1),
  17120. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17121. #endif
  17122. /* Test passing in size of 0 */
  17123. XMEMSET(dec, 0, sizeof(dec));
  17124. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, 0), 0);
  17125. /* Check dec was not modified */
  17126. {
  17127. int i;
  17128. for (i = 0; i < (int)sizeof(dec); i++)
  17129. ExpectIntEQ(dec[i], 0);
  17130. }
  17131. ExpectIntEQ(wc_AesCbcDecryptWithKey(NULL, enc, AES_BLOCK_SIZE,
  17132. key32, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17133. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, NULL, AES_BLOCK_SIZE,
  17134. key32, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17135. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE,
  17136. NULL, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17137. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE,
  17138. key32, sizeof(key32)/sizeof(byte), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17139. wc_AesFree(&aes);
  17140. #endif
  17141. return EXPECT_RESULT();
  17142. } /* END test_wc_AesCbcEncryptDecrypt */
  17143. /*
  17144. * Testing wc_AesCtrEncrypt and wc_AesCtrDecrypt
  17145. */
  17146. static int test_wc_AesCtrEncryptDecrypt(void)
  17147. {
  17148. EXPECT_DECLS;
  17149. #if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_256)
  17150. Aes aesEnc;
  17151. Aes aesDec;
  17152. byte key32[] = {
  17153. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17154. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17155. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17156. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17157. };
  17158. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  17159. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  17160. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  17161. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  17162. };
  17163. byte iv[] = "1234567890abcdef";
  17164. byte enc[AES_BLOCK_SIZE * 2];
  17165. byte dec[AES_BLOCK_SIZE * 2];
  17166. /* Init stack variables. */
  17167. XMEMSET(&aesEnc, 0, sizeof(Aes));
  17168. XMEMSET(&aesDec, 0, sizeof(Aes));
  17169. XMEMSET(enc, 0, AES_BLOCK_SIZE * 2);
  17170. XMEMSET(dec, 0, AES_BLOCK_SIZE * 2);
  17171. ExpectIntEQ(wc_AesInit(&aesEnc, NULL, INVALID_DEVID), 0);
  17172. ExpectIntEQ(wc_AesInit(&aesDec, NULL, INVALID_DEVID), 0);
  17173. ExpectIntEQ(wc_AesSetKey(&aesEnc, key32, AES_BLOCK_SIZE * 2, iv,
  17174. AES_ENCRYPTION), 0);
  17175. ExpectIntEQ(wc_AesCtrEncrypt(&aesEnc, enc, vector,
  17176. sizeof(vector)/sizeof(byte)), 0);
  17177. /* Decrypt with wc_AesCtrEncrypt() */
  17178. ExpectIntEQ(wc_AesSetKey(&aesDec, key32, AES_BLOCK_SIZE * 2, iv,
  17179. AES_ENCRYPTION), 0);
  17180. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, dec, enc, sizeof(enc)/sizeof(byte)),
  17181. 0);
  17182. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  17183. /* Test bad args. */
  17184. ExpectIntEQ(wc_AesCtrEncrypt(NULL, dec, enc, sizeof(enc)/sizeof(byte)),
  17185. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17186. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, NULL, enc, sizeof(enc)/sizeof(byte)),
  17187. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17188. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, dec, NULL, sizeof(enc)/sizeof(byte)),
  17189. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17190. wc_AesFree(&aesEnc);
  17191. wc_AesFree(&aesDec);
  17192. #endif
  17193. return EXPECT_RESULT();
  17194. } /* END test_wc_AesCtrEncryptDecrypt */
  17195. /*
  17196. * test function for wc_AesGcmSetKey()
  17197. */
  17198. static int test_wc_AesGcmSetKey(void)
  17199. {
  17200. EXPECT_DECLS;
  17201. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  17202. Aes aes;
  17203. #ifdef WOLFSSL_AES_128
  17204. byte key16[] = {
  17205. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17206. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17207. };
  17208. #endif
  17209. #ifdef WOLFSSL_AES_192
  17210. byte key24[] = {
  17211. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17212. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17213. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17214. };
  17215. #endif
  17216. #ifdef WOLFSSL_AES_256
  17217. byte key32[] = {
  17218. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17219. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17220. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17221. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17222. };
  17223. #endif
  17224. byte badKey16[] = {
  17225. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17226. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  17227. };
  17228. byte badKey24[] = {
  17229. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17230. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17231. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36
  17232. };
  17233. byte badKey32[] = {
  17234. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x37, 0x37,
  17235. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17236. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17237. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  17238. };
  17239. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17240. #ifdef WOLFSSL_AES_128
  17241. ExpectIntEQ(wc_AesGcmSetKey(&aes, key16, sizeof(key16)/sizeof(byte)), 0);
  17242. #endif
  17243. #ifdef WOLFSSL_AES_192
  17244. ExpectIntEQ(wc_AesGcmSetKey(&aes, key24, sizeof(key24)/sizeof(byte)), 0);
  17245. #endif
  17246. #ifdef WOLFSSL_AES_256
  17247. ExpectIntEQ(wc_AesGcmSetKey(&aes, key32, sizeof(key32)/sizeof(byte)), 0);
  17248. #endif
  17249. /* Pass in bad args. */
  17250. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey16, sizeof(badKey16)/sizeof(byte)),
  17251. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17252. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey24, sizeof(badKey24)/sizeof(byte)),
  17253. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17254. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey32, sizeof(badKey32)/sizeof(byte)),
  17255. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17256. wc_AesFree(&aes);
  17257. #endif
  17258. return EXPECT_RESULT();
  17259. } /* END test_wc_AesGcmSetKey */
  17260. /*
  17261. * test function for wc_AesGcmEncrypt and wc_AesGcmDecrypt
  17262. */
  17263. static int test_wc_AesGcmEncryptDecrypt(void)
  17264. {
  17265. EXPECT_DECLS;
  17266. /* WOLFSSL_AFALG requires 12 byte IV */
  17267. #if !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AES_256) && \
  17268. !defined(WOLFSSL_AFALG) && !defined(WOLFSSL_DEVCRYPTO_AES)
  17269. Aes aes;
  17270. byte key32[] = {
  17271. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17272. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17273. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17274. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17275. };
  17276. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  17277. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  17278. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  17279. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  17280. };
  17281. const byte a[] = {
  17282. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17283. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17284. 0xab, 0xad, 0xda, 0xd2
  17285. };
  17286. byte iv[] = "1234567890a";
  17287. byte longIV[] = "1234567890abcdefghij";
  17288. byte enc[sizeof(vector)];
  17289. byte resultT[AES_BLOCK_SIZE];
  17290. byte dec[sizeof(vector)];
  17291. /* Init stack variables. */
  17292. XMEMSET(&aes, 0, sizeof(Aes));
  17293. XMEMSET(enc, 0, sizeof(vector));
  17294. XMEMSET(dec, 0, sizeof(vector));
  17295. XMEMSET(resultT, 0, AES_BLOCK_SIZE);
  17296. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17297. ExpectIntEQ(wc_AesGcmSetKey(&aes, key32, sizeof(key32)/sizeof(byte)), 0);
  17298. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  17299. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)), 0);
  17300. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(vector), iv,
  17301. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)), 0);
  17302. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  17303. /* Test bad args for wc_AesGcmEncrypt and wc_AesGcmDecrypt */
  17304. ExpectIntEQ(wc_AesGcmEncrypt(NULL, enc, vector, sizeof(vector), iv,
  17305. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17306. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17307. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  17308. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) + 1, a, sizeof(a)),
  17309. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17310. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  17311. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) - 5, a, sizeof(a)),
  17312. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17313. #if (defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  17314. (HAVE_FIPS_VERSION == 2)) || defined(HAVE_SELFTEST) || \
  17315. defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  17316. /* FIPS does not check the lower bound of ivSz */
  17317. #else
  17318. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv, 0,
  17319. resultT, sizeof(resultT), a, sizeof(a)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17320. #endif
  17321. /* This case is now considered good. Long IVs are now allowed.
  17322. * Except for the original FIPS release, it still has an upper
  17323. * bound on the IV length. */
  17324. #if (!defined(HAVE_FIPS) || \
  17325. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) && \
  17326. !defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  17327. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), longIV,
  17328. sizeof(longIV)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17329. 0);
  17330. #else
  17331. (void)longIV;
  17332. #endif /* Old FIPS */
  17333. /* END wc_AesGcmEncrypt */
  17334. #ifdef HAVE_AES_DECRYPT
  17335. ExpectIntEQ(wc_AesGcmDecrypt(NULL, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17336. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17337. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17338. ExpectIntEQ(wc_AesGcmDecrypt(&aes, NULL, enc, sizeof(enc)/sizeof(byte), iv,
  17339. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17340. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17341. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, NULL, sizeof(enc)/sizeof(byte), iv,
  17342. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17343. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17344. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), NULL,
  17345. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17346. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17347. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17348. sizeof(iv)/sizeof(byte), NULL, sizeof(resultT), a, sizeof(a)),
  17349. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17350. #if (defined(HAVE_FIPS) && FIPS_VERSION_LE(2,0) && defined(WOLFSSL_ARMASM))
  17351. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17352. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) + 1, a, sizeof(a)),
  17353. WC_NO_ERR_TRACE(AES_GCM_AUTH_E));
  17354. #else
  17355. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17356. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) + 1, a, sizeof(a)),
  17357. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17358. #endif
  17359. #if ((defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  17360. (HAVE_FIPS_VERSION == 2)) || defined(HAVE_SELFTEST)) && \
  17361. !defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  17362. /* FIPS does not check the lower bound of ivSz */
  17363. #else
  17364. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte),
  17365. iv, 0, resultT, sizeof(resultT), a, sizeof(a)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17366. #endif
  17367. #endif /* HAVE_AES_DECRYPT */
  17368. wc_AesFree(&aes);
  17369. #endif
  17370. return EXPECT_RESULT();
  17371. } /* END test_wc_AesGcmEncryptDecrypt */
  17372. /*
  17373. * test function for mixed (one-shot encrpytion + stream decryption) AES GCM
  17374. * using a long IV (older FIPS does NOT support long IVs). Relates to zd15423
  17375. */
  17376. static int test_wc_AesGcmMixedEncDecLongIV(void)
  17377. {
  17378. EXPECT_DECLS;
  17379. #if (!defined(HAVE_FIPS) || \
  17380. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) && \
  17381. !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AESGCM_STREAM)
  17382. const byte key[] = {
  17383. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17384. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17385. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17386. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17387. };
  17388. const byte in[] = {
  17389. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  17390. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  17391. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  17392. };
  17393. const byte aad[] = {
  17394. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17395. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17396. 0xab, 0xad, 0xda, 0xd2
  17397. };
  17398. Aes aesEnc;
  17399. Aes aesDec;
  17400. byte iv[] = "1234567890abcdefghij";
  17401. byte out[sizeof(in)];
  17402. byte plain[sizeof(in)];
  17403. byte tag[AES_BLOCK_SIZE];
  17404. XMEMSET(&aesEnc, 0, sizeof(Aes));
  17405. XMEMSET(&aesDec, 0, sizeof(Aes));
  17406. XMEMSET(out, 0, sizeof(out));
  17407. XMEMSET(plain, 0, sizeof(plain));
  17408. XMEMSET(tag, 0, sizeof(tag));
  17409. /* Perform one-shot encryption using long IV */
  17410. ExpectIntEQ(wc_AesInit(&aesEnc, NULL, INVALID_DEVID), 0);
  17411. ExpectIntEQ(wc_AesGcmSetKey(&aesEnc, key, sizeof(key)), 0);
  17412. ExpectIntEQ(wc_AesGcmEncrypt(&aesEnc, out, in, sizeof(in), iv, sizeof(iv),
  17413. tag, sizeof(tag), aad, sizeof(aad)), 0);
  17414. /* Perform streaming decryption using long IV */
  17415. ExpectIntEQ(wc_AesInit(&aesDec, NULL, INVALID_DEVID), 0);
  17416. ExpectIntEQ(wc_AesGcmInit(&aesDec, key, sizeof(key), iv, sizeof(iv)), 0);
  17417. ExpectIntEQ(wc_AesGcmDecryptUpdate(&aesDec, plain, out, sizeof(out), aad,
  17418. sizeof(aad)), 0);
  17419. ExpectIntEQ(wc_AesGcmDecryptFinal(&aesDec, tag, sizeof(tag)), 0);
  17420. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  17421. /* Free resources */
  17422. wc_AesFree(&aesEnc);
  17423. wc_AesFree(&aesDec);
  17424. #endif
  17425. return EXPECT_RESULT();
  17426. } /* END wc_AesGcmMixedEncDecLongIV */
  17427. /*
  17428. * unit test for wc_GmacSetKey()
  17429. */
  17430. static int test_wc_GmacSetKey(void)
  17431. {
  17432. EXPECT_DECLS;
  17433. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  17434. Gmac gmac;
  17435. byte key16[] = {
  17436. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17437. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17438. };
  17439. #ifdef WOLFSSL_AES_192
  17440. byte key24[] = {
  17441. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17442. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17443. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17444. };
  17445. #endif
  17446. #ifdef WOLFSSL_AES_256
  17447. byte key32[] = {
  17448. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17449. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17450. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17451. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17452. };
  17453. #endif
  17454. byte badKey16[] = {
  17455. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17456. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x66
  17457. };
  17458. byte badKey24[] = {
  17459. 0x30, 0x31, 0x32, 0x33, 0x34, 0x36, 0x37,
  17460. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17461. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17462. };
  17463. byte badKey32[] = {
  17464. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17465. 0x38, 0x39, 0x61, 0x62, 0x64, 0x65, 0x66,
  17466. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17467. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17468. };
  17469. XMEMSET(&gmac, 0, sizeof(Gmac));
  17470. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17471. #ifdef WOLFSSL_AES_128
  17472. ExpectIntEQ(wc_GmacSetKey(&gmac, key16, sizeof(key16)/sizeof(byte)), 0);
  17473. #endif
  17474. #ifdef WOLFSSL_AES_192
  17475. ExpectIntEQ(wc_GmacSetKey(&gmac, key24, sizeof(key24)/sizeof(byte)), 0);
  17476. #endif
  17477. #ifdef WOLFSSL_AES_256
  17478. ExpectIntEQ(wc_GmacSetKey(&gmac, key32, sizeof(key32)/sizeof(byte)), 0);
  17479. #endif
  17480. /* Pass in bad args. */
  17481. ExpectIntEQ(wc_GmacSetKey(NULL, key16, sizeof(key16)/sizeof(byte)),
  17482. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17483. ExpectIntEQ(wc_GmacSetKey(&gmac, NULL, sizeof(key16)/sizeof(byte)),
  17484. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17485. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey16, sizeof(badKey16)/sizeof(byte)),
  17486. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17487. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey24, sizeof(badKey24)/sizeof(byte)),
  17488. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17489. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey32, sizeof(badKey32)/sizeof(byte)),
  17490. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17491. wc_AesFree(&gmac.aes);
  17492. #endif
  17493. return EXPECT_RESULT();
  17494. } /* END test_wc_GmacSetKey */
  17495. /*
  17496. * unit test for wc_GmacUpdate
  17497. */
  17498. static int test_wc_GmacUpdate(void)
  17499. {
  17500. EXPECT_DECLS;
  17501. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  17502. Gmac gmac;
  17503. #ifdef WOLFSSL_AES_128
  17504. const byte key16[] = {
  17505. 0x89, 0xc9, 0x49, 0xe9, 0xc8, 0x04, 0xaf, 0x01,
  17506. 0x4d, 0x56, 0x04, 0xb3, 0x94, 0x59, 0xf2, 0xc8
  17507. };
  17508. #endif
  17509. #ifdef WOLFSSL_AES_192
  17510. byte key24[] = {
  17511. 0x41, 0xc5, 0xda, 0x86, 0x67, 0xef, 0x72, 0x52,
  17512. 0x20, 0xff, 0xe3, 0x9a, 0xe0, 0xac, 0x59, 0x0a,
  17513. 0xc9, 0xfc, 0xa7, 0x29, 0xab, 0x60, 0xad, 0xa0
  17514. };
  17515. #endif
  17516. #ifdef WOLFSSL_AES_256
  17517. byte key32[] = {
  17518. 0x78, 0xdc, 0x4e, 0x0a, 0xaf, 0x52, 0xd9, 0x35,
  17519. 0xc3, 0xc0, 0x1e, 0xea, 0x57, 0x42, 0x8f, 0x00,
  17520. 0xca, 0x1f, 0xd4, 0x75, 0xf5, 0xda, 0x86, 0xa4,
  17521. 0x9c, 0x8d, 0xd7, 0x3d, 0x68, 0xc8, 0xe2, 0x23
  17522. };
  17523. #endif
  17524. #ifdef WOLFSSL_AES_128
  17525. const byte authIn[] = {
  17526. 0x82, 0xad, 0xcd, 0x63, 0x8d, 0x3f, 0xa9, 0xd9,
  17527. 0xf3, 0xe8, 0x41, 0x00, 0xd6, 0x1e, 0x07, 0x77
  17528. };
  17529. #endif
  17530. #ifdef WOLFSSL_AES_192
  17531. const byte authIn2[] = {
  17532. 0x8b, 0x5c, 0x12, 0x4b, 0xef, 0x6e, 0x2f, 0x0f,
  17533. 0xe4, 0xd8, 0xc9, 0x5c, 0xd5, 0xfa, 0x4c, 0xf1
  17534. };
  17535. #endif
  17536. const byte authIn3[] = {
  17537. 0xb9, 0x6b, 0xaa, 0x8c, 0x1c, 0x75, 0xa6, 0x71,
  17538. 0xbf, 0xb2, 0xd0, 0x8d, 0x06, 0xbe, 0x5f, 0x36
  17539. };
  17540. #ifdef WOLFSSL_AES_128
  17541. const byte tag1[] = { /* Known. */
  17542. 0x88, 0xdb, 0x9d, 0x62, 0x17, 0x2e, 0xd0, 0x43,
  17543. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  17544. };
  17545. #endif
  17546. #ifdef WOLFSSL_AES_192
  17547. const byte tag2[] = { /* Known */
  17548. 0x20, 0x4b, 0xdb, 0x1b, 0xd6, 0x21, 0x54, 0xbf,
  17549. 0x08, 0x92, 0x2a, 0xaa, 0x54, 0xee, 0xd7, 0x05
  17550. };
  17551. #endif
  17552. const byte tag3[] = { /* Known */
  17553. 0x3e, 0x5d, 0x48, 0x6a, 0xa2, 0xe3, 0x0b, 0x22,
  17554. 0xe0, 0x40, 0xb8, 0x57, 0x23, 0xa0, 0x6e, 0x76
  17555. };
  17556. #ifdef WOLFSSL_AES_128
  17557. const byte iv[] = {
  17558. 0xd1, 0xb1, 0x04, 0xc8, 0x15, 0xbf, 0x1e, 0x94,
  17559. 0xe2, 0x8c, 0x8f, 0x16
  17560. };
  17561. #endif
  17562. #ifdef WOLFSSL_AES_192
  17563. const byte iv2[] = {
  17564. 0x05, 0xad, 0x13, 0xa5, 0xe2, 0xc2, 0xab, 0x66,
  17565. 0x7e, 0x1a, 0x6f, 0xbc
  17566. };
  17567. #endif
  17568. const byte iv3[] = {
  17569. 0xd7, 0x9c, 0xf2, 0x2d, 0x50, 0x4c, 0xc7, 0x93,
  17570. 0xc3, 0xfb, 0x6c, 0x8a
  17571. };
  17572. byte tagOut[16];
  17573. byte tagOut2[24];
  17574. byte tagOut3[32];
  17575. /* Init stack variables. */
  17576. XMEMSET(&gmac, 0, sizeof(Gmac));
  17577. XMEMSET(tagOut, 0, sizeof(tagOut));
  17578. XMEMSET(tagOut2, 0, sizeof(tagOut2));
  17579. XMEMSET(tagOut3, 0, sizeof(tagOut3));
  17580. #ifdef WOLFSSL_AES_128
  17581. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17582. ExpectIntEQ(wc_GmacSetKey(&gmac, key16, sizeof(key16)), 0);
  17583. ExpectIntEQ(wc_GmacUpdate(&gmac, iv, sizeof(iv), authIn, sizeof(authIn),
  17584. tagOut, sizeof(tag1)), 0);
  17585. ExpectIntEQ(XMEMCMP(tag1, tagOut, sizeof(tag1)), 0);
  17586. wc_AesFree(&gmac.aes);
  17587. #endif
  17588. #ifdef WOLFSSL_AES_192
  17589. ExpectNotNull(XMEMSET(&gmac, 0, sizeof(Gmac)));
  17590. ExpectIntEQ(wc_AesInit(&gmac.aes, HEAP_HINT, INVALID_DEVID), 0);
  17591. ExpectIntEQ(wc_GmacSetKey(&gmac, key24, sizeof(key24)/sizeof(byte)), 0);
  17592. ExpectIntEQ(wc_GmacUpdate(&gmac, iv2, sizeof(iv2), authIn2, sizeof(authIn2),
  17593. tagOut2, sizeof(tag2)), 0);
  17594. ExpectIntEQ(XMEMCMP(tagOut2, tag2, sizeof(tag2)), 0);
  17595. wc_AesFree(&gmac.aes);
  17596. #endif
  17597. #ifdef WOLFSSL_AES_256
  17598. ExpectNotNull(XMEMSET(&gmac, 0, sizeof(Gmac)));
  17599. ExpectIntEQ(wc_AesInit(&gmac.aes, HEAP_HINT, INVALID_DEVID), 0);
  17600. ExpectIntEQ(wc_GmacSetKey(&gmac, key32, sizeof(key32)/sizeof(byte)), 0);
  17601. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17602. tagOut3, sizeof(tag3)), 0);
  17603. ExpectIntEQ(XMEMCMP(tag3, tagOut3, sizeof(tag3)), 0);
  17604. wc_AesFree(&gmac.aes);
  17605. #endif
  17606. /* Pass bad args. */
  17607. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17608. ExpectIntEQ(wc_GmacUpdate(NULL, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17609. tagOut3, sizeof(tag3)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17610. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17611. tagOut3, sizeof(tag3) - 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17612. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17613. tagOut3, sizeof(tag3) + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17614. wc_AesFree(&gmac.aes);
  17615. #endif
  17616. return EXPECT_RESULT();
  17617. } /* END test_wc_GmacUpdate */
  17618. /*
  17619. * testing wc_CamelliaSetKey
  17620. */
  17621. static int test_wc_CamelliaSetKey(void)
  17622. {
  17623. EXPECT_DECLS;
  17624. #ifdef HAVE_CAMELLIA
  17625. Camellia camellia;
  17626. /*128-bit key*/
  17627. static const byte key16[] = {
  17628. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17629. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  17630. };
  17631. /* 192-bit key */
  17632. static const byte key24[] = {
  17633. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17634. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17635. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17636. };
  17637. /* 256-bit key */
  17638. static const byte key32[] = {
  17639. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17640. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17641. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  17642. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
  17643. };
  17644. static const byte iv[] = {
  17645. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17646. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17647. };
  17648. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key16, (word32)sizeof(key16), iv),
  17649. 0);
  17650. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key16, (word32)sizeof(key16),
  17651. NULL), 0);
  17652. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24), iv),
  17653. 0);
  17654. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17655. NULL), 0);
  17656. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key32, (word32)sizeof(key32), iv),
  17657. 0);
  17658. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key32, (word32)sizeof(key32),
  17659. NULL), 0);
  17660. /* Bad args. */
  17661. ExpectIntEQ(wc_CamelliaSetKey(NULL, key32, (word32)sizeof(key32), iv),
  17662. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17663. #endif
  17664. return EXPECT_RESULT();
  17665. } /* END test_wc_CammeliaSetKey */
  17666. /*
  17667. * Testing wc_CamelliaSetIV()
  17668. */
  17669. static int test_wc_CamelliaSetIV(void)
  17670. {
  17671. EXPECT_DECLS;
  17672. #ifdef HAVE_CAMELLIA
  17673. Camellia camellia;
  17674. static const byte iv[] = {
  17675. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17676. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17677. };
  17678. ExpectIntEQ(wc_CamelliaSetIV(&camellia, iv), 0);
  17679. ExpectIntEQ(wc_CamelliaSetIV(&camellia, NULL), 0);
  17680. /* Bad args. */
  17681. ExpectIntEQ(wc_CamelliaSetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17682. ExpectIntEQ(wc_CamelliaSetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17683. #endif
  17684. return EXPECT_RESULT();
  17685. } /* END test_wc_CamelliaSetIV*/
  17686. /*
  17687. * Test wc_CamelliaEncryptDirect and wc_CamelliaDecryptDirect
  17688. */
  17689. static int test_wc_CamelliaEncryptDecryptDirect(void)
  17690. {
  17691. EXPECT_DECLS;
  17692. #ifdef HAVE_CAMELLIA
  17693. Camellia camellia;
  17694. static const byte key24[] = {
  17695. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17696. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17697. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17698. };
  17699. static const byte iv[] = {
  17700. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17701. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17702. };
  17703. static const byte plainT[] = {
  17704. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  17705. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  17706. };
  17707. byte enc[sizeof(plainT)];
  17708. byte dec[sizeof(enc)];
  17709. /* Init stack variables.*/
  17710. XMEMSET(enc, 0, 16);
  17711. XMEMSET(enc, 0, 16);
  17712. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24), iv),
  17713. 0);
  17714. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, enc, plainT), 0);
  17715. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, dec, enc), 0);
  17716. ExpectIntEQ(XMEMCMP(plainT, dec, CAMELLIA_BLOCK_SIZE), 0);
  17717. /* Pass bad args. */
  17718. ExpectIntEQ(wc_CamelliaEncryptDirect(NULL, enc, plainT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17719. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, NULL, plainT),
  17720. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17721. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, enc, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17722. ExpectIntEQ(wc_CamelliaDecryptDirect(NULL, dec, enc), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17723. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, NULL, enc), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17724. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, dec, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17725. #endif
  17726. return EXPECT_RESULT();
  17727. } /* END test-wc_CamelliaEncryptDecryptDirect */
  17728. /*
  17729. * Testing wc_CamelliaCbcEncrypt and wc_CamelliaCbcDecrypt
  17730. */
  17731. static int test_wc_CamelliaCbcEncryptDecrypt(void)
  17732. {
  17733. EXPECT_DECLS;
  17734. #ifdef HAVE_CAMELLIA
  17735. Camellia camellia;
  17736. static const byte key24[] = {
  17737. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17738. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17739. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17740. };
  17741. static const byte plainT[] = {
  17742. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  17743. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  17744. };
  17745. byte enc[CAMELLIA_BLOCK_SIZE];
  17746. byte dec[CAMELLIA_BLOCK_SIZE];
  17747. /* Init stack variables. */
  17748. XMEMSET(enc, 0, CAMELLIA_BLOCK_SIZE);
  17749. XMEMSET(enc, 0, CAMELLIA_BLOCK_SIZE);
  17750. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17751. NULL), 0);
  17752. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, enc, plainT,
  17753. CAMELLIA_BLOCK_SIZE), 0);
  17754. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17755. NULL), 0);
  17756. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, dec, enc, CAMELLIA_BLOCK_SIZE),
  17757. 0);
  17758. ExpectIntEQ(XMEMCMP(plainT, dec, CAMELLIA_BLOCK_SIZE), 0);
  17759. /* Pass in bad args. */
  17760. ExpectIntEQ(wc_CamelliaCbcEncrypt(NULL, enc, plainT, CAMELLIA_BLOCK_SIZE),
  17761. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17762. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, NULL, plainT,
  17763. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17764. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, enc, NULL,
  17765. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17766. ExpectIntEQ(wc_CamelliaCbcDecrypt(NULL, dec, enc, CAMELLIA_BLOCK_SIZE),
  17767. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17768. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, NULL, enc,
  17769. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17770. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, dec, NULL,
  17771. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17772. #endif
  17773. return EXPECT_RESULT();
  17774. } /* END test_wc_CamelliaCbcEncryptDecrypt */
  17775. /*
  17776. * Testing wc_Arc4SetKey()
  17777. */
  17778. static int test_wc_Arc4SetKey(void)
  17779. {
  17780. EXPECT_DECLS;
  17781. #ifndef NO_RC4
  17782. Arc4 arc;
  17783. const char* key = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17784. int keyLen = 8;
  17785. ExpectIntEQ(wc_Arc4SetKey(&arc, (byte*)key, (word32)keyLen), 0);
  17786. /* Test bad args. */
  17787. ExpectIntEQ(wc_Arc4SetKey(NULL, (byte*)key, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17788. ExpectIntEQ(wc_Arc4SetKey(&arc, NULL , (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17789. ExpectIntEQ(wc_Arc4SetKey(&arc, (byte*)key, 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17790. #endif
  17791. return EXPECT_RESULT();
  17792. } /* END test_wc_Arc4SetKey */
  17793. /*
  17794. * Testing wc_Arc4Process for ENC/DEC.
  17795. */
  17796. static int test_wc_Arc4Process(void)
  17797. {
  17798. EXPECT_DECLS;
  17799. #ifndef NO_RC4
  17800. Arc4 enc;
  17801. Arc4 dec;
  17802. const char* key = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17803. int keyLen = 8;
  17804. const char* input = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17805. byte cipher[8];
  17806. byte plain[8];
  17807. /* Init stack variables */
  17808. XMEMSET(&enc, 0, sizeof(Arc4));
  17809. XMEMSET(&dec, 0, sizeof(Arc4));
  17810. XMEMSET(cipher, 0, sizeof(cipher));
  17811. XMEMSET(plain, 0, sizeof(plain));
  17812. /* Use for async. */
  17813. ExpectIntEQ(wc_Arc4Init(&enc, NULL, INVALID_DEVID), 0);
  17814. ExpectIntEQ(wc_Arc4Init(&dec, NULL, INVALID_DEVID), 0);
  17815. ExpectIntEQ(wc_Arc4SetKey(&enc, (byte*)key, (word32)keyLen), 0);
  17816. ExpectIntEQ(wc_Arc4SetKey(&dec, (byte*)key, (word32)keyLen), 0);
  17817. ExpectIntEQ(wc_Arc4Process(&enc, cipher, (byte*)input, (word32)keyLen), 0);
  17818. ExpectIntEQ(wc_Arc4Process(&dec, plain, cipher, (word32)keyLen), 0);
  17819. ExpectIntEQ(XMEMCMP(plain, input, keyLen), 0);
  17820. /* Bad args. */
  17821. ExpectIntEQ(wc_Arc4Process(NULL, plain, cipher, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17822. ExpectIntEQ(wc_Arc4Process(&dec, NULL, cipher, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17823. ExpectIntEQ(wc_Arc4Process(&dec, plain, NULL, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17824. wc_Arc4Free(&enc);
  17825. wc_Arc4Free(&dec);
  17826. #endif
  17827. return EXPECT_RESULT();
  17828. } /* END test_wc_Arc4Process */
  17829. /*
  17830. * Testing wc_Init RsaKey()
  17831. */
  17832. static int test_wc_InitRsaKey(void)
  17833. {
  17834. EXPECT_DECLS;
  17835. #ifndef NO_RSA
  17836. RsaKey key;
  17837. XMEMSET(&key, 0, sizeof(RsaKey));
  17838. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17839. /* Test bad args. */
  17840. ExpectIntEQ(wc_InitRsaKey(NULL, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17841. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17842. #endif
  17843. return EXPECT_RESULT();
  17844. } /* END test_wc_InitRsaKey */
  17845. /*
  17846. * Testing wc_RsaPrivateKeyDecode()
  17847. */
  17848. static int test_wc_RsaPrivateKeyDecode(void)
  17849. {
  17850. EXPECT_DECLS;
  17851. #if !defined(NO_RSA) && (defined(USE_CERT_BUFFERS_1024)\
  17852. || defined(USE_CERT_BUFFERS_2048)) && !defined(HAVE_FIPS)
  17853. RsaKey key;
  17854. byte* tmp = NULL;
  17855. word32 idx = 0;
  17856. int bytes = 0;
  17857. XMEMSET(&key, 0, sizeof(RsaKey));
  17858. ExpectNotNull(tmp = (byte*)XMALLOC(FOURK_BUF, NULL,
  17859. DYNAMIC_TYPE_TMP_BUFFER));
  17860. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17861. if (tmp != NULL) {
  17862. #ifdef USE_CERT_BUFFERS_1024
  17863. XMEMCPY(tmp, client_key_der_1024, sizeof_client_key_der_1024);
  17864. bytes = sizeof_client_key_der_1024;
  17865. #else
  17866. XMEMCPY(tmp, client_key_der_2048, sizeof_client_key_der_2048);
  17867. bytes = sizeof_client_key_der_2048;
  17868. #endif /* Use cert buffers. */
  17869. }
  17870. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, &key, (word32)bytes), 0);
  17871. /* Test bad args. */
  17872. ExpectIntEQ(wc_RsaPrivateKeyDecode(NULL, &idx, &key, (word32)bytes),
  17873. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17874. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, NULL, &key, (word32)bytes),
  17875. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17876. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, NULL, (word32)bytes),
  17877. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17878. XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  17879. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17880. #endif
  17881. return EXPECT_RESULT();
  17882. } /* END test_wc_RsaPrivateKeyDecode */
  17883. /*
  17884. * Testing wc_RsaPublicKeyDecode()
  17885. */
  17886. static int test_wc_RsaPublicKeyDecode(void)
  17887. {
  17888. EXPECT_DECLS;
  17889. #if !defined(NO_RSA) && (defined(USE_CERT_BUFFERS_1024)\
  17890. || defined(USE_CERT_BUFFERS_2048)) && !defined(HAVE_FIPS)
  17891. RsaKey keyPub;
  17892. byte* tmp = NULL;
  17893. word32 idx = 0;
  17894. int bytes = 0;
  17895. word32 keySz = 0;
  17896. word32 tstKeySz = 0;
  17897. #if defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM)
  17898. XFILE f = XBADFILE;
  17899. const char* rsaPssPubKey = "./certs/rsapss/ca-rsapss-key.der";
  17900. const char* rsaPssPubKeyNoParams = "./certs/rsapss/ca-3072-rsapss-key.der";
  17901. byte buf[4096];
  17902. #endif
  17903. XMEMSET(&keyPub, 0, sizeof(RsaKey));
  17904. ExpectNotNull(tmp = (byte*)XMALLOC(GEN_BUF, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  17905. ExpectIntEQ(wc_InitRsaKey(&keyPub, HEAP_HINT), 0);
  17906. if (tmp != NULL) {
  17907. #ifdef USE_CERT_BUFFERS_1024
  17908. XMEMCPY(tmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  17909. bytes = sizeof_client_keypub_der_1024;
  17910. keySz = 1024;
  17911. #else
  17912. XMEMCPY(tmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  17913. bytes = sizeof_client_keypub_der_2048;
  17914. keySz = 2048;
  17915. #endif
  17916. }
  17917. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, &idx, &keyPub, (word32)bytes), 0);
  17918. /* Pass in bad args. */
  17919. ExpectIntEQ(wc_RsaPublicKeyDecode(NULL, &idx, &keyPub, (word32)bytes),
  17920. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17921. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, NULL, &keyPub, (word32)bytes),
  17922. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17923. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, &idx, NULL, (word32)bytes),
  17924. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17925. DoExpectIntEQ(wc_FreeRsaKey(&keyPub), 0);
  17926. /* Test for getting modulus key size */
  17927. idx = 0;
  17928. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(tmp, &idx, (word32)bytes, NULL,
  17929. &tstKeySz, NULL, NULL), 0);
  17930. ExpectIntEQ(tstKeySz, keySz/8);
  17931. #if defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM)
  17932. ExpectTrue((f = XFOPEN(rsaPssPubKey, "rb")) != XBADFILE);
  17933. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  17934. if (f != XBADFILE) {
  17935. XFCLOSE(f);
  17936. f = XBADFILE;
  17937. }
  17938. idx = 0;
  17939. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(buf, &idx, (word32)bytes, NULL, NULL, NULL,
  17940. NULL), 0);
  17941. ExpectTrue((f = XFOPEN(rsaPssPubKeyNoParams, "rb")) != XBADFILE);
  17942. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  17943. if (f != XBADFILE)
  17944. XFCLOSE(f);
  17945. idx = 0;
  17946. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(buf, &idx, (word32)bytes, NULL, NULL, NULL,
  17947. NULL), 0);
  17948. #endif
  17949. XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  17950. #endif
  17951. return EXPECT_RESULT();
  17952. } /* END test_wc_RsaPublicKeyDecode */
  17953. /*
  17954. * Testing wc_RsaPublicKeyDecodeRaw()
  17955. */
  17956. static int test_wc_RsaPublicKeyDecodeRaw(void)
  17957. {
  17958. EXPECT_DECLS;
  17959. #if !defined(NO_RSA)
  17960. RsaKey key;
  17961. const byte n = 0x23;
  17962. const byte e = 0x03;
  17963. word32 nSz = sizeof(n);
  17964. word32 eSz = sizeof(e);
  17965. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17966. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, &e, eSz, &key), 0);
  17967. /* Pass in bad args. */
  17968. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(NULL, nSz, &e, eSz, &key),
  17969. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17970. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, NULL, eSz, &key),
  17971. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17972. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, &e, eSz, NULL),
  17973. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17974. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17975. #endif
  17976. return EXPECT_RESULT();
  17977. } /* END test_wc_RsaPublicKeyDecodeRaw */
  17978. /*
  17979. * Testing wc_RsaPrivateKeyDecodeRaw()
  17980. */
  17981. static int test_wc_RsaPrivateKeyDecodeRaw(void)
  17982. {
  17983. EXPECT_DECLS;
  17984. #if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) \
  17985. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  17986. RsaKey key;
  17987. const byte n = 33;
  17988. const byte e = 3;
  17989. const byte d = 7;
  17990. const byte u = 2;
  17991. const byte p = 3;
  17992. const byte q = 11;
  17993. const byte dp = 1;
  17994. const byte dq = 7;
  17995. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17996. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17997. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17998. &p, sizeof(p), &q, sizeof(q), NULL, 0,
  17999. NULL, 0, &key), 0);
  18000. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18001. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18002. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18003. NULL, 0, &key), 0);
  18004. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18005. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18006. &p, sizeof(p), &q, sizeof(q), NULL, 0,
  18007. &dq, sizeof(dq), &key), 0);
  18008. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18009. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18010. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18011. &dq, sizeof(dq), &key), 0);
  18012. /* Pass in bad args. */
  18013. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(NULL, sizeof(n),
  18014. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18015. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18016. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18017. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, 0,
  18018. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18019. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18020. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18021. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18022. NULL, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18023. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18024. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18025. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18026. &e, 0, &d, sizeof(d), &u, sizeof(u),
  18027. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18028. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18029. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18030. &e, sizeof(e), NULL, sizeof(d), &u, sizeof(u),
  18031. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18032. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18033. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18034. &e, sizeof(e), &d, 0, &u, sizeof(u),
  18035. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18036. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18037. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18038. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18039. NULL, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18040. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18041. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18042. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18043. &p, 0, &q, sizeof(q), &dp, sizeof(dp),
  18044. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18045. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18046. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18047. &p, sizeof(p), NULL, sizeof(q), &dp, sizeof(dp),
  18048. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18049. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18050. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18051. &p, sizeof(p), &q, 0, &dp, sizeof(dp),
  18052. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18053. #if defined(WOLFSSL_KEY_GEN) || defined(OPENSSL_EXTRA) || !defined(RSA_LOW_MEM)
  18054. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18055. &e, sizeof(e), &d, sizeof(d), &u, 0,
  18056. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18057. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18058. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18059. &e, sizeof(e), &d, sizeof(d), NULL, sizeof(u),
  18060. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18061. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18062. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18063. &e, sizeof(e), &d, sizeof(d), &u, 0,
  18064. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18065. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18066. #endif
  18067. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18068. #endif
  18069. return EXPECT_RESULT();
  18070. } /* END test_wc_RsaPrivateKeyDecodeRaw */
  18071. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18072. /* In FIPS builds, wc_MakeRsaKey() will return an error if it cannot find
  18073. * a probable prime in 5*(modLen/2) attempts. In non-FIPS builds, it keeps
  18074. * trying until it gets a probable prime. */
  18075. #ifdef HAVE_FIPS
  18076. static int MakeRsaKeyRetry(RsaKey* key, int size, long e, WC_RNG* rng)
  18077. {
  18078. int ret;
  18079. for (;;) {
  18080. ret = wc_MakeRsaKey(key, size, e, rng);
  18081. if (ret != WC_NO_ERR_TRACE(PRIME_GEN_E)) break;
  18082. fprintf(stderr, "MakeRsaKey couldn't find prime; "
  18083. "trying again.\n");
  18084. }
  18085. return ret;
  18086. }
  18087. #define MAKE_RSA_KEY(a, b, c, d) MakeRsaKeyRetry(a, b, c, d)
  18088. #else
  18089. #define MAKE_RSA_KEY(a, b, c, d) wc_MakeRsaKey(a, b, c, d)
  18090. #endif
  18091. #endif
  18092. /*
  18093. * Testing wc_MakeRsaKey()
  18094. */
  18095. static int test_wc_MakeRsaKey(void)
  18096. {
  18097. EXPECT_DECLS;
  18098. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18099. RsaKey genKey;
  18100. WC_RNG rng;
  18101. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18102. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18103. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18104. int bits = 1024;
  18105. #else
  18106. int bits = 2048;
  18107. #endif
  18108. XMEMSET(&genKey, 0, sizeof(RsaKey));
  18109. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18110. ExpectIntEQ(wc_InitRsaKey(&genKey, HEAP_HINT), 0);
  18111. ExpectIntEQ(wc_InitRng(&rng), 0);
  18112. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, &rng), 0);
  18113. DoExpectIntEQ(wc_FreeRsaKey(&genKey), 0);
  18114. /* Test bad args. */
  18115. ExpectIntEQ(MAKE_RSA_KEY(NULL, bits, WC_RSA_EXPONENT, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18116. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, NULL),
  18117. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18118. /* e < 3 */
  18119. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, 2, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18120. /* e & 1 == 0 */
  18121. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, 6, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18122. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18123. #endif
  18124. return EXPECT_RESULT();
  18125. } /* END test_wc_MakeRsaKey */
  18126. /*
  18127. * Test the bounds checking on the cipher text versus the key modulus.
  18128. * 1. Make a new RSA key.
  18129. * 2. Set c to 1.
  18130. * 3. Decrypt c into k. (error)
  18131. * 4. Copy the key modulus to c and sub 1 from the copy.
  18132. * 5. Decrypt c into k. (error)
  18133. * Valid bounds test cases are covered by all the other RSA tests.
  18134. */
  18135. static int test_RsaDecryptBoundsCheck(void)
  18136. {
  18137. EXPECT_DECLS;
  18138. #if !defined(NO_RSA) && defined(WC_RSA_NO_PADDING) && \
  18139. (defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048)) && \
  18140. defined(WOLFSSL_PUBLIC_MP) && !defined(NO_RSA_BOUNDS_CHECK)
  18141. WC_RNG rng;
  18142. RsaKey key;
  18143. byte flatC[256];
  18144. word32 flatCSz;
  18145. byte out[256];
  18146. word32 outSz = sizeof(out);
  18147. XMEMSET(&key, 0, sizeof(RsaKey));
  18148. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18149. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18150. ExpectIntEQ(wc_InitRng(&rng), 0);
  18151. if (EXPECT_SUCCESS()) {
  18152. const byte* derKey;
  18153. word32 derKeySz;
  18154. word32 idx = 0;
  18155. #ifdef USE_CERT_BUFFERS_1024
  18156. derKey = server_key_der_1024;
  18157. derKeySz = (word32)sizeof_server_key_der_1024;
  18158. flatCSz = 128;
  18159. #else
  18160. derKey = server_key_der_2048;
  18161. derKeySz = (word32)sizeof_server_key_der_2048;
  18162. flatCSz = 256;
  18163. #endif
  18164. ExpectIntEQ(wc_RsaPrivateKeyDecode(derKey, &idx, &key, derKeySz), 0);
  18165. }
  18166. if (EXPECT_SUCCESS()) {
  18167. XMEMSET(flatC, 0, flatCSz);
  18168. flatC[flatCSz-1] = 1;
  18169. ExpectIntEQ(wc_RsaDirect(flatC, flatCSz, out, &outSz, &key,
  18170. RSA_PRIVATE_DECRYPT, &rng), WC_NO_ERR_TRACE(RSA_OUT_OF_RANGE_E));
  18171. if (EXPECT_SUCCESS()) {
  18172. mp_int c;
  18173. ExpectIntEQ(mp_init_copy(&c, &key.n), 0);
  18174. ExpectIntEQ(mp_sub_d(&c, 1, &c), 0);
  18175. ExpectIntEQ(mp_to_unsigned_bin(&c, flatC), 0);
  18176. ExpectIntEQ(wc_RsaDirect(flatC, flatCSz, out, &outSz, &key,
  18177. RSA_PRIVATE_DECRYPT, NULL), WC_NO_ERR_TRACE(RSA_OUT_OF_RANGE_E));
  18178. mp_clear(&c);
  18179. }
  18180. }
  18181. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18182. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18183. #endif
  18184. return EXPECT_RESULT();
  18185. } /* END test_wc_RsaDecryptBoundsCheck */
  18186. /*
  18187. * Testing wc_SetKeyUsage()
  18188. */
  18189. static int test_wc_SetKeyUsage(void)
  18190. {
  18191. EXPECT_DECLS;
  18192. #if !defined(NO_RSA) && defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN) && !defined(HAVE_FIPS)
  18193. Cert myCert;
  18194. ExpectIntEQ(wc_InitCert(&myCert), 0);
  18195. ExpectIntEQ(wc_SetKeyUsage(&myCert, "keyEncipherment,keyAgreement"), 0);
  18196. ExpectIntEQ(wc_SetKeyUsage(&myCert, "digitalSignature,nonRepudiation"), 0);
  18197. ExpectIntEQ(wc_SetKeyUsage(&myCert, "contentCommitment,encipherOnly"), 0);
  18198. ExpectIntEQ(wc_SetKeyUsage(&myCert, "decipherOnly"), 0);
  18199. ExpectIntEQ(wc_SetKeyUsage(&myCert, "cRLSign,keyCertSign"), 0);
  18200. /* Test bad args. */
  18201. ExpectIntEQ(wc_SetKeyUsage(NULL, "decipherOnly"), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18202. ExpectIntEQ(wc_SetKeyUsage(&myCert, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18203. ExpectIntEQ(wc_SetKeyUsage(&myCert, ""), WC_NO_ERR_TRACE(KEYUSAGE_E));
  18204. ExpectIntEQ(wc_SetKeyUsage(&myCert, ","), WC_NO_ERR_TRACE(KEYUSAGE_E));
  18205. ExpectIntEQ(wc_SetKeyUsage(&myCert, "digitalSignature, cRLSign"),
  18206. WC_NO_ERR_TRACE(KEYUSAGE_E));
  18207. #endif
  18208. return EXPECT_RESULT();
  18209. } /* END test_wc_SetKeyUsage */
  18210. /*
  18211. * Testing wc_CheckProbablePrime()
  18212. */
  18213. static int test_wc_CheckProbablePrime(void)
  18214. {
  18215. EXPECT_DECLS;
  18216. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18217. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING)
  18218. #define CHECK_PROBABLE_PRIME_KEY_BITS 2048
  18219. RsaKey key;
  18220. WC_RNG rng;
  18221. byte e[3];
  18222. word32 eSz = (word32)sizeof(e);
  18223. byte n[CHECK_PROBABLE_PRIME_KEY_BITS / 8];
  18224. word32 nSz = (word32)sizeof(n);
  18225. byte d[CHECK_PROBABLE_PRIME_KEY_BITS / 8];
  18226. word32 dSz = (word32)sizeof(d);
  18227. byte p[CHECK_PROBABLE_PRIME_KEY_BITS / 8 / 2];
  18228. word32 pSz = (word32)sizeof(p);
  18229. byte q[CHECK_PROBABLE_PRIME_KEY_BITS / 8 / 2];
  18230. word32 qSz = (word32)sizeof(q);
  18231. int nlen = CHECK_PROBABLE_PRIME_KEY_BITS;
  18232. int* isPrime;
  18233. int test[5];
  18234. isPrime = test;
  18235. XMEMSET(&key, 0, sizeof(RsaKey));
  18236. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18237. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18238. ExpectIntEQ(wc_InitRng(&rng), 0);
  18239. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18240. ExpectIntEQ(wc_MakeRsaKey(&key, CHECK_PROBABLE_PRIME_KEY_BITS,
  18241. WC_RSA_EXPONENT, &rng), 0);
  18242. PRIVATE_KEY_UNLOCK();
  18243. ExpectIntEQ(wc_RsaExportKey(&key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q,
  18244. &qSz), 0);
  18245. PRIVATE_KEY_LOCK();
  18246. /* Bad cases */
  18247. ExpectIntEQ(wc_CheckProbablePrime(NULL, pSz, q, qSz, e, eSz, nlen, isPrime),
  18248. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18249. ExpectIntEQ(wc_CheckProbablePrime(p, 0, q, qSz, e, eSz, nlen, isPrime),
  18250. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18251. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, NULL, qSz, e, eSz, nlen, isPrime),
  18252. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18253. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, 0, e, eSz, nlen, isPrime),
  18254. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18255. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, NULL, eSz, nlen, isPrime),
  18256. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18257. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, e, 0, nlen, isPrime),
  18258. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18259. ExpectIntEQ(wc_CheckProbablePrime(NULL, 0, NULL, 0, NULL, 0, nlen, isPrime),
  18260. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18261. /* Good case */
  18262. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, e, eSz, nlen, isPrime),
  18263. 0);
  18264. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18265. wc_FreeRng(&rng);
  18266. #undef CHECK_PROBABLE_PRIME_KEY_BITS
  18267. #endif
  18268. return EXPECT_RESULT();
  18269. } /* END test_wc_CheckProbablePrime */
  18270. /*
  18271. * Testing wc_RsaPSS_Verify()
  18272. */
  18273. static int test_wc_RsaPSS_Verify(void)
  18274. {
  18275. EXPECT_DECLS;
  18276. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18277. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  18278. RsaKey key;
  18279. WC_RNG rng;
  18280. int sz = 256;
  18281. const char* szMessage = "This is the string to be signed";
  18282. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  18283. unsigned char pDecrypted[2048/8];
  18284. byte* pt = pDecrypted;
  18285. word32 outLen = sizeof(pDecrypted);
  18286. XMEMSET(&key, 0, sizeof(RsaKey));
  18287. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18288. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18289. ExpectIntEQ(wc_InitRng(&rng), 0);
  18290. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18291. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18292. ExpectIntGT(sz = wc_RsaPSS_Sign((byte*)szMessage,
  18293. (word32)XSTRLEN(szMessage)+1, pSignature, sizeof(pSignature),
  18294. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  18295. /* Bad cases */
  18296. ExpectIntEQ(wc_RsaPSS_Verify(NULL, (word32)sz, pt, outLen,
  18297. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18298. ExpectIntEQ(wc_RsaPSS_Verify(pSignature, 0, pt, outLen,
  18299. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18300. ExpectIntEQ(wc_RsaPSS_Verify(pSignature, (word32)sz, NULL, outLen,
  18301. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18302. ExpectIntEQ(wc_RsaPSS_Verify(NULL, 0, NULL, outLen,
  18303. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18304. /* Good case */
  18305. ExpectIntGT(wc_RsaPSS_Verify(pSignature, (word32)sz, pt, outLen,
  18306. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  18307. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18308. wc_FreeRng(&rng);
  18309. #endif
  18310. return EXPECT_RESULT();
  18311. } /* END test_wc_RsaPSS_Verify */
  18312. /*
  18313. * Testing wc_RsaPSS_VerifyCheck()
  18314. */
  18315. static int test_wc_RsaPSS_VerifyCheck(void)
  18316. {
  18317. EXPECT_DECLS;
  18318. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18319. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  18320. RsaKey key;
  18321. WC_RNG rng;
  18322. int sz = 256; /* 2048/8 */
  18323. byte digest[32];
  18324. word32 digestSz = sizeof(digest);
  18325. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  18326. word32 pSignatureSz = sizeof(pSignature);
  18327. unsigned char pDecrypted[2048/8];
  18328. byte* pt = pDecrypted;
  18329. word32 outLen = sizeof(pDecrypted);
  18330. XMEMSET(&key, 0, sizeof(RsaKey));
  18331. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18332. XMEMSET(digest, 0, sizeof(digest));
  18333. XMEMSET(pSignature, 0, sizeof(pSignature));
  18334. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18335. ExpectIntEQ(wc_InitRng(&rng), 0);
  18336. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18337. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18338. ExpectTrue((digestSz = (word32)wc_HashGetDigestSize(WC_HASH_TYPE_SHA256)) > 0);
  18339. ExpectIntEQ(wc_Hash(WC_HASH_TYPE_SHA256, pSignature, (word32)sz, digest, digestSz),
  18340. 0);
  18341. ExpectIntGT(sz = wc_RsaPSS_Sign(digest, digestSz, pSignature, pSignatureSz,
  18342. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  18343. /* Bad cases */
  18344. ExpectIntEQ(wc_RsaPSS_VerifyCheck(NULL, (word32)sz, pt, outLen, digest,
  18345. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18346. ExpectIntEQ(wc_RsaPSS_VerifyCheck(pSignature, 0, pt, outLen, digest,
  18347. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18348. ExpectIntEQ(wc_RsaPSS_VerifyCheck(pSignature, (word32)sz, NULL, outLen, digest,
  18349. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18350. ExpectIntEQ(wc_RsaPSS_VerifyCheck(NULL, 0, NULL, outLen, digest,
  18351. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18352. /* Good case */
  18353. ExpectIntGT(wc_RsaPSS_VerifyCheck(pSignature, (word32)sz, pt, outLen, digest,
  18354. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  18355. ExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18356. wc_FreeRng(&rng);
  18357. #endif
  18358. return EXPECT_RESULT();
  18359. } /* END test_wc_RsaPSS_VerifyCheck */
  18360. /*
  18361. * Testing wc_RsaPSS_VerifyCheckInline()
  18362. */
  18363. static int test_wc_RsaPSS_VerifyCheckInline(void)
  18364. {
  18365. EXPECT_DECLS;
  18366. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18367. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  18368. RsaKey key;
  18369. WC_RNG rng;
  18370. int sz = 256;
  18371. byte digest[32];
  18372. word32 digestSz = sizeof(digest);
  18373. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  18374. unsigned char pDecrypted[2048/8];
  18375. byte* pt = pDecrypted;
  18376. XMEMSET(&key, 0, sizeof(RsaKey));
  18377. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18378. XMEMSET(digest, 0, sizeof(digest));
  18379. XMEMSET(pSignature, 0, sizeof(pSignature));
  18380. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18381. ExpectIntEQ(wc_InitRng(&rng), 0);
  18382. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18383. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18384. ExpectTrue((digestSz = (word32)wc_HashGetDigestSize(WC_HASH_TYPE_SHA256)) > 0);
  18385. ExpectIntEQ(wc_Hash(WC_HASH_TYPE_SHA256, pSignature, (word32)sz, digest, digestSz),
  18386. 0);
  18387. ExpectIntGT(sz = wc_RsaPSS_Sign(digest, digestSz, pSignature,
  18388. sizeof(pSignature), WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  18389. /* Bad Cases */
  18390. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(NULL, (word32)sz, &pt, digest,
  18391. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18392. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(pSignature, 0, NULL, digest,
  18393. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18394. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(NULL, 0, &pt, digest,
  18395. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18396. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(pSignature, (word32)sz, &pt, digest,
  18397. digestSz, WC_HASH_TYPE_SHA, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18398. /* Good case */
  18399. ExpectIntGT(wc_RsaPSS_VerifyCheckInline(pSignature, (word32)sz, &pt, digest,
  18400. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  18401. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18402. wc_FreeRng(&rng);
  18403. #endif
  18404. return EXPECT_RESULT();
  18405. } /* END test_wc_RsaPSS_VerifyCheckInline */
  18406. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  18407. static void sample_mutex_cb (int flag, int type, const char* file, int line)
  18408. {
  18409. (void)flag;
  18410. (void)type;
  18411. (void)file;
  18412. (void)line;
  18413. }
  18414. #endif
  18415. /*
  18416. * Testing wc_LockMutex_ex
  18417. */
  18418. static int test_wc_LockMutex_ex(void)
  18419. {
  18420. EXPECT_DECLS;
  18421. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  18422. int flag = CRYPTO_LOCK;
  18423. int type = 0;
  18424. const char* file = "./test-LockMutex_ex.txt";
  18425. int line = 0;
  18426. /* without SetMutexCb */
  18427. ExpectIntEQ(wc_LockMutex_ex(flag, type, file, line), WC_NO_ERR_TRACE(BAD_STATE_E));
  18428. /* with SetMutexCb */
  18429. ExpectIntEQ(wc_SetMutexCb(sample_mutex_cb), 0);
  18430. ExpectIntEQ(wc_LockMutex_ex(flag, type, file, line), 0);
  18431. ExpectIntEQ(wc_SetMutexCb(NULL), 0);
  18432. #endif
  18433. return EXPECT_RESULT();
  18434. } /* End test_wc_LockMutex_ex*/
  18435. /*
  18436. * Testing wc_SetMutexCb
  18437. */
  18438. static int test_wc_SetMutexCb(void)
  18439. {
  18440. EXPECT_DECLS;
  18441. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  18442. ExpectIntEQ(wc_SetMutexCb(sample_mutex_cb), 0);
  18443. ExpectIntEQ(wc_SetMutexCb(NULL), 0);
  18444. #endif
  18445. return EXPECT_RESULT();
  18446. } /* End test_wc_SetMutexCb*/
  18447. /*
  18448. * Testing wc_RsaKeyToDer()
  18449. */
  18450. static int test_wc_RsaKeyToDer(void)
  18451. {
  18452. EXPECT_DECLS;
  18453. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18454. RsaKey genKey;
  18455. WC_RNG rng;
  18456. byte* der = NULL;
  18457. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18458. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18459. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18460. int bits = 1024;
  18461. word32 derSz = 611;
  18462. /* (2 x 128) + 2 (possible leading 00) + (5 x 64) + 5 (possible leading 00)
  18463. + 3 (e) + 8 (ASN tag) + 10 (ASN length) + 4 seqSz + 3 version */
  18464. #else
  18465. int bits = 2048;
  18466. word32 derSz = 1196;
  18467. /* (2 x 256) + 2 (possible leading 00) + (5 x 128) + 5 (possible leading 00)
  18468. + 3 (e) + 8 (ASN tag) + 17 (ASN length) + 4 seqSz + 3 version */
  18469. #endif
  18470. XMEMSET(&rng, 0, sizeof(rng));
  18471. XMEMSET(&genKey, 0, sizeof(genKey));
  18472. ExpectNotNull(der = (byte*)XMALLOC(derSz, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  18473. /* Init structures. */
  18474. ExpectIntEQ(wc_InitRsaKey(&genKey, HEAP_HINT), 0);
  18475. ExpectIntEQ(wc_InitRng(&rng), 0);
  18476. /* Make key. */
  18477. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, &rng), 0);
  18478. ExpectIntGT(wc_RsaKeyToDer(&genKey, der, derSz), 0);
  18479. /* Pass good/bad args. */
  18480. ExpectIntEQ(wc_RsaKeyToDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18481. /* Get just the output length */
  18482. ExpectIntGT(wc_RsaKeyToDer(&genKey, NULL, 0), 0);
  18483. /* Try Public Key. */
  18484. genKey.type = 0;
  18485. ExpectIntEQ(wc_RsaKeyToDer(&genKey, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18486. #ifdef WOLFSSL_CHECK_MEM_ZERO
  18487. /* Put back to Private Key */
  18488. genKey.type = 1;
  18489. #endif
  18490. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  18491. DoExpectIntEQ(wc_FreeRsaKey(&genKey), 0);
  18492. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18493. #endif
  18494. return EXPECT_RESULT();
  18495. } /* END test_wc_RsaKeyToDer */
  18496. /*
  18497. * Testing wc_RsaKeyToPublicDer()
  18498. */
  18499. static int test_wc_RsaKeyToPublicDer(void)
  18500. {
  18501. EXPECT_DECLS;
  18502. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18503. RsaKey key;
  18504. WC_RNG rng;
  18505. byte* der = NULL;
  18506. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18507. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18508. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18509. int bits = 1024;
  18510. word32 derLen = 162;
  18511. #else
  18512. int bits = 2048;
  18513. word32 derLen = 294;
  18514. #endif
  18515. int ret = 0;
  18516. XMEMSET(&rng, 0, sizeof(rng));
  18517. XMEMSET(&key, 0, sizeof(key));
  18518. ExpectNotNull(der = (byte*)XMALLOC(derLen, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  18519. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18520. ExpectIntEQ(wc_InitRng(&rng), 0);
  18521. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18522. /* test getting size only */
  18523. ExpectIntGT(wc_RsaKeyToPublicDer(&key, NULL, derLen), 0);
  18524. ExpectIntGT(wc_RsaKeyToPublicDer(&key, der, derLen), 0);
  18525. /* test getting size only */
  18526. ExpectIntGT(wc_RsaKeyToPublicDer_ex(&key, NULL, derLen, 0), 0);
  18527. ExpectIntGT(wc_RsaKeyToPublicDer_ex(&key, der, derLen, 0), 0);
  18528. /* Pass in bad args. */
  18529. ExpectIntEQ(wc_RsaKeyToPublicDer(NULL, der, derLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18530. ExpectIntLT(ret = wc_RsaKeyToPublicDer(&key, der, -1), 0);
  18531. ExpectTrue((ret == WC_NO_ERR_TRACE(BUFFER_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  18532. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  18533. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18534. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18535. #endif
  18536. return EXPECT_RESULT();
  18537. } /* END test_wc_RsaKeyToPublicDer */
  18538. /*
  18539. * Testing wc_RsaPublicEncrypt() and wc_RsaPrivateDecrypt()
  18540. */
  18541. static int test_wc_RsaPublicEncryptDecrypt(void)
  18542. {
  18543. EXPECT_DECLS;
  18544. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18545. RsaKey key;
  18546. WC_RNG rng;
  18547. const char inStr[] = TEST_STRING;
  18548. const word32 plainLen = (word32)TEST_STRING_SZ;
  18549. const word32 inLen = (word32)TEST_STRING_SZ;
  18550. int bits = TEST_RSA_BITS;
  18551. const word32 cipherLen = TEST_RSA_BYTES;
  18552. word32 cipherLenResult = cipherLen;
  18553. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18554. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18555. WC_DECLARE_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18556. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18557. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18558. WC_ALLOC_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18559. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18560. ExpectNotNull(in);
  18561. ExpectNotNull(plain);
  18562. ExpectNotNull(cipher);
  18563. #endif
  18564. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18565. /* Initialize stack structures. */
  18566. XMEMSET(&key, 0, sizeof(RsaKey));
  18567. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18568. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18569. ExpectIntEQ(wc_InitRng(&rng), 0);
  18570. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18571. /* Encrypt. */
  18572. ExpectIntGT(cipherLenResult = (word32)wc_RsaPublicEncrypt(in, inLen, cipher,
  18573. cipherLen, &key, &rng), 0);
  18574. /* Pass bad args - tested in another testing function.*/
  18575. /* Decrypt */
  18576. #if defined(WC_RSA_BLINDING) && !defined(HAVE_FIPS)
  18577. /* Bind rng */
  18578. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18579. #endif
  18580. ExpectIntGE(wc_RsaPrivateDecrypt(cipher, cipherLenResult, plain, plainLen,
  18581. &key), 0);
  18582. ExpectIntEQ(XMEMCMP(plain, inStr, plainLen), 0);
  18583. /* Pass bad args - tested in another testing function.*/
  18584. WC_FREE_VAR(in, NULL);
  18585. WC_FREE_VAR(plain, NULL);
  18586. WC_FREE_VAR(cipher, NULL);
  18587. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18588. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18589. #endif
  18590. return EXPECT_RESULT();
  18591. } /* END test_wc_RsaPublicEncryptDecrypt */
  18592. /*
  18593. * Testing wc_RsaPrivateDecrypt_ex() and wc_RsaPrivateDecryptInline_ex()
  18594. */
  18595. static int test_wc_RsaPublicEncryptDecrypt_ex(void)
  18596. {
  18597. EXPECT_DECLS;
  18598. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_FIPS)\
  18599. && !defined(WC_NO_RSA_OAEP) && !defined(NO_SHA256)
  18600. RsaKey key;
  18601. WC_RNG rng;
  18602. const char inStr[] = TEST_STRING;
  18603. const word32 inLen = (word32)TEST_STRING_SZ;
  18604. const word32 plainSz = (word32)TEST_STRING_SZ;
  18605. byte* res = NULL;
  18606. int idx = 0;
  18607. int bits = TEST_RSA_BITS;
  18608. const word32 cipherSz = TEST_RSA_BYTES;
  18609. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18610. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18611. WC_DECLARE_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18612. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18613. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18614. WC_ALLOC_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18615. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18616. ExpectNotNull(in);
  18617. ExpectNotNull(plain);
  18618. ExpectNotNull(cipher);
  18619. #endif
  18620. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18621. /* Initialize stack structures. */
  18622. XMEMSET(&key, 0, sizeof(RsaKey));
  18623. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18624. ExpectIntEQ(wc_InitRsaKey_ex(&key, HEAP_HINT, INVALID_DEVID), 0);
  18625. ExpectIntEQ(wc_InitRng(&rng), 0);
  18626. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18627. /* Encrypt */
  18628. ExpectIntGE(idx = wc_RsaPublicEncrypt_ex(in, inLen, cipher, cipherSz, &key,
  18629. &rng, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18630. /* Pass bad args - tested in another testing function.*/
  18631. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18632. /* Decrypt */
  18633. #if defined(WC_RSA_BLINDING) && !defined(HAVE_FIPS)
  18634. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18635. #endif
  18636. ExpectIntGE(wc_RsaPrivateDecrypt_ex(cipher, (word32)idx, plain, plainSz,
  18637. &key, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18638. ExpectIntEQ(XMEMCMP(plain, inStr, plainSz), 0);
  18639. /* Pass bad args - tested in another testing function.*/
  18640. ExpectIntGE(wc_RsaPrivateDecryptInline_ex(cipher, (word32)idx, &res, &key,
  18641. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18642. ExpectIntEQ(XMEMCMP(inStr, res, plainSz), 0);
  18643. #endif
  18644. WC_FREE_VAR(in, NULL);
  18645. WC_FREE_VAR(plain, NULL);
  18646. WC_FREE_VAR(cipher, NULL);
  18647. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18648. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18649. #endif
  18650. return EXPECT_RESULT();
  18651. } /* END test_wc_RsaPublicEncryptDecrypt_ex */
  18652. /*
  18653. * Tesing wc_RsaSSL_Sign() and wc_RsaSSL_Verify()
  18654. */
  18655. static int test_wc_RsaSSL_SignVerify(void)
  18656. {
  18657. EXPECT_DECLS;
  18658. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18659. RsaKey key;
  18660. WC_RNG rng;
  18661. const char inStr[] = TEST_STRING;
  18662. const word32 plainSz = (word32)TEST_STRING_SZ;
  18663. const word32 inLen = (word32)TEST_STRING_SZ;
  18664. word32 idx = 0;
  18665. int bits = TEST_RSA_BITS;
  18666. const word32 outSz = TEST_RSA_BYTES;
  18667. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18668. WC_DECLARE_VAR(out, byte, TEST_RSA_BYTES, NULL);
  18669. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18670. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18671. WC_ALLOC_VAR(out, byte, TEST_RSA_BYTES, NULL);
  18672. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18673. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18674. ExpectNotNull(in);
  18675. ExpectNotNull(out);
  18676. ExpectNotNull(plain);
  18677. #endif
  18678. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18679. XMEMSET(&key, 0, sizeof(RsaKey));
  18680. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18681. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18682. ExpectIntEQ(wc_InitRng(&rng), 0);
  18683. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18684. /* Sign. */
  18685. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, out, outSz, &key, &rng), (int)outSz);
  18686. idx = (int)outSz;
  18687. /* Test bad args. */
  18688. ExpectIntEQ(wc_RsaSSL_Sign(NULL, inLen, out, outSz, &key, &rng),
  18689. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18690. ExpectIntEQ(wc_RsaSSL_Sign(in, 0, out, outSz, &key, &rng),
  18691. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18692. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, NULL, outSz, &key, &rng),
  18693. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18694. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, out, outSz, NULL, &rng),
  18695. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18696. /* Verify. */
  18697. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, plain, plainSz, &key), (int)inLen);
  18698. /* Pass bad args. */
  18699. ExpectIntEQ(wc_RsaSSL_Verify(NULL, idx, plain, plainSz, &key),
  18700. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18701. ExpectIntEQ(wc_RsaSSL_Verify(out, 0, plain, plainSz, &key),
  18702. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18703. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, NULL, plainSz, &key),
  18704. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18705. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, plain, plainSz, NULL),
  18706. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18707. WC_FREE_VAR(in, NULL);
  18708. WC_FREE_VAR(out, NULL);
  18709. WC_FREE_VAR(plain, NULL);
  18710. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18711. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18712. #endif
  18713. return EXPECT_RESULT();
  18714. } /* END test_wc_RsaSSL_SignVerify */
  18715. /*
  18716. * Testing wc_RsaEncryptSize()
  18717. */
  18718. static int test_wc_RsaEncryptSize(void)
  18719. {
  18720. EXPECT_DECLS;
  18721. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18722. RsaKey key;
  18723. WC_RNG rng;
  18724. XMEMSET(&key, 0, sizeof(RsaKey));
  18725. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18726. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18727. ExpectIntEQ(wc_InitRng(&rng), 0);
  18728. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18729. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18730. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18731. ExpectIntEQ(MAKE_RSA_KEY(&key, 1024, WC_RSA_EXPONENT, &rng), 0);
  18732. ExpectIntEQ(wc_RsaEncryptSize(&key), 128);
  18733. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18734. #endif
  18735. ExpectIntEQ(MAKE_RSA_KEY(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18736. ExpectIntEQ(wc_RsaEncryptSize(&key), 256);
  18737. /* Pass in bad arg. */
  18738. ExpectIntEQ(wc_RsaEncryptSize(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18739. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18740. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18741. #endif
  18742. return EXPECT_RESULT();
  18743. } /* END test_wc_RsaEncryptSize*/
  18744. /*
  18745. * Testing wc_RsaFlattenPublicKey()
  18746. */
  18747. static int test_wc_RsaFlattenPublicKey(void)
  18748. {
  18749. EXPECT_DECLS;
  18750. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18751. RsaKey key;
  18752. WC_RNG rng;
  18753. byte e[256];
  18754. byte n[256];
  18755. word32 eSz = sizeof(e);
  18756. word32 nSz = sizeof(n);
  18757. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18758. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18759. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18760. int bits = 1024;
  18761. #else
  18762. int bits = 2048;
  18763. #endif
  18764. XMEMSET(&key, 0, sizeof(RsaKey));
  18765. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18766. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18767. ExpectIntEQ(wc_InitRng(&rng), 0);
  18768. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18769. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, n, &nSz), 0);
  18770. /* Pass bad args. */
  18771. ExpectIntEQ(wc_RsaFlattenPublicKey(NULL, e, &eSz, n, &nSz),
  18772. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18773. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, NULL, &eSz, n, &nSz),
  18774. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18775. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, NULL, n, &nSz),
  18776. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18777. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, NULL, &nSz),
  18778. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18779. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, n, NULL),
  18780. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18781. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18782. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18783. #endif
  18784. return EXPECT_RESULT();
  18785. } /* END test_wc_RsaFlattenPublicKey */
  18786. /*
  18787. * unit test for wc_AesCcmSetKey
  18788. */
  18789. static int test_wc_AesCcmSetKey(void)
  18790. {
  18791. EXPECT_DECLS;
  18792. #ifdef HAVE_AESCCM
  18793. Aes aes;
  18794. const byte key16[] = {
  18795. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  18796. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  18797. };
  18798. const byte key24[] = {
  18799. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18800. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  18801. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  18802. };
  18803. const byte key32[] = {
  18804. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18805. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  18806. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18807. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  18808. };
  18809. XMEMSET(&aes, 0, sizeof(Aes));
  18810. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  18811. #ifdef WOLFSSL_AES_128
  18812. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16)), 0);
  18813. #endif
  18814. #ifdef WOLFSSL_AES_192
  18815. ExpectIntEQ(wc_AesCcmSetKey(&aes, key24, sizeof(key24)), 0);
  18816. #endif
  18817. #ifdef WOLFSSL_AES_256
  18818. ExpectIntEQ(wc_AesCcmSetKey(&aes, key32, sizeof(key32)), 0);
  18819. #endif
  18820. /* Test bad args. */
  18821. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18822. ExpectIntEQ(wc_AesCcmSetKey(&aes, key24, sizeof(key24) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18823. ExpectIntEQ(wc_AesCcmSetKey(&aes, key32, sizeof(key32) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18824. wc_AesFree(&aes);
  18825. #endif
  18826. return EXPECT_RESULT();
  18827. } /* END test_wc_AesCcmSetKey */
  18828. /*
  18829. * Unit test function for wc_AesCcmEncrypt and wc_AesCcmDecrypt
  18830. */
  18831. static int test_wc_AesCcmEncryptDecrypt(void)
  18832. {
  18833. EXPECT_DECLS;
  18834. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  18835. Aes aes;
  18836. const byte key16[] = {
  18837. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  18838. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  18839. };
  18840. /* plaintext */
  18841. const byte plainT[] = {
  18842. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  18843. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  18844. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e
  18845. };
  18846. /* nonce */
  18847. const byte iv[] = {
  18848. 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0xa0,
  18849. 0xa1, 0xa2, 0xa3, 0xa4, 0xa5
  18850. };
  18851. const byte c[] = { /* cipher text. */
  18852. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  18853. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  18854. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84
  18855. };
  18856. const byte t[] = { /* Auth tag */
  18857. 0x17, 0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0
  18858. };
  18859. const byte authIn[] = {
  18860. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  18861. };
  18862. byte cipherOut[sizeof(plainT)];
  18863. byte authTag[sizeof(t)];
  18864. #ifdef HAVE_AES_DECRYPT
  18865. byte plainOut[sizeof(cipherOut)];
  18866. #endif
  18867. XMEMSET(&aes, 0, sizeof(Aes));
  18868. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  18869. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16)), 0);
  18870. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18871. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)), 0);
  18872. ExpectIntEQ(XMEMCMP(cipherOut, c, sizeof(c)), 0);
  18873. ExpectIntEQ(XMEMCMP(t, authTag, sizeof(t)), 0);
  18874. #ifdef HAVE_AES_DECRYPT
  18875. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18876. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)), 0);
  18877. ExpectIntEQ(XMEMCMP(plainOut, plainT, sizeof(plainT)), 0);
  18878. #endif
  18879. /* Pass in bad args. Encrypt*/
  18880. ExpectIntEQ(wc_AesCcmEncrypt(NULL, cipherOut, plainT, sizeof(cipherOut),
  18881. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18882. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18883. ExpectIntEQ(wc_AesCcmEncrypt(&aes, NULL, plainT, sizeof(cipherOut),
  18884. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18885. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18886. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, NULL, sizeof(cipherOut),
  18887. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18888. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18889. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18890. NULL, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18891. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18892. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18893. iv, sizeof(iv), NULL, sizeof(authTag), authIn , sizeof(authIn)),
  18894. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18895. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18896. iv, sizeof(iv) + 1, authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18897. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18898. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18899. iv, sizeof(iv) - 7, authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18900. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18901. #ifdef HAVE_AES_DECRYPT
  18902. /* Pass in bad args. Decrypt*/
  18903. ExpectIntEQ(wc_AesCcmDecrypt(NULL, plainOut, cipherOut, sizeof(plainOut),
  18904. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18905. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18906. ExpectIntEQ(wc_AesCcmDecrypt(&aes, NULL, cipherOut, sizeof(plainOut),
  18907. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18908. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18909. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, NULL, sizeof(plainOut),
  18910. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18911. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18912. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18913. NULL, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18914. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18915. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18916. iv, sizeof(iv), NULL, sizeof(authTag), authIn, sizeof(authIn)),
  18917. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18918. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18919. iv, sizeof(iv) + 1, authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18920. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18921. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18922. iv, sizeof(iv) - 7, authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18923. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18924. #endif
  18925. wc_AesFree(&aes);
  18926. #endif /* HAVE_AESCCM */
  18927. return EXPECT_RESULT();
  18928. } /* END test_wc_AesCcmEncryptDecrypt */
  18929. #if defined(WOLFSSL_AES_EAX) && \
  18930. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  18931. /*
  18932. * Testing test_wc_AesEaxVectors()
  18933. */
  18934. static int test_wc_AesEaxVectors(void)
  18935. {
  18936. EXPECT_DECLS;
  18937. typedef struct {
  18938. byte key[AES_256_KEY_SIZE];
  18939. int key_length;
  18940. byte iv[AES_BLOCK_SIZE];
  18941. int iv_length;
  18942. byte aad[AES_BLOCK_SIZE * 2];
  18943. int aad_length;
  18944. byte msg[AES_BLOCK_SIZE * 5];
  18945. int msg_length;
  18946. byte ct[AES_BLOCK_SIZE * 5];
  18947. int ct_length;
  18948. byte tag[AES_BLOCK_SIZE];
  18949. int tag_length;
  18950. int valid;
  18951. } AadVector;
  18952. /* Test vectors obtained from Google wycheproof project
  18953. * https://github.com/google/wycheproof
  18954. * from testvectors/aes_eax_test.json
  18955. */
  18956. const AadVector vectors[] = {
  18957. {
  18958. /* key, key length */
  18959. {0x23, 0x39, 0x52, 0xde, 0xe4, 0xd5, 0xed, 0x5f,
  18960. 0x9b, 0x9c, 0x6d, 0x6f, 0xf8, 0x0f, 0xf4, 0x78}, 16,
  18961. /* iv, iv length */
  18962. {0x62, 0xec, 0x67, 0xf9, 0xc3, 0xa4, 0xa4, 0x07,
  18963. 0xfc, 0xb2, 0xa8, 0xc4, 0x90, 0x31, 0xa8, 0xb3}, 16,
  18964. /* aad, aad length */
  18965. {0x6b, 0xfb, 0x91, 0x4f, 0xd0, 0x7e, 0xae, 0x6b}, 8,
  18966. /* msg, msg length */
  18967. {0x00}, 0,
  18968. /* ct, ct length */
  18969. {0x00}, 0,
  18970. /* tag, tag length */
  18971. {0xe0, 0x37, 0x83, 0x0e, 0x83, 0x89, 0xf2, 0x7b,
  18972. 0x02, 0x5a, 0x2d, 0x65, 0x27, 0xe7, 0x9d, 0x01}, 16,
  18973. /* valid */
  18974. 1,
  18975. },
  18976. {
  18977. /* key, key length */
  18978. {0x91, 0x94, 0x5d, 0x3f, 0x4d, 0xcb, 0xee, 0x0b,
  18979. 0xf4, 0x5e, 0xf5, 0x22, 0x55, 0xf0, 0x95, 0xa4}, 16,
  18980. /* iv, iv length */
  18981. {0xbe, 0xca, 0xf0, 0x43, 0xb0, 0xa2, 0x3d, 0x84,
  18982. 0x31, 0x94, 0xba, 0x97, 0x2c, 0x66, 0xde, 0xbd}, 16,
  18983. /* aad, aad length */
  18984. {0xfa, 0x3b, 0xfd, 0x48, 0x06, 0xeb, 0x53, 0xfa}, 8,
  18985. /* msg, msg length */
  18986. {0xf7, 0xfb}, 2,
  18987. /* ct, ct length */
  18988. {0x19, 0xdd}, 2,
  18989. /* tag, tag length */
  18990. {0x5c, 0x4c, 0x93, 0x31, 0x04, 0x9d, 0x0b, 0xda,
  18991. 0xb0, 0x27, 0x74, 0x08, 0xf6, 0x79, 0x67, 0xe5}, 16,
  18992. /* valid */
  18993. 1,
  18994. },
  18995. {
  18996. /* key, key length */
  18997. {0x01, 0xf7, 0x4a, 0xd6, 0x40, 0x77, 0xf2, 0xe7,
  18998. 0x04, 0xc0, 0xf6, 0x0a, 0xda, 0x3d, 0xd5, 0x23}, 16,
  18999. /* iv, iv length */
  19000. {0x70, 0xc3, 0xdb, 0x4f, 0x0d, 0x26, 0x36, 0x84,
  19001. 0x00, 0xa1, 0x0e, 0xd0, 0x5d, 0x2b, 0xff, 0x5e}, 16,
  19002. /* aad, aad length */
  19003. {0x23, 0x4a, 0x34, 0x63, 0xc1, 0x26, 0x4a, 0xc6}, 8,
  19004. /* msg, msg length */
  19005. {0x1a, 0x47, 0xcb, 0x49, 0x33}, 5,
  19006. /* ct, ct length */
  19007. {0xd8, 0x51, 0xd5, 0xba, 0xe0}, 5,
  19008. /* tag, tag length */
  19009. {0x3a, 0x59, 0xf2, 0x38, 0xa2, 0x3e, 0x39, 0x19,
  19010. 0x9d, 0xc9, 0x26, 0x66, 0x26, 0xc4, 0x0f, 0x80}, 16,
  19011. /* valid */
  19012. 1,
  19013. },
  19014. {
  19015. /* key, key length */
  19016. {0xd0, 0x7c, 0xf6, 0xcb, 0xb7, 0xf3, 0x13, 0xbd,
  19017. 0xde, 0x66, 0xb7, 0x27, 0xaf, 0xd3, 0xc5, 0xe8}, 16,
  19018. /* iv, iv length */
  19019. {0x84, 0x08, 0xdf, 0xff, 0x3c, 0x1a, 0x2b, 0x12,
  19020. 0x92, 0xdc, 0x19, 0x9e, 0x46, 0xb7, 0xd6, 0x17}, 16,
  19021. /* aad, aad length */
  19022. {0x33, 0xcc, 0xe2, 0xea, 0xbf, 0xf5, 0xa7, 0x9d}, 8,
  19023. /* msg, msg length */
  19024. {0x48, 0x1c, 0x9e, 0x39, 0xb1}, 5,
  19025. /* ct, ct length */
  19026. {0x63, 0x2a, 0x9d, 0x13, 0x1a}, 5,
  19027. /* tag, tag length */
  19028. {0xd4, 0xc1, 0x68, 0xa4, 0x22, 0x5d, 0x8e, 0x1f,
  19029. 0xf7, 0x55, 0x93, 0x99, 0x74, 0xa7, 0xbe, 0xde}, 16,
  19030. /* valid */
  19031. 1,
  19032. },
  19033. {
  19034. /* key, key length */
  19035. {0x35, 0xb6, 0xd0, 0x58, 0x00, 0x05, 0xbb, 0xc1,
  19036. 0x2b, 0x05, 0x87, 0x12, 0x45, 0x57, 0xd2, 0xc2}, 16,
  19037. /* iv, iv length */
  19038. {0xfd, 0xb6, 0xb0, 0x66, 0x76, 0xee, 0xdc, 0x5c,
  19039. 0x61, 0xd7, 0x42, 0x76, 0xe1, 0xf8, 0xe8, 0x16}, 16,
  19040. /* aad, aad length */
  19041. {0xae, 0xb9, 0x6e, 0xae, 0xbe, 0x29, 0x70, 0xe9}, 8,
  19042. /* msg, msg length */
  19043. {0x40, 0xd0, 0xc0, 0x7d, 0xa5, 0xe4}, 6,
  19044. /* ct, ct length */
  19045. {0x07, 0x1d, 0xfe, 0x16, 0xc6, 0x75}, 6,
  19046. /* tag, tag length */
  19047. {0xcb, 0x06, 0x77, 0xe5, 0x36, 0xf7, 0x3a, 0xfe,
  19048. 0x6a, 0x14, 0xb7, 0x4e, 0xe4, 0x98, 0x44, 0xdd}, 16,
  19049. /* valid */
  19050. 1,
  19051. },
  19052. {
  19053. /* key, key length */
  19054. {0xbd, 0x8e, 0x6e, 0x11, 0x47, 0x5e, 0x60, 0xb2,
  19055. 0x68, 0x78, 0x4c, 0x38, 0xc6, 0x2f, 0xeb, 0x22}, 16,
  19056. /* iv, iv length */
  19057. {0x6e, 0xac, 0x5c, 0x93, 0x07, 0x2d, 0x8e, 0x85,
  19058. 0x13, 0xf7, 0x50, 0x93, 0x5e, 0x46, 0xda, 0x1b}, 16,
  19059. /* aad, aad length */
  19060. {0xd4, 0x48, 0x2d, 0x1c, 0xa7, 0x8d, 0xce, 0x0f}, 8,
  19061. /* msg, msg length */
  19062. {0x4d, 0xe3, 0xb3, 0x5c, 0x3f, 0xc0, 0x39, 0x24,
  19063. 0x5b, 0xd1, 0xfb, 0x7d}, 12,
  19064. /* ct, ct length */
  19065. {0x83, 0x5b, 0xb4, 0xf1, 0x5d, 0x74, 0x3e, 0x35,
  19066. 0x0e, 0x72, 0x84, 0x14}, 12,
  19067. /* tag, tag length */
  19068. {0xab, 0xb8, 0x64, 0x4f, 0xd6, 0xcc, 0xb8, 0x69,
  19069. 0x47, 0xc5, 0xe1, 0x05, 0x90, 0x21, 0x0a, 0x4f}, 16,
  19070. /* valid */
  19071. 1,
  19072. },
  19073. {
  19074. /* key, key length */
  19075. {0x7c, 0x77, 0xd6, 0xe8, 0x13, 0xbe, 0xd5, 0xac,
  19076. 0x98, 0xba, 0xa4, 0x17, 0x47, 0x7a, 0x2e, 0x7d}, 16,
  19077. /* iv, iv length */
  19078. {0x1a, 0x8c, 0x98, 0xdc, 0xd7, 0x3d, 0x38, 0x39,
  19079. 0x3b, 0x2b, 0xf1, 0x56, 0x9d, 0xee, 0xfc, 0x19}, 16,
  19080. /* aad, aad length */
  19081. {0x65, 0xd2, 0x01, 0x79, 0x90, 0xd6, 0x25, 0x28}, 8,
  19082. /* msg, msg length */
  19083. {0x8b, 0x0a, 0x79, 0x30, 0x6c, 0x9c, 0xe7, 0xed,
  19084. 0x99, 0xda, 0xe4, 0xf8, 0x7f, 0x8d, 0xd6, 0x16,
  19085. 0x36}, 17,
  19086. /* ct, ct length */
  19087. {0x02, 0x08, 0x3e, 0x39, 0x79, 0xda, 0x01, 0x48,
  19088. 0x12, 0xf5, 0x9f, 0x11, 0xd5, 0x26, 0x30, 0xda,
  19089. 0x30}, 17,
  19090. /* tag, tag length */
  19091. {0x13, 0x73, 0x27, 0xd1, 0x06, 0x49, 0xb0, 0xaa,
  19092. 0x6e, 0x1c, 0x18, 0x1d, 0xb6, 0x17, 0xd7, 0xf2}, 16,
  19093. /* valid */
  19094. 1,
  19095. },
  19096. {
  19097. /* key, key length */
  19098. {0x5f, 0xff, 0x20, 0xca, 0xfa, 0xb1, 0x19, 0xca,
  19099. 0x2f, 0xc7, 0x35, 0x49, 0xe2, 0x0f, 0x5b, 0x0d}, 16,
  19100. /* iv, iv length */
  19101. {0xdd, 0xe5, 0x9b, 0x97, 0xd7, 0x22, 0x15, 0x6d,
  19102. 0x4d, 0x9a, 0xff, 0x2b, 0xc7, 0x55, 0x98, 0x26}, 16,
  19103. /* aad, aad length */
  19104. {0x54, 0xb9, 0xf0, 0x4e, 0x6a, 0x09, 0x18, 0x9a}, 8,
  19105. /* msg, msg length */
  19106. {0x1b, 0xda, 0x12, 0x2b, 0xce, 0x8a, 0x8d, 0xba,
  19107. 0xf1, 0x87, 0x7d, 0x96, 0x2b, 0x85, 0x92, 0xdd,
  19108. 0x2d, 0x56}, 18,
  19109. /* ct, ct length */
  19110. {0x2e, 0xc4, 0x7b, 0x2c, 0x49, 0x54, 0xa4, 0x89,
  19111. 0xaf, 0xc7, 0xba, 0x48, 0x97, 0xed, 0xcd, 0xae,
  19112. 0x8c, 0xc3}, 18,
  19113. /* tag, tag length */
  19114. {0x3b, 0x60, 0x45, 0x05, 0x99, 0xbd, 0x02, 0xc9,
  19115. 0x63, 0x82, 0x90, 0x2a, 0xef, 0x7f, 0x83, 0x2a}, 16,
  19116. /* valid */
  19117. 1,
  19118. },
  19119. {
  19120. /* key, key length */
  19121. {0xa4, 0xa4, 0x78, 0x2b, 0xcf, 0xfd, 0x3e, 0xc5,
  19122. 0xe7, 0xef, 0x6d, 0x8c, 0x34, 0xa5, 0x61, 0x23}, 16,
  19123. /* iv, iv length */
  19124. {0xb7, 0x81, 0xfc, 0xf2, 0xf7, 0x5f, 0xa5, 0xa8,
  19125. 0xde, 0x97, 0xa9, 0xca, 0x48, 0xe5, 0x22, 0xec}, 16,
  19126. /* aad, aad length */
  19127. {0x89, 0x9a, 0x17, 0x58, 0x97, 0x56, 0x1d, 0x7e}, 8,
  19128. /* msg, msg length */
  19129. {0x6c, 0xf3, 0x67, 0x20, 0x87, 0x2b, 0x85, 0x13,
  19130. 0xf6, 0xea, 0xb1, 0xa8, 0xa4, 0x44, 0x38, 0xd5,
  19131. 0xef, 0x11}, 18,
  19132. /* ct, ct length */
  19133. {0x0d, 0xe1, 0x8f, 0xd0, 0xfd, 0xd9, 0x1e, 0x7a,
  19134. 0xf1, 0x9f, 0x1d, 0x8e, 0xe8, 0x73, 0x39, 0x38,
  19135. 0xb1, 0xe8}, 18,
  19136. /* tag, tag length */
  19137. {0xe7, 0xf6, 0xd2, 0x23, 0x16, 0x18, 0x10, 0x2f,
  19138. 0xdb, 0x7f, 0xe5, 0x5f, 0xf1, 0x99, 0x17, 0x00}, 16,
  19139. /* valid */
  19140. 1,
  19141. },
  19142. {
  19143. /* key, key length */
  19144. {0x83, 0x95, 0xfc, 0xf1, 0xe9, 0x5b, 0xeb, 0xd6,
  19145. 0x97, 0xbd, 0x01, 0x0b, 0xc7, 0x66, 0xaa, 0xc3}, 16,
  19146. /* iv, iv length */
  19147. {0x22, 0xe7, 0xad, 0xd9, 0x3c, 0xfc, 0x63, 0x93,
  19148. 0xc5, 0x7e, 0xc0, 0xb3, 0xc1, 0x7d, 0x6b, 0x44}, 16,
  19149. /* aad, aad length */
  19150. {0x12, 0x67, 0x35, 0xfc, 0xc3, 0x20, 0xd2, 0x5a}, 8,
  19151. /* msg, msg length */
  19152. {0xca, 0x40, 0xd7, 0x44, 0x6e, 0x54, 0x5f, 0xfa,
  19153. 0xed, 0x3b, 0xd1, 0x2a, 0x74, 0x0a, 0x65, 0x9f,
  19154. 0xfb, 0xbb, 0x3c, 0xea, 0xb7}, 21,
  19155. /* ct, ct length */
  19156. {0xcb, 0x89, 0x20, 0xf8, 0x7a, 0x6c, 0x75, 0xcf,
  19157. 0xf3, 0x96, 0x27, 0xb5, 0x6e, 0x3e, 0xd1, 0x97,
  19158. 0xc5, 0x52, 0xd2, 0x95, 0xa7}, 21,
  19159. /* tag, tag length */
  19160. {0xcf, 0xc4, 0x6a, 0xfc, 0x25, 0x3b, 0x46, 0x52,
  19161. 0xb1, 0xaf, 0x37, 0x95, 0xb1, 0x24, 0xab, 0x6e}, 16,
  19162. /* valid */
  19163. 1,
  19164. },
  19165. {
  19166. /* key, key length */
  19167. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19168. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19169. /* iv, iv length */
  19170. {0x3c, 0x8c, 0xc2, 0x97, 0x0a, 0x00, 0x8f, 0x75,
  19171. 0xcc, 0x5b, 0xea, 0xe2, 0x84, 0x72, 0x58, 0xc2}, 16,
  19172. /* aad, aad length */
  19173. {0x00}, 0,
  19174. /* msg, msg length */
  19175. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19176. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19177. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19178. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19179. /* ct, ct length */
  19180. {0x3c, 0x44, 0x1f, 0x32, 0xce, 0x07, 0x82, 0x23,
  19181. 0x64, 0xd7, 0xa2, 0x99, 0x0e, 0x50, 0xbb, 0x13,
  19182. 0xd7, 0xb0, 0x2a, 0x26, 0x96, 0x9e, 0x4a, 0x93,
  19183. 0x7e, 0x5e, 0x90, 0x73, 0xb0, 0xd9, 0xc9, 0x68}, 32,
  19184. /* tag, tag length */
  19185. {0xdb, 0x90, 0xbd, 0xb3, 0xda, 0x3d, 0x00, 0xaf,
  19186. 0xd0, 0xfc, 0x6a, 0x83, 0x55, 0x1d, 0xa9, 0x5e}, 16,
  19187. /* valid */
  19188. 1,
  19189. },
  19190. {
  19191. /* key, key length */
  19192. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19193. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19194. /* iv, iv length */
  19195. {0xae, 0xf0, 0x3d, 0x00, 0x59, 0x84, 0x94, 0xe9,
  19196. 0xfb, 0x03, 0xcd, 0x7d, 0x8b, 0x59, 0x08, 0x66}, 16,
  19197. /* aad, aad length */
  19198. {0x00}, 0,
  19199. /* msg, msg length */
  19200. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19201. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19202. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19203. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19204. /* ct, ct length */
  19205. {0xd1, 0x9a, 0xc5, 0x98, 0x49, 0x02, 0x6a, 0x91,
  19206. 0xaa, 0x1b, 0x9a, 0xec, 0x29, 0xb1, 0x1a, 0x20,
  19207. 0x2a, 0x4d, 0x73, 0x9f, 0xd8, 0x6c, 0x28, 0xe3,
  19208. 0xae, 0x3d, 0x58, 0x8e, 0xa2, 0x1d, 0x70, 0xc6}, 32,
  19209. /* tag, tag length */
  19210. {0xc3, 0x0f, 0x6c, 0xd9, 0x20, 0x20, 0x74, 0xed,
  19211. 0x6e, 0x2a, 0x2a, 0x36, 0x0e, 0xac, 0x8c, 0x47}, 16,
  19212. /* valid */
  19213. 1,
  19214. },
  19215. {
  19216. /* key, key length */
  19217. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19218. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19219. /* iv, iv length */
  19220. {0x55, 0xd1, 0x25, 0x11, 0xc6, 0x96, 0xa8, 0x0d,
  19221. 0x05, 0x14, 0xd1, 0xff, 0xba, 0x49, 0xca, 0xda}, 16,
  19222. /* aad, aad length */
  19223. {0x00}, 0,
  19224. /* msg, msg length */
  19225. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19226. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19227. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19228. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19229. /* ct, ct length */
  19230. {0x21, 0x08, 0x55, 0x8a, 0xc4, 0xb2, 0xc2, 0xd5,
  19231. 0xcc, 0x66, 0xce, 0xa5, 0x1d, 0x62, 0x10, 0xe0,
  19232. 0x46, 0x17, 0x7a, 0x67, 0x63, 0x1c, 0xd2, 0xdd,
  19233. 0x8f, 0x09, 0x46, 0x97, 0x33, 0xac, 0xb5, 0x17}, 32,
  19234. /* tag, tag length */
  19235. {0xfc, 0x35, 0x5e, 0x87, 0xa2, 0x67, 0xbe, 0x3a,
  19236. 0xe3, 0xe4, 0x4c, 0x0b, 0xf3, 0xf9, 0x9b, 0x2b}, 16,
  19237. /* valid */
  19238. 1,
  19239. },
  19240. {
  19241. /* key, key length */
  19242. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19243. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19244. /* iv, iv length */
  19245. {0x79, 0x42, 0x2d, 0xdd, 0x91, 0xc4, 0xee, 0xe2,
  19246. 0xde, 0xae, 0xf1, 0xf9, 0x68, 0x30, 0x53, 0x04}, 16,
  19247. /* aad, aad length */
  19248. {0x00}, 0,
  19249. /* msg, msg length */
  19250. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19251. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19252. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19253. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19254. /* ct, ct length */
  19255. {0x4d, 0x2c, 0x15, 0x24, 0xca, 0x4b, 0xaa, 0x4e,
  19256. 0xef, 0xcc, 0xe6, 0xb9, 0x1b, 0x22, 0x7e, 0xe8,
  19257. 0x3a, 0xba, 0xff, 0x81, 0x05, 0xdc, 0xaf, 0xa2,
  19258. 0xab, 0x19, 0x1f, 0x5d, 0xf2, 0x57, 0x50, 0x35}, 32,
  19259. /* tag, tag length */
  19260. {0xe2, 0xc8, 0x65, 0xce, 0x2d, 0x7a, 0xbd, 0xac,
  19261. 0x02, 0x4c, 0x6f, 0x99, 0x1a, 0x84, 0x83, 0x90}, 16,
  19262. /* valid */
  19263. 1,
  19264. },
  19265. {
  19266. /* key, key length */
  19267. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19268. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19269. /* iv, iv length */
  19270. {0x0a, 0xf5, 0xaa, 0x7a, 0x76, 0x76, 0xe2, 0x83,
  19271. 0x06, 0x30, 0x6b, 0xcd, 0x9b, 0xf2, 0x00, 0x3a}, 16,
  19272. /* aad, aad length */
  19273. {0x00}, 0,
  19274. /* msg, msg length */
  19275. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19276. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19277. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19278. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19279. /* ct, ct length */
  19280. {0x8e, 0xb0, 0x1e, 0x62, 0x18, 0x5d, 0x78, 0x2e,
  19281. 0xb9, 0x28, 0x7a, 0x34, 0x1a, 0x68, 0x62, 0xac,
  19282. 0x52, 0x57, 0xd6, 0xf9, 0xad, 0xc9, 0x9e, 0xe0,
  19283. 0xa2, 0x4d, 0x9c, 0x22, 0xb3, 0xe9, 0xb3, 0x8a}, 32,
  19284. /* tag, tag length */
  19285. {0x39, 0xc3, 0x39, 0xbc, 0x8a, 0x74, 0xc7, 0x5e,
  19286. 0x2c, 0x65, 0xc6, 0x11, 0x95, 0x44, 0xd6, 0x1e}, 16,
  19287. /* valid */
  19288. 1,
  19289. },
  19290. {
  19291. /* key, key length */
  19292. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19293. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19294. /* iv, iv length */
  19295. {0xaf, 0x5a, 0x03, 0xae, 0x7e, 0xdd, 0x73, 0x47,
  19296. 0x1b, 0xdc, 0xdf, 0xac, 0x5e, 0x19, 0x4a, 0x60}, 16,
  19297. /* aad, aad length */
  19298. {0x00}, 0,
  19299. /* msg, msg length */
  19300. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19301. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19302. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19303. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19304. /* ct, ct length */
  19305. {0x94, 0xc5, 0xd2, 0xac, 0xa6, 0xdb, 0xbc, 0xe8,
  19306. 0xc2, 0x45, 0x13, 0xa2, 0x5e, 0x09, 0x5c, 0x0e,
  19307. 0x54, 0xa9, 0x42, 0x86, 0x0d, 0x32, 0x7a, 0x22,
  19308. 0x2a, 0x81, 0x5c, 0xc7, 0x13, 0xb1, 0x63, 0xb4}, 32,
  19309. /* tag, tag length */
  19310. {0xf5, 0x0b, 0x30, 0x30, 0x4e, 0x45, 0xc9, 0xd4,
  19311. 0x11, 0xe8, 0xdf, 0x45, 0x08, 0xa9, 0x86, 0x12}, 16,
  19312. /* valid */
  19313. 1,
  19314. },
  19315. {
  19316. /* key, key length */
  19317. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19318. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19319. /* iv, iv length */
  19320. {0xb3, 0x70, 0x87, 0x68, 0x0f, 0x0e, 0xdd, 0x5a,
  19321. 0x52, 0x22, 0x8b, 0x8c, 0x7a, 0xae, 0xa6, 0x64}, 16,
  19322. /* aad, aad length */
  19323. {0x00}, 0,
  19324. /* msg, msg length */
  19325. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19326. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19327. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19328. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19329. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19330. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19331. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  19332. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33}, 64,
  19333. /* ct, ct length */
  19334. {0x3b, 0xb6, 0x17, 0x3e, 0x37, 0x72, 0xd4, 0xb6,
  19335. 0x2e, 0xef, 0x37, 0xf9, 0xef, 0x07, 0x81, 0xf3,
  19336. 0x60, 0xb6, 0xc7, 0x4b, 0xe3, 0xbf, 0x6b, 0x37,
  19337. 0x10, 0x67, 0xbc, 0x1b, 0x09, 0x0d, 0x9d, 0x66,
  19338. 0x22, 0xa1, 0xfb, 0xec, 0x6a, 0xc4, 0x71, 0xb3,
  19339. 0x34, 0x9c, 0xd4, 0x27, 0x7a, 0x10, 0x1d, 0x40,
  19340. 0x89, 0x0f, 0xbf, 0x27, 0xdf, 0xdc, 0xd0, 0xb4,
  19341. 0xe3, 0x78, 0x1f, 0x98, 0x06, 0xda, 0xab, 0xb6}, 64,
  19342. /* tag, tag length */
  19343. {0xa0, 0x49, 0x87, 0x45, 0xe5, 0x99, 0x99, 0xdd,
  19344. 0xc3, 0x2d, 0x5b, 0x14, 0x02, 0x41, 0x12, 0x4e}, 16,
  19345. /* valid */
  19346. 1,
  19347. },
  19348. {
  19349. /* key, key length */
  19350. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19351. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19352. /* iv, iv length */
  19353. {0x4f, 0x80, 0x2d, 0xa6, 0x2a, 0x38, 0x45, 0x55,
  19354. 0xa1, 0x9b, 0xc2, 0xb3, 0x82, 0xeb, 0x25, 0xaf}, 16,
  19355. /* aad, aad length */
  19356. {0x00}, 0,
  19357. /* msg, msg length */
  19358. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19359. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19360. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19361. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19362. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19363. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19364. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  19365. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  19366. 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
  19367. 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44}, 80,
  19368. /* ct, ct length */
  19369. {0xe9, 0xb0, 0xbb, 0x88, 0x57, 0x81, 0x8c, 0xe3,
  19370. 0x20, 0x1c, 0x36, 0x90, 0xd2, 0x1d, 0xaa, 0x7f,
  19371. 0x26, 0x4f, 0xb8, 0xee, 0x93, 0xcc, 0x7a, 0x46,
  19372. 0x74, 0xea, 0x2f, 0xc3, 0x2b, 0xf1, 0x82, 0xfb,
  19373. 0x2a, 0x7e, 0x8a, 0xd5, 0x15, 0x07, 0xad, 0x4f,
  19374. 0x31, 0xce, 0xfc, 0x23, 0x56, 0xfe, 0x79, 0x36,
  19375. 0xa7, 0xf6, 0xe1, 0x9f, 0x95, 0xe8, 0x8f, 0xdb,
  19376. 0xf1, 0x76, 0x20, 0x91, 0x6d, 0x3a, 0x6f, 0x3d,
  19377. 0x01, 0xfc, 0x17, 0xd3, 0x58, 0x67, 0x2f, 0x77,
  19378. 0x7f, 0xd4, 0x09, 0x92, 0x46, 0xe4, 0x36, 0xe1}, 80,
  19379. /* tag, tag length */
  19380. {0x67, 0x91, 0x0b, 0xe7, 0x44, 0xb8, 0x31, 0x5a,
  19381. 0xe0, 0xeb, 0x61, 0x24, 0x59, 0x0c, 0x5d, 0x8b}, 16,
  19382. /* valid */
  19383. 1,
  19384. },
  19385. {
  19386. /* key, key length */
  19387. {0xb6, 0x7b, 0x1a, 0x6e, 0xfd, 0xd4, 0x0d, 0x37,
  19388. 0x08, 0x0f, 0xbe, 0x8f, 0x80, 0x47, 0xae, 0xb9}, 16,
  19389. /* iv, iv length */
  19390. {0xfa, 0x29, 0x4b, 0x12, 0x99, 0x72, 0xf7, 0xfc,
  19391. 0x5b, 0xbd, 0x5b, 0x96, 0xbb, 0xa8, 0x37, 0xc9}, 16,
  19392. /* aad, aad length */
  19393. {0x00}, 0,
  19394. /* msg, msg length */
  19395. {0x00}, 0,
  19396. /* ct, ct length */
  19397. {0x00}, 0,
  19398. /* tag, tag length */
  19399. {0xb1, 0x4b, 0x64, 0xfb, 0x58, 0x98, 0x99, 0x69,
  19400. 0x95, 0x70, 0xcc, 0x91, 0x60, 0xe3, 0x98, 0x96}, 16,
  19401. /* valid */
  19402. 1,
  19403. },
  19404. {
  19405. /* key, key length */
  19406. {0x20, 0x9e, 0x6d, 0xbf, 0x2a, 0xd2, 0x6a, 0x10,
  19407. 0x54, 0x45, 0xfc, 0x02, 0x07, 0xcd, 0x9e, 0x9a}, 16,
  19408. /* iv, iv length */
  19409. {0x94, 0x77, 0x84, 0x9d, 0x6c, 0xcd, 0xfc, 0xa1,
  19410. 0x12, 0xd9, 0x2e, 0x53, 0xfa, 0xe4, 0xa7, 0xca}, 16,
  19411. /* aad, aad length */
  19412. {0x00}, 0,
  19413. /* msg, msg length */
  19414. {0x01}, 1,
  19415. /* ct, ct length */
  19416. {0x1d}, 1,
  19417. /* tag, tag length */
  19418. {0x52, 0xa5, 0xf6, 0x00, 0xfe, 0x53, 0x38, 0x02,
  19419. 0x6a, 0x7c, 0xb0, 0x9c, 0x11, 0x64, 0x00, 0x82}, 16,
  19420. /* valid */
  19421. 1,
  19422. },
  19423. {
  19424. /* key, key length */
  19425. {0xa5, 0x49, 0x44, 0x2e, 0x35, 0x15, 0x40, 0x32,
  19426. 0xd0, 0x7c, 0x86, 0x66, 0x00, 0x6a, 0xa6, 0xa2}, 16,
  19427. /* iv, iv length */
  19428. {0x51, 0x71, 0x52, 0x45, 0x68, 0xe8, 0x1d, 0x97,
  19429. 0xe8, 0xc4, 0xde, 0x4b, 0xa5, 0x6c, 0x10, 0xa0}, 16,
  19430. /* aad, aad length */
  19431. {0x00}, 0,
  19432. /* msg, msg length */
  19433. {0x11, 0x82, 0xe9, 0x35, 0x96, 0xca, 0xc5, 0x60,
  19434. 0x89, 0x46, 0x40, 0x0b, 0xc7, 0x3f, 0x3a}, 15,
  19435. /* ct, ct length */
  19436. {0xd7, 0xb8, 0xa6, 0xb4, 0x3d, 0x2e, 0x9f, 0x98,
  19437. 0xc2, 0xb4, 0x4c, 0xe5, 0xe3, 0xcf, 0xdb}, 15,
  19438. /* tag, tag length */
  19439. {0x1b, 0xdd, 0x52, 0xfc, 0x98, 0x7d, 0xaf, 0x0e,
  19440. 0xe1, 0x92, 0x34, 0xc9, 0x05, 0xea, 0x64, 0x5f}, 16,
  19441. /* valid */
  19442. 1,
  19443. },
  19444. {
  19445. /* key, key length */
  19446. {0x95, 0x8b, 0xcd, 0xb6, 0x6a, 0x39, 0x52, 0xb5,
  19447. 0x37, 0x01, 0x58, 0x2a, 0x68, 0xa0, 0xe4, 0x74}, 16,
  19448. /* iv, iv length */
  19449. {0x0e, 0x6e, 0xc8, 0x79, 0xb0, 0x2c, 0x6f, 0x51,
  19450. 0x69, 0x76, 0xe3, 0x58, 0x98, 0x42, 0x8d, 0xa7}, 16,
  19451. /* aad, aad length */
  19452. {0x00}, 0,
  19453. /* msg, msg length */
  19454. {0x14, 0x04, 0x15, 0x82, 0x3e, 0xcc, 0x89, 0x32,
  19455. 0xa0, 0x58, 0x38, 0x4b, 0x73, 0x8e, 0xa6, 0xea,
  19456. 0x6d, 0x4d, 0xfe, 0x3b, 0xbe, 0xee}, 22,
  19457. /* ct, ct length */
  19458. {0x73, 0xe5, 0xc6, 0xf0, 0xe7, 0x03, 0xa5, 0x2d,
  19459. 0x02, 0xf7, 0xf7, 0xfa, 0xeb, 0x1b, 0x77, 0xfd,
  19460. 0x4f, 0xd0, 0xcb, 0x42, 0x1e, 0xaf}, 22,
  19461. /* tag, tag length */
  19462. {0x6c, 0x15, 0x4a, 0x85, 0x96, 0x8e, 0xdd, 0x74,
  19463. 0x77, 0x65, 0x75, 0xa4, 0x45, 0x0b, 0xd8, 0x97}, 16,
  19464. /* valid */
  19465. 1,
  19466. },
  19467. {
  19468. /* key, key length */
  19469. {0x96, 0x5b, 0x75, 0x7b, 0xa5, 0x01, 0x8a, 0x8d,
  19470. 0x66, 0xed, 0xc7, 0x8e, 0x0c, 0xee, 0xe8, 0x6b}, 16,
  19471. /* iv, iv length */
  19472. {0x2e, 0x35, 0x90, 0x1a, 0xe7, 0xd4, 0x91, 0xee,
  19473. 0xcc, 0x88, 0x38, 0xfe, 0xdd, 0x63, 0x14, 0x05}, 16,
  19474. /* aad, aad length */
  19475. {0xdf, 0x10, 0xd0, 0xd2, 0x12, 0x24, 0x24, 0x50}, 8,
  19476. /* msg, msg length */
  19477. {0x36, 0xe5, 0x7a, 0x76, 0x39, 0x58, 0xb0, 0x2c,
  19478. 0xea, 0x9d, 0x6a, 0x67, 0x6e, 0xbc, 0xe8, 0x1f}, 16,
  19479. /* ct, ct length */
  19480. {0x93, 0x6b, 0x69, 0xb6, 0xc9, 0x55, 0xad, 0xfd,
  19481. 0x15, 0x53, 0x9b, 0x9b, 0xe4, 0x98, 0x9c, 0xb6}, 16,
  19482. /* tag, tag length */
  19483. {0xee, 0x15, 0xa1, 0x45, 0x4e, 0x88, 0xfa, 0xad,
  19484. 0x8e, 0x48, 0xa8, 0xdf, 0x29, 0x83, 0xb4, 0x25}, 16,
  19485. /* valid */
  19486. 1,
  19487. },
  19488. {
  19489. /* key, key length */
  19490. {0x88, 0xd0, 0x20, 0x33, 0x78, 0x1c, 0x7b, 0x41,
  19491. 0x64, 0x71, 0x1a, 0x05, 0x42, 0x0f, 0x25, 0x6e}, 16,
  19492. /* iv, iv length */
  19493. {0x7f, 0x29, 0x85, 0x29, 0x63, 0x15, 0x50, 0x7a,
  19494. 0xa4, 0xc0, 0xa9, 0x3d, 0x5c, 0x12, 0xbd, 0x77}, 16,
  19495. /* aad, aad length */
  19496. {0x7c, 0x57, 0x1d, 0x2f, 0xbb, 0x5f, 0x62, 0x52,
  19497. 0x3c, 0x0e, 0xb3, 0x38, 0xbe, 0xf9, 0xa9}, 15,
  19498. /* msg, msg length */
  19499. {0xd9, 0x8a, 0xdc, 0x03, 0xd9, 0xd5, 0x82, 0x73,
  19500. 0x2e, 0xb0, 0x7d, 0xf2, 0x3d, 0x7b, 0x9f, 0x74}, 16,
  19501. /* ct, ct length */
  19502. {0x67, 0xca, 0xac, 0x35, 0x44, 0x3a, 0x31, 0x38,
  19503. 0xd2, 0xcb, 0x81, 0x1f, 0x0c, 0xe0, 0x4d, 0xd2}, 16,
  19504. /* tag, tag length */
  19505. {0xb7, 0x96, 0x8e, 0x0b, 0x56, 0x40, 0xe3, 0xb2,
  19506. 0x36, 0x56, 0x96, 0x53, 0x20, 0x8b, 0x9d, 0xeb}, 16,
  19507. /* valid */
  19508. 1,
  19509. },
  19510. {
  19511. /* key, key length */
  19512. {0x51, 0x58, 0x40, 0xcf, 0x67, 0xd2, 0xe4, 0x0e,
  19513. 0xb6, 0x5e, 0x54, 0xa2, 0x4c, 0x72, 0xcb, 0xf2}, 16,
  19514. /* iv, iv length */
  19515. {0xbf, 0x47, 0xaf, 0xdf, 0xd4, 0x92, 0x13, 0x7a,
  19516. 0x24, 0x23, 0x6b, 0xc3, 0x67, 0x97, 0xa8, 0x8e}, 16,
  19517. /* aad, aad length */
  19518. {0x16, 0x84, 0x3c, 0x09, 0x1d, 0x43, 0xb0, 0xa1,
  19519. 0x91, 0xd0, 0xc7, 0x3d, 0x15, 0x60, 0x1b, 0xe9}, 16,
  19520. /* msg, msg length */
  19521. {0xc8, 0x34, 0x58, 0x8c, 0xb6, 0xda, 0xf9, 0xf0,
  19522. 0x6d, 0xd2, 0x35, 0x19, 0xf4, 0xbe, 0x9f, 0x56}, 16,
  19523. /* ct, ct length */
  19524. {0x20, 0x0a, 0xc4, 0x51, 0xfb, 0xeb, 0x0f, 0x61,
  19525. 0x51, 0xd6, 0x15, 0x83, 0xa4, 0x3b, 0x73, 0x43}, 16,
  19526. /* tag, tag length */
  19527. {0x2a, 0xd4, 0x3e, 0x4c, 0xaa, 0x51, 0x98, 0x3a,
  19528. 0x9d, 0x4d, 0x24, 0x48, 0x1b, 0xf4, 0xc8, 0x39}, 16,
  19529. /* valid */
  19530. 1,
  19531. },
  19532. {
  19533. /* key, key length */
  19534. {0x2e, 0x44, 0x92, 0xd4, 0x44, 0xe5, 0xb6, 0xf4,
  19535. 0xce, 0xc8, 0xc2, 0xd3, 0x61, 0x5a, 0xc8, 0x58}, 16,
  19536. /* iv, iv length */
  19537. {0xd0, 0x2b, 0xf0, 0x76, 0x3a, 0x9f, 0xef, 0xbf,
  19538. 0x70, 0xc3, 0x3a, 0xee, 0x1e, 0x9d, 0xa1, 0xd6}, 16,
  19539. /* aad, aad length */
  19540. {0x90, 0x4d, 0x86, 0xf1, 0x33, 0xce, 0xc1, 0x5a,
  19541. 0x0c, 0x3c, 0xaf, 0x14, 0xd7, 0xe0, 0x29, 0xc8,
  19542. 0x2a, 0x07, 0x70, 0x5a, 0x23, 0xf0, 0xd0, 0x80}, 24,
  19543. /* msg, msg length */
  19544. {0x9e, 0x62, 0xd6, 0x51, 0x1b, 0x0b, 0xda, 0x7d,
  19545. 0xd7, 0x74, 0x0b, 0x61, 0x4d, 0x97, 0xba, 0xe0}, 16,
  19546. /* ct, ct length */
  19547. {0x27, 0xc6, 0xe9, 0xa6, 0x53, 0xc5, 0x25, 0x3c,
  19548. 0xa1, 0xc5, 0x67, 0x3f, 0x97, 0xb9, 0xb3, 0x3e}, 16,
  19549. /* tag, tag length */
  19550. {0x2d, 0x58, 0x12, 0x71, 0xe1, 0xfa, 0x9e, 0x36,
  19551. 0x86, 0x13, 0x6c, 0xaa, 0x8f, 0x4d, 0x6c, 0x8e}, 16,
  19552. /* valid */
  19553. 1,
  19554. },
  19555. {
  19556. /* key, key length */
  19557. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19558. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19559. /* iv, iv length */
  19560. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19561. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19562. /* aad, aad length */
  19563. {0x00}, 0,
  19564. /* msg, msg length */
  19565. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19566. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19567. /* ct, ct length */
  19568. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19569. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19570. /* tag, tag length */
  19571. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19572. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19573. /* valid */
  19574. 0,
  19575. },
  19576. {
  19577. /* key, key length */
  19578. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19579. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19580. /* iv, iv length */
  19581. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19582. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19583. /* aad, aad length */
  19584. {0x00}, 0,
  19585. /* msg, msg length */
  19586. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19587. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19588. /* ct, ct length */
  19589. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19590. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19591. /* tag, tag length */
  19592. {0xe4, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19593. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19594. /* valid */
  19595. 0,
  19596. },
  19597. {
  19598. /* key, key length */
  19599. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19600. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19601. /* iv, iv length */
  19602. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19603. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19604. /* aad, aad length */
  19605. {0x00}, 0,
  19606. /* msg, msg length */
  19607. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19608. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19609. /* ct, ct length */
  19610. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19611. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19612. /* tag, tag length */
  19613. {0x66, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19614. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19615. /* valid */
  19616. 0,
  19617. },
  19618. {
  19619. /* key, key length */
  19620. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19621. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19622. /* iv, iv length */
  19623. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19624. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19625. /* aad, aad length */
  19626. {0x00}, 0,
  19627. /* msg, msg length */
  19628. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19629. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19630. /* ct, ct length */
  19631. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19632. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19633. /* tag, tag length */
  19634. {0xe6, 0x0f, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19635. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19636. /* valid */
  19637. 0,
  19638. },
  19639. {
  19640. /* key, key length */
  19641. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19642. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19643. /* iv, iv length */
  19644. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19645. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19646. /* aad, aad length */
  19647. {0x00}, 0,
  19648. /* msg, msg length */
  19649. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19650. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19651. /* ct, ct length */
  19652. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19653. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19654. /* tag, tag length */
  19655. {0xe6, 0x0e, 0x7c, 0xd0, 0x13, 0xa6, 0xdb, 0xf2,
  19656. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19657. /* valid */
  19658. 0,
  19659. },
  19660. {
  19661. /* key, key length */
  19662. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19663. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19664. /* iv, iv length */
  19665. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19666. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19667. /* aad, aad length */
  19668. {0x00}, 0,
  19669. /* msg, msg length */
  19670. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19671. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19672. /* ct, ct length */
  19673. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19674. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19675. /* tag, tag length */
  19676. {0xe6, 0x0e, 0x7c, 0x50, 0x12, 0xa6, 0xdb, 0xf2,
  19677. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19678. /* valid */
  19679. 0,
  19680. },
  19681. {
  19682. /* key, key length */
  19683. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19684. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19685. /* iv, iv length */
  19686. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19687. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19688. /* aad, aad length */
  19689. {0x00}, 0,
  19690. /* msg, msg length */
  19691. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19692. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19693. /* ct, ct length */
  19694. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19695. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19696. /* tag, tag length */
  19697. {0xe6, 0x0e, 0x7c, 0x50, 0x11, 0xa6, 0xdb, 0xf2,
  19698. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19699. /* valid */
  19700. 0,
  19701. },
  19702. {
  19703. /* key, key length */
  19704. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19705. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19706. /* iv, iv length */
  19707. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19708. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19709. /* aad, aad length */
  19710. {0x00}, 0,
  19711. /* msg, msg length */
  19712. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19713. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19714. /* ct, ct length */
  19715. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19716. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19717. /* tag, tag length */
  19718. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0x72,
  19719. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19720. /* valid */
  19721. 0,
  19722. },
  19723. {
  19724. /* key, key length */
  19725. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19726. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19727. /* iv, iv length */
  19728. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19729. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19730. /* aad, aad length */
  19731. {0x00}, 0,
  19732. /* msg, msg length */
  19733. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19734. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19735. /* ct, ct length */
  19736. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19737. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19738. /* tag, tag length */
  19739. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19740. 0x53, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19741. /* valid */
  19742. 0,
  19743. },
  19744. {
  19745. /* key, key length */
  19746. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19747. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19748. /* iv, iv length */
  19749. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19750. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19751. /* aad, aad length */
  19752. {0x00}, 0,
  19753. /* msg, msg length */
  19754. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19755. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19756. /* ct, ct length */
  19757. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19758. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19759. /* tag, tag length */
  19760. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19761. 0xd2, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19762. /* valid */
  19763. 0,
  19764. },
  19765. {
  19766. /* key, key length */
  19767. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19768. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19769. /* iv, iv length */
  19770. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19771. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19772. /* aad, aad length */
  19773. {0x00}, 0,
  19774. /* msg, msg length */
  19775. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19776. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19777. /* ct, ct length */
  19778. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19779. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19780. /* tag, tag length */
  19781. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19782. 0x52, 0xb8, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19783. /* valid */
  19784. 0,
  19785. },
  19786. {
  19787. /* key, key length */
  19788. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19789. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19790. /* iv, iv length */
  19791. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19792. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19793. /* aad, aad length */
  19794. {0x00}, 0,
  19795. /* msg, msg length */
  19796. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19797. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19798. /* ct, ct length */
  19799. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19800. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19801. /* tag, tag length */
  19802. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19803. 0x52, 0x98, 0xb0, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19804. /* valid */
  19805. 0,
  19806. },
  19807. {
  19808. /* key, key length */
  19809. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19810. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19811. /* iv, iv length */
  19812. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19813. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19814. /* aad, aad length */
  19815. {0x00}, 0,
  19816. /* msg, msg length */
  19817. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19818. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19819. /* ct, ct length */
  19820. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19821. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19822. /* tag, tag length */
  19823. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19824. 0x52, 0x98, 0xb1, 0x92, 0x9a, 0xc3, 0x56, 0xa7}, 16,
  19825. /* valid */
  19826. 0,
  19827. },
  19828. {
  19829. /* key, key length */
  19830. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19831. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19832. /* iv, iv length */
  19833. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19834. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19835. /* aad, aad length */
  19836. {0x00}, 0,
  19837. /* msg, msg length */
  19838. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19839. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19840. /* ct, ct length */
  19841. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19842. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19843. /* tag, tag length */
  19844. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19845. 0x52, 0x98, 0xb1, 0x92, 0x99, 0xc3, 0x56, 0xa7}, 16,
  19846. /* valid */
  19847. 0,
  19848. },
  19849. {
  19850. /* key, key length */
  19851. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19852. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19853. /* iv, iv length */
  19854. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19855. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19856. /* aad, aad length */
  19857. {0x00}, 0,
  19858. /* msg, msg length */
  19859. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19860. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19861. /* ct, ct length */
  19862. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19863. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19864. /* tag, tag length */
  19865. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19866. 0x52, 0x98, 0xb1, 0x92, 0x1b, 0xc3, 0x56, 0xa7}, 16,
  19867. /* valid */
  19868. 0,
  19869. },
  19870. {
  19871. /* key, key length */
  19872. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19873. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19874. /* iv, iv length */
  19875. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19876. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19877. /* aad, aad length */
  19878. {0x00}, 0,
  19879. /* msg, msg length */
  19880. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19881. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19882. /* ct, ct length */
  19883. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19884. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19885. /* tag, tag length */
  19886. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19887. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa6}, 16,
  19888. /* valid */
  19889. 0,
  19890. },
  19891. {
  19892. /* key, key length */
  19893. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19894. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19895. /* iv, iv length */
  19896. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19897. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19898. /* aad, aad length */
  19899. {0x00}, 0,
  19900. /* msg, msg length */
  19901. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19902. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19903. /* ct, ct length */
  19904. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19905. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19906. /* tag, tag length */
  19907. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19908. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa5}, 16,
  19909. /* valid */
  19910. 0,
  19911. },
  19912. {
  19913. /* key, key length */
  19914. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19915. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19916. /* iv, iv length */
  19917. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19918. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19919. /* aad, aad length */
  19920. {0x00}, 0,
  19921. /* msg, msg length */
  19922. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19923. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19924. /* ct, ct length */
  19925. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19926. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19927. /* tag, tag length */
  19928. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19929. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xe7}, 16,
  19930. /* valid */
  19931. 0,
  19932. },
  19933. {
  19934. /* key, key length */
  19935. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19936. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19937. /* iv, iv length */
  19938. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19939. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19940. /* aad, aad length */
  19941. {0x00}, 0,
  19942. /* msg, msg length */
  19943. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19944. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19945. /* ct, ct length */
  19946. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19947. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19948. /* tag, tag length */
  19949. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19950. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0x27}, 16,
  19951. /* valid */
  19952. 0,
  19953. },
  19954. {
  19955. /* key, key length */
  19956. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19957. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19958. /* iv, iv length */
  19959. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19960. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19961. /* aad, aad length */
  19962. {0x00}, 0,
  19963. /* msg, msg length */
  19964. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19965. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19966. /* ct, ct length */
  19967. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19968. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19969. /* tag, tag length */
  19970. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19971. 0x53, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19972. /* valid */
  19973. 0,
  19974. },
  19975. {
  19976. /* key, key length */
  19977. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19978. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19979. /* iv, iv length */
  19980. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19981. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19982. /* aad, aad length */
  19983. {0x00}, 0,
  19984. /* msg, msg length */
  19985. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19986. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19987. /* ct, ct length */
  19988. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19989. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19990. /* tag, tag length */
  19991. {0xe6, 0x0e, 0x7c, 0xd0, 0x13, 0xa6, 0xdb, 0x72,
  19992. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19993. /* valid */
  19994. 0,
  19995. },
  19996. {
  19997. /* key, key length */
  19998. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19999. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20000. /* iv, iv length */
  20001. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20002. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20003. /* aad, aad length */
  20004. {0x00}, 0,
  20005. /* msg, msg length */
  20006. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20007. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20008. /* ct, ct length */
  20009. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20010. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20011. /* tag, tag length */
  20012. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0x72,
  20013. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0x27}, 16,
  20014. /* valid */
  20015. 0,
  20016. },
  20017. {
  20018. /* key, key length */
  20019. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20020. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20021. /* iv, iv length */
  20022. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20023. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20024. /* aad, aad length */
  20025. {0x00}, 0,
  20026. /* msg, msg length */
  20027. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20028. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20029. /* ct, ct length */
  20030. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20031. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20032. /* tag, tag length */
  20033. {0x19, 0xf1, 0x83, 0xaf, 0xec, 0x59, 0x24, 0x0d,
  20034. 0xad, 0x67, 0x4e, 0x6d, 0x64, 0x3c, 0xa9, 0x58}, 16,
  20035. /* valid */
  20036. 0,
  20037. },
  20038. {
  20039. /* key, key length */
  20040. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20041. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20042. /* iv, iv length */
  20043. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20044. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20045. /* aad, aad length */
  20046. {0x00}, 0,
  20047. /* msg, msg length */
  20048. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20049. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20050. /* ct, ct length */
  20051. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20052. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20053. /* tag, tag length */
  20054. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  20055. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 16,
  20056. /* valid */
  20057. 0,
  20058. },
  20059. {
  20060. /* key, key length */
  20061. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20062. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20063. /* iv, iv length */
  20064. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20065. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20066. /* aad, aad length */
  20067. {0x00}, 0,
  20068. /* msg, msg length */
  20069. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20070. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20071. /* ct, ct length */
  20072. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20073. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20074. /* tag, tag length */
  20075. {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  20076. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 16,
  20077. /* valid */
  20078. 0,
  20079. },
  20080. {
  20081. /* key, key length */
  20082. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20083. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20084. /* iv, iv length */
  20085. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20086. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20087. /* aad, aad length */
  20088. {0x00}, 0,
  20089. /* msg, msg length */
  20090. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20091. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20092. /* ct, ct length */
  20093. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20094. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20095. /* tag, tag length */
  20096. {0x66, 0x8e, 0xfc, 0xd0, 0x93, 0x26, 0x5b, 0x72,
  20097. 0xd2, 0x18, 0x31, 0x12, 0x1b, 0x43, 0xd6, 0x27}, 16,
  20098. /* valid */
  20099. 0,
  20100. },
  20101. {
  20102. /* key, key length */
  20103. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20104. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20105. /* iv, iv length */
  20106. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20107. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20108. /* aad, aad length */
  20109. {0x00}, 0,
  20110. /* msg, msg length */
  20111. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20112. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20113. /* ct, ct length */
  20114. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20115. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20116. /* tag, tag length */
  20117. {0xe7, 0x0f, 0x7d, 0x51, 0x12, 0xa7, 0xda, 0xf3,
  20118. 0x53, 0x99, 0xb0, 0x93, 0x9a, 0xc2, 0x57, 0xa6}, 16,
  20119. /* valid */
  20120. 0,
  20121. },
  20122. };
  20123. byte ciphertext[sizeof(vectors[0].ct)];
  20124. byte authtag[sizeof(vectors[0].tag)];
  20125. int i;
  20126. int len;
  20127. int ret;
  20128. for (i = 0; i < (int)(sizeof(vectors)/sizeof(vectors[0])); i++) {
  20129. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  20130. len = sizeof(authtag);
  20131. ExpectIntEQ(wc_AesEaxEncryptAuth(vectors[i].key, vectors[i].key_length,
  20132. ciphertext,
  20133. vectors[i].msg, vectors[i].msg_length,
  20134. vectors[i].iv, vectors[i].iv_length,
  20135. authtag, len,
  20136. vectors[i].aad, vectors[i].aad_length),
  20137. 0);
  20138. /* check ciphertext matches vector */
  20139. ExpectIntEQ(XMEMCMP(ciphertext, vectors[i].ct, vectors[i].ct_length),
  20140. 0);
  20141. /* check that computed tag matches vector only for vectors marked as valid */
  20142. ret = XMEMCMP(authtag, vectors[i].tag, len);
  20143. if (vectors[i].valid) {
  20144. ExpectIntEQ(ret, 0);
  20145. }
  20146. else {
  20147. ExpectIntNE(ret, 0);
  20148. }
  20149. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  20150. /* Decrypt, checking that the computed auth tags match */
  20151. ExpectIntEQ(wc_AesEaxDecryptAuth(vectors[i].key, vectors[i].key_length,
  20152. ciphertext,
  20153. vectors[i].ct, vectors[i].ct_length,
  20154. vectors[i].iv, vectors[i].iv_length,
  20155. authtag, len,
  20156. vectors[i].aad, vectors[i].aad_length),
  20157. 0);
  20158. /* check decrypted ciphertext matches vector plaintext */
  20159. ExpectIntEQ(XMEMCMP(ciphertext, vectors[i].msg, vectors[i].msg_length),
  20160. 0);
  20161. }
  20162. return EXPECT_RESULT();
  20163. } /* END test_wc_AesEaxVectors */
  20164. /*
  20165. * Testing test_wc_AesEaxEncryptAuth()
  20166. */
  20167. static int test_wc_AesEaxEncryptAuth(void)
  20168. {
  20169. EXPECT_DECLS;
  20170. const byte key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20171. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  20172. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  20173. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  20174. const byte iv[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20175. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  20176. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  20177. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  20178. const byte aad[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  20179. const byte msg[] = {0x00, 0x01, 0x02, 0x03, 0x04};
  20180. byte ciphertext[sizeof(msg)];
  20181. byte authtag[AES_BLOCK_SIZE];
  20182. int i;
  20183. int len;
  20184. len = sizeof(authtag);
  20185. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20186. ciphertext,
  20187. msg, sizeof(msg),
  20188. iv, sizeof(iv),
  20189. authtag, (word32)len,
  20190. aad, sizeof(aad)),
  20191. 0);
  20192. /* Test null checking */
  20193. ExpectIntEQ(wc_AesEaxEncryptAuth(NULL, sizeof(key),
  20194. ciphertext,
  20195. msg, sizeof(msg),
  20196. iv, sizeof(iv),
  20197. authtag, (word32)len,
  20198. aad, sizeof(aad)),
  20199. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20200. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20201. NULL,
  20202. msg, sizeof(msg),
  20203. iv, sizeof(iv),
  20204. authtag, (word32)len,
  20205. aad, sizeof(aad)),
  20206. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20207. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20208. ciphertext,
  20209. NULL, sizeof(msg),
  20210. iv, sizeof(iv),
  20211. authtag, (word32)len,
  20212. aad, sizeof(aad)),
  20213. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20214. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20215. ciphertext,
  20216. msg, sizeof(msg),
  20217. NULL, sizeof(iv),
  20218. authtag, (word32)len,
  20219. aad, sizeof(aad)),
  20220. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20221. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20222. ciphertext,
  20223. msg, sizeof(msg),
  20224. iv, sizeof(iv),
  20225. NULL, (word32)len,
  20226. aad, sizeof(aad)),
  20227. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20228. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20229. ciphertext,
  20230. msg, sizeof(msg),
  20231. iv, sizeof(iv),
  20232. authtag, (word32)len,
  20233. NULL, sizeof(aad)),
  20234. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20235. /* Test bad key lengths */
  20236. for (i = 0; i <= 32; i++) {
  20237. int exp_ret;
  20238. if (i == AES_128_KEY_SIZE || i == AES_192_KEY_SIZE
  20239. || i == AES_256_KEY_SIZE) {
  20240. exp_ret = 0;
  20241. }
  20242. else {
  20243. exp_ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG);
  20244. }
  20245. ExpectIntEQ(wc_AesEaxEncryptAuth(key, (word32)i,
  20246. ciphertext,
  20247. msg, sizeof(msg),
  20248. iv, sizeof(iv),
  20249. authtag, (word32)len,
  20250. aad, sizeof(aad)),
  20251. exp_ret);
  20252. }
  20253. /* Test auth tag size out of range */
  20254. len = AES_BLOCK_SIZE + 1;
  20255. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20256. ciphertext,
  20257. msg, sizeof(msg),
  20258. iv, sizeof(iv),
  20259. authtag, (word32)len,
  20260. aad, sizeof(aad)),
  20261. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20262. return EXPECT_RESULT();
  20263. } /* END test_wc_AesEaxEncryptAuth() */
  20264. /*
  20265. * Testing test_wc_AesEaxDecryptAuth()
  20266. */
  20267. static int test_wc_AesEaxDecryptAuth(void)
  20268. {
  20269. EXPECT_DECLS;
  20270. const byte key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20271. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  20272. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  20273. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  20274. const byte iv[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20275. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  20276. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  20277. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  20278. const byte aad[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  20279. const byte ct[] = {0x00, 0x01, 0x02, 0x03, 0x04};
  20280. /* Garbage tag that should always fail for above aad */
  20281. const byte tag[] = {0xFE, 0xED, 0xBE, 0xEF, 0xDE, 0xAD, 0xC0, 0xDE,
  20282. 0xCA, 0xFE, 0xBE, 0xEF, 0xDE, 0xAF, 0xBE, 0xEF};
  20283. byte plaintext[sizeof(ct)];
  20284. int i;
  20285. int len;
  20286. len = sizeof(tag);
  20287. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20288. plaintext,
  20289. ct, sizeof(ct),
  20290. iv, sizeof(iv),
  20291. tag, (word32)len,
  20292. aad, sizeof(aad)),
  20293. WC_NO_ERR_TRACE(AES_EAX_AUTH_E));
  20294. /* Test null checking */
  20295. ExpectIntEQ(wc_AesEaxDecryptAuth(NULL, sizeof(key),
  20296. plaintext,
  20297. ct, sizeof(ct),
  20298. iv, sizeof(iv),
  20299. tag, (word32)len,
  20300. aad, sizeof(aad)),
  20301. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20302. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20303. NULL,
  20304. ct, sizeof(ct),
  20305. iv, sizeof(iv),
  20306. tag, (word32)len,
  20307. aad, sizeof(aad)),
  20308. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20309. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20310. plaintext,
  20311. NULL, sizeof(ct),
  20312. iv, sizeof(iv),
  20313. tag, (word32)len,
  20314. aad, sizeof(aad)),
  20315. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20316. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20317. plaintext,
  20318. ct, sizeof(ct),
  20319. NULL, sizeof(iv),
  20320. tag, (word32)len,
  20321. aad, sizeof(aad)),
  20322. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20323. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20324. plaintext,
  20325. ct, sizeof(ct),
  20326. iv, sizeof(iv),
  20327. NULL, (word32)len,
  20328. aad, sizeof(aad)),
  20329. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20330. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20331. plaintext,
  20332. ct, sizeof(ct),
  20333. iv, sizeof(iv),
  20334. tag, (word32)len,
  20335. NULL, sizeof(aad)),
  20336. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20337. /* Test bad key lengths */
  20338. for (i = 0; i <= 32; i++) {
  20339. int exp_ret;
  20340. if (i == AES_128_KEY_SIZE || i == AES_192_KEY_SIZE
  20341. || i == AES_256_KEY_SIZE) {
  20342. exp_ret = WC_NO_ERR_TRACE(AES_EAX_AUTH_E);
  20343. }
  20344. else {
  20345. exp_ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG);
  20346. }
  20347. ExpectIntEQ(wc_AesEaxDecryptAuth(key, (word32)i,
  20348. plaintext,
  20349. ct, sizeof(ct),
  20350. iv, sizeof(iv),
  20351. tag, (word32)len,
  20352. aad, sizeof(aad)),
  20353. exp_ret);
  20354. }
  20355. /* Test auth tag size out of range */
  20356. len = AES_BLOCK_SIZE + 1;
  20357. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20358. plaintext,
  20359. ct, sizeof(ct),
  20360. iv, sizeof(iv),
  20361. tag, (word32)len,
  20362. aad, sizeof(aad)),
  20363. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20364. return EXPECT_RESULT();
  20365. } /* END test_wc_AesEaxDecryptAuth() */
  20366. #endif /* WOLFSSL_AES_EAX &&
  20367. * (!HAVE_FIPS || FIPS_VERSION_GE(5, 3)) && !HAVE_SELFTEST
  20368. */
  20369. /*
  20370. * Testing wc_InitDsaKey()
  20371. */
  20372. static int test_wc_InitDsaKey(void)
  20373. {
  20374. EXPECT_DECLS;
  20375. #ifndef NO_DSA
  20376. DsaKey key;
  20377. XMEMSET(&key, 0, sizeof(DsaKey));
  20378. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20379. /* Pass in bad args. */
  20380. ExpectIntEQ(wc_InitDsaKey(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20381. wc_FreeDsaKey(&key);
  20382. #endif
  20383. return EXPECT_RESULT();
  20384. } /* END test_wc_InitDsaKey */
  20385. /*
  20386. * Testing wc_DsaSign() and wc_DsaVerify()
  20387. */
  20388. static int test_wc_DsaSignVerify(void)
  20389. {
  20390. EXPECT_DECLS;
  20391. #if !defined(NO_DSA)
  20392. DsaKey key;
  20393. WC_RNG rng;
  20394. wc_Sha sha;
  20395. byte signature[DSA_SIG_SIZE];
  20396. byte hash[WC_SHA_DIGEST_SIZE];
  20397. word32 idx = 0;
  20398. word32 bytes;
  20399. int answer;
  20400. #ifdef USE_CERT_BUFFERS_1024
  20401. byte tmp[ONEK_BUF];
  20402. XMEMSET(tmp, 0, sizeof(tmp));
  20403. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20404. bytes = sizeof_dsa_key_der_1024;
  20405. #elif defined(USE_CERT_BUFFERS_2048)
  20406. byte tmp[TWOK_BUF];
  20407. XMEMSET(tmp, 0, sizeof(tmp));
  20408. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20409. bytes = sizeof_dsa_key_der_2048;
  20410. #else
  20411. byte tmp[TWOK_BUF];
  20412. XFILE fp = XBADFILE;
  20413. XMEMSET(tmp, 0, sizeof(tmp));
  20414. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  20415. ExpectTrue((bytes = (word32)XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  20416. if (fp != XBADFILE)
  20417. XFCLOSE(fp);
  20418. #endif /* END USE_CERT_BUFFERS_1024 */
  20419. ExpectIntEQ(wc_InitSha(&sha), 0);
  20420. ExpectIntEQ(wc_ShaUpdate(&sha, tmp, bytes), 0);
  20421. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  20422. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20423. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20424. ExpectIntEQ(wc_InitRng(&rng), 0);
  20425. /* Sign. */
  20426. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), 0);
  20427. /* Test bad args. */
  20428. ExpectIntEQ(wc_DsaSign(NULL, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20429. ExpectIntEQ(wc_DsaSign(hash, NULL, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20430. ExpectIntEQ(wc_DsaSign(hash, signature, NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20431. ExpectIntEQ(wc_DsaSign(hash, signature, &key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20432. /* Verify. */
  20433. ExpectIntEQ(wc_DsaVerify(hash, signature, &key, &answer), 0);
  20434. ExpectIntEQ(answer, 1);
  20435. /* Pass in bad args. */
  20436. ExpectIntEQ(wc_DsaVerify(NULL, signature, &key, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20437. ExpectIntEQ(wc_DsaVerify(hash, NULL, &key, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20438. ExpectIntEQ(wc_DsaVerify(hash, signature, NULL, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20439. ExpectIntEQ(wc_DsaVerify(hash, signature, &key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20440. #if !defined(HAVE_FIPS) && defined(WOLFSSL_PUBLIC_MP)
  20441. /* hard set q to 0 and test fail case */
  20442. mp_free(&key.q);
  20443. mp_init(&key.q);
  20444. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20445. mp_set(&key.q, 1);
  20446. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20447. #endif
  20448. DoExpectIntEQ(wc_FreeRng(&rng),0);
  20449. wc_FreeDsaKey(&key);
  20450. wc_ShaFree(&sha);
  20451. #endif
  20452. return EXPECT_RESULT();
  20453. } /* END test_wc_DsaSign */
  20454. /*
  20455. * Testing wc_DsaPrivateKeyDecode() and wc_DsaPublicKeyDecode()
  20456. */
  20457. static int test_wc_DsaPublicPrivateKeyDecode(void)
  20458. {
  20459. EXPECT_DECLS;
  20460. #if !defined(NO_DSA)
  20461. DsaKey key;
  20462. word32 bytes = 0;
  20463. word32 idx = 0;
  20464. int ret = 0;
  20465. #ifdef USE_CERT_BUFFERS_1024
  20466. byte tmp[ONEK_BUF];
  20467. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20468. bytes = sizeof_dsa_key_der_1024;
  20469. #elif defined(USE_CERT_BUFFERS_2048)
  20470. byte tmp[TWOK_BUF];
  20471. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20472. bytes = sizeof_dsa_key_der_2048;
  20473. #else
  20474. byte tmp[TWOK_BUF];
  20475. XFILE fp = XBADFILE;
  20476. XMEMSET(tmp, 0, sizeof(tmp));
  20477. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  20478. ExpectTrue((bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  20479. if (fp != XBADFILE)
  20480. XFCLOSE(fp);
  20481. #endif /* END USE_CERT_BUFFERS_1024 */
  20482. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20483. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20484. /* Test bad args. */
  20485. ExpectIntEQ(wc_DsaPrivateKeyDecode(NULL, &idx, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20486. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, NULL, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20487. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, NULL, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20488. ExpectIntLT(ret = wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20489. ExpectTrue((ret == WC_NO_ERR_TRACE(ASN_PARSE_E)) || (ret == WC_NO_ERR_TRACE(BUFFER_E)));
  20490. wc_FreeDsaKey(&key);
  20491. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20492. idx = 0; /* Reset */
  20493. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, &idx, &key, bytes), 0);
  20494. /* Test bad args. */
  20495. ExpectIntEQ(wc_DsaPublicKeyDecode(NULL, &idx, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20496. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, NULL, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20497. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, &idx, NULL, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20498. ExpectIntLT(ret = wc_DsaPublicKeyDecode(tmp, &idx, &key, bytes), 0);
  20499. ExpectTrue((ret == WC_NO_ERR_TRACE(ASN_PARSE_E)) || (ret == WC_NO_ERR_TRACE(BUFFER_E)));
  20500. wc_FreeDsaKey(&key);
  20501. #endif /* !NO_DSA */
  20502. return EXPECT_RESULT();
  20503. } /* END test_wc_DsaPublicPrivateKeyDecode */
  20504. /*
  20505. * Testing wc_MakeDsaKey() and wc_MakeDsaParameters()
  20506. */
  20507. static int test_wc_MakeDsaKey(void)
  20508. {
  20509. EXPECT_DECLS;
  20510. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20511. DsaKey genKey;
  20512. WC_RNG rng;
  20513. XMEMSET(&genKey, 0, sizeof(genKey));
  20514. XMEMSET(&rng, 0, sizeof(rng));
  20515. ExpectIntEQ(wc_InitDsaKey(&genKey), 0);
  20516. ExpectIntEQ(wc_InitRng(&rng), 0);
  20517. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, &genKey), 0);
  20518. /* Test bad args. */
  20519. ExpectIntEQ(wc_MakeDsaParameters(NULL, ONEK_BUF, &genKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20520. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20521. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF + 1, &genKey),
  20522. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20523. ExpectIntEQ(wc_MakeDsaKey(&rng, &genKey), 0);
  20524. /* Test bad args. */
  20525. ExpectIntEQ(wc_MakeDsaKey(NULL, &genKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20526. ExpectIntEQ(wc_MakeDsaKey(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20527. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20528. wc_FreeDsaKey(&genKey);
  20529. #endif
  20530. return EXPECT_RESULT();
  20531. } /* END test_wc_MakeDsaKey */
  20532. /*
  20533. * Testing wc_DsaKeyToDer()
  20534. */
  20535. static int test_wc_DsaKeyToDer(void)
  20536. {
  20537. EXPECT_DECLS;
  20538. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20539. DsaKey key;
  20540. word32 bytes;
  20541. word32 idx = 0;
  20542. #ifdef USE_CERT_BUFFERS_1024
  20543. byte tmp[ONEK_BUF];
  20544. byte der[ONEK_BUF];
  20545. XMEMSET(tmp, 0, sizeof(tmp));
  20546. XMEMSET(der, 0, sizeof(der));
  20547. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20548. bytes = sizeof_dsa_key_der_1024;
  20549. #elif defined(USE_CERT_BUFFERS_2048)
  20550. byte tmp[TWOK_BUF];
  20551. byte der[TWOK_BUF];
  20552. XMEMSET(tmp, 0, sizeof(tmp));
  20553. XMEMSET(der, 0, sizeof(der));
  20554. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20555. bytes = sizeof_dsa_key_der_2048;
  20556. #else
  20557. byte tmp[TWOK_BUF];
  20558. byte der[TWOK_BUF];
  20559. XFILE fp = XBADFILE;
  20560. XMEMSET(tmp, 0, sizeof(tmp));
  20561. XMEMSET(der, 0, sizeof(der));
  20562. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  20563. ExpectTrue((bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  20564. if (fp != XBADFILE)
  20565. XFCLOSE(fp);
  20566. #endif /* END USE_CERT_BUFFERS_1024 */
  20567. XMEMSET(&key, 0, sizeof(DsaKey));
  20568. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20569. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20570. ExpectIntGE(wc_DsaKeyToDer(&key, der, bytes), 0);
  20571. ExpectIntEQ(XMEMCMP(der, tmp, bytes), 0);
  20572. /* Test bad args. */
  20573. ExpectIntEQ(wc_DsaKeyToDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20574. ExpectIntEQ(wc_DsaKeyToDer(&key, NULL, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20575. wc_FreeDsaKey(&key);
  20576. #endif /* !NO_DSA && WOLFSSL_KEY_GEN */
  20577. return EXPECT_RESULT();
  20578. } /* END test_wc_DsaKeyToDer */
  20579. /*
  20580. * Testing wc_DsaKeyToPublicDer()
  20581. * (indirectly testing setDsaPublicKey())
  20582. */
  20583. static int test_wc_DsaKeyToPublicDer(void)
  20584. {
  20585. EXPECT_DECLS;
  20586. #ifndef HAVE_SELFTEST
  20587. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20588. DsaKey key;
  20589. WC_RNG rng;
  20590. byte* der = NULL;
  20591. word32 sz = 0;
  20592. word32 idx = 0;
  20593. XMEMSET(&key, 0, sizeof(DsaKey));
  20594. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20595. ExpectNotNull(der = (byte*)XMALLOC(ONEK_BUF, NULL,
  20596. DYNAMIC_TYPE_TMP_BUFFER));
  20597. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20598. ExpectIntEQ(wc_InitRng(&rng), 0);
  20599. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, &key), 0);
  20600. ExpectIntEQ(wc_MakeDsaKey(&rng, &key), 0);
  20601. ExpectIntGE(sz = (word32)wc_DsaKeyToPublicDer(&key, der, ONEK_BUF), 0);
  20602. wc_FreeDsaKey(&key);
  20603. idx = 0;
  20604. ExpectIntEQ(wc_DsaPublicKeyDecode(der, &idx, &key, sz), 0);
  20605. /* Test without the SubjectPublicKeyInfo header */
  20606. ExpectIntGE(sz = (word32)wc_SetDsaPublicKey(der, &key, ONEK_BUF, 0), 0);
  20607. wc_FreeDsaKey(&key);
  20608. idx = 0;
  20609. ExpectIntEQ(wc_DsaPublicKeyDecode(der, &idx, &key, sz), 0);
  20610. /* Test bad args. */
  20611. ExpectIntEQ(wc_DsaKeyToPublicDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20612. ExpectIntEQ(wc_DsaKeyToPublicDer(&key, NULL, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20613. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20614. wc_FreeDsaKey(&key);
  20615. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  20616. #endif /* !NO_DSA && WOLFSSL_KEY_GEN */
  20617. #endif /* !HAVE_SELFTEST */
  20618. return EXPECT_RESULT();
  20619. } /* END test_wc_DsaKeyToPublicDer */
  20620. /*
  20621. * Testing wc_DsaImportParamsRaw()
  20622. */
  20623. static int test_wc_DsaImportParamsRaw(void)
  20624. {
  20625. EXPECT_DECLS;
  20626. #if !defined(NO_DSA)
  20627. DsaKey key;
  20628. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20629. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20630. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20631. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20632. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20633. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20634. "80a0093113a8bd73";
  20635. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20636. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20637. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20638. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20639. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20640. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20641. "76341a7e7d9";
  20642. /* invalid p and q parameters */
  20643. const char* invalidP = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d";
  20644. const char* invalidQ = "96c5390a";
  20645. XMEMSET(&key, 0, sizeof(DsaKey));
  20646. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20647. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, q, g), 0);
  20648. /* test bad args */
  20649. /* null key struct */
  20650. ExpectIntEQ(wc_DsaImportParamsRaw(NULL, p, q, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20651. /* null param pointers */
  20652. ExpectIntEQ(wc_DsaImportParamsRaw(&key, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20653. /* illegal p length */
  20654. ExpectIntEQ(wc_DsaImportParamsRaw(&key, invalidP, q, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20655. /* illegal q length */
  20656. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, invalidQ, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20657. wc_FreeDsaKey(&key);
  20658. #endif
  20659. return EXPECT_RESULT();
  20660. } /* END test_wc_DsaImportParamsRaw */
  20661. /*
  20662. * Testing wc_DsaImportParamsRawCheck()
  20663. */
  20664. static int test_wc_DsaImportParamsRawCheck(void)
  20665. {
  20666. EXPECT_DECLS;
  20667. #if !defined(NO_DSA) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20668. DsaKey key;
  20669. int trusted = 0;
  20670. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20671. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20672. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20673. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20674. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20675. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20676. "80a0093113a8bd73";
  20677. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20678. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20679. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20680. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20681. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20682. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20683. "76341a7e7d9";
  20684. /* invalid p and q parameters */
  20685. const char* invalidP = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d";
  20686. const char* invalidQ = "96c5390a";
  20687. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20688. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, p, q, g, trusted, NULL), 0);
  20689. /* test bad args */
  20690. /* null key struct */
  20691. ExpectIntEQ(wc_DsaImportParamsRawCheck(NULL, p, q, g, trusted, NULL),
  20692. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20693. /* null param pointers */
  20694. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, NULL, NULL, NULL, trusted,
  20695. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20696. /* illegal p length */
  20697. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, invalidP, q, g, trusted, NULL),
  20698. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20699. /* illegal q length */
  20700. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, p, invalidQ, g, trusted, NULL),
  20701. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20702. wc_FreeDsaKey(&key);
  20703. #endif
  20704. return EXPECT_RESULT();
  20705. } /* END test_wc_DsaImportParamsRawCheck */
  20706. /*
  20707. * Testing wc_DsaExportParamsRaw()
  20708. */
  20709. static int test_wc_DsaExportParamsRaw(void)
  20710. {
  20711. EXPECT_DECLS;
  20712. #if !defined(NO_DSA)
  20713. DsaKey key;
  20714. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20715. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20716. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20717. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20718. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20719. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20720. "80a0093113a8bd73";
  20721. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20722. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20723. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20724. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20725. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20726. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20727. "76341a7e7d9";
  20728. const char* pCompare = "\xd3\x83\x11\xe2\xcd\x38\x8c\x3e\xd6\x98\xe8\x2f"
  20729. "\xdf\x88\xeb\x92\xb5\xa9\xa4\x83\xdc\x88\x00\x5d"
  20730. "\x4b\x72\x5e\xf3\x41\xea\xbb\x47\xcf\x8a\x7a\x8a"
  20731. "\x41\xe7\x92\xa1\x56\xb7\xce\x97\x20\x6c\x4f\x9c"
  20732. "\x5c\xe6\xfc\x5a\xe7\x91\x21\x02\xb6\xb5\x02\xe5"
  20733. "\x90\x50\xb5\xb2\x1c\xe2\x63\xdd\xdb\x20\x44\xb6"
  20734. "\x52\x23\x6f\x4d\x42\xab\x4b\x5d\x6a\xa7\x31\x89"
  20735. "\xce\xf1\xac\xe7\x78\xd7\x84\x5a\x5c\x1c\x1c\x71"
  20736. "\x47\x12\x31\x88\xf8\xdc\x55\x10\x54\xee\x16\x2b"
  20737. "\x63\x4d\x60\xf0\x97\xf7\x19\x07\x66\x40\xe2\x09"
  20738. "\x80\xa0\x09\x31\x13\xa8\xbd\x73";
  20739. const char* qCompare = "\x96\xc5\x39\x0a\x8b\x61\x2c\x0e\x42\x2b\xb2\xb0"
  20740. "\xea\x19\x4a\x3e\xc9\x35\xa2\x81";
  20741. const char* gCompare = "\x06\xb7\x86\x1a\xbb\xd3\x5c\xc8\x9e\x79\xc5\x2f"
  20742. "\x68\xd2\x08\x75\x38\x9b\x12\x73\x61\xca\x66\x82"
  20743. "\x21\x38\xce\x49\x91\xd2\xb8\x62\x25\x9d\x6b\x45"
  20744. "\x48\xa6\x49\x5b\x19\x5a\xa0\xe0\xb6\x13\x7c\xa3"
  20745. "\x7e\xb2\x3b\x94\x07\x4d\x3c\x3d\x30\x00\x42\xbd"
  20746. "\xf1\x57\x62\x81\x2b\x63\x33\xef\x7b\x07\xce\xba"
  20747. "\x78\x60\x76\x10\xfc\xc9\xee\x68\x49\x1d\xbc\x1e"
  20748. "\x34\xcd\x12\x61\x54\x74\xe5\x2b\x18\xbc\x93\x4f"
  20749. "\xb0\x0c\x61\xd3\x9e\x7d\xa8\x90\x22\x91\xc4\x43"
  20750. "\x4a\x4e\x22\x24\xc3\xf4\xfd\x9f\x93\xcd\x6f\x4f"
  20751. "\x17\xfc\x07\x63\x41\xa7\xe7\xd9";
  20752. byte pOut[MAX_DSA_PARAM_SIZE];
  20753. byte qOut[MAX_DSA_PARAM_SIZE];
  20754. byte gOut[MAX_DSA_PARAM_SIZE];
  20755. word32 pOutSz;
  20756. word32 qOutSz;
  20757. word32 gOutSz;
  20758. XMEMSET(&key, 0, sizeof(DsaKey));
  20759. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20760. /* first test using imported raw parameters, for expected */
  20761. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, q, g), 0);
  20762. pOutSz = sizeof(pOut);
  20763. qOutSz = sizeof(qOut);
  20764. gOutSz = sizeof(gOut);
  20765. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20766. &gOutSz), 0);
  20767. /* validate exported parameters are correct */
  20768. ExpectIntEQ(XMEMCMP(pOut, pCompare, pOutSz), 0);
  20769. ExpectIntEQ(XMEMCMP(qOut, qCompare, qOutSz), 0);
  20770. ExpectIntEQ(XMEMCMP(gOut, gCompare, gOutSz), 0);
  20771. /* test bad args */
  20772. /* null key struct */
  20773. ExpectIntEQ(wc_DsaExportParamsRaw(NULL, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20774. &gOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20775. /* null output pointers */
  20776. ExpectIntEQ(wc_DsaExportParamsRaw(&key, NULL, &pOutSz, NULL, &qOutSz, NULL,
  20777. &gOutSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  20778. /* null output size pointers */
  20779. ExpectIntEQ( wc_DsaExportParamsRaw(&key, pOut, NULL, qOut, NULL, gOut,
  20780. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20781. /* p output buffer size too small */
  20782. pOutSz = 1;
  20783. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20784. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20785. pOutSz = sizeof(pOut);
  20786. /* q output buffer size too small */
  20787. qOutSz = 1;
  20788. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20789. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20790. qOutSz = sizeof(qOut);
  20791. /* g output buffer size too small */
  20792. gOutSz = 1;
  20793. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20794. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20795. wc_FreeDsaKey(&key);
  20796. #endif
  20797. return EXPECT_RESULT();
  20798. } /* END test_wc_DsaExportParamsRaw */
  20799. /*
  20800. * Testing wc_DsaExportKeyRaw()
  20801. */
  20802. static int test_wc_DsaExportKeyRaw(void)
  20803. {
  20804. EXPECT_DECLS;
  20805. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20806. DsaKey key;
  20807. WC_RNG rng;
  20808. byte xOut[MAX_DSA_PARAM_SIZE];
  20809. byte yOut[MAX_DSA_PARAM_SIZE];
  20810. word32 xOutSz, yOutSz;
  20811. XMEMSET(&key, 0, sizeof(key));
  20812. XMEMSET(&rng, 0, sizeof(rng));
  20813. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20814. ExpectIntEQ(wc_InitRng(&rng), 0);
  20815. ExpectIntEQ(wc_MakeDsaParameters(&rng, 1024, &key), 0);
  20816. ExpectIntEQ(wc_MakeDsaKey(&rng, &key), 0);
  20817. /* try successful export */
  20818. xOutSz = sizeof(xOut);
  20819. yOutSz = sizeof(yOut);
  20820. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz), 0);
  20821. /* test bad args */
  20822. /* null key struct */
  20823. ExpectIntEQ(wc_DsaExportKeyRaw(NULL, xOut, &xOutSz, yOut, &yOutSz),
  20824. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20825. /* null output pointers */
  20826. ExpectIntEQ(wc_DsaExportKeyRaw(&key, NULL, &xOutSz, NULL, &yOutSz),
  20827. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  20828. /* null output size pointers */
  20829. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, NULL, yOut, NULL),
  20830. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20831. /* x output buffer size too small */
  20832. xOutSz = 1;
  20833. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz),
  20834. WC_NO_ERR_TRACE(BUFFER_E));
  20835. xOutSz = sizeof(xOut);
  20836. /* y output buffer size too small */
  20837. yOutSz = 1;
  20838. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz),
  20839. WC_NO_ERR_TRACE(BUFFER_E));
  20840. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20841. wc_FreeDsaKey(&key);
  20842. #endif
  20843. return EXPECT_RESULT();
  20844. } /* END test_wc_DsaExportParamsRaw */
  20845. /*
  20846. * Testing wc_ed25519_make_key().
  20847. */
  20848. static int test_wc_ed25519_make_key(void)
  20849. {
  20850. EXPECT_DECLS;
  20851. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_MAKE_KEY)
  20852. ed25519_key key;
  20853. WC_RNG rng;
  20854. unsigned char pubkey[ED25519_PUB_KEY_SIZE+1];
  20855. int pubkey_sz = ED25519_PUB_KEY_SIZE;
  20856. XMEMSET(&key, 0, sizeof(ed25519_key));
  20857. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20858. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20859. ExpectIntEQ(wc_InitRng(&rng), 0);
  20860. ExpectIntEQ(wc_ed25519_make_public(&key, pubkey, (word32)pubkey_sz),
  20861. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  20862. ExpectIntEQ(wc_ed25519_make_public(&key, pubkey+1, (word32)pubkey_sz),
  20863. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  20864. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20865. /* Test bad args. */
  20866. ExpectIntEQ(wc_ed25519_make_key(NULL, ED25519_KEY_SIZE, &key),
  20867. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20868. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, NULL),
  20869. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20870. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE - 1, &key),
  20871. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20872. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE + 1, &key),
  20873. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20874. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20875. wc_ed25519_free(&key);
  20876. #endif
  20877. return EXPECT_RESULT();
  20878. } /* END test_wc_ed25519_make_key */
  20879. /*
  20880. * Testing wc_ed25519_init()
  20881. */
  20882. static int test_wc_ed25519_init(void)
  20883. {
  20884. EXPECT_DECLS;
  20885. #if defined(HAVE_ED25519)
  20886. ed25519_key key;
  20887. XMEMSET(&key, 0, sizeof(ed25519_key));
  20888. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20889. /* Test bad args. */
  20890. ExpectIntEQ(wc_ed25519_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20891. wc_ed25519_free(&key);
  20892. #endif
  20893. return EXPECT_RESULT();
  20894. } /* END test_wc_ed25519_init */
  20895. /*
  20896. * Test wc_ed25519_sign_msg() and wc_ed25519_verify_msg()
  20897. */
  20898. static int test_wc_ed25519_sign_msg(void)
  20899. {
  20900. EXPECT_DECLS;
  20901. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_SIGN)
  20902. WC_RNG rng;
  20903. ed25519_key key;
  20904. byte msg[] = "Everybody gets Friday off.\n";
  20905. byte sig[ED25519_SIG_SIZE+1];
  20906. word32 msglen = sizeof(msg);
  20907. word32 siglen = ED25519_SIG_SIZE;
  20908. word32 badSigLen = ED25519_SIG_SIZE - 1;
  20909. #ifdef HAVE_ED25519_VERIFY
  20910. int verify_ok = 0; /*1 = Verify success.*/
  20911. #endif
  20912. /* Initialize stack variables. */
  20913. XMEMSET(&key, 0, sizeof(ed25519_key));
  20914. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20915. XMEMSET(sig, 0, sizeof(sig));
  20916. /* Initialize key. */
  20917. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20918. ExpectIntEQ(wc_InitRng(&rng), 0);
  20919. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20920. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &siglen, &key), 0);
  20921. ExpectIntEQ(siglen, ED25519_SIG_SIZE);
  20922. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig+1, &siglen, &key), 0);
  20923. ExpectIntEQ(siglen, ED25519_SIG_SIZE);
  20924. /* Test bad args. */
  20925. ExpectIntEQ(wc_ed25519_sign_msg(NULL, msglen, sig, &siglen, &key),
  20926. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20927. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, NULL, &siglen, &key),
  20928. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20929. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, NULL, &key),
  20930. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20931. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &siglen, NULL),
  20932. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20933. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &badSigLen, &key),
  20934. WC_NO_ERR_TRACE(BUFFER_E));
  20935. ExpectIntEQ(badSigLen, ED25519_SIG_SIZE);
  20936. badSigLen -= 1;
  20937. #ifdef HAVE_ED25519_VERIFY
  20938. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, &verify_ok,
  20939. &key), 0);
  20940. ExpectIntEQ(verify_ok, 1);
  20941. /* Test bad args. */
  20942. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen - 1, msg, msglen,
  20943. &verify_ok, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20944. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen + 1, msg, msglen,
  20945. &verify_ok, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20946. ExpectIntEQ(wc_ed25519_verify_msg(NULL, siglen, msg, msglen, &verify_ok,
  20947. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20948. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, NULL, msglen, &verify_ok,
  20949. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20950. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, NULL, &key),
  20951. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20952. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, &verify_ok,
  20953. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20954. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, badSigLen, msg, msglen, &verify_ok,
  20955. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20956. #endif /* Verify. */
  20957. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20958. wc_ed25519_free(&key);
  20959. #endif
  20960. return EXPECT_RESULT();
  20961. } /* END test_wc_ed25519_sign_msg */
  20962. /*
  20963. * Testing wc_ed25519_import_public()
  20964. */
  20965. static int test_wc_ed25519_import_public(void)
  20966. {
  20967. EXPECT_DECLS;
  20968. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  20969. ed25519_key pubKey;
  20970. WC_RNG rng;
  20971. const byte in[] = "Ed25519PublicKeyUnitTest......\n";
  20972. word32 inlen = sizeof(in);
  20973. XMEMSET(&pubKey, 0, sizeof(ed25519_key));
  20974. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20975. ExpectIntEQ(wc_ed25519_init(&pubKey), 0);
  20976. ExpectIntEQ(wc_InitRng(&rng), 0);
  20977. #ifdef HAVE_ED25519_MAKE_KEY
  20978. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &pubKey), 0);
  20979. #endif
  20980. ExpectIntEQ(wc_ed25519_import_public_ex(in, inlen, &pubKey, 1), 0);
  20981. ExpectIntEQ(XMEMCMP(in, pubKey.p, inlen), 0);
  20982. /* Test bad args. */
  20983. ExpectIntEQ(wc_ed25519_import_public(NULL, inlen, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20984. ExpectIntEQ(wc_ed25519_import_public(in, inlen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20985. ExpectIntEQ(wc_ed25519_import_public(in, inlen - 1, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20986. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20987. wc_ed25519_free(&pubKey);
  20988. #endif
  20989. return EXPECT_RESULT();
  20990. } /* END wc_ed25519_import_public */
  20991. /*
  20992. * Testing wc_ed25519_import_private_key()
  20993. */
  20994. static int test_wc_ed25519_import_private_key(void)
  20995. {
  20996. EXPECT_DECLS;
  20997. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  20998. ed25519_key key;
  20999. WC_RNG rng;
  21000. const byte privKey[] = "Ed25519PrivateKeyUnitTest.....\n";
  21001. const byte pubKey[] = "Ed25519PublicKeyUnitTest......\n";
  21002. word32 privKeySz = sizeof(privKey);
  21003. word32 pubKeySz = sizeof(pubKey);
  21004. #ifdef HAVE_ED25519_KEY_EXPORT
  21005. byte bothKeys[sizeof(privKey) + sizeof(pubKey)];
  21006. word32 bothKeysSz = sizeof(bothKeys);
  21007. #endif
  21008. XMEMSET(&key, 0, sizeof(ed25519_key));
  21009. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21010. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21011. ExpectIntEQ(wc_InitRng(&rng), 0);
  21012. #ifdef HAVE_ED25519_MAKE_KEY
  21013. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21014. #endif
  21015. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, privKeySz, pubKey,
  21016. pubKeySz, &key, 1), 0);
  21017. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21018. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21019. #ifdef HAVE_ED25519_KEY_EXPORT
  21020. PRIVATE_KEY_UNLOCK();
  21021. ExpectIntEQ(wc_ed25519_export_private(&key, bothKeys, &bothKeysSz), 0);
  21022. PRIVATE_KEY_LOCK();
  21023. ExpectIntEQ(wc_ed25519_import_private_key_ex(bothKeys, bothKeysSz, NULL, 0,
  21024. &key, 1), 0);
  21025. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21026. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21027. #endif
  21028. /* Test bad args. */
  21029. ExpectIntEQ(wc_ed25519_import_private_key(NULL, privKeySz, pubKey, pubKeySz,
  21030. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21031. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, NULL,
  21032. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21033. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, pubKey,
  21034. pubKeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21035. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz - 1, pubKey,
  21036. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21037. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, pubKey,
  21038. pubKeySz - 1, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21039. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, NULL, 0,
  21040. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21041. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21042. wc_ed25519_free(&key);
  21043. #endif
  21044. return EXPECT_RESULT();
  21045. } /* END test_wc_ed25519_import_private_key */
  21046. /*
  21047. * Testing wc_ed25519_export_public() and wc_ed25519_export_private_only()
  21048. */
  21049. static int test_wc_ed25519_export(void)
  21050. {
  21051. EXPECT_DECLS;
  21052. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  21053. ed25519_key key;
  21054. WC_RNG rng;
  21055. byte priv[ED25519_PRV_KEY_SIZE];
  21056. byte pub[ED25519_PUB_KEY_SIZE];
  21057. word32 privSz = sizeof(priv);
  21058. word32 pubSz = sizeof(pub);
  21059. #ifndef HAVE_ED25519_MAKE_KEY
  21060. const byte privKey[] = {
  21061. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  21062. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  21063. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  21064. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  21065. };
  21066. const byte pubKey[] = {
  21067. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  21068. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  21069. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  21070. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  21071. };
  21072. #endif
  21073. XMEMSET(&key, 0, sizeof(ed25519_key));
  21074. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21075. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21076. ExpectIntEQ(wc_InitRng(&rng), 0);
  21077. #ifdef HAVE_ED25519_MAKE_KEY
  21078. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21079. #else
  21080. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  21081. pubKey, sizeof(pubKey), &key, 1), 0);
  21082. #endif
  21083. PRIVATE_KEY_UNLOCK();
  21084. ExpectIntEQ(wc_ed25519_export_public(&key, pub, &pubSz), 0);
  21085. ExpectIntEQ(pubSz, ED25519_KEY_SIZE);
  21086. ExpectIntEQ(XMEMCMP(key.p, pub, pubSz), 0);
  21087. /* Test bad args. */
  21088. ExpectIntEQ(wc_ed25519_export_public(NULL, pub, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21089. ExpectIntEQ(wc_ed25519_export_public(&key, NULL, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21090. ExpectIntEQ(wc_ed25519_export_public(&key, pub, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21091. ExpectIntEQ(wc_ed25519_export_private_only(&key, priv, &privSz), 0);
  21092. ExpectIntEQ(privSz, ED25519_KEY_SIZE);
  21093. ExpectIntEQ(XMEMCMP(key.k, priv, privSz), 0);
  21094. /* Test bad args. */
  21095. ExpectIntEQ(wc_ed25519_export_private_only(NULL, priv, &privSz),
  21096. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21097. ExpectIntEQ(wc_ed25519_export_private_only(&key, NULL, &privSz),
  21098. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21099. ExpectIntEQ(wc_ed25519_export_private_only(&key, priv, NULL),
  21100. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21101. PRIVATE_KEY_LOCK();
  21102. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21103. wc_ed25519_free(&key);
  21104. #endif
  21105. return EXPECT_RESULT();
  21106. } /* END test_wc_ed25519_export */
  21107. /*
  21108. * Testing wc_ed25519_size()
  21109. */
  21110. static int test_wc_ed25519_size(void)
  21111. {
  21112. EXPECT_DECLS;
  21113. #if defined(HAVE_ED25519)
  21114. ed25519_key key;
  21115. WC_RNG rng;
  21116. #ifndef HAVE_ED25519_MAKE_KEY
  21117. const byte privKey[] = {
  21118. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  21119. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  21120. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  21121. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  21122. };
  21123. const byte pubKey[] = {
  21124. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  21125. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  21126. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  21127. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  21128. };
  21129. #endif
  21130. XMEMSET(&key, 0, sizeof(ed25519_key));
  21131. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21132. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21133. ExpectIntEQ(wc_InitRng(&rng), 0);
  21134. #ifdef HAVE_ED25519_MAKE_KEY
  21135. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21136. #else
  21137. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  21138. pubKey, sizeof(pubKey), &key, 1), 0);
  21139. #endif
  21140. ExpectIntEQ(wc_ed25519_size(&key), ED25519_KEY_SIZE);
  21141. /* Test bad args. */
  21142. ExpectIntEQ(wc_ed25519_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21143. ExpectIntEQ(wc_ed25519_sig_size(&key), ED25519_SIG_SIZE);
  21144. /* Test bad args. */
  21145. ExpectIntEQ(wc_ed25519_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21146. ExpectIntEQ(wc_ed25519_pub_size(&key), ED25519_PUB_KEY_SIZE);
  21147. /* Test bad args. */
  21148. ExpectIntEQ(wc_ed25519_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21149. ExpectIntEQ(wc_ed25519_priv_size(&key), ED25519_PRV_KEY_SIZE);
  21150. /* Test bad args. */
  21151. ExpectIntEQ(wc_ed25519_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21152. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21153. wc_ed25519_free(&key);
  21154. #endif
  21155. return EXPECT_RESULT();
  21156. } /* END test_wc_ed25519_size */
  21157. /*
  21158. * Testing wc_ed25519_export_private() and wc_ed25519_export_key()
  21159. */
  21160. static int test_wc_ed25519_exportKey(void)
  21161. {
  21162. EXPECT_DECLS;
  21163. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  21164. WC_RNG rng;
  21165. ed25519_key key;
  21166. byte priv[ED25519_PRV_KEY_SIZE];
  21167. byte pub[ED25519_PUB_KEY_SIZE];
  21168. byte privOnly[ED25519_PRV_KEY_SIZE];
  21169. word32 privSz = sizeof(priv);
  21170. word32 pubSz = sizeof(pub);
  21171. word32 privOnlySz = sizeof(privOnly);
  21172. #ifndef HAVE_ED25519_MAKE_KEY
  21173. const byte privKey[] = {
  21174. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  21175. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  21176. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  21177. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  21178. };
  21179. const byte pubKey[] = {
  21180. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  21181. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  21182. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  21183. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  21184. };
  21185. #endif
  21186. XMEMSET(&key, 0, sizeof(ed25519_key));
  21187. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21188. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21189. ExpectIntEQ(wc_InitRng(&rng), 0);
  21190. #ifdef HAVE_ED25519_MAKE_KEY
  21191. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21192. #else
  21193. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  21194. pubKey, sizeof(pubKey), &key, 1), 0);
  21195. #endif
  21196. PRIVATE_KEY_UNLOCK();
  21197. ExpectIntEQ(wc_ed25519_export_private(&key, privOnly, &privOnlySz), 0);
  21198. /* Test bad args. */
  21199. ExpectIntEQ(wc_ed25519_export_private(NULL, privOnly, &privOnlySz),
  21200. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21201. ExpectIntEQ(wc_ed25519_export_private(&key, NULL, &privOnlySz),
  21202. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21203. ExpectIntEQ(wc_ed25519_export_private(&key, privOnly, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21204. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, pub, &pubSz), 0);
  21205. /* Test bad args. */
  21206. ExpectIntEQ(wc_ed25519_export_key(NULL, priv, &privSz, pub, &pubSz),
  21207. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21208. ExpectIntEQ(wc_ed25519_export_key(&key, NULL, &privSz, pub, &pubSz),
  21209. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21210. ExpectIntEQ(wc_ed25519_export_key(&key, priv, NULL, pub, &pubSz),
  21211. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21212. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, NULL, &pubSz),
  21213. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21214. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, pub, NULL),
  21215. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21216. PRIVATE_KEY_LOCK();
  21217. /* Cross check output. */
  21218. ExpectIntEQ(XMEMCMP(priv, privOnly, privSz), 0);
  21219. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21220. wc_ed25519_free(&key);
  21221. #endif
  21222. return EXPECT_RESULT();
  21223. } /* END test_wc_ed25519_exportKey */
  21224. /*
  21225. * Testing wc_Ed25519PublicKeyToDer
  21226. */
  21227. static int test_wc_Ed25519PublicKeyToDer(void)
  21228. {
  21229. EXPECT_DECLS;
  21230. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  21231. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  21232. ed25519_key key;
  21233. byte derBuf[1024];
  21234. XMEMSET(&key, 0, sizeof(ed25519_key));
  21235. /* Test bad args */
  21236. ExpectIntEQ(wc_Ed25519PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21237. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21238. ExpectIntEQ(wc_Ed25519PublicKeyToDer(&key, derBuf, 0, 0), WC_NO_ERR_TRACE(BUFFER_E));
  21239. wc_ed25519_free(&key);
  21240. /* Test good args */
  21241. if (EXPECT_SUCCESS()) {
  21242. WC_RNG rng;
  21243. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21244. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21245. ExpectIntEQ(wc_InitRng(&rng), 0);
  21246. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21247. /* length only */
  21248. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, NULL, 0, 0), 0);
  21249. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, NULL, 0, 1), 0);
  21250. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, derBuf,
  21251. (word32)sizeof(derBuf), 1), 0);
  21252. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21253. wc_ed25519_free(&key);
  21254. }
  21255. #endif
  21256. return EXPECT_RESULT();
  21257. } /* END testing wc_Ed25519PublicKeyToDer */
  21258. /*
  21259. * Testing wc_curve25519_init and wc_curve25519_free.
  21260. */
  21261. static int test_wc_curve25519_init(void)
  21262. {
  21263. EXPECT_DECLS;
  21264. #if defined(HAVE_CURVE25519)
  21265. curve25519_key key;
  21266. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21267. /* Test bad args for wc_curve25519_init */
  21268. ExpectIntEQ(wc_curve25519_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21269. /* Test good args for wc_curve_25519_free */
  21270. wc_curve25519_free(&key);
  21271. /* Test bad args for wc_curve25519 free. */
  21272. wc_curve25519_free(NULL);
  21273. #endif
  21274. return EXPECT_RESULT();
  21275. } /* END test_wc_curve25519_init and wc_curve_25519_free*/
  21276. /*
  21277. * Testing test_wc_curve25519_size.
  21278. */
  21279. static int test_wc_curve25519_size(void)
  21280. {
  21281. EXPECT_DECLS;
  21282. #if defined(HAVE_CURVE25519)
  21283. curve25519_key key;
  21284. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21285. /* Test good args for wc_curve25519_size */
  21286. ExpectIntEQ(wc_curve25519_size(&key), CURVE25519_KEYSIZE);
  21287. /* Test bad args for wc_curve25519_size */
  21288. ExpectIntEQ(wc_curve25519_size(NULL), 0);
  21289. wc_curve25519_free(&key);
  21290. #endif
  21291. return EXPECT_RESULT();
  21292. } /* END test_wc_curve25519_size*/
  21293. /*
  21294. * Testing test_wc_curve25519_export_key_raw().
  21295. */
  21296. static int test_wc_curve25519_export_key_raw(void)
  21297. {
  21298. EXPECT_DECLS;
  21299. #if defined(HAVE_CURVE25519) && defined(HAVE_CURVE25519_KEY_EXPORT)
  21300. curve25519_key key;
  21301. WC_RNG rng;
  21302. byte privateKey[CURVE25519_KEYSIZE];
  21303. byte publicKey[CURVE25519_KEYSIZE];
  21304. word32 prvkSz;
  21305. word32 pubkSz;
  21306. byte prik[CURVE25519_KEYSIZE];
  21307. byte pubk[CURVE25519_KEYSIZE];
  21308. word32 prksz;
  21309. word32 pbksz;
  21310. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21311. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21312. ExpectIntEQ(wc_InitRng(&rng), 0);
  21313. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21314. /* bad-argument-test cases - target function should return BAD_FUNC_ARG */
  21315. prvkSz = CURVE25519_KEYSIZE;
  21316. pubkSz = CURVE25519_KEYSIZE;
  21317. ExpectIntEQ(wc_curve25519_export_key_raw(NULL, privateKey, &prvkSz,
  21318. publicKey, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21319. prvkSz = CURVE25519_KEYSIZE;
  21320. pubkSz = CURVE25519_KEYSIZE;
  21321. ExpectIntEQ(wc_curve25519_export_key_raw(&key, NULL, &prvkSz, publicKey,
  21322. &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21323. prvkSz = CURVE25519_KEYSIZE;
  21324. pubkSz = CURVE25519_KEYSIZE;
  21325. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, NULL,
  21326. publicKey, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21327. /* prvkSz = CURVE25519_KEYSIZE; */
  21328. pubkSz = CURVE25519_KEYSIZE;
  21329. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
  21330. NULL, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21331. prvkSz = CURVE25519_KEYSIZE;
  21332. pubkSz = CURVE25519_KEYSIZE;
  21333. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
  21334. publicKey, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21335. /* cross-testing */
  21336. prksz = CURVE25519_KEYSIZE;
  21337. ExpectIntEQ(wc_curve25519_export_private_raw(&key, prik, &prksz), 0);
  21338. pbksz = CURVE25519_KEYSIZE;
  21339. ExpectIntEQ(wc_curve25519_export_public(&key, pubk, &pbksz), 0);
  21340. prvkSz = CURVE25519_KEYSIZE;
  21341. /* pubkSz = CURVE25519_KEYSIZE; */
  21342. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
  21343. publicKey, &pubkSz), 0);
  21344. ExpectIntEQ(prksz, CURVE25519_KEYSIZE);
  21345. ExpectIntEQ(pbksz, CURVE25519_KEYSIZE);
  21346. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21347. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21348. ExpectIntEQ(XMEMCMP(privateKey, prik, CURVE25519_KEYSIZE), 0);
  21349. ExpectIntEQ(XMEMCMP(publicKey, pubk, CURVE25519_KEYSIZE), 0);
  21350. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21351. wc_curve25519_free(&key);
  21352. #endif
  21353. return EXPECT_RESULT();
  21354. } /* end of test_wc_curve25519_export_key_raw */
  21355. /*
  21356. * Testing test_wc_curve25519_export_key_raw_ex().
  21357. */
  21358. static int test_wc_curve25519_export_key_raw_ex(void)
  21359. {
  21360. EXPECT_DECLS;
  21361. #if defined(HAVE_CURVE25519) && defined(HAVE_CURVE25519_KEY_EXPORT)
  21362. curve25519_key key;
  21363. WC_RNG rng;
  21364. byte privateKey[CURVE25519_KEYSIZE];
  21365. byte publicKey[CURVE25519_KEYSIZE];
  21366. word32 prvkSz;
  21367. word32 pubkSz;
  21368. byte prik[CURVE25519_KEYSIZE];
  21369. byte pubk[CURVE25519_KEYSIZE];
  21370. word32 prksz;
  21371. word32 pbksz;
  21372. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21373. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21374. ExpectIntEQ(wc_InitRng(&rng), 0);
  21375. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21376. /* bad-argument-test cases - target function should return BAD_FUNC_ARG */
  21377. prvkSz = CURVE25519_KEYSIZE;
  21378. pubkSz = CURVE25519_KEYSIZE;
  21379. ExpectIntEQ(wc_curve25519_export_key_raw_ex(NULL, privateKey,
  21380. &prvkSz, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21381. prvkSz = CURVE25519_KEYSIZE;
  21382. pubkSz = CURVE25519_KEYSIZE;
  21383. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, NULL,
  21384. &prvkSz, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21385. prvkSz = CURVE25519_KEYSIZE;
  21386. pubkSz = CURVE25519_KEYSIZE;
  21387. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21388. NULL, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21389. /* prvkSz = CURVE25519_KEYSIZE; */
  21390. pubkSz = CURVE25519_KEYSIZE;
  21391. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21392. &prvkSz, NULL, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21393. prvkSz = CURVE25519_KEYSIZE;
  21394. pubkSz = CURVE25519_KEYSIZE;
  21395. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21396. &prvkSz, publicKey, NULL, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21397. prvkSz = CURVE25519_KEYSIZE;
  21398. /* pubkSz = CURVE25519_KEYSIZE; */
  21399. ExpectIntEQ(wc_curve25519_export_key_raw_ex(NULL, privateKey,
  21400. &prvkSz, publicKey, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21401. prvkSz = CURVE25519_KEYSIZE;
  21402. pubkSz = CURVE25519_KEYSIZE;
  21403. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, NULL,
  21404. &prvkSz, publicKey, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21405. prvkSz = CURVE25519_KEYSIZE;
  21406. pubkSz = CURVE25519_KEYSIZE;
  21407. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21408. NULL, publicKey, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21409. /* prvkSz = CURVE25519_KEYSIZE; */
  21410. pubkSz = CURVE25519_KEYSIZE;
  21411. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21412. &prvkSz, NULL, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21413. prvkSz = CURVE25519_KEYSIZE;
  21414. pubkSz = CURVE25519_KEYSIZE;
  21415. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21416. &prvkSz, publicKey, NULL, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21417. /* illegal value for endian */
  21418. prvkSz = CURVE25519_KEYSIZE;
  21419. /* pubkSz = CURVE25519_KEYSIZE; */
  21420. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  21421. publicKey, NULL, EC25519_BIG_ENDIAN + 10), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21422. /* cross-testing */
  21423. prksz = CURVE25519_KEYSIZE;
  21424. ExpectIntEQ(wc_curve25519_export_private_raw( &key, prik, &prksz), 0);
  21425. pbksz = CURVE25519_KEYSIZE;
  21426. ExpectIntEQ(wc_curve25519_export_public( &key, pubk, &pbksz), 0);
  21427. prvkSz = CURVE25519_KEYSIZE;
  21428. /* pubkSz = CURVE25519_KEYSIZE; */
  21429. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  21430. publicKey, &pubkSz, EC25519_BIG_ENDIAN), 0);
  21431. ExpectIntEQ(prksz, CURVE25519_KEYSIZE);
  21432. ExpectIntEQ(pbksz, CURVE25519_KEYSIZE);
  21433. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21434. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21435. ExpectIntEQ(XMEMCMP(privateKey, prik, CURVE25519_KEYSIZE), 0);
  21436. ExpectIntEQ(XMEMCMP(publicKey, pubk, CURVE25519_KEYSIZE), 0);
  21437. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  21438. publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), 0);
  21439. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21440. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21441. /* try once with another endian */
  21442. prvkSz = CURVE25519_KEYSIZE;
  21443. pubkSz = CURVE25519_KEYSIZE;
  21444. ExpectIntEQ(wc_curve25519_export_key_raw_ex( &key, privateKey, &prvkSz,
  21445. publicKey, &pubkSz, EC25519_BIG_ENDIAN), 0);
  21446. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21447. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21448. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21449. wc_curve25519_free(&key);
  21450. #endif
  21451. return EXPECT_RESULT();
  21452. } /* end of test_wc_curve25519_export_key_raw_ex */
  21453. /*
  21454. * Testing wc_curve25519_make_key
  21455. */
  21456. static int test_wc_curve25519_make_key(void)
  21457. {
  21458. EXPECT_DECLS;
  21459. #if defined(HAVE_CURVE25519)
  21460. curve25519_key key;
  21461. WC_RNG rng;
  21462. int keysize = 0;
  21463. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21464. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21465. ExpectIntEQ(wc_InitRng(&rng), 0);
  21466. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21467. ExpectIntEQ(keysize = wc_curve25519_size(&key), CURVE25519_KEYSIZE);
  21468. ExpectIntEQ(wc_curve25519_make_key(&rng, keysize, &key), 0);
  21469. /* test bad cases*/
  21470. ExpectIntEQ(wc_curve25519_make_key(NULL, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21471. ExpectIntEQ(wc_curve25519_make_key(&rng, keysize, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21472. ExpectIntEQ(wc_curve25519_make_key(NULL, keysize, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21473. ExpectIntEQ(wc_curve25519_make_key(&rng, 0, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21474. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21475. wc_curve25519_free(&key);
  21476. #endif
  21477. return EXPECT_RESULT();
  21478. } /* END test_wc_curve25519_make_key*/
  21479. /*
  21480. * Testing wc_curve25519_shared_secret_ex
  21481. */
  21482. static int test_wc_curve25519_shared_secret_ex(void)
  21483. {
  21484. EXPECT_DECLS;
  21485. #if defined(HAVE_CURVE25519)
  21486. curve25519_key private_key;
  21487. curve25519_key public_key;
  21488. WC_RNG rng;
  21489. byte out[CURVE25519_KEYSIZE];
  21490. word32 outLen = sizeof(out);
  21491. int endian = EC25519_BIG_ENDIAN;
  21492. ExpectIntEQ(wc_curve25519_init(&private_key), 0);
  21493. ExpectIntEQ(wc_curve25519_init(&public_key), 0);
  21494. ExpectIntEQ(wc_InitRng(&rng), 0);
  21495. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &private_key),
  21496. 0);
  21497. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &public_key),
  21498. 0);
  21499. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21500. &outLen, endian), 0);
  21501. /* test bad cases*/
  21502. ExpectIntEQ(wc_curve25519_shared_secret_ex(NULL, NULL, NULL, 0, endian),
  21503. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21504. ExpectIntEQ(wc_curve25519_shared_secret_ex(NULL, &public_key, out, &outLen,
  21505. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21506. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, NULL, out, &outLen,
  21507. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21508. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, NULL,
  21509. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21510. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21511. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21512. /* curve25519.c is checking for public_key size less than or equal to 0x7f,
  21513. * increasing to 0x8f checks for error being returned*/
  21514. public_key.p.point[CURVE25519_KEYSIZE-1] = 0x8F;
  21515. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21516. &outLen, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21517. outLen = outLen - 2;
  21518. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21519. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21520. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21521. wc_curve25519_free(&private_key);
  21522. wc_curve25519_free(&public_key);
  21523. #endif
  21524. return EXPECT_RESULT();
  21525. } /* END test_wc_curve25519_shared_secret_ex*/
  21526. /*
  21527. * Testing wc_curve25519_make_pub
  21528. */
  21529. static int test_wc_curve25519_make_pub(void)
  21530. {
  21531. EXPECT_DECLS;
  21532. #ifdef HAVE_CURVE25519
  21533. curve25519_key key;
  21534. WC_RNG rng;
  21535. byte out[CURVE25519_KEYSIZE];
  21536. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21537. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21538. ExpectIntEQ(wc_InitRng(&rng), 0);
  21539. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21540. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(out), out,
  21541. (int)sizeof(key.k), key.k), 0);
  21542. /* test bad cases*/
  21543. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(key.k) - 1, key.k,
  21544. (int)sizeof out, out), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21545. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21546. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21547. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out - 1, out,
  21548. (int)sizeof(key.k), key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21549. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, NULL,
  21550. (int)sizeof(key.k), key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21551. /* verify clamping test */
  21552. key.k[0] |= ~248;
  21553. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21554. key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21555. key.k[0] &= 248;
  21556. /* repeat the expected-to-succeed test. */
  21557. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21558. key.k), 0);
  21559. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21560. wc_curve25519_free(&key);
  21561. #endif
  21562. return EXPECT_RESULT();
  21563. } /* END test_wc_curve25519_make_pub */
  21564. /*
  21565. * Testing test_wc_curve25519_export_public_ex
  21566. */
  21567. static int test_wc_curve25519_export_public_ex(void)
  21568. {
  21569. EXPECT_DECLS;
  21570. #if defined(HAVE_CURVE25519)
  21571. curve25519_key key;
  21572. WC_RNG rng;
  21573. byte out[CURVE25519_KEYSIZE];
  21574. word32 outLen = sizeof(out);
  21575. int endian = EC25519_BIG_ENDIAN;
  21576. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21577. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21578. ExpectIntEQ(wc_InitRng(&rng), 0);
  21579. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21580. ExpectIntEQ(wc_curve25519_export_public(&key, out, &outLen), 0);
  21581. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, &outLen, endian), 0);
  21582. /* test bad cases*/
  21583. ExpectIntEQ(wc_curve25519_export_public_ex(NULL, NULL, NULL, endian),
  21584. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21585. ExpectIntEQ(wc_curve25519_export_public_ex(NULL, out, &outLen, endian),
  21586. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21587. ExpectIntEQ(wc_curve25519_export_public_ex(&key, NULL, &outLen, endian),
  21588. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21589. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, NULL, endian),
  21590. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21591. outLen = outLen - 2;
  21592. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, &outLen, endian),
  21593. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21594. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21595. wc_curve25519_free(&key);
  21596. #endif
  21597. return EXPECT_RESULT();
  21598. } /* END test_wc_curve25519_export_public_ex*/
  21599. /*
  21600. * Testing test_wc_curve25519_import_private_raw_ex
  21601. */
  21602. static int test_wc_curve25519_import_private_raw_ex(void)
  21603. {
  21604. EXPECT_DECLS;
  21605. #if defined(HAVE_CURVE25519)
  21606. curve25519_key key;
  21607. WC_RNG rng;
  21608. byte priv[CURVE25519_KEYSIZE];
  21609. byte pub[CURVE25519_KEYSIZE];
  21610. word32 privSz = sizeof(priv);
  21611. word32 pubSz = sizeof(pub);
  21612. int endian = EC25519_BIG_ENDIAN;
  21613. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21614. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21615. ExpectIntEQ(wc_InitRng(&rng), 0);
  21616. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21617. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, priv, &privSz,
  21618. endian), 0);
  21619. ExpectIntEQ(wc_curve25519_export_public(&key, pub, &pubSz), 0);
  21620. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21621. &key, endian), 0);
  21622. /* test bad cases*/
  21623. ExpectIntEQ(wc_curve25519_import_private_raw_ex(NULL, 0, NULL, 0, NULL,
  21624. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21625. ExpectIntEQ(wc_curve25519_import_private_raw_ex(NULL, privSz, pub, pubSz,
  21626. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21627. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, NULL, pubSz,
  21628. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21629. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21630. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21631. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, 0, pub, pubSz,
  21632. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21633. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, 0,
  21634. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21635. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21636. &key, EC25519_LITTLE_ENDIAN), 0);
  21637. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21638. wc_curve25519_free(&key);
  21639. #endif
  21640. return EXPECT_RESULT();
  21641. } /* END test_wc_curve25519_import_private_raw_ex*/
  21642. /*
  21643. * Testing test_wc_curve25519_import_private
  21644. */
  21645. static int test_wc_curve25519_import_private(void)
  21646. {
  21647. EXPECT_DECLS;
  21648. #if defined(HAVE_CURVE25519)
  21649. curve25519_key key;
  21650. WC_RNG rng;
  21651. byte priv[CURVE25519_KEYSIZE];
  21652. word32 privSz = sizeof(priv);
  21653. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21654. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21655. ExpectIntEQ(wc_InitRng(&rng), 0);
  21656. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21657. ExpectIntEQ(wc_curve25519_export_private_raw(&key, priv, &privSz), 0);
  21658. ExpectIntEQ(wc_curve25519_import_private(priv, privSz, &key), 0);
  21659. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21660. wc_curve25519_free(&key);
  21661. #endif
  21662. return EXPECT_RESULT();
  21663. } /* END test_wc_curve25519_import*/
  21664. /*
  21665. * Testing test_wc_curve25519_export_private_raw_ex
  21666. */
  21667. static int test_wc_curve25519_export_private_raw_ex(void)
  21668. {
  21669. EXPECT_DECLS;
  21670. #if defined(HAVE_CURVE25519)
  21671. curve25519_key key;
  21672. byte out[CURVE25519_KEYSIZE];
  21673. word32 outLen = sizeof(out);
  21674. int endian = EC25519_BIG_ENDIAN;
  21675. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21676. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen, endian),
  21677. 0);
  21678. /* test bad cases*/
  21679. ExpectIntEQ(wc_curve25519_export_private_raw_ex(NULL, NULL, NULL, endian),
  21680. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21681. ExpectIntEQ(wc_curve25519_export_private_raw_ex(NULL, out, &outLen, endian),
  21682. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21683. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, NULL, &outLen,
  21684. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21685. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, NULL, endian),
  21686. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21687. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen,
  21688. EC25519_LITTLE_ENDIAN), 0);
  21689. outLen = outLen - 2;
  21690. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen, endian),
  21691. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21692. wc_curve25519_free(&key);
  21693. #endif
  21694. return EXPECT_RESULT();
  21695. } /* END test_wc_curve25519_export_private_raw_ex*/
  21696. /*
  21697. * Testing wc_ed448_make_key().
  21698. */
  21699. static int test_wc_ed448_make_key(void)
  21700. {
  21701. EXPECT_DECLS;
  21702. #if defined(HAVE_ED448)
  21703. ed448_key key;
  21704. WC_RNG rng;
  21705. unsigned char pubkey[ED448_PUB_KEY_SIZE];
  21706. XMEMSET(&key, 0, sizeof(ed448_key));
  21707. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21708. ExpectIntEQ(wc_ed448_init(&key), 0);
  21709. ExpectIntEQ(wc_InitRng(&rng), 0);
  21710. ExpectIntEQ(wc_ed448_make_public(&key, pubkey, sizeof(pubkey)),
  21711. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  21712. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21713. /* Test bad args. */
  21714. ExpectIntEQ(wc_ed448_make_key(NULL, ED448_KEY_SIZE, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21715. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21716. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE - 1, &key),
  21717. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21718. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE + 1, &key),
  21719. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21720. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21721. wc_ed448_free(&key);
  21722. #endif
  21723. return EXPECT_RESULT();
  21724. } /* END test_wc_ed448_make_key */
  21725. /*
  21726. * Testing wc_ed448_init()
  21727. */
  21728. static int test_wc_ed448_init(void)
  21729. {
  21730. EXPECT_DECLS;
  21731. #if defined(HAVE_ED448)
  21732. ed448_key key;
  21733. XMEMSET(&key, 0, sizeof(ed448_key));
  21734. ExpectIntEQ(wc_ed448_init(&key), 0);
  21735. /* Test bad args. */
  21736. ExpectIntEQ(wc_ed448_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21737. wc_ed448_free(&key);
  21738. #endif
  21739. return EXPECT_RESULT();
  21740. } /* END test_wc_ed448_init */
  21741. /*
  21742. * Test wc_ed448_sign_msg() and wc_ed448_verify_msg()
  21743. */
  21744. static int test_wc_ed448_sign_msg(void)
  21745. {
  21746. EXPECT_DECLS;
  21747. #if defined(HAVE_ED448) && defined(HAVE_ED448_SIGN)
  21748. ed448_key key;
  21749. WC_RNG rng;
  21750. byte msg[] = "Everybody gets Friday off.\n";
  21751. byte sig[ED448_SIG_SIZE];
  21752. word32 msglen = sizeof(msg);
  21753. word32 siglen = sizeof(sig);
  21754. word32 badSigLen = sizeof(sig) - 1;
  21755. #ifdef HAVE_ED448_VERIFY
  21756. int verify_ok = 0; /*1 = Verify success.*/
  21757. #endif
  21758. /* Initialize stack variables. */
  21759. XMEMSET(&key, 0, sizeof(ed448_key));
  21760. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21761. XMEMSET(sig, 0, siglen);
  21762. /* Initialize key. */
  21763. ExpectIntEQ(wc_ed448_init(&key), 0);
  21764. ExpectIntEQ(wc_InitRng(&rng), 0);
  21765. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21766. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &siglen, &key, NULL, 0), 0);
  21767. ExpectIntEQ(siglen, ED448_SIG_SIZE);
  21768. /* Test bad args. */
  21769. ExpectIntEQ(wc_ed448_sign_msg(NULL, msglen, sig, &siglen, &key, NULL, 0),
  21770. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21771. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, NULL, &siglen, &key, NULL, 0),
  21772. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21773. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, NULL, &key, NULL, 0),
  21774. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21775. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &siglen, NULL, NULL, 0),
  21776. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21777. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &badSigLen, &key, NULL, 0),
  21778. WC_NO_ERR_TRACE(BUFFER_E));
  21779. ExpectIntEQ(badSigLen, ED448_SIG_SIZE);
  21780. badSigLen -= 1;
  21781. #ifdef HAVE_ED448_VERIFY
  21782. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, &verify_ok, &key,
  21783. NULL, 0), 0);
  21784. ExpectIntEQ(verify_ok, 1);
  21785. /* Test bad args. */
  21786. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen - 1, msg, msglen, &verify_ok,
  21787. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21788. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen + 1, msg, msglen, &verify_ok,
  21789. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21790. ExpectIntEQ(wc_ed448_verify_msg(NULL, siglen, msg, msglen, &verify_ok,
  21791. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21792. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, NULL, msglen, &verify_ok,
  21793. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21794. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, NULL,
  21795. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21796. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, &verify_ok,
  21797. NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21798. ExpectIntEQ(wc_ed448_verify_msg(sig, badSigLen, msg, msglen, &verify_ok,
  21799. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21800. #endif /* Verify. */
  21801. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21802. wc_ed448_free(&key);
  21803. #endif
  21804. return EXPECT_RESULT();
  21805. } /* END test_wc_ed448_sign_msg */
  21806. /*
  21807. * Testing wc_ed448_import_public()
  21808. */
  21809. static int test_wc_ed448_import_public(void)
  21810. {
  21811. EXPECT_DECLS;
  21812. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  21813. ed448_key pubKey;
  21814. WC_RNG rng;
  21815. const byte in[] =
  21816. "Ed448PublicKeyUnitTest.................................\n";
  21817. word32 inlen = sizeof(in);
  21818. XMEMSET(&pubKey, 0, sizeof(ed448_key));
  21819. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21820. ExpectIntEQ(wc_ed448_init(&pubKey), 0);
  21821. ExpectIntEQ(wc_InitRng(&rng), 0);
  21822. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &pubKey), 0);
  21823. ExpectIntEQ(wc_ed448_import_public_ex(in, inlen, &pubKey, 1), 0);
  21824. ExpectIntEQ(XMEMCMP(in, pubKey.p, inlen), 0);
  21825. /* Test bad args. */
  21826. ExpectIntEQ(wc_ed448_import_public(NULL, inlen, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21827. ExpectIntEQ(wc_ed448_import_public(in, inlen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21828. ExpectIntEQ(wc_ed448_import_public(in, inlen - 1, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21829. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21830. wc_ed448_free(&pubKey);
  21831. #endif
  21832. return EXPECT_RESULT();
  21833. } /* END wc_ed448_import_public */
  21834. /*
  21835. * Testing wc_ed448_import_private_key()
  21836. */
  21837. static int test_wc_ed448_import_private_key(void)
  21838. {
  21839. EXPECT_DECLS;
  21840. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  21841. ed448_key key;
  21842. WC_RNG rng;
  21843. const byte privKey[] =
  21844. "Ed448PrivateKeyUnitTest................................\n";
  21845. const byte pubKey[] =
  21846. "Ed448PublicKeyUnitTest.................................\n";
  21847. word32 privKeySz = sizeof(privKey);
  21848. word32 pubKeySz = sizeof(pubKey);
  21849. #ifdef HAVE_ED448_KEY_EXPORT
  21850. byte bothKeys[sizeof(privKey) + sizeof(pubKey)];
  21851. word32 bothKeysSz = sizeof(bothKeys);
  21852. #endif
  21853. XMEMSET(&key, 0, sizeof(ed448_key));
  21854. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21855. ExpectIntEQ(wc_ed448_init(&key), 0);
  21856. ExpectIntEQ(wc_InitRng(&rng), 0);
  21857. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21858. ExpectIntEQ(wc_ed448_import_private_key_ex(privKey, privKeySz, pubKey,
  21859. pubKeySz, &key, 1), 0);
  21860. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21861. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21862. #ifdef HAVE_ED448_KEY_EXPORT
  21863. PRIVATE_KEY_UNLOCK();
  21864. ExpectIntEQ(wc_ed448_export_private(&key, bothKeys, &bothKeysSz), 0);
  21865. PRIVATE_KEY_LOCK();
  21866. ExpectIntEQ(wc_ed448_import_private_key_ex(bothKeys, bothKeysSz, NULL, 0,
  21867. &key, 1), 0);
  21868. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21869. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21870. #endif
  21871. /* Test bad args. */
  21872. ExpectIntEQ(wc_ed448_import_private_key(NULL, privKeySz, pubKey, pubKeySz,
  21873. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21874. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, NULL, pubKeySz,
  21875. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21876. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, pubKey,
  21877. pubKeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21878. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz - 1, pubKey,
  21879. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21880. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, pubKey,
  21881. pubKeySz - 1, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21882. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, NULL, 0, &key),
  21883. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21884. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21885. wc_ed448_free(&key);
  21886. #endif
  21887. return EXPECT_RESULT();
  21888. } /* END test_wc_ed448_import_private_key */
  21889. /*
  21890. * Testing wc_ed448_export_public() and wc_ed448_export_private_only()
  21891. */
  21892. static int test_wc_ed448_export(void)
  21893. {
  21894. EXPECT_DECLS;
  21895. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  21896. ed448_key key;
  21897. WC_RNG rng;
  21898. byte priv[ED448_PRV_KEY_SIZE];
  21899. byte pub[ED448_PUB_KEY_SIZE];
  21900. word32 privSz = sizeof(priv);
  21901. word32 pubSz = sizeof(pub);
  21902. XMEMSET(&key, 0, sizeof(ed448_key));
  21903. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21904. ExpectIntEQ(wc_ed448_init(&key), 0);
  21905. ExpectIntEQ(wc_InitRng(&rng), 0);
  21906. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21907. ExpectIntEQ(wc_ed448_export_public(&key, pub, &pubSz), 0);
  21908. ExpectIntEQ(pubSz, ED448_KEY_SIZE);
  21909. ExpectIntEQ(XMEMCMP(key.p, pub, pubSz), 0);
  21910. /* Test bad args. */
  21911. ExpectIntEQ(wc_ed448_export_public(NULL, pub, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21912. ExpectIntEQ(wc_ed448_export_public(&key, NULL, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21913. ExpectIntEQ(wc_ed448_export_public(&key, pub, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21914. PRIVATE_KEY_UNLOCK();
  21915. ExpectIntEQ(wc_ed448_export_private_only(&key, priv, &privSz), 0);
  21916. ExpectIntEQ(privSz, ED448_KEY_SIZE);
  21917. ExpectIntEQ(XMEMCMP(key.k, priv, privSz), 0);
  21918. /* Test bad args. */
  21919. ExpectIntEQ(wc_ed448_export_private_only(NULL, priv, &privSz),
  21920. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21921. ExpectIntEQ(wc_ed448_export_private_only(&key, NULL, &privSz),
  21922. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21923. ExpectIntEQ(wc_ed448_export_private_only(&key, priv, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21924. PRIVATE_KEY_LOCK();
  21925. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21926. wc_ed448_free(&key);
  21927. #endif
  21928. return EXPECT_RESULT();
  21929. } /* END test_wc_ed448_export */
  21930. /*
  21931. * Testing wc_ed448_size()
  21932. */
  21933. static int test_wc_ed448_size(void)
  21934. {
  21935. EXPECT_DECLS;
  21936. #if defined(HAVE_ED448)
  21937. ed448_key key;
  21938. WC_RNG rng;
  21939. XMEMSET(&key, 0, sizeof(ed448_key));
  21940. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21941. ExpectIntEQ(wc_ed448_init(&key), 0);
  21942. ExpectIntEQ(wc_InitRng(&rng), 0);
  21943. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21944. ExpectIntEQ(wc_ed448_size(&key), ED448_KEY_SIZE);
  21945. /* Test bad args. */
  21946. ExpectIntEQ(wc_ed448_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21947. ExpectIntEQ(wc_ed448_sig_size(&key), ED448_SIG_SIZE);
  21948. /* Test bad args. */
  21949. ExpectIntEQ(wc_ed448_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21950. ExpectIntEQ(wc_ed448_pub_size(&key), ED448_PUB_KEY_SIZE);
  21951. /* Test bad args. */
  21952. ExpectIntEQ(wc_ed448_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21953. ExpectIntEQ(wc_ed448_priv_size(&key), ED448_PRV_KEY_SIZE);
  21954. /* Test bad args. */
  21955. ExpectIntEQ(wc_ed448_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21956. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21957. wc_ed448_free(&key);
  21958. #endif
  21959. return EXPECT_RESULT();
  21960. } /* END test_wc_ed448_size */
  21961. /*
  21962. * Testing wc_ed448_export_private() and wc_ed448_export_key()
  21963. */
  21964. static int test_wc_ed448_exportKey(void)
  21965. {
  21966. EXPECT_DECLS;
  21967. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  21968. ed448_key key;
  21969. WC_RNG rng;
  21970. byte priv[ED448_PRV_KEY_SIZE];
  21971. byte pub[ED448_PUB_KEY_SIZE];
  21972. byte privOnly[ED448_PRV_KEY_SIZE];
  21973. word32 privSz = sizeof(priv);
  21974. word32 pubSz = sizeof(pub);
  21975. word32 privOnlySz = sizeof(privOnly);
  21976. XMEMSET(&key, 0, sizeof(ed448_key));
  21977. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21978. ExpectIntEQ(wc_ed448_init(&key), 0);
  21979. ExpectIntEQ(wc_InitRng(&rng), 0);
  21980. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21981. PRIVATE_KEY_UNLOCK();
  21982. ExpectIntEQ(wc_ed448_export_private(&key, privOnly, &privOnlySz), 0);
  21983. /* Test bad args. */
  21984. ExpectIntEQ(wc_ed448_export_private(NULL, privOnly, &privOnlySz),
  21985. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21986. ExpectIntEQ(wc_ed448_export_private(&key, NULL, &privOnlySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21987. ExpectIntEQ(wc_ed448_export_private(&key, privOnly, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21988. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, pub, &pubSz), 0);
  21989. /* Test bad args. */
  21990. ExpectIntEQ(wc_ed448_export_key(NULL, priv, &privSz, pub, &pubSz),
  21991. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21992. ExpectIntEQ(wc_ed448_export_key(&key, NULL, &privSz, pub, &pubSz),
  21993. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21994. ExpectIntEQ(wc_ed448_export_key(&key, priv, NULL, pub, &pubSz),
  21995. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21996. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, NULL, &pubSz),
  21997. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21998. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, pub, NULL),
  21999. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22000. PRIVATE_KEY_LOCK();
  22001. /* Cross check output. */
  22002. ExpectIntEQ(XMEMCMP(priv, privOnly, privSz), 0);
  22003. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22004. wc_ed448_free(&key);
  22005. #endif
  22006. return EXPECT_RESULT();
  22007. } /* END test_wc_ed448_exportKey */
  22008. /*
  22009. * Testing wc_Ed448PublicKeyToDer
  22010. */
  22011. static int test_wc_Ed448PublicKeyToDer(void)
  22012. {
  22013. EXPECT_DECLS;
  22014. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  22015. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  22016. ed448_key key;
  22017. byte derBuf[1024];
  22018. XMEMSET(&key, 0, sizeof(ed448_key));
  22019. /* Test bad args */
  22020. ExpectIntEQ(wc_Ed448PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22021. ExpectIntEQ(wc_ed448_init(&key), 0);
  22022. ExpectIntEQ(wc_Ed448PublicKeyToDer(&key, derBuf, 0, 0), WC_NO_ERR_TRACE(BUFFER_E));
  22023. wc_ed448_free(&key);
  22024. /* Test good args */
  22025. if (EXPECT_SUCCESS()) {
  22026. WC_RNG rng;
  22027. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22028. ExpectIntEQ(wc_ed448_init(&key), 0);
  22029. ExpectIntEQ(wc_InitRng(&rng), 0);
  22030. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  22031. /* length only */
  22032. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, NULL, 0, 0), 0);
  22033. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, NULL, 0, 1), 0);
  22034. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, derBuf,
  22035. (word32)sizeof(derBuf), 1), 0);
  22036. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22037. wc_ed448_free(&key);
  22038. }
  22039. #endif
  22040. return EXPECT_RESULT();
  22041. } /* END testing wc_Ed448PublicKeyToDer */
  22042. /*
  22043. * Testing wc_curve448_init and wc_curve448_free.
  22044. */
  22045. static int test_wc_curve448_init(void)
  22046. {
  22047. EXPECT_DECLS;
  22048. #if defined(HAVE_CURVE448)
  22049. curve448_key key;
  22050. /* Test bad args for wc_curve448_init */
  22051. ExpectIntEQ(wc_curve448_init(&key), 0);
  22052. /* Test bad args for wc_curve448_init */
  22053. ExpectIntEQ(wc_curve448_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22054. /* Test good args for wc_curve_448_free */
  22055. wc_curve448_free(&key);
  22056. /* Test bad args for wc_curve448_free */
  22057. wc_curve448_free(NULL);
  22058. #endif
  22059. return EXPECT_RESULT();
  22060. } /* END test_wc_curve448_init and wc_curve_448_free*/
  22061. /*
  22062. * Testing wc_curve448_make_key
  22063. */
  22064. static int test_wc_curve448_make_key(void)
  22065. {
  22066. EXPECT_DECLS;
  22067. #if defined(HAVE_CURVE448)
  22068. curve448_key key;
  22069. WC_RNG rng;
  22070. int keysize = 0;
  22071. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22072. ExpectIntEQ(wc_curve448_init(&key), 0);
  22073. ExpectIntEQ(wc_InitRng(&rng), 0);
  22074. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22075. ExpectIntEQ(keysize = wc_curve448_size(&key), CURVE448_KEY_SIZE);
  22076. ExpectIntEQ(wc_curve448_make_key(&rng, keysize, &key), 0);
  22077. /* test bad cases */
  22078. ExpectIntEQ(wc_curve448_make_key(NULL, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22079. ExpectIntEQ(wc_curve448_make_key(&rng, keysize, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22080. ExpectIntEQ(wc_curve448_make_key(NULL, keysize, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22081. ExpectIntEQ(wc_curve448_make_key(&rng, 0, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22082. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22083. wc_curve448_free(&key);
  22084. #endif
  22085. return EXPECT_RESULT();
  22086. } /* END test_wc_curve448_make_key*/
  22087. /*
  22088. * Testing test_wc_curve448_shared_secret_ex
  22089. */
  22090. static int test_wc_curve448_shared_secret_ex(void)
  22091. {
  22092. EXPECT_DECLS;
  22093. #if defined(HAVE_CURVE448)
  22094. curve448_key private_key;
  22095. curve448_key public_key;
  22096. WC_RNG rng;
  22097. byte out[CURVE448_KEY_SIZE];
  22098. word32 outLen = sizeof(out);
  22099. int endian = EC448_BIG_ENDIAN;
  22100. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22101. ExpectIntEQ(wc_curve448_init(&private_key), 0);
  22102. ExpectIntEQ(wc_InitRng(&rng), 0);
  22103. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &private_key), 0);
  22104. ExpectIntEQ(wc_curve448_init(&public_key), 0);
  22105. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &public_key), 0);
  22106. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  22107. &outLen, endian), 0);
  22108. /* test bad cases */
  22109. ExpectIntEQ(wc_curve448_shared_secret_ex(NULL, NULL, NULL, 0, endian),
  22110. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22111. ExpectIntEQ(wc_curve448_shared_secret_ex(NULL, &public_key, out, &outLen,
  22112. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22113. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, NULL, out, &outLen,
  22114. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22115. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, NULL,
  22116. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22117. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  22118. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22119. outLen = outLen - 2;
  22120. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  22121. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22122. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22123. wc_curve448_free(&private_key);
  22124. wc_curve448_free(&public_key);
  22125. #endif
  22126. return EXPECT_RESULT();
  22127. } /* END test_wc_curve448_shared_secret_ex*/
  22128. /*
  22129. * Testing test_wc_curve448_export_public_ex
  22130. */
  22131. static int test_wc_curve448_export_public_ex(void)
  22132. {
  22133. EXPECT_DECLS;
  22134. #if defined(HAVE_CURVE448)
  22135. WC_RNG rng;
  22136. curve448_key key;
  22137. byte out[CURVE448_KEY_SIZE];
  22138. word32 outLen = sizeof(out);
  22139. int endian = EC448_BIG_ENDIAN;
  22140. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22141. ExpectIntEQ(wc_curve448_init(&key), 0);
  22142. ExpectIntEQ(wc_InitRng(&rng), 0);
  22143. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22144. ExpectIntEQ(wc_curve448_export_public(&key, out, &outLen), 0);
  22145. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, &outLen, endian), 0);
  22146. /* test bad cases*/
  22147. ExpectIntEQ(wc_curve448_export_public_ex(NULL, NULL, NULL, endian),
  22148. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22149. ExpectIntEQ(wc_curve448_export_public_ex(NULL, out, &outLen, endian),
  22150. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22151. ExpectIntEQ(wc_curve448_export_public_ex(&key, NULL, &outLen, endian),
  22152. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22153. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, NULL, endian),
  22154. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22155. outLen = outLen - 2;
  22156. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, &outLen, endian),
  22157. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22158. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22159. wc_curve448_free(&key);
  22160. #endif
  22161. return EXPECT_RESULT();
  22162. } /* END test_wc_curve448_export_public_ex*/
  22163. /*
  22164. * Testing test_wc_curve448_export_private_raw_ex
  22165. */
  22166. static int test_wc_curve448_export_private_raw_ex(void)
  22167. {
  22168. EXPECT_DECLS;
  22169. #if defined(HAVE_CURVE448)
  22170. curve448_key key;
  22171. byte out[CURVE448_KEY_SIZE];
  22172. word32 outLen = sizeof(out);
  22173. int endian = EC448_BIG_ENDIAN;
  22174. ExpectIntEQ(wc_curve448_init(&key), 0);
  22175. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen, endian),
  22176. 0);
  22177. /* test bad cases*/
  22178. ExpectIntEQ(wc_curve448_export_private_raw_ex(NULL, NULL, NULL, endian),
  22179. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22180. ExpectIntEQ(wc_curve448_export_private_raw_ex(NULL, out, &outLen, endian),
  22181. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22182. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, NULL, &outLen, endian),
  22183. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22184. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, NULL, endian),
  22185. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22186. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen,
  22187. EC448_LITTLE_ENDIAN), 0);
  22188. outLen = outLen - 2;
  22189. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen, endian),
  22190. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22191. wc_curve448_free(&key);
  22192. #endif
  22193. return EXPECT_RESULT();
  22194. } /* END test_wc_curve448_export_private_raw_ex*/
  22195. /*
  22196. * Testing test_wc_curve448_import_private_raw_ex
  22197. */
  22198. static int test_wc_curve448_import_private_raw_ex(void)
  22199. {
  22200. EXPECT_DECLS;
  22201. #if defined(HAVE_CURVE448)
  22202. curve448_key key;
  22203. WC_RNG rng;
  22204. byte priv[CURVE448_KEY_SIZE];
  22205. byte pub[CURVE448_KEY_SIZE];
  22206. word32 privSz = sizeof(priv);
  22207. word32 pubSz = sizeof(pub);
  22208. int endian = EC448_BIG_ENDIAN;
  22209. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22210. ExpectIntEQ(wc_curve448_init(&key), 0);
  22211. ExpectIntEQ(wc_InitRng(&rng), 0);
  22212. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22213. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  22214. ExpectIntEQ(wc_curve448_export_public(&key, pub, &pubSz), 0);
  22215. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  22216. &key, endian), 0);
  22217. /* test bad cases */
  22218. ExpectIntEQ(wc_curve448_import_private_raw_ex(NULL, 0, NULL, 0, NULL, 0),
  22219. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22220. ExpectIntEQ(wc_curve448_import_private_raw_ex(NULL, privSz, pub, pubSz,
  22221. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22222. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, NULL, pubSz,
  22223. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22224. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  22225. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22226. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, 0, pub, pubSz,
  22227. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22228. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, 0,
  22229. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22230. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  22231. &key, EC448_LITTLE_ENDIAN), 0);
  22232. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22233. wc_curve448_free(&key);
  22234. #endif
  22235. return EXPECT_RESULT();
  22236. } /* END test_wc_curve448_import_private_raw_ex*/
  22237. /*
  22238. * Testing test_curve448_export_key_raw
  22239. */
  22240. static int test_wc_curve448_export_key_raw(void)
  22241. {
  22242. EXPECT_DECLS;
  22243. #if defined(HAVE_CURVE448)
  22244. curve448_key key;
  22245. WC_RNG rng;
  22246. byte priv[CURVE448_KEY_SIZE];
  22247. byte pub[CURVE448_KEY_SIZE];
  22248. word32 privSz = sizeof(priv);
  22249. word32 pubSz = sizeof(pub);
  22250. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22251. ExpectIntEQ(wc_curve448_init(&key), 0);
  22252. ExpectIntEQ(wc_InitRng(&rng), 0);
  22253. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22254. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  22255. ExpectIntEQ(wc_curve448_export_public(&key, pub, &pubSz), 0);
  22256. ExpectIntEQ(wc_curve448_export_key_raw(&key, priv, &privSz, pub, &pubSz),
  22257. 0);
  22258. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22259. wc_curve448_free(&key);
  22260. #endif
  22261. return EXPECT_RESULT();
  22262. } /* END test_wc_curve448_import_private_raw_ex*/
  22263. /*
  22264. * Testing test_wc_curve448_import_private
  22265. */
  22266. static int test_wc_curve448_import_private(void)
  22267. {
  22268. EXPECT_DECLS;
  22269. #if defined(HAVE_CURVE448)
  22270. curve448_key key;
  22271. WC_RNG rng;
  22272. byte priv[CURVE448_KEY_SIZE];
  22273. word32 privSz = sizeof(priv);
  22274. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22275. ExpectIntEQ(wc_curve448_init(&key), 0);
  22276. ExpectIntEQ(wc_InitRng(&rng), 0);
  22277. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22278. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  22279. ExpectIntEQ(wc_curve448_import_private(priv, privSz, &key), 0);
  22280. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22281. wc_curve448_free(&key);
  22282. #endif
  22283. return EXPECT_RESULT();
  22284. } /* END test_wc_curve448_import*/
  22285. /*
  22286. * Testing test_wc_curve448_size.
  22287. */
  22288. static int test_wc_curve448_size(void)
  22289. {
  22290. EXPECT_DECLS;
  22291. #if defined(HAVE_CURVE448)
  22292. curve448_key key;
  22293. ExpectIntEQ(wc_curve448_init(&key), 0);
  22294. /* Test good args for wc_curve448_size */
  22295. ExpectIntEQ(wc_curve448_size(&key), CURVE448_KEY_SIZE);
  22296. /* Test bad args for wc_curve448_size */
  22297. ExpectIntEQ(wc_curve448_size(NULL), 0);
  22298. wc_curve448_free(&key);
  22299. #endif
  22300. return EXPECT_RESULT();
  22301. } /* END test_wc_curve448_size*/
  22302. /*
  22303. * Testing wc_ecc_make_key.
  22304. */
  22305. static int test_wc_ecc_make_key(void)
  22306. {
  22307. EXPECT_DECLS;
  22308. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  22309. ecc_key key;
  22310. WC_RNG rng;
  22311. int ret;
  22312. XMEMSET(&key, 0, sizeof(ecc_key));
  22313. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22314. ExpectIntEQ(wc_ecc_init(&key), 0);
  22315. ExpectIntEQ(wc_InitRng(&rng), 0);
  22316. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22317. #if defined(WOLFSSL_ASYNC_CRYPT)
  22318. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22319. #endif
  22320. ExpectIntEQ(ret, 0);
  22321. /* Pass in bad args. */
  22322. ExpectIntEQ(wc_ecc_make_key(NULL, KEY14, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22323. ExpectIntEQ(wc_ecc_make_key(&rng, KEY14, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22324. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22325. wc_ecc_free(&key);
  22326. #ifdef FP_ECC
  22327. wc_ecc_fp_free();
  22328. #endif
  22329. #endif
  22330. return EXPECT_RESULT();
  22331. } /* END test_wc_ecc_make_key */
  22332. /*
  22333. * Testing wc_ecc_init()
  22334. */
  22335. static int test_wc_ecc_init(void)
  22336. {
  22337. EXPECT_DECLS;
  22338. #ifdef HAVE_ECC
  22339. ecc_key key;
  22340. XMEMSET(&key, 0, sizeof(ecc_key));
  22341. ExpectIntEQ(wc_ecc_init(&key), 0);
  22342. /* Pass in bad args. */
  22343. ExpectIntEQ(wc_ecc_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22344. wc_ecc_free(&key);
  22345. #endif
  22346. return EXPECT_RESULT();
  22347. } /* END test_wc_ecc_init */
  22348. /*
  22349. * Testing wc_ecc_check_key()
  22350. */
  22351. static int test_wc_ecc_check_key(void)
  22352. {
  22353. EXPECT_DECLS;
  22354. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  22355. ecc_key key;
  22356. WC_RNG rng;
  22357. int ret;
  22358. XMEMSET(&rng, 0, sizeof(rng));
  22359. XMEMSET(&key, 0, sizeof(key));
  22360. ExpectIntEQ(wc_ecc_init(&key), 0);
  22361. ExpectIntEQ(wc_InitRng(&rng), 0);
  22362. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22363. #if defined(WOLFSSL_ASYNC_CRYPT)
  22364. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22365. #endif
  22366. ExpectIntEQ(ret, 0);
  22367. ExpectIntEQ(wc_ecc_check_key(&key), 0);
  22368. /* Pass in bad args. */
  22369. ExpectIntEQ(wc_ecc_check_key(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22370. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22371. wc_ecc_free(&key);
  22372. #ifdef FP_ECC
  22373. wc_ecc_fp_free();
  22374. #endif
  22375. #endif
  22376. return EXPECT_RESULT();
  22377. } /* END test_wc_ecc_check_key */
  22378. /*
  22379. * Testing wc_ecc_get_generator()
  22380. */
  22381. static int test_wc_ecc_get_generator(void)
  22382. {
  22383. EXPECT_DECLS;
  22384. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  22385. !defined(HAVE_FIPS) && defined(OPENSSL_EXTRA)
  22386. ecc_point* pt = NULL;
  22387. ExpectNotNull(pt = wc_ecc_new_point());
  22388. ExpectIntEQ(wc_ecc_get_generator(pt, wc_ecc_get_curve_idx(ECC_SECP256R1)),
  22389. MP_OKAY);
  22390. /* Test bad args. */
  22391. /* Returns Zero for bad arg. */
  22392. ExpectIntNE(wc_ecc_get_generator(pt, -1), MP_OKAY);
  22393. ExpectIntNE(wc_ecc_get_generator(NULL, wc_ecc_get_curve_idx(ECC_SECP256R1)),
  22394. MP_OKAY);
  22395. /* If we ever get to 1000 curves increase this number */
  22396. ExpectIntNE(wc_ecc_get_generator(pt, 1000), MP_OKAY);
  22397. ExpectIntNE(wc_ecc_get_generator(NULL, -1), MP_OKAY);
  22398. wc_ecc_del_point(pt);
  22399. #endif
  22400. return EXPECT_RESULT();
  22401. } /* END test_wc_ecc_get_generator */
  22402. /*
  22403. * Testing wc_ecc_size()
  22404. */
  22405. static int test_wc_ecc_size(void)
  22406. {
  22407. EXPECT_DECLS;
  22408. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  22409. WC_RNG rng;
  22410. ecc_key key;
  22411. int ret;
  22412. XMEMSET(&key, 0, sizeof(ecc_key));
  22413. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22414. ExpectIntEQ(wc_ecc_init(&key), 0);
  22415. ExpectIntEQ(wc_InitRng(&rng), 0);
  22416. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22417. #if defined(WOLFSSL_ASYNC_CRYPT)
  22418. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22419. #endif
  22420. ExpectIntEQ(ret, 0);
  22421. ExpectIntEQ(wc_ecc_size(&key), KEY14);
  22422. /* Test bad args. */
  22423. /* Returns Zero for bad arg. */
  22424. ExpectIntEQ(wc_ecc_size(NULL), 0);
  22425. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22426. wc_ecc_free(&key);
  22427. #endif
  22428. return EXPECT_RESULT();
  22429. } /* END test_wc_ecc_size */
  22430. static int test_wc_ecc_params(void)
  22431. {
  22432. EXPECT_DECLS;
  22433. /* FIPS/CAVP self-test modules do not have `wc_ecc_get_curve_params`.
  22434. It was added after certifications */
  22435. #if defined(HAVE_ECC) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  22436. const ecc_set_type* ecc_set = NULL;
  22437. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  22438. /* Test for SECP256R1 curve */
  22439. int curve_id = ECC_SECP256R1;
  22440. int curve_idx;
  22441. ExpectIntNE(curve_idx = wc_ecc_get_curve_idx(curve_id), ECC_CURVE_INVALID);
  22442. ExpectNotNull(ecc_set = wc_ecc_get_curve_params(curve_idx));
  22443. ExpectIntEQ(ecc_set->id, curve_id);
  22444. #endif
  22445. /* Test case when SECP256R1 is not enabled */
  22446. /* Test that we get curve params for index 0 */
  22447. ExpectNotNull(ecc_set = wc_ecc_get_curve_params(0));
  22448. #endif /* HAVE_ECC && !HAVE_FIPS && !HAVE_SELFTEST */
  22449. return EXPECT_RESULT();
  22450. }
  22451. /*
  22452. * Testing wc_ecc_sign_hash() and wc_ecc_verify_hash()
  22453. */
  22454. static int test_wc_ecc_signVerify_hash(void)
  22455. {
  22456. EXPECT_DECLS;
  22457. #if defined(HAVE_ECC) && defined(HAVE_ECC_SIGN) && !defined(NO_ASN) && !defined(WC_NO_RNG)
  22458. ecc_key key;
  22459. WC_RNG rng;
  22460. int ret;
  22461. #ifdef HAVE_ECC_VERIFY
  22462. int verify = 0;
  22463. #endif
  22464. word32 siglen = ECC_BUFSIZE;
  22465. byte sig[ECC_BUFSIZE];
  22466. byte adjustedSig[ECC_BUFSIZE+1];
  22467. byte digest[] = TEST_STRING;
  22468. word32 digestlen = (word32)TEST_STRING_SZ;
  22469. /* Init stack var */
  22470. XMEMSET(&key, 0, sizeof(ecc_key));
  22471. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22472. XMEMSET(sig, 0, siglen);
  22473. XMEMSET(adjustedSig, 0, ECC_BUFSIZE+1);
  22474. /* Init structs. */
  22475. ExpectIntEQ(wc_ecc_init(&key), 0);
  22476. ExpectIntEQ(wc_InitRng(&rng), 0);
  22477. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22478. #if defined(WOLFSSL_ASYNC_CRYPT)
  22479. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22480. #endif
  22481. ExpectIntEQ(ret, 0);
  22482. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, &rng, &key),
  22483. 0);
  22484. /* Check bad args. */
  22485. ExpectIntEQ(wc_ecc_sign_hash(NULL, digestlen, sig, &siglen, &rng, &key),
  22486. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22487. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, NULL, &siglen, &rng, &key),
  22488. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22489. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, NULL, &rng, &key),
  22490. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22491. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, NULL, &key),
  22492. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22493. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, &rng, NULL),
  22494. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22495. #ifdef HAVE_ECC_VERIFY
  22496. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, &verify,
  22497. &key), 0);
  22498. ExpectIntEQ(verify, 1);
  22499. /* test check on length of signature passed in */
  22500. XMEMCPY(adjustedSig, sig, siglen);
  22501. adjustedSig[1] = adjustedSig[1] + 1; /* add 1 to length for extra byte*/
  22502. #ifndef NO_STRICT_ECDSA_LEN
  22503. ExpectIntNE(wc_ecc_verify_hash(adjustedSig, siglen+1, digest, digestlen,
  22504. &verify, &key), 0);
  22505. #else
  22506. /* if NO_STRICT_ECDSA_LEN is set then extra bytes after the signature
  22507. * is allowed */
  22508. ExpectIntEQ(wc_ecc_verify_hash(adjustedSig, siglen+1, digest, digestlen,
  22509. &verify, &key), 0);
  22510. #endif
  22511. /* Test bad args. */
  22512. ExpectIntEQ(wc_ecc_verify_hash(NULL, siglen, digest, digestlen, &verify,
  22513. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22514. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, NULL, digestlen, &verify, &key),
  22515. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22516. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, NULL, &key),
  22517. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22518. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, &verify,
  22519. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22520. #endif /* HAVE_ECC_VERIFY */
  22521. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22522. wc_ecc_free(&key);
  22523. #ifdef FP_ECC
  22524. wc_ecc_fp_free();
  22525. #endif
  22526. #endif
  22527. return EXPECT_RESULT();
  22528. } /* END test_wc_ecc_sign_hash */
  22529. /*
  22530. * Testing wc_ecc_shared_secret()
  22531. */
  22532. static int test_wc_ecc_shared_secret(void)
  22533. {
  22534. EXPECT_DECLS;
  22535. #if defined(HAVE_ECC) && defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG)
  22536. ecc_key key;
  22537. ecc_key pubKey;
  22538. WC_RNG rng;
  22539. #if defined(NO_ECC256)
  22540. int ret;
  22541. #endif
  22542. byte out[KEY32];
  22543. int keySz = sizeof(out);
  22544. word32 outlen = (word32)sizeof(out);
  22545. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  22546. const char* qx =
  22547. "bb33ac4c27504ac64aa504c33cde9f36db722dce94ea2bfacb2009392c16e861";
  22548. const char* qy =
  22549. "02e9af4dd302939a315b9792217ff0cf18da9111023486e82058330b803489d8";
  22550. const char* d =
  22551. "45b66902739c6c85a1385b72e8e8c7acc4038d533504fa6c28dc348de1a8098c";
  22552. const char* curveName = "SECP256R1";
  22553. const byte expected_shared_secret[] =
  22554. {
  22555. 0x65, 0xc0, 0xd4, 0x61, 0x17, 0xe6, 0x09, 0x75,
  22556. 0xf0, 0x12, 0xa0, 0x4d, 0x0b, 0x41, 0x30, 0x7a,
  22557. 0x51, 0xf0, 0xb3, 0xaf, 0x23, 0x8f, 0x0f, 0xdf,
  22558. 0xf1, 0xff, 0x23, 0x64, 0x28, 0xca, 0xf8, 0x06
  22559. };
  22560. #endif
  22561. PRIVATE_KEY_UNLOCK();
  22562. /* Initialize variables. */
  22563. XMEMSET(&key, 0, sizeof(ecc_key));
  22564. XMEMSET(&pubKey, 0, sizeof(ecc_key));
  22565. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22566. XMEMSET(out, 0, keySz);
  22567. ExpectIntEQ(wc_ecc_init(&key), 0);
  22568. ExpectIntEQ(wc_ecc_init(&pubKey), 0);
  22569. ExpectIntEQ(wc_InitRng(&rng), 0);
  22570. #if !defined(NO_ECC256)
  22571. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, curveName), 0);
  22572. ExpectIntEQ(wc_ecc_import_raw(&pubKey, qx, qy, NULL, curveName), 0);
  22573. #else
  22574. ret = wc_ecc_make_key(&rng, keySz, &key);
  22575. #if defined(WOLFSSL_ASYNC_CRYPT)
  22576. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22577. #endif
  22578. ExpectIntEQ(ret, 0);
  22579. ret = wc_ecc_make_key(&rng, keySz, &key);
  22580. #if defined(WOLFSSL_ASYNC_CRYPT)
  22581. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22582. #endif
  22583. ExpectIntEQ(ret, 0);
  22584. #endif
  22585. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  22586. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  22587. !defined(HAVE_SELFTEST)
  22588. ExpectIntEQ(wc_ecc_set_rng(&key, &rng), 0);
  22589. #endif
  22590. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, &outlen), 0);
  22591. #if !defined(NO_ECC256)
  22592. ExpectIntEQ(XMEMCMP(out, expected_shared_secret, outlen), 0);
  22593. #endif
  22594. /* Test bad args. */
  22595. ExpectIntEQ(wc_ecc_shared_secret(NULL, &pubKey, out, &outlen),
  22596. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22597. ExpectIntEQ(wc_ecc_shared_secret(&key, NULL, out, &outlen),
  22598. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22599. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, NULL, &outlen),
  22600. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22601. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, NULL),
  22602. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22603. /* Invalid length */
  22604. outlen = 1;
  22605. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, &outlen),
  22606. WC_NO_ERR_TRACE(BUFFER_E));
  22607. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22608. wc_ecc_free(&pubKey);
  22609. wc_ecc_free(&key);
  22610. #ifdef FP_ECC
  22611. wc_ecc_fp_free();
  22612. #endif
  22613. PRIVATE_KEY_LOCK();
  22614. #endif
  22615. return EXPECT_RESULT();
  22616. } /* END tests_wc_ecc_shared_secret */
  22617. /*
  22618. * testint wc_ecc_export_x963()
  22619. */
  22620. static int test_wc_ecc_export_x963(void)
  22621. {
  22622. EXPECT_DECLS;
  22623. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22624. ecc_key key;
  22625. WC_RNG rng;
  22626. byte out[ECC_ASN963_MAX_BUF_SZ];
  22627. word32 outlen = sizeof(out);
  22628. int ret;
  22629. PRIVATE_KEY_UNLOCK();
  22630. /* Initialize variables. */
  22631. XMEMSET(&key, 0, sizeof(ecc_key));
  22632. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22633. XMEMSET(out, 0, outlen);
  22634. ExpectIntEQ(wc_ecc_init(&key), 0);
  22635. ExpectIntEQ(wc_InitRng(&rng), 0);
  22636. ret = wc_ecc_make_key(&rng, KEY20, &key);
  22637. #if defined(WOLFSSL_ASYNC_CRYPT)
  22638. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22639. #endif
  22640. ExpectIntEQ(ret, 0);
  22641. ExpectIntEQ(wc_ecc_export_x963(&key, out, &outlen), 0);
  22642. /* Test bad args. */
  22643. ExpectIntEQ(wc_ecc_export_x963(NULL, out, &outlen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22644. ExpectIntEQ(wc_ecc_export_x963(&key, NULL, &outlen), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22645. ExpectIntEQ(wc_ecc_export_x963(&key, out, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22646. key.idx = -4;
  22647. ExpectIntEQ(wc_ecc_export_x963(&key, out, &outlen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22648. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22649. wc_ecc_free(&key);
  22650. #ifdef FP_ECC
  22651. wc_ecc_fp_free();
  22652. #endif
  22653. PRIVATE_KEY_LOCK();
  22654. #endif
  22655. return EXPECT_RESULT();
  22656. } /* END test_wc_ecc_export_x963 */
  22657. /*
  22658. * Testing wc_ecc_export_x963_ex()
  22659. * compile with --enable-compkey will use compression.
  22660. */
  22661. static int test_wc_ecc_export_x963_ex(void)
  22662. {
  22663. EXPECT_DECLS;
  22664. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22665. ecc_key key;
  22666. WC_RNG rng;
  22667. int ret;
  22668. byte out[ECC_ASN963_MAX_BUF_SZ];
  22669. word32 outlen = sizeof(out);
  22670. #ifdef HAVE_COMP_KEY
  22671. word32 badOutLen = 5;
  22672. #endif
  22673. /* Init stack variables. */
  22674. XMEMSET(&key, 0, sizeof(ecc_key));
  22675. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22676. XMEMSET(out, 0, outlen);
  22677. PRIVATE_KEY_UNLOCK();
  22678. ExpectIntEQ(wc_ecc_init(&key), 0);
  22679. ExpectIntEQ(wc_InitRng(&rng), 0);
  22680. ret = wc_ecc_make_key(&rng, KEY64, &key);
  22681. #if defined(WOLFSSL_ASYNC_CRYPT)
  22682. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22683. #endif
  22684. ExpectIntEQ(ret, 0);
  22685. #ifdef HAVE_COMP_KEY
  22686. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, COMP), 0);
  22687. #else
  22688. ExpectIntEQ(ret = wc_ecc_export_x963_ex(&key, out, &outlen, NOCOMP), 0);
  22689. #endif
  22690. /* Test bad args. */
  22691. #ifdef HAVE_COMP_KEY
  22692. ExpectIntEQ(wc_ecc_export_x963_ex(NULL, out, &outlen, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22693. ExpectIntEQ(wc_ecc_export_x963_ex(&key, NULL, &outlen, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22694. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, NULL, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22695. #if defined(HAVE_FIPS) && (!defined(FIPS_VERSION_LT) || FIPS_VERSION_LT(5,3))
  22696. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &badOutLen, COMP), WC_NO_ERR_TRACE(BUFFER_E));
  22697. #else
  22698. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &badOutLen, COMP),
  22699. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22700. #endif
  22701. key.idx = -4;
  22702. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, COMP), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22703. #else
  22704. ExpectIntEQ(wc_ecc_export_x963_ex(NULL, out, &outlen, NOCOMP),
  22705. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22706. ExpectIntEQ(wc_ecc_export_x963_ex(&key, NULL, &outlen, NOCOMP),
  22707. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22708. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, 1), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  22709. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, NULL, NOCOMP),
  22710. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22711. key.idx = -4;
  22712. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, NOCOMP),
  22713. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22714. #endif
  22715. PRIVATE_KEY_LOCK();
  22716. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22717. wc_ecc_free(&key);
  22718. #ifdef FP_ECC
  22719. wc_ecc_fp_free();
  22720. #endif
  22721. #endif
  22722. return EXPECT_RESULT();
  22723. } /* END test_wc_ecc_export_x963_ex */
  22724. /*
  22725. * testing wc_ecc_import_x963()
  22726. */
  22727. static int test_wc_ecc_import_x963(void)
  22728. {
  22729. EXPECT_DECLS;
  22730. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_IMPORT) && \
  22731. defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22732. ecc_key pubKey;
  22733. ecc_key key;
  22734. WC_RNG rng;
  22735. byte x963[ECC_ASN963_MAX_BUF_SZ];
  22736. word32 x963Len = (word32)sizeof(x963);
  22737. int ret;
  22738. /* Init stack variables. */
  22739. XMEMSET(&key, 0, sizeof(ecc_key));
  22740. XMEMSET(&pubKey, 0, sizeof(ecc_key));
  22741. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22742. XMEMSET(x963, 0, x963Len);
  22743. ExpectIntEQ(wc_ecc_init(&pubKey), 0);
  22744. ExpectIntEQ(wc_ecc_init(&key), 0);
  22745. ExpectIntEQ(wc_InitRng(&rng), 0);
  22746. #if FIPS_VERSION3_GE(6,0,0)
  22747. ret = wc_ecc_make_key(&rng, KEY32, &key);
  22748. #else
  22749. ret = wc_ecc_make_key(&rng, KEY24, &key);
  22750. #endif
  22751. #if defined(WOLFSSL_ASYNC_CRYPT)
  22752. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22753. #endif
  22754. ExpectIntEQ(ret, 0);
  22755. PRIVATE_KEY_UNLOCK();
  22756. ExpectIntEQ(wc_ecc_export_x963(&key, x963, &x963Len), 0);
  22757. PRIVATE_KEY_LOCK();
  22758. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len, &pubKey), 0);
  22759. /* Test bad args. */
  22760. ExpectIntEQ(wc_ecc_import_x963(NULL, x963Len, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22761. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22762. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len + 1, &pubKey), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22763. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22764. wc_ecc_free(&key);
  22765. wc_ecc_free(&pubKey);
  22766. #ifdef FP_ECC
  22767. wc_ecc_fp_free();
  22768. #endif
  22769. #endif
  22770. return EXPECT_RESULT();
  22771. } /* END wc_ecc_import_x963 */
  22772. /*
  22773. * testing wc_ecc_import_private_key()
  22774. */
  22775. static int test_wc_ecc_import_private_key(void)
  22776. {
  22777. EXPECT_DECLS;
  22778. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_IMPORT) && \
  22779. defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22780. ecc_key key;
  22781. ecc_key keyImp;
  22782. WC_RNG rng;
  22783. byte privKey[ECC_PRIV_KEY_BUF]; /* Raw private key.*/
  22784. byte x963Key[ECC_ASN963_MAX_BUF_SZ];
  22785. word32 privKeySz = (word32)sizeof(privKey);
  22786. word32 x963KeySz = (word32)sizeof(x963Key);
  22787. int ret;
  22788. /* Init stack variables. */
  22789. XMEMSET(&key, 0, sizeof(ecc_key));
  22790. XMEMSET(&keyImp, 0, sizeof(ecc_key));
  22791. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22792. XMEMSET(privKey, 0, privKeySz);
  22793. XMEMSET(x963Key, 0, x963KeySz);
  22794. PRIVATE_KEY_UNLOCK();
  22795. ExpectIntEQ(wc_ecc_init(&key), 0);
  22796. ExpectIntEQ(wc_ecc_init(&keyImp), 0);
  22797. ExpectIntEQ(wc_InitRng(&rng), 0);
  22798. ret = wc_ecc_make_key(&rng, KEY48, &key);
  22799. #if defined(WOLFSSL_ASYNC_CRYPT)
  22800. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22801. #endif
  22802. ExpectIntEQ(ret, 0);
  22803. PRIVATE_KEY_UNLOCK();
  22804. ExpectIntEQ(wc_ecc_export_x963(&key, x963Key, &x963KeySz), 0);
  22805. PRIVATE_KEY_LOCK();
  22806. ExpectIntEQ(wc_ecc_export_private_only(&key, privKey, &privKeySz), 0);
  22807. ExpectIntEQ(wc_ecc_import_private_key(privKey, privKeySz, x963Key,
  22808. x963KeySz, &keyImp), 0);
  22809. /* Pass in bad args. */
  22810. ExpectIntEQ(wc_ecc_import_private_key(privKey, privKeySz, x963Key,
  22811. x963KeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22812. ExpectIntEQ(wc_ecc_import_private_key(NULL, privKeySz, x963Key, x963KeySz,
  22813. &keyImp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22814. PRIVATE_KEY_LOCK();
  22815. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22816. wc_ecc_free(&keyImp);
  22817. wc_ecc_free(&key);
  22818. #ifdef FP_ECC
  22819. wc_ecc_fp_free();
  22820. #endif
  22821. #endif
  22822. return EXPECT_RESULT();
  22823. } /* END test_wc_ecc_import_private_key */
  22824. /*
  22825. * Testing wc_ecc_export_private_only()
  22826. */
  22827. static int test_wc_ecc_export_private_only(void)
  22828. {
  22829. EXPECT_DECLS;
  22830. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22831. ecc_key key;
  22832. WC_RNG rng;
  22833. byte out[ECC_PRIV_KEY_BUF];
  22834. word32 outlen = sizeof(out);
  22835. int ret;
  22836. /* Init stack variables. */
  22837. XMEMSET(&key, 0, sizeof(ecc_key));
  22838. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22839. XMEMSET(out, 0, outlen);
  22840. PRIVATE_KEY_UNLOCK();
  22841. ExpectIntEQ(wc_ecc_init(&key), 0);
  22842. ExpectIntEQ(wc_InitRng(&rng), 0);
  22843. ret = wc_ecc_make_key(&rng, KEY32, &key);
  22844. #if defined(WOLFSSL_ASYNC_CRYPT)
  22845. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22846. #endif
  22847. ExpectIntEQ(ret, 0);
  22848. ExpectIntEQ(wc_ecc_export_private_only(&key, out, &outlen), 0);
  22849. /* Pass in bad args. */
  22850. ExpectIntEQ(wc_ecc_export_private_only(NULL, out, &outlen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22851. ExpectIntEQ(wc_ecc_export_private_only(&key, NULL, &outlen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22852. ExpectIntEQ(wc_ecc_export_private_only(&key, out, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22853. PRIVATE_KEY_LOCK();
  22854. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22855. wc_ecc_free(&key);
  22856. #ifdef FP_ECC
  22857. wc_ecc_fp_free();
  22858. #endif
  22859. #endif
  22860. return EXPECT_RESULT();
  22861. } /* END test_wc_ecc_export_private_only */
  22862. /*
  22863. * Testing wc_ecc_rs_to_sig()
  22864. */
  22865. static int test_wc_ecc_rs_to_sig(void)
  22866. {
  22867. EXPECT_DECLS;
  22868. #if defined(HAVE_ECC) && !defined(NO_ASN)
  22869. /* first [P-192,SHA-1] vector from FIPS 186-3 NIST vectors */
  22870. const char* R = "6994d962bdd0d793ffddf855ec5bf2f91a9698b46258a63e";
  22871. const char* S = "02ba6465a234903744ab02bc8521405b73cf5fc00e1a9f41";
  22872. const char* zeroStr = "0";
  22873. byte sig[ECC_MAX_SIG_SIZE];
  22874. word32 siglen = (word32)sizeof(sig);
  22875. /* R and S max size is the order of curve. 2^192.*/
  22876. int keySz = KEY24;
  22877. byte r[KEY24];
  22878. byte s[KEY24];
  22879. word32 rlen = (word32)sizeof(r);
  22880. word32 slen = (word32)sizeof(s);
  22881. /* Init stack variables. */
  22882. XMEMSET(sig, 0, ECC_MAX_SIG_SIZE);
  22883. XMEMSET(r, 0, keySz);
  22884. XMEMSET(s, 0, keySz);
  22885. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, sig, &siglen), 0);
  22886. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, s, &slen), 0);
  22887. /* Test bad args. */
  22888. ExpectIntEQ(wc_ecc_rs_to_sig(NULL, S, sig, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22889. ExpectIntEQ(wc_ecc_rs_to_sig(R, NULL, sig, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22890. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, sig, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22891. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, NULL, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22892. ExpectIntEQ(wc_ecc_rs_to_sig(R, zeroStr, sig, &siglen), WC_NO_ERR_TRACE(MP_ZERO_E));
  22893. ExpectIntEQ(wc_ecc_rs_to_sig(zeroStr, S, sig, &siglen), WC_NO_ERR_TRACE(MP_ZERO_E));
  22894. ExpectIntEQ(wc_ecc_sig_to_rs(NULL, siglen, r, &rlen, s, &slen),
  22895. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22896. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, NULL, &rlen, s, &slen),
  22897. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22898. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, NULL, s, &slen),
  22899. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22900. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, NULL, &slen),
  22901. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22902. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, s, NULL),
  22903. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22904. #endif
  22905. return EXPECT_RESULT();
  22906. } /* END test_wc_ecc_rs_to_sig */
  22907. static int test_wc_ecc_import_raw(void)
  22908. {
  22909. EXPECT_DECLS;
  22910. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  22911. ecc_key key;
  22912. const char* qx =
  22913. "bb33ac4c27504ac64aa504c33cde9f36db722dce94ea2bfacb2009392c16e861";
  22914. const char* qy =
  22915. "02e9af4dd302939a315b9792217ff0cf18da9111023486e82058330b803489d8";
  22916. const char* d =
  22917. "45b66902739c6c85a1385b72e8e8c7acc4038d533504fa6c28dc348de1a8098c";
  22918. const char* curveName = "SECP256R1";
  22919. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22920. const char* kNullStr = "";
  22921. int ret;
  22922. #endif
  22923. XMEMSET(&key, 0, sizeof(ecc_key));
  22924. ExpectIntEQ(wc_ecc_init(&key), 0);
  22925. /* Test good import */
  22926. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, curveName), 0);
  22927. /* Test bad args. */
  22928. ExpectIntEQ(wc_ecc_import_raw(NULL, qx, qy, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22929. ExpectIntEQ(wc_ecc_import_raw(&key, NULL, qy, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22930. ExpectIntEQ(wc_ecc_import_raw(&key, qx, NULL, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22931. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22932. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22933. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22934. wc_ecc_free(&key);
  22935. #endif
  22936. ExpectIntLT(ret = wc_ecc_import_raw(&key, kNullStr, kNullStr, kNullStr,
  22937. curveName), 0);
  22938. ExpectTrue((ret == WC_NO_ERR_TRACE(ECC_INF_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  22939. #endif
  22940. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  22941. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22942. wc_ecc_free(&key);
  22943. #endif
  22944. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22945. ExpectIntLT(ret = wc_ecc_import_raw(&key, "0", qy, d, curveName), 0);
  22946. ExpectTrue((ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) || (ret == WC_NO_ERR_TRACE(MP_VAL)));
  22947. #else
  22948. ExpectIntEQ(wc_ecc_import_raw(&key, "0", qy, d, curveName), 0);
  22949. #endif
  22950. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22951. wc_ecc_free(&key);
  22952. #endif
  22953. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22954. ExpectIntLT(ret = wc_ecc_import_raw(&key, qx, "0", d, curveName), 0);
  22955. ExpectTrue((ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) || (ret == WC_NO_ERR_TRACE(MP_VAL)));
  22956. #else
  22957. ExpectIntEQ(wc_ecc_import_raw(&key, qx, "0", d, curveName), 0);
  22958. #endif
  22959. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22960. wc_ecc_free(&key);
  22961. #endif
  22962. ExpectIntEQ(wc_ecc_import_raw(&key, "0", "0", d, curveName), WC_NO_ERR_TRACE(ECC_INF_E));
  22963. #endif
  22964. wc_ecc_free(&key);
  22965. #endif
  22966. return EXPECT_RESULT();
  22967. } /* END test_wc_ecc_import_raw */
  22968. static int test_wc_ecc_import_unsigned(void)
  22969. {
  22970. EXPECT_DECLS;
  22971. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(HAVE_SELFTEST) && \
  22972. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  22973. HAVE_FIPS_VERSION >= 2))
  22974. ecc_key key;
  22975. const byte qx[] = {
  22976. 0xbb, 0x33, 0xac, 0x4c, 0x27, 0x50, 0x4a, 0xc6,
  22977. 0x4a, 0xa5, 0x04, 0xc3, 0x3c, 0xde, 0x9f, 0x36,
  22978. 0xdb, 0x72, 0x2d, 0xce, 0x94, 0xea, 0x2b, 0xfa,
  22979. 0xcb, 0x20, 0x09, 0x39, 0x2c, 0x16, 0xe8, 0x61
  22980. };
  22981. const byte qy[] = {
  22982. 0x02, 0xe9, 0xaf, 0x4d, 0xd3, 0x02, 0x93, 0x9a,
  22983. 0x31, 0x5b, 0x97, 0x92, 0x21, 0x7f, 0xf0, 0xcf,
  22984. 0x18, 0xda, 0x91, 0x11, 0x02, 0x34, 0x86, 0xe8,
  22985. 0x20, 0x58, 0x33, 0x0b, 0x80, 0x34, 0x89, 0xd8
  22986. };
  22987. const byte d[] = {
  22988. 0x45, 0xb6, 0x69, 0x02, 0x73, 0x9c, 0x6c, 0x85,
  22989. 0xa1, 0x38, 0x5b, 0x72, 0xe8, 0xe8, 0xc7, 0xac,
  22990. 0xc4, 0x03, 0x8d, 0x53, 0x35, 0x04, 0xfa, 0x6c,
  22991. 0x28, 0xdc, 0x34, 0x8d, 0xe1, 0xa8, 0x09, 0x8c
  22992. };
  22993. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22994. const byte nullBytes[32] = {0};
  22995. int ret;
  22996. #endif
  22997. int curveId = ECC_SECP256R1;
  22998. XMEMSET(&key, 0, sizeof(ecc_key));
  22999. ExpectIntEQ(wc_ecc_init(&key), 0);
  23000. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, (byte*)qy, (byte*)d,
  23001. curveId), 0);
  23002. /* Test bad args. */
  23003. ExpectIntEQ(wc_ecc_import_unsigned(NULL, (byte*)qx, (byte*)qy, (byte*)d,
  23004. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23005. ExpectIntEQ(wc_ecc_import_unsigned(&key, NULL, (byte*)qy, (byte*)d,
  23006. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23007. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, NULL, (byte*)d,
  23008. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23009. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, (byte*)qy, (byte*)d,
  23010. ECC_CURVE_INVALID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23011. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  23012. ExpectIntLT(ret = wc_ecc_import_unsigned(&key, (byte*)nullBytes,
  23013. (byte*)nullBytes, (byte*)nullBytes, curveId), 0);
  23014. ExpectTrue((ret == WC_NO_ERR_TRACE(ECC_INF_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  23015. #endif
  23016. wc_ecc_free(&key);
  23017. #endif
  23018. return EXPECT_RESULT();
  23019. } /* END test_wc_ecc_import_unsigned */
  23020. /*
  23021. * Testing wc_ecc_sig_size()
  23022. */
  23023. static int test_wc_ecc_sig_size(void)
  23024. {
  23025. EXPECT_DECLS;
  23026. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  23027. ecc_key key;
  23028. WC_RNG rng;
  23029. int keySz = KEY16;
  23030. int ret;
  23031. XMEMSET(&rng, 0, sizeof(rng));
  23032. XMEMSET(&key, 0, sizeof(key));
  23033. ExpectIntEQ(wc_ecc_init(&key), 0);
  23034. ExpectIntEQ(wc_InitRng(&rng), 0);
  23035. ret = wc_ecc_make_key(&rng, keySz, &key);
  23036. #if defined(WOLFSSL_ASYNC_CRYPT)
  23037. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23038. #endif
  23039. ExpectIntEQ(ret, 0);
  23040. ExpectIntLE(wc_ecc_sig_size(&key),
  23041. (2 * keySz + SIG_HEADER_SZ + ECC_MAX_PAD_SZ));
  23042. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23043. wc_ecc_free(&key);
  23044. #endif
  23045. return EXPECT_RESULT();
  23046. } /* END test_wc_ecc_sig_size */
  23047. /*
  23048. * Testing wc_ecc_ctx_new()
  23049. */
  23050. static int test_wc_ecc_ctx_new(void)
  23051. {
  23052. EXPECT_DECLS;
  23053. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  23054. WC_RNG rng;
  23055. ecEncCtx* cli = NULL;
  23056. ecEncCtx* srv = NULL;
  23057. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23058. ExpectIntEQ(wc_InitRng(&rng), 0);
  23059. ExpectNotNull(cli = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  23060. ExpectNotNull(srv = wc_ecc_ctx_new(REQ_RESP_SERVER, &rng));
  23061. wc_ecc_ctx_free(cli);
  23062. cli = NULL;
  23063. wc_ecc_ctx_free(srv);
  23064. /* Test bad args. */
  23065. /* wc_ecc_ctx_new_ex() will free if returned NULL. */
  23066. ExpectNull(cli = wc_ecc_ctx_new(0, &rng));
  23067. ExpectNull(cli = wc_ecc_ctx_new(REQ_RESP_CLIENT, NULL));
  23068. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23069. wc_ecc_ctx_free(cli);
  23070. #endif
  23071. return EXPECT_RESULT();
  23072. } /* END test_wc_ecc_ctx_new */
  23073. /*
  23074. * Tesing wc_ecc_reset()
  23075. */
  23076. static int test_wc_ecc_ctx_reset(void)
  23077. {
  23078. EXPECT_DECLS;
  23079. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  23080. ecEncCtx* ctx = NULL;
  23081. WC_RNG rng;
  23082. XMEMSET(&rng, 0, sizeof(rng));
  23083. ExpectIntEQ(wc_InitRng(&rng), 0);
  23084. ExpectNotNull(ctx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  23085. ExpectIntEQ(wc_ecc_ctx_reset(ctx, &rng), 0);
  23086. /* Pass in bad args. */
  23087. ExpectIntEQ(wc_ecc_ctx_reset(NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23088. ExpectIntEQ(wc_ecc_ctx_reset(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23089. wc_ecc_ctx_free(ctx);
  23090. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23091. #endif
  23092. return EXPECT_RESULT();
  23093. } /* END test_wc_ecc_ctx_reset */
  23094. /*
  23095. * Testing wc_ecc_ctx_set_peer_salt() and wc_ecc_ctx_get_own_salt()
  23096. */
  23097. static int test_wc_ecc_ctx_set_peer_salt(void)
  23098. {
  23099. EXPECT_DECLS;
  23100. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  23101. WC_RNG rng;
  23102. ecEncCtx* cliCtx = NULL;
  23103. ecEncCtx* servCtx = NULL;
  23104. const byte* cliSalt = NULL;
  23105. const byte* servSalt = NULL;
  23106. XMEMSET(&rng, 0, sizeof(rng));
  23107. ExpectIntEQ(wc_InitRng(&rng), 0);
  23108. ExpectNotNull(cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  23109. ExpectNotNull(servCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, &rng));
  23110. /* Test bad args. */
  23111. ExpectNull(cliSalt = wc_ecc_ctx_get_own_salt(NULL));
  23112. ExpectNotNull(cliSalt = wc_ecc_ctx_get_own_salt(cliCtx));
  23113. ExpectNotNull(servSalt = wc_ecc_ctx_get_own_salt(servCtx));
  23114. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(cliCtx, servSalt), 0);
  23115. /* Test bad args. */
  23116. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(NULL, servSalt), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23117. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(cliCtx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23118. wc_ecc_ctx_free(cliCtx);
  23119. wc_ecc_ctx_free(servCtx);
  23120. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23121. #endif
  23122. return EXPECT_RESULT();
  23123. } /* END test_wc_ecc_ctx_set_peer_salt */
  23124. /*
  23125. * Testing wc_ecc_ctx_set_info()
  23126. */
  23127. static int test_wc_ecc_ctx_set_info(void)
  23128. {
  23129. EXPECT_DECLS;
  23130. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  23131. ecEncCtx* ctx = NULL;
  23132. WC_RNG rng;
  23133. const char* optInfo = "Optional Test Info.";
  23134. int optInfoSz = (int)XSTRLEN(optInfo);
  23135. const char* badOptInfo = NULL;
  23136. XMEMSET(&rng, 0, sizeof(rng));
  23137. ExpectIntEQ(wc_InitRng(&rng), 0);
  23138. ExpectNotNull(ctx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  23139. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)optInfo, optInfoSz), 0);
  23140. /* Test bad args. */
  23141. ExpectIntEQ(wc_ecc_ctx_set_info(NULL, (byte*)optInfo, optInfoSz),
  23142. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23143. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)badOptInfo, optInfoSz),
  23144. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23145. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)optInfo, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23146. wc_ecc_ctx_free(ctx);
  23147. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23148. #endif
  23149. return EXPECT_RESULT();
  23150. } /* END test_wc_ecc_ctx_set_info */
  23151. /*
  23152. * Testing wc_ecc_encrypt() and wc_ecc_decrypt()
  23153. */
  23154. static int test_wc_ecc_encryptDecrypt(void)
  23155. {
  23156. EXPECT_DECLS;
  23157. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG) && \
  23158. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  23159. ecc_key srvKey;
  23160. ecc_key cliKey;
  23161. ecc_key tmpKey;
  23162. WC_RNG rng;
  23163. int ret;
  23164. const char* msg = "EccBlock Size 16";
  23165. word32 msgSz = (word32)XSTRLEN("EccBlock Size 16");
  23166. #ifdef WOLFSSL_ECIES_OLD
  23167. byte out[(sizeof("EccBlock Size 16") - 1) + WC_SHA256_DIGEST_SIZE];
  23168. #elif defined(WOLFSSL_ECIES_GEN_IV)
  23169. byte out[KEY20 * 2 + 1 + AES_BLOCK_SIZE +
  23170. (sizeof("EccBlock Size 16") - 1) + WC_SHA256_DIGEST_SIZE];
  23171. #else
  23172. byte out[KEY20 * 2 + 1 + (sizeof("EccBlock Size 16") - 1) +
  23173. WC_SHA256_DIGEST_SIZE];
  23174. #endif
  23175. word32 outSz = (word32)sizeof(out);
  23176. byte plain[sizeof("EccBlock Size 16")];
  23177. word32 plainSz = (word32)sizeof(plain);
  23178. int keySz = KEY20;
  23179. /* Init stack variables. */
  23180. XMEMSET(out, 0, outSz);
  23181. XMEMSET(plain, 0, plainSz);
  23182. XMEMSET(&rng, 0, sizeof(rng));
  23183. XMEMSET(&srvKey, 0, sizeof(ecc_key));
  23184. XMEMSET(&cliKey, 0, sizeof(ecc_key));
  23185. XMEMSET(&tmpKey, 0, sizeof(ecc_key));
  23186. ExpectIntEQ(wc_InitRng(&rng), 0);
  23187. ExpectIntEQ(wc_ecc_init(&cliKey), 0);
  23188. ret = wc_ecc_make_key(&rng, keySz, &cliKey);
  23189. #if defined(WOLFSSL_ASYNC_CRYPT)
  23190. ret = wc_AsyncWait(ret, &cliKey.asyncDev, WC_ASYNC_FLAG_NONE);
  23191. #endif
  23192. ExpectIntEQ(ret, 0);
  23193. ExpectIntEQ(wc_ecc_init(&srvKey), 0);
  23194. ret = wc_ecc_make_key(&rng, keySz, &srvKey);
  23195. #if defined(WOLFSSL_ASYNC_CRYPT)
  23196. ret = wc_AsyncWait(ret, &srvKey.asyncDev, WC_ASYNC_FLAG_NONE);
  23197. #endif
  23198. ExpectIntEQ(ret, 0);
  23199. ExpectIntEQ(wc_ecc_init(&tmpKey), 0);
  23200. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  23201. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  23202. !defined(HAVE_SELFTEST)
  23203. ExpectIntEQ(wc_ecc_set_rng(&srvKey, &rng), 0);
  23204. ExpectIntEQ(wc_ecc_set_rng(&cliKey, &rng), 0);
  23205. #endif
  23206. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, out,
  23207. &outSz, NULL), 0);
  23208. /* Test bad args. */
  23209. ExpectIntEQ(wc_ecc_encrypt(NULL, &srvKey, (byte*)msg, msgSz, out, &outSz,
  23210. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23211. ExpectIntEQ(wc_ecc_encrypt(&cliKey, NULL, (byte*)msg, msgSz, out, &outSz,
  23212. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23213. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, NULL, msgSz, out, &outSz,
  23214. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23215. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, NULL,
  23216. &outSz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23217. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, out, NULL,
  23218. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23219. #ifdef WOLFSSL_ECIES_OLD
  23220. tmpKey.dp = cliKey.dp;
  23221. ExpectIntEQ(wc_ecc_copy_point(&cliKey.pubkey, &tmpKey.pubkey), 0);
  23222. #endif
  23223. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, plain, &plainSz,
  23224. NULL), 0);
  23225. ExpectIntEQ(wc_ecc_decrypt(NULL, &tmpKey, out, outSz, plain, &plainSz,
  23226. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23227. #ifdef WOLFSSL_ECIES_OLD
  23228. /* NULL parameter allowed in new implementations - public key comes from
  23229. * the message. */
  23230. ExpectIntEQ(wc_ecc_decrypt(&srvKey, NULL, out, outSz, plain, &plainSz,
  23231. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23232. #endif
  23233. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, NULL, outSz, plain, &plainSz,
  23234. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23235. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, NULL, &plainSz,
  23236. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23237. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, plain, NULL, NULL),
  23238. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23239. ExpectIntEQ(XMEMCMP(msg, plain, msgSz), 0);
  23240. wc_ecc_free(&tmpKey);
  23241. wc_ecc_free(&srvKey);
  23242. wc_ecc_free(&cliKey);
  23243. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23244. #endif
  23245. return EXPECT_RESULT();
  23246. } /* END test_wc_ecc_encryptDecrypt */
  23247. /*
  23248. * Testing wc_ecc_del_point() and wc_ecc_new_point()
  23249. */
  23250. static int test_wc_ecc_del_point(void)
  23251. {
  23252. EXPECT_DECLS;
  23253. #if defined(HAVE_ECC)
  23254. ecc_point* pt = NULL;
  23255. ExpectNotNull(pt = wc_ecc_new_point());
  23256. wc_ecc_del_point(pt);
  23257. #endif
  23258. return EXPECT_RESULT();
  23259. } /* END test_wc_ecc_del_point */
  23260. /*
  23261. * Testing wc_ecc_point_is_at_infinity(), wc_ecc_export_point_der(),
  23262. * wc_ecc_import_point_der(), wc_ecc_copy_point(), wc_ecc_point_is_on_curve(),
  23263. * and wc_ecc_cmp_point()
  23264. */
  23265. static int test_wc_ecc_pointFns(void)
  23266. {
  23267. EXPECT_DECLS;
  23268. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && \
  23269. !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  23270. !defined(WOLFSSL_ATECC608A)
  23271. ecc_key key;
  23272. WC_RNG rng;
  23273. int ret;
  23274. ecc_point* point = NULL;
  23275. ecc_point* cpypt = NULL;
  23276. int idx = 0;
  23277. int keySz = KEY32;
  23278. byte der[DER_SZ(KEY32)];
  23279. word32 derlenChk = 0;
  23280. word32 derSz = DER_SZ(KEY32);
  23281. /* Init stack variables. */
  23282. XMEMSET(der, 0, derSz);
  23283. XMEMSET(&key, 0, sizeof(ecc_key));
  23284. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23285. ExpectIntEQ(wc_InitRng(&rng), 0);
  23286. ExpectIntEQ(wc_ecc_init(&key), 0);
  23287. ret = wc_ecc_make_key(&rng, keySz, &key);
  23288. #if defined(WOLFSSL_ASYNC_CRYPT)
  23289. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23290. #endif
  23291. ExpectIntEQ(ret, 0);
  23292. ExpectNotNull(point = wc_ecc_new_point());
  23293. ExpectNotNull(cpypt = wc_ecc_new_point());
  23294. /* Export */
  23295. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, NULL,
  23296. &derlenChk), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  23297. /* Check length value. */
  23298. ExpectIntEQ(derSz, derlenChk);
  23299. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, der,
  23300. &derSz), 0);
  23301. /* Test bad args. */
  23302. ExpectIntEQ(wc_ecc_export_point_der(-2, &key.pubkey, der, &derSz),
  23303. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23304. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), NULL, der, &derSz),
  23305. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23306. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, der,
  23307. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23308. /* Import */
  23309. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, idx, point), 0);
  23310. ExpectIntEQ(wc_ecc_cmp_point(&key.pubkey, point), 0);
  23311. /* Test bad args. */
  23312. ExpectIntEQ( wc_ecc_import_point_der(NULL, derSz, idx, point),
  23313. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23314. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, idx, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23315. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, -1, point), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23316. ExpectIntEQ(wc_ecc_import_point_der(der, derSz + 1, idx, point),
  23317. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23318. /* Copy */
  23319. ExpectIntEQ(wc_ecc_copy_point(point, cpypt), 0);
  23320. /* Test bad args. */
  23321. ExpectIntEQ(wc_ecc_copy_point(NULL, cpypt), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23322. ExpectIntEQ(wc_ecc_copy_point(point, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23323. /* Compare point */
  23324. ExpectIntEQ(wc_ecc_cmp_point(point, cpypt), 0);
  23325. /* Test bad args. */
  23326. ExpectIntEQ(wc_ecc_cmp_point(NULL, cpypt), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23327. ExpectIntEQ(wc_ecc_cmp_point(point, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23328. /* At infinity if return == 1, otherwise return == 0. */
  23329. ExpectIntEQ(wc_ecc_point_is_at_infinity(point), 0);
  23330. /* Test bad args. */
  23331. ExpectIntEQ(wc_ecc_point_is_at_infinity(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23332. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  23333. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  23334. #ifdef USE_ECC_B_PARAM
  23335. /* On curve if ret == 0 */
  23336. ExpectIntEQ(wc_ecc_point_is_on_curve(point, idx), 0);
  23337. /* Test bad args. */
  23338. ExpectIntEQ(wc_ecc_point_is_on_curve(NULL, idx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23339. ExpectIntEQ(wc_ecc_point_is_on_curve(point, 1000), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23340. #endif /* USE_ECC_B_PARAM */
  23341. #endif /* !HAVE_SELFTEST && (!HAVE_FIPS || HAVE_FIPS_VERSION > 2) */
  23342. /* Free */
  23343. wc_ecc_del_point(point);
  23344. wc_ecc_del_point(cpypt);
  23345. wc_ecc_free(&key);
  23346. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23347. #endif
  23348. return EXPECT_RESULT();
  23349. } /* END test_wc_ecc_pointFns */
  23350. /*
  23351. * Testing wc_ecc_shared_secret_ssh()
  23352. */
  23353. static int test_wc_ecc_shared_secret_ssh(void)
  23354. {
  23355. EXPECT_DECLS;
  23356. #if defined(HAVE_ECC) && defined(HAVE_ECC_DHE) && \
  23357. !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  23358. !defined(WOLFSSL_ATECC608A) && !defined(PLUTON_CRYPTO_ECC) && \
  23359. !defined(WOLFSSL_CRYPTOCELL)
  23360. ecc_key key;
  23361. ecc_key key2;
  23362. WC_RNG rng;
  23363. int ret;
  23364. int keySz = KEY32;
  23365. #if FIPS_VERSION3_GE(6,0,0)
  23366. int key2Sz = KEY28;
  23367. #else
  23368. int key2Sz = KEY24;
  23369. #endif
  23370. byte secret[KEY32];
  23371. word32 secretLen = (word32)keySz;
  23372. /* Init stack variables. */
  23373. XMEMSET(&key, 0, sizeof(ecc_key));
  23374. XMEMSET(&key2, 0, sizeof(ecc_key));
  23375. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23376. XMEMSET(secret, 0, secretLen);
  23377. PRIVATE_KEY_UNLOCK();
  23378. /* Make keys */
  23379. ExpectIntEQ(wc_ecc_init(&key), 0);
  23380. ExpectIntEQ(wc_InitRng(&rng), 0);
  23381. ret = wc_ecc_make_key(&rng, keySz, &key);
  23382. #if defined(WOLFSSL_ASYNC_CRYPT)
  23383. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23384. #endif
  23385. ExpectIntEQ(ret, 0);
  23386. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23387. ExpectIntEQ(wc_ecc_init(&key2), 0);
  23388. ExpectIntEQ(wc_InitRng(&rng), 0);
  23389. ret = wc_ecc_make_key(&rng, key2Sz, &key2);
  23390. #if defined(WOLFSSL_ASYNC_CRYPT)
  23391. ret = wc_AsyncWait(ret, &key2.asyncDev, WC_ASYNC_FLAG_NONE);
  23392. #endif
  23393. ExpectIntEQ(ret, 0);
  23394. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  23395. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  23396. !defined(HAVE_SELFTEST)
  23397. ExpectIntEQ(wc_ecc_set_rng(&key, &rng), 0);
  23398. #endif
  23399. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret,
  23400. &secretLen), 0);
  23401. /* Pass in bad args. */
  23402. ExpectIntEQ(wc_ecc_shared_secret_ssh(NULL, &key2.pubkey, secret,
  23403. &secretLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23404. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, NULL, secret, &secretLen),
  23405. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23406. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, NULL, &secretLen),
  23407. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23408. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret, NULL),
  23409. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23410. key.type = ECC_PUBLICKEY;
  23411. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret,
  23412. &secretLen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23413. PRIVATE_KEY_LOCK();
  23414. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23415. wc_ecc_free(&key);
  23416. wc_ecc_free(&key2);
  23417. #ifdef FP_ECC
  23418. wc_ecc_fp_free();
  23419. #endif
  23420. #endif
  23421. return EXPECT_RESULT();
  23422. } /* END test_wc_ecc_shared_secret_ssh */
  23423. /*
  23424. * Testing wc_ecc_verify_hash_ex() and wc_ecc_verify_hash_ex()
  23425. */
  23426. static int test_wc_ecc_verify_hash_ex(void)
  23427. {
  23428. EXPECT_DECLS;
  23429. #if defined(HAVE_ECC) && defined(HAVE_ECC_SIGN) && defined(WOLFSSL_PUBLIC_MP) \
  23430. && !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  23431. !defined(WOLFSSL_ATECC608A) && !defined(WOLFSSL_KCAPI_ECC)
  23432. ecc_key key;
  23433. WC_RNG rng;
  23434. int ret;
  23435. mp_int r;
  23436. mp_int s;
  23437. mp_int z;
  23438. unsigned char hash[] = "Everyone gets Friday off.EccSig";
  23439. unsigned char iHash[] = "Everyone gets Friday off.......";
  23440. unsigned char shortHash[] = TEST_STRING;
  23441. word32 hashlen = sizeof(hash);
  23442. word32 iHashLen = sizeof(iHash);
  23443. word32 shortHashLen = sizeof(shortHash);
  23444. int keySz = KEY32;
  23445. int verify_ok = 0;
  23446. XMEMSET(&key, 0, sizeof(ecc_key));
  23447. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23448. XMEMSET(&r, 0, sizeof(mp_int));
  23449. XMEMSET(&s, 0, sizeof(mp_int));
  23450. XMEMSET(&z, 0, sizeof(mp_int));
  23451. /* Initialize r, s and z. */
  23452. ExpectIntEQ(mp_init_multi(&r, &s, &z, NULL, NULL, NULL), MP_OKAY);
  23453. ExpectIntEQ(wc_ecc_init(&key), 0);
  23454. ExpectIntEQ(wc_InitRng(&rng), 0);
  23455. ret = wc_ecc_make_key(&rng, keySz, &key);
  23456. #if defined(WOLFSSL_ASYNC_CRYPT)
  23457. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23458. #endif
  23459. ExpectIntEQ(ret, 0);
  23460. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, &r, &s), 0);
  23461. /* verify_ok should be 1. */
  23462. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, hash, hashlen, &verify_ok, &key),
  23463. 0);
  23464. ExpectIntEQ(verify_ok, 1);
  23465. /* verify_ok should be 0 */
  23466. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, iHash, iHashLen, &verify_ok,
  23467. &key), 0);
  23468. ExpectIntEQ(verify_ok, 0);
  23469. /* verify_ok should be 0. */
  23470. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen,
  23471. &verify_ok, &key), 0);
  23472. ExpectIntEQ(verify_ok, 0);
  23473. /* Test bad args. */
  23474. ExpectIntEQ(wc_ecc_sign_hash_ex(NULL, hashlen, &rng, &key, &r, &s),
  23475. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23476. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, NULL, &key, &r, &s),
  23477. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23478. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, NULL, &r, &s),
  23479. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23480. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, NULL, &s),
  23481. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23482. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, &r, NULL),
  23483. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23484. /* Test bad args. */
  23485. ExpectIntEQ(wc_ecc_verify_hash_ex(NULL, &s, shortHash, shortHashLen,
  23486. &verify_ok, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23487. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, NULL, shortHash, shortHashLen,
  23488. &verify_ok, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23489. ExpectIntEQ(wc_ecc_verify_hash_ex(&z, &s, shortHash, shortHashLen,
  23490. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23491. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &z, shortHash, shortHashLen,
  23492. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23493. ExpectIntEQ(wc_ecc_verify_hash_ex(&z, &z, shortHash, shortHashLen,
  23494. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23495. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, NULL, shortHashLen, &verify_ok,
  23496. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23497. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen, NULL,
  23498. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23499. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen,
  23500. &verify_ok, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23501. wc_ecc_free(&key);
  23502. mp_free(&r);
  23503. mp_free(&s);
  23504. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23505. #endif
  23506. return EXPECT_RESULT();
  23507. } /* END test_wc_ecc_verify_hash_ex */
  23508. /*
  23509. * Testing wc_ecc_mulmod()
  23510. */
  23511. static int test_wc_ecc_mulmod(void)
  23512. {
  23513. EXPECT_DECLS;
  23514. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && \
  23515. !(defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) || \
  23516. defined(WOLFSSL_VALIDATE_ECC_IMPORT))
  23517. ecc_key key1;
  23518. ecc_key key2;
  23519. ecc_key key3;
  23520. WC_RNG rng;
  23521. int ret;
  23522. XMEMSET(&key1, 0, sizeof(ecc_key));
  23523. XMEMSET(&key2, 0, sizeof(ecc_key));
  23524. XMEMSET(&key3, 0, sizeof(ecc_key));
  23525. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23526. ExpectIntEQ(wc_ecc_init(&key1), 0);
  23527. ExpectIntEQ(wc_ecc_init(&key2), 0);
  23528. ExpectIntEQ(wc_ecc_init(&key3), 0);
  23529. ExpectIntEQ(wc_InitRng(&rng), 0);
  23530. ret = wc_ecc_make_key(&rng, KEY32, &key1);
  23531. #if defined(WOLFSSL_ASYNC_CRYPT)
  23532. ret = wc_AsyncWait(ret, &key1.asyncDev, WC_ASYNC_FLAG_NONE);
  23533. #endif
  23534. ExpectIntEQ(ret, 0);
  23535. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23536. ExpectIntEQ(wc_ecc_import_raw_ex(&key2, key1.dp->Gx, key1.dp->Gy,
  23537. key1.dp->Af, ECC_SECP256R1), 0);
  23538. ExpectIntEQ(wc_ecc_import_raw_ex(&key3, key1.dp->Gx, key1.dp->Gy,
  23539. key1.dp->prime, ECC_SECP256R1), 0);
  23540. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey,
  23541. &key3.pubkey, wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3),
  23542. 1), 0);
  23543. /* Test bad args. */
  23544. ExpectIntEQ(ret = wc_ecc_mulmod(NULL, &key2.pubkey, &key3.pubkey,
  23545. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23546. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23547. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), NULL, &key3.pubkey,
  23548. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23549. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23550. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey, NULL,
  23551. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23552. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23553. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey,
  23554. &key3.pubkey, wc_ecc_key_get_priv(&key2), NULL, 1), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23555. wc_ecc_free(&key1);
  23556. wc_ecc_free(&key2);
  23557. wc_ecc_free(&key3);
  23558. #ifdef FP_ECC
  23559. wc_ecc_fp_free();
  23560. #endif
  23561. #endif /* HAVE_ECC && !WOLFSSL_ATECC508A */
  23562. return EXPECT_RESULT();
  23563. } /* END test_wc_ecc_mulmod */
  23564. /*
  23565. * Testing wc_ecc_is_valid_idx()
  23566. */
  23567. static int test_wc_ecc_is_valid_idx(void)
  23568. {
  23569. EXPECT_DECLS;
  23570. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  23571. ecc_key key;
  23572. WC_RNG rng;
  23573. int ret;
  23574. int iVal = -2;
  23575. int iVal2 = 3000;
  23576. XMEMSET(&key, 0, sizeof(ecc_key));
  23577. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23578. ExpectIntEQ(wc_ecc_init(&key), 0);
  23579. ExpectIntEQ(wc_InitRng(&rng), 0);
  23580. ret = wc_ecc_make_key(&rng, 32, &key);
  23581. #if defined(WOLFSSL_ASYNC_CRYPT)
  23582. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23583. #endif
  23584. ExpectIntEQ(ret, 0);
  23585. ExpectIntEQ(wc_ecc_is_valid_idx(key.idx), 1);
  23586. /* Test bad args. */
  23587. ExpectIntEQ(wc_ecc_is_valid_idx(iVal), 0);
  23588. ExpectIntEQ(wc_ecc_is_valid_idx(iVal2), 0);
  23589. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23590. wc_ecc_free(&key);
  23591. #ifdef FP_ECC
  23592. wc_ecc_fp_free();
  23593. #endif
  23594. #endif
  23595. return EXPECT_RESULT();
  23596. } /* END test_wc_ecc_is_valid_idx */
  23597. /*
  23598. * Testing wc_ecc_get_curve_id_from_oid()
  23599. */
  23600. static int test_wc_ecc_get_curve_id_from_oid(void)
  23601. {
  23602. EXPECT_DECLS;
  23603. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(HAVE_SELFTEST) && \
  23604. !defined(HAVE_FIPS)
  23605. const byte oid[] = {0x2A,0x86,0x48,0xCE,0x3D,0x03,0x01,0x07};
  23606. word32 len = sizeof(oid);
  23607. /* Bad Cases */
  23608. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(NULL, len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23609. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(oid, 0), ECC_CURVE_INVALID);
  23610. /* Good Case */
  23611. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(oid, len), ECC_SECP256R1);
  23612. #endif
  23613. return EXPECT_RESULT();
  23614. } /* END test_wc_ecc_get_curve_id_from_oid */
  23615. /*
  23616. * Testing wc_ecc_sig_size_calc()
  23617. */
  23618. static int test_wc_ecc_sig_size_calc(void)
  23619. {
  23620. EXPECT_DECLS;
  23621. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST)
  23622. ecc_key key;
  23623. WC_RNG rng;
  23624. int sz = 0;
  23625. int ret;
  23626. XMEMSET(&key, 0, sizeof(ecc_key));
  23627. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23628. ExpectIntEQ(wc_ecc_init(&key), 0);
  23629. ExpectIntEQ(wc_InitRng(&rng), 0);
  23630. ret = wc_ecc_make_key(&rng, 16, &key);
  23631. #if defined(WOLFSSL_ASYNC_CRYPT)
  23632. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23633. #endif
  23634. #if FIPS_VERSION3_GE(6,0,0)
  23635. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23636. #else
  23637. ExpectIntEQ(ret, 0);
  23638. #endif
  23639. #if FIPS_VERSION3_LT(6,0,0)
  23640. sz = key.dp->size;
  23641. ExpectIntGT(wc_ecc_sig_size_calc(sz), 0);
  23642. #else
  23643. (void) sz;
  23644. #endif
  23645. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23646. wc_ecc_free(&key);
  23647. #endif
  23648. return EXPECT_RESULT();
  23649. } /* END test_wc_ecc_sig_size_calc */
  23650. /*
  23651. * Testing wc_ecc_sm2_make_key()
  23652. */
  23653. static int test_wc_ecc_sm2_make_key(void)
  23654. {
  23655. int res = TEST_SKIPPED;
  23656. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2)
  23657. EXPECT_DECLS;
  23658. WC_RNG rng[1];
  23659. ecc_key key[1];
  23660. XMEMSET(rng, 0, sizeof(*rng));
  23661. XMEMSET(key, 0, sizeof(*key));
  23662. ExpectIntEQ(wc_InitRng(rng), 0);
  23663. ExpectIntEQ(wc_ecc_init(key), 0);
  23664. /* Test invalid parameters. */
  23665. ExpectIntEQ(wc_ecc_sm2_make_key(NULL, NULL, WC_ECC_FLAG_NONE),
  23666. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23667. ExpectIntEQ(wc_ecc_sm2_make_key(rng, NULL, WC_ECC_FLAG_NONE),
  23668. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23669. ExpectIntEQ(wc_ecc_sm2_make_key(NULL, key, WC_ECC_FLAG_NONE),
  23670. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23671. /* Test valid parameters. */
  23672. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  23673. ExpectIntEQ(key->dp->id, ECC_SM2P256V1);
  23674. wc_ecc_free(key);
  23675. wc_FreeRng(rng);
  23676. #ifdef FP_ECC
  23677. wc_ecc_fp_free();
  23678. #endif
  23679. res = EXPECT_RESULT();
  23680. #endif
  23681. return res;
  23682. }
  23683. /*
  23684. * Testing wc_ecc_sm2_shared_secret()
  23685. */
  23686. static int test_wc_ecc_sm2_shared_secret(void)
  23687. {
  23688. int res = TEST_SKIPPED;
  23689. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2)
  23690. EXPECT_DECLS;
  23691. WC_RNG rng[1];
  23692. ecc_key keyA[1];
  23693. ecc_key keyB[1];
  23694. byte outA[32];
  23695. byte outB[32];
  23696. word32 outALen = 32;
  23697. word32 outBLen = 32;
  23698. XMEMSET(rng, 0, sizeof(*rng));
  23699. XMEMSET(keyA, 0, sizeof(*keyA));
  23700. XMEMSET(keyB, 0, sizeof(*keyB));
  23701. ExpectIntEQ(wc_InitRng(rng), 0);
  23702. ExpectIntEQ(wc_ecc_init(keyA), 0);
  23703. ExpectIntEQ(wc_ecc_init(keyB), 0);
  23704. ExpectIntEQ(wc_ecc_sm2_make_key(rng, keyA, WC_ECC_FLAG_NONE), 0);
  23705. ExpectIntEQ(wc_ecc_sm2_make_key(rng, keyB, WC_ECC_FLAG_NONE), 0);
  23706. #ifdef ECC_TIMING_RESISTANT
  23707. ExpectIntEQ(wc_ecc_set_rng(keyA, rng), 0);
  23708. ExpectIntEQ(wc_ecc_set_rng(keyB, rng), 0);
  23709. #endif
  23710. /* Test invalid parameters. */
  23711. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23712. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23713. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, keyB, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23714. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, outA, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23715. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, NULL, &outALen),
  23716. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23717. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, keyB, outA, &outALen),
  23718. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23719. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, NULL, outA, &outALen),
  23720. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23721. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, NULL, &outALen),
  23722. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23723. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, outA, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23724. /* Test valid parameters. */
  23725. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, outA, &outALen), 0);
  23726. ExpectIntLE(outALen, 32);
  23727. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyB, keyA, outB, &outBLen), 0);
  23728. ExpectIntLE(outBLen, 32);
  23729. ExpectIntEQ(outALen, outBLen);
  23730. ExpectBufEQ(outA, outB, outALen);
  23731. wc_ecc_free(keyB);
  23732. wc_ecc_free(keyA);
  23733. wc_FreeRng(rng);
  23734. #ifdef FP_ECC
  23735. wc_ecc_fp_free();
  23736. #endif
  23737. res = EXPECT_RESULT();
  23738. #endif
  23739. return res;
  23740. }
  23741. /*
  23742. * Testing wc_ecc_sm2_create_digest()
  23743. */
  23744. static int test_wc_ecc_sm2_create_digest(void)
  23745. {
  23746. int res = TEST_SKIPPED;
  23747. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && !defined(NO_HASH_WRAPPER) && \
  23748. (defined(WOLFSSL_SM3) || !defined(NO_SHA256))
  23749. EXPECT_DECLS;
  23750. ecc_key key[1];
  23751. enum wc_HashType hashType;
  23752. unsigned char pub[] = {
  23753. 0x04,
  23754. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  23755. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  23756. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  23757. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  23758. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  23759. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  23760. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  23761. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  23762. };
  23763. unsigned char id[] = {
  23764. 0x01, 0x02, 0x03,
  23765. };
  23766. unsigned char msg[] = {
  23767. 0x01, 0x02, 0x03,
  23768. };
  23769. unsigned char hash[32];
  23770. #ifdef WOLFSSL_SM3
  23771. unsigned char expHash[32] = {
  23772. 0xc1, 0xdd, 0x92, 0xc5, 0x60, 0xd3, 0x94, 0x28,
  23773. 0xeb, 0x0f, 0x57, 0x79, 0x3f, 0xc9, 0x96, 0xc5,
  23774. 0xfa, 0xf5, 0x90, 0xb2, 0x64, 0x2f, 0xaf, 0x9c,
  23775. 0xc8, 0x57, 0x21, 0x6a, 0x52, 0x7e, 0xf1, 0x95
  23776. };
  23777. #else
  23778. unsigned char expHash[32] = {
  23779. 0xea, 0x41, 0x55, 0x21, 0x61, 0x00, 0x5c, 0x9a,
  23780. 0x57, 0x35, 0x6b, 0x49, 0xca, 0x8f, 0x65, 0xc2,
  23781. 0x0e, 0x29, 0x0c, 0xa0, 0x1d, 0xa7, 0xc4, 0xed,
  23782. 0xdd, 0x51, 0x12, 0xf6, 0xe7, 0x55, 0xc5, 0xf4
  23783. };
  23784. #endif
  23785. #ifdef WOLFSSL_SM3
  23786. hashType = WC_HASH_TYPE_SM3;
  23787. #else
  23788. hashType = WC_HASH_TYPE_SHA256;
  23789. #endif
  23790. XMEMSET(key, 0, sizeof(*key));
  23791. ExpectIntEQ(wc_ecc_init(key), 0);
  23792. /* Test with no curve set. */
  23793. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23794. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23795. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  23796. /* Test invalid parameters. */
  23797. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23798. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23799. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), NULL, sizeof(msg),
  23800. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23801. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), msg, sizeof(msg),
  23802. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23803. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23804. hashType, hash, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23805. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23806. hashType, NULL, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23807. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), msg, sizeof(msg),
  23808. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23809. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), NULL, sizeof(msg),
  23810. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23811. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23812. hashType, NULL, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23813. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23814. hashType, hash, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23815. /* Bad hash type. */
  23816. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  23817. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23818. -1, hash, 0, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23819. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  23820. /* Bad hash size. */
  23821. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23822. hashType, hash, 0, key), WC_NO_ERR_TRACE(BUFFER_E));
  23823. /* Test valid parameters. */
  23824. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23825. hashType, hash, sizeof(hash), key), 0);
  23826. ExpectBufEQ(hash, expHash, sizeof(expHash));
  23827. wc_ecc_free(key);
  23828. res = EXPECT_RESULT();
  23829. #endif
  23830. return res;
  23831. }
  23832. /*
  23833. * Testing wc_ecc_sm2_verify_hash_ex()
  23834. */
  23835. static int test_wc_ecc_sm2_verify_hash_ex(void)
  23836. {
  23837. int res = TEST_SKIPPED;
  23838. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_VERIFY) && \
  23839. defined(WOLFSSL_PUBLIC_MP)
  23840. EXPECT_DECLS;
  23841. ecc_key key[1];
  23842. mp_int r[1];
  23843. mp_int s[1];
  23844. int verified;
  23845. unsigned char pub[] = {
  23846. 0x04,
  23847. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  23848. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  23849. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  23850. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  23851. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  23852. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  23853. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  23854. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  23855. };
  23856. unsigned char hash[] = {
  23857. 0x3B, 0xFA, 0x5F, 0xFB, 0xC4, 0x27, 0x8C, 0x9D,
  23858. 0x02, 0x3A, 0x19, 0xCB, 0x1E, 0xAA, 0xD2, 0xF1,
  23859. 0x50, 0x69, 0x5B, 0x20
  23860. };
  23861. unsigned char rData[] = {
  23862. 0xD2, 0xFC, 0xA3, 0x88, 0xE3, 0xDF, 0xA3, 0x00,
  23863. 0x73, 0x9B, 0x3C, 0x2A, 0x0D, 0xAD, 0x44, 0xA2,
  23864. 0xFC, 0x62, 0xD5, 0x6B, 0x84, 0x54, 0xD8, 0x40,
  23865. 0x22, 0x62, 0x3D, 0x5C, 0xA6, 0x61, 0x9B, 0xE7,
  23866. };
  23867. unsigned char sData[] = {
  23868. 0x1D,
  23869. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  23870. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  23871. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  23872. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDC
  23873. };
  23874. unsigned char rBadData[] = {
  23875. 0xD2, 0xFC, 0xA3, 0x88, 0xE3, 0xDF, 0xA3, 0x00,
  23876. 0x73, 0x9B, 0x3C, 0x2A, 0x0D, 0xAD, 0x44, 0xA2,
  23877. 0xFC, 0x62, 0xD5, 0x6B, 0x84, 0x54, 0xD8, 0x40,
  23878. 0x22, 0x62, 0x3D, 0x5C, 0xA6, 0x61, 0x9B, 0xE8,
  23879. };
  23880. XMEMSET(key, 0, sizeof(*key));
  23881. XMEMSET(r, 0, sizeof(*r));
  23882. XMEMSET(s, 0, sizeof(*s));
  23883. ExpectIntEQ(mp_init(r), 0);
  23884. ExpectIntEQ(mp_init(s), 0);
  23885. ExpectIntEQ(mp_read_unsigned_bin(r, rData, sizeof(rData)), 0);
  23886. ExpectIntEQ(mp_read_unsigned_bin(s, sData, sizeof(sData)), 0);
  23887. ExpectIntEQ(wc_ecc_init(key), 0);
  23888. /* Test with no curve set. */
  23889. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23890. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23891. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  23892. /* Test invalid parameters. */
  23893. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  23894. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23895. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, NULL, NULL, sizeof(hash),
  23896. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23897. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, s, NULL, sizeof(hash),
  23898. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23899. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, hash, sizeof(hash),
  23900. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23901. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  23902. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23903. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  23904. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23905. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, s, hash, sizeof(hash),
  23906. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23907. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, NULL, hash, sizeof(hash),
  23908. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23909. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, NULL, sizeof(hash),
  23910. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23911. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23912. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23913. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23914. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23915. /* Make key not on the SM2 curve. */
  23916. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  23917. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23918. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23919. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  23920. /* Test valid parameters. */
  23921. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23922. &verified, key), 0);
  23923. ExpectIntEQ(verified, 1);
  23924. ExpectIntEQ(mp_read_unsigned_bin(r, rBadData, sizeof(rBadData)), 0);
  23925. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23926. &verified, key), 0);
  23927. ExpectIntEQ(verified, 0);
  23928. mp_free(s);
  23929. mp_free(r);
  23930. wc_ecc_free(key);
  23931. #ifdef FP_ECC
  23932. wc_ecc_fp_free();
  23933. #endif
  23934. res = EXPECT_RESULT();
  23935. #endif
  23936. return res;
  23937. }
  23938. /*
  23939. * Testing wc_ecc_sm2_verify_hash()
  23940. */
  23941. static int test_wc_ecc_sm2_verify_hash(void)
  23942. {
  23943. int res = TEST_SKIPPED;
  23944. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_VERIFY)
  23945. EXPECT_DECLS;
  23946. ecc_key key[1];
  23947. int verified;
  23948. unsigned char pub[] = {
  23949. 0x04,
  23950. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  23951. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  23952. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  23953. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  23954. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  23955. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  23956. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  23957. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  23958. };
  23959. unsigned char hash[] = {
  23960. 0x3B, 0xFA, 0x5F, 0xFB, 0xC4, 0x27, 0x8C, 0x9D,
  23961. 0x02, 0x3A, 0x19, 0xCB, 0x1E, 0xAA, 0xD2, 0xF1,
  23962. 0x50, 0x69, 0x5B, 0x20
  23963. };
  23964. unsigned char sig[] = {
  23965. 0x30, 0x45, 0x02, 0x21, 0x00, 0xD2, 0xFC, 0xA3,
  23966. 0x88, 0xE3, 0xDF, 0xA3, 0x00, 0x73, 0x9B, 0x3C,
  23967. 0x2A, 0x0D, 0xAD, 0x44, 0xA2, 0xFC, 0x62, 0xD5,
  23968. 0x6B, 0x84, 0x54, 0xD8, 0x40, 0x22, 0x62, 0x3D,
  23969. 0x5C, 0xA6, 0x61, 0x9B, 0xE7, 0x02, 0x20, 0x1D,
  23970. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  23971. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  23972. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  23973. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDC
  23974. };
  23975. unsigned char sigBad[] = {
  23976. 0x30, 0x45, 0x02, 0x21, 0x00, 0xD2, 0xFC, 0xA3,
  23977. 0x88, 0xE3, 0xDF, 0xA3, 0x00, 0x73, 0x9B, 0x3C,
  23978. 0x2A, 0x0D, 0xAD, 0x44, 0xA2, 0xFC, 0x62, 0xD5,
  23979. 0x6B, 0x84, 0x54, 0xD8, 0x40, 0x22, 0x62, 0x3D,
  23980. 0x5C, 0xA6, 0x61, 0x9B, 0xE7, 0x02, 0x20, 0x1D,
  23981. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  23982. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  23983. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  23984. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDD
  23985. };
  23986. XMEMSET(key, 0, sizeof(*key));
  23987. ExpectIntEQ(wc_ecc_init(key), 0);
  23988. /* Test with no curve set. */
  23989. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  23990. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23991. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  23992. /* Test invalid parameters. */
  23993. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  23994. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23995. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), NULL, sizeof(hash),
  23996. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23997. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), hash, sizeof(hash),
  23998. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23999. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  24000. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24001. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  24002. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24003. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), hash, sizeof(hash),
  24004. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24005. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), NULL, sizeof(hash),
  24006. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24007. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  24008. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24009. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  24010. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24011. /* Make key not on the SM2 curve. */
  24012. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  24013. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  24014. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24015. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  24016. /* Test valid parameters. */
  24017. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  24018. &verified, key), 0);
  24019. ExpectIntEQ(verified, 1);
  24020. ExpectIntEQ(wc_ecc_sm2_verify_hash(sigBad, sizeof(sigBad), hash,
  24021. sizeof(hash), &verified, key), 0);
  24022. ExpectIntEQ(verified, 0);
  24023. wc_ecc_free(key);
  24024. #ifdef FP_ECC
  24025. wc_ecc_fp_free();
  24026. #endif
  24027. res = EXPECT_RESULT();
  24028. #endif
  24029. return res;
  24030. }
  24031. /*
  24032. * Testing wc_ecc_sm2_verify_hash_ex()
  24033. */
  24034. static int test_wc_ecc_sm2_sign_hash_ex(void)
  24035. {
  24036. int res = TEST_SKIPPED;
  24037. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_SIGN) && \
  24038. defined(WOLFSSL_PUBLIC_MP)
  24039. EXPECT_DECLS;
  24040. WC_RNG rng[1];
  24041. ecc_key key[1];
  24042. mp_int r[1];
  24043. mp_int s[1];
  24044. unsigned char hash[32];
  24045. #ifdef HAVE_ECC_VERIFY
  24046. int verified;
  24047. #endif
  24048. XMEMSET(rng, 0, sizeof(*rng));
  24049. XMEMSET(key, 0, sizeof(*key));
  24050. XMEMSET(r, 0, sizeof(*r));
  24051. XMEMSET(s, 0, sizeof(*s));
  24052. ExpectIntEQ(wc_InitRng(rng), 0);
  24053. ExpectIntEQ(mp_init(r), 0);
  24054. ExpectIntEQ(mp_init(s), 0);
  24055. ExpectIntEQ(wc_RNG_GenerateBlock(rng, hash, sizeof(hash)), 0);
  24056. ExpectIntEQ(wc_ecc_init(key), 0);
  24057. /* Test with no curve set. */
  24058. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  24059. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24060. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  24061. /* Test invalid parameters. */
  24062. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, NULL,
  24063. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24064. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), NULL, NULL, NULL,
  24065. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24066. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), rng, NULL, NULL,
  24067. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24068. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, key, NULL,
  24069. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24070. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, r,
  24071. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24072. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, NULL,
  24073. s), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24074. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), rng, key, r, s),
  24075. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24076. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), NULL, key, r, s),
  24077. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24078. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, NULL, r, s),
  24079. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24080. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, NULL, s),
  24081. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24082. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, NULL),
  24083. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24084. /* Make key not on the SM2 curve. */
  24085. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  24086. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  24087. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24088. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  24089. #ifdef WOLFSSL_SP_MATH_ALL
  24090. {
  24091. mp_int smallR[1];
  24092. sp_init_size(smallR, 1);
  24093. /* Force failure in _ecc_sm2_calc_r_s by r being too small. */
  24094. ExpectIntLT(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key,
  24095. smallR, s), 0);
  24096. }
  24097. #endif
  24098. /* Test valid parameters. */
  24099. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  24100. 0);
  24101. #ifdef HAVE_ECC_VERIFY
  24102. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash), &verified,
  24103. key), 0);
  24104. ExpectIntEQ(verified, 1);
  24105. #endif
  24106. mp_free(s);
  24107. mp_free(r);
  24108. wc_ecc_free(key);
  24109. wc_FreeRng(rng);
  24110. #ifdef FP_ECC
  24111. wc_ecc_fp_free();
  24112. #endif
  24113. res = EXPECT_RESULT();
  24114. #endif
  24115. return res;
  24116. }
  24117. /*
  24118. * Testing wc_ecc_sm2_verify_hash()
  24119. */
  24120. static int test_wc_ecc_sm2_sign_hash(void)
  24121. {
  24122. int res = TEST_SKIPPED;
  24123. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_SIGN)
  24124. EXPECT_DECLS;
  24125. WC_RNG rng[1];
  24126. ecc_key key[1];
  24127. unsigned char hash[32];
  24128. unsigned char sig[72];
  24129. word32 sigSz = sizeof(sig);
  24130. #ifdef HAVE_ECC_VERIFY
  24131. int verified;
  24132. #endif
  24133. XMEMSET(rng, 0, sizeof(*rng));
  24134. XMEMSET(key, 0, sizeof(*key));
  24135. ExpectIntEQ(wc_InitRng(rng), 0);
  24136. ExpectIntEQ(wc_RNG_GenerateBlock(rng, hash, sizeof(hash)), 0);
  24137. ExpectIntEQ(wc_ecc_init(key), 0);
  24138. /* Test with no curve set. */
  24139. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  24140. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24141. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  24142. /* Test invalid parameters. */
  24143. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, NULL,
  24144. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24145. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), NULL, NULL, NULL,
  24146. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24147. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), sig, NULL, NULL,
  24148. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24149. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, &sigSz, NULL,
  24150. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24151. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, rng,
  24152. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24153. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, NULL,
  24154. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24155. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), sig, &sigSz, rng,
  24156. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24157. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), NULL, &sigSz, rng,
  24158. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24159. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, NULL, rng,
  24160. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24161. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, NULL,
  24162. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24163. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng,
  24164. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24165. /* Make key not on the SM2 curve. */
  24166. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  24167. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  24168. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24169. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  24170. /* Test valid parameters. */
  24171. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  24172. 0);
  24173. #ifdef HAVE_ECC_VERIFY
  24174. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sigSz, hash, sizeof(hash),
  24175. &verified, key), 0);
  24176. ExpectIntEQ(verified, 1);
  24177. #endif
  24178. wc_ecc_free(key);
  24179. wc_FreeRng(rng);
  24180. #ifdef FP_ECC
  24181. wc_ecc_fp_free();
  24182. #endif
  24183. res = EXPECT_RESULT();
  24184. #endif
  24185. return res;
  24186. }
  24187. /*
  24188. * Testing ToTraditional
  24189. */
  24190. static int test_ToTraditional(void)
  24191. {
  24192. EXPECT_DECLS;
  24193. #if !defined(NO_ASN) && (defined(HAVE_PKCS8) || defined(HAVE_PKCS12)) && \
  24194. (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
  24195. defined(OPENSSL_EXTRA_X509_SMALL)) && !defined(NO_FILESYSTEM)
  24196. XFILE f = XBADFILE;
  24197. byte input[TWOK_BUF];
  24198. word32 sz = 0;
  24199. ExpectTrue((f = XFOPEN("./certs/server-keyPkcs8.der", "rb")) != XBADFILE);
  24200. ExpectTrue((sz = (word32)XFREAD(input, 1, sizeof(input), f)) > 0);
  24201. if (f != XBADFILE)
  24202. XFCLOSE(f);
  24203. /* Good case */
  24204. ExpectIntGT(ToTraditional(input, sz), 0);
  24205. /* Bad cases */
  24206. ExpectIntEQ(ToTraditional(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24207. ExpectIntEQ(ToTraditional(NULL, sz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24208. #ifdef WOLFSSL_ASN_TEMPLATE
  24209. ExpectIntEQ(ToTraditional(input, 0), WC_NO_ERR_TRACE(BUFFER_E));
  24210. #else
  24211. ExpectIntEQ(ToTraditional(input, 0), WC_NO_ERR_TRACE(ASN_PARSE_E));
  24212. #endif
  24213. #endif
  24214. return EXPECT_RESULT();
  24215. } /* End test_ToTraditional*/
  24216. /*
  24217. * Testing wc_EccPrivateKeyToDer
  24218. */
  24219. static int test_wc_EccPrivateKeyToDer(void)
  24220. {
  24221. EXPECT_DECLS;
  24222. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  24223. byte output[ONEK_BUF];
  24224. ecc_key eccKey;
  24225. WC_RNG rng;
  24226. word32 inLen;
  24227. word32 outLen = 0;
  24228. int ret;
  24229. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  24230. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24231. PRIVATE_KEY_UNLOCK();
  24232. ExpectIntEQ(wc_InitRng(&rng), 0);
  24233. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  24234. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  24235. #if defined(WOLFSSL_ASYNC_CRYPT)
  24236. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  24237. #endif
  24238. ExpectIntEQ(ret, 0);
  24239. inLen = (word32)sizeof(output);
  24240. /* Bad Cases */
  24241. ExpectIntEQ(wc_EccPrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24242. ExpectIntEQ(wc_EccPrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24243. ExpectIntEQ(wc_EccPrivateKeyToDer(&eccKey, NULL, inLen), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  24244. ExpectIntEQ(wc_EccPrivateKeyToDer(&eccKey, output, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24245. /* Good Case */
  24246. ExpectIntGT(outLen = (word32)wc_EccPrivateKeyToDer(&eccKey, output, inLen), 0);
  24247. wc_ecc_free(&eccKey);
  24248. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24249. #if defined(OPENSSL_EXTRA) && defined(HAVE_ALL_CURVES)
  24250. {
  24251. /* test importing private only into a PKEY struct */
  24252. EC_KEY* ec = NULL;
  24253. EVP_PKEY* pkey = NULL;
  24254. const unsigned char* der;
  24255. der = output;
  24256. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &der, outLen));
  24257. der = output;
  24258. ExpectNotNull(ec = d2i_ECPrivateKey(NULL, &der, outLen));
  24259. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ec), SSL_SUCCESS);
  24260. if (EXPECT_FAIL()) {
  24261. EC_KEY_free(ec);
  24262. }
  24263. EVP_PKEY_free(pkey); /* EC_KEY should be free'd by free'ing pkey */
  24264. }
  24265. #endif
  24266. PRIVATE_KEY_LOCK();
  24267. #endif
  24268. return EXPECT_RESULT();
  24269. } /* End test_wc_EccPrivateKeyToDer*/
  24270. /*
  24271. * Testing wc_DhPublicKeyDecode
  24272. */
  24273. static int test_wc_DhPublicKeyDecode(void)
  24274. {
  24275. EXPECT_DECLS;
  24276. #ifndef NO_DH
  24277. #if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048)
  24278. DhKey key;
  24279. word32 inOutIdx;
  24280. XMEMSET(&key, 0, sizeof(DhKey));
  24281. ExpectIntEQ(wc_InitDhKey(&key), 0);
  24282. ExpectIntEQ(wc_DhPublicKeyDecode(NULL,NULL,NULL,0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24283. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,NULL,NULL,0),
  24284. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24285. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,NULL,NULL,0),
  24286. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24287. inOutIdx = 0;
  24288. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,NULL, 0),
  24289. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24290. inOutIdx = 0;
  24291. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key, 0),
  24292. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24293. inOutIdx = 0;
  24294. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key,
  24295. sizeof_dh_pub_key_der_2048), 0);
  24296. ExpectIntNE(key.p.used, 0);
  24297. ExpectIntNE(key.g.used, 0);
  24298. ExpectIntEQ(key.q.used, 0);
  24299. ExpectIntNE(key.pub.used, 0);
  24300. ExpectIntEQ(key.priv.used, 0);
  24301. DoExpectIntEQ(wc_FreeDhKey(&key), 0);
  24302. #endif
  24303. #endif /* !NO_DH */
  24304. return EXPECT_RESULT();
  24305. }
  24306. /*
  24307. * Testing wc_Ed25519KeyToDer
  24308. */
  24309. static int test_wc_Ed25519KeyToDer(void)
  24310. {
  24311. EXPECT_DECLS;
  24312. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  24313. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24314. byte output[ONEK_BUF];
  24315. ed25519_key ed25519Key;
  24316. WC_RNG rng;
  24317. word32 inLen;
  24318. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  24319. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24320. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  24321. ExpectIntEQ(wc_InitRng(&rng), 0);
  24322. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  24323. inLen = (word32)sizeof(output);
  24324. /* Bad Cases */
  24325. ExpectIntEQ(wc_Ed25519KeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24326. ExpectIntEQ(wc_Ed25519KeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24327. ExpectIntEQ(wc_Ed25519KeyToDer(&ed25519Key, output, 0), WC_NO_ERR_TRACE(BUFFER_E));
  24328. /* Good Cases */
  24329. /* length only */
  24330. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, NULL, 0), 0);
  24331. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, NULL, inLen), 0);
  24332. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, output, inLen), 0);
  24333. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24334. wc_ed25519_free(&ed25519Key);
  24335. #endif
  24336. return EXPECT_RESULT();
  24337. } /* End test_wc_Ed25519KeyToDer*/
  24338. /*
  24339. * Testing wc_Ed25519PrivateKeyToDer
  24340. */
  24341. static int test_wc_Ed25519PrivateKeyToDer(void)
  24342. {
  24343. EXPECT_DECLS;
  24344. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  24345. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24346. byte output[ONEK_BUF];
  24347. ed25519_key ed25519PrivKey;
  24348. WC_RNG rng;
  24349. word32 inLen;
  24350. XMEMSET(&ed25519PrivKey, 0, sizeof(ed25519_key));
  24351. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24352. ExpectIntEQ(wc_ed25519_init(&ed25519PrivKey), 0);
  24353. ExpectIntEQ(wc_InitRng(&rng), 0);
  24354. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519PrivKey),
  24355. 0);
  24356. inLen = (word32)sizeof(output);
  24357. /* Bad Cases */
  24358. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24359. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24360. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, output, 0),
  24361. WC_NO_ERR_TRACE(BUFFER_E));
  24362. /* Good Cases */
  24363. /* length only */
  24364. ExpectIntGT(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, NULL, 0), 0);
  24365. ExpectIntGT(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, output, inLen), 0);
  24366. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24367. wc_ed25519_free(&ed25519PrivKey);
  24368. #endif
  24369. return EXPECT_RESULT();
  24370. } /* End test_wc_Ed25519PrivateKeyToDer*/
  24371. /*
  24372. * Testing wc_Ed448KeyToDer
  24373. */
  24374. static int test_wc_Ed448KeyToDer(void)
  24375. {
  24376. EXPECT_DECLS;
  24377. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  24378. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24379. byte output[ONEK_BUF];
  24380. ed448_key ed448Key;
  24381. WC_RNG rng;
  24382. word32 inLen;
  24383. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  24384. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24385. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  24386. ExpectIntEQ(wc_InitRng(&rng), 0);
  24387. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  24388. inLen = (word32)sizeof(output);
  24389. /* Bad Cases */
  24390. ExpectIntEQ(wc_Ed448KeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24391. ExpectIntEQ(wc_Ed448KeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24392. ExpectIntEQ(wc_Ed448KeyToDer(&ed448Key, output, 0), WC_NO_ERR_TRACE(BUFFER_E));
  24393. /* Good Cases */
  24394. /* length only */
  24395. ExpectIntGT(wc_Ed448KeyToDer(&ed448Key, NULL, 0), 0);
  24396. ExpectIntGT(wc_Ed448KeyToDer(&ed448Key, output, inLen), 0);
  24397. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24398. wc_ed448_free(&ed448Key);
  24399. #endif
  24400. return EXPECT_RESULT();
  24401. } /* End test_wc_Ed448KeyToDer*/
  24402. /*
  24403. * Testing wc_Ed448PrivateKeyToDer
  24404. */
  24405. static int test_wc_Ed448PrivateKeyToDer(void)
  24406. {
  24407. EXPECT_DECLS;
  24408. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  24409. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24410. byte output[ONEK_BUF];
  24411. ed448_key ed448PrivKey;
  24412. WC_RNG rng;
  24413. word32 inLen;
  24414. XMEMSET(&ed448PrivKey, 0, sizeof(ed448_key));
  24415. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24416. ExpectIntEQ(wc_ed448_init(&ed448PrivKey), 0);
  24417. ExpectIntEQ(wc_InitRng(&rng), 0);
  24418. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448PrivKey),
  24419. 0);
  24420. inLen = (word32)sizeof(output);
  24421. /* Bad Cases */
  24422. ExpectIntEQ(wc_Ed448PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24423. ExpectIntEQ(wc_Ed448PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24424. ExpectIntEQ(wc_Ed448PrivateKeyToDer(&ed448PrivKey, output, 0),
  24425. WC_NO_ERR_TRACE(BUFFER_E));
  24426. /* Good cases */
  24427. /* length only */
  24428. ExpectIntGT(wc_Ed448PrivateKeyToDer(&ed448PrivKey, NULL, 0), 0);
  24429. ExpectIntGT(wc_Ed448PrivateKeyToDer(&ed448PrivKey, output, inLen), 0);
  24430. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24431. wc_ed448_free(&ed448PrivKey);
  24432. #endif
  24433. return EXPECT_RESULT();
  24434. } /* End test_wc_Ed448PrivateKeyToDer*/
  24435. /*
  24436. * Testing wc_Curve448PrivateKeyToDer
  24437. */
  24438. static int test_wc_Curve448PrivateKeyToDer(void)
  24439. {
  24440. EXPECT_DECLS;
  24441. #if defined(HAVE_CURVE448) && defined(HAVE_CURVE448_KEY_EXPORT) && \
  24442. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24443. byte output[ONEK_BUF];
  24444. curve448_key curve448PrivKey;
  24445. WC_RNG rng;
  24446. word32 inLen;
  24447. XMEMSET(&curve448PrivKey, 0, sizeof(curve448PrivKey));
  24448. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24449. ExpectIntEQ(wc_curve448_init(&curve448PrivKey), 0);
  24450. ExpectIntEQ(wc_InitRng(&rng), 0);
  24451. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &curve448PrivKey),
  24452. 0);
  24453. inLen = (word32)sizeof(output);
  24454. /* Bad Cases */
  24455. ExpectIntEQ(wc_Curve448PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24456. ExpectIntEQ(wc_Curve448PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24457. ExpectIntEQ(wc_Curve448PrivateKeyToDer(&curve448PrivKey, output, 0),
  24458. WC_NO_ERR_TRACE(BUFFER_E));
  24459. /* Good cases */
  24460. /* length only */
  24461. ExpectIntGT(wc_Curve448PrivateKeyToDer(&curve448PrivKey, NULL, 0), 0);
  24462. ExpectIntGT(wc_Curve448PrivateKeyToDer(&curve448PrivKey, output, inLen), 0);
  24463. /* Bad Cases */
  24464. ExpectIntEQ(wc_Curve448PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24465. ExpectIntEQ(wc_Curve448PublicKeyToDer(NULL, output, inLen, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24466. ExpectIntEQ(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, 0, 0),
  24467. WC_NO_ERR_TRACE(BUFFER_E));
  24468. ExpectIntEQ(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, 0, 1),
  24469. WC_NO_ERR_TRACE(BUFFER_E));
  24470. /* Good cases */
  24471. /* length only */
  24472. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, NULL, 0, 0), 0);
  24473. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, NULL, 0, 1), 0);
  24474. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, inLen, 0), 0);
  24475. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, inLen, 1), 0);
  24476. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24477. wc_curve448_free(&curve448PrivKey);
  24478. #endif
  24479. return EXPECT_RESULT();
  24480. } /* End wc_Curve448PrivateKeyToDer*/
  24481. static int test_wc_kyber_make_key_kats(void)
  24482. {
  24483. EXPECT_DECLS;
  24484. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  24485. !defined(WOLFSSL_KYBER_ORIGINAL)
  24486. KyberKey* key;
  24487. #ifndef WOLFSSL_NO_KYBER512
  24488. static const byte seed_512[KYBER_MAKEKEY_RAND_SZ] = {
  24489. /* d */
  24490. 0x2C, 0xB8, 0x43, 0xA0, 0x2E, 0xF0, 0x2E, 0xE1,
  24491. 0x09, 0x30, 0x5F, 0x39, 0x11, 0x9F, 0xAB, 0xF4,
  24492. 0x9A, 0xB9, 0x0A, 0x57, 0xFF, 0xEC, 0xB3, 0xA0,
  24493. 0xE7, 0x5E, 0x17, 0x94, 0x50, 0xF5, 0x27, 0x61,
  24494. /* z */
  24495. 0x84, 0xCC, 0x91, 0x21, 0xAE, 0x56, 0xFB, 0xF3,
  24496. 0x9E, 0x67, 0xAD, 0xBD, 0x83, 0xAD, 0x2D, 0x3E,
  24497. 0x3B, 0xB8, 0x08, 0x43, 0x64, 0x52, 0x06, 0xBD,
  24498. 0xD9, 0xF2, 0xF6, 0x29, 0xE3, 0xCC, 0x49, 0xB7
  24499. };
  24500. static const byte ek_512[KYBER512_PUBLIC_KEY_SIZE] = {
  24501. 0xA3, 0x24, 0x39, 0xF8, 0x5A, 0x3C, 0x21, 0xD2,
  24502. 0x1A, 0x71, 0xB9, 0xB9, 0x2A, 0x9B, 0x64, 0xEA,
  24503. 0x0A, 0xB8, 0x43, 0x12, 0xC7, 0x70, 0x23, 0x69,
  24504. 0x4F, 0xD6, 0x4E, 0xAA, 0xB9, 0x07, 0xA4, 0x35,
  24505. 0x39, 0xDD, 0xB2, 0x7B, 0xA0, 0xA8, 0x53, 0xCC,
  24506. 0x90, 0x69, 0xEA, 0xC8, 0x50, 0x8C, 0x65, 0x3E,
  24507. 0x60, 0x0B, 0x2A, 0xC0, 0x18, 0x38, 0x1B, 0x4B,
  24508. 0xB4, 0xA8, 0x79, 0xAC, 0xDA, 0xD3, 0x42, 0xF9,
  24509. 0x11, 0x79, 0xCA, 0x82, 0x49, 0x52, 0x5C, 0xB1,
  24510. 0x96, 0x8B, 0xBE, 0x52, 0xF7, 0x55, 0xB7, 0xF5,
  24511. 0xB4, 0x3D, 0x66, 0x63, 0xD7, 0xA3, 0xBF, 0x0F,
  24512. 0x33, 0x57, 0xD8, 0xA2, 0x1D, 0x15, 0xB5, 0x2D,
  24513. 0xB3, 0x81, 0x8E, 0xCE, 0x5B, 0x40, 0x2A, 0x60,
  24514. 0xC9, 0x93, 0xE7, 0xCF, 0x43, 0x64, 0x87, 0xB8,
  24515. 0xD2, 0xAE, 0x91, 0xE6, 0xC5, 0xB8, 0x82, 0x75,
  24516. 0xE7, 0x58, 0x24, 0xB0, 0x00, 0x7E, 0xF3, 0x12,
  24517. 0x3C, 0x0A, 0xB5, 0x1B, 0x5C, 0xC6, 0x1B, 0x9B,
  24518. 0x22, 0x38, 0x0D, 0xE6, 0x6C, 0x5B, 0x20, 0xB0,
  24519. 0x60, 0xCB, 0xB9, 0x86, 0xF8, 0x12, 0x3D, 0x94,
  24520. 0x06, 0x00, 0x49, 0xCD, 0xF8, 0x03, 0x68, 0x73,
  24521. 0xA7, 0xBE, 0x10, 0x94, 0x44, 0xA0, 0xA1, 0xCD,
  24522. 0x87, 0xA4, 0x8C, 0xAE, 0x54, 0x19, 0x24, 0x84,
  24523. 0xAF, 0x84, 0x44, 0x29, 0xC1, 0xC5, 0x8C, 0x29,
  24524. 0xAC, 0x62, 0x4C, 0xD5, 0x04, 0xF1, 0xC4, 0x4F,
  24525. 0x1E, 0x13, 0x47, 0x82, 0x2B, 0x6F, 0x22, 0x13,
  24526. 0x23, 0x85, 0x9A, 0x7F, 0x6F, 0x75, 0x4B, 0xFE,
  24527. 0x71, 0x0B, 0xDA, 0x60, 0x27, 0x62, 0x40, 0xA4,
  24528. 0xFF, 0x2A, 0x53, 0x50, 0x70, 0x37, 0x86, 0xF5,
  24529. 0x67, 0x1F, 0x44, 0x9F, 0x20, 0xC2, 0xA9, 0x5A,
  24530. 0xE7, 0xC2, 0x90, 0x3A, 0x42, 0xCB, 0x3B, 0x30,
  24531. 0x3F, 0xF4, 0xC4, 0x27, 0xC0, 0x8B, 0x11, 0xB4,
  24532. 0xCD, 0x31, 0xC4, 0x18, 0xC6, 0xD1, 0x8D, 0x08,
  24533. 0x61, 0x87, 0x3B, 0xFA, 0x03, 0x32, 0xF1, 0x12,
  24534. 0x71, 0x55, 0x2E, 0xD7, 0xC0, 0x35, 0xF0, 0xE4,
  24535. 0xBC, 0x42, 0x8C, 0x43, 0x72, 0x0B, 0x39, 0xA6,
  24536. 0x51, 0x66, 0xBA, 0x9C, 0x2D, 0x3D, 0x77, 0x0E,
  24537. 0x13, 0x03, 0x60, 0xCC, 0x23, 0x84, 0xE8, 0x30,
  24538. 0x95, 0xB1, 0xA1, 0x59, 0x49, 0x55, 0x33, 0xF1,
  24539. 0x16, 0xC7, 0xB5, 0x58, 0xB6, 0x50, 0xDB, 0x04,
  24540. 0xD5, 0xA2, 0x6E, 0xAA, 0xA0, 0x8C, 0x3E, 0xE5,
  24541. 0x7D, 0xE4, 0x5A, 0x7F, 0x88, 0xC6, 0xA3, 0xCE,
  24542. 0xB2, 0x4D, 0xC5, 0x39, 0x7B, 0x88, 0xC3, 0xCE,
  24543. 0xF0, 0x03, 0x31, 0x9B, 0xB0, 0x23, 0x3F, 0xD6,
  24544. 0x92, 0xFD, 0xA1, 0x52, 0x44, 0x75, 0xB3, 0x51,
  24545. 0xF3, 0xC7, 0x82, 0x18, 0x2D, 0xEC, 0xF5, 0x90,
  24546. 0xB7, 0x72, 0x3B, 0xE4, 0x00, 0xBE, 0x14, 0x80,
  24547. 0x9C, 0x44, 0x32, 0x99, 0x63, 0xFC, 0x46, 0x95,
  24548. 0x92, 0x11, 0xD6, 0xA6, 0x23, 0x33, 0x95, 0x37,
  24549. 0x84, 0x8C, 0x25, 0x16, 0x69, 0x94, 0x1D, 0x90,
  24550. 0xB1, 0x30, 0x25, 0x8A, 0xDF, 0x55, 0xA7, 0x20,
  24551. 0xA7, 0x24, 0xE8, 0xB6, 0xA6, 0xCA, 0xE3, 0xC2,
  24552. 0x26, 0x4B, 0x16, 0x24, 0xCC, 0xBE, 0x7B, 0x45,
  24553. 0x6B, 0x30, 0xC8, 0xC7, 0x39, 0x32, 0x94, 0xCA,
  24554. 0x51, 0x80, 0xBC, 0x83, 0x7D, 0xD2, 0xE4, 0x5D,
  24555. 0xBD, 0x59, 0xB6, 0xE1, 0x7B, 0x24, 0xFE, 0x93,
  24556. 0x05, 0x2E, 0xB7, 0xC4, 0x3B, 0x27, 0xAC, 0x3D,
  24557. 0xC2, 0x49, 0xCA, 0x0C, 0xBC, 0xA4, 0xFB, 0x58,
  24558. 0x97, 0xC0, 0xB7, 0x44, 0x08, 0x8A, 0x8A, 0x07,
  24559. 0x79, 0xD3, 0x22, 0x33, 0x82, 0x6A, 0x01, 0xDD,
  24560. 0x64, 0x89, 0x95, 0x2A, 0x48, 0x25, 0xE5, 0x35,
  24561. 0x8A, 0x70, 0x0B, 0xE0, 0xE1, 0x79, 0xAC, 0x19,
  24562. 0x77, 0x10, 0xD8, 0x3E, 0xCC, 0x85, 0x3E, 0x52,
  24563. 0x69, 0x5E, 0x9B, 0xF8, 0x7B, 0xB1, 0xF6, 0xCB,
  24564. 0xD0, 0x5B, 0x02, 0xD4, 0xE6, 0x79, 0xE3, 0xB8,
  24565. 0x8D, 0xD4, 0x83, 0xB0, 0x74, 0x9B, 0x11, 0xBD,
  24566. 0x37, 0xB3, 0x83, 0xDC, 0xCA, 0x71, 0xF9, 0x09,
  24567. 0x18, 0x34, 0xA1, 0x69, 0x55, 0x02, 0xC4, 0xB9,
  24568. 0x5F, 0xC9, 0x11, 0x8C, 0x1C, 0xFC, 0x34, 0xC8,
  24569. 0x4C, 0x22, 0x65, 0xBB, 0xBC, 0x56, 0x3C, 0x28,
  24570. 0x26, 0x66, 0xB6, 0x0A, 0xE5, 0xC7, 0xF3, 0x85,
  24571. 0x1D, 0x25, 0xEC, 0xBB, 0x50, 0x21, 0xCC, 0x38,
  24572. 0xCB, 0x73, 0xEB, 0x6A, 0x34, 0x11, 0xB1, 0xC2,
  24573. 0x90, 0x46, 0xCA, 0x66, 0x54, 0x06, 0x67, 0xD1,
  24574. 0x36, 0x95, 0x44, 0x60, 0xC6, 0xFC, 0xBC, 0x4B,
  24575. 0xC7, 0xC0, 0x49, 0xBB, 0x04, 0x7F, 0xA6, 0x7A,
  24576. 0x63, 0xB3, 0xCC, 0x11, 0x11, 0xC1, 0xD8, 0xAC,
  24577. 0x27, 0xE8, 0x05, 0x8B, 0xCC, 0xA4, 0xA1, 0x54,
  24578. 0x55, 0x85, 0x8A, 0x58, 0x35, 0x8F, 0x7A, 0x61,
  24579. 0x02, 0x0B, 0xC9, 0xC4, 0xC1, 0x7F, 0x8B, 0x95,
  24580. 0xC2, 0x68, 0xCC, 0xB4, 0x04, 0xB9, 0xAA, 0xB4,
  24581. 0xA2, 0x72, 0xA2, 0x1A, 0x70, 0xDA, 0xF6, 0xB6,
  24582. 0xF1, 0x51, 0x21, 0xEE, 0x01, 0xC1, 0x56, 0xA3,
  24583. 0x54, 0xAA, 0x17, 0x08, 0x7E, 0x07, 0x70, 0x2E,
  24584. 0xAB, 0x38, 0xB3, 0x24, 0x1F, 0xDB, 0x55, 0x3F,
  24585. 0x65, 0x73, 0x39, 0xD5, 0xE2, 0x9D, 0xC5, 0xD9,
  24586. 0x1B, 0x7A, 0x5A, 0x82, 0x8E, 0xE9, 0x59, 0xFE,
  24587. 0xBB, 0x90, 0xB0, 0x72, 0x29, 0xF6, 0xE4, 0x9D,
  24588. 0x23, 0xC3, 0xA1, 0x90, 0x29, 0x70, 0x42, 0xFB,
  24589. 0x43, 0x98, 0x69, 0x55, 0xB6, 0x9C, 0x28, 0xE1,
  24590. 0x01, 0x6F, 0x77, 0xA5, 0x8B, 0x43, 0x15, 0x14,
  24591. 0xD2, 0x1B, 0x88, 0x88, 0x99, 0xC3, 0x60, 0x82,
  24592. 0x76, 0x08, 0x1B, 0x75, 0xF5, 0x68, 0x09, 0x7C,
  24593. 0xDC, 0x17, 0x48, 0xF3, 0x23, 0x07, 0x88, 0x58,
  24594. 0x15, 0xF3, 0xAE, 0xC9, 0x65, 0x18, 0x19, 0xAA,
  24595. 0x68, 0x73, 0xD1, 0xA4, 0xEB, 0x83, 0xB1, 0x95,
  24596. 0x38, 0x43, 0xB9, 0x34, 0x22, 0x51, 0x94, 0x83,
  24597. 0xFE, 0xF0, 0x05, 0x9D, 0x36, 0xBB, 0x2D, 0xB1,
  24598. 0xF3, 0xD4, 0x68, 0xFB, 0x06, 0x8C, 0x86, 0xE8,
  24599. 0x97, 0x37, 0x33, 0xC3, 0x98, 0xEA, 0xF0, 0x0E,
  24600. 0x17, 0x02, 0xC6, 0x73, 0x4A, 0xD8, 0xEB, 0x3B
  24601. };
  24602. static const byte dk_512[KYBER512_PRIVATE_KEY_SIZE] = {
  24603. 0x7F, 0xE4, 0x20, 0x6F, 0x26, 0xBE, 0xDB, 0x64,
  24604. 0xC1, 0xED, 0x00, 0x09, 0x61, 0x52, 0x45, 0xDC,
  24605. 0x98, 0x48, 0x3F, 0x66, 0x3A, 0xCC, 0x61, 0x7E,
  24606. 0x65, 0x89, 0x8D, 0x59, 0x6A, 0x88, 0x36, 0xC4,
  24607. 0x9F, 0xBD, 0x3B, 0x4A, 0x84, 0x97, 0x59, 0xAA,
  24608. 0x15, 0x46, 0xBD, 0xA8, 0x35, 0xCA, 0xF1, 0x75,
  24609. 0x64, 0x2C, 0x28, 0x28, 0x08, 0x92, 0xA7, 0x87,
  24610. 0x8C, 0xC3, 0x18, 0xBC, 0xC7, 0x5B, 0x83, 0x4C,
  24611. 0xB2, 0x9F, 0xDF, 0x53, 0x60, 0xD7, 0xF9, 0x82,
  24612. 0xA5, 0x2C, 0x88, 0xAE, 0x91, 0x4D, 0xBF, 0x02,
  24613. 0xB5, 0x8B, 0xEB, 0x8B, 0xA8, 0x87, 0xAE, 0x8F,
  24614. 0xAB, 0x5E, 0xB7, 0x87, 0x31, 0xC6, 0x75, 0x78,
  24615. 0x05, 0x47, 0x1E, 0xBC, 0xEC, 0x2E, 0x38, 0xDB,
  24616. 0x1F, 0x4B, 0x83, 0x10, 0xD2, 0x88, 0x92, 0x0D,
  24617. 0x8A, 0x49, 0x27, 0x95, 0xA3, 0x90, 0xA7, 0x4B,
  24618. 0xCD, 0x55, 0xCD, 0x85, 0x57, 0xB4, 0xDA, 0xAB,
  24619. 0xA8, 0x2C, 0x28, 0xCB, 0x3F, 0x15, 0x2C, 0x52,
  24620. 0x31, 0x19, 0x61, 0x93, 0xA6, 0x6A, 0x8C, 0xCF,
  24621. 0x34, 0xB8, 0x0E, 0x1F, 0x69, 0x42, 0xC3, 0x2B,
  24622. 0xCF, 0xF9, 0x6A, 0x6E, 0x3C, 0xF3, 0x93, 0x9B,
  24623. 0x7B, 0x94, 0x24, 0x98, 0xCC, 0x5E, 0x4C, 0xB8,
  24624. 0xE8, 0x46, 0x8E, 0x70, 0x27, 0x59, 0x85, 0x2A,
  24625. 0xA2, 0x29, 0xC0, 0x25, 0x7F, 0x02, 0x98, 0x20,
  24626. 0x97, 0x33, 0x86, 0x07, 0xC0, 0xF0, 0xF4, 0x54,
  24627. 0x46, 0xFA, 0xB4, 0x26, 0x79, 0x93, 0xB8, 0xA5,
  24628. 0x90, 0x8C, 0xAB, 0x9C, 0x46, 0x78, 0x01, 0x34,
  24629. 0x80, 0x4A, 0xE1, 0x88, 0x15, 0xB1, 0x02, 0x05,
  24630. 0x27, 0xA2, 0x22, 0xEC, 0x4B, 0x39, 0xA3, 0x19,
  24631. 0x4E, 0x66, 0x17, 0x37, 0x79, 0x17, 0x14, 0x12,
  24632. 0x26, 0x62, 0xD8, 0xB9, 0x76, 0x9F, 0x6C, 0x67,
  24633. 0xDE, 0x62, 0x5C, 0x0D, 0x48, 0x3C, 0x3D, 0x42,
  24634. 0x0F, 0xF1, 0xBB, 0x88, 0x9A, 0x72, 0x7E, 0x75,
  24635. 0x62, 0x81, 0x51, 0x3A, 0x70, 0x04, 0x76, 0x48,
  24636. 0xD2, 0x9C, 0x0C, 0x30, 0xF9, 0xBE, 0x52, 0xEC,
  24637. 0x0D, 0xEB, 0x97, 0x7C, 0xF0, 0xF3, 0x4F, 0xC2,
  24638. 0x07, 0x84, 0x83, 0x45, 0x69, 0x64, 0x74, 0x34,
  24639. 0x10, 0x63, 0x8C, 0x57, 0xB5, 0x53, 0x95, 0x77,
  24640. 0xBF, 0x85, 0x66, 0x90, 0x78, 0xC3, 0x56, 0xB3,
  24641. 0x46, 0x2E, 0x9F, 0xA5, 0x80, 0x7D, 0x49, 0x59,
  24642. 0x1A, 0xFA, 0x41, 0xC1, 0x96, 0x9F, 0x65, 0xE3,
  24643. 0x40, 0x5C, 0xB6, 0x4D, 0xDF, 0x16, 0x3F, 0x26,
  24644. 0x73, 0x4C, 0xE3, 0x48, 0xB9, 0xCF, 0x45, 0x67,
  24645. 0xA3, 0x3A, 0x59, 0x69, 0xEB, 0x32, 0x6C, 0xFB,
  24646. 0x5A, 0xDC, 0x69, 0x5D, 0xCA, 0x0C, 0x8B, 0x2A,
  24647. 0x7B, 0x1F, 0x4F, 0x40, 0x4C, 0xC7, 0xA0, 0x98,
  24648. 0x1E, 0x2C, 0xC2, 0x4C, 0x1C, 0x23, 0xD1, 0x6A,
  24649. 0xA9, 0xB4, 0x39, 0x24, 0x15, 0xE2, 0x6C, 0x22,
  24650. 0xF4, 0xA9, 0x34, 0xD7, 0x94, 0xC1, 0xFB, 0x4E,
  24651. 0x5A, 0x67, 0x05, 0x11, 0x23, 0xCC, 0xD1, 0x53,
  24652. 0x76, 0x4D, 0xEC, 0x99, 0xD5, 0x53, 0x52, 0x90,
  24653. 0x53, 0xC3, 0xDA, 0x55, 0x0B, 0xCE, 0xA3, 0xAC,
  24654. 0x54, 0x13, 0x6A, 0x26, 0xA6, 0x76, 0xD2, 0xBA,
  24655. 0x84, 0x21, 0x06, 0x70, 0x68, 0xC6, 0x38, 0x1C,
  24656. 0x2A, 0x62, 0xA7, 0x27, 0xC9, 0x33, 0x70, 0x2E,
  24657. 0xE5, 0x80, 0x4A, 0x31, 0xCA, 0x86, 0x5A, 0x45,
  24658. 0x58, 0x8F, 0xB7, 0x4D, 0xE7, 0xE2, 0x22, 0x3D,
  24659. 0x88, 0xC0, 0x60, 0x8A, 0x16, 0xBF, 0xEC, 0x4F,
  24660. 0xAD, 0x67, 0x52, 0xDB, 0x56, 0xB4, 0x8B, 0x88,
  24661. 0x72, 0xBF, 0x26, 0xBA, 0x2F, 0xFA, 0x0C, 0xED,
  24662. 0xE5, 0x34, 0x3B, 0xE8, 0x14, 0x36, 0x89, 0x26,
  24663. 0x5E, 0x06, 0x5F, 0x41, 0xA6, 0x92, 0x5B, 0x86,
  24664. 0xC8, 0x92, 0xE6, 0x2E, 0xB0, 0x77, 0x27, 0x34,
  24665. 0xF5, 0xA3, 0x57, 0xC7, 0x5C, 0xA1, 0xAC, 0x6D,
  24666. 0xF7, 0x8A, 0xB1, 0xB8, 0x88, 0x5A, 0xD0, 0x81,
  24667. 0x96, 0x15, 0x37, 0x6D, 0x33, 0xEB, 0xB9, 0x8F,
  24668. 0x87, 0x33, 0xA6, 0x75, 0x58, 0x03, 0xD9, 0x77,
  24669. 0xBF, 0x51, 0xC1, 0x27, 0x40, 0x42, 0x4B, 0x2B,
  24670. 0x49, 0xC2, 0x83, 0x82, 0xA6, 0x91, 0x7C, 0xBF,
  24671. 0xA0, 0x34, 0xC3, 0xF1, 0x26, 0xA3, 0x8C, 0x21,
  24672. 0x6C, 0x03, 0xC3, 0x57, 0x70, 0xAD, 0x48, 0x1B,
  24673. 0x90, 0x84, 0xB5, 0x58, 0x8D, 0xA6, 0x5F, 0xF1,
  24674. 0x18, 0xA7, 0x4F, 0x93, 0x2C, 0x7E, 0x53, 0x7A,
  24675. 0xBE, 0x58, 0x63, 0xFB, 0x29, 0xA1, 0x0C, 0x09,
  24676. 0x70, 0x1B, 0x44, 0x1F, 0x83, 0x99, 0xC1, 0xF8,
  24677. 0xA6, 0x37, 0x82, 0x5A, 0xCE, 0xA3, 0xE9, 0x31,
  24678. 0x80, 0x57, 0x4F, 0xDE, 0xB8, 0x80, 0x76, 0x66,
  24679. 0x1A, 0xB4, 0x69, 0x51, 0x71, 0x6A, 0x50, 0x01,
  24680. 0x84, 0xA0, 0x40, 0x55, 0x72, 0x66, 0x59, 0x8C,
  24681. 0xAF, 0x76, 0x10, 0x5E, 0x1C, 0x18, 0x70, 0xB4,
  24682. 0x39, 0x69, 0xC3, 0xBC, 0xC1, 0xA0, 0x49, 0x27,
  24683. 0x63, 0x80, 0x17, 0x49, 0x8B, 0xB6, 0x2C, 0xAF,
  24684. 0xD3, 0xA6, 0xB0, 0x82, 0xB7, 0xBF, 0x7A, 0x23,
  24685. 0x45, 0x0E, 0x19, 0x17, 0x99, 0x61, 0x9B, 0x92,
  24686. 0x51, 0x12, 0xD0, 0x72, 0x02, 0x5C, 0xA8, 0x88,
  24687. 0x54, 0x8C, 0x79, 0x1A, 0xA4, 0x22, 0x51, 0x50,
  24688. 0x4D, 0x5D, 0x1C, 0x1C, 0xDD, 0xB2, 0x13, 0x30,
  24689. 0x3B, 0x04, 0x9E, 0x73, 0x46, 0xE8, 0xD8, 0x3A,
  24690. 0xD5, 0x87, 0x83, 0x6F, 0x35, 0x28, 0x4E, 0x10,
  24691. 0x97, 0x27, 0xE6, 0x6B, 0xBC, 0xC9, 0x52, 0x1F,
  24692. 0xE0, 0xB1, 0x91, 0x63, 0x00, 0x47, 0xD1, 0x58,
  24693. 0xF7, 0x56, 0x40, 0xFF, 0xEB, 0x54, 0x56, 0x07,
  24694. 0x27, 0x40, 0x02, 0x1A, 0xFD, 0x15, 0xA4, 0x54,
  24695. 0x69, 0xC5, 0x83, 0x82, 0x9D, 0xAA, 0xC8, 0xA7,
  24696. 0xDE, 0xB0, 0x5B, 0x24, 0xF0, 0x56, 0x7E, 0x43,
  24697. 0x17, 0xB3, 0xE3, 0xB3, 0x33, 0x89, 0xB5, 0xC5,
  24698. 0xF8, 0xB0, 0x4B, 0x09, 0x9F, 0xB4, 0xD1, 0x03,
  24699. 0xA3, 0x24, 0x39, 0xF8, 0x5A, 0x3C, 0x21, 0xD2,
  24700. 0x1A, 0x71, 0xB9, 0xB9, 0x2A, 0x9B, 0x64, 0xEA,
  24701. 0x0A, 0xB8, 0x43, 0x12, 0xC7, 0x70, 0x23, 0x69,
  24702. 0x4F, 0xD6, 0x4E, 0xAA, 0xB9, 0x07, 0xA4, 0x35,
  24703. 0x39, 0xDD, 0xB2, 0x7B, 0xA0, 0xA8, 0x53, 0xCC,
  24704. 0x90, 0x69, 0xEA, 0xC8, 0x50, 0x8C, 0x65, 0x3E,
  24705. 0x60, 0x0B, 0x2A, 0xC0, 0x18, 0x38, 0x1B, 0x4B,
  24706. 0xB4, 0xA8, 0x79, 0xAC, 0xDA, 0xD3, 0x42, 0xF9,
  24707. 0x11, 0x79, 0xCA, 0x82, 0x49, 0x52, 0x5C, 0xB1,
  24708. 0x96, 0x8B, 0xBE, 0x52, 0xF7, 0x55, 0xB7, 0xF5,
  24709. 0xB4, 0x3D, 0x66, 0x63, 0xD7, 0xA3, 0xBF, 0x0F,
  24710. 0x33, 0x57, 0xD8, 0xA2, 0x1D, 0x15, 0xB5, 0x2D,
  24711. 0xB3, 0x81, 0x8E, 0xCE, 0x5B, 0x40, 0x2A, 0x60,
  24712. 0xC9, 0x93, 0xE7, 0xCF, 0x43, 0x64, 0x87, 0xB8,
  24713. 0xD2, 0xAE, 0x91, 0xE6, 0xC5, 0xB8, 0x82, 0x75,
  24714. 0xE7, 0x58, 0x24, 0xB0, 0x00, 0x7E, 0xF3, 0x12,
  24715. 0x3C, 0x0A, 0xB5, 0x1B, 0x5C, 0xC6, 0x1B, 0x9B,
  24716. 0x22, 0x38, 0x0D, 0xE6, 0x6C, 0x5B, 0x20, 0xB0,
  24717. 0x60, 0xCB, 0xB9, 0x86, 0xF8, 0x12, 0x3D, 0x94,
  24718. 0x06, 0x00, 0x49, 0xCD, 0xF8, 0x03, 0x68, 0x73,
  24719. 0xA7, 0xBE, 0x10, 0x94, 0x44, 0xA0, 0xA1, 0xCD,
  24720. 0x87, 0xA4, 0x8C, 0xAE, 0x54, 0x19, 0x24, 0x84,
  24721. 0xAF, 0x84, 0x44, 0x29, 0xC1, 0xC5, 0x8C, 0x29,
  24722. 0xAC, 0x62, 0x4C, 0xD5, 0x04, 0xF1, 0xC4, 0x4F,
  24723. 0x1E, 0x13, 0x47, 0x82, 0x2B, 0x6F, 0x22, 0x13,
  24724. 0x23, 0x85, 0x9A, 0x7F, 0x6F, 0x75, 0x4B, 0xFE,
  24725. 0x71, 0x0B, 0xDA, 0x60, 0x27, 0x62, 0x40, 0xA4,
  24726. 0xFF, 0x2A, 0x53, 0x50, 0x70, 0x37, 0x86, 0xF5,
  24727. 0x67, 0x1F, 0x44, 0x9F, 0x20, 0xC2, 0xA9, 0x5A,
  24728. 0xE7, 0xC2, 0x90, 0x3A, 0x42, 0xCB, 0x3B, 0x30,
  24729. 0x3F, 0xF4, 0xC4, 0x27, 0xC0, 0x8B, 0x11, 0xB4,
  24730. 0xCD, 0x31, 0xC4, 0x18, 0xC6, 0xD1, 0x8D, 0x08,
  24731. 0x61, 0x87, 0x3B, 0xFA, 0x03, 0x32, 0xF1, 0x12,
  24732. 0x71, 0x55, 0x2E, 0xD7, 0xC0, 0x35, 0xF0, 0xE4,
  24733. 0xBC, 0x42, 0x8C, 0x43, 0x72, 0x0B, 0x39, 0xA6,
  24734. 0x51, 0x66, 0xBA, 0x9C, 0x2D, 0x3D, 0x77, 0x0E,
  24735. 0x13, 0x03, 0x60, 0xCC, 0x23, 0x84, 0xE8, 0x30,
  24736. 0x95, 0xB1, 0xA1, 0x59, 0x49, 0x55, 0x33, 0xF1,
  24737. 0x16, 0xC7, 0xB5, 0x58, 0xB6, 0x50, 0xDB, 0x04,
  24738. 0xD5, 0xA2, 0x6E, 0xAA, 0xA0, 0x8C, 0x3E, 0xE5,
  24739. 0x7D, 0xE4, 0x5A, 0x7F, 0x88, 0xC6, 0xA3, 0xCE,
  24740. 0xB2, 0x4D, 0xC5, 0x39, 0x7B, 0x88, 0xC3, 0xCE,
  24741. 0xF0, 0x03, 0x31, 0x9B, 0xB0, 0x23, 0x3F, 0xD6,
  24742. 0x92, 0xFD, 0xA1, 0x52, 0x44, 0x75, 0xB3, 0x51,
  24743. 0xF3, 0xC7, 0x82, 0x18, 0x2D, 0xEC, 0xF5, 0x90,
  24744. 0xB7, 0x72, 0x3B, 0xE4, 0x00, 0xBE, 0x14, 0x80,
  24745. 0x9C, 0x44, 0x32, 0x99, 0x63, 0xFC, 0x46, 0x95,
  24746. 0x92, 0x11, 0xD6, 0xA6, 0x23, 0x33, 0x95, 0x37,
  24747. 0x84, 0x8C, 0x25, 0x16, 0x69, 0x94, 0x1D, 0x90,
  24748. 0xB1, 0x30, 0x25, 0x8A, 0xDF, 0x55, 0xA7, 0x20,
  24749. 0xA7, 0x24, 0xE8, 0xB6, 0xA6, 0xCA, 0xE3, 0xC2,
  24750. 0x26, 0x4B, 0x16, 0x24, 0xCC, 0xBE, 0x7B, 0x45,
  24751. 0x6B, 0x30, 0xC8, 0xC7, 0x39, 0x32, 0x94, 0xCA,
  24752. 0x51, 0x80, 0xBC, 0x83, 0x7D, 0xD2, 0xE4, 0x5D,
  24753. 0xBD, 0x59, 0xB6, 0xE1, 0x7B, 0x24, 0xFE, 0x93,
  24754. 0x05, 0x2E, 0xB7, 0xC4, 0x3B, 0x27, 0xAC, 0x3D,
  24755. 0xC2, 0x49, 0xCA, 0x0C, 0xBC, 0xA4, 0xFB, 0x58,
  24756. 0x97, 0xC0, 0xB7, 0x44, 0x08, 0x8A, 0x8A, 0x07,
  24757. 0x79, 0xD3, 0x22, 0x33, 0x82, 0x6A, 0x01, 0xDD,
  24758. 0x64, 0x89, 0x95, 0x2A, 0x48, 0x25, 0xE5, 0x35,
  24759. 0x8A, 0x70, 0x0B, 0xE0, 0xE1, 0x79, 0xAC, 0x19,
  24760. 0x77, 0x10, 0xD8, 0x3E, 0xCC, 0x85, 0x3E, 0x52,
  24761. 0x69, 0x5E, 0x9B, 0xF8, 0x7B, 0xB1, 0xF6, 0xCB,
  24762. 0xD0, 0x5B, 0x02, 0xD4, 0xE6, 0x79, 0xE3, 0xB8,
  24763. 0x8D, 0xD4, 0x83, 0xB0, 0x74, 0x9B, 0x11, 0xBD,
  24764. 0x37, 0xB3, 0x83, 0xDC, 0xCA, 0x71, 0xF9, 0x09,
  24765. 0x18, 0x34, 0xA1, 0x69, 0x55, 0x02, 0xC4, 0xB9,
  24766. 0x5F, 0xC9, 0x11, 0x8C, 0x1C, 0xFC, 0x34, 0xC8,
  24767. 0x4C, 0x22, 0x65, 0xBB, 0xBC, 0x56, 0x3C, 0x28,
  24768. 0x26, 0x66, 0xB6, 0x0A, 0xE5, 0xC7, 0xF3, 0x85,
  24769. 0x1D, 0x25, 0xEC, 0xBB, 0x50, 0x21, 0xCC, 0x38,
  24770. 0xCB, 0x73, 0xEB, 0x6A, 0x34, 0x11, 0xB1, 0xC2,
  24771. 0x90, 0x46, 0xCA, 0x66, 0x54, 0x06, 0x67, 0xD1,
  24772. 0x36, 0x95, 0x44, 0x60, 0xC6, 0xFC, 0xBC, 0x4B,
  24773. 0xC7, 0xC0, 0x49, 0xBB, 0x04, 0x7F, 0xA6, 0x7A,
  24774. 0x63, 0xB3, 0xCC, 0x11, 0x11, 0xC1, 0xD8, 0xAC,
  24775. 0x27, 0xE8, 0x05, 0x8B, 0xCC, 0xA4, 0xA1, 0x54,
  24776. 0x55, 0x85, 0x8A, 0x58, 0x35, 0x8F, 0x7A, 0x61,
  24777. 0x02, 0x0B, 0xC9, 0xC4, 0xC1, 0x7F, 0x8B, 0x95,
  24778. 0xC2, 0x68, 0xCC, 0xB4, 0x04, 0xB9, 0xAA, 0xB4,
  24779. 0xA2, 0x72, 0xA2, 0x1A, 0x70, 0xDA, 0xF6, 0xB6,
  24780. 0xF1, 0x51, 0x21, 0xEE, 0x01, 0xC1, 0x56, 0xA3,
  24781. 0x54, 0xAA, 0x17, 0x08, 0x7E, 0x07, 0x70, 0x2E,
  24782. 0xAB, 0x38, 0xB3, 0x24, 0x1F, 0xDB, 0x55, 0x3F,
  24783. 0x65, 0x73, 0x39, 0xD5, 0xE2, 0x9D, 0xC5, 0xD9,
  24784. 0x1B, 0x7A, 0x5A, 0x82, 0x8E, 0xE9, 0x59, 0xFE,
  24785. 0xBB, 0x90, 0xB0, 0x72, 0x29, 0xF6, 0xE4, 0x9D,
  24786. 0x23, 0xC3, 0xA1, 0x90, 0x29, 0x70, 0x42, 0xFB,
  24787. 0x43, 0x98, 0x69, 0x55, 0xB6, 0x9C, 0x28, 0xE1,
  24788. 0x01, 0x6F, 0x77, 0xA5, 0x8B, 0x43, 0x15, 0x14,
  24789. 0xD2, 0x1B, 0x88, 0x88, 0x99, 0xC3, 0x60, 0x82,
  24790. 0x76, 0x08, 0x1B, 0x75, 0xF5, 0x68, 0x09, 0x7C,
  24791. 0xDC, 0x17, 0x48, 0xF3, 0x23, 0x07, 0x88, 0x58,
  24792. 0x15, 0xF3, 0xAE, 0xC9, 0x65, 0x18, 0x19, 0xAA,
  24793. 0x68, 0x73, 0xD1, 0xA4, 0xEB, 0x83, 0xB1, 0x95,
  24794. 0x38, 0x43, 0xB9, 0x34, 0x22, 0x51, 0x94, 0x83,
  24795. 0xFE, 0xF0, 0x05, 0x9D, 0x36, 0xBB, 0x2D, 0xB1,
  24796. 0xF3, 0xD4, 0x68, 0xFB, 0x06, 0x8C, 0x86, 0xE8,
  24797. 0x97, 0x37, 0x33, 0xC3, 0x98, 0xEA, 0xF0, 0x0E,
  24798. 0x17, 0x02, 0xC6, 0x73, 0x4A, 0xD8, 0xEB, 0x3B,
  24799. 0x62, 0x01, 0x30, 0xD6, 0xC2, 0xB8, 0xC9, 0x04,
  24800. 0xA3, 0xBB, 0x93, 0x07, 0xBE, 0x51, 0x03, 0xF8,
  24801. 0xD8, 0x14, 0x50, 0x5F, 0xB6, 0xA6, 0x0A, 0xF7,
  24802. 0x93, 0x7E, 0xA6, 0xCA, 0xA1, 0x17, 0x31, 0x5E,
  24803. 0x84, 0xCC, 0x91, 0x21, 0xAE, 0x56, 0xFB, 0xF3,
  24804. 0x9E, 0x67, 0xAD, 0xBD, 0x83, 0xAD, 0x2D, 0x3E,
  24805. 0x3B, 0xB8, 0x08, 0x43, 0x64, 0x52, 0x06, 0xBD,
  24806. 0xD9, 0xF2, 0xF6, 0x29, 0xE3, 0xCC, 0x49, 0xB7
  24807. };
  24808. #endif
  24809. #ifndef WOLFSSL_NO_KYBER768
  24810. static const byte seed_768[KYBER_MAKEKEY_RAND_SZ] = {
  24811. /* d */
  24812. 0xE3, 0x4A, 0x70, 0x1C, 0x4C, 0x87, 0x58, 0x2F,
  24813. 0x42, 0x26, 0x4E, 0xE4, 0x22, 0xD3, 0xC6, 0x84,
  24814. 0xD9, 0x76, 0x11, 0xF2, 0x52, 0x3E, 0xFE, 0x0C,
  24815. 0x99, 0x8A, 0xF0, 0x50, 0x56, 0xD6, 0x93, 0xDC,
  24816. /* z */
  24817. 0xA8, 0x57, 0x68, 0xF3, 0x48, 0x6B, 0xD3, 0x2A,
  24818. 0x01, 0xBF, 0x9A, 0x8F, 0x21, 0xEA, 0x93, 0x8E,
  24819. 0x64, 0x8E, 0xAE, 0x4E, 0x54, 0x48, 0xC3, 0x4C,
  24820. 0x3E, 0xB8, 0x88, 0x20, 0xB1, 0x59, 0xEE, 0xDD
  24821. };
  24822. static const byte ek_768[KYBER768_PUBLIC_KEY_SIZE] = {
  24823. 0x6D, 0x14, 0xA0, 0x71, 0xF7, 0xCC, 0x45, 0x25,
  24824. 0x58, 0xD5, 0xE7, 0x1A, 0x7B, 0x08, 0x70, 0x62,
  24825. 0xEC, 0xB1, 0x38, 0x68, 0x44, 0x58, 0x82, 0x46,
  24826. 0x12, 0x64, 0x02, 0xB1, 0xFA, 0x16, 0x37, 0x73,
  24827. 0x3C, 0xD5, 0xF6, 0x0C, 0xC8, 0x4B, 0xCB, 0x64,
  24828. 0x6A, 0x78, 0x92, 0x61, 0x4D, 0x7C, 0x51, 0xB1,
  24829. 0xC7, 0xF1, 0xA2, 0x79, 0x91, 0x32, 0xF1, 0x34,
  24830. 0x27, 0xDC, 0x48, 0x21, 0x58, 0xDA, 0x25, 0x44,
  24831. 0x70, 0xA5, 0x9E, 0x00, 0xA4, 0xE4, 0x96, 0x86,
  24832. 0xFD, 0xC0, 0x77, 0x55, 0x93, 0x67, 0x27, 0x0C,
  24833. 0x21, 0x53, 0xF1, 0x10, 0x07, 0x59, 0x2C, 0x9C,
  24834. 0x43, 0x10, 0xCF, 0x8A, 0x12, 0xC6, 0xA8, 0x71,
  24835. 0x3B, 0xD6, 0xBB, 0x51, 0xF3, 0x12, 0x4F, 0x98,
  24836. 0x9B, 0xA0, 0xD5, 0x40, 0x73, 0xCC, 0x24, 0x2E,
  24837. 0x09, 0x68, 0x78, 0x0B, 0x87, 0x5A, 0x86, 0x9E,
  24838. 0xFB, 0x85, 0x15, 0x86, 0xB9, 0xA8, 0x68, 0xA3,
  24839. 0x84, 0xB9, 0xE6, 0x82, 0x1B, 0x20, 0x1B, 0x93,
  24840. 0x2C, 0x45, 0x53, 0x69, 0xA7, 0x39, 0xEC, 0x22,
  24841. 0x56, 0x9C, 0x97, 0x7C, 0x21, 0x2B, 0x38, 0x18,
  24842. 0x71, 0x81, 0x36, 0x56, 0xAF, 0x5B, 0x56, 0x7E,
  24843. 0xF8, 0x93, 0xB5, 0x84, 0x62, 0x4C, 0x86, 0x3A,
  24844. 0x25, 0x90, 0x00, 0xF1, 0x7B, 0x25, 0x4B, 0x98,
  24845. 0xB1, 0x85, 0x09, 0x7C, 0x50, 0xEB, 0xB6, 0x8B,
  24846. 0x24, 0x43, 0x42, 0xE0, 0x5D, 0x4D, 0xE5, 0x20,
  24847. 0x12, 0x5B, 0x8E, 0x10, 0x33, 0xB1, 0x43, 0x60,
  24848. 0x93, 0xAC, 0xE7, 0xCE, 0x8E, 0x71, 0xB4, 0x58,
  24849. 0xD5, 0x25, 0x67, 0x33, 0x63, 0x04, 0x5A, 0x3B,
  24850. 0x3E, 0xEA, 0x94, 0x55, 0x42, 0x8A, 0x39, 0x87,
  24851. 0x05, 0xA4, 0x23, 0x27, 0xAD, 0xB3, 0x77, 0x4B,
  24852. 0x70, 0x57, 0xF4, 0x2B, 0x01, 0x7E, 0xC0, 0x73,
  24853. 0x9A, 0x98, 0x3F, 0x19, 0xE8, 0x21, 0x4D, 0x09,
  24854. 0x19, 0x5F, 0xA2, 0x4D, 0x2D, 0x57, 0x1D, 0xB7,
  24855. 0x3C, 0x19, 0xA6, 0xF8, 0x46, 0x0E, 0x50, 0x83,
  24856. 0x0D, 0x41, 0x5F, 0x62, 0x7B, 0x88, 0xE9, 0x4A,
  24857. 0x7B, 0x15, 0x37, 0x91, 0xA0, 0xC0, 0xC7, 0xE9,
  24858. 0x48, 0x4C, 0x74, 0xD5, 0x3C, 0x71, 0x48, 0x89,
  24859. 0xF0, 0xE3, 0x21, 0xB6, 0x66, 0x0A, 0x53, 0x2A,
  24860. 0x5B, 0xC0, 0xE5, 0x57, 0xFB, 0xCA, 0x35, 0xE2,
  24861. 0x9B, 0xC6, 0x11, 0x20, 0x0E, 0xD3, 0xC6, 0x33,
  24862. 0x07, 0x7A, 0x4D, 0x87, 0x3C, 0x5C, 0xC6, 0x70,
  24863. 0x06, 0xB7, 0x53, 0xBF, 0x6D, 0x6B, 0x7A, 0xF6,
  24864. 0xCA, 0x40, 0x2A, 0xB6, 0x18, 0x23, 0x6C, 0x0A,
  24865. 0xFF, 0xBC, 0x80, 0x1F, 0x82, 0x22, 0xFB, 0xC3,
  24866. 0x6C, 0xE0, 0x98, 0x4E, 0x2B, 0x18, 0xC9, 0x44,
  24867. 0xBB, 0xCB, 0xEF, 0x03, 0xB1, 0xE1, 0x36, 0x1C,
  24868. 0x1F, 0x44, 0xB0, 0xD7, 0x34, 0xAF, 0xB1, 0x56,
  24869. 0x6C, 0xFF, 0x87, 0x44, 0xDA, 0x8B, 0x99, 0x43,
  24870. 0xD6, 0xB4, 0x5A, 0x3C, 0x09, 0x03, 0x07, 0x02,
  24871. 0xCA, 0x20, 0x1F, 0xFE, 0x20, 0xCB, 0x7E, 0xC5,
  24872. 0xB0, 0xD4, 0x14, 0x9E, 0xE2, 0xC2, 0x8E, 0x8B,
  24873. 0x23, 0x37, 0x4F, 0x47, 0x1B, 0x57, 0x15, 0x0D,
  24874. 0x0E, 0xC9, 0x33, 0x62, 0x61, 0xA2, 0xD5, 0xCB,
  24875. 0x84, 0xA3, 0xAC, 0xAC, 0xC4, 0x28, 0x94, 0x73,
  24876. 0xA4, 0xC0, 0xAB, 0xC6, 0x17, 0xC9, 0xAB, 0xC1,
  24877. 0x78, 0x73, 0x44, 0x34, 0xC8, 0x2E, 0x16, 0x85,
  24878. 0x58, 0x8A, 0x5C, 0x2E, 0xA2, 0x67, 0x8F, 0x6B,
  24879. 0x3C, 0x22, 0x28, 0x73, 0x31, 0x30, 0xC4, 0x66,
  24880. 0xE5, 0xB8, 0x6E, 0xF4, 0x91, 0x15, 0x3E, 0x48,
  24881. 0x66, 0x22, 0x47, 0xB8, 0x75, 0xD2, 0x01, 0x02,
  24882. 0x0B, 0x56, 0x6B, 0x81, 0xB6, 0x4D, 0x83, 0x9A,
  24883. 0xB4, 0x63, 0x3B, 0xAA, 0x8A, 0xCE, 0x20, 0x2B,
  24884. 0xAA, 0xB4, 0x49, 0x62, 0x97, 0xF9, 0x80, 0x7A,
  24885. 0xDB, 0xBB, 0x1E, 0x33, 0x2C, 0x6F, 0x80, 0x22,
  24886. 0xB2, 0xA1, 0x8C, 0xFD, 0xD4, 0xA8, 0x25, 0x30,
  24887. 0xB6, 0xD3, 0xF0, 0x07, 0xC3, 0x35, 0x38, 0x98,
  24888. 0xD9, 0x66, 0xCC, 0x2C, 0x21, 0xCB, 0x42, 0x44,
  24889. 0xBD, 0x00, 0x44, 0x3F, 0x20, 0x98, 0x70, 0xAC,
  24890. 0xC4, 0x2B, 0xC3, 0x30, 0x68, 0xC7, 0x24, 0xEC,
  24891. 0x17, 0x22, 0x36, 0x19, 0xC1, 0x09, 0x3C, 0xCA,
  24892. 0x6A, 0xEB, 0x29, 0x50, 0x06, 0x64, 0xD1, 0x22,
  24893. 0x50, 0x36, 0xB4, 0xB8, 0x10, 0x91, 0x90, 0x69,
  24894. 0x69, 0x48, 0x1F, 0x1C, 0x72, 0x3C, 0x14, 0x0B,
  24895. 0x9D, 0x6C, 0x16, 0x8F, 0x5B, 0x64, 0xBE, 0xA6,
  24896. 0x9C, 0x5F, 0xD6, 0x38, 0x5D, 0xF7, 0x36, 0x4B,
  24897. 0x87, 0x23, 0xBC, 0xC8, 0x5E, 0x03, 0x8C, 0x7E,
  24898. 0x46, 0x4A, 0x90, 0x0D, 0x68, 0xA2, 0x12, 0x78,
  24899. 0x18, 0x99, 0x42, 0x17, 0xAE, 0xC8, 0xBD, 0xB3,
  24900. 0x9A, 0x97, 0x0A, 0x99, 0x63, 0xDE, 0x93, 0x68,
  24901. 0x8E, 0x2A, 0xC8, 0x2A, 0xBC, 0xC2, 0x2F, 0xB9,
  24902. 0x27, 0x7B, 0xA2, 0x20, 0x09, 0xE8, 0x78, 0x38,
  24903. 0x1A, 0x38, 0x16, 0x39, 0x01, 0xC7, 0xD4, 0xC8,
  24904. 0x50, 0x19, 0x53, 0x8D, 0x35, 0xCA, 0xAE, 0x9C,
  24905. 0x41, 0xAF, 0x8C, 0x92, 0x9E, 0xE2, 0x0B, 0xB0,
  24906. 0x8C, 0xA6, 0x19, 0xE7, 0x2C, 0x2F, 0x22, 0x62,
  24907. 0xC1, 0xC9, 0x93, 0x85, 0x72, 0x55, 0x1A, 0xC0,
  24908. 0x2D, 0xC9, 0x26, 0x8F, 0xBC, 0xC3, 0x5D, 0x79,
  24909. 0x01, 0x1C, 0x3C, 0x09, 0x0A, 0xD4, 0x0A, 0x4F,
  24910. 0x11, 0x1C, 0x9B, 0xE5, 0x5C, 0x42, 0x7E, 0xB7,
  24911. 0x96, 0xC1, 0x93, 0x2D, 0x86, 0x73, 0x57, 0x9A,
  24912. 0xF1, 0xB4, 0xC6, 0x38, 0xB0, 0x94, 0x44, 0x89,
  24913. 0x01, 0x2A, 0x25, 0x59, 0xA3, 0xB0, 0x24, 0x81,
  24914. 0xB0, 0x1A, 0xC3, 0x0B, 0xA8, 0x96, 0x0F, 0x80,
  24915. 0xC0, 0xC2, 0xB3, 0x94, 0x7D, 0x36, 0xA1, 0x2C,
  24916. 0x08, 0x04, 0x98, 0xBE, 0xE4, 0x48, 0x71, 0x6C,
  24917. 0x97, 0x34, 0x16, 0xC8, 0x24, 0x28, 0x04, 0xA3,
  24918. 0xDA, 0x09, 0x9E, 0xE1, 0x37, 0xB0, 0xBA, 0x90,
  24919. 0xFE, 0x4A, 0x5C, 0x6A, 0x89, 0x20, 0x02, 0x76,
  24920. 0xA0, 0xCF, 0xB6, 0x43, 0xEC, 0x2C, 0x56, 0xA2,
  24921. 0xD7, 0x08, 0xD7, 0xB4, 0x37, 0x3E, 0x44, 0xC1,
  24922. 0x50, 0x2A, 0x76, 0x3A, 0x60, 0x05, 0x86, 0xE6,
  24923. 0xCD, 0xA6, 0x27, 0x38, 0x97, 0xD4, 0x44, 0x48,
  24924. 0x28, 0x7D, 0xC2, 0xE6, 0x02, 0xDC, 0x39, 0x20,
  24925. 0x0B, 0xF6, 0x16, 0x62, 0x36, 0x55, 0x9F, 0xD1,
  24926. 0x2A, 0x60, 0x89, 0x2A, 0xEB, 0x15, 0x3D, 0xD6,
  24927. 0x51, 0xBB, 0x46, 0x99, 0x10, 0xB4, 0xB3, 0x46,
  24928. 0x69, 0xF9, 0x1D, 0xA8, 0x65, 0x4D, 0x1E, 0xB7,
  24929. 0x2E, 0xB6, 0xE0, 0x28, 0x00, 0xB3, 0xB0, 0xA7,
  24930. 0xD0, 0xA4, 0x8C, 0x83, 0x68, 0x54, 0xD3, 0xA8,
  24931. 0x3E, 0x65, 0x56, 0x9C, 0xB7, 0x23, 0x0B, 0xB4,
  24932. 0x4F, 0x3F, 0x14, 0x3A, 0x6D, 0xEC, 0x5F, 0x2C,
  24933. 0x39, 0xAB, 0x90, 0xF2, 0x74, 0xF2, 0x08, 0x8B,
  24934. 0xD3, 0xD6, 0xA6, 0xFC, 0xA0, 0x07, 0x02, 0x73,
  24935. 0xBE, 0xDC, 0x84, 0x77, 0x7F, 0xB5, 0x2E, 0x3C,
  24936. 0x55, 0x8B, 0x0A, 0xE0, 0x61, 0x83, 0xD5, 0xA4,
  24937. 0x8D, 0x45, 0x2F, 0x68, 0xE1, 0x52, 0x07, 0xF8,
  24938. 0x61, 0x62, 0x7A, 0xCA, 0x14, 0x27, 0x96, 0x30,
  24939. 0xF8, 0x2E, 0xC3, 0xA0, 0xCA, 0x07, 0x86, 0x33,
  24940. 0xB6, 0x00, 0xAF, 0xA7, 0x97, 0x43, 0xA6, 0x00,
  24941. 0x21, 0x5B, 0xE5, 0x63, 0x74, 0x58, 0xCE, 0x2C,
  24942. 0xE8, 0xAF, 0xF5, 0xA0, 0x8E, 0xB5, 0x01, 0x7B,
  24943. 0x2C, 0x76, 0x65, 0x77, 0x47, 0x9F, 0x8D, 0xC6,
  24944. 0xBF, 0x9F, 0x5C, 0xC7, 0x50, 0x89, 0x93, 0x21,
  24945. 0x61, 0xB9, 0x6C, 0xEA, 0x40, 0x66, 0x20, 0xAE,
  24946. 0xDB, 0x63, 0x04, 0x07, 0xF7, 0x68, 0x7E, 0xBB,
  24947. 0xB4, 0x81, 0x4C, 0x79, 0x81, 0x63, 0x7A, 0x48,
  24948. 0xA9, 0x0D, 0xE6, 0x80, 0x31, 0xE0, 0x62, 0xA7,
  24949. 0xAF, 0x76, 0x12, 0xB4, 0xF5, 0xC7, 0xA6, 0xDA,
  24950. 0x86, 0xBD, 0x13, 0x65, 0x29, 0xE6, 0x42, 0x95,
  24951. 0xA5, 0x61, 0x3E, 0xA7, 0x3B, 0xD3, 0xD4, 0x44,
  24952. 0x8C, 0xB8, 0x1F, 0x24, 0x31, 0x35, 0xC0, 0xA6,
  24953. 0x60, 0xBE, 0xB9, 0xC1, 0x7E, 0x65, 0x1D, 0xEF,
  24954. 0x46, 0x9A, 0x7D, 0x90, 0xA1, 0x5D, 0x34, 0x81,
  24955. 0x09, 0x0B, 0xCB, 0xF2, 0x27, 0x01, 0x23, 0x28,
  24956. 0x94, 0x1F, 0xA4, 0x6F, 0x39, 0xC5, 0x00, 0x6A,
  24957. 0xD9, 0x3D, 0x45, 0x8A, 0xA6, 0xAD, 0xD6, 0x55,
  24958. 0x86, 0x2B, 0x41, 0x8C, 0x30, 0x94, 0xF5, 0x51,
  24959. 0x46, 0x0D, 0xF2, 0x15, 0x3A, 0x58, 0x10, 0xA7,
  24960. 0xDA, 0x74, 0xF0, 0x61, 0x4C, 0x25, 0x88, 0xBE,
  24961. 0x49, 0xDC, 0x6F, 0x5E, 0x88, 0x15, 0x46, 0x42,
  24962. 0xBD, 0x1D, 0x37, 0x62, 0x56, 0x33, 0x26, 0x43,
  24963. 0x35, 0x07, 0x15, 0x6A, 0x57, 0xC5, 0x76, 0x94,
  24964. 0xBD, 0xD2, 0x6E, 0x7A, 0x24, 0x6F, 0xEB, 0x72,
  24965. 0x3A, 0xED, 0x67, 0xB0, 0x48, 0x87, 0xC8, 0xE4,
  24966. 0x76, 0xB4, 0x8C, 0xAB, 0x59, 0xE5, 0x36, 0x2F,
  24967. 0x26, 0xA9, 0xEF, 0x50, 0xC2, 0xBC, 0x80, 0xBA,
  24968. 0x14, 0x62, 0x26, 0x21, 0x6F, 0xE6, 0x29, 0x68,
  24969. 0xA6, 0x0D, 0x04, 0xE8, 0xC1, 0x70, 0xD7, 0x41,
  24970. 0xC7, 0xA2, 0xB0, 0xE1, 0xAB, 0xDA, 0xC9, 0x68
  24971. };
  24972. static const byte dk_768[KYBER768_PRIVATE_KEY_SIZE] = {
  24973. 0x98, 0xA1, 0xB2, 0xDA, 0x4A, 0x65, 0xCF, 0xB5,
  24974. 0x84, 0x5E, 0xA7, 0x31, 0x1E, 0x6A, 0x06, 0xDB,
  24975. 0x73, 0x1F, 0x15, 0x90, 0xC4, 0x1E, 0xE7, 0x4B,
  24976. 0xA1, 0x07, 0x82, 0x71, 0x5B, 0x35, 0xA3, 0x10,
  24977. 0x2D, 0xF6, 0x37, 0x87, 0x2B, 0xE6, 0x5B, 0xAB,
  24978. 0x37, 0xA1, 0xDE, 0x25, 0x11, 0xD7, 0x03, 0xC7,
  24979. 0x02, 0x47, 0xB3, 0x5E, 0xF2, 0x74, 0x35, 0x48,
  24980. 0x50, 0x24, 0xD9, 0x3F, 0xD9, 0xE7, 0x7C, 0x43,
  24981. 0x80, 0x4F, 0x37, 0x17, 0x49, 0xBA, 0x00, 0xB2,
  24982. 0x0A, 0x8C, 0x5C, 0x58, 0x8B, 0xC9, 0xAB, 0xE0,
  24983. 0x68, 0xAE, 0xAA, 0xA9, 0x38, 0x51, 0x7E, 0xBF,
  24984. 0xE5, 0x3B, 0x6B, 0x66, 0x32, 0x82, 0x90, 0x3D,
  24985. 0xCD, 0x18, 0x97, 0x36, 0xD7, 0x29, 0x68, 0x16,
  24986. 0xC7, 0x33, 0xA1, 0xC7, 0x7C, 0x63, 0x75, 0xE5,
  24987. 0x39, 0x7C, 0x0F, 0x18, 0x9B, 0xBF, 0xE4, 0x76,
  24988. 0x43, 0xA6, 0x1F, 0x58, 0xF8, 0xA3, 0xC6, 0x91,
  24989. 0x1B, 0xE4, 0x61, 0x1A, 0x8C, 0x7B, 0xC0, 0x50,
  24990. 0x02, 0x11, 0x63, 0xD0, 0xA4, 0x04, 0xDC, 0x14,
  24991. 0x06, 0x57, 0x48, 0xFF, 0x29, 0xBE, 0x60, 0xD2,
  24992. 0xB9, 0xFD, 0xCC, 0x8F, 0xFD, 0x98, 0xC5, 0x87,
  24993. 0xF3, 0x8C, 0x67, 0x11, 0x57, 0x86, 0x46, 0x4B,
  24994. 0xDB, 0x34, 0x2B, 0x17, 0xE8, 0x97, 0xD6, 0x46,
  24995. 0x17, 0xCB, 0xFB, 0x11, 0x79, 0x73, 0xA5, 0x45,
  24996. 0x89, 0x77, 0xA7, 0xD7, 0x61, 0x7A, 0x1B, 0x4D,
  24997. 0x83, 0xBA, 0x03, 0xC6, 0x11, 0x13, 0x8A, 0x46,
  24998. 0x73, 0xB1, 0xEB, 0x34, 0xB0, 0x78, 0x03, 0x3F,
  24999. 0x97, 0xCF, 0xFE, 0x80, 0xC1, 0x46, 0xA2, 0x69,
  25000. 0x43, 0xF8, 0x42, 0xB9, 0x76, 0x32, 0x7B, 0xF1,
  25001. 0xCB, 0xC6, 0x01, 0x19, 0x52, 0x5B, 0xB9, 0xA3,
  25002. 0xC0, 0x34, 0x93, 0x34, 0x90, 0x00, 0xDD, 0x8F,
  25003. 0x51, 0xBA, 0x21, 0xA2, 0xE9, 0x23, 0x61, 0x76,
  25004. 0x23, 0x24, 0x60, 0x0E, 0x0C, 0x13, 0xAA, 0xA6,
  25005. 0xCB, 0x69, 0xBF, 0xB2, 0x42, 0x76, 0x48, 0x3F,
  25006. 0x6B, 0x02, 0x42, 0x12, 0x59, 0xB7, 0x58, 0x52,
  25007. 0x63, 0xC1, 0xA0, 0x28, 0xD6, 0x82, 0xC5, 0x08,
  25008. 0xBB, 0xC2, 0x80, 0x1A, 0x56, 0xE9, 0x8B, 0x8F,
  25009. 0x62, 0x0B, 0x04, 0x83, 0xD7, 0x9B, 0x5A, 0xD8,
  25010. 0x58, 0x5A, 0xC0, 0xA4, 0x75, 0xBA, 0xC7, 0x78,
  25011. 0x65, 0x19, 0x41, 0x96, 0x33, 0x87, 0x91, 0xB7,
  25012. 0x98, 0x5A, 0x05, 0xD1, 0x09, 0x39, 0x5C, 0xCA,
  25013. 0x89, 0x32, 0x72, 0x2A, 0x91, 0x95, 0x0D, 0x37,
  25014. 0xE1, 0x2B, 0x89, 0x14, 0x20, 0xA5, 0x2B, 0x62,
  25015. 0xCB, 0xFA, 0x81, 0x5D, 0xF6, 0x17, 0x4C, 0xE0,
  25016. 0x0E, 0x68, 0xBC, 0xA7, 0x5D, 0x48, 0x38, 0xCA,
  25017. 0x28, 0x0F, 0x71, 0x3C, 0x7E, 0x69, 0x24, 0xAF,
  25018. 0xD9, 0x5B, 0xAA, 0x0D, 0x01, 0xAD, 0xA6, 0x37,
  25019. 0xB1, 0x58, 0x34, 0x70, 0x34, 0xC0, 0xAB, 0x1A,
  25020. 0x71, 0x83, 0x33, 0x1A, 0x82, 0x0A, 0xCB, 0xCB,
  25021. 0x83, 0x19, 0x3A, 0x1A, 0x94, 0xC8, 0xF7, 0xE3,
  25022. 0x84, 0xAE, 0xD0, 0xC3, 0x5E, 0xD3, 0xCB, 0x33,
  25023. 0x97, 0xBB, 0x63, 0x80, 0x86, 0xE7, 0xA3, 0x5A,
  25024. 0x64, 0x08, 0xA3, 0xA4, 0xB9, 0x0C, 0xE9, 0x53,
  25025. 0x70, 0x7C, 0x19, 0xBC, 0x46, 0xC3, 0xB2, 0xDA,
  25026. 0x3B, 0x2E, 0xE3, 0x23, 0x19, 0xC5, 0x6B, 0x92,
  25027. 0x80, 0x32, 0xB5, 0xED, 0x12, 0x56, 0xD0, 0x75,
  25028. 0x3D, 0x34, 0x14, 0x23, 0xE9, 0xDB, 0x13, 0x9D,
  25029. 0xE7, 0x71, 0x4F, 0xF0, 0x75, 0xCA, 0xF5, 0x8F,
  25030. 0xD9, 0xF5, 0x7D, 0x1A, 0x54, 0x01, 0x9B, 0x59,
  25031. 0x26, 0x40, 0x68, 0x30, 0xDA, 0xE2, 0x9A, 0x87,
  25032. 0x53, 0x02, 0xA8, 0x12, 0x56, 0xF4, 0xD6, 0xCF,
  25033. 0x5E, 0x74, 0x03, 0x4E, 0xA6, 0x14, 0xBF, 0x70,
  25034. 0xC2, 0x76, 0x4B, 0x20, 0xC9, 0x58, 0x9C, 0xDB,
  25035. 0x5C, 0x25, 0x76, 0x1A, 0x04, 0xE5, 0x82, 0x92,
  25036. 0x90, 0x7C, 0x57, 0x8A, 0x94, 0xA3, 0x58, 0x36,
  25037. 0xBE, 0xE3, 0x11, 0x2D, 0xC2, 0xC3, 0xAE, 0x21,
  25038. 0x92, 0xC9, 0xDE, 0xAA, 0x30, 0x4B, 0x29, 0xC7,
  25039. 0xFE, 0xA1, 0xBD, 0xF4, 0x7B, 0x3B, 0x6B, 0xCB,
  25040. 0xA2, 0xC0, 0xE5, 0x5C, 0x9C, 0xDB, 0x6D, 0xE7,
  25041. 0x14, 0x9E, 0x9C, 0xB1, 0x79, 0x17, 0x71, 0x8F,
  25042. 0x12, 0xC8, 0x03, 0x2D, 0xE1, 0xAD, 0xE0, 0x64,
  25043. 0x8D, 0x40, 0x55, 0x19, 0xC7, 0x07, 0x19, 0xBE,
  25044. 0xCC, 0x70, 0x18, 0x45, 0xCF, 0x9F, 0x4B, 0x91,
  25045. 0x2F, 0xE7, 0x19, 0x83, 0xCA, 0x34, 0xF9, 0x01,
  25046. 0x8C, 0x7C, 0xA7, 0xBB, 0x2F, 0x6C, 0x5D, 0x7F,
  25047. 0x8C, 0x5B, 0x29, 0x73, 0x59, 0xEC, 0x75, 0x20,
  25048. 0x9C, 0x25, 0x43, 0xFF, 0x11, 0xC4, 0x24, 0x49,
  25049. 0x77, 0xC5, 0x96, 0x95, 0x24, 0xEC, 0x45, 0x4D,
  25050. 0x44, 0xC3, 0x23, 0xFC, 0xCA, 0x94, 0xAC, 0xAC,
  25051. 0x27, 0x3A, 0x0E, 0xC4, 0x9B, 0x4A, 0x8A, 0x58,
  25052. 0x5B, 0xCE, 0x7A, 0x5B, 0x30, 0x5C, 0x04, 0xC3,
  25053. 0x50, 0x64, 0x22, 0x58, 0x03, 0x57, 0x01, 0x6A,
  25054. 0x85, 0x0C, 0x3F, 0x7E, 0xE1, 0x72, 0x05, 0xA7,
  25055. 0x7B, 0x29, 0x1C, 0x77, 0x31, 0xC9, 0x83, 0x6C,
  25056. 0x02, 0xAE, 0xE5, 0x40, 0x6F, 0x63, 0xC6, 0xA0,
  25057. 0x7A, 0x21, 0x43, 0x82, 0xAA, 0x15, 0x33, 0x6C,
  25058. 0x05, 0xD1, 0x04, 0x55, 0x88, 0x10, 0x76, 0x45,
  25059. 0xEA, 0x7D, 0xE6, 0x87, 0x0F, 0xC0, 0xE5, 0x5E,
  25060. 0x15, 0x40, 0x97, 0x43, 0x01, 0xC4, 0x2E, 0xC1,
  25061. 0x41, 0x05, 0x51, 0x86, 0x80, 0xF6, 0x88, 0xAB,
  25062. 0xE4, 0xCE, 0x45, 0x37, 0x38, 0xFE, 0x47, 0x1B,
  25063. 0x87, 0xFC, 0x31, 0xF5, 0xC6, 0x8A, 0x39, 0xE6,
  25064. 0x8A, 0xF5, 0x1B, 0x02, 0x40, 0xB9, 0x0E, 0x03,
  25065. 0x64, 0xB0, 0x4B, 0xAC, 0x43, 0xD6, 0xFB, 0x68,
  25066. 0xAB, 0x65, 0xAE, 0x02, 0x8B, 0x62, 0xBD, 0x68,
  25067. 0x3B, 0x7D, 0x28, 0xAD, 0x38, 0x80, 0x6B, 0xEE,
  25068. 0x72, 0x5B, 0x5B, 0x24, 0x16, 0xA8, 0xD7, 0x9C,
  25069. 0x16, 0xEC, 0x2A, 0x99, 0xEA, 0x4A, 0x8D, 0x92,
  25070. 0xA2, 0xF5, 0x05, 0x2E, 0x67, 0xF9, 0x73, 0x52,
  25071. 0x28, 0x97, 0x61, 0xC5, 0xC3, 0x9F, 0xC5, 0xC7,
  25072. 0x42, 0xE9, 0xC0, 0xA7, 0x40, 0xCA, 0x59, 0xFC,
  25073. 0x01, 0x82, 0xF7, 0x09, 0xD0, 0x1B, 0x51, 0x87,
  25074. 0xF0, 0x00, 0x63, 0xDA, 0xAB, 0x39, 0x75, 0x96,
  25075. 0xEE, 0xA4, 0xA3, 0x1B, 0xDB, 0xCB, 0xD4, 0xC1,
  25076. 0xBB, 0x0C, 0x55, 0xBE, 0x7C, 0x68, 0x50, 0xFD,
  25077. 0xA9, 0x32, 0x6B, 0x35, 0x3E, 0x28, 0x8C, 0x50,
  25078. 0x13, 0x22, 0x6C, 0x3C, 0x39, 0x23, 0xA7, 0x91,
  25079. 0x60, 0x9E, 0x80, 0x02, 0xE7, 0x3A, 0x5F, 0x7B,
  25080. 0x6B, 0xB4, 0xA8, 0x77, 0xB1, 0xFD, 0xF5, 0x3B,
  25081. 0xB2, 0xBA, 0xB3, 0xDD, 0x42, 0x4D, 0x31, 0xBB,
  25082. 0xB4, 0x48, 0xE6, 0x09, 0xA6, 0x6B, 0x0E, 0x34,
  25083. 0x3C, 0x28, 0x6E, 0x87, 0x60, 0x31, 0x2B, 0x6D,
  25084. 0x37, 0xAA, 0x52, 0x01, 0xD2, 0x1F, 0x53, 0x50,
  25085. 0x3D, 0x88, 0x38, 0x9A, 0xDC, 0xA2, 0x1C, 0x70,
  25086. 0xFB, 0x6C, 0x0F, 0xC9, 0xC6, 0x9D, 0x66, 0x16,
  25087. 0xC9, 0xEA, 0x37, 0x80, 0xE3, 0x55, 0x65, 0xC0,
  25088. 0xC9, 0x7C, 0x15, 0x17, 0x9C, 0x95, 0x34, 0x3E,
  25089. 0xCC, 0x5E, 0x1C, 0x2A, 0x24, 0xDE, 0x46, 0x99,
  25090. 0xF6, 0x87, 0x5E, 0xA2, 0xFA, 0x2D, 0xD3, 0xE3,
  25091. 0x57, 0xBC, 0x43, 0x91, 0x47, 0x95, 0x20, 0x7E,
  25092. 0x02, 0x6B, 0x85, 0x0A, 0x22, 0x37, 0x95, 0x0C,
  25093. 0x10, 0x8A, 0x51, 0x2F, 0xC8, 0x8C, 0x22, 0x48,
  25094. 0x81, 0x12, 0x60, 0x70, 0x88, 0x18, 0x5F, 0xB0,
  25095. 0xE0, 0x9C, 0x2C, 0x41, 0x97, 0xA8, 0x36, 0x87,
  25096. 0x26, 0x6B, 0xAB, 0x2E, 0x58, 0x3E, 0x21, 0xC4,
  25097. 0x0F, 0x4C, 0xC0, 0x08, 0xFE, 0x65, 0x28, 0x04,
  25098. 0xD8, 0x22, 0x3F, 0x15, 0x20, 0xA9, 0x0B, 0x0D,
  25099. 0x53, 0x85, 0xC7, 0x55, 0x3C, 0xC7, 0x67, 0xC5,
  25100. 0x8D, 0x12, 0x0C, 0xCD, 0x3E, 0xF5, 0xB5, 0xD1,
  25101. 0xA6, 0xCD, 0x7B, 0xC0, 0x0D, 0xFF, 0x13, 0x21,
  25102. 0xB2, 0xF2, 0xC4, 0x32, 0xB6, 0x4E, 0xFB, 0x8A,
  25103. 0x3F, 0x5D, 0x00, 0x64, 0xB3, 0xF3, 0x42, 0x93,
  25104. 0x02, 0x6C, 0x85, 0x1C, 0x2D, 0xED, 0x68, 0xB9,
  25105. 0xDF, 0xF4, 0xA2, 0x8F, 0x6A, 0x8D, 0x22, 0x55,
  25106. 0x35, 0xE0, 0x47, 0x70, 0x84, 0x43, 0x0C, 0xFF,
  25107. 0xDA, 0x0A, 0xC0, 0x55, 0x2F, 0x9A, 0x21, 0x27,
  25108. 0x85, 0xB7, 0x49, 0x91, 0x3A, 0x06, 0xFA, 0x22,
  25109. 0x74, 0xC0, 0xD1, 0x5B, 0xAD, 0x32, 0x54, 0x58,
  25110. 0xD3, 0x23, 0xEF, 0x6B, 0xAE, 0x13, 0xC0, 0x01,
  25111. 0x0D, 0x52, 0x5C, 0x1D, 0x52, 0x69, 0x97, 0x3A,
  25112. 0xC2, 0x9B, 0xDA, 0x7C, 0x98, 0x37, 0x46, 0x91,
  25113. 0x8B, 0xA0, 0xE0, 0x02, 0x58, 0x8E, 0x30, 0x37,
  25114. 0x5D, 0x78, 0x32, 0x9E, 0x6B, 0x8B, 0xA8, 0xC4,
  25115. 0x46, 0x2A, 0x69, 0x2F, 0xB6, 0x08, 0x38, 0x42,
  25116. 0xB8, 0xC8, 0xC9, 0x2C, 0x60, 0xF2, 0x52, 0x72,
  25117. 0x6D, 0x14, 0xA0, 0x71, 0xF7, 0xCC, 0x45, 0x25,
  25118. 0x58, 0xD5, 0xE7, 0x1A, 0x7B, 0x08, 0x70, 0x62,
  25119. 0xEC, 0xB1, 0x38, 0x68, 0x44, 0x58, 0x82, 0x46,
  25120. 0x12, 0x64, 0x02, 0xB1, 0xFA, 0x16, 0x37, 0x73,
  25121. 0x3C, 0xD5, 0xF6, 0x0C, 0xC8, 0x4B, 0xCB, 0x64,
  25122. 0x6A, 0x78, 0x92, 0x61, 0x4D, 0x7C, 0x51, 0xB1,
  25123. 0xC7, 0xF1, 0xA2, 0x79, 0x91, 0x32, 0xF1, 0x34,
  25124. 0x27, 0xDC, 0x48, 0x21, 0x58, 0xDA, 0x25, 0x44,
  25125. 0x70, 0xA5, 0x9E, 0x00, 0xA4, 0xE4, 0x96, 0x86,
  25126. 0xFD, 0xC0, 0x77, 0x55, 0x93, 0x67, 0x27, 0x0C,
  25127. 0x21, 0x53, 0xF1, 0x10, 0x07, 0x59, 0x2C, 0x9C,
  25128. 0x43, 0x10, 0xCF, 0x8A, 0x12, 0xC6, 0xA8, 0x71,
  25129. 0x3B, 0xD6, 0xBB, 0x51, 0xF3, 0x12, 0x4F, 0x98,
  25130. 0x9B, 0xA0, 0xD5, 0x40, 0x73, 0xCC, 0x24, 0x2E,
  25131. 0x09, 0x68, 0x78, 0x0B, 0x87, 0x5A, 0x86, 0x9E,
  25132. 0xFB, 0x85, 0x15, 0x86, 0xB9, 0xA8, 0x68, 0xA3,
  25133. 0x84, 0xB9, 0xE6, 0x82, 0x1B, 0x20, 0x1B, 0x93,
  25134. 0x2C, 0x45, 0x53, 0x69, 0xA7, 0x39, 0xEC, 0x22,
  25135. 0x56, 0x9C, 0x97, 0x7C, 0x21, 0x2B, 0x38, 0x18,
  25136. 0x71, 0x81, 0x36, 0x56, 0xAF, 0x5B, 0x56, 0x7E,
  25137. 0xF8, 0x93, 0xB5, 0x84, 0x62, 0x4C, 0x86, 0x3A,
  25138. 0x25, 0x90, 0x00, 0xF1, 0x7B, 0x25, 0x4B, 0x98,
  25139. 0xB1, 0x85, 0x09, 0x7C, 0x50, 0xEB, 0xB6, 0x8B,
  25140. 0x24, 0x43, 0x42, 0xE0, 0x5D, 0x4D, 0xE5, 0x20,
  25141. 0x12, 0x5B, 0x8E, 0x10, 0x33, 0xB1, 0x43, 0x60,
  25142. 0x93, 0xAC, 0xE7, 0xCE, 0x8E, 0x71, 0xB4, 0x58,
  25143. 0xD5, 0x25, 0x67, 0x33, 0x63, 0x04, 0x5A, 0x3B,
  25144. 0x3E, 0xEA, 0x94, 0x55, 0x42, 0x8A, 0x39, 0x87,
  25145. 0x05, 0xA4, 0x23, 0x27, 0xAD, 0xB3, 0x77, 0x4B,
  25146. 0x70, 0x57, 0xF4, 0x2B, 0x01, 0x7E, 0xC0, 0x73,
  25147. 0x9A, 0x98, 0x3F, 0x19, 0xE8, 0x21, 0x4D, 0x09,
  25148. 0x19, 0x5F, 0xA2, 0x4D, 0x2D, 0x57, 0x1D, 0xB7,
  25149. 0x3C, 0x19, 0xA6, 0xF8, 0x46, 0x0E, 0x50, 0x83,
  25150. 0x0D, 0x41, 0x5F, 0x62, 0x7B, 0x88, 0xE9, 0x4A,
  25151. 0x7B, 0x15, 0x37, 0x91, 0xA0, 0xC0, 0xC7, 0xE9,
  25152. 0x48, 0x4C, 0x74, 0xD5, 0x3C, 0x71, 0x48, 0x89,
  25153. 0xF0, 0xE3, 0x21, 0xB6, 0x66, 0x0A, 0x53, 0x2A,
  25154. 0x5B, 0xC0, 0xE5, 0x57, 0xFB, 0xCA, 0x35, 0xE2,
  25155. 0x9B, 0xC6, 0x11, 0x20, 0x0E, 0xD3, 0xC6, 0x33,
  25156. 0x07, 0x7A, 0x4D, 0x87, 0x3C, 0x5C, 0xC6, 0x70,
  25157. 0x06, 0xB7, 0x53, 0xBF, 0x6D, 0x6B, 0x7A, 0xF6,
  25158. 0xCA, 0x40, 0x2A, 0xB6, 0x18, 0x23, 0x6C, 0x0A,
  25159. 0xFF, 0xBC, 0x80, 0x1F, 0x82, 0x22, 0xFB, 0xC3,
  25160. 0x6C, 0xE0, 0x98, 0x4E, 0x2B, 0x18, 0xC9, 0x44,
  25161. 0xBB, 0xCB, 0xEF, 0x03, 0xB1, 0xE1, 0x36, 0x1C,
  25162. 0x1F, 0x44, 0xB0, 0xD7, 0x34, 0xAF, 0xB1, 0x56,
  25163. 0x6C, 0xFF, 0x87, 0x44, 0xDA, 0x8B, 0x99, 0x43,
  25164. 0xD6, 0xB4, 0x5A, 0x3C, 0x09, 0x03, 0x07, 0x02,
  25165. 0xCA, 0x20, 0x1F, 0xFE, 0x20, 0xCB, 0x7E, 0xC5,
  25166. 0xB0, 0xD4, 0x14, 0x9E, 0xE2, 0xC2, 0x8E, 0x8B,
  25167. 0x23, 0x37, 0x4F, 0x47, 0x1B, 0x57, 0x15, 0x0D,
  25168. 0x0E, 0xC9, 0x33, 0x62, 0x61, 0xA2, 0xD5, 0xCB,
  25169. 0x84, 0xA3, 0xAC, 0xAC, 0xC4, 0x28, 0x94, 0x73,
  25170. 0xA4, 0xC0, 0xAB, 0xC6, 0x17, 0xC9, 0xAB, 0xC1,
  25171. 0x78, 0x73, 0x44, 0x34, 0xC8, 0x2E, 0x16, 0x85,
  25172. 0x58, 0x8A, 0x5C, 0x2E, 0xA2, 0x67, 0x8F, 0x6B,
  25173. 0x3C, 0x22, 0x28, 0x73, 0x31, 0x30, 0xC4, 0x66,
  25174. 0xE5, 0xB8, 0x6E, 0xF4, 0x91, 0x15, 0x3E, 0x48,
  25175. 0x66, 0x22, 0x47, 0xB8, 0x75, 0xD2, 0x01, 0x02,
  25176. 0x0B, 0x56, 0x6B, 0x81, 0xB6, 0x4D, 0x83, 0x9A,
  25177. 0xB4, 0x63, 0x3B, 0xAA, 0x8A, 0xCE, 0x20, 0x2B,
  25178. 0xAA, 0xB4, 0x49, 0x62, 0x97, 0xF9, 0x80, 0x7A,
  25179. 0xDB, 0xBB, 0x1E, 0x33, 0x2C, 0x6F, 0x80, 0x22,
  25180. 0xB2, 0xA1, 0x8C, 0xFD, 0xD4, 0xA8, 0x25, 0x30,
  25181. 0xB6, 0xD3, 0xF0, 0x07, 0xC3, 0x35, 0x38, 0x98,
  25182. 0xD9, 0x66, 0xCC, 0x2C, 0x21, 0xCB, 0x42, 0x44,
  25183. 0xBD, 0x00, 0x44, 0x3F, 0x20, 0x98, 0x70, 0xAC,
  25184. 0xC4, 0x2B, 0xC3, 0x30, 0x68, 0xC7, 0x24, 0xEC,
  25185. 0x17, 0x22, 0x36, 0x19, 0xC1, 0x09, 0x3C, 0xCA,
  25186. 0x6A, 0xEB, 0x29, 0x50, 0x06, 0x64, 0xD1, 0x22,
  25187. 0x50, 0x36, 0xB4, 0xB8, 0x10, 0x91, 0x90, 0x69,
  25188. 0x69, 0x48, 0x1F, 0x1C, 0x72, 0x3C, 0x14, 0x0B,
  25189. 0x9D, 0x6C, 0x16, 0x8F, 0x5B, 0x64, 0xBE, 0xA6,
  25190. 0x9C, 0x5F, 0xD6, 0x38, 0x5D, 0xF7, 0x36, 0x4B,
  25191. 0x87, 0x23, 0xBC, 0xC8, 0x5E, 0x03, 0x8C, 0x7E,
  25192. 0x46, 0x4A, 0x90, 0x0D, 0x68, 0xA2, 0x12, 0x78,
  25193. 0x18, 0x99, 0x42, 0x17, 0xAE, 0xC8, 0xBD, 0xB3,
  25194. 0x9A, 0x97, 0x0A, 0x99, 0x63, 0xDE, 0x93, 0x68,
  25195. 0x8E, 0x2A, 0xC8, 0x2A, 0xBC, 0xC2, 0x2F, 0xB9,
  25196. 0x27, 0x7B, 0xA2, 0x20, 0x09, 0xE8, 0x78, 0x38,
  25197. 0x1A, 0x38, 0x16, 0x39, 0x01, 0xC7, 0xD4, 0xC8,
  25198. 0x50, 0x19, 0x53, 0x8D, 0x35, 0xCA, 0xAE, 0x9C,
  25199. 0x41, 0xAF, 0x8C, 0x92, 0x9E, 0xE2, 0x0B, 0xB0,
  25200. 0x8C, 0xA6, 0x19, 0xE7, 0x2C, 0x2F, 0x22, 0x62,
  25201. 0xC1, 0xC9, 0x93, 0x85, 0x72, 0x55, 0x1A, 0xC0,
  25202. 0x2D, 0xC9, 0x26, 0x8F, 0xBC, 0xC3, 0x5D, 0x79,
  25203. 0x01, 0x1C, 0x3C, 0x09, 0x0A, 0xD4, 0x0A, 0x4F,
  25204. 0x11, 0x1C, 0x9B, 0xE5, 0x5C, 0x42, 0x7E, 0xB7,
  25205. 0x96, 0xC1, 0x93, 0x2D, 0x86, 0x73, 0x57, 0x9A,
  25206. 0xF1, 0xB4, 0xC6, 0x38, 0xB0, 0x94, 0x44, 0x89,
  25207. 0x01, 0x2A, 0x25, 0x59, 0xA3, 0xB0, 0x24, 0x81,
  25208. 0xB0, 0x1A, 0xC3, 0x0B, 0xA8, 0x96, 0x0F, 0x80,
  25209. 0xC0, 0xC2, 0xB3, 0x94, 0x7D, 0x36, 0xA1, 0x2C,
  25210. 0x08, 0x04, 0x98, 0xBE, 0xE4, 0x48, 0x71, 0x6C,
  25211. 0x97, 0x34, 0x16, 0xC8, 0x24, 0x28, 0x04, 0xA3,
  25212. 0xDA, 0x09, 0x9E, 0xE1, 0x37, 0xB0, 0xBA, 0x90,
  25213. 0xFE, 0x4A, 0x5C, 0x6A, 0x89, 0x20, 0x02, 0x76,
  25214. 0xA0, 0xCF, 0xB6, 0x43, 0xEC, 0x2C, 0x56, 0xA2,
  25215. 0xD7, 0x08, 0xD7, 0xB4, 0x37, 0x3E, 0x44, 0xC1,
  25216. 0x50, 0x2A, 0x76, 0x3A, 0x60, 0x05, 0x86, 0xE6,
  25217. 0xCD, 0xA6, 0x27, 0x38, 0x97, 0xD4, 0x44, 0x48,
  25218. 0x28, 0x7D, 0xC2, 0xE6, 0x02, 0xDC, 0x39, 0x20,
  25219. 0x0B, 0xF6, 0x16, 0x62, 0x36, 0x55, 0x9F, 0xD1,
  25220. 0x2A, 0x60, 0x89, 0x2A, 0xEB, 0x15, 0x3D, 0xD6,
  25221. 0x51, 0xBB, 0x46, 0x99, 0x10, 0xB4, 0xB3, 0x46,
  25222. 0x69, 0xF9, 0x1D, 0xA8, 0x65, 0x4D, 0x1E, 0xB7,
  25223. 0x2E, 0xB6, 0xE0, 0x28, 0x00, 0xB3, 0xB0, 0xA7,
  25224. 0xD0, 0xA4, 0x8C, 0x83, 0x68, 0x54, 0xD3, 0xA8,
  25225. 0x3E, 0x65, 0x56, 0x9C, 0xB7, 0x23, 0x0B, 0xB4,
  25226. 0x4F, 0x3F, 0x14, 0x3A, 0x6D, 0xEC, 0x5F, 0x2C,
  25227. 0x39, 0xAB, 0x90, 0xF2, 0x74, 0xF2, 0x08, 0x8B,
  25228. 0xD3, 0xD6, 0xA6, 0xFC, 0xA0, 0x07, 0x02, 0x73,
  25229. 0xBE, 0xDC, 0x84, 0x77, 0x7F, 0xB5, 0x2E, 0x3C,
  25230. 0x55, 0x8B, 0x0A, 0xE0, 0x61, 0x83, 0xD5, 0xA4,
  25231. 0x8D, 0x45, 0x2F, 0x68, 0xE1, 0x52, 0x07, 0xF8,
  25232. 0x61, 0x62, 0x7A, 0xCA, 0x14, 0x27, 0x96, 0x30,
  25233. 0xF8, 0x2E, 0xC3, 0xA0, 0xCA, 0x07, 0x86, 0x33,
  25234. 0xB6, 0x00, 0xAF, 0xA7, 0x97, 0x43, 0xA6, 0x00,
  25235. 0x21, 0x5B, 0xE5, 0x63, 0x74, 0x58, 0xCE, 0x2C,
  25236. 0xE8, 0xAF, 0xF5, 0xA0, 0x8E, 0xB5, 0x01, 0x7B,
  25237. 0x2C, 0x76, 0x65, 0x77, 0x47, 0x9F, 0x8D, 0xC6,
  25238. 0xBF, 0x9F, 0x5C, 0xC7, 0x50, 0x89, 0x93, 0x21,
  25239. 0x61, 0xB9, 0x6C, 0xEA, 0x40, 0x66, 0x20, 0xAE,
  25240. 0xDB, 0x63, 0x04, 0x07, 0xF7, 0x68, 0x7E, 0xBB,
  25241. 0xB4, 0x81, 0x4C, 0x79, 0x81, 0x63, 0x7A, 0x48,
  25242. 0xA9, 0x0D, 0xE6, 0x80, 0x31, 0xE0, 0x62, 0xA7,
  25243. 0xAF, 0x76, 0x12, 0xB4, 0xF5, 0xC7, 0xA6, 0xDA,
  25244. 0x86, 0xBD, 0x13, 0x65, 0x29, 0xE6, 0x42, 0x95,
  25245. 0xA5, 0x61, 0x3E, 0xA7, 0x3B, 0xD3, 0xD4, 0x44,
  25246. 0x8C, 0xB8, 0x1F, 0x24, 0x31, 0x35, 0xC0, 0xA6,
  25247. 0x60, 0xBE, 0xB9, 0xC1, 0x7E, 0x65, 0x1D, 0xEF,
  25248. 0x46, 0x9A, 0x7D, 0x90, 0xA1, 0x5D, 0x34, 0x81,
  25249. 0x09, 0x0B, 0xCB, 0xF2, 0x27, 0x01, 0x23, 0x28,
  25250. 0x94, 0x1F, 0xA4, 0x6F, 0x39, 0xC5, 0x00, 0x6A,
  25251. 0xD9, 0x3D, 0x45, 0x8A, 0xA6, 0xAD, 0xD6, 0x55,
  25252. 0x86, 0x2B, 0x41, 0x8C, 0x30, 0x94, 0xF5, 0x51,
  25253. 0x46, 0x0D, 0xF2, 0x15, 0x3A, 0x58, 0x10, 0xA7,
  25254. 0xDA, 0x74, 0xF0, 0x61, 0x4C, 0x25, 0x88, 0xBE,
  25255. 0x49, 0xDC, 0x6F, 0x5E, 0x88, 0x15, 0x46, 0x42,
  25256. 0xBD, 0x1D, 0x37, 0x62, 0x56, 0x33, 0x26, 0x43,
  25257. 0x35, 0x07, 0x15, 0x6A, 0x57, 0xC5, 0x76, 0x94,
  25258. 0xBD, 0xD2, 0x6E, 0x7A, 0x24, 0x6F, 0xEB, 0x72,
  25259. 0x3A, 0xED, 0x67, 0xB0, 0x48, 0x87, 0xC8, 0xE4,
  25260. 0x76, 0xB4, 0x8C, 0xAB, 0x59, 0xE5, 0x36, 0x2F,
  25261. 0x26, 0xA9, 0xEF, 0x50, 0xC2, 0xBC, 0x80, 0xBA,
  25262. 0x14, 0x62, 0x26, 0x21, 0x6F, 0xE6, 0x29, 0x68,
  25263. 0xA6, 0x0D, 0x04, 0xE8, 0xC1, 0x70, 0xD7, 0x41,
  25264. 0xC7, 0xA2, 0xB0, 0xE1, 0xAB, 0xDA, 0xC9, 0x68,
  25265. 0xE2, 0x90, 0x20, 0x83, 0x9D, 0x05, 0x2F, 0xA3,
  25266. 0x72, 0x58, 0x56, 0x27, 0xF8, 0xB5, 0x9E, 0xE3,
  25267. 0x12, 0xAE, 0x41, 0x4C, 0x97, 0x9D, 0x82, 0x5F,
  25268. 0x06, 0xA6, 0x92, 0x9A, 0x79, 0x62, 0x57, 0x18,
  25269. 0xA8, 0x57, 0x68, 0xF3, 0x48, 0x6B, 0xD3, 0x2A,
  25270. 0x01, 0xBF, 0x9A, 0x8F, 0x21, 0xEA, 0x93, 0x8E,
  25271. 0x64, 0x8E, 0xAE, 0x4E, 0x54, 0x48, 0xC3, 0x4C,
  25272. 0x3E, 0xB8, 0x88, 0x20, 0xB1, 0x59, 0xEE, 0xDD
  25273. };
  25274. #endif
  25275. #ifndef WOLFSSL_NO_KYBER1024
  25276. static const byte seed_1024[KYBER_MAKEKEY_RAND_SZ] = {
  25277. /* d */
  25278. 0x49, 0xAC, 0x8B, 0x99, 0xBB, 0x1E, 0x6A, 0x8E,
  25279. 0xA8, 0x18, 0x26, 0x1F, 0x8B, 0xE6, 0x8B, 0xDE,
  25280. 0xAA, 0x52, 0x89, 0x7E, 0x7E, 0xC6, 0xC4, 0x0B,
  25281. 0x53, 0x0B, 0xC7, 0x60, 0xAB, 0x77, 0xDC, 0xE3,
  25282. /* z */
  25283. 0x99, 0xE3, 0x24, 0x68, 0x84, 0x18, 0x1F, 0x8E,
  25284. 0x1D, 0xD4, 0x4E, 0x0C, 0x76, 0x29, 0x09, 0x33,
  25285. 0x30, 0x22, 0x1F, 0xD6, 0x7D, 0x9B, 0x7D, 0x6E,
  25286. 0x15, 0x10, 0xB2, 0xDB, 0xAD, 0x87, 0x62, 0xF7
  25287. };
  25288. static const byte ek_1024[KYBER1024_PUBLIC_KEY_SIZE] = {
  25289. 0xA0, 0x41, 0x84, 0xD4, 0xBC, 0x7B, 0x53, 0x2A,
  25290. 0x0F, 0x70, 0xA5, 0x4D, 0x77, 0x57, 0xCD, 0xE6,
  25291. 0x17, 0x5A, 0x68, 0x43, 0xB8, 0x61, 0xCB, 0x2B,
  25292. 0xC4, 0x83, 0x0C, 0x00, 0x12, 0x55, 0x4C, 0xFC,
  25293. 0x5D, 0x2C, 0x8A, 0x20, 0x27, 0xAA, 0x3C, 0xD9,
  25294. 0x67, 0x13, 0x0E, 0x9B, 0x96, 0x24, 0x1B, 0x11,
  25295. 0xC4, 0x32, 0x0C, 0x76, 0x49, 0xCC, 0x23, 0xA7,
  25296. 0x1B, 0xAF, 0xE6, 0x91, 0xAF, 0xC0, 0x8E, 0x68,
  25297. 0x0B, 0xCE, 0xF4, 0x29, 0x07, 0x00, 0x07, 0x18,
  25298. 0xE4, 0xEA, 0xCE, 0x8D, 0xA2, 0x82, 0x14, 0x19,
  25299. 0x7B, 0xE1, 0xC2, 0x69, 0xDA, 0x9C, 0xB5, 0x41,
  25300. 0xE1, 0xA3, 0xCE, 0x97, 0xCF, 0xAD, 0xF9, 0xC6,
  25301. 0x05, 0x87, 0x80, 0xFE, 0x67, 0x93, 0xDB, 0xFA,
  25302. 0x82, 0x18, 0xA2, 0x76, 0x0B, 0x80, 0x2B, 0x8D,
  25303. 0xA2, 0xAA, 0x27, 0x1A, 0x38, 0x77, 0x25, 0x23,
  25304. 0xA7, 0x67, 0x36, 0xA7, 0xA3, 0x1B, 0x9D, 0x30,
  25305. 0x37, 0xAD, 0x21, 0xCE, 0xBB, 0x11, 0xA4, 0x72,
  25306. 0xB8, 0x79, 0x2E, 0xB1, 0x75, 0x58, 0xB9, 0x40,
  25307. 0xE7, 0x08, 0x83, 0xF2, 0x64, 0x59, 0x2C, 0x68,
  25308. 0x9B, 0x24, 0x0B, 0xB4, 0x3D, 0x54, 0x08, 0xBF,
  25309. 0x44, 0x64, 0x32, 0xF4, 0x12, 0xF4, 0xB9, 0xA5,
  25310. 0xF6, 0x86, 0x5C, 0xC2, 0x52, 0xA4, 0x3C, 0xF4,
  25311. 0x0A, 0x32, 0x03, 0x91, 0x55, 0x55, 0x91, 0xD6,
  25312. 0x75, 0x61, 0xFD, 0xD0, 0x53, 0x53, 0xAB, 0x6B,
  25313. 0x01, 0x9B, 0x3A, 0x08, 0xA7, 0x33, 0x53, 0xD5,
  25314. 0x1B, 0x61, 0x13, 0xAB, 0x2F, 0xA5, 0x1D, 0x97,
  25315. 0x56, 0x48, 0xEE, 0x25, 0x4A, 0xF8, 0x9A, 0x23,
  25316. 0x05, 0x04, 0xA2, 0x36, 0xA4, 0x65, 0x82, 0x57,
  25317. 0x74, 0x0B, 0xDC, 0xBB, 0xE1, 0x70, 0x8A, 0xB0,
  25318. 0x22, 0xC3, 0xC5, 0x88, 0xA4, 0x10, 0xDB, 0x3B,
  25319. 0x9C, 0x30, 0x8A, 0x06, 0x27, 0x5B, 0xDF, 0x5B,
  25320. 0x48, 0x59, 0xD3, 0xA2, 0x61, 0x7A, 0x29, 0x5E,
  25321. 0x1A, 0x22, 0xF9, 0x01, 0x98, 0xBA, 0xD0, 0x16,
  25322. 0x6F, 0x4A, 0x94, 0x34, 0x17, 0xC5, 0xB8, 0x31,
  25323. 0x73, 0x6C, 0xB2, 0xC8, 0x58, 0x0A, 0xBF, 0xDE,
  25324. 0x57, 0x14, 0xB5, 0x86, 0xAB, 0xEE, 0xC0, 0xA1,
  25325. 0x75, 0xA0, 0x8B, 0xC7, 0x10, 0xC7, 0xA2, 0x89,
  25326. 0x5D, 0xE9, 0x3A, 0xC4, 0x38, 0x06, 0x1B, 0xF7,
  25327. 0x76, 0x5D, 0x0D, 0x21, 0xCD, 0x41, 0x81, 0x67,
  25328. 0xCA, 0xF8, 0x9D, 0x1E, 0xFC, 0x34, 0x48, 0xBC,
  25329. 0xBB, 0x96, 0xD6, 0x9B, 0x3E, 0x01, 0x0C, 0x82,
  25330. 0xD1, 0x5C, 0xAB, 0x6C, 0xAC, 0xC6, 0x79, 0x9D,
  25331. 0x36, 0x39, 0x66, 0x9A, 0x5B, 0x21, 0xA6, 0x33,
  25332. 0xC8, 0x65, 0xF8, 0x59, 0x3B, 0x5B, 0x7B, 0xC8,
  25333. 0x00, 0x26, 0x2B, 0xB8, 0x37, 0xA9, 0x24, 0xA6,
  25334. 0xC5, 0x44, 0x0E, 0x4F, 0xC7, 0x3B, 0x41, 0xB2,
  25335. 0x30, 0x92, 0xC3, 0x91, 0x2F, 0x4C, 0x6B, 0xEB,
  25336. 0xB4, 0xC7, 0xB4, 0xC6, 0x29, 0x08, 0xB0, 0x37,
  25337. 0x75, 0x66, 0x6C, 0x22, 0x22, 0x0D, 0xF9, 0xC8,
  25338. 0x88, 0x23, 0xE3, 0x44, 0xC7, 0x30, 0x83, 0x32,
  25339. 0x34, 0x5C, 0x8B, 0x79, 0x5D, 0x34, 0xE8, 0xC0,
  25340. 0x51, 0xF2, 0x1F, 0x5A, 0x21, 0xC2, 0x14, 0xB6,
  25341. 0x98, 0x41, 0x35, 0x87, 0x09, 0xB1, 0xC3, 0x05,
  25342. 0xB3, 0x2C, 0xC2, 0xC3, 0x80, 0x6A, 0xE9, 0xCC,
  25343. 0xD3, 0x81, 0x9F, 0xFF, 0x45, 0x07, 0xFE, 0x52,
  25344. 0x0F, 0xBF, 0xC2, 0x71, 0x99, 0xBC, 0x23, 0xBE,
  25345. 0x6B, 0x9B, 0x2D, 0x2A, 0xC1, 0x71, 0x75, 0x79,
  25346. 0xAC, 0x76, 0x92, 0x79, 0xE2, 0xA7, 0xAA, 0xC6,
  25347. 0x8A, 0x37, 0x1A, 0x47, 0xBA, 0x3A, 0x7D, 0xBE,
  25348. 0x01, 0x6F, 0x14, 0xE1, 0xA7, 0x27, 0x33, 0x36,
  25349. 0x63, 0xC4, 0xA5, 0xCD, 0x1A, 0x0F, 0x88, 0x36,
  25350. 0xCF, 0x7B, 0x5C, 0x49, 0xAC, 0x51, 0x48, 0x5C,
  25351. 0xA6, 0x03, 0x45, 0xC9, 0x90, 0xE0, 0x68, 0x88,
  25352. 0x72, 0x00, 0x03, 0x73, 0x13, 0x22, 0xC5, 0xB8,
  25353. 0xCD, 0x5E, 0x69, 0x07, 0xFD, 0xA1, 0x15, 0x7F,
  25354. 0x46, 0x8F, 0xD3, 0xFC, 0x20, 0xFA, 0x81, 0x75,
  25355. 0xEE, 0xC9, 0x5C, 0x29, 0x1A, 0x26, 0x2B, 0xA8,
  25356. 0xC5, 0xBE, 0x99, 0x08, 0x72, 0x41, 0x89, 0x30,
  25357. 0x85, 0x23, 0x39, 0xD8, 0x8A, 0x19, 0xB3, 0x7F,
  25358. 0xEF, 0xA3, 0xCF, 0xE8, 0x21, 0x75, 0xC2, 0x24,
  25359. 0x40, 0x7C, 0xA4, 0x14, 0xBA, 0xEB, 0x37, 0x92,
  25360. 0x3B, 0x4D, 0x2D, 0x83, 0x13, 0x4A, 0xE1, 0x54,
  25361. 0xE4, 0x90, 0xA9, 0xB4, 0x5A, 0x05, 0x63, 0xB0,
  25362. 0x6C, 0x95, 0x3C, 0x33, 0x01, 0x45, 0x0A, 0x21,
  25363. 0x76, 0xA0, 0x7C, 0x61, 0x4A, 0x74, 0xE3, 0x47,
  25364. 0x8E, 0x48, 0x50, 0x9F, 0x9A, 0x60, 0xAE, 0x94,
  25365. 0x5A, 0x8E, 0xBC, 0x78, 0x15, 0x12, 0x1D, 0x90,
  25366. 0xA3, 0xB0, 0xE0, 0x70, 0x91, 0xA0, 0x96, 0xCF,
  25367. 0x02, 0xC5, 0x7B, 0x25, 0xBC, 0xA5, 0x81, 0x26,
  25368. 0xAD, 0x0C, 0x62, 0x9C, 0xE1, 0x66, 0xA7, 0xED,
  25369. 0xB4, 0xB3, 0x32, 0x21, 0xA0, 0xD3, 0xF7, 0x2B,
  25370. 0x85, 0xD5, 0x62, 0xEC, 0x69, 0x8B, 0x7D, 0x0A,
  25371. 0x91, 0x3D, 0x73, 0x80, 0x6F, 0x1C, 0x5C, 0x87,
  25372. 0xB3, 0x8E, 0xC0, 0x03, 0xCB, 0x30, 0x3A, 0x3D,
  25373. 0xC5, 0x1B, 0x4B, 0x35, 0x35, 0x6A, 0x67, 0x82,
  25374. 0x6D, 0x6E, 0xDA, 0xA8, 0xFE, 0xB9, 0x3B, 0x98,
  25375. 0x49, 0x3B, 0x2D, 0x1C, 0x11, 0xB6, 0x76, 0xA6,
  25376. 0xAD, 0x95, 0x06, 0xA1, 0xAA, 0xAE, 0x13, 0xA8,
  25377. 0x24, 0xC7, 0xC0, 0x8D, 0x1C, 0x6C, 0x2C, 0x4D,
  25378. 0xBA, 0x96, 0x42, 0xC7, 0x6E, 0xA7, 0xF6, 0xC8,
  25379. 0x26, 0x4B, 0x64, 0xA2, 0x3C, 0xCC, 0xA9, 0xA7,
  25380. 0x46, 0x35, 0xFC, 0xBF, 0x03, 0xE0, 0x0F, 0x1B,
  25381. 0x57, 0x22, 0xB2, 0x14, 0x37, 0x67, 0x90, 0x79,
  25382. 0x3B, 0x2C, 0x4F, 0x0A, 0x13, 0xB5, 0xC4, 0x07,
  25383. 0x60, 0xB4, 0x21, 0x8E, 0x1D, 0x25, 0x94, 0xDC,
  25384. 0xB3, 0x0A, 0x70, 0xD9, 0xC1, 0x78, 0x2A, 0x5D,
  25385. 0xD3, 0x05, 0x76, 0xFA, 0x41, 0x44, 0xBF, 0xC8,
  25386. 0x41, 0x6E, 0xDA, 0x81, 0x18, 0xFC, 0x64, 0x72,
  25387. 0xF5, 0x6A, 0x97, 0x95, 0x86, 0xF3, 0x3B, 0xB0,
  25388. 0x70, 0xFB, 0x0F, 0x1B, 0x0B, 0x10, 0xBC, 0x48,
  25389. 0x97, 0xEB, 0xE0, 0x1B, 0xCA, 0x38, 0x93, 0xD4,
  25390. 0xE1, 0x6A, 0xDB, 0x25, 0x09, 0x3A, 0x74, 0x17,
  25391. 0xD0, 0x70, 0x8C, 0x83, 0xA2, 0x63, 0x22, 0xE2,
  25392. 0x2E, 0x63, 0x30, 0x09, 0x1E, 0x30, 0x15, 0x2B,
  25393. 0xF8, 0x23, 0x59, 0x7C, 0x04, 0xCC, 0xF4, 0xCF,
  25394. 0xC7, 0x33, 0x15, 0x78, 0xF4, 0x3A, 0x27, 0x26,
  25395. 0xCC, 0xB4, 0x28, 0x28, 0x9A, 0x90, 0xC8, 0x63,
  25396. 0x25, 0x9D, 0xD1, 0x80, 0xC5, 0xFF, 0x14, 0x2B,
  25397. 0xEF, 0x41, 0xC7, 0x71, 0x70, 0x94, 0xBE, 0x07,
  25398. 0x85, 0x6D, 0xA2, 0xB1, 0x40, 0xFA, 0x67, 0x71,
  25399. 0x09, 0x67, 0x35, 0x6A, 0xA4, 0x7D, 0xFB, 0xC8,
  25400. 0xD2, 0x55, 0xB4, 0x72, 0x2A, 0xB8, 0x6D, 0x43,
  25401. 0x9B, 0x7E, 0x0A, 0x60, 0x90, 0x25, 0x1D, 0x2D,
  25402. 0x4C, 0x1E, 0xD5, 0xF2, 0x0B, 0xBE, 0x68, 0x07,
  25403. 0xBF, 0x65, 0xA9, 0x0B, 0x7C, 0xB2, 0xEC, 0x01,
  25404. 0x02, 0xAF, 0x02, 0x80, 0x9D, 0xC9, 0xAC, 0x7D,
  25405. 0x0A, 0x3A, 0xBC, 0x69, 0xC1, 0x83, 0x65, 0xBC,
  25406. 0xFF, 0x59, 0x18, 0x5F, 0x33, 0x99, 0x68, 0x87,
  25407. 0x74, 0x61, 0x85, 0x90, 0x6C, 0x01, 0x91, 0xAE,
  25408. 0xD4, 0x40, 0x7E, 0x13, 0x94, 0x46, 0x45, 0x9B,
  25409. 0xE2, 0x9C, 0x68, 0x22, 0x71, 0x76, 0x44, 0x35,
  25410. 0x3D, 0x24, 0xAB, 0x63, 0x39, 0x15, 0x6A, 0x9C,
  25411. 0x42, 0x49, 0x09, 0xF0, 0xA9, 0x02, 0x5B, 0xB7,
  25412. 0x47, 0x20, 0x77, 0x9B, 0xE4, 0x3F, 0x16, 0xD8,
  25413. 0x1C, 0x8C, 0xC6, 0x66, 0xE9, 0x97, 0x10, 0xD8,
  25414. 0xC6, 0x8B, 0xB5, 0xCC, 0x4E, 0x12, 0xF3, 0x14,
  25415. 0xE9, 0x25, 0xA5, 0x51, 0xF0, 0x9C, 0xC5, 0x90,
  25416. 0x03, 0xA1, 0xF8, 0x81, 0x03, 0xC2, 0x54, 0xBB,
  25417. 0x97, 0x8D, 0x75, 0xF3, 0x94, 0xD3, 0x54, 0x0E,
  25418. 0x31, 0xE7, 0x71, 0xCD, 0xA3, 0x6E, 0x39, 0xEC,
  25419. 0x54, 0xA6, 0x2B, 0x58, 0x32, 0x66, 0x4D, 0x82,
  25420. 0x1A, 0x72, 0xF1, 0xE6, 0xAF, 0xBB, 0xA2, 0x7F,
  25421. 0x84, 0x29, 0x5B, 0x26, 0x94, 0xC4, 0x98, 0x49,
  25422. 0x8E, 0x81, 0x2B, 0xC8, 0xE9, 0x37, 0x8F, 0xE5,
  25423. 0x41, 0xCE, 0xC5, 0x89, 0x1B, 0x25, 0x06, 0x29,
  25424. 0x01, 0xCB, 0x72, 0x12, 0xE3, 0xCD, 0xC4, 0x61,
  25425. 0x79, 0xEC, 0x5B, 0xCE, 0xC1, 0x0B, 0xC0, 0xB9,
  25426. 0x31, 0x1D, 0xE0, 0x50, 0x74, 0x29, 0x06, 0x87,
  25427. 0xFD, 0x6A, 0x53, 0x92, 0x67, 0x16, 0x54, 0x28,
  25428. 0x4C, 0xD9, 0xC8, 0xCC, 0x3E, 0xBA, 0x80, 0xEB,
  25429. 0x3B, 0x66, 0x2E, 0xB5, 0x3E, 0xB7, 0x51, 0x16,
  25430. 0x70, 0x4A, 0x1F, 0xEB, 0x5C, 0x2D, 0x05, 0x63,
  25431. 0x38, 0x53, 0x28, 0x68, 0xDD, 0xF2, 0x4E, 0xB8,
  25432. 0x99, 0x2A, 0xB8, 0x56, 0x5D, 0x9E, 0x49, 0x0C,
  25433. 0xAD, 0xF1, 0x48, 0x04, 0x36, 0x0D, 0xAA, 0x90,
  25434. 0x71, 0x8E, 0xAB, 0x61, 0x6B, 0xAB, 0x07, 0x65,
  25435. 0xD3, 0x39, 0x87, 0xB4, 0x7E, 0xFB, 0x65, 0x99,
  25436. 0xC5, 0x56, 0x32, 0x35, 0xE6, 0x1E, 0x4B, 0xE6,
  25437. 0x70, 0xE9, 0x79, 0x55, 0xAB, 0x29, 0x2D, 0x97,
  25438. 0x32, 0xCB, 0x89, 0x30, 0x94, 0x8A, 0xC8, 0x2D,
  25439. 0xF2, 0x30, 0xAC, 0x72, 0x29, 0x7A, 0x23, 0x67,
  25440. 0x9D, 0x6B, 0x94, 0xC1, 0x7F, 0x13, 0x59, 0x48,
  25441. 0x32, 0x54, 0xFE, 0xDC, 0x2F, 0x05, 0x81, 0x9F,
  25442. 0x0D, 0x06, 0x9A, 0x44, 0x3B, 0x78, 0xE3, 0xFC,
  25443. 0x6C, 0x3E, 0xF4, 0x71, 0x4B, 0x05, 0xA3, 0xFC,
  25444. 0xA8, 0x1C, 0xBB, 0xA6, 0x02, 0x42, 0xA7, 0x06,
  25445. 0x0C, 0xD8, 0x85, 0xD8, 0xF3, 0x99, 0x81, 0xBB,
  25446. 0x18, 0x09, 0x2B, 0x23, 0xDA, 0xA5, 0x9F, 0xD9,
  25447. 0x57, 0x83, 0x88, 0x68, 0x8A, 0x09, 0xBB, 0xA0,
  25448. 0x79, 0xBC, 0x80, 0x9A, 0x54, 0x84, 0x3A, 0x60,
  25449. 0x38, 0x5E, 0x23, 0x10, 0xBB, 0xCB, 0xCC, 0x02,
  25450. 0x13, 0xCE, 0x3D, 0xFA, 0xAB, 0x33, 0xB4, 0x7F,
  25451. 0x9D, 0x63, 0x05, 0xBC, 0x95, 0xC6, 0x10, 0x78,
  25452. 0x13, 0xC5, 0x85, 0xC4, 0xB6, 0x57, 0xBF, 0x30,
  25453. 0x54, 0x28, 0x33, 0xB1, 0x49, 0x49, 0xF5, 0x73,
  25454. 0xC0, 0x61, 0x2A, 0xD5, 0x24, 0xBA, 0xAE, 0x69,
  25455. 0x59, 0x0C, 0x12, 0x77, 0xB8, 0x6C, 0x28, 0x65,
  25456. 0x71, 0xBF, 0x66, 0xB3, 0xCF, 0xF4, 0x6A, 0x38,
  25457. 0x58, 0xC0, 0x99, 0x06, 0xA7, 0x94, 0xDF, 0x4A,
  25458. 0x06, 0xE9, 0xD4, 0xB0, 0xA2, 0xE4, 0x3F, 0x10,
  25459. 0xF7, 0x2A, 0x6C, 0x6C, 0x47, 0xE5, 0x64, 0x6E,
  25460. 0x2C, 0x79, 0x9B, 0x71, 0xC3, 0x3E, 0xD2, 0xF0,
  25461. 0x1E, 0xEB, 0x45, 0x93, 0x8E, 0xB7, 0xA4, 0xE2,
  25462. 0xE2, 0x90, 0x8C, 0x53, 0x55, 0x8A, 0x54, 0x0D,
  25463. 0x35, 0x03, 0x69, 0xFA, 0x18, 0x9C, 0x61, 0x69,
  25464. 0x43, 0xF7, 0x98, 0x1D, 0x76, 0x18, 0xCF, 0x02,
  25465. 0xA5, 0xB0, 0xA2, 0xBC, 0xC4, 0x22, 0xE8, 0x57,
  25466. 0xD1, 0xA4, 0x78, 0x71, 0x25, 0x3D, 0x08, 0x29,
  25467. 0x3C, 0x1C, 0x17, 0x9B, 0xCD, 0xC0, 0x43, 0x70,
  25468. 0x69, 0x10, 0x74, 0x18, 0x20, 0x5F, 0xDB, 0x98,
  25469. 0x56, 0x62, 0x3B, 0x8C, 0xA6, 0xB6, 0x94, 0xC9,
  25470. 0x6C, 0x08, 0x4B, 0x17, 0xF1, 0x3B, 0xB6, 0xDF,
  25471. 0x12, 0xB2, 0xCF, 0xBB, 0xC2, 0xB0, 0xE0, 0xC3,
  25472. 0x4B, 0x00, 0xD0, 0xFC, 0xD0, 0xAE, 0xCF, 0xB2,
  25473. 0x79, 0x24, 0xF6, 0x98, 0x4E, 0x74, 0x7B, 0xE2,
  25474. 0xA0, 0x9D, 0x83, 0xA8, 0x66, 0x45, 0x90, 0xA8,
  25475. 0x07, 0x73, 0x31, 0x49, 0x1A, 0x4F, 0x7D, 0x72,
  25476. 0x08, 0x43, 0xF2, 0x3E, 0x65, 0x2C, 0x6F, 0xA8,
  25477. 0x40, 0x30, 0x8D, 0xB4, 0x02, 0x03, 0x37, 0xAA,
  25478. 0xD3, 0x79, 0x67, 0x03, 0x4A, 0x9F, 0xB5, 0x23,
  25479. 0xB6, 0x7C, 0xA7, 0x03, 0x30, 0xF0, 0x2D, 0x9E,
  25480. 0xA2, 0x0C, 0x1E, 0x84, 0xCB, 0x8E, 0x57, 0x57,
  25481. 0xC9, 0xE1, 0x89, 0x6B, 0x60, 0x58, 0x14, 0x41,
  25482. 0xED, 0x61, 0x8A, 0xA5, 0xB2, 0x6D, 0xA5, 0x6C,
  25483. 0x0A, 0x5A, 0x73, 0xC4, 0xDC, 0xFD, 0x75, 0x5E,
  25484. 0x61, 0x0B, 0x4F, 0xC8, 0x1F, 0xF8, 0x4E, 0x21
  25485. };
  25486. static const byte dk_1024[KYBER1024_PRIVATE_KEY_SIZE] = {
  25487. 0x8C, 0x8B, 0x37, 0x22, 0xA8, 0x2E, 0x55, 0x05,
  25488. 0x65, 0x52, 0x16, 0x11, 0xEB, 0xBC, 0x63, 0x07,
  25489. 0x99, 0x44, 0xC9, 0xB1, 0xAB, 0xB3, 0xB0, 0x02,
  25490. 0x0F, 0xF1, 0x2F, 0x63, 0x18, 0x91, 0xA9, 0xC4,
  25491. 0x68, 0xD3, 0xA6, 0x7B, 0xF6, 0x27, 0x12, 0x80,
  25492. 0xDA, 0x58, 0xD0, 0x3C, 0xB0, 0x42, 0xB3, 0xA4,
  25493. 0x61, 0x44, 0x16, 0x37, 0xF9, 0x29, 0xC2, 0x73,
  25494. 0x46, 0x9A, 0xD1, 0x53, 0x11, 0xE9, 0x10, 0xDE,
  25495. 0x18, 0xCB, 0x95, 0x37, 0xBA, 0x1B, 0xE4, 0x2E,
  25496. 0x98, 0xBB, 0x59, 0xE4, 0x98, 0xA1, 0x3F, 0xD4,
  25497. 0x40, 0xD0, 0xE6, 0x9E, 0xE8, 0x32, 0xB4, 0x5C,
  25498. 0xD9, 0x5C, 0x38, 0x21, 0x77, 0xD6, 0x70, 0x96,
  25499. 0xA1, 0x8C, 0x07, 0xF1, 0x78, 0x16, 0x63, 0x65,
  25500. 0x1B, 0xDC, 0xAC, 0x90, 0xDE, 0xDA, 0x3D, 0xDD,
  25501. 0x14, 0x34, 0x85, 0x86, 0x41, 0x81, 0xC9, 0x1F,
  25502. 0xA2, 0x08, 0x0F, 0x6D, 0xAB, 0x3F, 0x86, 0x20,
  25503. 0x4C, 0xEB, 0x64, 0xA7, 0xB4, 0x44, 0x68, 0x95,
  25504. 0xC0, 0x39, 0x87, 0xA0, 0x31, 0xCB, 0x4B, 0x6D,
  25505. 0x9E, 0x04, 0x62, 0xFD, 0xA8, 0x29, 0x17, 0x2B,
  25506. 0x6C, 0x01, 0x2C, 0x63, 0x8B, 0x29, 0xB5, 0xCD,
  25507. 0x75, 0xA2, 0xC9, 0x30, 0xA5, 0x59, 0x6A, 0x31,
  25508. 0x81, 0xC3, 0x3A, 0x22, 0xD5, 0x74, 0xD3, 0x02,
  25509. 0x61, 0x19, 0x6B, 0xC3, 0x50, 0x73, 0x8D, 0x4F,
  25510. 0xD9, 0x18, 0x3A, 0x76, 0x33, 0x36, 0x24, 0x3A,
  25511. 0xCE, 0xD9, 0x9B, 0x32, 0x21, 0xC7, 0x1D, 0x88,
  25512. 0x66, 0x89, 0x5C, 0x4E, 0x52, 0xC1, 0x19, 0xBF,
  25513. 0x32, 0x80, 0xDA, 0xF8, 0x0A, 0x95, 0xE1, 0x52,
  25514. 0x09, 0xA7, 0x95, 0xC4, 0x43, 0x5F, 0xBB, 0x35,
  25515. 0x70, 0xFD, 0xB8, 0xAA, 0x9B, 0xF9, 0xAE, 0xFD,
  25516. 0x43, 0xB0, 0x94, 0xB7, 0x81, 0xD5, 0xA8, 0x11,
  25517. 0x36, 0xDA, 0xB8, 0x8B, 0x87, 0x99, 0x69, 0x65,
  25518. 0x56, 0xFE, 0xC6, 0xAE, 0x14, 0xB0, 0xBB, 0x8B,
  25519. 0xE4, 0x69, 0x5E, 0x9A, 0x12, 0x4C, 0x2A, 0xB8,
  25520. 0xFF, 0x4A, 0xB1, 0x22, 0x9B, 0x8A, 0xAA, 0x8C,
  25521. 0x6F, 0x41, 0xA6, 0x0C, 0x34, 0xC7, 0xB5, 0x61,
  25522. 0x82, 0xC5, 0x5C, 0x2C, 0x68, 0x5E, 0x73, 0x7C,
  25523. 0x6C, 0xA0, 0x0A, 0x23, 0xFB, 0x8A, 0x68, 0xC1,
  25524. 0xCD, 0x61, 0xF3, 0x0D, 0x39, 0x93, 0xA1, 0x65,
  25525. 0x3C, 0x16, 0x75, 0xAC, 0x5F, 0x09, 0x01, 0xA7,
  25526. 0x16, 0x0A, 0x73, 0x96, 0x64, 0x08, 0xB8, 0x87,
  25527. 0x6B, 0x71, 0x53, 0x96, 0xCF, 0xA4, 0x90, 0x3F,
  25528. 0xC6, 0x9D, 0x60, 0x49, 0x1F, 0x81, 0x46, 0x80,
  25529. 0x8C, 0x97, 0xCD, 0x5C, 0x53, 0x3E, 0x71, 0x01,
  25530. 0x79, 0x09, 0xE9, 0x7B, 0x83, 0x5B, 0x86, 0xFF,
  25531. 0x84, 0x7B, 0x42, 0xA6, 0x96, 0x37, 0x54, 0x35,
  25532. 0xE0, 0x06, 0x06, 0x1C, 0xF7, 0xA4, 0x79, 0x46,
  25533. 0x32, 0x72, 0x11, 0x4A, 0x89, 0xEB, 0x3E, 0xAF,
  25534. 0x22, 0x46, 0xF0, 0xF8, 0xC1, 0x04, 0xA1, 0x49,
  25535. 0x86, 0x82, 0x8E, 0x0A, 0xD2, 0x04, 0x20, 0xC9,
  25536. 0xB3, 0x7E, 0xA2, 0x3F, 0x5C, 0x51, 0x49, 0x49,
  25537. 0xE7, 0x7A, 0xD9, 0xE9, 0xAD, 0x12, 0x29, 0x0D,
  25538. 0xD1, 0x21, 0x5E, 0x11, 0xDA, 0x27, 0x44, 0x57,
  25539. 0xAC, 0x86, 0xB1, 0xCE, 0x68, 0x64, 0xB1, 0x22,
  25540. 0x67, 0x7F, 0x37, 0x18, 0xAA, 0x31, 0xB0, 0x25,
  25541. 0x80, 0xE6, 0x43, 0x17, 0x17, 0x8D, 0x38, 0xF2,
  25542. 0x5F, 0x60, 0x9B, 0xC6, 0xC5, 0x5B, 0xC3, 0x74,
  25543. 0xA1, 0xBF, 0x78, 0xEA, 0x8E, 0xCC, 0x21, 0x9B,
  25544. 0x30, 0xB7, 0x4C, 0xBB, 0x32, 0x72, 0xA5, 0x99,
  25545. 0x23, 0x8C, 0x93, 0x98, 0x51, 0x70, 0x04, 0x8F,
  25546. 0x17, 0x67, 0x75, 0xFB, 0x19, 0x96, 0x2A, 0xC3,
  25547. 0xB1, 0x35, 0xAA, 0x59, 0xDB, 0x10, 0x4F, 0x71,
  25548. 0x14, 0xDB, 0xC2, 0xC2, 0xD4, 0x29, 0x49, 0xAD,
  25549. 0xEC, 0xA6, 0xA8, 0x5B, 0x32, 0x3E, 0xE2, 0xB2,
  25550. 0xB2, 0x3A, 0x77, 0xD9, 0xDB, 0x23, 0x59, 0x79,
  25551. 0xA8, 0xE2, 0xD6, 0x7C, 0xF7, 0xD2, 0x13, 0x6B,
  25552. 0xBB, 0xA7, 0x1F, 0x26, 0x95, 0x74, 0xB3, 0x88,
  25553. 0x88, 0xE1, 0x54, 0x13, 0x40, 0xC1, 0x92, 0x84,
  25554. 0x07, 0x4F, 0x9B, 0x7C, 0x8C, 0xF3, 0x7E, 0xB0,
  25555. 0x13, 0x84, 0xE6, 0xE3, 0x82, 0x2E, 0xC4, 0x88,
  25556. 0x2D, 0xFB, 0xBE, 0xC4, 0xE6, 0x09, 0x8E, 0xF2,
  25557. 0xB2, 0xFC, 0x17, 0x7A, 0x1F, 0x0B, 0xCB, 0x65,
  25558. 0xA5, 0x7F, 0xDA, 0xA8, 0x93, 0x15, 0x46, 0x1B,
  25559. 0xEB, 0x78, 0x85, 0xFB, 0x68, 0xB3, 0xCD, 0x09,
  25560. 0x6E, 0xDA, 0x59, 0x6A, 0xC0, 0xE6, 0x1D, 0xD7,
  25561. 0xA9, 0xC5, 0x07, 0xBC, 0x63, 0x45, 0xE0, 0x82,
  25562. 0x7D, 0xFC, 0xC8, 0xA3, 0xAC, 0x2D, 0xCE, 0x51,
  25563. 0xAD, 0x73, 0x1A, 0xA0, 0xEB, 0x93, 0x2A, 0x6D,
  25564. 0x09, 0x83, 0x99, 0x23, 0x47, 0xCB, 0xEB, 0x3C,
  25565. 0xD0, 0xD9, 0xC9, 0x71, 0x97, 0x97, 0xCC, 0x21,
  25566. 0xCF, 0x00, 0x62, 0xB0, 0xAD, 0x94, 0xCA, 0xD7,
  25567. 0x34, 0xC6, 0x3E, 0x6B, 0x5D, 0x85, 0x9C, 0xBE,
  25568. 0x19, 0xF0, 0x36, 0x82, 0x45, 0x35, 0x1B, 0xF4,
  25569. 0x64, 0xD7, 0x50, 0x55, 0x69, 0x79, 0x0D, 0x2B,
  25570. 0xB7, 0x24, 0xD8, 0x65, 0x9A, 0x9F, 0xEB, 0x1C,
  25571. 0x7C, 0x47, 0x3D, 0xC4, 0xD0, 0x61, 0xE2, 0x98,
  25572. 0x63, 0xA2, 0x71, 0x4B, 0xAC, 0x42, 0xAD, 0xCD,
  25573. 0x1A, 0x83, 0x72, 0x77, 0x65, 0x56, 0xF7, 0x92,
  25574. 0x8A, 0x7A, 0x44, 0xE9, 0x4B, 0x6A, 0x25, 0x32,
  25575. 0x2D, 0x03, 0xC0, 0xA1, 0x62, 0x2A, 0x7F, 0xD2,
  25576. 0x61, 0x52, 0x2B, 0x73, 0x58, 0xF0, 0x85, 0xBD,
  25577. 0xFB, 0x60, 0x75, 0x87, 0x62, 0xCB, 0x90, 0x10,
  25578. 0x31, 0x90, 0x1B, 0x5E, 0xEC, 0xF4, 0x92, 0x0C,
  25579. 0x81, 0x02, 0x0A, 0x9B, 0x17, 0x81, 0xBC, 0xB9,
  25580. 0xDD, 0x19, 0xA9, 0xDF, 0xB6, 0x64, 0x58, 0xE7,
  25581. 0x75, 0x7C, 0x52, 0xCE, 0xC7, 0x5B, 0x4B, 0xA7,
  25582. 0x40, 0xA2, 0x40, 0x99, 0xCB, 0x56, 0xBB, 0x60,
  25583. 0xA7, 0x6B, 0x69, 0x01, 0xAA, 0x3E, 0x01, 0x69,
  25584. 0xC9, 0xE8, 0x34, 0x96, 0xD7, 0x3C, 0x4C, 0x99,
  25585. 0x43, 0x5A, 0x28, 0xD6, 0x13, 0xE9, 0x7A, 0x11,
  25586. 0x77, 0xF5, 0x8B, 0x6C, 0xC5, 0x95, 0xD3, 0xB2,
  25587. 0x33, 0x1E, 0x9C, 0xA7, 0xB5, 0x7B, 0x74, 0xDC,
  25588. 0x2C, 0x52, 0x77, 0xD2, 0x6F, 0x2F, 0xE1, 0x92,
  25589. 0x40, 0xA5, 0x5C, 0x35, 0xD6, 0xCF, 0xCA, 0x26,
  25590. 0xC7, 0x3E, 0x9A, 0x2D, 0x7C, 0x98, 0x0D, 0x97,
  25591. 0x96, 0x0A, 0xE1, 0xA0, 0x46, 0x98, 0xC1, 0x6B,
  25592. 0x39, 0x8A, 0x5F, 0x20, 0xC3, 0x5A, 0x09, 0x14,
  25593. 0x14, 0x5C, 0xE1, 0x67, 0x4B, 0x71, 0xAB, 0xC6,
  25594. 0x06, 0x6A, 0x90, 0x9A, 0x3E, 0x4B, 0x91, 0x1E,
  25595. 0x69, 0xD5, 0xA8, 0x49, 0x43, 0x03, 0x61, 0xF7,
  25596. 0x31, 0xB0, 0x72, 0x46, 0xA6, 0x32, 0x9B, 0x52,
  25597. 0x36, 0x19, 0x04, 0x22, 0x50, 0x82, 0xD0, 0xAA,
  25598. 0xC5, 0xB2, 0x1D, 0x6B, 0x34, 0x86, 0x24, 0x81,
  25599. 0xA8, 0x90, 0xC3, 0xC3, 0x60, 0x76, 0x6F, 0x04,
  25600. 0x26, 0x36, 0x03, 0xA6, 0xB7, 0x3E, 0x80, 0x2B,
  25601. 0x1F, 0x70, 0xB2, 0xEB, 0x00, 0x04, 0x68, 0x36,
  25602. 0xB8, 0xF4, 0x93, 0xBF, 0x10, 0xB9, 0x0B, 0x87,
  25603. 0x37, 0xC6, 0xC5, 0x48, 0x44, 0x9B, 0x29, 0x4C,
  25604. 0x47, 0x25, 0x3B, 0xE2, 0x6C, 0xA7, 0x23, 0x36,
  25605. 0xA6, 0x32, 0x06, 0x3A, 0xD3, 0xD0, 0xB4, 0x8C,
  25606. 0x8B, 0x0F, 0x4A, 0x34, 0x44, 0x7E, 0xF1, 0x3B,
  25607. 0x76, 0x40, 0x20, 0xDE, 0x73, 0x9E, 0xB7, 0x9A,
  25608. 0xBA, 0x20, 0xE2, 0xBE, 0x19, 0x51, 0x82, 0x5F,
  25609. 0x29, 0x3B, 0xED, 0xD1, 0x08, 0x9F, 0xCB, 0x0A,
  25610. 0x91, 0xF5, 0x60, 0xC8, 0xE1, 0x7C, 0xDF, 0x52,
  25611. 0x54, 0x1D, 0xC2, 0xB8, 0x1F, 0x97, 0x2A, 0x73,
  25612. 0x75, 0xB2, 0x01, 0xF1, 0x0C, 0x08, 0xD9, 0xB5,
  25613. 0xBC, 0x8B, 0x95, 0x10, 0x00, 0x54, 0xA3, 0xD0,
  25614. 0xAA, 0xFF, 0x89, 0xBD, 0x08, 0xD6, 0xA0, 0xE7,
  25615. 0xF2, 0x11, 0x5A, 0x43, 0x52, 0x31, 0x29, 0x04,
  25616. 0x60, 0xC9, 0xAD, 0x43, 0x5A, 0x3B, 0x3C, 0xF3,
  25617. 0x5E, 0x52, 0x09, 0x1E, 0xDD, 0x18, 0x90, 0x04,
  25618. 0x7B, 0xCC, 0x0A, 0xAB, 0xB1, 0xAC, 0xEB, 0xC7,
  25619. 0x5F, 0x4A, 0x32, 0xBC, 0x14, 0x51, 0xAC, 0xC4,
  25620. 0x96, 0x99, 0x40, 0x78, 0x8E, 0x89, 0x41, 0x21,
  25621. 0x88, 0x94, 0x6C, 0x91, 0x43, 0xC5, 0x04, 0x6B,
  25622. 0xD1, 0xB4, 0x58, 0xDF, 0x61, 0x7C, 0x5D, 0xF5,
  25623. 0x33, 0xB0, 0x52, 0xCD, 0x60, 0x38, 0xB7, 0x75,
  25624. 0x40, 0x34, 0xA2, 0x3C, 0x2F, 0x77, 0x20, 0x13,
  25625. 0x4C, 0x7B, 0x4E, 0xAC, 0xE0, 0x1F, 0xAC, 0x0A,
  25626. 0x28, 0x53, 0xA9, 0x28, 0x58, 0x47, 0xAB, 0xBD,
  25627. 0x06, 0xA3, 0x34, 0x3A, 0x77, 0x8A, 0xC6, 0x06,
  25628. 0x2E, 0x45, 0x8B, 0xC5, 0xE6, 0x1E, 0xCE, 0x1C,
  25629. 0x0D, 0xE0, 0x20, 0x6E, 0x6F, 0xE8, 0xA8, 0x40,
  25630. 0x34, 0xA7, 0xC5, 0xF1, 0xB0, 0x05, 0xFB, 0x0A,
  25631. 0x58, 0x40, 0x51, 0xD3, 0x22, 0x9B, 0x86, 0xC9,
  25632. 0x09, 0xAC, 0x56, 0x47, 0xB3, 0xD7, 0x55, 0x69,
  25633. 0xE0, 0x5A, 0x88, 0x27, 0x9D, 0x80, 0xE5, 0xC3,
  25634. 0x0F, 0x57, 0x4D, 0xC3, 0x27, 0x51, 0x2C, 0x6B,
  25635. 0xBE, 0x81, 0x01, 0x23, 0x9E, 0xC6, 0x28, 0x61,
  25636. 0xF4, 0xBE, 0x67, 0xB0, 0x5B, 0x9C, 0xDA, 0x9C,
  25637. 0x54, 0x5C, 0x13, 0xE7, 0xEB, 0x53, 0xCF, 0xF2,
  25638. 0x60, 0xAD, 0x98, 0x70, 0x19, 0x9C, 0x21, 0xF8,
  25639. 0xC6, 0x3D, 0x64, 0xF0, 0x45, 0x8A, 0x71, 0x41,
  25640. 0x28, 0x50, 0x23, 0xFE, 0xB8, 0x29, 0x29, 0x08,
  25641. 0x72, 0x38, 0x96, 0x44, 0xB0, 0xC3, 0xB7, 0x3A,
  25642. 0xC2, 0xC8, 0xE1, 0x21, 0xA2, 0x9B, 0xB1, 0xC4,
  25643. 0x3C, 0x19, 0xA2, 0x33, 0xD5, 0x6B, 0xED, 0x82,
  25644. 0x74, 0x0E, 0xB0, 0x21, 0xC9, 0x7B, 0x8E, 0xBB,
  25645. 0xA4, 0x0F, 0xF3, 0x28, 0xB5, 0x41, 0x76, 0x0F,
  25646. 0xCC, 0x37, 0x2B, 0x52, 0xD3, 0xBC, 0x4F, 0xCB,
  25647. 0xC0, 0x6F, 0x42, 0x4E, 0xAF, 0x25, 0x38, 0x04,
  25648. 0xD4, 0xCB, 0x46, 0xF4, 0x1F, 0xF2, 0x54, 0xC0,
  25649. 0xC5, 0xBA, 0x48, 0x3B, 0x44, 0xA8, 0x7C, 0x21,
  25650. 0x96, 0x54, 0x55, 0x5E, 0xC7, 0xC1, 0x63, 0xC7,
  25651. 0x9B, 0x9C, 0xB7, 0x60, 0xA2, 0xAD, 0x9B, 0xB7,
  25652. 0x22, 0xB9, 0x3E, 0x0C, 0x28, 0xBD, 0x4B, 0x16,
  25653. 0x85, 0x94, 0x9C, 0x49, 0x6E, 0xAB, 0x1A, 0xFF,
  25654. 0x90, 0x91, 0x9E, 0x37, 0x61, 0xB3, 0x46, 0x83,
  25655. 0x8A, 0xBB, 0x2F, 0x01, 0xA9, 0x1E, 0x55, 0x43,
  25656. 0x75, 0xAF, 0xDA, 0xAA, 0xF3, 0x82, 0x6E, 0x6D,
  25657. 0xB7, 0x9F, 0xE7, 0x35, 0x3A, 0x7A, 0x57, 0x8A,
  25658. 0x7C, 0x05, 0x98, 0xCE, 0x28, 0xB6, 0xD9, 0x91,
  25659. 0x52, 0x14, 0x23, 0x6B, 0xBF, 0xFA, 0x6D, 0x45,
  25660. 0xB6, 0x37, 0x6A, 0x07, 0x92, 0x4A, 0x39, 0xA7,
  25661. 0xBE, 0x81, 0x82, 0x86, 0x71, 0x5C, 0x8A, 0x3C,
  25662. 0x11, 0x0C, 0xD7, 0x6C, 0x02, 0xE0, 0x41, 0x7A,
  25663. 0xF1, 0x38, 0xBD, 0xB9, 0x5C, 0x3C, 0xCA, 0x79,
  25664. 0x8A, 0xC8, 0x09, 0xED, 0x69, 0xCF, 0xB6, 0x72,
  25665. 0xB6, 0xFD, 0xDC, 0x24, 0xD8, 0x9C, 0x06, 0xA6,
  25666. 0x55, 0x88, 0x14, 0xAB, 0x0C, 0x21, 0xC6, 0x2B,
  25667. 0x2F, 0x84, 0xC0, 0xE3, 0xE0, 0x80, 0x3D, 0xB3,
  25668. 0x37, 0xA4, 0xE0, 0xC7, 0x12, 0x7A, 0x6B, 0x4C,
  25669. 0x8C, 0x08, 0xB1, 0xD1, 0xA7, 0x6B, 0xF0, 0x7E,
  25670. 0xB6, 0xE5, 0xB5, 0xBB, 0x47, 0xA1, 0x6C, 0x74,
  25671. 0xBC, 0x54, 0x83, 0x75, 0xFB, 0x29, 0xCD, 0x78,
  25672. 0x9A, 0x5C, 0xFF, 0x91, 0xBD, 0xBD, 0x07, 0x18,
  25673. 0x59, 0xF4, 0x84, 0x6E, 0x35, 0x5B, 0xB0, 0xD2,
  25674. 0x94, 0x84, 0xE2, 0x64, 0xDF, 0xF3, 0x6C, 0x91,
  25675. 0x77, 0xA7, 0xAC, 0xA7, 0x89, 0x08, 0x87, 0x96,
  25676. 0x95, 0xCA, 0x87, 0xF2, 0x54, 0x36, 0xBC, 0x12,
  25677. 0x63, 0x07, 0x24, 0xBB, 0x22, 0xF0, 0xCB, 0x64,
  25678. 0x89, 0x7F, 0xE5, 0xC4, 0x11, 0x95, 0x28, 0x0D,
  25679. 0xA0, 0x41, 0x84, 0xD4, 0xBC, 0x7B, 0x53, 0x2A,
  25680. 0x0F, 0x70, 0xA5, 0x4D, 0x77, 0x57, 0xCD, 0xE6,
  25681. 0x17, 0x5A, 0x68, 0x43, 0xB8, 0x61, 0xCB, 0x2B,
  25682. 0xC4, 0x83, 0x0C, 0x00, 0x12, 0x55, 0x4C, 0xFC,
  25683. 0x5D, 0x2C, 0x8A, 0x20, 0x27, 0xAA, 0x3C, 0xD9,
  25684. 0x67, 0x13, 0x0E, 0x9B, 0x96, 0x24, 0x1B, 0x11,
  25685. 0xC4, 0x32, 0x0C, 0x76, 0x49, 0xCC, 0x23, 0xA7,
  25686. 0x1B, 0xAF, 0xE6, 0x91, 0xAF, 0xC0, 0x8E, 0x68,
  25687. 0x0B, 0xCE, 0xF4, 0x29, 0x07, 0x00, 0x07, 0x18,
  25688. 0xE4, 0xEA, 0xCE, 0x8D, 0xA2, 0x82, 0x14, 0x19,
  25689. 0x7B, 0xE1, 0xC2, 0x69, 0xDA, 0x9C, 0xB5, 0x41,
  25690. 0xE1, 0xA3, 0xCE, 0x97, 0xCF, 0xAD, 0xF9, 0xC6,
  25691. 0x05, 0x87, 0x80, 0xFE, 0x67, 0x93, 0xDB, 0xFA,
  25692. 0x82, 0x18, 0xA2, 0x76, 0x0B, 0x80, 0x2B, 0x8D,
  25693. 0xA2, 0xAA, 0x27, 0x1A, 0x38, 0x77, 0x25, 0x23,
  25694. 0xA7, 0x67, 0x36, 0xA7, 0xA3, 0x1B, 0x9D, 0x30,
  25695. 0x37, 0xAD, 0x21, 0xCE, 0xBB, 0x11, 0xA4, 0x72,
  25696. 0xB8, 0x79, 0x2E, 0xB1, 0x75, 0x58, 0xB9, 0x40,
  25697. 0xE7, 0x08, 0x83, 0xF2, 0x64, 0x59, 0x2C, 0x68,
  25698. 0x9B, 0x24, 0x0B, 0xB4, 0x3D, 0x54, 0x08, 0xBF,
  25699. 0x44, 0x64, 0x32, 0xF4, 0x12, 0xF4, 0xB9, 0xA5,
  25700. 0xF6, 0x86, 0x5C, 0xC2, 0x52, 0xA4, 0x3C, 0xF4,
  25701. 0x0A, 0x32, 0x03, 0x91, 0x55, 0x55, 0x91, 0xD6,
  25702. 0x75, 0x61, 0xFD, 0xD0, 0x53, 0x53, 0xAB, 0x6B,
  25703. 0x01, 0x9B, 0x3A, 0x08, 0xA7, 0x33, 0x53, 0xD5,
  25704. 0x1B, 0x61, 0x13, 0xAB, 0x2F, 0xA5, 0x1D, 0x97,
  25705. 0x56, 0x48, 0xEE, 0x25, 0x4A, 0xF8, 0x9A, 0x23,
  25706. 0x05, 0x04, 0xA2, 0x36, 0xA4, 0x65, 0x82, 0x57,
  25707. 0x74, 0x0B, 0xDC, 0xBB, 0xE1, 0x70, 0x8A, 0xB0,
  25708. 0x22, 0xC3, 0xC5, 0x88, 0xA4, 0x10, 0xDB, 0x3B,
  25709. 0x9C, 0x30, 0x8A, 0x06, 0x27, 0x5B, 0xDF, 0x5B,
  25710. 0x48, 0x59, 0xD3, 0xA2, 0x61, 0x7A, 0x29, 0x5E,
  25711. 0x1A, 0x22, 0xF9, 0x01, 0x98, 0xBA, 0xD0, 0x16,
  25712. 0x6F, 0x4A, 0x94, 0x34, 0x17, 0xC5, 0xB8, 0x31,
  25713. 0x73, 0x6C, 0xB2, 0xC8, 0x58, 0x0A, 0xBF, 0xDE,
  25714. 0x57, 0x14, 0xB5, 0x86, 0xAB, 0xEE, 0xC0, 0xA1,
  25715. 0x75, 0xA0, 0x8B, 0xC7, 0x10, 0xC7, 0xA2, 0x89,
  25716. 0x5D, 0xE9, 0x3A, 0xC4, 0x38, 0x06, 0x1B, 0xF7,
  25717. 0x76, 0x5D, 0x0D, 0x21, 0xCD, 0x41, 0x81, 0x67,
  25718. 0xCA, 0xF8, 0x9D, 0x1E, 0xFC, 0x34, 0x48, 0xBC,
  25719. 0xBB, 0x96, 0xD6, 0x9B, 0x3E, 0x01, 0x0C, 0x82,
  25720. 0xD1, 0x5C, 0xAB, 0x6C, 0xAC, 0xC6, 0x79, 0x9D,
  25721. 0x36, 0x39, 0x66, 0x9A, 0x5B, 0x21, 0xA6, 0x33,
  25722. 0xC8, 0x65, 0xF8, 0x59, 0x3B, 0x5B, 0x7B, 0xC8,
  25723. 0x00, 0x26, 0x2B, 0xB8, 0x37, 0xA9, 0x24, 0xA6,
  25724. 0xC5, 0x44, 0x0E, 0x4F, 0xC7, 0x3B, 0x41, 0xB2,
  25725. 0x30, 0x92, 0xC3, 0x91, 0x2F, 0x4C, 0x6B, 0xEB,
  25726. 0xB4, 0xC7, 0xB4, 0xC6, 0x29, 0x08, 0xB0, 0x37,
  25727. 0x75, 0x66, 0x6C, 0x22, 0x22, 0x0D, 0xF9, 0xC8,
  25728. 0x88, 0x23, 0xE3, 0x44, 0xC7, 0x30, 0x83, 0x32,
  25729. 0x34, 0x5C, 0x8B, 0x79, 0x5D, 0x34, 0xE8, 0xC0,
  25730. 0x51, 0xF2, 0x1F, 0x5A, 0x21, 0xC2, 0x14, 0xB6,
  25731. 0x98, 0x41, 0x35, 0x87, 0x09, 0xB1, 0xC3, 0x05,
  25732. 0xB3, 0x2C, 0xC2, 0xC3, 0x80, 0x6A, 0xE9, 0xCC,
  25733. 0xD3, 0x81, 0x9F, 0xFF, 0x45, 0x07, 0xFE, 0x52,
  25734. 0x0F, 0xBF, 0xC2, 0x71, 0x99, 0xBC, 0x23, 0xBE,
  25735. 0x6B, 0x9B, 0x2D, 0x2A, 0xC1, 0x71, 0x75, 0x79,
  25736. 0xAC, 0x76, 0x92, 0x79, 0xE2, 0xA7, 0xAA, 0xC6,
  25737. 0x8A, 0x37, 0x1A, 0x47, 0xBA, 0x3A, 0x7D, 0xBE,
  25738. 0x01, 0x6F, 0x14, 0xE1, 0xA7, 0x27, 0x33, 0x36,
  25739. 0x63, 0xC4, 0xA5, 0xCD, 0x1A, 0x0F, 0x88, 0x36,
  25740. 0xCF, 0x7B, 0x5C, 0x49, 0xAC, 0x51, 0x48, 0x5C,
  25741. 0xA6, 0x03, 0x45, 0xC9, 0x90, 0xE0, 0x68, 0x88,
  25742. 0x72, 0x00, 0x03, 0x73, 0x13, 0x22, 0xC5, 0xB8,
  25743. 0xCD, 0x5E, 0x69, 0x07, 0xFD, 0xA1, 0x15, 0x7F,
  25744. 0x46, 0x8F, 0xD3, 0xFC, 0x20, 0xFA, 0x81, 0x75,
  25745. 0xEE, 0xC9, 0x5C, 0x29, 0x1A, 0x26, 0x2B, 0xA8,
  25746. 0xC5, 0xBE, 0x99, 0x08, 0x72, 0x41, 0x89, 0x30,
  25747. 0x85, 0x23, 0x39, 0xD8, 0x8A, 0x19, 0xB3, 0x7F,
  25748. 0xEF, 0xA3, 0xCF, 0xE8, 0x21, 0x75, 0xC2, 0x24,
  25749. 0x40, 0x7C, 0xA4, 0x14, 0xBA, 0xEB, 0x37, 0x92,
  25750. 0x3B, 0x4D, 0x2D, 0x83, 0x13, 0x4A, 0xE1, 0x54,
  25751. 0xE4, 0x90, 0xA9, 0xB4, 0x5A, 0x05, 0x63, 0xB0,
  25752. 0x6C, 0x95, 0x3C, 0x33, 0x01, 0x45, 0x0A, 0x21,
  25753. 0x76, 0xA0, 0x7C, 0x61, 0x4A, 0x74, 0xE3, 0x47,
  25754. 0x8E, 0x48, 0x50, 0x9F, 0x9A, 0x60, 0xAE, 0x94,
  25755. 0x5A, 0x8E, 0xBC, 0x78, 0x15, 0x12, 0x1D, 0x90,
  25756. 0xA3, 0xB0, 0xE0, 0x70, 0x91, 0xA0, 0x96, 0xCF,
  25757. 0x02, 0xC5, 0x7B, 0x25, 0xBC, 0xA5, 0x81, 0x26,
  25758. 0xAD, 0x0C, 0x62, 0x9C, 0xE1, 0x66, 0xA7, 0xED,
  25759. 0xB4, 0xB3, 0x32, 0x21, 0xA0, 0xD3, 0xF7, 0x2B,
  25760. 0x85, 0xD5, 0x62, 0xEC, 0x69, 0x8B, 0x7D, 0x0A,
  25761. 0x91, 0x3D, 0x73, 0x80, 0x6F, 0x1C, 0x5C, 0x87,
  25762. 0xB3, 0x8E, 0xC0, 0x03, 0xCB, 0x30, 0x3A, 0x3D,
  25763. 0xC5, 0x1B, 0x4B, 0x35, 0x35, 0x6A, 0x67, 0x82,
  25764. 0x6D, 0x6E, 0xDA, 0xA8, 0xFE, 0xB9, 0x3B, 0x98,
  25765. 0x49, 0x3B, 0x2D, 0x1C, 0x11, 0xB6, 0x76, 0xA6,
  25766. 0xAD, 0x95, 0x06, 0xA1, 0xAA, 0xAE, 0x13, 0xA8,
  25767. 0x24, 0xC7, 0xC0, 0x8D, 0x1C, 0x6C, 0x2C, 0x4D,
  25768. 0xBA, 0x96, 0x42, 0xC7, 0x6E, 0xA7, 0xF6, 0xC8,
  25769. 0x26, 0x4B, 0x64, 0xA2, 0x3C, 0xCC, 0xA9, 0xA7,
  25770. 0x46, 0x35, 0xFC, 0xBF, 0x03, 0xE0, 0x0F, 0x1B,
  25771. 0x57, 0x22, 0xB2, 0x14, 0x37, 0x67, 0x90, 0x79,
  25772. 0x3B, 0x2C, 0x4F, 0x0A, 0x13, 0xB5, 0xC4, 0x07,
  25773. 0x60, 0xB4, 0x21, 0x8E, 0x1D, 0x25, 0x94, 0xDC,
  25774. 0xB3, 0x0A, 0x70, 0xD9, 0xC1, 0x78, 0x2A, 0x5D,
  25775. 0xD3, 0x05, 0x76, 0xFA, 0x41, 0x44, 0xBF, 0xC8,
  25776. 0x41, 0x6E, 0xDA, 0x81, 0x18, 0xFC, 0x64, 0x72,
  25777. 0xF5, 0x6A, 0x97, 0x95, 0x86, 0xF3, 0x3B, 0xB0,
  25778. 0x70, 0xFB, 0x0F, 0x1B, 0x0B, 0x10, 0xBC, 0x48,
  25779. 0x97, 0xEB, 0xE0, 0x1B, 0xCA, 0x38, 0x93, 0xD4,
  25780. 0xE1, 0x6A, 0xDB, 0x25, 0x09, 0x3A, 0x74, 0x17,
  25781. 0xD0, 0x70, 0x8C, 0x83, 0xA2, 0x63, 0x22, 0xE2,
  25782. 0x2E, 0x63, 0x30, 0x09, 0x1E, 0x30, 0x15, 0x2B,
  25783. 0xF8, 0x23, 0x59, 0x7C, 0x04, 0xCC, 0xF4, 0xCF,
  25784. 0xC7, 0x33, 0x15, 0x78, 0xF4, 0x3A, 0x27, 0x26,
  25785. 0xCC, 0xB4, 0x28, 0x28, 0x9A, 0x90, 0xC8, 0x63,
  25786. 0x25, 0x9D, 0xD1, 0x80, 0xC5, 0xFF, 0x14, 0x2B,
  25787. 0xEF, 0x41, 0xC7, 0x71, 0x70, 0x94, 0xBE, 0x07,
  25788. 0x85, 0x6D, 0xA2, 0xB1, 0x40, 0xFA, 0x67, 0x71,
  25789. 0x09, 0x67, 0x35, 0x6A, 0xA4, 0x7D, 0xFB, 0xC8,
  25790. 0xD2, 0x55, 0xB4, 0x72, 0x2A, 0xB8, 0x6D, 0x43,
  25791. 0x9B, 0x7E, 0x0A, 0x60, 0x90, 0x25, 0x1D, 0x2D,
  25792. 0x4C, 0x1E, 0xD5, 0xF2, 0x0B, 0xBE, 0x68, 0x07,
  25793. 0xBF, 0x65, 0xA9, 0x0B, 0x7C, 0xB2, 0xEC, 0x01,
  25794. 0x02, 0xAF, 0x02, 0x80, 0x9D, 0xC9, 0xAC, 0x7D,
  25795. 0x0A, 0x3A, 0xBC, 0x69, 0xC1, 0x83, 0x65, 0xBC,
  25796. 0xFF, 0x59, 0x18, 0x5F, 0x33, 0x99, 0x68, 0x87,
  25797. 0x74, 0x61, 0x85, 0x90, 0x6C, 0x01, 0x91, 0xAE,
  25798. 0xD4, 0x40, 0x7E, 0x13, 0x94, 0x46, 0x45, 0x9B,
  25799. 0xE2, 0x9C, 0x68, 0x22, 0x71, 0x76, 0x44, 0x35,
  25800. 0x3D, 0x24, 0xAB, 0x63, 0x39, 0x15, 0x6A, 0x9C,
  25801. 0x42, 0x49, 0x09, 0xF0, 0xA9, 0x02, 0x5B, 0xB7,
  25802. 0x47, 0x20, 0x77, 0x9B, 0xE4, 0x3F, 0x16, 0xD8,
  25803. 0x1C, 0x8C, 0xC6, 0x66, 0xE9, 0x97, 0x10, 0xD8,
  25804. 0xC6, 0x8B, 0xB5, 0xCC, 0x4E, 0x12, 0xF3, 0x14,
  25805. 0xE9, 0x25, 0xA5, 0x51, 0xF0, 0x9C, 0xC5, 0x90,
  25806. 0x03, 0xA1, 0xF8, 0x81, 0x03, 0xC2, 0x54, 0xBB,
  25807. 0x97, 0x8D, 0x75, 0xF3, 0x94, 0xD3, 0x54, 0x0E,
  25808. 0x31, 0xE7, 0x71, 0xCD, 0xA3, 0x6E, 0x39, 0xEC,
  25809. 0x54, 0xA6, 0x2B, 0x58, 0x32, 0x66, 0x4D, 0x82,
  25810. 0x1A, 0x72, 0xF1, 0xE6, 0xAF, 0xBB, 0xA2, 0x7F,
  25811. 0x84, 0x29, 0x5B, 0x26, 0x94, 0xC4, 0x98, 0x49,
  25812. 0x8E, 0x81, 0x2B, 0xC8, 0xE9, 0x37, 0x8F, 0xE5,
  25813. 0x41, 0xCE, 0xC5, 0x89, 0x1B, 0x25, 0x06, 0x29,
  25814. 0x01, 0xCB, 0x72, 0x12, 0xE3, 0xCD, 0xC4, 0x61,
  25815. 0x79, 0xEC, 0x5B, 0xCE, 0xC1, 0x0B, 0xC0, 0xB9,
  25816. 0x31, 0x1D, 0xE0, 0x50, 0x74, 0x29, 0x06, 0x87,
  25817. 0xFD, 0x6A, 0x53, 0x92, 0x67, 0x16, 0x54, 0x28,
  25818. 0x4C, 0xD9, 0xC8, 0xCC, 0x3E, 0xBA, 0x80, 0xEB,
  25819. 0x3B, 0x66, 0x2E, 0xB5, 0x3E, 0xB7, 0x51, 0x16,
  25820. 0x70, 0x4A, 0x1F, 0xEB, 0x5C, 0x2D, 0x05, 0x63,
  25821. 0x38, 0x53, 0x28, 0x68, 0xDD, 0xF2, 0x4E, 0xB8,
  25822. 0x99, 0x2A, 0xB8, 0x56, 0x5D, 0x9E, 0x49, 0x0C,
  25823. 0xAD, 0xF1, 0x48, 0x04, 0x36, 0x0D, 0xAA, 0x90,
  25824. 0x71, 0x8E, 0xAB, 0x61, 0x6B, 0xAB, 0x07, 0x65,
  25825. 0xD3, 0x39, 0x87, 0xB4, 0x7E, 0xFB, 0x65, 0x99,
  25826. 0xC5, 0x56, 0x32, 0x35, 0xE6, 0x1E, 0x4B, 0xE6,
  25827. 0x70, 0xE9, 0x79, 0x55, 0xAB, 0x29, 0x2D, 0x97,
  25828. 0x32, 0xCB, 0x89, 0x30, 0x94, 0x8A, 0xC8, 0x2D,
  25829. 0xF2, 0x30, 0xAC, 0x72, 0x29, 0x7A, 0x23, 0x67,
  25830. 0x9D, 0x6B, 0x94, 0xC1, 0x7F, 0x13, 0x59, 0x48,
  25831. 0x32, 0x54, 0xFE, 0xDC, 0x2F, 0x05, 0x81, 0x9F,
  25832. 0x0D, 0x06, 0x9A, 0x44, 0x3B, 0x78, 0xE3, 0xFC,
  25833. 0x6C, 0x3E, 0xF4, 0x71, 0x4B, 0x05, 0xA3, 0xFC,
  25834. 0xA8, 0x1C, 0xBB, 0xA6, 0x02, 0x42, 0xA7, 0x06,
  25835. 0x0C, 0xD8, 0x85, 0xD8, 0xF3, 0x99, 0x81, 0xBB,
  25836. 0x18, 0x09, 0x2B, 0x23, 0xDA, 0xA5, 0x9F, 0xD9,
  25837. 0x57, 0x83, 0x88, 0x68, 0x8A, 0x09, 0xBB, 0xA0,
  25838. 0x79, 0xBC, 0x80, 0x9A, 0x54, 0x84, 0x3A, 0x60,
  25839. 0x38, 0x5E, 0x23, 0x10, 0xBB, 0xCB, 0xCC, 0x02,
  25840. 0x13, 0xCE, 0x3D, 0xFA, 0xAB, 0x33, 0xB4, 0x7F,
  25841. 0x9D, 0x63, 0x05, 0xBC, 0x95, 0xC6, 0x10, 0x78,
  25842. 0x13, 0xC5, 0x85, 0xC4, 0xB6, 0x57, 0xBF, 0x30,
  25843. 0x54, 0x28, 0x33, 0xB1, 0x49, 0x49, 0xF5, 0x73,
  25844. 0xC0, 0x61, 0x2A, 0xD5, 0x24, 0xBA, 0xAE, 0x69,
  25845. 0x59, 0x0C, 0x12, 0x77, 0xB8, 0x6C, 0x28, 0x65,
  25846. 0x71, 0xBF, 0x66, 0xB3, 0xCF, 0xF4, 0x6A, 0x38,
  25847. 0x58, 0xC0, 0x99, 0x06, 0xA7, 0x94, 0xDF, 0x4A,
  25848. 0x06, 0xE9, 0xD4, 0xB0, 0xA2, 0xE4, 0x3F, 0x10,
  25849. 0xF7, 0x2A, 0x6C, 0x6C, 0x47, 0xE5, 0x64, 0x6E,
  25850. 0x2C, 0x79, 0x9B, 0x71, 0xC3, 0x3E, 0xD2, 0xF0,
  25851. 0x1E, 0xEB, 0x45, 0x93, 0x8E, 0xB7, 0xA4, 0xE2,
  25852. 0xE2, 0x90, 0x8C, 0x53, 0x55, 0x8A, 0x54, 0x0D,
  25853. 0x35, 0x03, 0x69, 0xFA, 0x18, 0x9C, 0x61, 0x69,
  25854. 0x43, 0xF7, 0x98, 0x1D, 0x76, 0x18, 0xCF, 0x02,
  25855. 0xA5, 0xB0, 0xA2, 0xBC, 0xC4, 0x22, 0xE8, 0x57,
  25856. 0xD1, 0xA4, 0x78, 0x71, 0x25, 0x3D, 0x08, 0x29,
  25857. 0x3C, 0x1C, 0x17, 0x9B, 0xCD, 0xC0, 0x43, 0x70,
  25858. 0x69, 0x10, 0x74, 0x18, 0x20, 0x5F, 0xDB, 0x98,
  25859. 0x56, 0x62, 0x3B, 0x8C, 0xA6, 0xB6, 0x94, 0xC9,
  25860. 0x6C, 0x08, 0x4B, 0x17, 0xF1, 0x3B, 0xB6, 0xDF,
  25861. 0x12, 0xB2, 0xCF, 0xBB, 0xC2, 0xB0, 0xE0, 0xC3,
  25862. 0x4B, 0x00, 0xD0, 0xFC, 0xD0, 0xAE, 0xCF, 0xB2,
  25863. 0x79, 0x24, 0xF6, 0x98, 0x4E, 0x74, 0x7B, 0xE2,
  25864. 0xA0, 0x9D, 0x83, 0xA8, 0x66, 0x45, 0x90, 0xA8,
  25865. 0x07, 0x73, 0x31, 0x49, 0x1A, 0x4F, 0x7D, 0x72,
  25866. 0x08, 0x43, 0xF2, 0x3E, 0x65, 0x2C, 0x6F, 0xA8,
  25867. 0x40, 0x30, 0x8D, 0xB4, 0x02, 0x03, 0x37, 0xAA,
  25868. 0xD3, 0x79, 0x67, 0x03, 0x4A, 0x9F, 0xB5, 0x23,
  25869. 0xB6, 0x7C, 0xA7, 0x03, 0x30, 0xF0, 0x2D, 0x9E,
  25870. 0xA2, 0x0C, 0x1E, 0x84, 0xCB, 0x8E, 0x57, 0x57,
  25871. 0xC9, 0xE1, 0x89, 0x6B, 0x60, 0x58, 0x14, 0x41,
  25872. 0xED, 0x61, 0x8A, 0xA5, 0xB2, 0x6D, 0xA5, 0x6C,
  25873. 0x0A, 0x5A, 0x73, 0xC4, 0xDC, 0xFD, 0x75, 0x5E,
  25874. 0x61, 0x0B, 0x4F, 0xC8, 0x1F, 0xF8, 0x4E, 0x21,
  25875. 0xD2, 0xE5, 0x74, 0xDF, 0xD8, 0xCD, 0x0A, 0xE8,
  25876. 0x93, 0xAA, 0x7E, 0x12, 0x5B, 0x44, 0xB9, 0x24,
  25877. 0xF4, 0x52, 0x23, 0xEC, 0x09, 0xF2, 0xAD, 0x11,
  25878. 0x41, 0xEA, 0x93, 0xA6, 0x80, 0x50, 0xDB, 0xF6,
  25879. 0x99, 0xE3, 0x24, 0x68, 0x84, 0x18, 0x1F, 0x8E,
  25880. 0x1D, 0xD4, 0x4E, 0x0C, 0x76, 0x29, 0x09, 0x33,
  25881. 0x30, 0x22, 0x1F, 0xD6, 0x7D, 0x9B, 0x7D, 0x6E,
  25882. 0x15, 0x10, 0xB2, 0xDB, 0xAD, 0x87, 0x62, 0xF7
  25883. };
  25884. #endif
  25885. static byte pubKey[KYBER_MAX_PUBLIC_KEY_SIZE];
  25886. static byte privKey[KYBER_MAX_PRIVATE_KEY_SIZE];
  25887. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  25888. ExpectNotNull(key);
  25889. if (key != NULL) {
  25890. XMEMSET(key, 0, sizeof(KyberKey));
  25891. }
  25892. #ifndef WOLFSSL_NO_KYBER512
  25893. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  25894. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_512, sizeof(seed_512)),
  25895. 0);
  25896. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  25897. KYBER512_PUBLIC_KEY_SIZE), 0);
  25898. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  25899. KYBER512_PRIVATE_KEY_SIZE), 0);
  25900. ExpectIntEQ(XMEMCMP(pubKey, ek_512, KYBER512_PUBLIC_KEY_SIZE), 0);
  25901. ExpectIntEQ(XMEMCMP(privKey, dk_512, KYBER512_PRIVATE_KEY_SIZE), 0);
  25902. wc_KyberKey_Free(key);
  25903. #endif
  25904. #ifndef WOLFSSL_NO_KYBER768
  25905. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  25906. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_768, sizeof(seed_768)),
  25907. 0);
  25908. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  25909. KYBER768_PUBLIC_KEY_SIZE), 0);
  25910. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  25911. KYBER768_PRIVATE_KEY_SIZE), 0);
  25912. ExpectIntEQ(XMEMCMP(pubKey, ek_768, KYBER768_PUBLIC_KEY_SIZE), 0);
  25913. ExpectIntEQ(XMEMCMP(privKey, dk_768, KYBER768_PRIVATE_KEY_SIZE), 0);
  25914. wc_KyberKey_Free(key);
  25915. #endif
  25916. #ifndef WOLFSSL_NO_KYBER1024
  25917. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  25918. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_1024,
  25919. sizeof(seed_1024)), 0);
  25920. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  25921. KYBER1024_PUBLIC_KEY_SIZE), 0);
  25922. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  25923. KYBER1024_PRIVATE_KEY_SIZE), 0);
  25924. ExpectIntEQ(XMEMCMP(pubKey, ek_1024, KYBER1024_PUBLIC_KEY_SIZE), 0);
  25925. ExpectIntEQ(XMEMCMP(privKey, dk_1024, KYBER1024_PRIVATE_KEY_SIZE), 0);
  25926. wc_KyberKey_Free(key);
  25927. #endif
  25928. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  25929. #endif
  25930. return EXPECT_RESULT();
  25931. }
  25932. static int test_wc_kyber_encapsulate_kats(void)
  25933. {
  25934. EXPECT_DECLS;
  25935. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  25936. !defined(WOLFSSL_KYBER_ORIGINAL)
  25937. KyberKey* key;
  25938. #ifndef WOLFSSL_NO_KYBER512
  25939. static const byte ek_512[KYBER512_PUBLIC_KEY_SIZE] = {
  25940. 0xDD, 0x19, 0x24, 0x93, 0x5A, 0xA8, 0xE6, 0x17,
  25941. 0xAF, 0x18, 0xB5, 0xA0, 0x65, 0xAC, 0x45, 0x72,
  25942. 0x77, 0x67, 0xEE, 0x89, 0x7C, 0xF4, 0xF9, 0x44,
  25943. 0x2B, 0x2A, 0xCE, 0x30, 0xC0, 0x23, 0x7B, 0x30,
  25944. 0x7D, 0x3E, 0x76, 0xBF, 0x8E, 0xEB, 0x78, 0xAD,
  25945. 0xDC, 0x4A, 0xAC, 0xD1, 0x64, 0x63, 0xD8, 0x60,
  25946. 0x2F, 0xD5, 0x48, 0x7B, 0x63, 0xC8, 0x8B, 0xB6,
  25947. 0x60, 0x27, 0xF3, 0x7D, 0x0D, 0x61, 0x4D, 0x6F,
  25948. 0x9C, 0x24, 0x60, 0x3C, 0x42, 0x94, 0x76, 0x64,
  25949. 0xAC, 0x43, 0x98, 0xC6, 0xC5, 0x23, 0x83, 0x46,
  25950. 0x9B, 0x4F, 0x97, 0x77, 0xE5, 0xEC, 0x72, 0x06,
  25951. 0x21, 0x0F, 0x3E, 0x5A, 0x79, 0x6B, 0xF4, 0x5C,
  25952. 0x53, 0x26, 0x8E, 0x25, 0xF3, 0x9A, 0xC2, 0x61,
  25953. 0xAF, 0x3B, 0xFA, 0x2E, 0xE7, 0x55, 0xBE, 0xB8,
  25954. 0xB6, 0x7A, 0xB3, 0xAC, 0x8D, 0xF6, 0xC6, 0x29,
  25955. 0xC1, 0x17, 0x6E, 0x9E, 0x3B, 0x96, 0x5E, 0x93,
  25956. 0x69, 0xF9, 0xB3, 0xB9, 0x2A, 0xD7, 0xC2, 0x09,
  25957. 0x55, 0x64, 0x1D, 0x99, 0x52, 0x6F, 0xE7, 0xB9,
  25958. 0xFE, 0x8C, 0x85, 0x08, 0x20, 0x27, 0x5C, 0xD9,
  25959. 0x64, 0x84, 0x92, 0x50, 0x09, 0x07, 0x33, 0xCE,
  25960. 0x12, 0x4E, 0xCF, 0x31, 0x66, 0x24, 0x37, 0x4B,
  25961. 0xD1, 0x8B, 0x7C, 0x35, 0x8C, 0x06, 0xE9, 0xC1,
  25962. 0x36, 0xEE, 0x12, 0x59, 0xA9, 0x24, 0x5A, 0xBC,
  25963. 0x55, 0xB9, 0x64, 0xD6, 0x89, 0xF5, 0xA0, 0x82,
  25964. 0x92, 0xD2, 0x82, 0x65, 0x65, 0x8E, 0xBB, 0x40,
  25965. 0xCB, 0xFE, 0x48, 0x8A, 0x22, 0x28, 0x27, 0x55,
  25966. 0x90, 0xAB, 0x9F, 0x32, 0xA3, 0x41, 0x09, 0x70,
  25967. 0x9C, 0x1C, 0x29, 0x1D, 0x4A, 0x23, 0x33, 0x72,
  25968. 0x74, 0xC7, 0xA5, 0xA5, 0x99, 0x1C, 0x7A, 0x87,
  25969. 0xB8, 0x1C, 0x97, 0x4A, 0xB1, 0x8C, 0xE7, 0x78,
  25970. 0x59, 0xE4, 0x99, 0x5E, 0x7C, 0x14, 0xF0, 0x37,
  25971. 0x17, 0x48, 0xB7, 0x71, 0x2F, 0xB5, 0x2C, 0x59,
  25972. 0x66, 0xCD, 0x63, 0x06, 0x3C, 0x4F, 0x3B, 0x81,
  25973. 0xB4, 0x7C, 0x45, 0xDD, 0xE8, 0x3F, 0xB3, 0xA2,
  25974. 0x72, 0x40, 0x29, 0xB1, 0x0B, 0x32, 0x30, 0x21,
  25975. 0x4C, 0x04, 0xFA, 0x05, 0x77, 0xFC, 0x29, 0xAC,
  25976. 0x90, 0x86, 0xAE, 0x18, 0xC5, 0x3B, 0x3E, 0xD4,
  25977. 0x4E, 0x50, 0x74, 0x12, 0xFC, 0xA0, 0x4B, 0x4F,
  25978. 0x53, 0x8A, 0x51, 0x58, 0x8E, 0xC1, 0xF1, 0x02,
  25979. 0x9D, 0x15, 0x2D, 0x9A, 0xE7, 0x73, 0x5F, 0x76,
  25980. 0xA0, 0x77, 0xAA, 0x94, 0x84, 0x38, 0x0A, 0xED,
  25981. 0x91, 0x89, 0xE5, 0x91, 0x24, 0x87, 0xFC, 0xC5,
  25982. 0xB7, 0xC7, 0x01, 0x2D, 0x92, 0x23, 0xDD, 0x96,
  25983. 0x7E, 0xEC, 0xDA, 0xC3, 0x00, 0x8A, 0x89, 0x31,
  25984. 0xB6, 0x48, 0x24, 0x35, 0x37, 0xF5, 0x48, 0xC1,
  25985. 0x71, 0x69, 0x8C, 0x5B, 0x38, 0x1D, 0x84, 0x6A,
  25986. 0x72, 0xE5, 0xC9, 0x2D, 0x42, 0x26, 0xC5, 0xA8,
  25987. 0x90, 0x98, 0x84, 0xF1, 0xC4, 0xA3, 0x40, 0x4C,
  25988. 0x17, 0x20, 0xA5, 0x27, 0x94, 0x14, 0xD7, 0xF2,
  25989. 0x7B, 0x2B, 0x98, 0x26, 0x52, 0xB6, 0x74, 0x02,
  25990. 0x19, 0xC5, 0x6D, 0x21, 0x77, 0x80, 0xD7, 0xA5,
  25991. 0xE5, 0xBA, 0x59, 0x83, 0x63, 0x49, 0xF7, 0x26,
  25992. 0x88, 0x1D, 0xEA, 0x18, 0xEF, 0x75, 0xC0, 0x77,
  25993. 0x2A, 0x8B, 0x92, 0x27, 0x66, 0x95, 0x37, 0x18,
  25994. 0xCA, 0xCC, 0x14, 0xCC, 0xBA, 0xCB, 0x5F, 0xC4,
  25995. 0x12, 0xA2, 0xD0, 0xBE, 0x52, 0x18, 0x17, 0x64,
  25996. 0x5A, 0xB2, 0xBF, 0x6A, 0x47, 0x85, 0xE9, 0x2B,
  25997. 0xC9, 0x4C, 0xAF, 0x47, 0x7A, 0x96, 0x78, 0x76,
  25998. 0x79, 0x6C, 0x0A, 0x51, 0x90, 0x31, 0x5A, 0xC0,
  25999. 0x88, 0x56, 0x71, 0xA4, 0xC7, 0x49, 0x56, 0x4C,
  26000. 0x3B, 0x2C, 0x7A, 0xED, 0x90, 0x64, 0xEB, 0xA2,
  26001. 0x99, 0xEF, 0x21, 0x4B, 0xA2, 0xF4, 0x04, 0x93,
  26002. 0x66, 0x7C, 0x8B, 0xD0, 0x32, 0xAE, 0xC5, 0x62,
  26003. 0x17, 0x11, 0xB4, 0x1A, 0x38, 0x52, 0xC5, 0xC2,
  26004. 0xBA, 0xB4, 0xA3, 0x49, 0xCE, 0x4B, 0x7F, 0x08,
  26005. 0x5A, 0x81, 0x2B, 0xBB, 0xC8, 0x20, 0xB8, 0x1B,
  26006. 0xEF, 0xE6, 0x3A, 0x05, 0xB8, 0xBC, 0xDF, 0xE9,
  26007. 0xC2, 0xA7, 0x0A, 0x8B, 0x1A, 0xCA, 0x9B, 0xF9,
  26008. 0x81, 0x64, 0x81, 0x90, 0x7F, 0xF4, 0x43, 0x24,
  26009. 0x61, 0x11, 0x12, 0x87, 0x30, 0x3F, 0x0B, 0xD8,
  26010. 0x17, 0xC0, 0x57, 0x26, 0xBF, 0xA1, 0x8A, 0x2E,
  26011. 0x24, 0xC7, 0x72, 0x49, 0x21, 0x02, 0x80, 0x32,
  26012. 0xF6, 0x22, 0xBD, 0x96, 0x0A, 0x31, 0x7D, 0x83,
  26013. 0xB3, 0x56, 0xB5, 0x7F, 0x4A, 0x80, 0x04, 0x49,
  26014. 0x9C, 0xBC, 0x73, 0xC9, 0x7D, 0x1E, 0xB7, 0x74,
  26015. 0x59, 0x72, 0x63, 0x1C, 0x05, 0x61, 0xC1, 0xA3,
  26016. 0xAB, 0x6E, 0xF9, 0x1B, 0xD3, 0x63, 0x28, 0x0A,
  26017. 0x10, 0x54, 0x5D, 0xA6, 0x93, 0xE6, 0xD5, 0x8A,
  26018. 0xED, 0x68, 0x45, 0xE7, 0xCC, 0x5F, 0x0D, 0x08,
  26019. 0xCA, 0x79, 0x05, 0x05, 0x2C, 0x77, 0x36, 0x6D,
  26020. 0x19, 0x72, 0xCC, 0xFC, 0xC1, 0xA2, 0x76, 0x10,
  26021. 0xCB, 0x54, 0x36, 0x65, 0xAA, 0x79, 0x8E, 0x20,
  26022. 0x94, 0x01, 0x28, 0xB9, 0x56, 0x7A, 0x7E, 0xDB,
  26023. 0x7A, 0x90, 0x04, 0x07, 0xC7, 0x0D, 0x35, 0x94,
  26024. 0x38, 0x43, 0x5E, 0x13, 0x96, 0x16, 0x08, 0xD5,
  26025. 0x52, 0xA9, 0x4C, 0x5C, 0xDA, 0x78, 0x59, 0x22,
  26026. 0x05, 0x09, 0xB4, 0x83, 0xC5, 0xC5, 0x2A, 0x21,
  26027. 0x0E, 0x9C, 0x81, 0x2B, 0xC0, 0xC2, 0x32, 0x8C,
  26028. 0xA0, 0x0E, 0x78, 0x9A, 0x56, 0xB2, 0x60, 0x6B,
  26029. 0x90, 0x29, 0x2E, 0x35, 0x43, 0xDA, 0xCA, 0xA2,
  26030. 0x43, 0x18, 0x41, 0xD6, 0x1A, 0x22, 0xCA, 0x90,
  26031. 0xC1, 0xCC, 0xF0, 0xB5, 0xB4, 0xE0, 0xA6, 0xF6,
  26032. 0x40, 0x53, 0x6D, 0x1A, 0x26, 0xAB, 0x5B, 0x8D,
  26033. 0x21, 0x51, 0x32, 0x79, 0x28, 0xCE, 0x02, 0x90,
  26034. 0x4C, 0xF1, 0xD1, 0x5E, 0x32, 0x78, 0x8A, 0x95,
  26035. 0xF6, 0x2D, 0x3C, 0x27, 0x0B, 0x6F, 0xA1, 0x50,
  26036. 0x8F, 0x97, 0xB9, 0x15, 0x5A, 0x27, 0x26, 0xD8,
  26037. 0x0A, 0x1A, 0xFA, 0x3C, 0x53, 0x87, 0xA2, 0x76,
  26038. 0xA4, 0xD0, 0x31, 0xA0, 0x8A, 0xBF, 0x4F, 0x2E,
  26039. 0x74, 0xF1, 0xA0, 0xBB, 0x8A, 0x0F, 0xD3, 0xCB
  26040. };
  26041. static const byte seed_512[KYBER_ENC_RAND_SZ] = {
  26042. 0x6F, 0xF0, 0x2E, 0x1D, 0xC7, 0xFD, 0x91, 0x1B,
  26043. 0xEE, 0xE0, 0xC6, 0x92, 0xC8, 0xBD, 0x10, 0x0C,
  26044. 0x3E, 0x5C, 0x48, 0x96, 0x4D, 0x31, 0xDF, 0x92,
  26045. 0x99, 0x42, 0x18, 0xE8, 0x06, 0x64, 0xA6, 0xCA
  26046. };
  26047. static const byte c_512[KYBER512_CIPHER_TEXT_SIZE] = {
  26048. 0x19, 0xC5, 0x92, 0x50, 0x59, 0x07, 0xC2, 0x4C,
  26049. 0x5F, 0xA2, 0xEB, 0xFA, 0x93, 0x2D, 0x2C, 0xBB,
  26050. 0x48, 0xF3, 0xE4, 0x34, 0x0A, 0x28, 0xF7, 0xEB,
  26051. 0xA5, 0xD0, 0x68, 0xFC, 0xAC, 0xAB, 0xED, 0xF7,
  26052. 0x77, 0x84, 0xE2, 0xB2, 0x4D, 0x79, 0x61, 0x77,
  26053. 0x5F, 0x0B, 0xF1, 0xA9, 0x97, 0xAE, 0x8B, 0xA9,
  26054. 0xFC, 0x43, 0x11, 0xBE, 0x63, 0x71, 0x67, 0x79,
  26055. 0xC2, 0xB7, 0x88, 0xF8, 0x12, 0xCB, 0xB7, 0x8C,
  26056. 0x74, 0xE7, 0x51, 0x7E, 0x22, 0xE9, 0x10, 0xEF,
  26057. 0xF5, 0xF3, 0x8D, 0x44, 0x46, 0x9C, 0x50, 0xDE,
  26058. 0x16, 0x75, 0xAE, 0x19, 0x8F, 0xD6, 0xA2, 0x89,
  26059. 0xAE, 0x7E, 0x6C, 0x30, 0xA9, 0xD4, 0x35, 0x1B,
  26060. 0x3D, 0x1F, 0x4C, 0x36, 0xEF, 0xF9, 0xC6, 0x8D,
  26061. 0xA9, 0x1C, 0x40, 0xB8, 0x2D, 0xC9, 0xB2, 0x79,
  26062. 0x9A, 0x33, 0xA2, 0x6B, 0x60, 0xA4, 0xE7, 0x0D,
  26063. 0x71, 0x01, 0x86, 0x27, 0x79, 0x46, 0x9F, 0x3A,
  26064. 0x9D, 0xAE, 0xC8, 0xE3, 0xE8, 0xF8, 0xC6, 0xA1,
  26065. 0x6B, 0xF0, 0x92, 0xFB, 0xA5, 0x86, 0x61, 0x86,
  26066. 0xB8, 0xD2, 0x08, 0xFD, 0xEB, 0x27, 0x4A, 0xC1,
  26067. 0xF8, 0x29, 0x65, 0x9D, 0xC2, 0xBE, 0x4A, 0xC4,
  26068. 0xF3, 0x06, 0xCB, 0x55, 0x84, 0xBA, 0xD1, 0x93,
  26069. 0x6A, 0x92, 0xC9, 0xB7, 0x68, 0x19, 0x23, 0x42,
  26070. 0x81, 0xBB, 0x39, 0x58, 0x41, 0xC2, 0x57, 0x56,
  26071. 0x08, 0x6E, 0xA5, 0x64, 0xCA, 0x3E, 0x22, 0x7E,
  26072. 0x3D, 0x9F, 0x10, 0x52, 0xC0, 0x76, 0x6D, 0x2E,
  26073. 0xB7, 0x9A, 0x47, 0xC1, 0x50, 0x72, 0x1E, 0x0D,
  26074. 0xEA, 0x7C, 0x00, 0x69, 0xD5, 0x51, 0xB2, 0x64,
  26075. 0x80, 0x1B, 0x77, 0x27, 0xEC, 0xAF, 0x82, 0xEE,
  26076. 0xCB, 0x99, 0xA8, 0x76, 0xFD, 0xA0, 0x90, 0xBF,
  26077. 0x6C, 0x3F, 0xC6, 0xB1, 0x09, 0xF1, 0x70, 0x14,
  26078. 0x85, 0xF0, 0x3C, 0xE6, 0x62, 0x74, 0xB8, 0x43,
  26079. 0x5B, 0x0A, 0x01, 0x4C, 0xFB, 0x3E, 0x79, 0xCC,
  26080. 0xED, 0x67, 0x05, 0x7B, 0x5A, 0xE2, 0xAD, 0x7F,
  26081. 0x52, 0x79, 0xEB, 0x71, 0x49, 0x42, 0xE4, 0xC1,
  26082. 0xCC, 0xFF, 0x7E, 0x85, 0xC0, 0xDB, 0x43, 0xE5,
  26083. 0xD4, 0x12, 0x89, 0x20, 0x73, 0x63, 0xB4, 0x44,
  26084. 0xBB, 0x51, 0xBB, 0x8A, 0xB0, 0x37, 0x1E, 0x70,
  26085. 0xCB, 0xD5, 0x5F, 0x0F, 0x3D, 0xAD, 0x40, 0x3E,
  26086. 0x10, 0x51, 0x76, 0xE3, 0xE8, 0xA2, 0x25, 0xD8,
  26087. 0x4A, 0xC8, 0xBE, 0xE3, 0x8C, 0x82, 0x1E, 0xE0,
  26088. 0xF5, 0x47, 0x43, 0x11, 0x45, 0xDC, 0xB3, 0x13,
  26089. 0x92, 0x86, 0xAB, 0xB1, 0x17, 0x94, 0xA4, 0x3A,
  26090. 0x3C, 0x1B, 0x52, 0x29, 0xE4, 0xBC, 0xFE, 0x95,
  26091. 0x9C, 0x78, 0xAD, 0xAE, 0xE2, 0xD5, 0xF2, 0x49,
  26092. 0x7B, 0x5D, 0x24, 0xBC, 0x21, 0xFA, 0x03, 0xA9,
  26093. 0xA5, 0x8C, 0x24, 0x55, 0x37, 0x3E, 0xC8, 0x95,
  26094. 0x83, 0xE7, 0xE5, 0x88, 0xD7, 0xFE, 0x67, 0x99,
  26095. 0x1E, 0xE9, 0x37, 0x83, 0xED, 0x4A, 0x6F, 0x9E,
  26096. 0xEA, 0xE0, 0x4E, 0x64, 0xE2, 0xE1, 0xE0, 0xE6,
  26097. 0x99, 0xF6, 0xDC, 0x9C, 0x5D, 0x39, 0xEF, 0x92,
  26098. 0x78, 0xC9, 0x85, 0xE7, 0xFD, 0xF2, 0xA7, 0x64,
  26099. 0xFF, 0xD1, 0xA0, 0xB9, 0x57, 0x92, 0xAD, 0x68,
  26100. 0x1E, 0x93, 0x0D, 0x76, 0xDF, 0x4E, 0xFE, 0x5D,
  26101. 0x65, 0xDB, 0xBD, 0x0F, 0x14, 0x38, 0x48, 0x1E,
  26102. 0xD8, 0x33, 0xAD, 0x49, 0x46, 0xAD, 0x1C, 0x69,
  26103. 0xAD, 0x21, 0xDD, 0x7C, 0x86, 0x18, 0x57, 0x74,
  26104. 0x42, 0x6F, 0x3F, 0xCF, 0x53, 0xB5, 0x2A, 0xD4,
  26105. 0xB4, 0x0D, 0x22, 0x8C, 0xE1, 0x24, 0x07, 0x2F,
  26106. 0x59, 0x2C, 0x7D, 0xAA, 0x05, 0x7F, 0x17, 0xD7,
  26107. 0x90, 0xA5, 0xBD, 0x5B, 0x93, 0x83, 0x4D, 0x58,
  26108. 0xC0, 0x8C, 0x88, 0xDC, 0x8F, 0x0E, 0xF4, 0x88,
  26109. 0x15, 0x64, 0x25, 0xB7, 0x44, 0x65, 0x4E, 0xAC,
  26110. 0xA9, 0xD6, 0x48, 0x58, 0xA4, 0xD6, 0xCE, 0xB4,
  26111. 0x78, 0x79, 0x51, 0x94, 0xBF, 0xAD, 0xB1, 0x8D,
  26112. 0xC0, 0xEA, 0x05, 0x4F, 0x97, 0x71, 0x21, 0x5A,
  26113. 0xD3, 0xCB, 0x1F, 0xD0, 0x31, 0xD7, 0xBE, 0x45,
  26114. 0x98, 0x62, 0x19, 0x26, 0x47, 0x8D, 0x37, 0x5A,
  26115. 0x18, 0x45, 0xAA, 0x91, 0xD7, 0xC7, 0x33, 0xF8,
  26116. 0xF0, 0xE1, 0x88, 0xC8, 0x38, 0x96, 0xED, 0xF8,
  26117. 0x3B, 0x86, 0x46, 0xC9, 0x9E, 0x29, 0xC0, 0xDA,
  26118. 0x22, 0x90, 0xE7, 0x1C, 0x3D, 0x2E, 0x97, 0x07,
  26119. 0x20, 0xC9, 0x7B, 0x5B, 0x7F, 0x95, 0x04, 0x86,
  26120. 0x03, 0x3C, 0x6A, 0x25, 0x71, 0xDD, 0xF2, 0xBC,
  26121. 0xCD, 0xAB, 0xB2, 0xDF, 0xA5, 0xFC, 0xE4, 0xC3,
  26122. 0xA1, 0x88, 0x46, 0x06, 0x04, 0x1D, 0x18, 0x1C,
  26123. 0x72, 0x87, 0x94, 0xAE, 0x0E, 0x80, 0x6E, 0xCB,
  26124. 0x49, 0xAF, 0x16, 0x75, 0x6A, 0x4C, 0xE7, 0x3C,
  26125. 0x87, 0xBD, 0x42, 0x34, 0xE6, 0x0F, 0x05, 0x53,
  26126. 0x5F, 0xA5, 0x92, 0x9F, 0xD5, 0xA3, 0x44, 0x73,
  26127. 0x26, 0x64, 0x01, 0xF6, 0x3B, 0xBD, 0x6B, 0x90,
  26128. 0xE0, 0x03, 0x47, 0x2A, 0xC0, 0xCE, 0x88, 0xF1,
  26129. 0xB6, 0x66, 0x59, 0x72, 0x79, 0xD0, 0x56, 0xA6,
  26130. 0x32, 0xC8, 0xD6, 0xB7, 0x90, 0xFD, 0x41, 0x17,
  26131. 0x67, 0x84, 0x8A, 0x69, 0xE3, 0x7A, 0x8A, 0x83,
  26132. 0x9B, 0xC7, 0x66, 0xA0, 0x2C, 0xA2, 0xF6, 0x95,
  26133. 0xEC, 0x63, 0xF0, 0x56, 0xA4, 0xE2, 0xA1, 0x14,
  26134. 0xCA, 0xCF, 0x9F, 0xD9, 0x0D, 0x73, 0x0C, 0x97,
  26135. 0x0D, 0xB3, 0x87, 0xF6, 0xDE, 0x73, 0x39, 0x5F,
  26136. 0x70, 0x1A, 0x1D, 0x95, 0x3B, 0x2A, 0x89, 0xDD,
  26137. 0x7E, 0xDA, 0xD4, 0x39, 0xFC, 0x20, 0x5A, 0x54,
  26138. 0xA4, 0x81, 0xE8, 0x89, 0xB0, 0x98, 0xD5, 0x25,
  26139. 0x56, 0x70, 0xF0, 0x26, 0xB4, 0xA2, 0xBF, 0x02,
  26140. 0xD2, 0xBD, 0xDE, 0x87, 0xC7, 0x66, 0xB2, 0x5F,
  26141. 0xC5, 0xE0, 0xFD, 0x45, 0x37, 0x57, 0xE7, 0x56,
  26142. 0xD1, 0x8C, 0x8C, 0xD9, 0x12, 0xF9, 0xA7, 0x7F,
  26143. 0x8E, 0x6B, 0xF0, 0x20, 0x53, 0x74, 0xB4, 0x62
  26144. };
  26145. static const byte k_512[KYBER_SS_SZ] = {
  26146. 0x0B, 0xF3, 0x23, 0x33, 0x8D, 0x6F, 0x0A, 0x21,
  26147. 0xD5, 0x51, 0x4B, 0x67, 0x3C, 0xD1, 0x0B, 0x71,
  26148. 0x4C, 0xE6, 0xE3, 0x6F, 0x35, 0xBC, 0xD1, 0xBF,
  26149. 0x54, 0x41, 0x96, 0x36, 0x8E, 0xE5, 0x1A, 0x13
  26150. };
  26151. #endif
  26152. #ifndef WOLFSSL_NO_KYBER768
  26153. static const byte ek_768[KYBER768_PUBLIC_KEY_SIZE] = {
  26154. 0x89, 0xD2, 0xCB, 0x65, 0xF9, 0x4D, 0xCB, 0xFC,
  26155. 0x89, 0x0E, 0xFC, 0x7D, 0x0E, 0x5A, 0x7A, 0x38,
  26156. 0x34, 0x4D, 0x16, 0x41, 0xA3, 0xD0, 0xB0, 0x24,
  26157. 0xD5, 0x07, 0x97, 0xA5, 0xF2, 0x3C, 0x3A, 0x18,
  26158. 0xB3, 0x10, 0x1A, 0x12, 0x69, 0x06, 0x9F, 0x43,
  26159. 0xA8, 0x42, 0xBA, 0xCC, 0x09, 0x8A, 0x88, 0x21,
  26160. 0x27, 0x1C, 0x67, 0x3D, 0xB1, 0xBE, 0xB3, 0x30,
  26161. 0x34, 0xE4, 0xD7, 0x77, 0x4D, 0x16, 0x63, 0x5C,
  26162. 0x7C, 0x2C, 0x3C, 0x27, 0x63, 0x45, 0x35, 0x38,
  26163. 0xBC, 0x16, 0x32, 0xE1, 0x85, 0x15, 0x91, 0xA5,
  26164. 0x16, 0x42, 0x97, 0x4E, 0x59, 0x28, 0xAB, 0xB8,
  26165. 0xE5, 0x5F, 0xE5, 0x56, 0x12, 0xF9, 0xB1, 0x41,
  26166. 0xAF, 0xF0, 0x15, 0x54, 0x53, 0x94, 0xB2, 0x09,
  26167. 0x2E, 0x59, 0x09, 0x70, 0xEC, 0x29, 0xA7, 0xB7,
  26168. 0xE7, 0xAA, 0x1F, 0xB4, 0x49, 0x3B, 0xF7, 0xCB,
  26169. 0x73, 0x19, 0x06, 0xC2, 0xA5, 0xCB, 0x49, 0xE6,
  26170. 0x61, 0x48, 0x59, 0x06, 0x4E, 0x19, 0xB8, 0xFA,
  26171. 0x26, 0xAF, 0x51, 0xC4, 0x4B, 0x5E, 0x75, 0x35,
  26172. 0xBF, 0xDA, 0xC0, 0x72, 0xB6, 0x46, 0xD3, 0xEA,
  26173. 0x49, 0x0D, 0x27, 0x7F, 0x0D, 0x97, 0xCE, 0xD4,
  26174. 0x73, 0x95, 0xFE, 0xD9, 0x1E, 0x8F, 0x2B, 0xCE,
  26175. 0x0E, 0x3C, 0xA1, 0x22, 0xC2, 0x02, 0x5F, 0x74,
  26176. 0x06, 0x7A, 0xB9, 0x28, 0xA8, 0x22, 0xB3, 0x56,
  26177. 0x53, 0xA7, 0x4F, 0x06, 0x75, 0x76, 0x29, 0xAF,
  26178. 0xB1, 0xA1, 0xCA, 0xF2, 0x37, 0x10, 0x0E, 0xA9,
  26179. 0x35, 0xE7, 0x93, 0xC8, 0xF5, 0x8A, 0x71, 0xB3,
  26180. 0xD6, 0xAE, 0x2C, 0x86, 0x58, 0xB1, 0x01, 0x50,
  26181. 0xD4, 0xA3, 0x8F, 0x57, 0x2A, 0x0D, 0x49, 0xD2,
  26182. 0x8A, 0xE8, 0x94, 0x51, 0xD3, 0x38, 0x32, 0x6F,
  26183. 0xDB, 0x3B, 0x43, 0x50, 0x03, 0x6C, 0x10, 0x81,
  26184. 0x11, 0x77, 0x40, 0xED, 0xB8, 0x6B, 0x12, 0x08,
  26185. 0x1C, 0x5C, 0x12, 0x23, 0xDB, 0xB5, 0x66, 0x0D,
  26186. 0x5B, 0x3C, 0xB3, 0x78, 0x7D, 0x48, 0x18, 0x49,
  26187. 0x30, 0x4C, 0x68, 0xBE, 0x87, 0x54, 0x66, 0xF1,
  26188. 0x4E, 0xE5, 0x49, 0x5C, 0x2B, 0xD7, 0x95, 0xAE,
  26189. 0x41, 0x2D, 0x09, 0x00, 0x2D, 0x65, 0xB8, 0x71,
  26190. 0x9B, 0x90, 0xCB, 0xA3, 0x60, 0x3A, 0xC4, 0x95,
  26191. 0x8E, 0xA0, 0x3C, 0xC1, 0x38, 0xC8, 0x6F, 0x78,
  26192. 0x51, 0x59, 0x31, 0x25, 0x33, 0x47, 0x01, 0xB6,
  26193. 0x77, 0xF8, 0x2F, 0x49, 0x52, 0xA4, 0xC9, 0x3B,
  26194. 0x5B, 0x4C, 0x13, 0x4B, 0xB4, 0x2A, 0x85, 0x7F,
  26195. 0xD1, 0x5C, 0x65, 0x08, 0x64, 0xA6, 0xAA, 0x94,
  26196. 0xEB, 0x69, 0x1C, 0x0B, 0x69, 0x1B, 0xE4, 0x68,
  26197. 0x4C, 0x1F, 0x5B, 0x74, 0x90, 0x46, 0x7F, 0xC0,
  26198. 0x1B, 0x1D, 0x1F, 0xDA, 0x4D, 0xDA, 0x35, 0xC4,
  26199. 0xEC, 0xC2, 0x31, 0xBC, 0x73, 0xA6, 0xFE, 0xF4,
  26200. 0x2C, 0x99, 0xD3, 0x4E, 0xB8, 0x2A, 0x4D, 0x01,
  26201. 0x49, 0x87, 0xB3, 0xE3, 0x86, 0x91, 0x0C, 0x62,
  26202. 0x67, 0x9A, 0x11, 0x8F, 0x3C, 0x5B, 0xD9, 0xF4,
  26203. 0x67, 0xE4, 0x16, 0x20, 0x42, 0x42, 0x43, 0x57,
  26204. 0xDB, 0x92, 0xEF, 0x48, 0x4A, 0x4A, 0x17, 0x98,
  26205. 0xC1, 0x25, 0x7E, 0x87, 0x0A, 0x30, 0xCB, 0x20,
  26206. 0xAA, 0xA0, 0x33, 0x5D, 0x83, 0x31, 0x4F, 0xE0,
  26207. 0xAA, 0x7E, 0x63, 0xA8, 0x62, 0x64, 0x80, 0x41,
  26208. 0xA7, 0x2A, 0x63, 0x21, 0x52, 0x32, 0x20, 0xB1,
  26209. 0xAC, 0xE9, 0xBB, 0x70, 0x1B, 0x21, 0xAC, 0x12,
  26210. 0x53, 0xCB, 0x81, 0x2C, 0x15, 0x57, 0x5A, 0x90,
  26211. 0x85, 0xEA, 0xBE, 0xAD, 0xE7, 0x3A, 0x4A, 0xE7,
  26212. 0x6E, 0x6A, 0x7B, 0x15, 0x8A, 0x20, 0x58, 0x6D,
  26213. 0x78, 0xA5, 0xAC, 0x62, 0x0A, 0x5C, 0x9A, 0xBC,
  26214. 0xC9, 0xC0, 0x43, 0x35, 0x0A, 0x73, 0x65, 0x6B,
  26215. 0x0A, 0xBE, 0x82, 0x2D, 0xA5, 0xE0, 0xBA, 0x76,
  26216. 0x04, 0x5F, 0xAD, 0x75, 0x40, 0x1D, 0x7A, 0x3B,
  26217. 0x70, 0x37, 0x91, 0xB7, 0xE9, 0x92, 0x61, 0x71,
  26218. 0x0F, 0x86, 0xB7, 0x24, 0x21, 0xD2, 0x40, 0xA3,
  26219. 0x47, 0x63, 0x83, 0x77, 0x20, 0x5A, 0x15, 0x2C,
  26220. 0x79, 0x41, 0x30, 0xA4, 0xE0, 0x47, 0x74, 0x2B,
  26221. 0x88, 0x83, 0x03, 0xBD, 0xDC, 0x30, 0x91, 0x16,
  26222. 0x76, 0x4D, 0xE7, 0x42, 0x4C, 0xEB, 0xEA, 0x6D,
  26223. 0xB6, 0x53, 0x48, 0xAC, 0x53, 0x7E, 0x01, 0xA9,
  26224. 0xCC, 0x56, 0xEA, 0x66, 0x7D, 0x5A, 0xA8, 0x7A,
  26225. 0xC9, 0xAA, 0xA4, 0x31, 0x7D, 0x26, 0x2C, 0x10,
  26226. 0x14, 0x30, 0x50, 0xB8, 0xD0, 0x7A, 0x72, 0x8C,
  26227. 0xA6, 0x33, 0xC1, 0x3E, 0x46, 0x8A, 0xBC, 0xEA,
  26228. 0xD3, 0x72, 0xC7, 0x7B, 0x8E, 0xCF, 0x3B, 0x98,
  26229. 0x6B, 0x98, 0xC1, 0xE5, 0x58, 0x60, 0xB2, 0xB4,
  26230. 0x21, 0x67, 0x66, 0xAD, 0x87, 0x4C, 0x35, 0xED,
  26231. 0x72, 0x05, 0x06, 0x87, 0x39, 0x23, 0x02, 0x20,
  26232. 0xB5, 0xA2, 0x31, 0x7D, 0x10, 0x2C, 0x59, 0x83,
  26233. 0x56, 0xF1, 0x68, 0xAC, 0xBE, 0x80, 0x60, 0x8D,
  26234. 0xE4, 0xC9, 0xA7, 0x10, 0xB8, 0xDD, 0x07, 0x07,
  26235. 0x8C, 0xD7, 0xC6, 0x71, 0x05, 0x8A, 0xF1, 0xB0,
  26236. 0xB8, 0x30, 0x4A, 0x31, 0x4F, 0x7B, 0x29, 0xBE,
  26237. 0x78, 0xA9, 0x33, 0xC7, 0xB9, 0x29, 0x44, 0x24,
  26238. 0x95, 0x4A, 0x1B, 0xF8, 0xBC, 0x74, 0x5D, 0xE8,
  26239. 0x61, 0x98, 0x65, 0x9E, 0x0E, 0x12, 0x25, 0xA9,
  26240. 0x10, 0x72, 0x60, 0x74, 0x96, 0x9C, 0x39, 0xA9,
  26241. 0x7C, 0x19, 0x24, 0x06, 0x01, 0xA4, 0x6E, 0x01,
  26242. 0x3D, 0xCD, 0xCB, 0x67, 0x7A, 0x8C, 0xBD, 0x2C,
  26243. 0x95, 0xA4, 0x06, 0x29, 0xC2, 0x56, 0xF2, 0x4A,
  26244. 0x32, 0x89, 0x51, 0xDF, 0x57, 0x50, 0x2A, 0xB3,
  26245. 0x07, 0x72, 0xCC, 0x7E, 0x5B, 0x85, 0x00, 0x27,
  26246. 0xC8, 0x55, 0x17, 0x81, 0xCE, 0x49, 0x85, 0xBD,
  26247. 0xAC, 0xF6, 0xB8, 0x65, 0xC1, 0x04, 0xE8, 0xA4,
  26248. 0xBC, 0x65, 0xC4, 0x16, 0x94, 0xD4, 0x56, 0xB7,
  26249. 0x16, 0x9E, 0x45, 0xAB, 0x3D, 0x7A, 0xCA, 0xBE,
  26250. 0xAF, 0xE2, 0x3A, 0xD6, 0xA7, 0xB9, 0x4D, 0x19,
  26251. 0x79, 0xA2, 0xF4, 0xC1, 0xCA, 0xE7, 0xCD, 0x77,
  26252. 0xD6, 0x81, 0xD2, 0x90, 0xB5, 0xD8, 0xE4, 0x51,
  26253. 0xBF, 0xDC, 0xCC, 0xF5, 0x31, 0x0B, 0x9D, 0x12,
  26254. 0xA8, 0x8E, 0xC2, 0x9B, 0x10, 0x25, 0x5D, 0x5E,
  26255. 0x17, 0xA1, 0x92, 0x67, 0x0A, 0xA9, 0x73, 0x1C,
  26256. 0x5C, 0xA6, 0x7E, 0xC7, 0x84, 0xC5, 0x02, 0x78,
  26257. 0x1B, 0xE8, 0x52, 0x7D, 0x6F, 0xC0, 0x03, 0xC6,
  26258. 0x70, 0x1B, 0x36, 0x32, 0x28, 0x4B, 0x40, 0x30,
  26259. 0x7A, 0x52, 0x7C, 0x76, 0x20, 0x37, 0x7F, 0xEB,
  26260. 0x0B, 0x73, 0xF7, 0x22, 0xC9, 0xE3, 0xCD, 0x4D,
  26261. 0xEC, 0x64, 0x87, 0x6B, 0x93, 0xAB, 0x5B, 0x7C,
  26262. 0xFC, 0x4A, 0x65, 0x7F, 0x85, 0x2B, 0x65, 0x92,
  26263. 0x82, 0x86, 0x43, 0x84, 0xF4, 0x42, 0xB2, 0x2E,
  26264. 0x8A, 0x21, 0x10, 0x93, 0x87, 0xB8, 0xB4, 0x75,
  26265. 0x85, 0xFC, 0x68, 0x0D, 0x0B, 0xA4, 0x5C, 0x7A,
  26266. 0x8B, 0x1D, 0x72, 0x74, 0xBD, 0xA5, 0x78, 0x45,
  26267. 0xD1, 0x00, 0xD0, 0xF4, 0x2A, 0x3B, 0x74, 0x62,
  26268. 0x87, 0x73, 0x35, 0x1F, 0xD7, 0xAC, 0x30, 0x5B,
  26269. 0x24, 0x97, 0x63, 0x9B, 0xE9, 0x0B, 0x3F, 0x4F,
  26270. 0x71, 0xA6, 0xAA, 0x35, 0x61, 0xEE, 0xCC, 0x6A,
  26271. 0x69, 0x1B, 0xB5, 0xCB, 0x39, 0x14, 0xD8, 0x63,
  26272. 0x4C, 0xA1, 0xE1, 0xAF, 0x54, 0x3C, 0x04, 0x9A,
  26273. 0x8C, 0x6E, 0x86, 0x8C, 0x51, 0xF0, 0x42, 0x3B,
  26274. 0xD2, 0xD5, 0xAE, 0x09, 0xB7, 0x9E, 0x57, 0xC2,
  26275. 0x7F, 0x3F, 0xE3, 0xAE, 0x2B, 0x26, 0xA4, 0x41,
  26276. 0xBA, 0xBF, 0xC6, 0x71, 0x8C, 0xE8, 0xC0, 0x5B,
  26277. 0x4F, 0xE7, 0x93, 0xB9, 0x10, 0xB8, 0xFB, 0xCB,
  26278. 0xBE, 0x7F, 0x10, 0x13, 0x24, 0x2B, 0x40, 0xE0,
  26279. 0x51, 0x4D, 0x0B, 0xDC, 0x5C, 0x88, 0xBA, 0xC5,
  26280. 0x94, 0xC7, 0x94, 0xCE, 0x51, 0x22, 0xFB, 0xF3,
  26281. 0x48, 0x96, 0x81, 0x91, 0x47, 0xB9, 0x28, 0x38,
  26282. 0x15, 0x87, 0x96, 0x3B, 0x0B, 0x90, 0x03, 0x4A,
  26283. 0xA0, 0x7A, 0x10, 0xBE, 0x17, 0x6E, 0x01, 0xC8,
  26284. 0x0A, 0xD6, 0xA4, 0xB7, 0x1B, 0x10, 0xAF, 0x42,
  26285. 0x41, 0x40, 0x0A, 0x2A, 0x4C, 0xBB, 0xC0, 0x59,
  26286. 0x61, 0xA1, 0x5E, 0xC1, 0x47, 0x4E, 0xD5, 0x1A,
  26287. 0x3C, 0xC6, 0xD3, 0x58, 0x00, 0x67, 0x9A, 0x46,
  26288. 0x28, 0x09, 0xCA, 0xA3, 0xAB, 0x4F, 0x70, 0x94,
  26289. 0xCD, 0x66, 0x10, 0xB4, 0xA7, 0x00, 0xCB, 0xA9,
  26290. 0x39, 0xE7, 0xEA, 0xC9, 0x3E, 0x38, 0xC9, 0x97,
  26291. 0x55, 0x90, 0x87, 0x27, 0x61, 0x9E, 0xD7, 0x6A,
  26292. 0x34, 0xE5, 0x3C, 0x4F, 0xA2, 0x5B, 0xFC, 0x97,
  26293. 0x00, 0x82, 0x06, 0x69, 0x7D, 0xD1, 0x45, 0xE5,
  26294. 0xB9, 0x18, 0x8E, 0x5B, 0x01, 0x4E, 0x94, 0x16,
  26295. 0x81, 0xE1, 0x5F, 0xE3, 0xE1, 0x32, 0xB8, 0xA3,
  26296. 0x90, 0x34, 0x74, 0x14, 0x8B, 0xA2, 0x8B, 0x98,
  26297. 0x71, 0x11, 0xC9, 0xBC, 0xB3, 0x98, 0x9B, 0xBB,
  26298. 0xC6, 0x71, 0xC5, 0x81, 0xB4, 0x4A, 0x49, 0x28,
  26299. 0x45, 0xF2, 0x88, 0xE6, 0x21, 0x96, 0xE4, 0x71,
  26300. 0xFE, 0xD3, 0xC3, 0x9C, 0x1B, 0xBD, 0xDB, 0x08,
  26301. 0x37, 0xD0, 0xD4, 0x70, 0x6B, 0x09, 0x22, 0xC4
  26302. };
  26303. static const byte seed_768[KYBER_ENC_RAND_SZ] = {
  26304. 0x2C, 0xE7, 0x4A, 0xD2, 0x91, 0x13, 0x35, 0x18,
  26305. 0xFE, 0x60, 0xC7, 0xDF, 0x5D, 0x25, 0x1B, 0x9D,
  26306. 0x82, 0xAD, 0xD4, 0x84, 0x62, 0xFF, 0x50, 0x5C,
  26307. 0x6E, 0x54, 0x7E, 0x94, 0x9E, 0x6B, 0x6B, 0xF7
  26308. };
  26309. static const byte c_768[KYBER768_CIPHER_TEXT_SIZE] = {
  26310. 0x56, 0xB4, 0x2D, 0x59, 0x3A, 0xAB, 0x8E, 0x87,
  26311. 0x73, 0xBD, 0x92, 0xD7, 0x6E, 0xAB, 0xDD, 0xF3,
  26312. 0xB1, 0x54, 0x6F, 0x83, 0x26, 0xF5, 0x7A, 0x7B,
  26313. 0x77, 0x37, 0x64, 0xB6, 0xC0, 0xDD, 0x30, 0x47,
  26314. 0x0F, 0x68, 0xDF, 0xF8, 0x2E, 0x0D, 0xCA, 0x92,
  26315. 0x50, 0x92, 0x74, 0xEC, 0xFE, 0x83, 0xA9, 0x54,
  26316. 0x73, 0x5F, 0xDE, 0x6E, 0x14, 0x67, 0x6D, 0xAA,
  26317. 0xA3, 0x68, 0x0C, 0x30, 0xD5, 0x24, 0xF4, 0xEF,
  26318. 0xA7, 0x9E, 0xD6, 0xA1, 0xF9, 0xED, 0x7E, 0x1C,
  26319. 0x00, 0x56, 0x0E, 0x86, 0x83, 0x53, 0x8C, 0x31,
  26320. 0x05, 0xAB, 0x93, 0x1B, 0xE0, 0xD2, 0xB2, 0x49,
  26321. 0xB3, 0x8C, 0xB9, 0xB1, 0x3A, 0xF5, 0xCE, 0xAF,
  26322. 0x78, 0x87, 0xA5, 0x9D, 0xBA, 0x16, 0x68, 0x8A,
  26323. 0x7F, 0x28, 0xDE, 0x0B, 0x14, 0xD1, 0x9F, 0x39,
  26324. 0x1E, 0xB4, 0x18, 0x32, 0xA5, 0x64, 0x79, 0x41,
  26325. 0x6C, 0xCF, 0x94, 0xE9, 0x97, 0x39, 0x0E, 0xD7,
  26326. 0x87, 0x8E, 0xEA, 0xFF, 0x49, 0x32, 0x8A, 0x70,
  26327. 0xE0, 0xAB, 0x5F, 0xCE, 0x6C, 0x63, 0xC0, 0x9B,
  26328. 0x35, 0xF4, 0xE4, 0x59, 0x94, 0xDE, 0x61, 0x5B,
  26329. 0x88, 0xBB, 0x72, 0x2F, 0x70, 0xE8, 0x7D, 0x2B,
  26330. 0xBD, 0x72, 0xAE, 0x71, 0xE1, 0xEE, 0x90, 0x08,
  26331. 0xE4, 0x59, 0xD8, 0xE7, 0x43, 0x03, 0x9A, 0x8D,
  26332. 0xDE, 0xB8, 0x74, 0xFC, 0xE5, 0x30, 0x1A, 0x2F,
  26333. 0x8C, 0x0E, 0xE8, 0xC2, 0xFE, 0xE7, 0xA4, 0xEE,
  26334. 0x68, 0xB5, 0xED, 0x6A, 0x6D, 0x9A, 0xB7, 0x4F,
  26335. 0x98, 0xBB, 0x3B, 0xA0, 0xFE, 0x89, 0xE8, 0x2B,
  26336. 0xD5, 0xA5, 0x25, 0xC5, 0xE8, 0x79, 0x0F, 0x81,
  26337. 0x8C, 0xCC, 0x60, 0x58, 0x77, 0xD4, 0x6C, 0x8B,
  26338. 0xDB, 0x5C, 0x33, 0x7B, 0x02, 0x5B, 0xB8, 0x40,
  26339. 0xFF, 0x47, 0x18, 0x96, 0xE4, 0x3B, 0xFA, 0x99,
  26340. 0xD7, 0x3D, 0xBE, 0x31, 0x80, 0x5C, 0x27, 0xA4,
  26341. 0x3E, 0x57, 0xF0, 0x61, 0x8B, 0x3A, 0xE5, 0x22,
  26342. 0xA4, 0x64, 0x4E, 0x0D, 0x4E, 0x4C, 0x1C, 0x54,
  26343. 0x84, 0x89, 0x43, 0x1B, 0xE5, 0x58, 0xF3, 0xBF,
  26344. 0xC5, 0x0E, 0x16, 0x61, 0x7E, 0x11, 0x0D, 0xD7,
  26345. 0xAF, 0x9A, 0x6F, 0xD8, 0x3E, 0x3F, 0xBB, 0x68,
  26346. 0xC3, 0x04, 0xD1, 0x5F, 0x6C, 0xB7, 0x00, 0xD6,
  26347. 0x1D, 0x7A, 0xA9, 0x15, 0xA6, 0x75, 0x1E, 0xA3,
  26348. 0xBA, 0x80, 0x22, 0x3E, 0x65, 0x41, 0x32, 0xA2,
  26349. 0x09, 0x99, 0xA4, 0x3B, 0xF4, 0x08, 0x59, 0x27,
  26350. 0x30, 0xB9, 0xA9, 0x49, 0x96, 0x36, 0xC0, 0x9F,
  26351. 0xA7, 0x29, 0xF9, 0xCB, 0x1F, 0x9D, 0x34, 0x42,
  26352. 0xF4, 0x73, 0x57, 0xA2, 0xB9, 0xCF, 0x15, 0xD3,
  26353. 0x10, 0x3B, 0x9B, 0xF3, 0x96, 0xC2, 0x30, 0x88,
  26354. 0xF1, 0x18, 0xED, 0xE3, 0x46, 0xB5, 0xC0, 0x38,
  26355. 0x91, 0xCF, 0xA5, 0xD5, 0x17, 0xCE, 0xF8, 0x47,
  26356. 0x13, 0x22, 0xE7, 0xE3, 0x10, 0x87, 0xC4, 0xB0,
  26357. 0x36, 0xAB, 0xAD, 0x78, 0x4B, 0xFF, 0x72, 0xA9,
  26358. 0xB1, 0x1F, 0xA1, 0x98, 0xFA, 0xCB, 0xCB, 0x91,
  26359. 0xF0, 0x67, 0xFE, 0xAF, 0x76, 0xFC, 0xFE, 0x53,
  26360. 0x27, 0xC1, 0x07, 0x0B, 0x3D, 0xA6, 0x98, 0x84,
  26361. 0x00, 0x75, 0x67, 0x60, 0xD2, 0xD1, 0xF0, 0x60,
  26362. 0x29, 0x8F, 0x16, 0x83, 0xD5, 0x1E, 0x36, 0x16,
  26363. 0xE9, 0x8C, 0x51, 0xC9, 0xC0, 0x3A, 0xA4, 0x2F,
  26364. 0x2E, 0x63, 0x36, 0x51, 0xA4, 0x7A, 0xD3, 0xCC,
  26365. 0x2A, 0xB4, 0xA8, 0x52, 0xAE, 0x0C, 0x4B, 0x04,
  26366. 0xB4, 0xE1, 0xC3, 0xDD, 0x94, 0x44, 0x45, 0xA2,
  26367. 0xB1, 0x2B, 0x4F, 0x42, 0xA6, 0x43, 0x51, 0x05,
  26368. 0xC0, 0x41, 0x22, 0xFC, 0x35, 0x87, 0xAF, 0xE4,
  26369. 0x09, 0xA0, 0x0B, 0x30, 0x8D, 0x63, 0xC5, 0xDD,
  26370. 0x81, 0x63, 0x65, 0x45, 0x04, 0xEE, 0xDB, 0xB7,
  26371. 0xB5, 0x32, 0x95, 0x77, 0xC3, 0x5F, 0xBE, 0xB3,
  26372. 0xF4, 0x63, 0x87, 0x2C, 0xAC, 0x28, 0x14, 0x2B,
  26373. 0x3C, 0x12, 0xA7, 0x40, 0xEC, 0x6E, 0xA7, 0xCE,
  26374. 0x9A, 0xD7, 0x8C, 0x6F, 0xC8, 0xFE, 0x1B, 0x4D,
  26375. 0xF5, 0xFC, 0x55, 0xC1, 0x66, 0x7F, 0x31, 0xF2,
  26376. 0x31, 0x2D, 0xA0, 0x77, 0x99, 0xDC, 0x87, 0x0A,
  26377. 0x47, 0x86, 0x08, 0x54, 0x9F, 0xED, 0xAF, 0xE0,
  26378. 0x21, 0xF1, 0xCF, 0x29, 0x84, 0x18, 0x03, 0x64,
  26379. 0xE9, 0x0A, 0xD9, 0x8D, 0x84, 0x56, 0x52, 0xAA,
  26380. 0x3C, 0xDD, 0x7A, 0x8E, 0xB0, 0x9F, 0x5E, 0x51,
  26381. 0x42, 0x3F, 0xAB, 0x42, 0xA7, 0xB7, 0xBB, 0x4D,
  26382. 0x51, 0x48, 0x64, 0xBE, 0x8D, 0x71, 0x29, 0x7E,
  26383. 0x9C, 0x3B, 0x17, 0xA9, 0x93, 0xF0, 0xAE, 0x62,
  26384. 0xE8, 0xEF, 0x52, 0x63, 0x7B, 0xD1, 0xB8, 0x85,
  26385. 0xBD, 0x9B, 0x6A, 0xB7, 0x27, 0x85, 0x4D, 0x70,
  26386. 0x3D, 0x8D, 0xC4, 0x78, 0xF9, 0x6C, 0xB8, 0x1F,
  26387. 0xCE, 0x4C, 0x60, 0x38, 0x3A, 0xC0, 0x1F, 0xCF,
  26388. 0x0F, 0x97, 0x1D, 0x4C, 0x8F, 0x35, 0x2B, 0x7A,
  26389. 0x82, 0xE2, 0x18, 0x65, 0x2F, 0x2C, 0x10, 0x6C,
  26390. 0xA9, 0x2A, 0xE6, 0x86, 0xBA, 0xCF, 0xCE, 0xF5,
  26391. 0xD3, 0x27, 0x34, 0x7A, 0x97, 0xA9, 0xB3, 0x75,
  26392. 0xD6, 0x73, 0x41, 0x55, 0x2B, 0xC2, 0xC5, 0x38,
  26393. 0x77, 0x8E, 0x0F, 0x98, 0x01, 0x82, 0x3C, 0xCD,
  26394. 0xFC, 0xD1, 0xEA, 0xAD, 0xED, 0x55, 0xB1, 0x8C,
  26395. 0x97, 0x57, 0xE3, 0xF2, 0x12, 0xB2, 0x88, 0x9D,
  26396. 0x38, 0x57, 0xDB, 0x51, 0xF9, 0x81, 0xD1, 0x61,
  26397. 0x85, 0xFD, 0x0F, 0x90, 0x08, 0x53, 0xA7, 0x50,
  26398. 0x05, 0xE3, 0x02, 0x0A, 0x8B, 0x95, 0xB7, 0xD8,
  26399. 0xF2, 0xF2, 0x63, 0x1C, 0x70, 0xD7, 0x8A, 0x95,
  26400. 0x7C, 0x7A, 0x62, 0xE1, 0xB3, 0x71, 0x90, 0x70,
  26401. 0xAC, 0xD1, 0xFD, 0x48, 0x0C, 0x25, 0xB8, 0x38,
  26402. 0x47, 0xDA, 0x02, 0x7B, 0x6E, 0xBB, 0xC2, 0xEE,
  26403. 0xC2, 0xDF, 0x22, 0xC8, 0x7F, 0x9B, 0x46, 0xD5,
  26404. 0xD7, 0xBA, 0xF1, 0x56, 0xB5, 0x3C, 0xEE, 0x92,
  26405. 0x95, 0x72, 0xB9, 0x2C, 0x47, 0x84, 0xC4, 0xE8,
  26406. 0x29, 0xF3, 0x44, 0x6A, 0x1F, 0xFE, 0x47, 0xF9,
  26407. 0x9D, 0xEC, 0xD0, 0x43, 0x60, 0x29, 0xDD, 0xEB,
  26408. 0xD3, 0xED, 0x8E, 0x87, 0xE5, 0xE7, 0x3D, 0x12,
  26409. 0x3D, 0xBE, 0x8A, 0x4D, 0xDA, 0xCF, 0x2A, 0xBD,
  26410. 0xE8, 0x7F, 0x33, 0xAE, 0x2B, 0x62, 0x1C, 0x0E,
  26411. 0xC5, 0xD5, 0xCA, 0xD1, 0x25, 0x9D, 0xEE, 0xC2,
  26412. 0xAE, 0xFF, 0x60, 0x88, 0xF0, 0x4F, 0x27, 0xA2,
  26413. 0x03, 0x38, 0xB5, 0x76, 0x25, 0x43, 0xE5, 0x10,
  26414. 0x08, 0x99, 0xA4, 0xCB, 0xFB, 0x7B, 0x3C, 0xA4,
  26415. 0x56, 0xB3, 0xA1, 0x9B, 0x83, 0xA4, 0xC4, 0x32,
  26416. 0x23, 0x0C, 0x23, 0xE1, 0xC7, 0xF1, 0x07, 0xC4,
  26417. 0xCB, 0x11, 0x21, 0x52, 0xF1, 0xC0, 0xF3, 0x0D,
  26418. 0xA0, 0xBB, 0x33, 0xF4, 0xF1, 0x1F, 0x47, 0xEE,
  26419. 0xA4, 0x38, 0x72, 0xBA, 0xFA, 0x84, 0xAE, 0x22,
  26420. 0x25, 0x6D, 0x70, 0x8E, 0x06, 0x04, 0xDA, 0xDE,
  26421. 0x4B, 0x2A, 0x4D, 0xDE, 0x8C, 0xCC, 0xF1, 0x19,
  26422. 0x30, 0xE1, 0x35, 0x53, 0x93, 0x4A, 0xE3, 0xEC,
  26423. 0xE5, 0x2F, 0x3D, 0x7C, 0xCC, 0x00, 0x28, 0x73,
  26424. 0x77, 0x87, 0x9F, 0xE6, 0xB8, 0xEC, 0xE7, 0xEF,
  26425. 0x79, 0x42, 0x35, 0x07, 0xC9, 0xDA, 0x33, 0x95,
  26426. 0x59, 0xC2, 0x0D, 0xE1, 0xC5, 0x19, 0x55, 0x99,
  26427. 0x9B, 0xAE, 0x47, 0x40, 0x1D, 0xC3, 0xCD, 0xFA,
  26428. 0xA1, 0xB2, 0x56, 0xD0, 0x9C, 0x7D, 0xB9, 0xFC,
  26429. 0x86, 0x98, 0xBF, 0xCE, 0xFA, 0x73, 0x02, 0xD5,
  26430. 0x6F, 0xBC, 0xDE, 0x1F, 0xBA, 0xAA, 0x1C, 0x65,
  26431. 0x34, 0x54, 0xE6, 0xFD, 0x3D, 0x84, 0xE4, 0xF7,
  26432. 0x9A, 0x93, 0x1C, 0x68, 0x1C, 0xBB, 0x6C, 0xB4,
  26433. 0x62, 0xB1, 0x0D, 0xAE, 0x11, 0x2B, 0xDF, 0xB7,
  26434. 0xF6, 0x5C, 0x7F, 0xDF, 0x6E, 0x5F, 0xC5, 0x94,
  26435. 0xEC, 0x3A, 0x47, 0x4A, 0x94, 0xBD, 0x97, 0xE6,
  26436. 0xEC, 0x81, 0xF7, 0x1C, 0x23, 0x0B, 0xF7, 0x0C,
  26437. 0xA0, 0xF1, 0x3C, 0xE3, 0xDF, 0xFB, 0xD9, 0xFF,
  26438. 0x98, 0x04, 0xEF, 0xD8, 0xF3, 0x7A, 0x4D, 0x36,
  26439. 0x29, 0xB4, 0x3A, 0x8F, 0x55, 0x54, 0x4E, 0xBC,
  26440. 0x5A, 0xC0, 0xAB, 0xD9, 0xA3, 0x3D, 0x79, 0x69,
  26441. 0x90, 0x68, 0x34, 0x6A, 0x0F, 0x1A, 0x3A, 0x96,
  26442. 0xE1, 0x15, 0xA5, 0xD8, 0x0B, 0xE1, 0x65, 0xB5,
  26443. 0x62, 0xD0, 0x82, 0x98, 0x4D, 0x5A, 0xAC, 0xC3,
  26444. 0xA2, 0x30, 0x19, 0x81, 0xA6, 0x41, 0x8F, 0x8B,
  26445. 0xA7, 0xD7, 0xB0, 0xD7, 0xCA, 0x58, 0x75, 0xC6
  26446. };
  26447. static const byte k_768[KYBER_SS_SZ] = {
  26448. 0x26, 0x96, 0xD2, 0x8E, 0x9C, 0x61, 0xC2, 0xA0,
  26449. 0x1C, 0xE9, 0xB1, 0x60, 0x8D, 0xCB, 0x9D, 0x29,
  26450. 0x27, 0x85, 0xA0, 0xCD, 0x58, 0xEF, 0xB7, 0xFE,
  26451. 0x13, 0xB1, 0xDE, 0x95, 0xF0, 0xDB, 0x55, 0xB3
  26452. };
  26453. #endif
  26454. #ifndef WOLFSSL_NO_KYBER1024
  26455. static const byte ek_1024[KYBER1024_PUBLIC_KEY_SIZE] = {
  26456. 0x30, 0x7A, 0x4C, 0xEA, 0x41, 0x48, 0x21, 0x9B,
  26457. 0x95, 0x8E, 0xA0, 0xB7, 0x88, 0x66, 0x59, 0x23,
  26458. 0x5A, 0x4D, 0x19, 0x80, 0xB1, 0x92, 0x61, 0x08,
  26459. 0x47, 0xD8, 0x6E, 0xF3, 0x27, 0x39, 0xF9, 0x4C,
  26460. 0x3B, 0x44, 0x6C, 0x4D, 0x81, 0xD8, 0x9B, 0x8B,
  26461. 0x42, 0x2A, 0x9D, 0x07, 0x9C, 0x88, 0xB1, 0x1A,
  26462. 0xCA, 0xF3, 0x21, 0xB0, 0x14, 0x29, 0x4E, 0x18,
  26463. 0xB2, 0x96, 0xE5, 0x2F, 0x3F, 0x74, 0x4C, 0xF9,
  26464. 0x63, 0x4A, 0x4F, 0xB0, 0x1D, 0xB0, 0xD9, 0x9E,
  26465. 0xF2, 0x0A, 0x63, 0x3A, 0x55, 0x2E, 0x76, 0xA0,
  26466. 0x58, 0x5C, 0x61, 0x09, 0xF0, 0x18, 0x76, 0x8B,
  26467. 0x76, 0x3A, 0xF3, 0x67, 0x8B, 0x47, 0x80, 0x08,
  26468. 0x9C, 0x13, 0x42, 0xB9, 0x69, 0x07, 0xA2, 0x9A,
  26469. 0x1C, 0x11, 0x52, 0x1C, 0x74, 0x4C, 0x27, 0x97,
  26470. 0xD0, 0xBF, 0x2B, 0x9C, 0xCD, 0xCA, 0x61, 0x46,
  26471. 0x72, 0xB4, 0x50, 0x76, 0x77, 0x3F, 0x45, 0x8A,
  26472. 0x31, 0xEF, 0x86, 0x9B, 0xE1, 0xEB, 0x2E, 0xFE,
  26473. 0xB5, 0x0D, 0x0E, 0x37, 0x49, 0x5D, 0xC5, 0xCA,
  26474. 0x55, 0xE0, 0x75, 0x28, 0x93, 0x4F, 0x62, 0x93,
  26475. 0xC4, 0x16, 0x80, 0x27, 0xD0, 0xE5, 0x3D, 0x07,
  26476. 0xFA, 0xCC, 0x66, 0x30, 0xCB, 0x08, 0x19, 0x7E,
  26477. 0x53, 0xFB, 0x19, 0x3A, 0x17, 0x11, 0x35, 0xDC,
  26478. 0x8A, 0xD9, 0x97, 0x94, 0x02, 0xA7, 0x1B, 0x69,
  26479. 0x26, 0xBC, 0xDC, 0xDC, 0x47, 0xB9, 0x34, 0x01,
  26480. 0x91, 0x0A, 0x5F, 0xCC, 0x1A, 0x81, 0x3B, 0x68,
  26481. 0x2B, 0x09, 0xBA, 0x7A, 0x72, 0xD2, 0x48, 0x6D,
  26482. 0x6C, 0x79, 0x95, 0x16, 0x46, 0x5C, 0x14, 0x72,
  26483. 0x9B, 0x26, 0x94, 0x9B, 0x0B, 0x7C, 0xBC, 0x7C,
  26484. 0x64, 0x0F, 0x26, 0x7F, 0xED, 0x80, 0xB1, 0x62,
  26485. 0xC5, 0x1F, 0xD8, 0xE0, 0x92, 0x27, 0xC1, 0x01,
  26486. 0xD5, 0x05, 0xA8, 0xFA, 0xE8, 0xA2, 0xD7, 0x05,
  26487. 0x4E, 0x28, 0xA7, 0x8B, 0xA8, 0x75, 0x0D, 0xEC,
  26488. 0xF9, 0x05, 0x7C, 0x83, 0x97, 0x9F, 0x7A, 0xBB,
  26489. 0x08, 0x49, 0x45, 0x64, 0x80, 0x06, 0xC5, 0xB2,
  26490. 0x88, 0x04, 0xF3, 0x4E, 0x73, 0xB2, 0x38, 0x11,
  26491. 0x1A, 0x65, 0xA1, 0xF5, 0x00, 0xB1, 0xCC, 0x60,
  26492. 0x6A, 0x84, 0x8F, 0x28, 0x59, 0x07, 0x0B, 0xEB,
  26493. 0xA7, 0x57, 0x31, 0x79, 0xF3, 0x61, 0x49, 0xCF,
  26494. 0x58, 0x01, 0xBF, 0x89, 0xA1, 0xC3, 0x8C, 0xC2,
  26495. 0x78, 0x41, 0x55, 0x28, 0xD0, 0x3B, 0xDB, 0x94,
  26496. 0x3F, 0x96, 0x28, 0x0C, 0x8C, 0xC5, 0x20, 0x42,
  26497. 0xD9, 0xB9, 0x1F, 0xAA, 0x9D, 0x6E, 0xA7, 0xBC,
  26498. 0xBB, 0x7A, 0xB1, 0x89, 0x7A, 0x32, 0x66, 0x96,
  26499. 0x6F, 0x78, 0x39, 0x34, 0x26, 0xC7, 0x6D, 0x8A,
  26500. 0x49, 0x57, 0x8B, 0x98, 0xB1, 0x59, 0xEB, 0xB4,
  26501. 0x6E, 0xE0, 0xA8, 0x83, 0xA2, 0x70, 0xD8, 0x05,
  26502. 0x7C, 0xD0, 0x23, 0x1C, 0x86, 0x90, 0x6A, 0x91,
  26503. 0xDB, 0xBA, 0xDE, 0x6B, 0x24, 0x69, 0x58, 0x1E,
  26504. 0x2B, 0xCA, 0x2F, 0xEA, 0x83, 0x89, 0xF7, 0xC7,
  26505. 0x4B, 0xCD, 0x70, 0x96, 0x1E, 0xA5, 0xB9, 0x34,
  26506. 0xFB, 0xCF, 0x9A, 0x65, 0x90, 0xBF, 0x86, 0xB8,
  26507. 0xDB, 0x54, 0x88, 0x54, 0xD9, 0xA3, 0xFB, 0x30,
  26508. 0x11, 0x04, 0x33, 0xBD, 0x7A, 0x1B, 0x65, 0x9C,
  26509. 0xA8, 0x56, 0x80, 0x85, 0x63, 0x92, 0x37, 0xB3,
  26510. 0xBD, 0xC3, 0x7B, 0x7F, 0xA7, 0x16, 0xD4, 0x82,
  26511. 0xA2, 0x5B, 0x54, 0x10, 0x6B, 0x3A, 0x8F, 0x54,
  26512. 0xD3, 0xAA, 0x99, 0xB5, 0x12, 0x3D, 0xA9, 0x60,
  26513. 0x66, 0x90, 0x45, 0x92, 0xF3, 0xA5, 0x4E, 0xE2,
  26514. 0x3A, 0x79, 0x81, 0xAB, 0x60, 0x8A, 0x2F, 0x44,
  26515. 0x13, 0xCC, 0x65, 0x89, 0x46, 0xC6, 0xD7, 0x78,
  26516. 0x0E, 0xA7, 0x65, 0x64, 0x4B, 0x3C, 0xC0, 0x6C,
  26517. 0x70, 0x03, 0x4A, 0xB4, 0xEB, 0x35, 0x19, 0x12,
  26518. 0xE7, 0x71, 0x5B, 0x56, 0x75, 0x5D, 0x09, 0x02,
  26519. 0x15, 0x71, 0xBF, 0x34, 0x0A, 0xB9, 0x25, 0x98,
  26520. 0xA2, 0x4E, 0x81, 0x18, 0x93, 0x19, 0x5B, 0x96,
  26521. 0xA1, 0x62, 0x9F, 0x80, 0x41, 0xF5, 0x86, 0x58,
  26522. 0x43, 0x15, 0x61, 0xFC, 0x0A, 0xB1, 0x52, 0x92,
  26523. 0xB9, 0x13, 0xEC, 0x47, 0x3F, 0x04, 0x47, 0x9B,
  26524. 0xC1, 0x45, 0xCD, 0x4C, 0x56, 0x3A, 0x28, 0x62,
  26525. 0x35, 0x64, 0x6C, 0xD3, 0x05, 0xA9, 0xBE, 0x10,
  26526. 0x14, 0xE2, 0xC7, 0xB1, 0x30, 0xC3, 0x3E, 0xB7,
  26527. 0x7C, 0xC4, 0xA0, 0xD9, 0x78, 0x6B, 0xD6, 0xBC,
  26528. 0x2A, 0x95, 0x4B, 0xF3, 0x00, 0x57, 0x78, 0xF8,
  26529. 0x91, 0x7C, 0xE1, 0x37, 0x89, 0xBB, 0xB9, 0x62,
  26530. 0x80, 0x78, 0x58, 0xB6, 0x77, 0x31, 0x57, 0x2B,
  26531. 0x6D, 0x3C, 0x9B, 0x4B, 0x52, 0x06, 0xFA, 0xC9,
  26532. 0xA7, 0xC8, 0x96, 0x16, 0x98, 0xD8, 0x83, 0x24,
  26533. 0xA9, 0x15, 0x18, 0x68, 0x99, 0xB2, 0x99, 0x23,
  26534. 0xF0, 0x84, 0x42, 0xA3, 0xD3, 0x86, 0xBD, 0x41,
  26535. 0x6B, 0xCC, 0x9A, 0x10, 0x01, 0x64, 0xC9, 0x30,
  26536. 0xEC, 0x35, 0xEA, 0xFB, 0x6A, 0xB3, 0x58, 0x51,
  26537. 0xB6, 0xC8, 0xCE, 0x63, 0x77, 0x36, 0x6A, 0x17,
  26538. 0x5F, 0x3D, 0x75, 0x29, 0x8C, 0x51, 0x8D, 0x44,
  26539. 0x89, 0x89, 0x33, 0xF5, 0x3D, 0xEE, 0x61, 0x71,
  26540. 0x45, 0x09, 0x33, 0x79, 0xC4, 0x65, 0x9F, 0x68,
  26541. 0x58, 0x3B, 0x2B, 0x28, 0x12, 0x26, 0x66, 0xBE,
  26542. 0xC5, 0x78, 0x38, 0x99, 0x1F, 0xF1, 0x6C, 0x36,
  26543. 0x8D, 0xD2, 0x2C, 0x36, 0xE7, 0x80, 0xC9, 0x1A,
  26544. 0x35, 0x82, 0xE2, 0x5E, 0x19, 0x79, 0x4C, 0x6B,
  26545. 0xF2, 0xAB, 0x42, 0x45, 0x8A, 0x8D, 0xD7, 0x70,
  26546. 0x5D, 0xE2, 0xC2, 0xAA, 0x20, 0xC0, 0x54, 0xE8,
  26547. 0x4B, 0x3E, 0xF3, 0x50, 0x32, 0x79, 0x86, 0x26,
  26548. 0xC2, 0x48, 0x26, 0x32, 0x53, 0xA7, 0x1A, 0x11,
  26549. 0x94, 0x35, 0x71, 0x34, 0x0A, 0x97, 0x8C, 0xD0,
  26550. 0xA6, 0x02, 0xE4, 0x7D, 0xEE, 0x54, 0x0A, 0x88,
  26551. 0x14, 0xBA, 0x06, 0xF3, 0x14, 0x14, 0x79, 0x7C,
  26552. 0xDF, 0x60, 0x49, 0x58, 0x23, 0x61, 0xBB, 0xAB,
  26553. 0xA3, 0x87, 0xA8, 0x3D, 0x89, 0x91, 0x3F, 0xE4,
  26554. 0xC0, 0xC1, 0x12, 0xB9, 0x56, 0x21, 0xA4, 0xBD,
  26555. 0xA8, 0x12, 0x3A, 0x14, 0xD1, 0xA8, 0x42, 0xFB,
  26556. 0x57, 0xB8, 0x3A, 0x4F, 0xBA, 0xF3, 0x3A, 0x8E,
  26557. 0x55, 0x22, 0x38, 0xA5, 0x96, 0xAA, 0xE7, 0xA1,
  26558. 0x50, 0xD7, 0x5D, 0xA6, 0x48, 0xBC, 0x44, 0x64,
  26559. 0x49, 0x77, 0xBA, 0x1F, 0x87, 0xA4, 0xC6, 0x8A,
  26560. 0x8C, 0x4B, 0xD2, 0x45, 0xB7, 0xD0, 0x07, 0x21,
  26561. 0xF7, 0xD6, 0x4E, 0x82, 0x2B, 0x08, 0x5B, 0x90,
  26562. 0x13, 0x12, 0xEC, 0x37, 0xA8, 0x16, 0x98, 0x02,
  26563. 0x16, 0x0C, 0xCE, 0x11, 0x60, 0xF0, 0x10, 0xBE,
  26564. 0x8C, 0xBC, 0xAC, 0xE8, 0xE7, 0xB0, 0x05, 0xD7,
  26565. 0x83, 0x92, 0x34, 0xA7, 0x07, 0x86, 0x83, 0x09,
  26566. 0xD0, 0x37, 0x84, 0xB4, 0x27, 0x3B, 0x1C, 0x8A,
  26567. 0x16, 0x01, 0x33, 0xED, 0x29, 0x81, 0x84, 0x70,
  26568. 0x46, 0x25, 0xF2, 0x9C, 0xFA, 0x08, 0x6D, 0x13,
  26569. 0x26, 0x3E, 0xE5, 0x89, 0x91, 0x23, 0xC5, 0x96,
  26570. 0xBA, 0x78, 0x8E, 0x5C, 0x54, 0xA8, 0xE9, 0xBA,
  26571. 0x82, 0x9B, 0x8A, 0x9D, 0x90, 0x4B, 0xC4, 0xBC,
  26572. 0x0B, 0xBE, 0xA7, 0x6B, 0xC5, 0x3F, 0xF8, 0x11,
  26573. 0x21, 0x45, 0x98, 0x47, 0x2C, 0x9C, 0x20, 0x2B,
  26574. 0x73, 0xEF, 0xF0, 0x35, 0xDC, 0x09, 0x70, 0x3A,
  26575. 0xF7, 0xBF, 0x1B, 0xAB, 0xAA, 0xC7, 0x31, 0x93,
  26576. 0xCB, 0x46, 0x11, 0x7A, 0x7C, 0x94, 0x92, 0xA4,
  26577. 0x3F, 0xC9, 0x57, 0x89, 0xA9, 0x24, 0xC5, 0x91,
  26578. 0x27, 0x87, 0xB2, 0xE2, 0x09, 0x0E, 0xBB, 0xCF,
  26579. 0xD3, 0x79, 0x62, 0x21, 0xF0, 0x6D, 0xEB, 0xF9,
  26580. 0xCF, 0x70, 0xE0, 0x56, 0xB8, 0xB9, 0x16, 0x1D,
  26581. 0x63, 0x47, 0xF4, 0x73, 0x35, 0xF3, 0xE1, 0x77,
  26582. 0x6D, 0xA4, 0xBB, 0x87, 0xC1, 0x5C, 0xC8, 0x26,
  26583. 0x14, 0x6F, 0xF0, 0x24, 0x9A, 0x41, 0x3B, 0x45,
  26584. 0xAA, 0x93, 0xA8, 0x05, 0x19, 0x6E, 0xA4, 0x53,
  26585. 0x11, 0x4B, 0x52, 0x4E, 0x31, 0x0A, 0xED, 0xAA,
  26586. 0x46, 0xE3, 0xB9, 0x96, 0x42, 0x36, 0x87, 0x82,
  26587. 0x56, 0x6D, 0x04, 0x9A, 0x72, 0x6D, 0x6C, 0xCA,
  26588. 0x91, 0x09, 0x93, 0xAE, 0xD6, 0x21, 0xD0, 0x14,
  26589. 0x9E, 0xA5, 0x88, 0xA9, 0xAB, 0xD9, 0x09, 0xDB,
  26590. 0xB6, 0x9A, 0xA2, 0x28, 0x29, 0xD9, 0xB8, 0x3A,
  26591. 0xDA, 0x22, 0x09, 0xA6, 0xC2, 0x65, 0x9F, 0x21,
  26592. 0x69, 0xD6, 0x68, 0xB9, 0x31, 0x48, 0x42, 0xC6,
  26593. 0xE2, 0x2A, 0x74, 0x95, 0x8B, 0x4C, 0x25, 0xBB,
  26594. 0xDC, 0xD2, 0x93, 0xD9, 0x9C, 0xB6, 0x09, 0xD8,
  26595. 0x66, 0x74, 0x9A, 0x48, 0x5D, 0xFB, 0x56, 0x02,
  26596. 0x48, 0x83, 0xCF, 0x54, 0x65, 0xDB, 0xA0, 0x36,
  26597. 0x32, 0x06, 0x58, 0x7F, 0x45, 0x59, 0x7F, 0x89,
  26598. 0x00, 0x2F, 0xB8, 0x60, 0x72, 0x32, 0x13, 0x8E,
  26599. 0x03, 0xB2, 0xA8, 0x94, 0x52, 0x5F, 0x26, 0x53,
  26600. 0x70, 0x05, 0x4B, 0x48, 0x86, 0x36, 0x14, 0x47,
  26601. 0x2B, 0x95, 0xD0, 0xA2, 0x30, 0x34, 0x42, 0xE3,
  26602. 0x78, 0xB0, 0xDD, 0x1C, 0x75, 0xAC, 0xBA, 0xB9,
  26603. 0x71, 0xA9, 0xA8, 0xD1, 0x28, 0x1C, 0x79, 0x61,
  26604. 0x3A, 0xCE, 0xC6, 0x93, 0x3C, 0x37, 0x7B, 0x3C,
  26605. 0x57, 0x8C, 0x2A, 0x61, 0xA1, 0xEC, 0x18, 0x1B,
  26606. 0x10, 0x12, 0x97, 0xA3, 0x7C, 0xC5, 0x19, 0x7B,
  26607. 0x29, 0x42, 0xF6, 0xA0, 0xE4, 0x70, 0x4C, 0x0E,
  26608. 0xC6, 0x35, 0x40, 0x48, 0x1B, 0x9F, 0x15, 0x9D,
  26609. 0xC2, 0x55, 0xB5, 0x9B, 0xB5, 0x5D, 0xF4, 0x96,
  26610. 0xAE, 0x54, 0x21, 0x7B, 0x76, 0x89, 0xBD, 0x51,
  26611. 0xDB, 0xA0, 0x38, 0x3A, 0x3D, 0x72, 0xD8, 0x52,
  26612. 0xFF, 0xCA, 0x76, 0xDF, 0x05, 0xB6, 0x6E, 0xEC,
  26613. 0xCB, 0xD4, 0x7B, 0xC5, 0x30, 0x40, 0x81, 0x76,
  26614. 0x28, 0xC7, 0x1E, 0x36, 0x1D, 0x6A, 0xF8, 0x89,
  26615. 0x08, 0x49, 0x16, 0xB4, 0x08, 0xA4, 0x66, 0xC9,
  26616. 0x6E, 0x70, 0x86, 0xC4, 0xA6, 0x0A, 0x10, 0xFC,
  26617. 0xF7, 0x53, 0x7B, 0xB9, 0x4A, 0xFB, 0xCC, 0x7D,
  26618. 0x43, 0x75, 0x90, 0x91, 0x9C, 0x28, 0x65, 0x0C,
  26619. 0x4F, 0x23, 0x68, 0x25, 0x92, 0x26, 0xA9, 0xBF,
  26620. 0xDA, 0x3A, 0x3A, 0x0B, 0xA1, 0xB5, 0x08, 0x7D,
  26621. 0x9D, 0x76, 0x44, 0x2F, 0xD7, 0x86, 0xC6, 0xF8,
  26622. 0x1C, 0x68, 0xC0, 0x36, 0x0D, 0x71, 0x94, 0xD7,
  26623. 0x07, 0x2C, 0x45, 0x33, 0xAE, 0xA8, 0x6C, 0x2D,
  26624. 0x1F, 0x8C, 0x0A, 0x27, 0x69, 0x60, 0x66, 0xF6,
  26625. 0xCF, 0xD1, 0x10, 0x03, 0xF7, 0x97, 0x27, 0x0B,
  26626. 0x32, 0x38, 0x97, 0x13, 0xCF, 0xFA, 0x09, 0x3D,
  26627. 0x99, 0x1B, 0x63, 0x84, 0x4C, 0x38, 0x5E, 0x72,
  26628. 0x27, 0x7F, 0x16, 0x6F, 0x5A, 0x39, 0x34, 0xD6,
  26629. 0xBB, 0x89, 0xA4, 0x78, 0x8D, 0xE2, 0x83, 0x21,
  26630. 0xDE, 0xFC, 0x74, 0x57, 0xAB, 0x48, 0x4B, 0xD3,
  26631. 0x09, 0x86, 0xDC, 0x1D, 0xAB, 0x30, 0x08, 0xCD,
  26632. 0x7B, 0x22, 0xF6, 0x97, 0x02, 0xFA, 0xBB, 0x9A,
  26633. 0x10, 0x45, 0x40, 0x7D, 0xA4, 0x79, 0x1C, 0x35,
  26634. 0x90, 0xFF, 0x59, 0x9D, 0x81, 0xD6, 0x88, 0xCF,
  26635. 0xA7, 0xCC, 0x12, 0xA6, 0x8C, 0x50, 0xF5, 0x1A,
  26636. 0x10, 0x09, 0x41, 0x1B, 0x44, 0x85, 0x0F, 0x90,
  26637. 0x15, 0xDC, 0x84, 0xA9, 0x3B, 0x17, 0xC7, 0xA2,
  26638. 0x07, 0x55, 0x2C, 0x66, 0x1E, 0xA9, 0x83, 0x8E,
  26639. 0x31, 0xB9, 0x5E, 0xAD, 0x54, 0x62, 0x48, 0xE5,
  26640. 0x6B, 0xE7, 0xA5, 0x13, 0x05, 0x05, 0x26, 0x87,
  26641. 0x71, 0x19, 0x98, 0x80, 0xA1, 0x41, 0x77, 0x1A,
  26642. 0x9E, 0x47, 0xAC, 0xFE, 0xD5, 0x90, 0xCB, 0x3A,
  26643. 0xA7, 0xCB, 0x7C, 0x5F, 0x74, 0x91, 0x1D, 0x89,
  26644. 0x12, 0xC2, 0x9D, 0x62, 0x33, 0xF4, 0xD5, 0x3B,
  26645. 0xC6, 0x41, 0x39, 0xE2, 0xF5, 0x5B, 0xE7, 0x55,
  26646. 0x07, 0xDD, 0x77, 0x86, 0x8E, 0x38, 0x4A, 0xEC,
  26647. 0x58, 0x1F, 0x3F, 0x41, 0x1D, 0xB1, 0xA7, 0x42,
  26648. 0x97, 0x2D, 0x3E, 0xBF, 0xD3, 0x31, 0x5C, 0x84,
  26649. 0xA5, 0xAD, 0x63, 0xA0, 0xE7, 0x5C, 0x8B, 0xCA,
  26650. 0x3E, 0x30, 0x41, 0xE0, 0x5D, 0x90, 0x67, 0xAF,
  26651. 0xF3, 0xB1, 0x24, 0x4F, 0x76, 0x3E, 0x79, 0x83
  26652. };
  26653. static const byte seed_1024[KYBER_ENC_RAND_SZ] = {
  26654. 0x59, 0xC5, 0x15, 0x4C, 0x04, 0xAE, 0x43, 0xAA,
  26655. 0xFF, 0x32, 0x70, 0x0F, 0x08, 0x17, 0x00, 0x38,
  26656. 0x9D, 0x54, 0xBE, 0xC4, 0xC3, 0x7C, 0x08, 0x8B,
  26657. 0x1C, 0x53, 0xF6, 0x62, 0x12, 0xB1, 0x2C, 0x72
  26658. };
  26659. static const byte c_1024[KYBER1024_CIPHER_TEXT_SIZE] = {
  26660. 0xE2, 0xD5, 0xFD, 0x4C, 0x13, 0xCE, 0xA0, 0xB5,
  26661. 0x2D, 0x87, 0x4F, 0xEA, 0x90, 0x12, 0xF3, 0xA5,
  26662. 0x17, 0x43, 0xA1, 0x09, 0x37, 0x10, 0xBB, 0xF2,
  26663. 0x39, 0x50, 0xF9, 0x14, 0x7A, 0x47, 0x2E, 0xE5,
  26664. 0x53, 0x39, 0x28, 0xA2, 0xF4, 0x6D, 0x59, 0x2F,
  26665. 0x35, 0xDA, 0x8B, 0x4F, 0x75, 0x8C, 0x89, 0x3B,
  26666. 0x0D, 0x7B, 0x98, 0x94, 0x8B, 0xE4, 0x47, 0xB1,
  26667. 0x7C, 0xB2, 0xAE, 0x58, 0xAF, 0x8A, 0x48, 0x9D,
  26668. 0xDD, 0x92, 0x32, 0xB9, 0x9B, 0x1C, 0x0D, 0x2D,
  26669. 0xE7, 0x7C, 0xAA, 0x47, 0x2B, 0xC3, 0xBB, 0xD4,
  26670. 0xA7, 0xC6, 0x0D, 0xBF, 0xDC, 0xA9, 0x2E, 0xBF,
  26671. 0x3A, 0x1C, 0xE1, 0xC2, 0x2D, 0xAD, 0x13, 0xE8,
  26672. 0x87, 0x00, 0x4E, 0x29, 0x24, 0xFD, 0x22, 0x65,
  26673. 0x6F, 0x5E, 0x50, 0x87, 0x91, 0xDE, 0x06, 0xD8,
  26674. 0x5E, 0x1A, 0x14, 0x26, 0x80, 0x8E, 0xD9, 0xA8,
  26675. 0x9F, 0x6E, 0x2F, 0xD3, 0xC2, 0x45, 0xD4, 0x75,
  26676. 0x8B, 0x22, 0xB0, 0x2C, 0xAD, 0xE3, 0x3B, 0x60,
  26677. 0xFC, 0x88, 0x9A, 0x33, 0xFC, 0x44, 0x47, 0xED,
  26678. 0xEB, 0xBF, 0xD4, 0x53, 0x0D, 0xE8, 0x65, 0x96,
  26679. 0xA3, 0x37, 0x89, 0xD5, 0xDB, 0xA6, 0xE6, 0xEC,
  26680. 0x9F, 0x89, 0x87, 0x9A, 0xF4, 0xBE, 0x49, 0x09,
  26681. 0xA6, 0x90, 0x17, 0xC9, 0xBB, 0x7A, 0x5E, 0x31,
  26682. 0x81, 0x5E, 0xA5, 0xF1, 0x32, 0xEE, 0xC4, 0x98,
  26683. 0x4F, 0xAA, 0x7C, 0xCF, 0x59, 0x4D, 0xD0, 0x0D,
  26684. 0x4D, 0x84, 0x87, 0xE4, 0x56, 0x21, 0xAF, 0x8F,
  26685. 0x6E, 0x33, 0x05, 0x51, 0x43, 0x9C, 0x93, 0xEC,
  26686. 0x07, 0x8A, 0x7A, 0x3C, 0xC1, 0x59, 0x4A, 0xF9,
  26687. 0x1F, 0x84, 0x17, 0x37, 0x5F, 0xD6, 0x08, 0x8C,
  26688. 0xEB, 0x5E, 0x85, 0xC6, 0x70, 0x99, 0x09, 0x1B,
  26689. 0xAC, 0x11, 0x49, 0x8A, 0x0D, 0x71, 0x14, 0x55,
  26690. 0xF5, 0xE0, 0xD9, 0x5C, 0xD7, 0xBB, 0xE5, 0xCD,
  26691. 0xD8, 0xFE, 0xCB, 0x31, 0x9E, 0x68, 0x53, 0xC2,
  26692. 0x3C, 0x9B, 0xE2, 0xC7, 0x63, 0xDF, 0x57, 0x86,
  26693. 0x66, 0xC4, 0x0A, 0x40, 0xA8, 0x74, 0x86, 0xE4,
  26694. 0x6B, 0xA8, 0x71, 0x61, 0x46, 0x19, 0x29, 0x04,
  26695. 0x51, 0x0A, 0x6D, 0xC5, 0x9D, 0xA8, 0x02, 0x58,
  26696. 0x25, 0x28, 0x3D, 0x68, 0x4D, 0xB9, 0x14, 0x10,
  26697. 0xB4, 0xF1, 0x2C, 0x6D, 0x8F, 0xBD, 0x0A, 0xDD,
  26698. 0x75, 0xD3, 0x09, 0x89, 0x18, 0xCB, 0x04, 0xAC,
  26699. 0x7B, 0xC4, 0xDB, 0x0D, 0x6B, 0xCD, 0xF1, 0x19,
  26700. 0x4D, 0xD8, 0x62, 0x92, 0xE0, 0x5B, 0x7B, 0x86,
  26701. 0x30, 0x62, 0x5B, 0x58, 0x9C, 0xC5, 0x09, 0xD2,
  26702. 0x15, 0xBB, 0xD0, 0x6A, 0x2E, 0x7C, 0x66, 0xF4,
  26703. 0x24, 0xCD, 0xF8, 0xC4, 0x0A, 0xC6, 0xC1, 0xE5,
  26704. 0xAE, 0x6C, 0x96, 0x4B, 0x7D, 0x9E, 0x92, 0xF9,
  26705. 0x5F, 0xC5, 0xC8, 0x85, 0x22, 0x81, 0x62, 0x8B,
  26706. 0x81, 0xB9, 0xAF, 0xAB, 0xC7, 0xF0, 0x3B, 0xE3,
  26707. 0xF6, 0x2E, 0x80, 0x47, 0xBB, 0x88, 0xD0, 0x1C,
  26708. 0x68, 0x68, 0x7B, 0x8D, 0xD4, 0xFE, 0x63, 0x82,
  26709. 0x00, 0x62, 0xB6, 0x78, 0x8A, 0x53, 0x72, 0x90,
  26710. 0x53, 0x82, 0x6E, 0xD3, 0xB7, 0xC7, 0xEF, 0x82,
  26711. 0x41, 0xE1, 0x9C, 0x85, 0x11, 0x7B, 0x3C, 0x53,
  26712. 0x41, 0x88, 0x1D, 0x4F, 0x29, 0x9E, 0x50, 0x37,
  26713. 0x4C, 0x8E, 0xEF, 0xD5, 0x56, 0x0B, 0xD1, 0x83,
  26714. 0x19, 0xA7, 0x96, 0x3A, 0x3D, 0x02, 0xF0, 0xFB,
  26715. 0xE8, 0x4B, 0xC4, 0x84, 0xB5, 0xA4, 0x01, 0x8B,
  26716. 0x97, 0xD2, 0x74, 0x19, 0x1C, 0x95, 0xF7, 0x02,
  26717. 0xBA, 0xB9, 0xB0, 0xD1, 0x05, 0xFA, 0xF9, 0xFD,
  26718. 0xCF, 0xF9, 0x7E, 0x43, 0x72, 0x36, 0x56, 0x75,
  26719. 0x99, 0xFA, 0xF7, 0x3B, 0x07, 0x5D, 0x40, 0x61,
  26720. 0x04, 0xD4, 0x03, 0xCD, 0xF8, 0x12, 0x24, 0xDA,
  26721. 0x59, 0x0B, 0xEC, 0x28, 0x97, 0xE3, 0x01, 0x09,
  26722. 0xE1, 0xF2, 0xE5, 0xAE, 0x46, 0x10, 0xC8, 0x09,
  26723. 0xA7, 0x3F, 0x63, 0x8C, 0x84, 0x21, 0x0B, 0x34,
  26724. 0x47, 0xA7, 0xC8, 0xB6, 0xDD, 0xDB, 0x5A, 0xE2,
  26725. 0x00, 0xBF, 0x20, 0xE2, 0xFE, 0x4D, 0x4B, 0xA6,
  26726. 0xC6, 0xB1, 0x27, 0x67, 0xFB, 0x87, 0x60, 0xF6,
  26727. 0x6C, 0x51, 0x18, 0xE7, 0xA9, 0x93, 0x5B, 0x41,
  26728. 0xC9, 0xA4, 0x71, 0xA1, 0xD3, 0x23, 0x76, 0x88,
  26729. 0xC1, 0xE6, 0x18, 0xCC, 0x3B, 0xE9, 0x36, 0xAA,
  26730. 0x3F, 0x5E, 0x44, 0xE0, 0x86, 0x82, 0x0B, 0x81,
  26731. 0x0E, 0x06, 0x32, 0x11, 0xFC, 0x21, 0xC4, 0x04,
  26732. 0x4B, 0x3A, 0xC4, 0xD0, 0x0D, 0xF1, 0xBC, 0xC7,
  26733. 0xB2, 0x4D, 0xC0, 0x7B, 0xA4, 0x8B, 0x23, 0xB0,
  26734. 0xFC, 0x12, 0xA3, 0xED, 0x3D, 0x0A, 0x5C, 0xF7,
  26735. 0x67, 0x14, 0x15, 0xAB, 0x9C, 0xF2, 0x12, 0x86,
  26736. 0xFE, 0x63, 0xFB, 0x41, 0x41, 0x85, 0x70, 0x55,
  26737. 0x5D, 0x47, 0x39, 0xB8, 0x81, 0x04, 0xA8, 0x59,
  26738. 0x3F, 0x29, 0x30, 0x25, 0xA4, 0xE3, 0xEE, 0x7C,
  26739. 0x67, 0xE4, 0xB4, 0x8E, 0x40, 0xF6, 0xBA, 0x8C,
  26740. 0x09, 0x86, 0x0C, 0x3F, 0xBB, 0xE5, 0x5D, 0x45,
  26741. 0xB4, 0x5F, 0xC9, 0xAB, 0x62, 0x9B, 0x17, 0xC2,
  26742. 0x76, 0xC9, 0xC9, 0xE2, 0xAF, 0x3A, 0x04, 0x3B,
  26743. 0xEA, 0xFC, 0x18, 0xFD, 0x4F, 0x25, 0xEE, 0x7F,
  26744. 0x83, 0xBD, 0xDC, 0xD2, 0xD9, 0x39, 0x14, 0xB7,
  26745. 0xED, 0x4F, 0x7C, 0x9A, 0xF1, 0x27, 0xF3, 0xF1,
  26746. 0x5C, 0x27, 0x7B, 0xE1, 0x65, 0x51, 0xFE, 0xF3,
  26747. 0xAE, 0x03, 0xD7, 0xB9, 0x14, 0x3F, 0x0C, 0x9C,
  26748. 0x01, 0x9A, 0xB9, 0x7E, 0xEA, 0x07, 0x63, 0x66,
  26749. 0x13, 0x1F, 0x51, 0x83, 0x63, 0x71, 0x1B, 0x34,
  26750. 0xE9, 0x6D, 0x3F, 0x8A, 0x51, 0x3F, 0x3E, 0x20,
  26751. 0xB1, 0xD4, 0x52, 0xC4, 0xB7, 0xAE, 0x3B, 0x97,
  26752. 0x5E, 0xA9, 0x4D, 0x88, 0x0D, 0xAC, 0x66, 0x93,
  26753. 0x39, 0x97, 0x50, 0xD0, 0x22, 0x20, 0x40, 0x3F,
  26754. 0x0D, 0x3E, 0x3F, 0xC1, 0x17, 0x2A, 0x4D, 0xE9,
  26755. 0xDC, 0x28, 0x0E, 0xAF, 0x0F, 0xEE, 0x28, 0x83,
  26756. 0xA6, 0x66, 0x0B, 0xF5, 0xA3, 0xD2, 0x46, 0xFF,
  26757. 0x41, 0xD2, 0x1B, 0x36, 0xEA, 0x52, 0x1C, 0xF7,
  26758. 0xAA, 0x68, 0x9F, 0x80, 0x0D, 0x0F, 0x86, 0xF4,
  26759. 0xFA, 0x10, 0x57, 0xD8, 0xA1, 0x3F, 0x9D, 0xA8,
  26760. 0xFF, 0xFD, 0x0D, 0xC1, 0xFA, 0xD3, 0xC0, 0x4B,
  26761. 0xB1, 0xCC, 0xCB, 0x7C, 0x83, 0x4D, 0xB0, 0x51,
  26762. 0xA7, 0xAC, 0x2E, 0x4C, 0x60, 0x30, 0x19, 0x96,
  26763. 0xC9, 0x30, 0x71, 0xEA, 0x41, 0x6B, 0x42, 0x17,
  26764. 0x59, 0x93, 0x56, 0x59, 0xCF, 0x62, 0xCA, 0x5F,
  26765. 0x13, 0xAE, 0x07, 0xC3, 0xB1, 0x95, 0xC1, 0x48,
  26766. 0x15, 0x9D, 0x8B, 0xEB, 0x03, 0xD4, 0x40, 0xB0,
  26767. 0x0F, 0x53, 0x05, 0x76, 0x5F, 0x20, 0xC0, 0xC4,
  26768. 0x6E, 0xEE, 0x59, 0xC6, 0xD1, 0x62, 0x06, 0x40,
  26769. 0x2D, 0xB1, 0xC7, 0x15, 0xE8, 0x88, 0xBD, 0xE5,
  26770. 0x9C, 0x78, 0x1F, 0x35, 0xA7, 0xCC, 0x7C, 0x1C,
  26771. 0x5E, 0xCB, 0x21, 0x55, 0xAE, 0x3E, 0x95, 0x9C,
  26772. 0x09, 0x64, 0xCC, 0x1E, 0xF8, 0xD7, 0xC6, 0x9D,
  26773. 0x14, 0x58, 0xA9, 0xA4, 0x2F, 0x95, 0xF4, 0xC6,
  26774. 0xB5, 0xB9, 0x96, 0x34, 0x57, 0x12, 0xAA, 0x29,
  26775. 0x0F, 0xBB, 0xF7, 0xDF, 0xD4, 0xA6, 0xE8, 0x64,
  26776. 0x63, 0x02, 0x2A, 0x3F, 0x47, 0x25, 0xF6, 0x51,
  26777. 0x1B, 0xF7, 0xEA, 0x5E, 0x95, 0xC7, 0x07, 0xCD,
  26778. 0x35, 0x73, 0x60, 0x9A, 0xAD, 0xEA, 0xF5, 0x40,
  26779. 0x15, 0x2C, 0x49, 0x5F, 0x37, 0xFE, 0x6E, 0xC8,
  26780. 0xBB, 0x9F, 0xA2, 0xAA, 0x61, 0xD1, 0x57, 0x35,
  26781. 0x93, 0x4F, 0x47, 0x37, 0x92, 0x8F, 0xDE, 0x90,
  26782. 0xBA, 0x99, 0x57, 0x22, 0x46, 0x5D, 0x4A, 0x64,
  26783. 0x50, 0x5A, 0x52, 0x01, 0xF0, 0x7A, 0xA5, 0x8C,
  26784. 0xFD, 0x8A, 0xE2, 0x26, 0xE0, 0x20, 0x70, 0xB2,
  26785. 0xDB, 0xF5, 0x12, 0xB9, 0x75, 0x31, 0x9A, 0x7E,
  26786. 0x87, 0x53, 0xB4, 0xFD, 0xAE, 0x0E, 0xB4, 0x92,
  26787. 0x28, 0x69, 0xCC, 0x8E, 0x25, 0xC4, 0xA5, 0x56,
  26788. 0x0C, 0x2A, 0x06, 0x85, 0xDE, 0x3A, 0xC3, 0x92,
  26789. 0xA8, 0x92, 0x5B, 0xA8, 0x82, 0x00, 0x48, 0x94,
  26790. 0x74, 0x2E, 0x43, 0xCC, 0xFC, 0x27, 0x74, 0x39,
  26791. 0xEC, 0x80, 0x50, 0xA9, 0xAE, 0xB4, 0x29, 0x32,
  26792. 0xE0, 0x1C, 0x84, 0x0D, 0xFC, 0xED, 0xCC, 0x34,
  26793. 0xD3, 0x99, 0x12, 0x89, 0xA6, 0x2C, 0x17, 0xD1,
  26794. 0x28, 0x4C, 0x83, 0x95, 0x14, 0xB9, 0x33, 0x51,
  26795. 0xDB, 0xB2, 0xDD, 0xA8, 0x1F, 0x92, 0x45, 0x65,
  26796. 0xD7, 0x0E, 0x70, 0x79, 0xD5, 0xB8, 0x12, 0x6C,
  26797. 0xAA, 0xB7, 0xA4, 0xA1, 0xC7, 0x31, 0x65, 0x5A,
  26798. 0x53, 0xBC, 0xC0, 0x9F, 0x5D, 0x63, 0xEC, 0x90,
  26799. 0x86, 0xDE, 0xA6, 0x50, 0x05, 0x59, 0x85, 0xED,
  26800. 0xFA, 0x82, 0x97, 0xD9, 0xC9, 0x54, 0x10, 0xC5,
  26801. 0xD1, 0x89, 0x4D, 0x17, 0xD5, 0x93, 0x05, 0x49,
  26802. 0xAD, 0xBC, 0x2B, 0x87, 0x33, 0xC9, 0x9F, 0xE6,
  26803. 0x2E, 0x17, 0xC4, 0xDE, 0x34, 0xA5, 0xD8, 0x9B,
  26804. 0x12, 0xD1, 0x8E, 0x42, 0xA4, 0x22, 0xD2, 0xCE,
  26805. 0x77, 0x9C, 0x2C, 0x28, 0xEB, 0x2D, 0x98, 0x00,
  26806. 0x3D, 0x5C, 0xD3, 0x23, 0xFC, 0xBE, 0xCF, 0x02,
  26807. 0xB5, 0x06, 0x6E, 0x0E, 0x73, 0x48, 0x10, 0xF0,
  26808. 0x9E, 0xD8, 0x90, 0x13, 0xC0, 0x0F, 0x01, 0x1B,
  26809. 0xD2, 0x20, 0xF2, 0xE5, 0xD6, 0xA3, 0x62, 0xDF,
  26810. 0x90, 0x59, 0x91, 0x98, 0xA0, 0x93, 0xB0, 0x3C,
  26811. 0x8D, 0x8E, 0xFB, 0xFE, 0x0B, 0x61, 0x75, 0x92,
  26812. 0xFA, 0xF1, 0xE6, 0x42, 0x20, 0xC4, 0x44, 0x0B,
  26813. 0x53, 0xFF, 0xB4, 0x71, 0x64, 0xF3, 0x69, 0xC9,
  26814. 0x52, 0x90, 0xBA, 0x9F, 0x31, 0x08, 0xD6, 0x86,
  26815. 0xC5, 0x7D, 0xB6, 0x45, 0xC5, 0x3C, 0x01, 0x2E,
  26816. 0x57, 0xAF, 0x25, 0xBD, 0x66, 0x93, 0xE2, 0xCC,
  26817. 0x6B, 0x57, 0x65, 0x1A, 0xF1, 0x59, 0x1F, 0xE5,
  26818. 0xD8, 0x91, 0x66, 0x40, 0xEC, 0x01, 0x7C, 0x25,
  26819. 0x3D, 0xF0, 0x60, 0x6B, 0xB6, 0xB3, 0x03, 0x5F,
  26820. 0xAE, 0x74, 0x8F, 0x3D, 0x40, 0x34, 0x22, 0x3B,
  26821. 0x1B, 0x5E, 0xFB, 0xF5, 0x28, 0x3E, 0x77, 0x8C,
  26822. 0x10, 0x94, 0x29, 0x1C, 0xF7, 0xB1, 0x9B, 0xE0,
  26823. 0xF3, 0x17, 0x35, 0x0E, 0x6F, 0x85, 0x18, 0xFD,
  26824. 0xE0, 0xEF, 0xB1, 0x38, 0x1F, 0xB6, 0xE1, 0x6C,
  26825. 0x24, 0x1F, 0x7F, 0x17, 0xA5, 0x21, 0x06, 0x93,
  26826. 0xA2, 0x74, 0x15, 0x9E, 0x7F, 0xAC, 0x86, 0x8C,
  26827. 0xD0, 0xDC, 0x43, 0x59, 0xC3, 0xD9, 0xEE, 0xFE,
  26828. 0xA0, 0xD9, 0xE3, 0x1E, 0x43, 0xFA, 0x65, 0x13,
  26829. 0x92, 0xC6, 0x5A, 0x54, 0x3A, 0x59, 0xB3, 0xEE,
  26830. 0xE3, 0xA6, 0x39, 0xDC, 0x94, 0x17, 0xD0, 0x56,
  26831. 0xA5, 0xFF, 0x0F, 0x16, 0x0B, 0xEE, 0xE2, 0xEA,
  26832. 0xC2, 0x9A, 0x7D, 0x88, 0xC0, 0x98, 0x2C, 0xF7,
  26833. 0x0B, 0x5A, 0x46, 0x37, 0x9F, 0x21, 0xE5, 0x06,
  26834. 0xAA, 0xC6, 0x1A, 0x9B, 0xB1, 0xB8, 0xC2, 0xB9,
  26835. 0xDA, 0xB0, 0xE4, 0x4A, 0x82, 0x3B, 0x61, 0xD0,
  26836. 0xAA, 0x11, 0xD9, 0x4F, 0x76, 0xA4, 0xA8, 0xE2,
  26837. 0x1F, 0x9D, 0x42, 0x80, 0x68, 0x32, 0x08, 0xF4,
  26838. 0xEA, 0x91, 0x11, 0x16, 0xF6, 0xFD, 0x6A, 0x97,
  26839. 0x42, 0x69, 0x34, 0xEC, 0x34, 0x26, 0xB8, 0xC8,
  26840. 0xF7, 0x03, 0xDA, 0x85, 0xE9, 0xDC, 0xF9, 0x93,
  26841. 0x36, 0x13, 0x60, 0x03, 0x72, 0x8B, 0x8E, 0xCD,
  26842. 0xD0, 0x4A, 0x38, 0x9F, 0x6A, 0x81, 0x7A, 0x78,
  26843. 0xBF, 0xA6, 0x1B, 0xA4, 0x60, 0x20, 0xBF, 0x3C,
  26844. 0x34, 0x82, 0x95, 0x08, 0xF9, 0xD0, 0x6D, 0x15,
  26845. 0x53, 0xCD, 0x98, 0x7A, 0xAC, 0x38, 0x0D, 0x86,
  26846. 0xF1, 0x68, 0x84, 0x3B, 0xA3, 0x90, 0x4D, 0xE5,
  26847. 0xF7, 0x05, 0x8A, 0x41, 0xB4, 0xCD, 0x38, 0x8B,
  26848. 0xC9, 0xCE, 0x3A, 0xBA, 0x7E, 0xE7, 0x13, 0x9B,
  26849. 0x7F, 0xC9, 0xE5, 0xB8, 0xCF, 0xAA, 0xA3, 0x89,
  26850. 0x90, 0xBD, 0x4A, 0x5D, 0xB3, 0x2E, 0x26, 0x13,
  26851. 0xE7, 0xEC, 0x4F, 0x5F, 0x8B, 0x12, 0x92, 0xA3,
  26852. 0x8C, 0x6F, 0x4F, 0xF5, 0xA4, 0x04, 0x90, 0xD7,
  26853. 0x6B, 0x12, 0x66, 0x52, 0xFC, 0xF8, 0x6E, 0x24,
  26854. 0x52, 0x35, 0xD6, 0x36, 0xC6, 0x5C, 0xD1, 0x02,
  26855. 0xB0, 0x1E, 0x22, 0x78, 0x1A, 0x72, 0x91, 0x8C
  26856. };
  26857. static const byte k_1024[KYBER_SS_SZ] = {
  26858. 0x72, 0x64, 0xBD, 0xE5, 0xC6, 0xCE, 0xC1, 0x48,
  26859. 0x49, 0x69, 0x3E, 0x2C, 0x3C, 0x86, 0xE4, 0x8F,
  26860. 0x80, 0x95, 0x8A, 0x4F, 0x61, 0x86, 0xFC, 0x69,
  26861. 0x33, 0x3A, 0x41, 0x48, 0xE6, 0xE4, 0x97, 0xF3
  26862. };
  26863. #endif
  26864. static byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  26865. static byte ss[KYBER_SS_SZ];
  26866. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  26867. ExpectNotNull(key);
  26868. if (key != NULL) {
  26869. XMEMSET(key, 0, sizeof(KyberKey));
  26870. }
  26871. #ifndef WOLFSSL_NO_KYBER512
  26872. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  26873. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_512, sizeof(ek_512)), 0);
  26874. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_512,
  26875. sizeof(seed_512)), 0);
  26876. ExpectIntEQ(XMEMCMP(ct, c_512, KYBER512_CIPHER_TEXT_SIZE), 0);
  26877. ExpectIntEQ(XMEMCMP(ss, k_512, KYBER_SS_SZ), 0);
  26878. wc_KyberKey_Free(key);
  26879. #endif
  26880. #ifndef WOLFSSL_NO_KYBER768
  26881. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  26882. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_768, sizeof(ek_768)), 0);
  26883. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_768,
  26884. sizeof(seed_768)), 0);
  26885. ExpectIntEQ(XMEMCMP(ct, c_768, KYBER768_CIPHER_TEXT_SIZE), 0);
  26886. ExpectIntEQ(XMEMCMP(ss, k_768, KYBER_SS_SZ), 0);
  26887. wc_KyberKey_Free(key);
  26888. #endif
  26889. #ifndef WOLFSSL_NO_KYBER1024
  26890. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  26891. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_1024, sizeof(ek_1024)), 0);
  26892. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_1024,
  26893. sizeof(seed_1024)), 0);
  26894. ExpectIntEQ(XMEMCMP(ct, c_1024, KYBER1024_CIPHER_TEXT_SIZE), 0);
  26895. ExpectIntEQ(XMEMCMP(ss, k_1024, KYBER_SS_SZ), 0);
  26896. wc_KyberKey_Free(key);
  26897. #endif
  26898. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  26899. #endif
  26900. return EXPECT_RESULT();
  26901. }
  26902. static int test_wc_kyber_decapsulate_kats(void)
  26903. {
  26904. EXPECT_DECLS;
  26905. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  26906. !defined(WOLFSSL_KYBER_ORIGINAL)
  26907. KyberKey* key;
  26908. #ifndef WOLFSSL_NO_KYBER512
  26909. static const byte dk_512[KYBER512_PRIVATE_KEY_SIZE] = {
  26910. 0x69, 0xF9, 0xCB, 0xFD, 0x12, 0x37, 0xBA, 0x16,
  26911. 0x1C, 0xF6, 0xE6, 0xC1, 0x8F, 0x48, 0x8F, 0xC6,
  26912. 0xE3, 0x9A, 0xB4, 0xA5, 0xC9, 0xE6, 0xC2, 0x2E,
  26913. 0xA4, 0xE3, 0xAD, 0x8F, 0x26, 0x7A, 0x9C, 0x44,
  26914. 0x20, 0x10, 0xD3, 0x2E, 0x61, 0xF8, 0x3E, 0x6B,
  26915. 0xFA, 0x5C, 0x58, 0x70, 0x61, 0x45, 0x37, 0x6D,
  26916. 0xBB, 0x84, 0x95, 0x28, 0xF6, 0x80, 0x07, 0xC8,
  26917. 0x22, 0xB3, 0x3A, 0x95, 0xB8, 0x49, 0x04, 0xDC,
  26918. 0xD2, 0x70, 0x8D, 0x03, 0x40, 0xC8, 0xB8, 0x08,
  26919. 0xBC, 0xD3, 0xAA, 0xD0, 0xE4, 0x8B, 0x85, 0x84,
  26920. 0x95, 0x83, 0xA1, 0xB4, 0xE5, 0x94, 0x5D, 0xD9,
  26921. 0x51, 0x4A, 0x7F, 0x64, 0x61, 0xE0, 0x57, 0xB7,
  26922. 0xEC, 0xF6, 0x19, 0x57, 0xE9, 0x7C, 0xF6, 0x28,
  26923. 0x15, 0xF9, 0xC3, 0x22, 0x94, 0xB3, 0x26, 0xE1,
  26924. 0xA1, 0xC4, 0xE3, 0x60, 0xB9, 0x49, 0x8B, 0xA8,
  26925. 0x0F, 0x8C, 0xA9, 0x15, 0x32, 0xB1, 0x71, 0xD0,
  26926. 0xAE, 0xFC, 0x48, 0x49, 0xFA, 0x53, 0xBC, 0x61,
  26927. 0x79, 0x32, 0xE2, 0x08, 0xA6, 0x77, 0xC6, 0x04,
  26928. 0x4A, 0x66, 0x00, 0xB8, 0xD8, 0xB8, 0x3F, 0x26,
  26929. 0xA7, 0x47, 0xB1, 0x8C, 0xFB, 0x78, 0xBE, 0xAF,
  26930. 0xC5, 0x51, 0xAD, 0x52, 0xB7, 0xCA, 0x6C, 0xB8,
  26931. 0x8F, 0x3B, 0x5D, 0x9C, 0xE2, 0xAF, 0x6C, 0x67,
  26932. 0x95, 0x6C, 0x47, 0x8C, 0xEF, 0x49, 0x1F, 0x59,
  26933. 0xE0, 0x19, 0x1B, 0x3B, 0xBE, 0x92, 0x9B, 0x94,
  26934. 0xB6, 0x66, 0xC1, 0x76, 0x13, 0x8B, 0x00, 0xF4,
  26935. 0x97, 0x24, 0x34, 0x1E, 0xE2, 0xE1, 0x64, 0xB9,
  26936. 0x4C, 0x05, 0x3C, 0x18, 0x5A, 0x51, 0xF9, 0x3E,
  26937. 0x00, 0xF3, 0x68, 0x61, 0x61, 0x3A, 0x7F, 0xD7,
  26938. 0x2F, 0xEB, 0xD2, 0x3A, 0x8B, 0x96, 0xA2, 0x60,
  26939. 0x23, 0x42, 0x39, 0xC9, 0x62, 0x8F, 0x99, 0x5D,
  26940. 0xC1, 0x38, 0x07, 0xB4, 0x3A, 0x69, 0x46, 0x81,
  26941. 0x67, 0xCB, 0x1A, 0x8F, 0x9D, 0xD0, 0x7E, 0xE3,
  26942. 0xB3, 0x32, 0x38, 0xF6, 0x30, 0x96, 0xEB, 0xC4,
  26943. 0x9D, 0x50, 0x51, 0xC4, 0xB6, 0x59, 0x63, 0xD7,
  26944. 0x4A, 0x47, 0x66, 0xC2, 0x26, 0xF0, 0xB9, 0x4F,
  26945. 0x18, 0x62, 0xC2, 0x12, 0x4C, 0x8C, 0x74, 0x97,
  26946. 0x48, 0xC0, 0xBC, 0x4D, 0xC1, 0x4C, 0xB3, 0x49,
  26947. 0x06, 0xB8, 0x1C, 0x55, 0x24, 0xFB, 0x81, 0x00,
  26948. 0x79, 0x85, 0x42, 0xDC, 0x6C, 0xC2, 0xAA, 0x0A,
  26949. 0x70, 0x85, 0x75, 0xEA, 0xBC, 0xC1, 0x1F, 0x96,
  26950. 0xA9, 0xE6, 0x1C, 0x01, 0x7A, 0x96, 0xA7, 0xCE,
  26951. 0x93, 0xC4, 0x20, 0x91, 0x73, 0x71, 0x13, 0xAE,
  26952. 0x78, 0x3C, 0x0A, 0xE8, 0x75, 0x5E, 0x59, 0x41,
  26953. 0x11, 0xED, 0xFA, 0xBF, 0xD8, 0x6C, 0x32, 0x12,
  26954. 0xC6, 0x12, 0xA7, 0xB6, 0x2A, 0xFD, 0x3C, 0x7A,
  26955. 0x5C, 0x78, 0xB2, 0xF0, 0x73, 0x44, 0xB7, 0x89,
  26956. 0xC2, 0xB2, 0xDB, 0xB5, 0xF4, 0x44, 0x8B, 0xE9,
  26957. 0x7B, 0xBA, 0x42, 0x33, 0xC0, 0x03, 0x9C, 0x0F,
  26958. 0xE8, 0x43, 0x00, 0xF9, 0xB0, 0x3A, 0xC9, 0x94,
  26959. 0x97, 0xE6, 0xD4, 0x6B, 0x6E, 0x95, 0x30, 0x8F,
  26960. 0xF8, 0x47, 0x90, 0xF6, 0x12, 0xCF, 0x18, 0x6E,
  26961. 0xC1, 0x68, 0x11, 0xE8, 0x0C, 0x17, 0x93, 0x16,
  26962. 0xA6, 0x3B, 0x25, 0x70, 0x3F, 0x60, 0xB8, 0x42,
  26963. 0xB6, 0x19, 0x07, 0xE6, 0x28, 0x94, 0xE7, 0x36,
  26964. 0x64, 0x7B, 0x3C, 0x09, 0xDA, 0x6F, 0xEC, 0x59,
  26965. 0x32, 0x78, 0x2B, 0x36, 0xE0, 0x63, 0x50, 0x85,
  26966. 0xA3, 0x94, 0x9E, 0x69, 0x4D, 0x7E, 0x17, 0xCB,
  26967. 0xA3, 0xD9, 0x06, 0x43, 0x30, 0x43, 0x8C, 0x07,
  26968. 0x1B, 0x58, 0x36, 0xA7, 0x70, 0xC5, 0x5F, 0x62,
  26969. 0x13, 0xCC, 0x14, 0x25, 0x84, 0x5D, 0xE5, 0xA3,
  26970. 0x34, 0xD7, 0x5D, 0x3E, 0x50, 0x58, 0xC7, 0x80,
  26971. 0x9F, 0xDA, 0x4B, 0xCD, 0x78, 0x19, 0x1D, 0xA9,
  26972. 0x79, 0x73, 0x25, 0xE6, 0x23, 0x6C, 0x26, 0x50,
  26973. 0xFC, 0x60, 0x4E, 0xE4, 0x3A, 0x83, 0xCE, 0xB3,
  26974. 0x49, 0x80, 0x08, 0x44, 0x03, 0xA3, 0x32, 0x59,
  26975. 0x85, 0x79, 0x07, 0x79, 0x9A, 0x9D, 0x2A, 0x71,
  26976. 0x3A, 0x63, 0x3B, 0x5C, 0x90, 0x47, 0x27, 0xF6,
  26977. 0x1E, 0x42, 0x52, 0x09, 0x91, 0xD6, 0x55, 0x70,
  26978. 0x5C, 0xB6, 0xBC, 0x1B, 0x74, 0xAF, 0x60, 0x71,
  26979. 0x3E, 0xF8, 0x71, 0x2F, 0x14, 0x08, 0x68, 0x69,
  26980. 0xBE, 0x8E, 0xB2, 0x97, 0xD2, 0x28, 0xB3, 0x25,
  26981. 0xA0, 0x60, 0x9F, 0xD6, 0x15, 0xEA, 0xB7, 0x08,
  26982. 0x15, 0x40, 0xA6, 0x1A, 0x82, 0xAB, 0xF4, 0x3B,
  26983. 0x7D, 0xF9, 0x8A, 0x59, 0x5B, 0xE1, 0x1F, 0x41,
  26984. 0x6B, 0x41, 0xE1, 0xEB, 0x75, 0xBB, 0x57, 0x97,
  26985. 0x7C, 0x25, 0xC6, 0x4E, 0x97, 0x43, 0x7D, 0x88,
  26986. 0xCA, 0x5F, 0xDA, 0x61, 0x59, 0xD6, 0x68, 0xF6,
  26987. 0xBA, 0xB8, 0x15, 0x75, 0x55, 0xB5, 0xD5, 0x4C,
  26988. 0x0F, 0x47, 0xCB, 0xCD, 0x16, 0x84, 0x3B, 0x1A,
  26989. 0x0A, 0x0F, 0x02, 0x10, 0xEE, 0x31, 0x03, 0x13,
  26990. 0x96, 0x7F, 0x3D, 0x51, 0x64, 0x99, 0x01, 0x8F,
  26991. 0xDF, 0x31, 0x14, 0x77, 0x24, 0x70, 0xA1, 0x88,
  26992. 0x9C, 0xC0, 0x6C, 0xB6, 0xB6, 0x69, 0x0A, 0xC3,
  26993. 0x1A, 0xBC, 0xFA, 0xF4, 0xBC, 0x70, 0x76, 0x84,
  26994. 0x54, 0x5B, 0x00, 0x0B, 0x58, 0x0C, 0xCB, 0xFC,
  26995. 0xBC, 0xE9, 0xFA, 0x70, 0xAA, 0xEA, 0x0B, 0xBD,
  26996. 0x91, 0x10, 0x99, 0x2A, 0x7C, 0x6C, 0x06, 0xCB,
  26997. 0x36, 0x85, 0x27, 0xFD, 0x22, 0x90, 0x90, 0x75,
  26998. 0x7E, 0x6F, 0xE7, 0x57, 0x05, 0xFA, 0x59, 0x2A,
  26999. 0x76, 0x08, 0xF0, 0x50, 0xC6, 0xF8, 0x87, 0x03,
  27000. 0xCC, 0x28, 0xCB, 0x00, 0x0C, 0x1D, 0x7E, 0x77,
  27001. 0xB8, 0x97, 0xB7, 0x2C, 0x62, 0xBC, 0xC7, 0xAE,
  27002. 0xA2, 0x1A, 0x57, 0x72, 0x94, 0x83, 0xD2, 0x21,
  27003. 0x18, 0x32, 0xBE, 0xD6, 0x12, 0x43, 0x0C, 0x98,
  27004. 0x31, 0x03, 0xC6, 0x9E, 0x8C, 0x07, 0x2C, 0x0E,
  27005. 0xA7, 0x89, 0x8F, 0x22, 0x83, 0xBE, 0xC4, 0x8C,
  27006. 0x5A, 0xC8, 0x19, 0x84, 0xD4, 0xA5, 0xA8, 0x36,
  27007. 0x19, 0x73, 0x5A, 0x84, 0x2B, 0xD1, 0x72, 0xC0,
  27008. 0xD1, 0xB3, 0x9F, 0x43, 0x58, 0x8A, 0xF1, 0x70,
  27009. 0x45, 0x8B, 0xA9, 0xEE, 0x74, 0x92, 0xEA, 0xAA,
  27010. 0x94, 0xEA, 0x53, 0xA4, 0xD3, 0x84, 0x98, 0xEC,
  27011. 0xBB, 0x98, 0xA5, 0xF4, 0x07, 0xE7, 0xC9, 0x7B,
  27012. 0x4E, 0x16, 0x6E, 0x39, 0x71, 0x92, 0xC2, 0x16,
  27013. 0x03, 0x30, 0x14, 0xB8, 0x78, 0xE9, 0x38, 0x07,
  27014. 0x5C, 0x6C, 0x1F, 0x10, 0xA0, 0x06, 0x5A, 0xBC,
  27015. 0x31, 0x63, 0x72, 0x2F, 0x1A, 0x2E, 0xFF, 0xEC,
  27016. 0x8D, 0x6E, 0x3A, 0x0C, 0x4F, 0x71, 0x74, 0xFC,
  27017. 0x16, 0xB7, 0x9F, 0xB5, 0x18, 0x6A, 0x75, 0x16,
  27018. 0x8F, 0x81, 0xA5, 0x6A, 0xA4, 0x8A, 0x20, 0xA0,
  27019. 0x4B, 0xDD, 0xF1, 0x82, 0xC6, 0xE1, 0x79, 0xC3,
  27020. 0xF6, 0x90, 0x61, 0x55, 0x5E, 0xF7, 0x39, 0x6D,
  27021. 0xD0, 0xB7, 0x49, 0x96, 0x01, 0xA6, 0xEB, 0x3A,
  27022. 0x96, 0xA9, 0xA2, 0x2D, 0x04, 0xF1, 0x16, 0x8D,
  27023. 0xB5, 0x63, 0x55, 0xB0, 0x76, 0x00, 0xA2, 0x03,
  27024. 0x70, 0x63, 0x7B, 0x64, 0x59, 0x76, 0xBB, 0xD9,
  27025. 0x7B, 0x6D, 0x62, 0x88, 0xA0, 0xD3, 0x03, 0x63,
  27026. 0x60, 0x47, 0x2E, 0x3A, 0xC7, 0x1D, 0x56, 0x6D,
  27027. 0xB8, 0xFB, 0xB1, 0xB1, 0xD7, 0x6C, 0xB7, 0x55,
  27028. 0xCD, 0x0D, 0x68, 0xBD, 0xBF, 0xC0, 0x48, 0xEB,
  27029. 0xA2, 0x52, 0x5E, 0xEA, 0x9D, 0xD5, 0xB1, 0x44,
  27030. 0xFB, 0x3B, 0x60, 0xFB, 0xC3, 0x42, 0x39, 0x32,
  27031. 0x0C, 0xBC, 0x06, 0x9B, 0x35, 0xAB, 0x16, 0xB8,
  27032. 0x75, 0x65, 0x36, 0xFB, 0x33, 0xE8, 0xA6, 0xAF,
  27033. 0x1D, 0xD4, 0x2C, 0x79, 0xF4, 0x8A, 0xD1, 0x20,
  27034. 0xAE, 0x4B, 0x15, 0x9D, 0x3D, 0x8C, 0x31, 0x90,
  27035. 0x60, 0xCC, 0xE5, 0x69, 0xC3, 0xF6, 0x03, 0x53,
  27036. 0x65, 0x58, 0x5D, 0x34, 0x41, 0x37, 0x95, 0xA6,
  27037. 0xA1, 0x8E, 0xC5, 0x13, 0x6A, 0xB1, 0x3C, 0x90,
  27038. 0xE3, 0xAF, 0x14, 0xC0, 0xB8, 0xA4, 0x64, 0xC8,
  27039. 0x6B, 0x90, 0x73, 0x22, 0x2B, 0x56, 0xB3, 0xF7,
  27040. 0x32, 0x8A, 0xEA, 0x79, 0x81, 0x55, 0x32, 0x59,
  27041. 0x11, 0x25, 0x0E, 0xF0, 0x16, 0xD7, 0x28, 0x02,
  27042. 0xE3, 0x87, 0x8A, 0xA5, 0x05, 0x40, 0xCC, 0x98,
  27043. 0x39, 0x56, 0x97, 0x1D, 0x6E, 0xFA, 0x35, 0x2C,
  27044. 0x02, 0x55, 0x4D, 0xC7, 0x60, 0xA5, 0xA9, 0x13,
  27045. 0x58, 0xEA, 0x56, 0x37, 0x08, 0x84, 0xFD, 0x5B,
  27046. 0x3F, 0x85, 0xB7, 0x0E, 0x83, 0xE4, 0x69, 0x7D,
  27047. 0xEB, 0x17, 0x05, 0x16, 0x9E, 0x9C, 0x60, 0xA7,
  27048. 0x45, 0x28, 0xCF, 0x15, 0x28, 0x1C, 0xB1, 0xB1,
  27049. 0xC4, 0x57, 0xD4, 0x67, 0xB5, 0xF9, 0x3A, 0x60,
  27050. 0x37, 0x3D, 0x10, 0xE0, 0xCF, 0x6A, 0x83, 0x7A,
  27051. 0xA3, 0xC9, 0x59, 0x6A, 0x72, 0xBE, 0xC2, 0x9B,
  27052. 0x2D, 0x7E, 0x58, 0x65, 0x3D, 0x53, 0x30, 0x61,
  27053. 0xD3, 0x81, 0xD5, 0x17, 0x59, 0x75, 0x22, 0x17,
  27054. 0xEB, 0x46, 0xCA, 0xC7, 0x80, 0x7C, 0x4A, 0xD3,
  27055. 0x8B, 0x61, 0x16, 0x44, 0xAC, 0xF0, 0xA3, 0xF2,
  27056. 0x6B, 0x6B, 0x08, 0x4A, 0xB4, 0x7A, 0x83, 0xBF,
  27057. 0x0D, 0x69, 0x6F, 0x8A, 0x47, 0x68, 0xFC, 0x35,
  27058. 0xBC, 0xA6, 0xBC, 0x79, 0x03, 0xB2, 0xA2, 0x37,
  27059. 0xC2, 0x77, 0x49, 0xF5, 0x51, 0x0C, 0x86, 0x38,
  27060. 0x69, 0xE6, 0xAE, 0x56, 0xBB, 0x2A, 0xFE, 0x47,
  27061. 0x71, 0xC9, 0x22, 0x18, 0x74, 0xF5, 0x0F, 0x5B,
  27062. 0x14, 0xBA, 0xAD, 0x59, 0x93, 0xB4, 0x92, 0x38,
  27063. 0xFD, 0x0A, 0x0C, 0x9F, 0x79, 0xB7, 0xB4, 0x58,
  27064. 0x4E, 0x41, 0x30, 0x1F, 0x7A, 0x88, 0x5C, 0x9F,
  27065. 0x91, 0x81, 0x9B, 0xEA, 0x00, 0xD5, 0x12, 0x58,
  27066. 0x17, 0x30, 0x53, 0x9F, 0xB3, 0x7E, 0x59, 0xE8,
  27067. 0x6A, 0x6D, 0x19, 0xCA, 0x25, 0xF0, 0xA8, 0x11,
  27068. 0xC9, 0xB4, 0x28, 0xBA, 0x86, 0x14, 0xAA, 0x4F,
  27069. 0x94, 0x80, 0x7B, 0xC0, 0x31, 0xCB, 0xCC, 0x18,
  27070. 0x3F, 0x3B, 0xF0, 0x7F, 0xE2, 0xC1, 0xA6, 0xEB,
  27071. 0xA8, 0x0D, 0x5A, 0x70, 0x6E, 0xE0, 0xDA, 0xB2,
  27072. 0x7E, 0x23, 0x14, 0x58, 0x02, 0x5D, 0x84, 0xA7,
  27073. 0xA9, 0xB0, 0x23, 0x05, 0x01, 0x11, 0x6C, 0x29,
  27074. 0x0A, 0x6B, 0xB5, 0x06, 0x26, 0xD9, 0x7B, 0x93,
  27075. 0x98, 0x50, 0x94, 0x28, 0x28, 0x39, 0x0B, 0x0A,
  27076. 0x20, 0x01, 0xB7, 0x85, 0x3A, 0xD1, 0xAE, 0x9B,
  27077. 0x01, 0x1B, 0x2D, 0xB3, 0x6C, 0xAE, 0xEA, 0x73,
  27078. 0xA2, 0x32, 0x8E, 0x3C, 0x56, 0x48, 0x5B, 0x49,
  27079. 0x1C, 0x29, 0x91, 0x15, 0xA0, 0x17, 0xC9, 0x07,
  27080. 0xAB, 0x54, 0x31, 0x72, 0x60, 0xA5, 0x93, 0xA0,
  27081. 0xD7, 0xBA, 0x6D, 0x06, 0x61, 0x5D, 0x6E, 0x2C,
  27082. 0xA8, 0x4B, 0x86, 0x0E, 0xFF, 0x3C, 0xCB, 0x59,
  27083. 0x72, 0x11, 0xBF, 0xE3, 0x6B, 0xDE, 0xF8, 0x06,
  27084. 0x9A, 0xFA, 0x36, 0xC5, 0xA7, 0x33, 0x92, 0x72,
  27085. 0x26, 0x50, 0xE4, 0x95, 0x7D, 0xCA, 0x59, 0x7A,
  27086. 0xCB, 0xA5, 0x60, 0x5B, 0x63, 0xC1, 0x63, 0xCF,
  27087. 0xA9, 0x4B, 0x64, 0xDD, 0xD6, 0x23, 0x01, 0xA4,
  27088. 0x33, 0x20, 0x83, 0x36, 0x19, 0x72, 0x58, 0x9D,
  27089. 0xB0, 0x59, 0x9A, 0x69, 0x4D, 0xD4, 0x54, 0x7A,
  27090. 0x5E, 0xE9, 0x19, 0x65, 0x77, 0xC2, 0x2E, 0xD4,
  27091. 0x27, 0xAC, 0x89, 0xBB, 0x8B, 0xA3, 0x75, 0x3E,
  27092. 0xB7, 0x6C, 0x41, 0xF2, 0xC1, 0x12, 0x9C, 0x8A,
  27093. 0x77, 0xD6, 0x80, 0x5F, 0xA7, 0x19, 0xB1, 0xB6,
  27094. 0xCA, 0x11, 0xB7, 0x40, 0xA7, 0x8A, 0x3D, 0x41,
  27095. 0xB5, 0x33, 0x05, 0x26, 0xAB, 0x87, 0xD5, 0x8D,
  27096. 0x59, 0x25, 0x31, 0x5A, 0x14, 0x85, 0xED, 0xC6,
  27097. 0x47, 0xC1, 0x60, 0x4E, 0xB3, 0x81, 0x38, 0xDE,
  27098. 0x63, 0x7A, 0xD2, 0xC6, 0xCA, 0x5B, 0xE4, 0x4E,
  27099. 0x10, 0x08, 0xB2, 0xC0, 0x86, 0x7B, 0x22, 0x9C,
  27100. 0xCC, 0x36, 0x61, 0x9E, 0x27, 0x58, 0xC4, 0xC2,
  27101. 0x02, 0x9E, 0xAE, 0xB2, 0x6E, 0x7A, 0x80, 0x3F,
  27102. 0xCA, 0x30, 0x5A, 0x59, 0xCD, 0x58, 0x5E, 0x11,
  27103. 0x7D, 0x69, 0x8E, 0xCE, 0x01, 0x1C, 0xC3, 0xFC,
  27104. 0xE5, 0x4D, 0x2E, 0x11, 0x45, 0x45, 0xA2, 0x1A,
  27105. 0xC5, 0xBE, 0x67, 0x71, 0xAB, 0x8F, 0x13, 0x12,
  27106. 0x2F, 0xAD, 0x29, 0x5E, 0x74, 0x5A, 0x50, 0x3B,
  27107. 0x14, 0x2F, 0x91, 0xAE, 0xF7, 0xBD, 0xE9, 0x99,
  27108. 0x98, 0x84, 0x5F, 0xDA, 0x04, 0x35, 0x55, 0xC9,
  27109. 0xC1, 0xEE, 0x53, 0x5B, 0xE1, 0x25, 0xE5, 0xDC,
  27110. 0xE5, 0xD2, 0x66, 0x66, 0x7E, 0x72, 0x3E, 0x67,
  27111. 0xB6, 0xBA, 0x89, 0x1C, 0x16, 0xCB, 0xA1, 0x74,
  27112. 0x09, 0x8A, 0x3F, 0x35, 0x17, 0x78, 0xB0, 0x88,
  27113. 0x8C, 0x95, 0x90, 0xA9, 0x09, 0x0C, 0xD4, 0x04
  27114. };
  27115. static const byte c_512[KYBER512_CIPHER_TEXT_SIZE] = {
  27116. 0x16, 0x1C, 0xD2, 0x59, 0xFE, 0xAA, 0x7E, 0xC6,
  27117. 0xB2, 0x86, 0x49, 0x8A, 0x9A, 0x6F, 0x69, 0xF8,
  27118. 0xB2, 0x62, 0xA2, 0xE2, 0x09, 0x3D, 0x0F, 0xBD,
  27119. 0x76, 0xD5, 0xDC, 0x1C, 0x9F, 0xDE, 0x0D, 0xED,
  27120. 0xB3, 0x65, 0x81, 0x00, 0x4C, 0xB4, 0x81, 0x12,
  27121. 0xF8, 0x52, 0xE7, 0xF8, 0x7F, 0x64, 0x9E, 0x8A,
  27122. 0x42, 0xCD, 0x9E, 0x03, 0x49, 0xE7, 0xDA, 0xBD,
  27123. 0xF0, 0xA9, 0xAC, 0x1B, 0x52, 0x1C, 0x37, 0xEA,
  27124. 0x52, 0x41, 0x37, 0x0A, 0x8A, 0xB2, 0x91, 0x1C,
  27125. 0xC7, 0x99, 0x02, 0xC9, 0x5D, 0x28, 0x22, 0x4F,
  27126. 0xA8, 0x89, 0x6A, 0xD7, 0x15, 0x20, 0x9E, 0xCD,
  27127. 0xD5, 0xD7, 0x84, 0xE9, 0x1D, 0xD9, 0xD0, 0xBE,
  27128. 0x91, 0x6B, 0x45, 0x65, 0xF4, 0xD5, 0x66, 0x9A,
  27129. 0xEE, 0x0D, 0xEF, 0x93, 0x1E, 0x97, 0x68, 0x29,
  27130. 0x4E, 0xEC, 0x52, 0x58, 0xDE, 0x83, 0x91, 0xEC,
  27131. 0xE2, 0x71, 0xE7, 0xE4, 0xCF, 0xD9, 0xD2, 0x3A,
  27132. 0x79, 0xFA, 0xC3, 0xA8, 0xE0, 0xDB, 0x5D, 0xDD,
  27133. 0x6E, 0x01, 0x07, 0x23, 0x56, 0x88, 0xBB, 0xDF,
  27134. 0x7B, 0xC5, 0xD5, 0x63, 0x2F, 0x20, 0x6C, 0x63,
  27135. 0xA0, 0xC9, 0x56, 0x4F, 0x30, 0x96, 0x5C, 0xA5,
  27136. 0x8C, 0x69, 0xFF, 0x92, 0xD2, 0x5A, 0x4F, 0x93,
  27137. 0xA0, 0x9E, 0xAB, 0x9B, 0x90, 0x85, 0x94, 0x7E,
  27138. 0x07, 0x8A, 0x23, 0xE4, 0xD9, 0xC1, 0x3B, 0x8A,
  27139. 0x56, 0xE7, 0x3E, 0x18, 0xDF, 0x42, 0xD6, 0x94,
  27140. 0x9F, 0xAF, 0x59, 0x21, 0xF2, 0xE3, 0x73, 0xD4,
  27141. 0x50, 0xC8, 0xC0, 0x9D, 0x07, 0xB1, 0x52, 0xA9,
  27142. 0x7C, 0x24, 0x54, 0x47, 0x42, 0x94, 0x81, 0xD4,
  27143. 0x98, 0xBE, 0xB7, 0x25, 0x6B, 0xC4, 0x7F, 0x68,
  27144. 0xF9, 0x92, 0x2B, 0x0B, 0x1C, 0x62, 0xD9, 0xC2,
  27145. 0x3F, 0x9F, 0x73, 0x3D, 0xD7, 0x37, 0x92, 0xCF,
  27146. 0xC7, 0xB4, 0x3C, 0xBC, 0xEA, 0x27, 0x7D, 0x51,
  27147. 0xB2, 0xB8, 0xAD, 0x4A, 0x4F, 0x52, 0x2F, 0x64,
  27148. 0x2C, 0xAD, 0x5C, 0x5D, 0xEB, 0x21, 0xF3, 0x62,
  27149. 0x7F, 0x8A, 0xF4, 0xD3, 0xE5, 0xBC, 0x9E, 0x91,
  27150. 0xD4, 0xCB, 0x2F, 0x12, 0x4B, 0x5B, 0xD7, 0xC2,
  27151. 0xF4, 0xA0, 0x50, 0xCA, 0x75, 0x5B, 0xDB, 0x80,
  27152. 0x56, 0x60, 0x96, 0x63, 0xFB, 0x95, 0x11, 0xC9,
  27153. 0xAD, 0x83, 0xB5, 0x03, 0x90, 0x88, 0xCC, 0x01,
  27154. 0xF0, 0xDD, 0x54, 0x35, 0x3B, 0x0D, 0xD7, 0x43,
  27155. 0x3F, 0x0C, 0x6C, 0xEE, 0x0D, 0x07, 0x59, 0x59,
  27156. 0x81, 0x0D, 0xEC, 0x54, 0x16, 0x52, 0x2B, 0xB1,
  27157. 0xF1, 0xF6, 0x55, 0x47, 0xA0, 0xC2, 0xE9, 0xCC,
  27158. 0x9B, 0xC1, 0x7F, 0x8D, 0x39, 0xD2, 0x93, 0x09,
  27159. 0xEB, 0xE7, 0x9F, 0x21, 0x33, 0x1B, 0x75, 0xE1,
  27160. 0x2A, 0xF2, 0xE9, 0x3F, 0x03, 0xF7, 0x4F, 0x7F,
  27161. 0x87, 0xD3, 0x60, 0xF1, 0xDA, 0xF8, 0x6C, 0xED,
  27162. 0x73, 0x60, 0x92, 0xA2, 0x11, 0xA8, 0x15, 0x88,
  27163. 0x59, 0xC4, 0x2E, 0x22, 0x3C, 0xFE, 0x2E, 0x6E,
  27164. 0x55, 0x34, 0x37, 0xD8, 0x05, 0x76, 0xCF, 0xD1,
  27165. 0x94, 0x4E, 0x97, 0xEE, 0xFF, 0x9B, 0x49, 0xE5,
  27166. 0xEC, 0xCF, 0xC6, 0x78, 0xEE, 0x16, 0x52, 0x68,
  27167. 0xDF, 0xE3, 0xD3, 0x59, 0x6B, 0x4B, 0x86, 0x20,
  27168. 0x4A, 0x81, 0xC6, 0x06, 0x3B, 0x0C, 0xDC, 0xE6,
  27169. 0x19, 0xFD, 0xBB, 0x96, 0xDF, 0x7D, 0xE6, 0xE0,
  27170. 0xBD, 0x52, 0x70, 0xB4, 0xD5, 0x9C, 0x4D, 0xC5,
  27171. 0x08, 0x47, 0x6E, 0x7F, 0x07, 0x08, 0xF9, 0x8C,
  27172. 0x7A, 0x4F, 0x66, 0x45, 0xC4, 0x9D, 0x06, 0x10,
  27173. 0x0C, 0x76, 0x0C, 0x59, 0x95, 0x28, 0xD1, 0xB8,
  27174. 0xBB, 0xFE, 0x62, 0x81, 0x91, 0xCC, 0x08, 0x3C,
  27175. 0x8D, 0x22, 0x5A, 0x09, 0x3F, 0x9F, 0x17, 0xE3,
  27176. 0x55, 0x74, 0x98, 0x6F, 0x86, 0xBA, 0xA4, 0x68,
  27177. 0x98, 0xB5, 0x89, 0xF3, 0xCB, 0x7D, 0xB4, 0x6A,
  27178. 0x45, 0xF3, 0xED, 0xD4, 0xFA, 0xC2, 0x08, 0x08,
  27179. 0xF4, 0xCD, 0x02, 0x49, 0xDA, 0x69, 0x3F, 0x8F,
  27180. 0xAB, 0xFB, 0xD4, 0xE1, 0x0C, 0x02, 0xC6, 0x5B,
  27181. 0xA8, 0xC8, 0x61, 0x0F, 0xA8, 0xC6, 0xDF, 0x3D,
  27182. 0xBA, 0xEB, 0x67, 0x63, 0xDD, 0x48, 0x2A, 0xF4,
  27183. 0x15, 0x58, 0xB1, 0xE1, 0x5C, 0xC9, 0xC7, 0xA7,
  27184. 0x2E, 0x07, 0x16, 0x85, 0xAC, 0x19, 0xA0, 0x51,
  27185. 0xF1, 0x92, 0x45, 0xB9, 0xF7, 0x7C, 0x30, 0x38,
  27186. 0xA5, 0x4E, 0x29, 0x58, 0x62, 0x3E, 0xB8, 0x10,
  27187. 0x59, 0x55, 0x60, 0x9E, 0x27, 0xD6, 0x7C, 0xF7,
  27188. 0x2E, 0xC5, 0xC4, 0xA8, 0xE9, 0xB9, 0xC2, 0x92,
  27189. 0x4A, 0x9E, 0x22, 0x98, 0x50, 0x8B, 0xAB, 0xA1,
  27190. 0x3C, 0xF1, 0x11, 0xFD, 0xFB, 0x06, 0x2C, 0x96,
  27191. 0x07, 0xAC, 0x1A, 0xAA, 0x6C, 0x63, 0x73, 0x10,
  27192. 0xA8, 0x89, 0x4B, 0xF0, 0xB9, 0x6F, 0x0C, 0x19,
  27193. 0x13, 0x61, 0x86, 0xB6, 0x18, 0xDF, 0xFB, 0x27,
  27194. 0x55, 0x28, 0xBE, 0xD1, 0xCC, 0x27, 0x15, 0xDE,
  27195. 0xF4, 0x12, 0xF7, 0x7A, 0x3C, 0xF9, 0x66, 0x45,
  27196. 0x73, 0x3B, 0x04, 0x8A, 0x78, 0x47, 0x43, 0x20,
  27197. 0xD1, 0xA3, 0x80, 0xF5, 0xEE, 0xDB, 0xDA, 0x21,
  27198. 0xFA, 0x01, 0x25, 0xC9, 0x1D, 0x3C, 0x37, 0xC5,
  27199. 0x4B, 0xF3, 0x75, 0x2A, 0x1F, 0x84, 0x71, 0xC8,
  27200. 0x1F, 0xCA, 0xE2, 0xD3, 0xED, 0xA9, 0x66, 0xE1,
  27201. 0x4E, 0x66, 0xF2, 0x23, 0xB0, 0x54, 0xD7, 0x98,
  27202. 0x48, 0xFF, 0x94, 0x11, 0xD6, 0x34, 0x02, 0x4A,
  27203. 0x09, 0x89, 0x70, 0xAD, 0xE6, 0xA8, 0x8B, 0x5F,
  27204. 0x90, 0x69, 0xF7, 0x60, 0x58, 0x4D, 0xC4, 0xCF,
  27205. 0xFF, 0xCE, 0xA8, 0xEC, 0xE1, 0x1B, 0xB5, 0x56,
  27206. 0x6B, 0xD2, 0x36, 0x0A, 0xB7, 0x07, 0xDF, 0x2D,
  27207. 0x21, 0xB6, 0x74, 0x88, 0xD9, 0x31, 0xF0, 0x20,
  27208. 0x06, 0x91, 0x76, 0x42, 0x3E, 0x69, 0x44, 0x49,
  27209. 0x0C, 0xB3, 0x85, 0xE7, 0x0B, 0x35, 0x8A, 0x25,
  27210. 0x34, 0x6B, 0xAF, 0xCD, 0xD0, 0x6D, 0x40, 0x2F,
  27211. 0xF2, 0x4D, 0x6C, 0x1E, 0x5F, 0x61, 0xA8, 0x5D
  27212. };
  27213. static const byte kprime_512[KYBER_SS_SZ] = {
  27214. 0xDF, 0x46, 0x2A, 0xD6, 0x8F, 0x1E, 0xC8, 0x97,
  27215. 0x2E, 0xD9, 0xB0, 0x2D, 0x6D, 0xE0, 0x60, 0x4B,
  27216. 0xDE, 0xC7, 0x57, 0x20, 0xE0, 0x50, 0x49, 0x73,
  27217. 0x51, 0xE6, 0xEC, 0x93, 0x3E, 0x71, 0xF8, 0x82
  27218. };
  27219. #endif
  27220. #ifndef WOLFSSL_NO_KYBER768
  27221. static const byte dk_768[KYBER768_PRIVATE_KEY_SIZE] = {
  27222. 0x1E, 0x4A, 0xC8, 0x7B, 0x1A, 0x69, 0x2A, 0x52,
  27223. 0x9F, 0xDB, 0xBA, 0xB9, 0x33, 0x74, 0xC5, 0x7D,
  27224. 0x11, 0x0B, 0x10, 0xF2, 0xB1, 0xDD, 0xEB, 0xAC,
  27225. 0x0D, 0x19, 0x6B, 0x7B, 0xA6, 0x31, 0xB8, 0xE9,
  27226. 0x29, 0x30, 0x28, 0xA8, 0xF3, 0x79, 0x88, 0x8C,
  27227. 0x42, 0x2D, 0xC8, 0xD3, 0x2B, 0xBF, 0x22, 0x60,
  27228. 0x10, 0xC2, 0xC1, 0xEC, 0x73, 0x18, 0x90, 0x80,
  27229. 0x45, 0x6B, 0x05, 0x64, 0xB2, 0x58, 0xB0, 0xF2,
  27230. 0x31, 0x31, 0xBC, 0x79, 0xC8, 0xE8, 0xC1, 0x1C,
  27231. 0xEF, 0x39, 0x38, 0xB2, 0x43, 0xC5, 0xCE, 0x9C,
  27232. 0x0E, 0xDD, 0x37, 0xC8, 0xF9, 0xD2, 0x98, 0x77,
  27233. 0xDB, 0xBB, 0x61, 0x5B, 0x9B, 0x5A, 0xC3, 0xC9,
  27234. 0x48, 0x48, 0x7E, 0x46, 0x71, 0x96, 0xA9, 0x14,
  27235. 0x3E, 0xFB, 0xC7, 0xCE, 0xDB, 0x64, 0xB4, 0x5D,
  27236. 0x4A, 0xCD, 0xA2, 0x66, 0x6C, 0xBC, 0x28, 0x04,
  27237. 0xF2, 0xC8, 0x66, 0x2E, 0x12, 0x8F, 0x6A, 0x99,
  27238. 0x69, 0xEC, 0x15, 0xBC, 0x0B, 0x93, 0x51, 0xF6,
  27239. 0xF9, 0x63, 0x46, 0xAA, 0x7A, 0xBC, 0x74, 0x3A,
  27240. 0x14, 0xFA, 0x03, 0x0E, 0x37, 0xA2, 0xE7, 0x59,
  27241. 0x7B, 0xDD, 0xFC, 0x5A, 0x22, 0xF9, 0xCE, 0xDA,
  27242. 0xF8, 0x61, 0x48, 0x32, 0x52, 0x72, 0x10, 0xB2,
  27243. 0x6F, 0x02, 0x4C, 0x7F, 0x6C, 0x0D, 0xCF, 0x55,
  27244. 0x1E, 0x97, 0xA4, 0x85, 0x87, 0x64, 0xC3, 0x21,
  27245. 0xD1, 0x83, 0x4A, 0xD5, 0x1D, 0x75, 0xBB, 0x24,
  27246. 0x6D, 0x27, 0x72, 0x37, 0xB7, 0xBD, 0x41, 0xDC,
  27247. 0x43, 0x62, 0xD0, 0x63, 0xF4, 0x29, 0x82, 0x92,
  27248. 0x27, 0x2D, 0x01, 0x01, 0x17, 0x80, 0xB7, 0x98,
  27249. 0x56, 0xB2, 0x96, 0xC4, 0xE9, 0x46, 0x65, 0x8B,
  27250. 0x79, 0x60, 0x31, 0x97, 0xC9, 0xB2, 0xA9, 0x9E,
  27251. 0xC6, 0x6A, 0xCB, 0x06, 0xCE, 0x2F, 0x69, 0xB5,
  27252. 0xA5, 0xA6, 0x1E, 0x9B, 0xD0, 0x6A, 0xD4, 0x43,
  27253. 0xCE, 0xB0, 0xC7, 0x4E, 0xD6, 0x53, 0x45, 0xA9,
  27254. 0x03, 0xB6, 0x14, 0xE8, 0x13, 0x68, 0xAA, 0xC2,
  27255. 0xB3, 0xD2, 0xA7, 0x9C, 0xA8, 0xCC, 0xAA, 0x1C,
  27256. 0x3B, 0x88, 0xFB, 0x82, 0xA3, 0x66, 0x32, 0x86,
  27257. 0x0B, 0x3F, 0x79, 0x50, 0x83, 0x3F, 0xD0, 0x21,
  27258. 0x2E, 0xC9, 0x6E, 0xDE, 0x4A, 0xB6, 0xF5, 0xA0,
  27259. 0xBD, 0xA3, 0xEC, 0x60, 0x60, 0xA6, 0x58, 0xF9,
  27260. 0x45, 0x7F, 0x6C, 0xC8, 0x7C, 0x6B, 0x62, 0x0C,
  27261. 0x1A, 0x14, 0x51, 0x98, 0x74, 0x86, 0xE4, 0x96,
  27262. 0x61, 0x2A, 0x10, 0x1D, 0x0E, 0x9C, 0x20, 0x57,
  27263. 0x7C, 0x57, 0x1E, 0xDB, 0x52, 0x82, 0x60, 0x8B,
  27264. 0xF4, 0xE1, 0xAC, 0x92, 0x6C, 0x0D, 0xB1, 0xC8,
  27265. 0x2A, 0x50, 0x4A, 0x79, 0x9D, 0x89, 0x88, 0x5C,
  27266. 0xA6, 0x25, 0x2B, 0xD5, 0xB1, 0xC1, 0x83, 0xAF,
  27267. 0x70, 0x13, 0x92, 0xA4, 0x07, 0xC0, 0x5B, 0x84,
  27268. 0x8C, 0x2A, 0x30, 0x16, 0xC4, 0x06, 0x13, 0xF0,
  27269. 0x2A, 0x44, 0x9B, 0x3C, 0x79, 0x26, 0xDA, 0x06,
  27270. 0x7A, 0x53, 0x31, 0x16, 0x50, 0x68, 0x40, 0x09,
  27271. 0x75, 0x10, 0x46, 0x0B, 0xBF, 0xD3, 0x60, 0x73,
  27272. 0xDC, 0xB0, 0xBF, 0xA0, 0x09, 0xB3, 0x6A, 0x91,
  27273. 0x23, 0xEA, 0xA6, 0x8F, 0x83, 0x5F, 0x74, 0xA0,
  27274. 0x1B, 0x00, 0xD2, 0x09, 0x78, 0x35, 0x96, 0x4D,
  27275. 0xF5, 0x21, 0xCE, 0x92, 0x10, 0x78, 0x9C, 0x30,
  27276. 0xB7, 0xF0, 0x6E, 0x58, 0x44, 0xB4, 0x44, 0xC5,
  27277. 0x33, 0x22, 0x39, 0x6E, 0x47, 0x99, 0xBA, 0xF6,
  27278. 0xA8, 0x8A, 0xF7, 0x31, 0x58, 0x60, 0xD0, 0x19,
  27279. 0x2D, 0x48, 0xC2, 0xC0, 0xDA, 0x6B, 0x5B, 0xA6,
  27280. 0x43, 0x25, 0x54, 0x3A, 0xCD, 0xF5, 0x90, 0x0E,
  27281. 0x8B, 0xC4, 0x77, 0xAB, 0x05, 0x82, 0x00, 0x72,
  27282. 0xD4, 0x63, 0xAF, 0xFE, 0xD0, 0x97, 0xE0, 0x62,
  27283. 0xBD, 0x78, 0xC9, 0x9D, 0x12, 0xB3, 0x85, 0x13,
  27284. 0x1A, 0x24, 0x1B, 0x70, 0x88, 0x65, 0xB4, 0x19,
  27285. 0x0A, 0xF6, 0x9E, 0xA0, 0xA6, 0x4D, 0xB7, 0x14,
  27286. 0x48, 0xA6, 0x08, 0x29, 0x36, 0x9C, 0x75, 0x55,
  27287. 0x19, 0x8E, 0x43, 0x8C, 0x9A, 0xBC, 0x31, 0x0B,
  27288. 0xC7, 0x01, 0x01, 0x91, 0x3B, 0xB1, 0x2F, 0xAA,
  27289. 0x5B, 0xEE, 0xF9, 0x75, 0x84, 0x16, 0x17, 0xC8,
  27290. 0x47, 0xCD, 0x6B, 0x33, 0x6F, 0x87, 0x79, 0x87,
  27291. 0x75, 0x38, 0x22, 0x02, 0x0B, 0x92, 0xC4, 0xCC,
  27292. 0x97, 0x05, 0x5C, 0x9B, 0x1E, 0x0B, 0x12, 0x8B,
  27293. 0xF1, 0x1F, 0x50, 0x50, 0x05, 0xB6, 0xAB, 0x0E,
  27294. 0x62, 0x77, 0x95, 0xA2, 0x06, 0x09, 0xEF, 0xA9,
  27295. 0x91, 0xE5, 0x98, 0xB8, 0x0F, 0x37, 0xB1, 0xC6,
  27296. 0xA1, 0xC3, 0xA1, 0xE9, 0xAE, 0xE7, 0x02, 0x8F,
  27297. 0x77, 0x57, 0x0A, 0xB2, 0x13, 0x91, 0x28, 0xA0,
  27298. 0x01, 0x08, 0xC5, 0x0E, 0xB3, 0x05, 0xCD, 0xB8,
  27299. 0xF9, 0xA6, 0x03, 0xA6, 0xB0, 0x78, 0x41, 0x3F,
  27300. 0x6F, 0x9B, 0x14, 0xC6, 0xD8, 0x2B, 0x51, 0x99,
  27301. 0xCE, 0x59, 0xD8, 0x87, 0x90, 0x2A, 0x28, 0x1A,
  27302. 0x02, 0x7B, 0x71, 0x74, 0x95, 0xFE, 0x12, 0x67,
  27303. 0x2A, 0x12, 0x7B, 0xBF, 0x9B, 0x25, 0x6C, 0x43,
  27304. 0x72, 0x0D, 0x7C, 0x16, 0x0B, 0x28, 0x1C, 0x12,
  27305. 0x75, 0x7D, 0xA1, 0x35, 0xB1, 0x93, 0x33, 0x52,
  27306. 0xBE, 0x4A, 0xB6, 0x7E, 0x40, 0x24, 0x8A, 0xFC,
  27307. 0x31, 0x8E, 0x23, 0x70, 0xC3, 0xB8, 0x20, 0x8E,
  27308. 0x69, 0x5B, 0xDF, 0x33, 0x74, 0x59, 0xB9, 0xAC,
  27309. 0xBF, 0xE5, 0xB4, 0x87, 0xF7, 0x6E, 0x9B, 0x4B,
  27310. 0x40, 0x01, 0xD6, 0xCF, 0x90, 0xCA, 0x8C, 0x69,
  27311. 0x9A, 0x17, 0x4D, 0x42, 0x97, 0x2D, 0xC7, 0x33,
  27312. 0xF3, 0x33, 0x89, 0xFD, 0xF5, 0x9A, 0x1D, 0xAB,
  27313. 0xA8, 0x1D, 0x83, 0x49, 0x55, 0x02, 0x73, 0x34,
  27314. 0x18, 0x5A, 0xD0, 0x2C, 0x76, 0xCF, 0x29, 0x48,
  27315. 0x46, 0xCA, 0x92, 0x94, 0xBA, 0x0E, 0xD6, 0x67,
  27316. 0x41, 0xDD, 0xEC, 0x79, 0x1C, 0xAB, 0x34, 0x19,
  27317. 0x6A, 0xC5, 0x65, 0x7C, 0x5A, 0x78, 0x32, 0x1B,
  27318. 0x56, 0xC3, 0x33, 0x06, 0xB5, 0x10, 0x23, 0x97,
  27319. 0xA5, 0xC0, 0x9C, 0x35, 0x08, 0xF7, 0x6B, 0x48,
  27320. 0x28, 0x24, 0x59, 0xF8, 0x1D, 0x0C, 0x72, 0xA4,
  27321. 0x3F, 0x73, 0x7B, 0xC2, 0xF1, 0x2F, 0x45, 0x42,
  27322. 0x26, 0x28, 0xB6, 0x7D, 0xB5, 0x1A, 0xC1, 0x42,
  27323. 0x42, 0x76, 0xA6, 0xC0, 0x8C, 0x3F, 0x76, 0x15,
  27324. 0x66, 0x5B, 0xBB, 0x8E, 0x92, 0x81, 0x48, 0xA2,
  27325. 0x70, 0xF9, 0x91, 0xBC, 0xF3, 0x65, 0xA9, 0x0F,
  27326. 0x87, 0xC3, 0x06, 0x87, 0xB6, 0x88, 0x09, 0xC9,
  27327. 0x1F, 0x23, 0x18, 0x13, 0xB8, 0x66, 0xBE, 0xA8,
  27328. 0x2E, 0x30, 0x37, 0x4D, 0x80, 0xAA, 0x0C, 0x02,
  27329. 0x97, 0x34, 0x37, 0x49, 0x8A, 0x53, 0xB1, 0x4B,
  27330. 0xF6, 0xB6, 0xCA, 0x1E, 0xD7, 0x6A, 0xB8, 0xA2,
  27331. 0x0D, 0x54, 0xA0, 0x83, 0xF4, 0xA2, 0x6B, 0x7C,
  27332. 0x03, 0x8D, 0x81, 0x96, 0x76, 0x40, 0xC2, 0x0B,
  27333. 0xF4, 0x43, 0x1E, 0x71, 0xDA, 0xCC, 0xE8, 0x57,
  27334. 0x7B, 0x21, 0x24, 0x0E, 0x49, 0x4C, 0x31, 0xF2,
  27335. 0xD8, 0x77, 0xDA, 0xF4, 0x92, 0x4F, 0xD3, 0x9D,
  27336. 0x82, 0xD6, 0x16, 0x7F, 0xBC, 0xC1, 0xF9, 0xC5,
  27337. 0xA2, 0x59, 0xF8, 0x43, 0xE3, 0x09, 0x87, 0xCC,
  27338. 0xC4, 0xBC, 0xE7, 0x49, 0x3A, 0x24, 0x04, 0xB5,
  27339. 0xE4, 0x43, 0x87, 0xF7, 0x07, 0x42, 0x57, 0x81,
  27340. 0xB7, 0x43, 0xFB, 0x55, 0x56, 0x85, 0x58, 0x4E,
  27341. 0x25, 0x57, 0xCC, 0x03, 0x8B, 0x1A, 0x9B, 0x3F,
  27342. 0x40, 0x43, 0x12, 0x1F, 0x54, 0x72, 0xEB, 0x2B,
  27343. 0x96, 0xE5, 0x94, 0x1F, 0xEC, 0x01, 0x1C, 0xEE,
  27344. 0xA5, 0x07, 0x91, 0x63, 0x6C, 0x6A, 0xBC, 0x26,
  27345. 0xC1, 0x37, 0x7E, 0xE3, 0xB5, 0x14, 0x6F, 0xC7,
  27346. 0xC8, 0x5C, 0xB3, 0x35, 0xB1, 0xE7, 0x95, 0xEE,
  27347. 0xC2, 0x03, 0x3E, 0xE4, 0x4B, 0x9A, 0xA9, 0x06,
  27348. 0x85, 0x24, 0x5E, 0xF7, 0xB4, 0x43, 0x6C, 0x00,
  27349. 0x0E, 0x66, 0xBC, 0x8B, 0xCB, 0xF1, 0xCD, 0xB8,
  27350. 0x03, 0xAC, 0x14, 0x21, 0xB1, 0xFD, 0xB2, 0x66,
  27351. 0xD5, 0x29, 0x1C, 0x83, 0x10, 0x37, 0x3A, 0x8A,
  27352. 0x3C, 0xE9, 0x56, 0x2A, 0xB1, 0x97, 0x95, 0x38,
  27353. 0x71, 0xAB, 0x99, 0xF3, 0x82, 0xCC, 0x5A, 0xA9,
  27354. 0xC0, 0xF2, 0x73, 0xD1, 0xDC, 0xA5, 0x5D, 0x27,
  27355. 0x12, 0x85, 0x38, 0x71, 0xE1, 0xA8, 0x3C, 0xB3,
  27356. 0xB8, 0x54, 0x50, 0xF7, 0x6D, 0x3F, 0x3C, 0x42,
  27357. 0xBA, 0xB5, 0x50, 0x5F, 0x72, 0x12, 0xFD, 0xB6,
  27358. 0xB8, 0xB7, 0xF6, 0x02, 0x99, 0x72, 0xA8, 0xF3,
  27359. 0x75, 0x1E, 0x4C, 0x94, 0xC1, 0x10, 0x8B, 0x02,
  27360. 0xD6, 0xAC, 0x79, 0xF8, 0xD9, 0x38, 0xF0, 0x5A,
  27361. 0x1B, 0x2C, 0x22, 0x9B, 0x14, 0xB4, 0x2B, 0x31,
  27362. 0xB0, 0x1A, 0x36, 0x40, 0x17, 0xE5, 0x95, 0x78,
  27363. 0xC6, 0xB0, 0x33, 0x83, 0x37, 0x74, 0xCB, 0x9B,
  27364. 0x57, 0x0F, 0x90, 0x86, 0xB7, 0x22, 0x90, 0x3B,
  27365. 0x37, 0x54, 0x46, 0xB4, 0x95, 0xD8, 0xA2, 0x9B,
  27366. 0xF8, 0x07, 0x51, 0x87, 0x7A, 0x80, 0xFB, 0x72,
  27367. 0x4A, 0x02, 0x10, 0xC3, 0xE1, 0x69, 0x2F, 0x39,
  27368. 0x7C, 0x2F, 0x1D, 0xDC, 0x2E, 0x6B, 0xA1, 0x7A,
  27369. 0xF8, 0x1B, 0x92, 0xAC, 0xFA, 0xBE, 0xF5, 0xF7,
  27370. 0x57, 0x3C, 0xB4, 0x93, 0xD1, 0x84, 0x02, 0x7B,
  27371. 0x71, 0x82, 0x38, 0xC8, 0x9A, 0x35, 0x49, 0xB8,
  27372. 0x90, 0x5B, 0x28, 0xA8, 0x33, 0x62, 0x86, 0x7C,
  27373. 0x08, 0x2D, 0x30, 0x19, 0xD3, 0xCA, 0x70, 0x70,
  27374. 0x07, 0x31, 0xCE, 0xB7, 0x3E, 0x84, 0x72, 0xC1,
  27375. 0xA3, 0xA0, 0x93, 0x36, 0x1C, 0x5F, 0xEA, 0x6A,
  27376. 0x7D, 0x40, 0x95, 0x5D, 0x07, 0xA4, 0x1B, 0x64,
  27377. 0xE5, 0x00, 0x81, 0xA3, 0x61, 0xB6, 0x04, 0xCC,
  27378. 0x51, 0x84, 0x47, 0xC8, 0xE2, 0x57, 0x65, 0xAB,
  27379. 0x7D, 0x68, 0xB2, 0x43, 0x27, 0x52, 0x07, 0xAF,
  27380. 0x8C, 0xA6, 0x56, 0x4A, 0x4C, 0xB1, 0xE9, 0x41,
  27381. 0x99, 0xDB, 0xA1, 0x87, 0x8C, 0x59, 0xBE, 0xC8,
  27382. 0x09, 0xAB, 0x48, 0xB2, 0xF2, 0x11, 0xBA, 0xDC,
  27383. 0x6A, 0x19, 0x98, 0xD9, 0xC7, 0x22, 0x7C, 0x13,
  27384. 0x03, 0xF4, 0x69, 0xD4, 0x6A, 0x9C, 0x7E, 0x53,
  27385. 0x03, 0xF9, 0x8A, 0xBA, 0x67, 0x56, 0x9A, 0xE8,
  27386. 0x22, 0x7C, 0x16, 0xBA, 0x1F, 0xB3, 0x24, 0x44,
  27387. 0x66, 0xA2, 0x5E, 0x7F, 0x82, 0x36, 0x71, 0x81,
  27388. 0x0C, 0xC2, 0x62, 0x06, 0xFE, 0xB2, 0x9C, 0x7E,
  27389. 0x2A, 0x1A, 0x91, 0x95, 0x9E, 0xEB, 0x03, 0xA9,
  27390. 0x82, 0x52, 0xA4, 0xF7, 0x41, 0x26, 0x74, 0xEB,
  27391. 0x9A, 0x4B, 0x27, 0x7E, 0x1F, 0x25, 0x95, 0xFC,
  27392. 0xA6, 0x40, 0x33, 0xB4, 0x1B, 0x40, 0x33, 0x08,
  27393. 0x12, 0xE9, 0x73, 0x5B, 0x7C, 0x60, 0x75, 0x01,
  27394. 0xCD, 0x81, 0x83, 0xA2, 0x2A, 0xFC, 0x33, 0x92,
  27395. 0x55, 0x37, 0x44, 0xF3, 0x3C, 0x4D, 0x20, 0x25,
  27396. 0x26, 0x94, 0x5C, 0x6D, 0x78, 0xA6, 0x0E, 0x20,
  27397. 0x1A, 0x16, 0x98, 0x7A, 0x6F, 0xA5, 0x9D, 0x94,
  27398. 0x46, 0x4B, 0x56, 0x50, 0x65, 0x56, 0x78, 0x48,
  27399. 0x24, 0xA0, 0x70, 0x58, 0xF5, 0x73, 0x20, 0xE7,
  27400. 0x6C, 0x82, 0x5B, 0x93, 0x47, 0xF2, 0x93, 0x6F,
  27401. 0x4A, 0x0E, 0x5C, 0xDA, 0xA1, 0x8C, 0xF8, 0x83,
  27402. 0x39, 0x45, 0xAE, 0x31, 0x2A, 0x36, 0xB5, 0xF5,
  27403. 0xA3, 0x81, 0x0A, 0xAC, 0x82, 0x38, 0x1F, 0xDA,
  27404. 0xE4, 0xCB, 0x9C, 0x68, 0x31, 0xD8, 0xEB, 0x8A,
  27405. 0xBA, 0xB8, 0x50, 0x41, 0x64, 0x43, 0xD7, 0x39,
  27406. 0x08, 0x6B, 0x1C, 0x32, 0x6F, 0xC2, 0xA3, 0x97,
  27407. 0x57, 0x04, 0xE3, 0x96, 0xA5, 0x96, 0x80, 0xC3,
  27408. 0xB5, 0xF3, 0x60, 0xF5, 0x48, 0x0D, 0x2B, 0x62,
  27409. 0x16, 0x9C, 0xD9, 0x4C, 0xA7, 0x1B, 0x37, 0xBC,
  27410. 0x58, 0x78, 0xBA, 0x29, 0x85, 0xE0, 0x68, 0xBA,
  27411. 0x05, 0x0B, 0x2C, 0xE5, 0x07, 0x26, 0xD4, 0xB4,
  27412. 0x45, 0x1B, 0x77, 0xAA, 0xA8, 0x67, 0x6E, 0xAE,
  27413. 0x09, 0x49, 0x82, 0x21, 0x01, 0x92, 0x19, 0x7B,
  27414. 0x1E, 0x92, 0xA2, 0x7F, 0x59, 0x86, 0x8B, 0x78,
  27415. 0x86, 0x78, 0x87, 0xB9, 0xA7, 0x0C, 0x32, 0xAF,
  27416. 0x84, 0x63, 0x0A, 0xA9, 0x08, 0x81, 0x43, 0x79,
  27417. 0xE6, 0x51, 0x91, 0x50, 0xBA, 0x16, 0x43, 0x9B,
  27418. 0x5E, 0x2B, 0x06, 0x03, 0xD0, 0x6A, 0xA6, 0x67,
  27419. 0x45, 0x57, 0xF5, 0xB0, 0x98, 0x3E, 0x5C, 0xB6,
  27420. 0xA9, 0x75, 0x96, 0x06, 0x9B, 0x01, 0xBB, 0x31,
  27421. 0x28, 0xC4, 0x16, 0x68, 0x06, 0x57, 0x20, 0x4F,
  27422. 0xD0, 0x76, 0x40, 0x39, 0x2E, 0x16, 0xB1, 0x9F,
  27423. 0x33, 0x7A, 0x99, 0xA3, 0x04, 0x84, 0x4E, 0x1A,
  27424. 0xA4, 0x74, 0xE9, 0xC7, 0x99, 0x06, 0x29, 0x71,
  27425. 0xF6, 0x72, 0x26, 0x89, 0x60, 0xF5, 0xA8, 0x2F,
  27426. 0x95, 0x00, 0x70, 0xBB, 0xE9, 0xC2, 0xA7, 0x19,
  27427. 0x50, 0xA3, 0x78, 0x5B, 0xDF, 0x0B, 0x84, 0x40,
  27428. 0x25, 0x5E, 0xD6, 0x39, 0x28, 0xD2, 0x57, 0x84,
  27429. 0x51, 0x68, 0xB1, 0xEC, 0xCC, 0x41, 0x91, 0x32,
  27430. 0x5A, 0xA7, 0x66, 0x45, 0x71, 0x9B, 0x28, 0xEB,
  27431. 0xD8, 0x93, 0x02, 0xDC, 0x67, 0x23, 0xC7, 0x86,
  27432. 0xDF, 0x52, 0x17, 0xB2, 0x43, 0x09, 0x9C, 0xA7,
  27433. 0x82, 0x38, 0xE5, 0x7E, 0x64, 0x69, 0x2F, 0x20,
  27434. 0x6B, 0x17, 0x7A, 0xBC, 0x25, 0x96, 0x60, 0x39,
  27435. 0x5C, 0xD7, 0x86, 0x0F, 0xB3, 0x5A, 0x16, 0xF6,
  27436. 0xB2, 0xFE, 0x65, 0x48, 0xC8, 0x5A, 0xB6, 0x63,
  27437. 0x30, 0xC5, 0x17, 0xFA, 0x74, 0xCD, 0xF3, 0xCB,
  27438. 0x49, 0xD2, 0x6B, 0x11, 0x81, 0x90, 0x1A, 0xF7,
  27439. 0x75, 0xA1, 0xE1, 0x80, 0x81, 0x3B, 0x6A, 0x24,
  27440. 0xC4, 0x56, 0x82, 0x9B, 0x5C, 0x38, 0x10, 0x4E,
  27441. 0xCE, 0x43, 0xC7, 0x6A, 0x43, 0x7A, 0x6A, 0x33,
  27442. 0xB6, 0xFC, 0x6C, 0x5E, 0x65, 0xC8, 0xA8, 0x94,
  27443. 0x66, 0xC1, 0x42, 0x54, 0x85, 0xB2, 0x9B, 0x9E,
  27444. 0x18, 0x54, 0x36, 0x8A, 0xFC, 0xA3, 0x53, 0xE1,
  27445. 0x43, 0xD0, 0xA9, 0x0A, 0x6C, 0x6C, 0x9E, 0x7F,
  27446. 0xDB, 0x62, 0xA6, 0x06, 0x85, 0x6B, 0x56, 0x14,
  27447. 0xF1, 0x2B, 0x64, 0xB7, 0x96, 0x02, 0x0C, 0x35,
  27448. 0x34, 0xC3, 0x60, 0x5C, 0xFD, 0xC7, 0x3B, 0x86,
  27449. 0x71, 0x4F, 0x41, 0x18, 0x50, 0x22, 0x8A, 0x28,
  27450. 0xB8, 0xF4, 0xB4, 0x9E, 0x66, 0x34, 0x16, 0xC8,
  27451. 0x4F, 0x7E, 0x38, 0x1F, 0x6A, 0xF1, 0x07, 0x13,
  27452. 0x43, 0xBF, 0x9D, 0x39, 0xB4, 0x54, 0x39, 0x24,
  27453. 0x0C, 0xC0, 0x38, 0x97, 0x29, 0x5F, 0xEA, 0x08,
  27454. 0x0B, 0x14, 0xBB, 0x2D, 0x81, 0x19, 0xA8, 0x80,
  27455. 0xE1, 0x64, 0x49, 0x5C, 0x61, 0xBE, 0xBC, 0x71,
  27456. 0x39, 0xC1, 0x18, 0x57, 0xC8, 0x5E, 0x17, 0x50,
  27457. 0x33, 0x8D, 0x63, 0x43, 0x91, 0x37, 0x06, 0xA5,
  27458. 0x07, 0xC9, 0x56, 0x64, 0x64, 0xCD, 0x28, 0x37,
  27459. 0xCF, 0x91, 0x4D, 0x1A, 0x3C, 0x35, 0xE8, 0x9B,
  27460. 0x23, 0x5C, 0x6A, 0xB7, 0xED, 0x07, 0x8B, 0xED,
  27461. 0x23, 0x47, 0x57, 0xC0, 0x2E, 0xF6, 0x99, 0x3D,
  27462. 0x4A, 0x27, 0x3C, 0xB8, 0x15, 0x05, 0x28, 0xDA,
  27463. 0x4D, 0x76, 0x70, 0x81, 0x77, 0xE9, 0x42, 0x55,
  27464. 0x46, 0xC8, 0x3E, 0x14, 0x70, 0x39, 0x76, 0x66,
  27465. 0x03, 0xB3, 0x0D, 0xA6, 0x26, 0x8F, 0x45, 0x98,
  27466. 0xA5, 0x31, 0x94, 0x24, 0x0A, 0x28, 0x32, 0xA3,
  27467. 0xD6, 0x75, 0x33, 0xB5, 0x05, 0x6F, 0x9A, 0xAA,
  27468. 0xC6, 0x1B, 0x4B, 0x17, 0xB9, 0xA2, 0x69, 0x3A,
  27469. 0xA0, 0xD5, 0x88, 0x91, 0xE6, 0xCC, 0x56, 0xCD,
  27470. 0xD7, 0x72, 0x41, 0x09, 0x00, 0xC4, 0x05, 0xAF,
  27471. 0x20, 0xB9, 0x03, 0x79, 0x7C, 0x64, 0x87, 0x69,
  27472. 0x15, 0xC3, 0x7B, 0x84, 0x87, 0xA1, 0x44, 0x9C,
  27473. 0xE9, 0x24, 0xCD, 0x34, 0x5C, 0x29, 0xA3, 0x6E,
  27474. 0x08, 0x23, 0x8F, 0x7A, 0x15, 0x7C, 0xC7, 0xE5,
  27475. 0x16, 0xAB, 0x5B, 0xA7, 0x3C, 0x80, 0x63, 0xF7,
  27476. 0x26, 0xBB, 0x5A, 0x0A, 0x03, 0x19, 0xE5, 0x71,
  27477. 0x27, 0x43, 0x8C, 0x7F, 0xC6, 0x01, 0xC9, 0x9C,
  27478. 0xCA, 0xAE, 0x4C, 0x1A, 0x83, 0x72, 0x6F, 0xDC,
  27479. 0xB5, 0x04, 0x5E, 0xD1, 0xA8, 0x2A, 0x98, 0x5E,
  27480. 0xA9, 0x95, 0x39, 0x6D, 0x77, 0x27, 0x2C, 0x66,
  27481. 0xCE, 0x49, 0x32, 0x89, 0xF6, 0x11, 0x09, 0x10,
  27482. 0xF3, 0x7C, 0x27, 0x41, 0xCE, 0x47, 0x02, 0x6A,
  27483. 0x6F, 0x82, 0x61, 0x99, 0x9C, 0x64, 0x82, 0x57,
  27484. 0x2B, 0x16, 0x93, 0x91, 0x2E, 0xF1, 0x2E, 0xEB,
  27485. 0xEA, 0x7A, 0xCF, 0x92, 0x34, 0xFB, 0x40, 0x9F,
  27486. 0x2A, 0x60, 0x90, 0xE6, 0xB0, 0xBF, 0xD8, 0x95,
  27487. 0x46, 0x9D, 0x0B, 0x2A, 0x92, 0x1B, 0xB7, 0x23,
  27488. 0xF8, 0x7A, 0x33, 0xEA, 0x54, 0x65, 0xAB, 0x90,
  27489. 0xF5, 0x14, 0xB6, 0x76, 0x98, 0xC0, 0x76, 0x8B,
  27490. 0x6C, 0xA4, 0x98, 0xB0, 0x22, 0xC5, 0x12, 0xFA,
  27491. 0x08, 0x75, 0xF0, 0x54, 0xAA, 0x22, 0x65, 0x86,
  27492. 0x7E, 0x31, 0xC0, 0xE5, 0x22, 0x65, 0x1E, 0x02,
  27493. 0x4A, 0x07, 0xD6, 0x0D, 0xD9, 0xF6, 0x33, 0x16,
  27494. 0x69, 0x21, 0xF4, 0x12, 0x6B, 0xC2, 0xB6, 0xAA,
  27495. 0x01, 0xCC, 0x15, 0xA0, 0x9B, 0x85, 0xBF, 0xF8,
  27496. 0x21, 0x8C, 0x5A, 0xAE, 0x95, 0xBC, 0x1F, 0xFB,
  27497. 0x26, 0xAE, 0x5A, 0x13, 0x76, 0x70, 0xF0, 0x49,
  27498. 0x10, 0xCA, 0x9D, 0x72, 0x41, 0xB6, 0x66, 0x0C,
  27499. 0x39, 0x4C, 0x54, 0x55, 0x91, 0x77, 0x46, 0xA2,
  27500. 0x66, 0x82, 0xFB, 0x71, 0xA4, 0x32, 0xEA, 0x95,
  27501. 0x30, 0xE8, 0x39, 0xBD, 0xEB, 0x07, 0x43, 0x30,
  27502. 0x04, 0xF4, 0x5A, 0x0D, 0xDA, 0xA0, 0xB2, 0x4E,
  27503. 0x3A, 0x56, 0x6A, 0x54, 0x08, 0x15, 0xF2, 0x81,
  27504. 0xE3, 0xFC, 0x25, 0x9A, 0xC6, 0xCB, 0xC0, 0xAC,
  27505. 0xB8, 0xD6, 0x22, 0x68, 0xB6, 0x03, 0xBC, 0x67,
  27506. 0x6A, 0xB4, 0x15, 0xC4, 0x74, 0xBB, 0x94, 0x87,
  27507. 0x3E, 0x44, 0x87, 0xAE, 0x31, 0xA4, 0xE3, 0x84,
  27508. 0x5C, 0x79, 0x90, 0x15, 0x50, 0x89, 0x0E, 0xE8,
  27509. 0x78, 0x4E, 0xEF, 0x90, 0x4F, 0xEE, 0x62, 0xBA,
  27510. 0x8C, 0x5F, 0x95, 0x2C, 0x68, 0x41, 0x30, 0x52,
  27511. 0xE0, 0xA7, 0xE3, 0x38, 0x8B, 0xB8, 0xFF, 0x0A,
  27512. 0xD6, 0x02, 0xAE, 0x3E, 0xA1, 0x4D, 0x9D, 0xF6,
  27513. 0xDD, 0x5E, 0x4C, 0xC6, 0xA3, 0x81, 0xA4, 0x1D,
  27514. 0xA5, 0xC1, 0x37, 0xEC, 0xC4, 0x9D, 0xF5, 0x87,
  27515. 0xE1, 0x78, 0xEA, 0xF4, 0x77, 0x02, 0xEC, 0x62,
  27516. 0x37, 0x80, 0x69, 0x1A, 0x32, 0x33, 0xF6, 0x9F,
  27517. 0x12, 0xBD, 0x9C, 0x9B, 0x96, 0x37, 0xC5, 0x13,
  27518. 0x78, 0xAD, 0x71, 0xA8, 0x31, 0x05, 0x52, 0x77,
  27519. 0x25, 0x4C, 0xC6, 0x3C, 0x5A, 0xD4, 0xCB, 0x76,
  27520. 0xB4, 0xAB, 0x82, 0xE5, 0xFC, 0xA1, 0x35, 0xE8,
  27521. 0xD2, 0x6A, 0x6B, 0x3A, 0x89, 0xFA, 0x5B, 0x6F
  27522. };
  27523. static const byte c_768[KYBER768_CIPHER_TEXT_SIZE] = {
  27524. 0xA5, 0xC8, 0x1C, 0x76, 0xC2, 0x43, 0x05, 0xE1,
  27525. 0xCE, 0x5D, 0x81, 0x35, 0xD4, 0x15, 0x23, 0x68,
  27526. 0x2E, 0x9E, 0xE6, 0xD7, 0xB4, 0x0A, 0xD4, 0x1D,
  27527. 0xF1, 0xF3, 0x7C, 0x9B, 0x17, 0xDC, 0xE7, 0x80,
  27528. 0x76, 0x01, 0x9A, 0x6B, 0x0B, 0x7C, 0x95, 0xC9,
  27529. 0xBE, 0x7A, 0xF2, 0x95, 0x07, 0xB2, 0xD5, 0xA6,
  27530. 0x98, 0x7C, 0x8E, 0xE3, 0x25, 0x91, 0x90, 0x85,
  27531. 0x52, 0x43, 0xE6, 0xE5, 0x6F, 0x56, 0x20, 0x60,
  27532. 0x8C, 0x52, 0xD9, 0x6F, 0xAB, 0x10, 0x3A, 0x87,
  27533. 0x00, 0xFB, 0xA1, 0xA8, 0x7D, 0xCA, 0x60, 0x78,
  27534. 0x11, 0x8A, 0x08, 0x71, 0x76, 0x2C, 0x95, 0x34,
  27535. 0xC0, 0xC0, 0xC3, 0x97, 0x8C, 0x91, 0xC3, 0xA0,
  27536. 0x1F, 0x0F, 0x60, 0x8D, 0xCF, 0x75, 0x78, 0x15,
  27537. 0x43, 0x8F, 0xE8, 0x95, 0x7C, 0x8A, 0x85, 0x91,
  27538. 0x83, 0xB1, 0xB6, 0x72, 0x1A, 0x08, 0x65, 0xBE,
  27539. 0xBC, 0x79, 0x9D, 0x4E, 0x5C, 0x0E, 0x7B, 0xD3,
  27540. 0xEA, 0xE4, 0x85, 0x8E, 0x6A, 0xB6, 0xA2, 0xE7,
  27541. 0x65, 0x8E, 0xD8, 0x0D, 0x4E, 0xD1, 0x58, 0xB0,
  27542. 0x36, 0xB9, 0x3F, 0xA0, 0x3A, 0xFA, 0x6A, 0xE3,
  27543. 0x13, 0x6C, 0xF3, 0xD6, 0x93, 0xC9, 0x11, 0xBC,
  27544. 0xC7, 0x59, 0x05, 0xE5, 0xB0, 0xCB, 0x28, 0x65,
  27545. 0xB9, 0xE9, 0x88, 0x45, 0x22, 0xA7, 0x77, 0x77,
  27546. 0x61, 0x3E, 0x53, 0x11, 0x1D, 0x5A, 0x1C, 0x7D,
  27547. 0x3D, 0xAB, 0x73, 0x4C, 0xEB, 0x03, 0x65, 0x7A,
  27548. 0xE0, 0xC8, 0x97, 0x63, 0xE9, 0x94, 0x71, 0x05,
  27549. 0x47, 0x76, 0xBA, 0xE7, 0xD5, 0x1B, 0x0E, 0x73,
  27550. 0xA5, 0xBB, 0x35, 0xAE, 0xC3, 0x0F, 0xF6, 0xBC,
  27551. 0x93, 0x68, 0x49, 0x16, 0xFE, 0xF1, 0x16, 0x25,
  27552. 0x86, 0x45, 0x2F, 0x42, 0x66, 0x53, 0xE2, 0xCA,
  27553. 0x84, 0x4D, 0x57, 0x44, 0x30, 0x7F, 0xF9, 0xAE,
  27554. 0xB2, 0x87, 0xA6, 0x44, 0x77, 0x83, 0xB2, 0x1A,
  27555. 0x0E, 0x93, 0x9C, 0x81, 0x42, 0x1D, 0x63, 0x1F,
  27556. 0x5D, 0xCB, 0x45, 0x2E, 0x51, 0xED, 0x34, 0xE3,
  27557. 0xDA, 0xD1, 0xCF, 0x50, 0x4E, 0x0A, 0x3B, 0x0F,
  27558. 0x47, 0x11, 0xA8, 0xDC, 0x64, 0x99, 0xD1, 0x69,
  27559. 0x1D, 0x10, 0x95, 0x69, 0x33, 0x6C, 0xE1, 0x55,
  27560. 0x8A, 0x4C, 0x0A, 0x46, 0x4E, 0x20, 0x87, 0xEA,
  27561. 0x8F, 0x9E, 0x3B, 0x18, 0xF7, 0x47, 0xEF, 0x61,
  27562. 0xF4, 0x57, 0x6A, 0xEB, 0x42, 0xB1, 0x7C, 0xAD,
  27563. 0xB7, 0xF0, 0xFD, 0x84, 0xDA, 0x8E, 0x3A, 0x6F,
  27564. 0x47, 0x1D, 0x95, 0xED, 0xFA, 0x65, 0xBE, 0x9E,
  27565. 0x6C, 0x9F, 0x6A, 0xE7, 0x56, 0xA2, 0x2A, 0x4F,
  27566. 0x1A, 0x5C, 0x54, 0x3C, 0x26, 0xBA, 0x7B, 0xAD,
  27567. 0x88, 0xE1, 0x6D, 0x5F, 0x5B, 0x7E, 0x12, 0xE2,
  27568. 0xD4, 0xCA, 0x34, 0xB3, 0xA6, 0x4D, 0x17, 0xF8,
  27569. 0x7C, 0xCF, 0xC4, 0xFF, 0x8C, 0x5E, 0x4F, 0x53,
  27570. 0x75, 0x2A, 0x07, 0x7C, 0x68, 0x72, 0x1E, 0x8C,
  27571. 0xC8, 0x17, 0xF9, 0xFF, 0x24, 0x87, 0x61, 0x70,
  27572. 0xFF, 0x2A, 0xF8, 0x9F, 0xA9, 0x58, 0x55, 0xA5,
  27573. 0xB1, 0xDE, 0x34, 0x7C, 0x07, 0xFD, 0xDB, 0xCF,
  27574. 0xE7, 0x26, 0x4A, 0xA5, 0xED, 0x64, 0x01, 0x49,
  27575. 0x15, 0x61, 0xD8, 0x31, 0x53, 0x8F, 0x85, 0x2B,
  27576. 0x0E, 0xD7, 0xB9, 0xE8, 0xEB, 0xAF, 0xFC, 0x06,
  27577. 0x02, 0x84, 0xF2, 0x2D, 0x2B, 0xAE, 0xE5, 0x6F,
  27578. 0xA9, 0xF6, 0xD0, 0x14, 0x32, 0xA1, 0x15, 0xA2,
  27579. 0xD6, 0xA6, 0x4C, 0x38, 0xAE, 0x0A, 0x50, 0xBA,
  27580. 0x36, 0x2F, 0xB5, 0x7B, 0x53, 0xE3, 0xE8, 0x55,
  27581. 0xB8, 0x3C, 0xE8, 0xC4, 0x22, 0x74, 0x04, 0x55,
  27582. 0x99, 0xF6, 0x5F, 0xA6, 0xA8, 0x92, 0x1D, 0x85,
  27583. 0xF9, 0x4E, 0xD2, 0x30, 0xB5, 0x16, 0x71, 0x2D,
  27584. 0xB6, 0xFD, 0x2F, 0xF2, 0x8B, 0x3A, 0x33, 0x71,
  27585. 0xD9, 0xBE, 0x05, 0x8A, 0xE7, 0x5C, 0x2F, 0xA5,
  27586. 0x91, 0xB7, 0xEC, 0x3C, 0x3D, 0xAA, 0x1F, 0x76,
  27587. 0x42, 0xBC, 0x26, 0xC3, 0x24, 0xC0, 0x80, 0x90,
  27588. 0x60, 0x7E, 0x66, 0x62, 0x15, 0x4D, 0xB3, 0x7C,
  27589. 0xF7, 0x47, 0x96, 0x7A, 0x1F, 0x9F, 0xC2, 0x90,
  27590. 0x89, 0xF5, 0x70, 0xEB, 0xE6, 0x0E, 0xEE, 0xF8,
  27591. 0x9F, 0xD2, 0x44, 0x81, 0x02, 0x8C, 0x85, 0xAE,
  27592. 0xF1, 0xDC, 0x3B, 0x09, 0xF2, 0x2C, 0xD3, 0x69,
  27593. 0x1B, 0xBB, 0xB8, 0x21, 0xC7, 0xA8, 0xA0, 0xF3,
  27594. 0x5A, 0xD1, 0x2B, 0xE1, 0xDD, 0x19, 0x9B, 0x97,
  27595. 0x70, 0x48, 0xF3, 0xD4, 0x8C, 0x16, 0xBB, 0x2C,
  27596. 0xA9, 0x4C, 0xEC, 0xB8, 0x92, 0x87, 0x70, 0xD5,
  27597. 0xBB, 0x32, 0x9A, 0x03, 0x27, 0xE0, 0xB2, 0x86,
  27598. 0xFA, 0xA1, 0xC6, 0x52, 0x81, 0x03, 0x1A, 0x31,
  27599. 0xC8, 0x4F, 0x2E, 0xDC, 0x9C, 0x04, 0xD4, 0x75,
  27600. 0xED, 0x4E, 0x12, 0x8E, 0x51, 0xEF, 0xA9, 0x7D,
  27601. 0x01, 0x48, 0xCB, 0xA6, 0xC9, 0x5F, 0x67, 0x4C,
  27602. 0x58, 0x9F, 0x30, 0x1C, 0x26, 0x5B, 0xED, 0x70,
  27603. 0x8E, 0x9A, 0xD8, 0xDA, 0x3C, 0x5C, 0xEC, 0xBD,
  27604. 0xEE, 0xED, 0x35, 0xEF, 0x1E, 0x25, 0x31, 0x32,
  27605. 0xBA, 0x89, 0x92, 0x0D, 0x78, 0x6B, 0x88, 0x23,
  27606. 0x0B, 0x01, 0x3B, 0xCF, 0x2D, 0xC9, 0x2D, 0x6B,
  27607. 0x15, 0x7A, 0xFA, 0x8D, 0xA8, 0x59, 0x2C, 0xD0,
  27608. 0x74, 0x3D, 0x49, 0x82, 0xBE, 0x60, 0xD7, 0xC2,
  27609. 0xD5, 0xC4, 0x72, 0xAB, 0x9F, 0xA7, 0xF4, 0xCC,
  27610. 0x3D, 0x12, 0xB0, 0xEB, 0xAF, 0x0A, 0xBE, 0x55,
  27611. 0x5C, 0x75, 0x80, 0x54, 0x26, 0x84, 0x4D, 0xD9,
  27612. 0x42, 0x86, 0x43, 0xF8, 0x44, 0x06, 0xA1, 0xB8,
  27613. 0xD6, 0xFA, 0xED, 0xFD, 0x8A, 0xE6, 0xE7, 0x3A,
  27614. 0x72, 0x77, 0x2A, 0x21, 0x59, 0xAC, 0xAB, 0xD9,
  27615. 0x72, 0xAE, 0xB6, 0xF7, 0xDE, 0x09, 0x1A, 0xC5,
  27616. 0xFD, 0xD7, 0xF4, 0x9A, 0x3D, 0xC6, 0x64, 0x1C,
  27617. 0xDF, 0x62, 0x44, 0x6B, 0x4B, 0x04, 0xA3, 0x1F,
  27618. 0x73, 0xB8, 0x0A, 0x62, 0xF8, 0x0A, 0x40, 0x4A,
  27619. 0x8C, 0xB1, 0x8C, 0xE3, 0xE6, 0x54, 0x80, 0xEF,
  27620. 0x7B, 0x52, 0xBF, 0x00, 0x91, 0x11, 0x7E, 0x5D,
  27621. 0x08, 0xEA, 0xE1, 0xB0, 0xAA, 0xBB, 0x72, 0xE6,
  27622. 0xDF, 0xFF, 0xF7, 0x6F, 0x6E, 0x44, 0xBB, 0xD7,
  27623. 0xEA, 0x57, 0x0D, 0x66, 0x04, 0xBC, 0x2E, 0x74,
  27624. 0x31, 0x8B, 0xAF, 0xA3, 0x15, 0xA3, 0x88, 0x61,
  27625. 0xAA, 0x1B, 0x21, 0xAF, 0xB2, 0xA5, 0x3F, 0x26,
  27626. 0x14, 0xF1, 0xD6, 0x40, 0x07, 0x59, 0x84, 0xAE,
  27627. 0x62, 0xE2, 0xFC, 0xA1, 0xD1, 0xB4, 0xDB, 0x36,
  27628. 0x9F, 0x15, 0x70, 0x5C, 0xE7, 0xD4, 0xDF, 0x8A,
  27629. 0xE9, 0x82, 0x64, 0x50, 0x10, 0x51, 0xC0, 0xDE,
  27630. 0xF2, 0x1D, 0x64, 0x5D, 0x49, 0x62, 0x5A, 0xF0,
  27631. 0x2C, 0xA4, 0x28, 0xD9, 0xF0, 0xC2, 0xCD, 0x9F,
  27632. 0xBA, 0xEE, 0xAB, 0x97, 0xE8, 0xE9, 0x15, 0x16,
  27633. 0x62, 0xB6, 0x99, 0x2B, 0x4C, 0x99, 0xAB, 0x1B,
  27634. 0x92, 0x5D, 0x08, 0x92, 0x03, 0x63, 0x37, 0x3F,
  27635. 0x76, 0xD3, 0xFD, 0xF0, 0x82, 0x8C, 0xAA, 0x69,
  27636. 0xC8, 0xB1, 0xBD, 0xC6, 0xF5, 0x21, 0xDF, 0x64,
  27637. 0x1C, 0xF1, 0xC8, 0xA4, 0xE7, 0xEF, 0x0C, 0x23,
  27638. 0x28, 0x9A, 0x4E, 0x2C, 0xF1, 0x8A, 0xCE, 0xBB,
  27639. 0xE4, 0xC1, 0xE6, 0x83, 0x69, 0xBD, 0x52, 0x35,
  27640. 0x12, 0x01, 0x42, 0xEC, 0xDD, 0x1A, 0x73, 0x81,
  27641. 0x1E, 0x2E, 0x53, 0x3A, 0x64, 0x7D, 0x7A, 0xEE,
  27642. 0x16, 0xDA, 0xA0, 0x3B, 0x68, 0x36, 0x39, 0xDC,
  27643. 0xF1, 0xE1, 0xF1, 0xE7, 0x1C, 0xFA, 0xED, 0x48,
  27644. 0xF6, 0x9A, 0xEC, 0x3E, 0x83, 0x17, 0x33, 0xDA,
  27645. 0x19, 0xCE, 0xBE, 0xC1, 0xDD, 0xBF, 0x71, 0xCB,
  27646. 0xAE, 0x08, 0x00, 0xF2, 0xF6, 0xD6, 0x4A, 0x09,
  27647. 0x6E, 0xC4, 0x95, 0xD6, 0x2F, 0x43, 0x44, 0xF7,
  27648. 0xAA, 0x56, 0x21, 0xB3, 0x22, 0x35, 0x3A, 0x79,
  27649. 0x5A, 0xA0, 0x99, 0xEA, 0x3A, 0x07, 0x02, 0x72,
  27650. 0xD0, 0x53, 0xD4, 0x65, 0x3A, 0x20, 0xCF, 0x21,
  27651. 0x0E, 0xAA, 0xF1, 0x2C, 0xAE, 0x60, 0x23, 0xD8,
  27652. 0xE5, 0x11, 0x8D, 0xF0, 0x4B, 0x38, 0x4A, 0x44,
  27653. 0xD1, 0xED, 0xB9, 0x1C, 0x44, 0x98, 0x9E, 0xF7,
  27654. 0xEE, 0x57, 0xF2, 0xBF, 0x81, 0xA2, 0x4B, 0xDC,
  27655. 0x76, 0x80, 0x7D, 0xA9, 0x67, 0xEE, 0x65, 0x25,
  27656. 0x41, 0x0C, 0x5C, 0x48, 0x50, 0x67, 0xEF, 0xC3,
  27657. 0xD3, 0x9A, 0x9A, 0xD4, 0x2C, 0xC7, 0x53, 0xBA,
  27658. 0xA5, 0x9A, 0x1F, 0xD2, 0x8A, 0xF3, 0x5C, 0x00,
  27659. 0xD1, 0x8A, 0x40, 0x6A, 0x28, 0xFC, 0x79, 0xBA
  27660. };
  27661. static const byte kprime_768[KYBER_SS_SZ] = {
  27662. 0xDC, 0x5B, 0x88, 0x88, 0xBC, 0x1E, 0xBA, 0x5C,
  27663. 0x19, 0x69, 0xC2, 0x11, 0x64, 0xEA, 0x43, 0xE2,
  27664. 0x2E, 0x7A, 0xC0, 0xCD, 0x01, 0x2A, 0x2F, 0x26,
  27665. 0xCB, 0x8C, 0x48, 0x7E, 0x69, 0xEF, 0x7C, 0xE4
  27666. };
  27667. #endif
  27668. #ifndef WOLFSSL_NO_KYBER1024
  27669. static const byte dk_1024[KYBER1024_PRIVATE_KEY_SIZE] = {
  27670. 0x84, 0x45, 0xC3, 0x36, 0xF3, 0x51, 0x8B, 0x29,
  27671. 0x81, 0x63, 0xDC, 0xBB, 0x63, 0x57, 0x59, 0x79,
  27672. 0x83, 0xCA, 0x2E, 0x87, 0x3D, 0xCB, 0x49, 0x61,
  27673. 0x0C, 0xF5, 0x2F, 0x14, 0xDB, 0xCB, 0x94, 0x7C,
  27674. 0x1F, 0x3E, 0xE9, 0x26, 0x69, 0x67, 0x27, 0x6B,
  27675. 0x0C, 0x57, 0x6C, 0xF7, 0xC3, 0x0E, 0xE6, 0xB9,
  27676. 0x3D, 0xEA, 0x51, 0x18, 0x67, 0x6C, 0xBE, 0xE1,
  27677. 0xB1, 0xD4, 0x79, 0x42, 0x06, 0xFB, 0x36, 0x9A,
  27678. 0xBA, 0x41, 0x16, 0x7B, 0x43, 0x93, 0x85, 0x5C,
  27679. 0x84, 0xEB, 0xA8, 0xF3, 0x23, 0x73, 0xC0, 0x5B,
  27680. 0xAE, 0x76, 0x31, 0xC8, 0x02, 0x74, 0x4A, 0xAD,
  27681. 0xB6, 0xC2, 0xDE, 0x41, 0x25, 0x0C, 0x49, 0x43,
  27682. 0x15, 0x23, 0x0B, 0x52, 0x82, 0x6C, 0x34, 0x58,
  27683. 0x7C, 0xB2, 0x1B, 0x18, 0x3B, 0x49, 0xB2, 0xA5,
  27684. 0xAC, 0x04, 0x92, 0x1A, 0xC6, 0xBF, 0xAC, 0x1B,
  27685. 0x24, 0xA4, 0xB3, 0x7A, 0x93, 0xA4, 0xB1, 0x68,
  27686. 0xCC, 0xE7, 0x59, 0x1B, 0xE6, 0x11, 0x1F, 0x47,
  27687. 0x62, 0x60, 0xF2, 0x76, 0x29, 0x59, 0xF5, 0xC1,
  27688. 0x64, 0x01, 0x18, 0xC2, 0x42, 0x37, 0x72, 0xE2,
  27689. 0xAD, 0x03, 0xDC, 0x71, 0x68, 0xA3, 0x8C, 0x6D,
  27690. 0xD3, 0x9F, 0x5F, 0x72, 0x54, 0x26, 0x42, 0x80,
  27691. 0xC8, 0xBC, 0x10, 0xB9, 0x14, 0x16, 0x80, 0x70,
  27692. 0x47, 0x2F, 0xA8, 0x80, 0xAC, 0xB8, 0x60, 0x1A,
  27693. 0x8A, 0x08, 0x37, 0xF2, 0x5F, 0xE1, 0x94, 0x68,
  27694. 0x7C, 0xD6, 0x8B, 0x7D, 0xE2, 0x34, 0x0F, 0x03,
  27695. 0x6D, 0xAD, 0x89, 0x1D, 0x38, 0xD1, 0xB0, 0xCE,
  27696. 0x9C, 0x26, 0x33, 0x35, 0x5C, 0xF5, 0x7B, 0x50,
  27697. 0xB8, 0x96, 0x03, 0x6F, 0xCA, 0x26, 0x0D, 0x26,
  27698. 0x69, 0xF8, 0x5B, 0xAC, 0x79, 0x71, 0x4F, 0xDA,
  27699. 0xFB, 0x41, 0xEF, 0x80, 0xB8, 0xC3, 0x02, 0x64,
  27700. 0xC3, 0x13, 0x86, 0xAE, 0x60, 0xB0, 0x5F, 0xAA,
  27701. 0x54, 0x2A, 0x26, 0xB4, 0x1E, 0xB8, 0x5F, 0x67,
  27702. 0x06, 0x8F, 0x08, 0x80, 0x34, 0xFF, 0x67, 0xAA,
  27703. 0x2E, 0x81, 0x5A, 0xAB, 0x8B, 0xCA, 0x6B, 0xF7,
  27704. 0x1F, 0x70, 0xEC, 0xC3, 0xCB, 0xCB, 0xC4, 0x5E,
  27705. 0xF7, 0x01, 0xFC, 0xD5, 0x42, 0xBD, 0x21, 0xC7,
  27706. 0xB0, 0x95, 0x68, 0xF3, 0x69, 0xC6, 0x69, 0xF3,
  27707. 0x96, 0x47, 0x38, 0x44, 0xFB, 0xA1, 0x49, 0x57,
  27708. 0xF5, 0x19, 0x74, 0xD8, 0x52, 0xB9, 0x78, 0x01,
  27709. 0x46, 0x03, 0xA2, 0x10, 0xC0, 0x19, 0x03, 0x62,
  27710. 0x87, 0x00, 0x89, 0x94, 0xF2, 0x12, 0x55, 0xB2,
  27711. 0x50, 0x99, 0xAD, 0x82, 0xAA, 0x13, 0x24, 0x38,
  27712. 0x96, 0x3B, 0x2C, 0x0A, 0x47, 0xCD, 0xF5, 0xF3,
  27713. 0x2B, 0xA4, 0x6B, 0x76, 0xC7, 0xA6, 0x55, 0x9F,
  27714. 0x18, 0xBF, 0xD5, 0x55, 0xB7, 0x62, 0xE4, 0x87,
  27715. 0xB6, 0xAC, 0x99, 0x2F, 0xE2, 0x0E, 0x28, 0x3C,
  27716. 0xA0, 0xB3, 0xF6, 0x16, 0x44, 0x96, 0x95, 0x59,
  27717. 0x95, 0xC3, 0xB2, 0x8A, 0x57, 0xBB, 0xC2, 0x98,
  27718. 0x26, 0xF0, 0x6F, 0xB3, 0x8B, 0x25, 0x34, 0x70,
  27719. 0xAF, 0x63, 0x1B, 0xC4, 0x6C, 0x3A, 0x8F, 0x9C,
  27720. 0xE8, 0x24, 0x32, 0x19, 0x85, 0xDD, 0x01, 0xC0,
  27721. 0x5F, 0x69, 0xB8, 0x24, 0xF9, 0x16, 0x63, 0x3B,
  27722. 0x40, 0x65, 0x4C, 0x75, 0xAA, 0xEB, 0x93, 0x85,
  27723. 0x57, 0x6F, 0xFD, 0xE2, 0x99, 0x0A, 0x6B, 0x0A,
  27724. 0x3B, 0xE8, 0x29, 0xD6, 0xD8, 0x4E, 0x34, 0xF1,
  27725. 0x78, 0x05, 0x89, 0xC7, 0x92, 0x04, 0xC6, 0x3C,
  27726. 0x79, 0x8F, 0x55, 0xD2, 0x31, 0x87, 0xE4, 0x61,
  27727. 0xD4, 0x8C, 0x21, 0xE5, 0xC0, 0x47, 0xE5, 0x35,
  27728. 0xB1, 0x9F, 0x45, 0x8B, 0xBA, 0x13, 0x45, 0xB9,
  27729. 0xE4, 0x1E, 0x0C, 0xB4, 0xA9, 0xC2, 0xD8, 0xC4,
  27730. 0x0B, 0x49, 0x0A, 0x3B, 0xAB, 0xC5, 0x53, 0xB3,
  27731. 0x02, 0x6B, 0x16, 0x72, 0xD2, 0x8C, 0xBC, 0x8B,
  27732. 0x49, 0x8A, 0x3A, 0x99, 0x57, 0x9A, 0x83, 0x2F,
  27733. 0xEA, 0xE7, 0x46, 0x10, 0xF0, 0xB6, 0x25, 0x0C,
  27734. 0xC3, 0x33, 0xE9, 0x49, 0x3E, 0xB1, 0x62, 0x1E,
  27735. 0xD3, 0x4A, 0xA4, 0xAB, 0x17, 0x5F, 0x2C, 0xA2,
  27736. 0x31, 0x15, 0x25, 0x09, 0xAC, 0xB6, 0xAC, 0x86,
  27737. 0xB2, 0x0F, 0x6B, 0x39, 0x10, 0x84, 0x39, 0xE5,
  27738. 0xEC, 0x12, 0xD4, 0x65, 0xA0, 0xFE, 0xF3, 0x50,
  27739. 0x03, 0xE1, 0x42, 0x77, 0xA2, 0x18, 0x12, 0x14,
  27740. 0x6B, 0x25, 0x44, 0x71, 0x6D, 0x6A, 0xB8, 0x2D,
  27741. 0x1B, 0x07, 0x26, 0xC2, 0x7A, 0x98, 0xD5, 0x89,
  27742. 0xEB, 0xDA, 0xCC, 0x4C, 0x54, 0xBA, 0x77, 0xB2,
  27743. 0x49, 0x8F, 0x21, 0x7E, 0x14, 0xE3, 0x4E, 0x66,
  27744. 0x02, 0x5A, 0x2A, 0x14, 0x3A, 0x99, 0x25, 0x20,
  27745. 0xA6, 0x1C, 0x06, 0x72, 0xCC, 0x9C, 0xCE, 0xD7,
  27746. 0xC9, 0x45, 0x0C, 0x68, 0x3E, 0x90, 0xA3, 0xE4,
  27747. 0x65, 0x1D, 0xB6, 0x23, 0xA6, 0xDB, 0x39, 0xAC,
  27748. 0x26, 0x12, 0x5B, 0x7F, 0xC1, 0x98, 0x6D, 0x7B,
  27749. 0x04, 0x93, 0xB8, 0xB7, 0x2D, 0xE7, 0x70, 0x7D,
  27750. 0xC2, 0x0B, 0xBD, 0xD4, 0x37, 0x13, 0x15, 0x6A,
  27751. 0xF7, 0xD9, 0x43, 0x0E, 0xF4, 0x53, 0x99, 0x66,
  27752. 0x3C, 0x22, 0x02, 0x73, 0x91, 0x68, 0x69, 0x2D,
  27753. 0xD6, 0x57, 0x54, 0x5B, 0x05, 0x6D, 0x9C, 0x92,
  27754. 0x38, 0x5A, 0x7F, 0x41, 0x4B, 0x34, 0xB9, 0x0C,
  27755. 0x79, 0x60, 0xD5, 0x7B, 0x35, 0xBA, 0x7D, 0xDE,
  27756. 0x7B, 0x81, 0xFC, 0xA0, 0x11, 0x9D, 0x74, 0x1B,
  27757. 0x12, 0x78, 0x09, 0x26, 0x01, 0x8F, 0xE4, 0xC8,
  27758. 0x03, 0x0B, 0xF0, 0x38, 0xE1, 0x8B, 0x4F, 0xA3,
  27759. 0x37, 0x43, 0xD0, 0xD3, 0xC8, 0x46, 0x41, 0x7E,
  27760. 0x9D, 0x59, 0x15, 0xC2, 0x46, 0x31, 0x59, 0x38,
  27761. 0xB1, 0xE2, 0x33, 0x61, 0x45, 0x01, 0xD0, 0x26,
  27762. 0x95, 0x95, 0x51, 0x25, 0x8B, 0x23, 0x32, 0x30,
  27763. 0xD4, 0x28, 0xB1, 0x81, 0xB1, 0x32, 0xF1, 0xD0,
  27764. 0xB0, 0x26, 0x06, 0x7B, 0xA8, 0x16, 0x99, 0x9B,
  27765. 0xC0, 0xCD, 0x6B, 0x54, 0x7E, 0x54, 0x8B, 0x63,
  27766. 0xC9, 0xEA, 0xA0, 0x91, 0xBA, 0xC4, 0x93, 0xDC,
  27767. 0x59, 0x8D, 0xBC, 0x2B, 0x0E, 0x14, 0x6A, 0x25,
  27768. 0x91, 0xC2, 0xA8, 0xC0, 0x09, 0xDD, 0x51, 0x70,
  27769. 0xAA, 0xE0, 0x27, 0xC5, 0x41, 0xA1, 0xB5, 0xE6,
  27770. 0x6E, 0x45, 0xC6, 0x56, 0x12, 0x98, 0x4C, 0x46,
  27771. 0x77, 0x04, 0x93, 0xEC, 0x89, 0x6E, 0xF2, 0x5A,
  27772. 0xA9, 0x30, 0x5E, 0x9F, 0x06, 0x69, 0x2C, 0xD0,
  27773. 0xB2, 0xF0, 0x69, 0x62, 0xE2, 0x05, 0xBE, 0xBE,
  27774. 0x11, 0x3A, 0x34, 0xEB, 0xB1, 0xA4, 0x83, 0x0A,
  27775. 0x9B, 0x37, 0x49, 0x64, 0x1B, 0xB9, 0x35, 0x00,
  27776. 0x7B, 0x23, 0xB2, 0x4B, 0xFE, 0x57, 0x69, 0x56,
  27777. 0x25, 0x4D, 0x7A, 0x35, 0xAA, 0x49, 0x6A, 0xC4,
  27778. 0x46, 0xC6, 0x7A, 0x7F, 0xEC, 0x85, 0xA6, 0x00,
  27779. 0x57, 0xE8, 0x58, 0x06, 0x17, 0xBC, 0xB3, 0xFA,
  27780. 0xD1, 0x5C, 0x76, 0x44, 0x0F, 0xED, 0x54, 0xCC,
  27781. 0x78, 0x93, 0x94, 0xFE, 0xA2, 0x44, 0x52, 0xCC,
  27782. 0x6B, 0x05, 0x85, 0xB7, 0xEB, 0x0A, 0x88, 0xBB,
  27783. 0xA9, 0x50, 0x0D, 0x98, 0x00, 0xE6, 0x24, 0x1A,
  27784. 0xFE, 0xB5, 0x23, 0xB5, 0x5A, 0x96, 0xA5, 0x35,
  27785. 0x15, 0x1D, 0x10, 0x49, 0x57, 0x32, 0x06, 0xE5,
  27786. 0x9C, 0x7F, 0xEB, 0x07, 0x09, 0x66, 0x82, 0x36,
  27787. 0x34, 0xF7, 0x7D, 0x5F, 0x12, 0x91, 0x75, 0x5A,
  27788. 0x24, 0x31, 0x19, 0x62, 0x1A, 0xF8, 0x08, 0x4A,
  27789. 0xB7, 0xAC, 0x1E, 0x22, 0xA0, 0x56, 0x8C, 0x62,
  27790. 0x01, 0x41, 0x7C, 0xBE, 0x36, 0x55, 0xD8, 0xA0,
  27791. 0x8D, 0xD5, 0xB5, 0x13, 0x88, 0x4C, 0x98, 0xD5,
  27792. 0xA4, 0x93, 0xFD, 0x49, 0x38, 0x2E, 0xA4, 0x18,
  27793. 0x60, 0xF1, 0x33, 0xCC, 0xD6, 0x01, 0xE8, 0x85,
  27794. 0x96, 0x64, 0x26, 0xA2, 0xB1, 0xF2, 0x3D, 0x42,
  27795. 0xD8, 0x2E, 0x24, 0x58, 0x2D, 0x99, 0x72, 0x51,
  27796. 0x92, 0xC2, 0x17, 0x77, 0x46, 0x7B, 0x14, 0x57,
  27797. 0xB1, 0xDD, 0x42, 0x9A, 0x0C, 0x41, 0xA5, 0xC3,
  27798. 0xD7, 0x04, 0xCE, 0xA0, 0x62, 0x78, 0xC5, 0x99,
  27799. 0x41, 0xB4, 0x38, 0xC6, 0x27, 0x27, 0x09, 0x78,
  27800. 0x09, 0xB4, 0x53, 0x0D, 0xBE, 0x83, 0x7E, 0xA3,
  27801. 0x96, 0xB6, 0xD3, 0x10, 0x77, 0xFA, 0xD3, 0x73,
  27802. 0x30, 0x53, 0x98, 0x9A, 0x84, 0x42, 0xAA, 0xC4,
  27803. 0x25, 0x5C, 0xB1, 0x63, 0xB8, 0xCA, 0x2F, 0x27,
  27804. 0x50, 0x1E, 0xA9, 0x67, 0x30, 0x56, 0x95, 0xAB,
  27805. 0xD6, 0x59, 0xAA, 0x02, 0xC8, 0x3E, 0xE6, 0x0B,
  27806. 0xB5, 0x74, 0x20, 0x3E, 0x99, 0x37, 0xAE, 0x1C,
  27807. 0x62, 0x1C, 0x8E, 0xCB, 0x5C, 0xC1, 0xD2, 0x1D,
  27808. 0x55, 0x69, 0x60, 0xB5, 0xB9, 0x16, 0x1E, 0xA9,
  27809. 0x6F, 0xFF, 0xEB, 0xAC, 0x72, 0xE1, 0xB8, 0xA6,
  27810. 0x15, 0x4F, 0xC4, 0xD8, 0x8B, 0x56, 0xC0, 0x47,
  27811. 0x41, 0xF0, 0x90, 0xCB, 0xB1, 0x56, 0xA7, 0x37,
  27812. 0xC9, 0xE6, 0xA2, 0x2B, 0xA8, 0xAC, 0x70, 0x4B,
  27813. 0xC3, 0x04, 0xF8, 0xE1, 0x7E, 0x5E, 0xA8, 0x45,
  27814. 0xFD, 0xE5, 0x9F, 0xBF, 0x78, 0x8C, 0xCE, 0x0B,
  27815. 0x97, 0xC8, 0x76, 0x1F, 0x89, 0xA2, 0x42, 0xF3,
  27816. 0x05, 0x25, 0x83, 0xC6, 0x84, 0x4A, 0x63, 0x20,
  27817. 0x31, 0xC9, 0x64, 0xA6, 0xC4, 0xA8, 0x5A, 0x12,
  27818. 0x8A, 0x28, 0x61, 0x9B, 0xA1, 0xBB, 0x3D, 0x1B,
  27819. 0xEA, 0x4B, 0x49, 0x84, 0x1F, 0xC8, 0x47, 0x61,
  27820. 0x4A, 0x06, 0x68, 0x41, 0xF5, 0x2E, 0xD0, 0xEB,
  27821. 0x8A, 0xE0, 0xB8, 0xB0, 0x96, 0xE9, 0x2B, 0x81,
  27822. 0x95, 0x40, 0x58, 0x15, 0xB2, 0x31, 0x26, 0x6F,
  27823. 0x36, 0xB1, 0x8C, 0x1A, 0x53, 0x33, 0x3D, 0xAB,
  27824. 0x95, 0xD2, 0xA9, 0xA3, 0x74, 0xB5, 0x47, 0x8A,
  27825. 0x4A, 0x41, 0xFB, 0x87, 0x59, 0x95, 0x7C, 0x9A,
  27826. 0xB2, 0x2C, 0xAE, 0x54, 0x5A, 0xB5, 0x44, 0xBA,
  27827. 0x8D, 0xD0, 0x5B, 0x83, 0xF3, 0xA6, 0x13, 0xA2,
  27828. 0x43, 0x7A, 0xDB, 0x07, 0x3A, 0x96, 0x35, 0xCB,
  27829. 0x4B, 0xBC, 0x96, 0x5F, 0xB4, 0x54, 0xCF, 0x27,
  27830. 0xB2, 0x98, 0xA4, 0x0C, 0xD0, 0xDA, 0x3B, 0x8F,
  27831. 0x9C, 0xA9, 0x9D, 0x8C, 0xB4, 0x28, 0x6C, 0x5E,
  27832. 0xB4, 0x76, 0x41, 0x67, 0x96, 0x07, 0x0B, 0xA5,
  27833. 0x35, 0xAA, 0xA5, 0x8C, 0xDB, 0x45, 0x1C, 0xD6,
  27834. 0xDB, 0x5C, 0xBB, 0x0C, 0xA2, 0x0F, 0x0C, 0x71,
  27835. 0xDE, 0x97, 0xC3, 0x0D, 0xA9, 0x7E, 0xC7, 0x90,
  27836. 0x6D, 0x06, 0xB4, 0xB9, 0x39, 0x39, 0x60, 0x28,
  27837. 0xC4, 0x6B, 0xA0, 0xE7, 0xA8, 0x65, 0xBC, 0x83,
  27838. 0x08, 0xA3, 0x81, 0x0F, 0x12, 0x12, 0x00, 0x63,
  27839. 0x39, 0xF7, 0xBC, 0x16, 0x9B, 0x16, 0x66, 0xFD,
  27840. 0xF4, 0x75, 0x91, 0x1B, 0xBC, 0x8A, 0xAA, 0xB4,
  27841. 0x17, 0x55, 0xC9, 0xA8, 0xAA, 0xBF, 0xA2, 0x3C,
  27842. 0x0E, 0x37, 0xF8, 0x4F, 0xE4, 0x69, 0x99, 0xE0,
  27843. 0x30, 0x49, 0x4B, 0x92, 0x98, 0xEF, 0x99, 0x34,
  27844. 0xE8, 0xA6, 0x49, 0xC0, 0xA5, 0xCC, 0xE2, 0xB2,
  27845. 0x2F, 0x31, 0x80, 0x9A, 0xFE, 0xD2, 0x39, 0x55,
  27846. 0xD8, 0x78, 0x81, 0xD9, 0x9F, 0xC1, 0xD3, 0x52,
  27847. 0x89, 0x6C, 0xAC, 0x90, 0x55, 0xBE, 0xA0, 0xD0,
  27848. 0x16, 0xCC, 0xBA, 0x78, 0x05, 0xA3, 0xA5, 0x0E,
  27849. 0x22, 0x16, 0x30, 0x37, 0x9B, 0xD0, 0x11, 0x35,
  27850. 0x22, 0x1C, 0xAD, 0x5D, 0x95, 0x17, 0xC8, 0xCC,
  27851. 0x42, 0x63, 0x7B, 0x9F, 0xC0, 0x71, 0x8E, 0x9A,
  27852. 0x9B, 0xB4, 0x94, 0x5C, 0x72, 0xD8, 0xD1, 0x1D,
  27853. 0x3D, 0x65, 0x9D, 0x83, 0xA3, 0xC4, 0x19, 0x50,
  27854. 0x9A, 0xF5, 0xB4, 0x70, 0xDD, 0x89, 0xB7, 0xF3,
  27855. 0xAC, 0xCF, 0x5F, 0x35, 0xCF, 0xC3, 0x22, 0x11,
  27856. 0x5F, 0xD6, 0x6A, 0x5C, 0xD2, 0x87, 0x56, 0x51,
  27857. 0x32, 0x6F, 0x9B, 0x31, 0x68, 0x91, 0x3B, 0xE5,
  27858. 0xB9, 0xC8, 0x7A, 0xE0, 0xB0, 0x25, 0xEC, 0x7A,
  27859. 0x2F, 0x4A, 0x07, 0x27, 0x50, 0x94, 0x6A, 0xC6,
  27860. 0x11, 0x70, 0xA7, 0x82, 0x6D, 0x97, 0x04, 0xC5,
  27861. 0xA2, 0x3A, 0x1C, 0x0A, 0x23, 0x25, 0x14, 0x6C,
  27862. 0x3B, 0xC1, 0x85, 0x88, 0x26, 0xC6, 0xB3, 0x92,
  27863. 0x79, 0xC2, 0xDA, 0x74, 0x38, 0xA3, 0x70, 0xED,
  27864. 0x8A, 0x0A, 0xA5, 0x16, 0x9E, 0x3B, 0xEC, 0x29,
  27865. 0xED, 0x88, 0x47, 0x87, 0x32, 0x75, 0x8D, 0x45,
  27866. 0x41, 0x43, 0xE2, 0x27, 0xF8, 0x59, 0x58, 0x83,
  27867. 0x29, 0x78, 0x42, 0xE6, 0xAF, 0x13, 0x3B, 0x17,
  27868. 0xE4, 0x81, 0x1B, 0x0F, 0x57, 0x13, 0xAC, 0x73,
  27869. 0xB7, 0xE3, 0x47, 0x42, 0x3E, 0xB9, 0x28, 0x22,
  27870. 0xD2, 0x30, 0x6F, 0xA1, 0x45, 0x00, 0xA7, 0x20,
  27871. 0x7A, 0x06, 0x72, 0x67, 0x20, 0x46, 0x54, 0x4A,
  27872. 0xCC, 0x4E, 0xA9, 0xC1, 0x6E, 0xD7, 0x42, 0x1A,
  27873. 0x06, 0x9E, 0x0D, 0x73, 0x7A, 0x98, 0x62, 0x85,
  27874. 0x19, 0xC6, 0xA2, 0x9A, 0x42, 0x4A, 0x86, 0x8B,
  27875. 0x46, 0xD9, 0xA0, 0xCC, 0x7C, 0x6C, 0x9D, 0xDD,
  27876. 0x8B, 0x8B, 0xCB, 0xF4, 0x22, 0xC8, 0xF4, 0x8A,
  27877. 0x73, 0x14, 0x3D, 0x5A, 0xBB, 0x66, 0xBC, 0x55,
  27878. 0x49, 0x94, 0x18, 0x43, 0x08, 0x02, 0xBA, 0xC5,
  27879. 0x44, 0x46, 0x3C, 0xC7, 0x31, 0x9D, 0x17, 0x99,
  27880. 0x8F, 0x29, 0x41, 0x13, 0x65, 0x76, 0x6D, 0x04,
  27881. 0xC8, 0x47, 0xF3, 0x12, 0x9D, 0x90, 0x77, 0xB7,
  27882. 0xD8, 0x33, 0x9B, 0xFB, 0x96, 0xA6, 0x73, 0x9C,
  27883. 0x3F, 0x6B, 0x74, 0xA8, 0xF0, 0x5F, 0x91, 0x38,
  27884. 0xAB, 0x2F, 0xE3, 0x7A, 0xCB, 0x57, 0x63, 0x4D,
  27885. 0x18, 0x20, 0xB5, 0x01, 0x76, 0xF5, 0xA0, 0xB6,
  27886. 0xBC, 0x29, 0x40, 0xF1, 0xD5, 0x93, 0x8F, 0x19,
  27887. 0x36, 0xB5, 0xF9, 0x58, 0x28, 0xB9, 0x2E, 0xB7,
  27888. 0x29, 0x73, 0xC1, 0x59, 0x0A, 0xEB, 0x7A, 0x55,
  27889. 0x2C, 0xEC, 0xA1, 0x0B, 0x00, 0xC3, 0x03, 0xB7,
  27890. 0xC7, 0x5D, 0x40, 0x20, 0x71, 0xA7, 0x9E, 0x2C,
  27891. 0x81, 0x0A, 0xF7, 0xC7, 0x45, 0xE3, 0x33, 0x67,
  27892. 0x12, 0x49, 0x2A, 0x42, 0x04, 0x3F, 0x29, 0x03,
  27893. 0xA3, 0x7C, 0x64, 0x34, 0xCE, 0xE2, 0x0B, 0x1D,
  27894. 0x15, 0x9B, 0x05, 0x76, 0x99, 0xFF, 0x9C, 0x1D,
  27895. 0x3B, 0xD6, 0x80, 0x29, 0x83, 0x9A, 0x08, 0xF4,
  27896. 0x3E, 0x6C, 0x1C, 0x81, 0x99, 0x13, 0x53, 0x2F,
  27897. 0x91, 0x1D, 0xD3, 0x70, 0xC7, 0x02, 0x14, 0x88,
  27898. 0xE1, 0x1C, 0xB5, 0x04, 0xCB, 0x9C, 0x70, 0x57,
  27899. 0x0F, 0xFF, 0x35, 0xB4, 0xB4, 0x60, 0x11, 0x91,
  27900. 0xDC, 0x1A, 0xD9, 0xE6, 0xAD, 0xC5, 0xFA, 0x96,
  27901. 0x18, 0x79, 0x8D, 0x7C, 0xC8, 0x60, 0xC8, 0x7A,
  27902. 0x93, 0x9E, 0x4C, 0xCF, 0x85, 0x33, 0x63, 0x22,
  27903. 0x68, 0xCF, 0x1A, 0x51, 0xAF, 0xF0, 0xCB, 0x81,
  27904. 0x1C, 0x55, 0x45, 0xCB, 0x16, 0x56, 0xE6, 0x52,
  27905. 0x69, 0x47, 0x74, 0x30, 0x69, 0x9C, 0xCD, 0xEA,
  27906. 0x38, 0x00, 0x63, 0x0B, 0x78, 0xCD, 0x58, 0x10,
  27907. 0x33, 0x4C, 0xCF, 0x02, 0xE0, 0x13, 0xF3, 0xB8,
  27908. 0x02, 0x44, 0xE7, 0x0A, 0xCD, 0xB0, 0x60, 0xBB,
  27909. 0xE7, 0xA5, 0x53, 0xB0, 0x63, 0x45, 0x6B, 0x2E,
  27910. 0xA8, 0x07, 0x47, 0x34, 0x13, 0x16, 0x5C, 0xE5,
  27911. 0x7D, 0xD5, 0x63, 0x47, 0x3C, 0xFB, 0xC9, 0x06,
  27912. 0x18, 0xAD, 0xE1, 0xF0, 0xB8, 0x88, 0xAA, 0x48,
  27913. 0xE7, 0x22, 0xBB, 0x27, 0x51, 0x85, 0x8F, 0xE1,
  27914. 0x96, 0x87, 0x44, 0x2A, 0x48, 0xE7, 0xCA, 0x0D,
  27915. 0x2A, 0x29, 0xCD, 0x51, 0xBF, 0xD8, 0xF7, 0x8C,
  27916. 0x17, 0xB9, 0x66, 0x0B, 0xFB, 0x54, 0xA4, 0x70,
  27917. 0xB2, 0xAE, 0x9A, 0x95, 0x5C, 0x6A, 0xB8, 0xD6,
  27918. 0xE5, 0xCC, 0x92, 0xAC, 0x8E, 0xD3, 0xC1, 0x85,
  27919. 0xDA, 0xA8, 0xBC, 0x29, 0xF0, 0x57, 0x8E, 0xBB,
  27920. 0x81, 0x2B, 0x97, 0xC9, 0xE5, 0xA8, 0x48, 0xA6,
  27921. 0x38, 0x4D, 0xE4, 0xE7, 0x5A, 0x31, 0x47, 0x0B,
  27922. 0x53, 0x06, 0x6A, 0x8D, 0x02, 0x7B, 0xA4, 0x4B,
  27923. 0x21, 0x74, 0x9C, 0x04, 0x92, 0x46, 0x5F, 0x90,
  27924. 0x72, 0xB2, 0x83, 0x76, 0xC4, 0xE2, 0x90, 0xB3,
  27925. 0x0C, 0x18, 0x63, 0xF9, 0xE5, 0xB7, 0x99, 0x96,
  27926. 0x08, 0x34, 0x22, 0xBD, 0x8C, 0x27, 0x2C, 0x10,
  27927. 0xEC, 0xC6, 0xEB, 0x9A, 0x0A, 0x82, 0x25, 0xB3,
  27928. 0x1A, 0xA0, 0xA6, 0x6E, 0x35, 0xB9, 0xC0, 0xB9,
  27929. 0xA7, 0x95, 0x82, 0xBA, 0x20, 0xA3, 0xC0, 0x4C,
  27930. 0xD2, 0x99, 0x14, 0xF0, 0x83, 0xA0, 0x15, 0x82,
  27931. 0x88, 0xBA, 0x4D, 0x6E, 0xB6, 0x2D, 0x87, 0x26,
  27932. 0x4B, 0x91, 0x2B, 0xCA, 0x39, 0x73, 0x2F, 0xBD,
  27933. 0xE5, 0x36, 0xA3, 0x77, 0xAD, 0x02, 0xB8, 0xC8,
  27934. 0x35, 0xD4, 0xA2, 0xF4, 0xE7, 0xB1, 0xCE, 0x11,
  27935. 0x5D, 0x0C, 0x86, 0x0B, 0xEA, 0xA7, 0x95, 0x5A,
  27936. 0x49, 0xAD, 0x68, 0x95, 0x86, 0xA8, 0x9A, 0x2B,
  27937. 0x9F, 0x9B, 0x10, 0xD1, 0x59, 0x5D, 0x2F, 0xC0,
  27938. 0x65, 0xAD, 0x01, 0x8A, 0x7D, 0x56, 0xC6, 0x14,
  27939. 0x47, 0x1F, 0x8E, 0x94, 0x6F, 0xE8, 0xAB, 0x49,
  27940. 0xE8, 0x22, 0x65, 0x91, 0x11, 0x9F, 0xCA, 0xDB,
  27941. 0x4F, 0x9A, 0x86, 0x16, 0x31, 0x37, 0x87, 0x36,
  27942. 0xB6, 0x68, 0x8B, 0x78, 0x2D, 0x58, 0xE9, 0x7E,
  27943. 0x45, 0x72, 0x75, 0x3A, 0x96, 0x64, 0xB6, 0xB8,
  27944. 0x53, 0x68, 0x12, 0xB2, 0x59, 0x11, 0xAA, 0x76,
  27945. 0xA2, 0x42, 0x37, 0x54, 0x33, 0x19, 0x27, 0x38,
  27946. 0xEE, 0xE7, 0x62, 0xF6, 0xB8, 0x43, 0x15, 0xBB,
  27947. 0x34, 0x36, 0x23, 0x1E, 0x0A, 0x9B, 0x27, 0x7E,
  27948. 0xD2, 0x8A, 0xE0, 0x05, 0x07, 0x28, 0x34, 0x64,
  27949. 0x57, 0xE1, 0x34, 0x05, 0x06, 0x2D, 0xB2, 0x80,
  27950. 0x4B, 0x8D, 0xA6, 0x0B, 0xB5, 0xC7, 0x93, 0xD4,
  27951. 0xCC, 0x0E, 0x10, 0x1C, 0xBA, 0x2D, 0x91, 0x82,
  27952. 0xFD, 0x71, 0x24, 0xFF, 0x52, 0xBF, 0x4C, 0xA2,
  27953. 0x82, 0x92, 0xAC, 0x26, 0xD6, 0x78, 0x08, 0x89,
  27954. 0x53, 0x97, 0x1D, 0xBA, 0x0B, 0x6F, 0xEC, 0x2C,
  27955. 0x96, 0x59, 0x35, 0x32, 0x91, 0xC7, 0x0C, 0x5B,
  27956. 0x92, 0x45, 0xA0, 0xCA, 0x25, 0x33, 0x04, 0xAF,
  27957. 0xD3, 0xC9, 0x51, 0x02, 0xBE, 0xA6, 0x68, 0x75,
  27958. 0xC6, 0x20, 0x16, 0x80, 0xB4, 0xBD, 0xA3, 0x86,
  27959. 0x87, 0xB6, 0x48, 0xC2, 0x8E, 0xB3, 0x74, 0x78,
  27960. 0xE3, 0xBC, 0x00, 0xCA, 0x8A, 0x3C, 0xC2, 0x72,
  27961. 0x04, 0x64, 0x2B, 0x42, 0xB6, 0x8F, 0xCB, 0xE7,
  27962. 0xB2, 0x1A, 0x36, 0x6D, 0x06, 0x68, 0xA5, 0x02,
  27963. 0x9A, 0x7D, 0xEE, 0xF9, 0x4C, 0xDD, 0x6A, 0x95,
  27964. 0xD7, 0xEA, 0x89, 0x31, 0x67, 0x3B, 0xF7, 0x11,
  27965. 0x2D, 0x40, 0x42, 0x10, 0x7B, 0x1B, 0x8B, 0x97,
  27966. 0x00, 0xC9, 0x74, 0xF9, 0xC4, 0xE8, 0x3A, 0x8F,
  27967. 0xAC, 0xD8, 0x9B, 0xFE, 0x0C, 0xA3, 0xCC, 0x4C,
  27968. 0x2F, 0xCE, 0x80, 0xA0, 0x3D, 0x35, 0x76, 0xC2,
  27969. 0x22, 0xA7, 0x92, 0xB7, 0x2B, 0x1F, 0x07, 0x0A,
  27970. 0xB7, 0xF6, 0xB6, 0xF2, 0xB5, 0xCA, 0x2A, 0xF5,
  27971. 0x05, 0x4A, 0xFA, 0x70, 0xA8, 0x96, 0x99, 0x01,
  27972. 0x59, 0xB4, 0x5D, 0x10, 0x03, 0xE2, 0xA0, 0x56,
  27973. 0x48, 0x67, 0x5E, 0x59, 0x60, 0x16, 0xF1, 0xB7,
  27974. 0x1D, 0xD0, 0xF7, 0xBD, 0xA7, 0xE2, 0x09, 0x7F,
  27975. 0xC7, 0x3B, 0x3A, 0x14, 0x3D, 0x12, 0xC7, 0x26,
  27976. 0x02, 0x0A, 0xC3, 0x49, 0x58, 0xAD, 0x70, 0x62,
  27977. 0xB9, 0x2B, 0x9A, 0xBF, 0x3C, 0xA6, 0xBE, 0x5A,
  27978. 0xE2, 0x9F, 0x57, 0x13, 0x5E, 0x62, 0x5A, 0x36,
  27979. 0x79, 0x71, 0x83, 0x7E, 0x63, 0x63, 0xD1, 0x53,
  27980. 0x20, 0x94, 0xE0, 0x22, 0xA2, 0x34, 0x67, 0xCF,
  27981. 0x93, 0x2E, 0x1F, 0x89, 0xB5, 0xB0, 0x80, 0x3C,
  27982. 0x1E, 0xC9, 0x9B, 0x58, 0x5A, 0x78, 0xB5, 0x86,
  27983. 0x50, 0x96, 0x74, 0x6F, 0x32, 0x25, 0x82, 0x14,
  27984. 0xEC, 0xB3, 0x80, 0x65, 0xC9, 0x7F, 0x45, 0x5E,
  27985. 0x15, 0x5A, 0xCC, 0x2D, 0xD0, 0x05, 0xA9, 0xC7,
  27986. 0x6B, 0xED, 0x59, 0xCD, 0xA7, 0x38, 0x37, 0xD3,
  27987. 0x03, 0x50, 0x4E, 0x6C, 0x97, 0x6A, 0x60, 0x6A,
  27988. 0x2B, 0xE7, 0xBB, 0xEC, 0x59, 0x48, 0xB9, 0x1A,
  27989. 0x34, 0x9E, 0x89, 0x36, 0x68, 0x8C, 0xC0, 0x27,
  27990. 0x97, 0x54, 0xB7, 0x43, 0xAB, 0xC5, 0x86, 0x66,
  27991. 0xB1, 0x9B, 0x6C, 0x32, 0x60, 0x05, 0x1F, 0x19,
  27992. 0x20, 0x6B, 0xB9, 0x62, 0xBB, 0x66, 0x33, 0xEB,
  27993. 0x00, 0x48, 0xE3, 0x2B, 0xAA, 0xCC, 0x5B, 0x02,
  27994. 0x0D, 0x02, 0xC8, 0x6C, 0xA9, 0x77, 0x0A, 0xD4,
  27995. 0x69, 0xDB, 0x54, 0xA1, 0x06, 0xAC, 0x73, 0xA3,
  27996. 0x5B, 0x80, 0x57, 0x42, 0x2B, 0x3D, 0xB2, 0x02,
  27997. 0xC5, 0xA5, 0xB4, 0xE3, 0xD5, 0x35, 0xF0, 0xFC,
  27998. 0x99, 0x32, 0x6C, 0x4B, 0x8B, 0x7B, 0x16, 0xF1,
  27999. 0xCB, 0x5A, 0xF9, 0x68, 0x03, 0xFA, 0x8C, 0x19,
  28000. 0x5F, 0xC0, 0xBC, 0xED, 0xDA, 0xAF, 0x01, 0x2A,
  28001. 0x51, 0x72, 0x8B, 0x76, 0x48, 0x90, 0x82, 0x37,
  28002. 0x3C, 0x91, 0xE9, 0x2C, 0x87, 0xAC, 0xCA, 0x79,
  28003. 0x51, 0x60, 0x78, 0x2E, 0x3B, 0x0D, 0xD6, 0x43,
  28004. 0x54, 0x4B, 0xB9, 0x6A, 0xBC, 0x27, 0x08, 0xD4,
  28005. 0x9B, 0x75, 0x9C, 0xF0, 0x57, 0xAA, 0x22, 0x3B,
  28006. 0xAF, 0xD9, 0x6A, 0x33, 0x0B, 0xAF, 0x39, 0x81,
  28007. 0x0F, 0xE8, 0x67, 0x1B, 0x43, 0x43, 0xC2, 0x97,
  28008. 0xDA, 0x1E, 0x19, 0x69, 0xC9, 0x96, 0x21, 0x6A,
  28009. 0xB5, 0x10, 0x6D, 0xA6, 0x68, 0x94, 0x1B, 0x16,
  28010. 0x0D, 0x44, 0x77, 0x01, 0x71, 0x36, 0xCB, 0xCA,
  28011. 0x5B, 0x5A, 0x8D, 0x44, 0xC4, 0xA8, 0xB1, 0xCF,
  28012. 0x3E, 0xF7, 0x97, 0x85, 0xE5, 0xAA, 0x25, 0xC3,
  28013. 0xA1, 0xAD, 0x6C, 0x24, 0xFD, 0x14, 0x0F, 0x79,
  28014. 0x20, 0x7D, 0xE5, 0xA4, 0x99, 0xF8, 0xA1, 0x53,
  28015. 0x4F, 0xFA, 0x80, 0x4A, 0xA7, 0xB3, 0x88, 0x9C,
  28016. 0xBE, 0x25, 0xC0, 0x41, 0x47, 0x04, 0xAA, 0x57,
  28017. 0x89, 0x7F, 0x17, 0x86, 0x23, 0x64, 0xEC, 0xA5,
  28018. 0x62, 0x58, 0x00, 0x72, 0x48, 0x81, 0x39, 0x12,
  28019. 0xB8, 0x36, 0x49, 0x7F, 0x03, 0x59, 0xC2, 0xF7,
  28020. 0x23, 0x8A, 0x05, 0xD3, 0x05, 0xA0, 0xEA, 0x15,
  28021. 0x2E, 0x72, 0xB4, 0x44, 0x17, 0xA8, 0x68, 0x13,
  28022. 0x4E, 0x91, 0xB3, 0xCA, 0x79, 0x31, 0x23, 0x2F,
  28023. 0xD4, 0xC2, 0x5F, 0x8C, 0x2A, 0x49, 0x2A, 0x33,
  28024. 0x9C, 0xDC, 0x0A, 0x13, 0x89, 0x67, 0x21, 0x14,
  28025. 0x51, 0xF2, 0x56, 0x26, 0x78, 0xFA, 0x14, 0x08,
  28026. 0x0A, 0x34, 0x43, 0x6C, 0x42, 0xB0, 0x78, 0x65,
  28027. 0xAC, 0x03, 0x6A, 0x81, 0xE9, 0x7A, 0x77, 0x87,
  28028. 0xA9, 0x38, 0x02, 0x5C, 0xAF, 0x81, 0x34, 0x50,
  28029. 0x36, 0x8B, 0xED, 0x0C, 0x94, 0xB1, 0x85, 0x76,
  28030. 0x04, 0x52, 0x64, 0x05, 0xD2, 0x7A, 0x1C, 0x1A,
  28031. 0xBC, 0x81, 0xB5, 0xB6, 0xEC, 0x13, 0xC7, 0x19,
  28032. 0x30, 0xA9, 0x7D, 0x92, 0x32, 0xCF, 0x70, 0x21,
  28033. 0xEF, 0x87, 0xA4, 0xD1, 0x55, 0x32, 0x8E, 0x62,
  28034. 0xB5, 0x83, 0xA8, 0x3B, 0x4A, 0xF2, 0x1F, 0x9F,
  28035. 0x57, 0x50, 0xF8, 0x57, 0x51, 0x50, 0x42, 0x4F,
  28036. 0x63, 0xB8, 0x99, 0xD7, 0x1C, 0xAD, 0x26, 0x7C,
  28037. 0x09, 0xE4, 0x46, 0x71, 0x46, 0xE1, 0x6E, 0x9B,
  28038. 0x6C, 0x65, 0x3F, 0x00, 0x8C, 0x31, 0x13, 0x75,
  28039. 0xE2, 0xE0, 0x06, 0xD4, 0x07, 0x6A, 0x54, 0x6B,
  28040. 0x82, 0xF5, 0x31, 0x42, 0x22, 0xF7, 0xC6, 0x54,
  28041. 0x31, 0x7E, 0x79, 0xEC, 0x60, 0x35, 0xB7, 0x3F,
  28042. 0xAF, 0x49, 0x17, 0x57, 0xE6, 0x1C, 0x82, 0x83,
  28043. 0x26, 0xD5, 0x30, 0x44, 0x54, 0x1C, 0x4D, 0x45,
  28044. 0x37, 0xAB, 0xD3, 0xEA, 0x1E, 0x67, 0x99, 0x8C,
  28045. 0x33, 0x82, 0x97, 0x4C, 0xA7, 0x8A, 0xE1, 0xB1,
  28046. 0x96, 0x0E, 0x4A, 0x92, 0x26, 0xB0, 0x21, 0x9A,
  28047. 0xB0, 0x70, 0xF0, 0xD7, 0xAA, 0x66, 0xD7, 0x6F,
  28048. 0x93, 0x16, 0xAD, 0xB8, 0x0C, 0x54, 0xD6, 0x49,
  28049. 0x97, 0x71, 0xB4, 0x71, 0xE8, 0x16, 0x8D, 0x47,
  28050. 0xBC, 0xAA, 0x08, 0x32, 0x4A, 0xB6, 0xBA, 0x92,
  28051. 0xC3, 0xA7, 0x02, 0x75, 0xF2, 0x4F, 0xA4, 0xDC,
  28052. 0x10, 0xE2, 0x51, 0x63, 0x3F, 0xB9, 0x8D, 0x16,
  28053. 0x2B, 0xB5, 0x53, 0x72, 0x02, 0xC6, 0xA5, 0x53,
  28054. 0xCE, 0x78, 0x41, 0xC4, 0xD4, 0x0B, 0x87, 0x3B,
  28055. 0x85, 0xCA, 0x03, 0xA0, 0xA1, 0xE1, 0xCF, 0xAD,
  28056. 0xE6, 0xBA, 0x51, 0x80, 0xAB, 0x13, 0x23, 0xCC,
  28057. 0xBA, 0x9A, 0x3E, 0x9C, 0x53, 0xD3, 0x75, 0x75,
  28058. 0xAB, 0x1F, 0xD9, 0xE7, 0x31, 0x6C, 0x6F, 0xEE,
  28059. 0xCB, 0x0A, 0x14, 0xDF, 0x6F, 0x2D, 0xA5, 0x6C,
  28060. 0x2F, 0x56, 0xF5, 0x5A, 0x89, 0x63, 0x5C, 0xFC,
  28061. 0xFD, 0xA4, 0x79, 0x27, 0xAF, 0x1F, 0x0A, 0x47,
  28062. 0xB2, 0xD4, 0xE4, 0xE6, 0x16, 0x34, 0xB1, 0xB5,
  28063. 0x1D, 0x37, 0xA3, 0xA3, 0x07, 0xA9, 0x72, 0x42,
  28064. 0x0D, 0xE1, 0xB7, 0xA4, 0x81, 0xB8, 0x3E, 0x58,
  28065. 0x3B, 0x6A, 0xF1, 0x6F, 0x63, 0xCB, 0x00, 0xC6
  28066. };
  28067. static const byte c_1024[KYBER1024_CIPHER_TEXT_SIZE] = {
  28068. 0x0C, 0x68, 0x1B, 0x4A, 0xA8, 0x1F, 0x26, 0xAD,
  28069. 0xFB, 0x64, 0x5E, 0xC2, 0x4B, 0x37, 0x52, 0xF6,
  28070. 0xB3, 0x2C, 0x68, 0x64, 0x5A, 0xA5, 0xE7, 0xA9,
  28071. 0x99, 0xB6, 0x20, 0x36, 0xA5, 0x3D, 0xC5, 0xCB,
  28072. 0x06, 0x0A, 0x47, 0x3C, 0x08, 0xE5, 0xDA, 0x5C,
  28073. 0x0F, 0x5A, 0xF0, 0xE5, 0x17, 0x0C, 0x65, 0x97,
  28074. 0xE5, 0x0E, 0xC0, 0x80, 0x60, 0xF9, 0x9B, 0x0C,
  28075. 0x00, 0xEE, 0x9B, 0xDD, 0xAD, 0x7E, 0x7D, 0x25,
  28076. 0xA2, 0x2B, 0x22, 0x6F, 0x90, 0x14, 0x9B, 0x4C,
  28077. 0xE8, 0x87, 0xC7, 0x2F, 0xB6, 0x0A, 0xFF, 0x21,
  28078. 0x44, 0xEA, 0x2A, 0x72, 0x38, 0x3B, 0x31, 0x18,
  28079. 0xF9, 0x22, 0xD0, 0x32, 0xA1, 0x6F, 0x55, 0x42,
  28080. 0x89, 0x90, 0x2A, 0x14, 0xCF, 0x77, 0x55, 0x51,
  28081. 0x2B, 0xB1, 0x18, 0x6B, 0xAF, 0xAF, 0xFE, 0x79,
  28082. 0x4D, 0x2B, 0x6C, 0xDE, 0x90, 0x10, 0x9E, 0x65,
  28083. 0x82, 0xD3, 0x9C, 0xE0, 0xC9, 0x61, 0x97, 0x48,
  28084. 0x4B, 0x3F, 0xA0, 0x7F, 0xC9, 0x1D, 0x39, 0x4F,
  28085. 0xC8, 0xD8, 0x8E, 0x7F, 0xC4, 0xBE, 0x00, 0x2E,
  28086. 0x2D, 0xB5, 0x6F, 0x0C, 0x4D, 0x9D, 0x3F, 0xBD,
  28087. 0xA2, 0x74, 0x53, 0x6A, 0x0B, 0x86, 0xAB, 0xC6,
  28088. 0xE3, 0x9B, 0xDA, 0x52, 0x93, 0x1A, 0xEB, 0xB8,
  28089. 0xF1, 0x08, 0x4C, 0x5C, 0x1F, 0x7C, 0xB3, 0x17,
  28090. 0x77, 0x88, 0xB7, 0xF3, 0x31, 0xB7, 0x07, 0x43,
  28091. 0x61, 0x16, 0x34, 0x91, 0xD4, 0x28, 0xE7, 0x8B,
  28092. 0xCB, 0xB5, 0x7B, 0x63, 0x08, 0x41, 0xAA, 0x98,
  28093. 0x73, 0x33, 0x37, 0x7C, 0xF0, 0x95, 0x69, 0xCF,
  28094. 0xD1, 0x4C, 0xC2, 0xA1, 0x1C, 0x50, 0x1B, 0xDF,
  28095. 0x82, 0xC9, 0x3D, 0xE0, 0x5B, 0xEA, 0x20, 0x06,
  28096. 0x0D, 0xE8, 0x9C, 0x68, 0x6B, 0x82, 0x45, 0x71,
  28097. 0xCE, 0xF9, 0x4A, 0xB3, 0xFD, 0xAF, 0xA8, 0x51,
  28098. 0x26, 0x19, 0x81, 0x36, 0x69, 0xD4, 0xF5, 0x36,
  28099. 0x37, 0xFE, 0xFA, 0x4D, 0x02, 0x8C, 0xB2, 0x33,
  28100. 0xE5, 0x69, 0x30, 0xE2, 0x23, 0x5F, 0x7E, 0x60,
  28101. 0x34, 0xCA, 0x94, 0xB1, 0x43, 0xB7, 0x7A, 0xD4,
  28102. 0xA6, 0x87, 0x56, 0xE8, 0xA9, 0x18, 0x4D, 0xBA,
  28103. 0x61, 0xA8, 0x9F, 0x91, 0xED, 0xFB, 0x51, 0xA3,
  28104. 0x92, 0x11, 0x40, 0x24, 0x73, 0xA5, 0xF8, 0x91,
  28105. 0x45, 0x73, 0x6B, 0x2B, 0xF8, 0x56, 0x9C, 0x70,
  28106. 0x5B, 0x0C, 0xDB, 0x89, 0x80, 0xA4, 0x47, 0xE4,
  28107. 0xE1, 0xEA, 0xAD, 0x3E, 0x7E, 0x05, 0x78, 0xF5,
  28108. 0xF8, 0x6B, 0x8D, 0x03, 0xC9, 0xDA, 0xFE, 0x87,
  28109. 0x5E, 0x33, 0x9B, 0x44, 0x23, 0x84, 0x56, 0x16,
  28110. 0x79, 0x9E, 0xDC, 0xE0, 0x5F, 0x31, 0xB9, 0x26,
  28111. 0x64, 0xC5, 0xA5, 0x92, 0x53, 0xA6, 0x0E, 0x9D,
  28112. 0x89, 0x54, 0x8A, 0x30, 0x0C, 0x1A, 0xDB, 0x6D,
  28113. 0x19, 0x0A, 0x77, 0x5C, 0x5E, 0xE6, 0xE8, 0xA8,
  28114. 0x9B, 0x6E, 0x77, 0x9B, 0x03, 0x4C, 0x34, 0x00,
  28115. 0xA6, 0x25, 0xF4, 0xBB, 0xED, 0xBF, 0x91, 0x9C,
  28116. 0x45, 0xB2, 0xBC, 0xD1, 0x4C, 0x66, 0x92, 0x48,
  28117. 0xFC, 0x43, 0xC3, 0xEF, 0x47, 0xE1, 0x00, 0x75,
  28118. 0x89, 0x42, 0xE7, 0x5E, 0x8E, 0xD6, 0x07, 0x5A,
  28119. 0x96, 0xD7, 0x0D, 0x4E, 0xBD, 0x2B, 0x61, 0x35,
  28120. 0x82, 0x24, 0xDD, 0xA1, 0xEC, 0x4C, 0x19, 0xC2,
  28121. 0xA9, 0x28, 0x98, 0x17, 0x6F, 0xEB, 0x3C, 0x02,
  28122. 0xED, 0xCB, 0x99, 0x08, 0xBA, 0xE4, 0x9B, 0xD9,
  28123. 0x4A, 0xF0, 0x28, 0xED, 0xF8, 0xCF, 0xC2, 0xE5,
  28124. 0xF2, 0xE0, 0xBD, 0x37, 0x50, 0x06, 0x98, 0x6A,
  28125. 0xD4, 0x9E, 0x71, 0x75, 0x48, 0xE7, 0x46, 0xFE,
  28126. 0xF4, 0x9C, 0x86, 0x8B, 0xCE, 0xA2, 0x79, 0x0A,
  28127. 0xA9, 0x7E, 0x04, 0x06, 0x1B, 0x75, 0x60, 0x5C,
  28128. 0xB3, 0x9E, 0xFD, 0x46, 0x3D, 0x7B, 0x3D, 0x68,
  28129. 0xBA, 0x57, 0x44, 0x34, 0xFF, 0x7B, 0xE8, 0xE2,
  28130. 0xB8, 0x4B, 0xFC, 0x47, 0xE6, 0x7E, 0x9C, 0xD1,
  28131. 0x5F, 0x3E, 0xD4, 0x50, 0xC6, 0x1A, 0xFB, 0xA7,
  28132. 0x9A, 0x20, 0xB0, 0xB6, 0xF2, 0x87, 0x77, 0x7C,
  28133. 0x72, 0xF4, 0xAD, 0x24, 0x81, 0x74, 0xF1, 0x95,
  28134. 0x94, 0x77, 0xAA, 0x7A, 0x7C, 0x97, 0xF1, 0x22,
  28135. 0xC5, 0x04, 0x47, 0xC7, 0x48, 0x4F, 0x38, 0x2B,
  28136. 0xC4, 0x7D, 0x81, 0xFC, 0xC9, 0xC7, 0xE8, 0x92,
  28137. 0xC8, 0x83, 0x9D, 0x37, 0xB3, 0x53, 0x94, 0xB5,
  28138. 0x3E, 0x6B, 0x2B, 0x18, 0x95, 0xAB, 0xB0, 0xDE,
  28139. 0x8C, 0x98, 0xF2, 0x63, 0x3D, 0xC4, 0x41, 0x3A,
  28140. 0x8D, 0x57, 0x35, 0xDF, 0xC9, 0xA6, 0x40, 0x26,
  28141. 0xB6, 0xF3, 0x47, 0x79, 0xD6, 0xAC, 0x8A, 0xD9,
  28142. 0x9C, 0xC3, 0x1A, 0xA8, 0x98, 0xC2, 0xE7, 0x05,
  28143. 0x7F, 0x3D, 0xB8, 0xA1, 0xA8, 0xA9, 0x85, 0x27,
  28144. 0xA7, 0x9E, 0x43, 0x55, 0x2F, 0x28, 0xD1, 0x02,
  28145. 0x3E, 0x1F, 0x6A, 0x6B, 0x84, 0x85, 0x5C, 0xF5,
  28146. 0xE6, 0xDF, 0x88, 0x9B, 0xA2, 0x69, 0xF0, 0x48,
  28147. 0x94, 0x6E, 0x84, 0x02, 0x1C, 0x65, 0xC5, 0xA9,
  28148. 0x3B, 0x00, 0x7B, 0x07, 0x74, 0x1C, 0x1E, 0xE1,
  28149. 0x76, 0xC7, 0x39, 0x49, 0x11, 0x0F, 0x54, 0x8E,
  28150. 0xF4, 0x33, 0x2D, 0xCD, 0xD4, 0x91, 0xD2, 0xCE,
  28151. 0xFD, 0x02, 0x48, 0x88, 0x3F, 0x5E, 0x95, 0x25,
  28152. 0xBC, 0x91, 0xF3, 0x0A, 0xF1, 0x7C, 0xF5, 0xA9,
  28153. 0x8D, 0xD4, 0x4E, 0xF9, 0xA7, 0x1F, 0x99, 0xBB,
  28154. 0x73, 0x29, 0x85, 0xBA, 0x10, 0xA7, 0x23, 0xEF,
  28155. 0x47, 0x6F, 0xCF, 0x96, 0x6D, 0xA9, 0x45, 0x6B,
  28156. 0x24, 0x97, 0x8E, 0x33, 0x05, 0x0D, 0x0E, 0xC9,
  28157. 0x0D, 0x3C, 0xE4, 0x63, 0x78, 0x85, 0x1C, 0x9E,
  28158. 0xCF, 0xCF, 0xD3, 0x6C, 0x89, 0x5D, 0x44, 0xE9,
  28159. 0xE5, 0x06, 0x99, 0x30, 0x82, 0x52, 0x3D, 0x26,
  28160. 0x18, 0x57, 0x66, 0xB2, 0x35, 0x68, 0xCB, 0x95,
  28161. 0xE6, 0x41, 0x08, 0xF8, 0x9D, 0x10, 0x14, 0x74,
  28162. 0x7C, 0x67, 0xB6, 0xF3, 0xC8, 0x76, 0x7B, 0xE5,
  28163. 0xFC, 0x34, 0x12, 0x27, 0xDE, 0x94, 0x88, 0x86,
  28164. 0x1C, 0x5F, 0xE8, 0x11, 0x40, 0x9F, 0x80, 0x95,
  28165. 0x7D, 0x07, 0x52, 0x2A, 0x72, 0xCF, 0x6A, 0xB0,
  28166. 0x37, 0x8D, 0x0F, 0x2F, 0x28, 0xAF, 0x54, 0x81,
  28167. 0x85, 0xC3, 0x93, 0x67, 0x77, 0x99, 0x44, 0x66,
  28168. 0xA0, 0x19, 0xD3, 0x3B, 0x18, 0xA5, 0x4F, 0x38,
  28169. 0x0A, 0x33, 0x89, 0x2A, 0xB4, 0xD4, 0xBD, 0x50,
  28170. 0x7B, 0x5A, 0x61, 0xD0, 0xD3, 0x58, 0x34, 0x1A,
  28171. 0xC9, 0x2F, 0x07, 0xB4, 0x3B, 0x8F, 0x6A, 0xFC,
  28172. 0x69, 0x91, 0xBB, 0x6A, 0x1E, 0xAC, 0x23, 0xCA,
  28173. 0x6F, 0x73, 0xE9, 0x1F, 0x24, 0x64, 0xBD, 0x11,
  28174. 0x90, 0x98, 0xD7, 0xE7, 0x68, 0xE7, 0x7E, 0xCE,
  28175. 0x53, 0xFB, 0x89, 0x9B, 0xEB, 0x42, 0x26, 0x5E,
  28176. 0xCF, 0x7B, 0x27, 0x1F, 0x66, 0x54, 0x62, 0x82,
  28177. 0xD4, 0x72, 0xC3, 0x62, 0x39, 0x00, 0x6B, 0xB0,
  28178. 0xAB, 0xAB, 0xCC, 0xA2, 0x45, 0x50, 0xBA, 0xA0,
  28179. 0xA6, 0x01, 0x34, 0x8C, 0x81, 0x0F, 0xF5, 0xF9,
  28180. 0xEE, 0x50, 0x4B, 0xF7, 0x15, 0x5D, 0xEE, 0x41,
  28181. 0x41, 0xA1, 0x16, 0x05, 0xA4, 0xF3, 0x50, 0x9A,
  28182. 0xC9, 0xCA, 0xEF, 0x66, 0x24, 0xD2, 0x1D, 0xE3,
  28183. 0x32, 0xD5, 0xD5, 0x08, 0x28, 0xB5, 0x2E, 0x92,
  28184. 0x88, 0x5D, 0x3B, 0x90, 0x55, 0x3B, 0x14, 0x46,
  28185. 0x3A, 0xFB, 0x1E, 0xDC, 0xCD, 0x3B, 0x56, 0x9B,
  28186. 0x5A, 0x7F, 0x00, 0xBB, 0x66, 0x76, 0x9D, 0xAD,
  28187. 0xAC, 0x23, 0xAD, 0x8B, 0xB5, 0xD7, 0x3A, 0x6F,
  28188. 0x39, 0x0E, 0x6F, 0xC2, 0xF6, 0xF8, 0xEE, 0x3C,
  28189. 0xF4, 0x00, 0x9A, 0x5C, 0x3E, 0x1E, 0xF6, 0x0E,
  28190. 0x8F, 0x04, 0x06, 0x72, 0xD2, 0x62, 0xE6, 0x49,
  28191. 0x03, 0x79, 0xBB, 0xC7, 0x04, 0x95, 0xDF, 0xF2,
  28192. 0x37, 0xBE, 0xCD, 0x99, 0x52, 0xCD, 0x7E, 0xDE,
  28193. 0xB6, 0xD1, 0xDF, 0xC3, 0x60, 0xB3, 0xFC, 0x8B,
  28194. 0x0A, 0xF4, 0x80, 0xFF, 0xE0, 0x24, 0xAE, 0xEF,
  28195. 0xCD, 0x4E, 0x9C, 0xE9, 0x5D, 0x9B, 0x46, 0x9C,
  28196. 0x9A, 0x70, 0xE5, 0x11, 0x0D, 0xA0, 0xBA, 0xC1,
  28197. 0x24, 0xFC, 0x37, 0x41, 0xDC, 0xF4, 0x91, 0x16,
  28198. 0x26, 0x17, 0x96, 0x50, 0x4D, 0x5F, 0x49, 0x0B,
  28199. 0x43, 0x3C, 0x33, 0xC4, 0x0E, 0xDC, 0xE2, 0xB7,
  28200. 0x51, 0x51, 0xDA, 0x25, 0x6A, 0x86, 0x8A, 0x5E,
  28201. 0x35, 0xF8, 0x62, 0x26, 0xB8, 0x15, 0x1C, 0x91,
  28202. 0x93, 0x4C, 0xCC, 0x3D, 0xAC, 0xA3, 0x91, 0xDE,
  28203. 0xCC, 0xA7, 0x45, 0x37, 0x56, 0x60, 0xB6, 0xEC,
  28204. 0x41, 0xAE, 0x5D, 0x81, 0x08, 0x38, 0xCB, 0xEE,
  28205. 0xFF, 0xA1, 0x25, 0x57, 0x88, 0x44, 0x12, 0x35,
  28206. 0x7B, 0x10, 0x08, 0x36, 0x3D, 0x32, 0xB2, 0x37,
  28207. 0xAA, 0x1D, 0xD8, 0xE2, 0xD9, 0xC6, 0x36, 0x7A,
  28208. 0xDA, 0x09, 0xB2, 0xC9, 0x50, 0x60, 0x20, 0x6C,
  28209. 0xEC, 0x3E, 0xED, 0x39, 0x1F, 0xDC, 0x5D, 0xBE,
  28210. 0xF6, 0xF0, 0x8B, 0xDF, 0x04, 0x08, 0xE5, 0x85,
  28211. 0xAE, 0x5E, 0xBC, 0x8E, 0x97, 0x45, 0xD4, 0x4F,
  28212. 0xEC, 0xA9, 0x75, 0xAB, 0xBC, 0x14, 0x0B, 0xB3,
  28213. 0x7B, 0x8A, 0xDD, 0x16, 0xFC, 0xC2, 0x95, 0x69,
  28214. 0x10, 0xDC, 0x72, 0xBB, 0x3F, 0x02, 0xE9, 0xA1,
  28215. 0x30, 0xC9, 0xA8, 0x4F, 0x9C, 0xCB, 0x74, 0xD1,
  28216. 0x34, 0xCD, 0xF4, 0x0A, 0xFC, 0xBA, 0x20, 0x09,
  28217. 0xC8, 0xF0, 0x04, 0x02, 0x39, 0xBC, 0x99, 0x22,
  28218. 0x0E, 0xF6, 0x4C, 0x4D, 0xCC, 0xDE, 0x2E, 0x2E,
  28219. 0x5C, 0x9B, 0x68, 0x60, 0x2F, 0xBE, 0x8E, 0xF4,
  28220. 0xC9, 0x8B, 0x34, 0x68, 0xC7, 0x9D, 0xF4, 0xE0,
  28221. 0x78, 0x51, 0x1B, 0xFB, 0x8A, 0xA3, 0xDA, 0x09,
  28222. 0x59, 0x7A, 0x02, 0x51, 0x1E, 0x7C, 0x21, 0xA7,
  28223. 0xCF, 0x66, 0xA9, 0x38, 0x43, 0xA9, 0x48, 0x68,
  28224. 0xF1, 0x9E, 0x85, 0x52, 0x55, 0x2E, 0x3A, 0xCD,
  28225. 0xF6, 0xCB, 0x81, 0x06, 0x34, 0xDB, 0x97, 0xCB,
  28226. 0xC4, 0xBB, 0x56, 0x97, 0x09, 0xDA, 0xD4, 0x84,
  28227. 0x56, 0x45, 0x44, 0x6F, 0xA8, 0xD2, 0x89, 0xFC,
  28228. 0x59, 0x30, 0x7B, 0x80, 0x1E, 0x60, 0xCE, 0x2A,
  28229. 0x91, 0xE0, 0x6E, 0x9C, 0x22, 0xC1, 0x6E, 0x2E,
  28230. 0x59, 0xBD, 0xE3, 0x8A, 0x41, 0x6B, 0xB1, 0xB4,
  28231. 0xAC, 0x54, 0x57, 0x43, 0x8F, 0xDC, 0x5D, 0x64,
  28232. 0x45, 0x0A, 0x89, 0xEC, 0xB8, 0x32, 0xC1, 0xBB,
  28233. 0x27, 0x9D, 0xBF, 0x59, 0x33, 0x46, 0x81, 0x77,
  28234. 0x6A, 0xC0, 0x04, 0x09, 0x84, 0x6D, 0x09, 0xD6,
  28235. 0xF6, 0x87, 0x77, 0x2E, 0x34, 0x08, 0x50, 0xAB,
  28236. 0x86, 0x73, 0x38, 0x42, 0x15, 0xE1, 0x2C, 0x8D,
  28237. 0x0F, 0x53, 0x1C, 0x45, 0x1E, 0x58, 0x49, 0x3E,
  28238. 0x0E, 0xE4, 0x15, 0xAD, 0x59, 0x4D, 0xF3, 0x8C,
  28239. 0x34, 0x40, 0x8C, 0x7E, 0xD9, 0xF0, 0xC3, 0x92,
  28240. 0xF1, 0x53, 0x46, 0x04, 0xEA, 0xC3, 0xD9, 0xC1,
  28241. 0x54, 0x65, 0xA9, 0xA4, 0x66, 0x32, 0x21, 0x4B,
  28242. 0x53, 0x69, 0x90, 0xD7, 0x80, 0x78, 0xE5, 0xBD,
  28243. 0x7E, 0xAE, 0x20, 0x13, 0xFF, 0xF8, 0xFD, 0xD8,
  28244. 0xB2, 0x75, 0xC8, 0x9D, 0x97, 0xC9, 0x35, 0x3D,
  28245. 0xF3, 0xC4, 0x2A, 0x28, 0xE8, 0x14, 0xD8, 0x46,
  28246. 0x8E, 0x2B, 0x48, 0xDB, 0x09, 0x76, 0xD8, 0x8F,
  28247. 0x5E, 0xEC, 0xEF, 0xEA, 0xFB, 0x8F, 0x7F, 0x4A,
  28248. 0xF2, 0x91, 0xA7, 0x28, 0xF6, 0x24, 0x9E, 0xCF,
  28249. 0x56, 0x22, 0x33, 0x92, 0x69, 0xAA, 0x94, 0x53,
  28250. 0x29, 0xE9, 0x19, 0xF8, 0xB4, 0x41, 0xC8, 0x3D,
  28251. 0x55, 0x07, 0xF3, 0x0D, 0xF0, 0xFD, 0x2B, 0x13,
  28252. 0xFF, 0x80, 0x6F, 0x52, 0x2D, 0xAA, 0x11, 0xAF,
  28253. 0x67, 0x6A, 0x51, 0x3C, 0x14, 0x9C, 0x70, 0xF0,
  28254. 0xD6, 0xE9, 0x9A, 0x88, 0x04, 0x50, 0xA5, 0x4E,
  28255. 0x04, 0x17, 0xFE, 0x3C, 0x1E, 0x51, 0x3E, 0x9D,
  28256. 0x92, 0x0E, 0x30, 0xA8, 0xB4, 0x28, 0x91, 0x26,
  28257. 0x7A, 0x2D, 0xC5, 0x0A, 0xD8, 0x1F, 0x98, 0x04,
  28258. 0x49, 0x20, 0xC0, 0x99, 0xDF, 0x22, 0xC7, 0x39,
  28259. 0x98, 0xA2, 0x5C, 0x58, 0x1A, 0x51, 0x78, 0xC7,
  28260. 0x2B, 0x17, 0xAC, 0x87, 0x5B, 0xC6, 0x85, 0x48,
  28261. 0xA0, 0xFB, 0x0C, 0xBE, 0xE3, 0x8F, 0x05, 0x01,
  28262. 0x7B, 0x12, 0x43, 0x33, 0x43, 0xA6, 0x58, 0xF1,
  28263. 0x98, 0x0C, 0x81, 0x24, 0xEA, 0x6D, 0xD8, 0x1F
  28264. };
  28265. static const byte kprime_1024[KYBER_SS_SZ] = {
  28266. 0x8F, 0x33, 0x6E, 0x9C, 0x28, 0xDF, 0x34, 0x9E,
  28267. 0x03, 0x22, 0x0A, 0xF0, 0x1C, 0x42, 0x83, 0x2F,
  28268. 0xEF, 0xAB, 0x1F, 0x2A, 0x74, 0xC1, 0x6F, 0xAF,
  28269. 0x6F, 0x64, 0xAD, 0x07, 0x1C, 0x1A, 0x33, 0x94
  28270. };
  28271. #endif
  28272. static byte ss[KYBER_SS_SZ];
  28273. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28274. ExpectNotNull(key);
  28275. if (key != NULL) {
  28276. XMEMSET(key, 0, sizeof(KyberKey));
  28277. }
  28278. #ifndef WOLFSSL_NO_KYBER512
  28279. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  28280. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_512, sizeof(dk_512)), 0);
  28281. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_512, sizeof(c_512)), 0);
  28282. ExpectIntEQ(XMEMCMP(ss, kprime_512, KYBER_SS_SZ), 0);
  28283. wc_KyberKey_Free(key);
  28284. #endif
  28285. #ifndef WOLFSSL_NO_KYBER768
  28286. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  28287. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_768, sizeof(dk_768)), 0);
  28288. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_768, sizeof(c_768)), 0);
  28289. ExpectIntEQ(XMEMCMP(ss, kprime_768, KYBER_SS_SZ), 0);
  28290. wc_KyberKey_Free(key);
  28291. #endif
  28292. #ifndef WOLFSSL_NO_KYBER1024
  28293. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  28294. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_1024, sizeof(dk_1024)), 0);
  28295. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_1024, sizeof(c_1024)), 0);
  28296. ExpectIntEQ(XMEMCMP(ss, kprime_1024, KYBER_SS_SZ), 0);
  28297. wc_KyberKey_Free(key);
  28298. #endif
  28299. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28300. #endif
  28301. return EXPECT_RESULT();
  28302. }
  28303. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28304. !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && !defined(WOLFSSL_NO_ML_DSA_44)
  28305. static const byte ml_dsa_44_pub_key[] = {
  28306. 0x7c, 0x33, 0x31, 0x41, 0x15, 0xa7, 0x2d, 0x6b,
  28307. 0x17, 0x7c, 0x10, 0xab, 0x75, 0xf7, 0x83, 0xb3,
  28308. 0x30, 0x75, 0x6f, 0xa9, 0x42, 0xb0, 0x9b, 0x59,
  28309. 0x59, 0x99, 0x2b, 0x5d, 0x7d, 0x6e, 0xeb, 0xdd,
  28310. 0xd9, 0x99, 0x8f, 0x7b, 0xad, 0xe5, 0x90, 0x0f,
  28311. 0xa4, 0x80, 0xd8, 0xa2, 0x0d, 0x95, 0xea, 0x63,
  28312. 0x2b, 0xcf, 0xb4, 0x5b, 0x3c, 0xd1, 0x5a, 0xc4,
  28313. 0xc4, 0xd1, 0x71, 0x28, 0x4b, 0x0b, 0x28, 0x32,
  28314. 0x73, 0xb5, 0x0d, 0xd6, 0x8f, 0x6b, 0x01, 0x26,
  28315. 0x04, 0x45, 0xa3, 0x80, 0xc0, 0x21, 0x12, 0xee,
  28316. 0x52, 0x0f, 0x35, 0xe4, 0x8e, 0xca, 0xf8, 0x91,
  28317. 0xf4, 0x99, 0x51, 0xe2, 0x80, 0x76, 0xa7, 0x2d,
  28318. 0x09, 0xf5, 0x04, 0xcc, 0xa6, 0x6b, 0x20, 0xc4,
  28319. 0xac, 0xcd, 0x6c, 0x9c, 0x09, 0xe7, 0x51, 0xa2,
  28320. 0x29, 0x60, 0xfd, 0xf2, 0xbd, 0x7e, 0x4c, 0x9d,
  28321. 0xc0, 0xba, 0x62, 0x2f, 0x53, 0xb2, 0x47, 0x03,
  28322. 0xf2, 0x6f, 0x70, 0x51, 0xa8, 0xe1, 0xb7, 0x9f,
  28323. 0x37, 0x15, 0xfa, 0xd1, 0x6c, 0x74, 0x1a, 0x2b,
  28324. 0x4f, 0x39, 0x4f, 0x43, 0x49, 0x71, 0x6a, 0xf8,
  28325. 0x7c, 0x65, 0x1a, 0xdd, 0x1a, 0x25, 0xf8, 0x79,
  28326. 0xfa, 0x8c, 0x02, 0xf2, 0xf7, 0xf7, 0x7b, 0x9f,
  28327. 0xe4, 0xaf, 0x9e, 0x1a, 0x0b, 0x5b, 0x2e, 0x41,
  28328. 0xbb, 0xa9, 0x4f, 0xd0, 0xdb, 0xad, 0xe5, 0x25,
  28329. 0xff, 0x36, 0x3b, 0x9a, 0xc3, 0xdf, 0xb6, 0x27,
  28330. 0xd3, 0xba, 0xb0, 0xd4, 0xb2, 0x07, 0xc3, 0xd8,
  28331. 0xab, 0x10, 0x3d, 0xcd, 0x23, 0x52, 0x46, 0xe6,
  28332. 0x96, 0x57, 0x85, 0xc7, 0x60, 0xe2, 0x8c, 0x46,
  28333. 0x65, 0x7d, 0x76, 0x1c, 0x45, 0x20, 0x5d, 0x51,
  28334. 0xd6, 0x13, 0xde, 0xe5, 0x3d, 0xc2, 0x8c, 0x36,
  28335. 0xdb, 0x7f, 0x83, 0x6f, 0x6a, 0xc2, 0xa3, 0xf2,
  28336. 0xdc, 0x63, 0x69, 0x7f, 0xbd, 0xd0, 0xc1, 0x90,
  28337. 0xfb, 0x62, 0x42, 0xa1, 0xf6, 0xf7, 0xdd, 0xc2,
  28338. 0x4a, 0x38, 0x62, 0x9b, 0xef, 0x67, 0xf9, 0x5c,
  28339. 0xd8, 0xff, 0xf4, 0xf2, 0x67, 0x90, 0x42, 0x85,
  28340. 0xaf, 0xe2, 0x92, 0x6e, 0xc4, 0x9b, 0x63, 0xc3,
  28341. 0x91, 0xa5, 0x11, 0x66, 0x13, 0x83, 0xbc, 0xbb,
  28342. 0xc7, 0x34, 0x3b, 0x30, 0x40, 0x53, 0x91, 0xdf,
  28343. 0x7c, 0x3d, 0x17, 0xdd, 0xa1, 0xa6, 0x80, 0xfd,
  28344. 0x26, 0x9d, 0x60, 0x7b, 0xcd, 0xb4, 0x2b, 0xba,
  28345. 0x61, 0x0f, 0x43, 0x7c, 0x51, 0x3c, 0xb9, 0xfa,
  28346. 0xdb, 0x48, 0x35, 0x9f, 0x0d, 0x0c, 0x04, 0xe8,
  28347. 0xf9, 0x6e, 0x07, 0x65, 0x7d, 0x46, 0x1b, 0xd2,
  28348. 0x51, 0xdb, 0x55, 0x27, 0xd7, 0x3d, 0x1e, 0x36,
  28349. 0x07, 0x59, 0x18, 0xec, 0x04, 0x4b, 0x87, 0xbb,
  28350. 0xfb, 0x27, 0xac, 0xeb, 0x8f, 0x43, 0x46, 0xd0,
  28351. 0x39, 0x00, 0x90, 0x54, 0x70, 0xb1, 0x71, 0xf2,
  28352. 0xe7, 0x3d, 0x02, 0x1a, 0xcf, 0x87, 0x16, 0x67,
  28353. 0xa2, 0x3c, 0x31, 0x48, 0xe8, 0xbd, 0x4f, 0xb3,
  28354. 0xc2, 0xfd, 0x3d, 0xa1, 0x9c, 0x87, 0x54, 0x60,
  28355. 0x30, 0x21, 0x52, 0x57, 0xcd, 0x03, 0x96, 0x9e,
  28356. 0xa7, 0x8d, 0xe5, 0x02, 0x04, 0x78, 0x43, 0x72,
  28357. 0xda, 0xb2, 0x22, 0xf1, 0xee, 0x8f, 0x27, 0x0b,
  28358. 0x8f, 0x7b, 0xf8, 0xbc, 0x16, 0xa1, 0xef, 0x0b,
  28359. 0x35, 0xda, 0xfc, 0x29, 0x1b, 0xf8, 0xa1, 0x35,
  28360. 0x40, 0xe7, 0xed, 0x4c, 0x02, 0x4a, 0x83, 0xb7,
  28361. 0x49, 0x75, 0x34, 0x3f, 0x2b, 0xb3, 0x61, 0xf5,
  28362. 0xa3, 0x9b, 0x23, 0xca, 0xfb, 0x58, 0x16, 0x4f,
  28363. 0x3c, 0x50, 0xbf, 0x81, 0xab, 0x54, 0x50, 0x1a,
  28364. 0x39, 0x57, 0x5f, 0x9a, 0x72, 0x22, 0xba, 0xa4,
  28365. 0xf6, 0xbf, 0xac, 0x31, 0x5c, 0xc5, 0x96, 0xd7,
  28366. 0xa9, 0xe4, 0x3b, 0x0c, 0xd0, 0x7f, 0x79, 0x68,
  28367. 0x4d, 0x41, 0x04, 0x81, 0x73, 0xcf, 0x47, 0x4a,
  28368. 0x7b, 0x37, 0xac, 0x8e, 0x47, 0x0d, 0x72, 0x65,
  28369. 0x0f, 0x9d, 0x44, 0xd7, 0x08, 0x21, 0x5b, 0x3f,
  28370. 0xc8, 0x9d, 0xea, 0xa2, 0x64, 0x7b, 0x0d, 0x98,
  28371. 0xc1, 0x61, 0xcd, 0xa4, 0xf7, 0x8c, 0x4a, 0xa3,
  28372. 0x3b, 0xdd, 0x92, 0xce, 0x61, 0x97, 0x0e, 0x98,
  28373. 0xa4, 0x10, 0xb5, 0x1f, 0xc5, 0xfb, 0xee, 0x49,
  28374. 0x36, 0x8f, 0xe3, 0x2d, 0x46, 0x9c, 0xa9, 0xff,
  28375. 0xdd, 0x1a, 0x48, 0x1b, 0x5a, 0x99, 0x84, 0x0a,
  28376. 0x3d, 0x5c, 0xd7, 0x67, 0x32, 0x88, 0x87, 0x2a,
  28377. 0x34, 0x50, 0x04, 0xad, 0xe6, 0xbb, 0x3c, 0xb5,
  28378. 0xee, 0x80, 0x99, 0x70, 0xaa, 0x9d, 0x5a, 0x63,
  28379. 0xec, 0xd5, 0x9a, 0x6a, 0x3a, 0xe8, 0xaa, 0x3d,
  28380. 0x3f, 0xe8, 0x15, 0x2c, 0x16, 0x3e, 0x86, 0x46,
  28381. 0x21, 0xf2, 0xd2, 0x6e, 0x74, 0x3d, 0x53, 0x94,
  28382. 0x7c, 0x41, 0xec, 0x5b, 0xf5, 0xa4, 0xc8, 0x1f,
  28383. 0x75, 0x22, 0x50, 0x58, 0x31, 0xf5, 0x29, 0x9a,
  28384. 0xc2, 0x2c, 0x67, 0xd9, 0xf6, 0x2e, 0xa1, 0xa9,
  28385. 0x0a, 0x69, 0x90, 0x7a, 0xd8, 0xed, 0x5c, 0x09,
  28386. 0x3d, 0x14, 0xa3, 0x2b, 0xc0, 0x47, 0x88, 0xb7,
  28387. 0xea, 0x14, 0x8a, 0xec, 0xaf, 0x0c, 0xb7, 0xc6,
  28388. 0x7c, 0x32, 0x0f, 0x57, 0xea, 0x9f, 0xd4, 0x99,
  28389. 0x8d, 0xab, 0xd6, 0xc9, 0x31, 0x07, 0x81, 0x37,
  28390. 0x3d, 0xf5, 0x07, 0xb3, 0x93, 0xb7, 0x04, 0x20,
  28391. 0xdf, 0x91, 0xef, 0xfb, 0xa6, 0x7d, 0x4b, 0x5d,
  28392. 0xd4, 0x24, 0xd2, 0x0b, 0xc5, 0x34, 0xf6, 0x7a,
  28393. 0xf9, 0x4a, 0x48, 0xc7, 0xab, 0xaf, 0xa8, 0xd2,
  28394. 0xfc, 0x41, 0xc9, 0x8b, 0xa8, 0xc4, 0x2f, 0x94,
  28395. 0x4e, 0xb0, 0xab, 0xd3, 0xd9, 0x09, 0x4b, 0x1f,
  28396. 0x35, 0xb7, 0xb4, 0x4c, 0x2d, 0x6b, 0xe6, 0xb4,
  28397. 0x2e, 0x8a, 0x09, 0xd3, 0x9d, 0x54, 0x3f, 0x53,
  28398. 0xcc, 0x8e, 0x16, 0x18, 0x4e, 0x9a, 0xe8, 0x52,
  28399. 0x84, 0x3a, 0x3e, 0xdb, 0xab, 0x65, 0xc4, 0xa1,
  28400. 0x3c, 0xd0, 0xf6, 0x57, 0x3c, 0x0e, 0x10, 0xed,
  28401. 0xb2, 0xa9, 0x7d, 0x70, 0x3f, 0x18, 0x1a, 0xba,
  28402. 0x31, 0x33, 0xcb, 0x2a, 0xfd, 0x13, 0xf5, 0x23,
  28403. 0xd7, 0x71, 0xfa, 0xb6, 0xe8, 0xda, 0x63, 0xca,
  28404. 0x55, 0x3c, 0x5b, 0x87, 0x27, 0x96, 0x3d, 0xd0,
  28405. 0x43, 0x9d, 0x76, 0x9f, 0x28, 0x5a, 0xb6, 0xc8,
  28406. 0x81, 0xe4, 0x7c, 0x2a, 0x7a, 0x84, 0x0f, 0x2d,
  28407. 0x1b, 0xd0, 0xe4, 0x0e, 0x1b, 0x47, 0x32, 0xc8,
  28408. 0x02, 0x2d, 0x39, 0x0e, 0x7d, 0xb1, 0x12, 0x56,
  28409. 0x50, 0x00, 0xae, 0xcc, 0x45, 0x0a, 0xd5, 0x30,
  28410. 0x16, 0xe7, 0x3a, 0x53, 0x02, 0xbc, 0xd5, 0xef,
  28411. 0xca, 0x00, 0xea, 0x5f, 0xbe, 0x15, 0x0d, 0x08,
  28412. 0x76, 0xc1, 0x03, 0x93, 0x96, 0x4a, 0x88, 0xda,
  28413. 0x9d, 0x0b, 0x51, 0x39, 0x9a, 0xef, 0xd2, 0xde,
  28414. 0x8a, 0x2c, 0xe6, 0xf3, 0xa5, 0x70, 0x15, 0x3a,
  28415. 0x17, 0x43, 0x31, 0xfc, 0x47, 0x9d, 0xec, 0x3b,
  28416. 0x28, 0x6f, 0xdf, 0x45, 0x6f, 0x9e, 0x10, 0xbb,
  28417. 0x8e, 0x43, 0xc5, 0x59, 0xe5, 0x61, 0x9b, 0xa7,
  28418. 0xa1, 0xb8, 0x7a, 0x1c, 0xd4, 0x25, 0x26, 0xca,
  28419. 0xe9, 0x2b, 0x0b, 0x3d, 0x06, 0xeb, 0x44, 0x44,
  28420. 0xab, 0x4a, 0x5e, 0x68, 0x5c, 0x93, 0xf1, 0x3f,
  28421. 0x39, 0x01, 0xb9, 0xf1, 0x01, 0xb7, 0xb6, 0x14,
  28422. 0x44, 0x1d, 0x6d, 0x6b, 0x03, 0x45, 0x0d, 0xf3,
  28423. 0xbf, 0x71, 0x4e, 0xf3, 0x84, 0x3d, 0xef, 0xea,
  28424. 0x60, 0x2e, 0x2e, 0xf7, 0x33, 0xa6, 0xbe, 0x53,
  28425. 0x49, 0x26, 0xed, 0xb4, 0xbf, 0x7f, 0xb0, 0x1d,
  28426. 0x39, 0xb2, 0xc2, 0x88, 0xc2, 0xa2, 0xd4, 0x7f,
  28427. 0x0e, 0x1c, 0x44, 0xa3, 0x38, 0x76, 0xa7, 0xa6,
  28428. 0x19, 0x7e, 0x4c, 0x84, 0x25, 0x01, 0xb2, 0x78,
  28429. 0xb4, 0x56, 0xc5, 0xc1, 0x50, 0x3f, 0xf2, 0xb6,
  28430. 0x76, 0x09, 0x55, 0x57, 0x1c, 0xd1, 0x55, 0x23,
  28431. 0x16, 0x2a, 0x51, 0x16, 0xaa, 0x13, 0x4f, 0x35,
  28432. 0x69, 0xaf, 0xea, 0x01, 0x5f, 0x22, 0xc9, 0x2e,
  28433. 0xe9, 0x8c, 0x6c, 0xa2, 0x17, 0x92, 0xdc, 0x3d,
  28434. 0xd6, 0xf0, 0xfa, 0x5a, 0x53, 0xe0, 0xcd, 0x55,
  28435. 0xa2, 0x91, 0x62, 0xba, 0xae, 0x67, 0x40, 0x1c,
  28436. 0xda, 0xb4, 0xcc, 0xfc, 0x67, 0x1f, 0x44, 0xa0,
  28437. 0x50, 0xa5, 0xde, 0xc5, 0xde, 0x5e, 0xa0, 0x3b,
  28438. 0x05, 0x84, 0x1c, 0x2a, 0xc4, 0x96, 0x47, 0xd6,
  28439. 0x97, 0x56, 0x40, 0x33, 0x99, 0x7c, 0x8b, 0x56,
  28440. 0xb4, 0xfb, 0xf4, 0x23, 0xcb, 0x48, 0x81, 0x6c,
  28441. 0xa4, 0x53, 0x41, 0x8c, 0x28, 0x61, 0xd7, 0x8c,
  28442. 0xde, 0xde, 0xeb, 0xd4, 0xe7, 0x8a, 0x2a, 0x40,
  28443. 0x83, 0x1c, 0xa4, 0x19, 0x0f, 0x6c, 0x73, 0xa5,
  28444. 0x0e, 0xb6, 0x5c, 0x14, 0x36, 0xff, 0xc9, 0x99,
  28445. 0x56, 0x53, 0x8c, 0x4e, 0x4f, 0x4a, 0x82, 0xc8,
  28446. 0x76, 0x83, 0x81, 0xf1, 0x17, 0x82, 0x98, 0x3e,
  28447. 0x9c, 0x99, 0x3a, 0x7c, 0x08, 0x77, 0x3e, 0xe2,
  28448. 0x10, 0x98, 0xb0, 0xf6, 0x1d, 0xd3, 0x24, 0xe8,
  28449. 0x98, 0xcf, 0xd8, 0x9a, 0xb8, 0xd7, 0xbe, 0x56,
  28450. 0xa2, 0xb6, 0xf8, 0x2e, 0xfe, 0xeb, 0x96, 0xfa,
  28451. 0xd0, 0xba, 0x79, 0x9e, 0xde, 0x72, 0x0d, 0x53,
  28452. 0x5f, 0xdd, 0x0d, 0xb2, 0x0a, 0x8f, 0x14, 0x94,
  28453. 0x87, 0x25, 0x5e, 0xcd, 0xd4, 0x4b, 0xaa, 0xc9,
  28454. 0x7e, 0x41, 0x9f, 0x33, 0x77, 0xbe, 0x6d, 0x57,
  28455. 0x68, 0xef, 0xee, 0x1a, 0xc4, 0x5c, 0x7b, 0xca,
  28456. 0x7e, 0x33, 0x93, 0x3d, 0x88, 0x91, 0xd1, 0x34,
  28457. 0x6a, 0x39, 0x98, 0x92, 0x50, 0x1a, 0x02, 0xcf,
  28458. 0x89, 0x34, 0x33, 0x10, 0x65, 0x23, 0x4d, 0xb7,
  28459. 0x00, 0xcc, 0xc1, 0x60, 0xdd, 0x7d, 0x8e, 0xd1,
  28460. 0x16, 0xa7, 0x71, 0x7b, 0x20, 0xcb, 0xe4, 0xe8,
  28461. 0xcc, 0xfc, 0xb8, 0x5f, 0xe4, 0xe2, 0xd6, 0x8c,
  28462. 0x43, 0x9c, 0x06, 0xf4, 0x8d, 0xbc, 0x56, 0xd0,
  28463. 0x0c, 0xd6, 0x0b, 0x6c, 0x33, 0x0e, 0x08, 0x77,
  28464. 0x66, 0x52, 0x1f, 0x48, 0x0c, 0x50, 0x4a, 0xc2,
  28465. 0x99, 0x0a, 0x15, 0x86, 0xc3, 0x9b, 0x7a, 0x5f,
  28466. 0xfb, 0x58, 0xbd, 0x63, 0x0c, 0xbe, 0x83, 0x40,
  28467. 0x8f, 0xba, 0x39, 0xfb, 0x45, 0xb9, 0xf7, 0x96,
  28468. 0x62, 0xec, 0x7e, 0x77, 0xa4, 0xfb, 0xe1, 0x86,
  28469. 0x5c, 0x0a, 0xae, 0x32, 0xbd, 0x79, 0x76, 0x8b
  28470. };
  28471. static const byte ml_dsa_44_good_sig[] = {
  28472. 0x09, 0xf0, 0xae, 0xbb, 0x25, 0xc7, 0xfc, 0xdd,
  28473. 0x93, 0x25, 0x9c, 0x50, 0xd9, 0x2e, 0x72, 0x5d,
  28474. 0x53, 0xf5, 0x29, 0xd7, 0x4c, 0xc2, 0xd6, 0x81,
  28475. 0x5c, 0xf3, 0x3f, 0x9a, 0x8a, 0xa9, 0x00, 0x21,
  28476. 0x6c, 0xc6, 0xb9, 0x72, 0xb7, 0x0e, 0x00, 0x55,
  28477. 0x9f, 0xd7, 0xae, 0x92, 0xc3, 0xbc, 0x8f, 0x2d,
  28478. 0x4f, 0x54, 0x87, 0x56, 0x52, 0xd3, 0xdd, 0xaf,
  28479. 0xe0, 0xff, 0xda, 0x80, 0x1b, 0xf3, 0x56, 0x90,
  28480. 0xdd, 0x07, 0x86, 0xad, 0xf7, 0xf3, 0x8e, 0xcf,
  28481. 0x3a, 0x57, 0x30, 0x52, 0xaa, 0xd2, 0xb1, 0xf0,
  28482. 0x66, 0xea, 0x67, 0xab, 0x94, 0x1d, 0x96, 0x04,
  28483. 0xaa, 0xcf, 0x0e, 0xb0, 0xbc, 0x7d, 0x8a, 0x4c,
  28484. 0x62, 0x21, 0x82, 0x81, 0x98, 0x63, 0x22, 0x91,
  28485. 0xb9, 0xfe, 0x53, 0x63, 0x8d, 0xdf, 0xe6, 0x19,
  28486. 0xc1, 0x54, 0x3b, 0xf0, 0xf5, 0xe4, 0xc4, 0x36,
  28487. 0x66, 0x2f, 0xcc, 0x4f, 0xed, 0xc6, 0x62, 0x7d,
  28488. 0x8b, 0x7b, 0x89, 0xac, 0x23, 0x0b, 0x40, 0x4e,
  28489. 0x2d, 0xdc, 0xe5, 0xa2, 0xbc, 0x8b, 0xac, 0xe7,
  28490. 0x0b, 0xaa, 0x15, 0xa0, 0x79, 0x4a, 0x97, 0x8a,
  28491. 0xc8, 0xb1, 0x31, 0xea, 0x29, 0x99, 0x14, 0x5d,
  28492. 0x5b, 0x8c, 0xc2, 0xd0, 0xc2, 0x29, 0xd0, 0x85,
  28493. 0xb9, 0x25, 0x16, 0x08, 0xe8, 0x41, 0xa7, 0x77,
  28494. 0x1a, 0xbf, 0x5a, 0x48, 0x5a, 0x7f, 0x97, 0x44,
  28495. 0x62, 0xb4, 0x68, 0x2e, 0x05, 0x48, 0xde, 0x0f,
  28496. 0x69, 0xcc, 0x05, 0x3c, 0xa4, 0x85, 0x20, 0x60,
  28497. 0xfd, 0x45, 0x6a, 0x14, 0xb9, 0x76, 0x8d, 0x48,
  28498. 0xe7, 0x71, 0xd0, 0xd7, 0xbe, 0xe3, 0x36, 0xd6,
  28499. 0x94, 0x5c, 0x22, 0x6e, 0x28, 0xc6, 0x34, 0x93,
  28500. 0xf4, 0x6c, 0xf2, 0x62, 0xbf, 0x8f, 0x6d, 0x07,
  28501. 0xff, 0x38, 0x92, 0x23, 0x19, 0x55, 0xd0, 0x66,
  28502. 0x72, 0x76, 0xc1, 0x43, 0xbc, 0x60, 0x5d, 0xaa,
  28503. 0x61, 0x10, 0xdb, 0x0c, 0x49, 0x7b, 0x99, 0xce,
  28504. 0x14, 0xe3, 0x0b, 0x80, 0xdc, 0x8a, 0x3d, 0xa5,
  28505. 0x3a, 0x0e, 0x29, 0x88, 0x09, 0x1f, 0x9c, 0x03,
  28506. 0x32, 0x13, 0xc2, 0xe1, 0x49, 0x26, 0xc7, 0x11,
  28507. 0xfa, 0x7f, 0x2d, 0x64, 0xfc, 0xf9, 0xaf, 0xd0,
  28508. 0x4d, 0xcf, 0x3a, 0x23, 0x49, 0xde, 0xf2, 0x5d,
  28509. 0xad, 0xf3, 0xde, 0xe0, 0x9a, 0xa2, 0x96, 0x0a,
  28510. 0x9d, 0x97, 0x39, 0x88, 0x60, 0x75, 0xec, 0x29,
  28511. 0x9b, 0x93, 0xfc, 0x80, 0xb3, 0xeb, 0xb0, 0xc6,
  28512. 0xa8, 0xea, 0x75, 0x67, 0xed, 0xbd, 0x42, 0x2a,
  28513. 0xed, 0x22, 0x27, 0xdb, 0x41, 0x3a, 0x94, 0x86,
  28514. 0xd7, 0x4a, 0xf1, 0x8f, 0xa5, 0x47, 0x38, 0xa3,
  28515. 0x3c, 0xe7, 0x17, 0x5d, 0xce, 0xdc, 0x32, 0x7c,
  28516. 0xe4, 0x05, 0x58, 0x98, 0x67, 0xc8, 0xaf, 0x35,
  28517. 0x5d, 0xf9, 0xc0, 0x10, 0x6d, 0x9d, 0xd3, 0x27,
  28518. 0x79, 0x3c, 0x1d, 0xdd, 0xfb, 0x53, 0x3c, 0x03,
  28519. 0x4c, 0xb3, 0x1b, 0x0b, 0x3a, 0x60, 0x80, 0xcd,
  28520. 0x9b, 0x1e, 0x5f, 0x3f, 0x29, 0xfa, 0xb1, 0x09,
  28521. 0x9a, 0x88, 0x58, 0x4a, 0xf5, 0xed, 0xe9, 0x7c,
  28522. 0x9d, 0x70, 0xbe, 0x57, 0xfb, 0x92, 0x12, 0xc9,
  28523. 0x8c, 0x6b, 0x77, 0xe2, 0x44, 0xc6, 0x82, 0x2a,
  28524. 0x29, 0xb3, 0x9c, 0xb0, 0x60, 0xda, 0x3d, 0xcd,
  28525. 0x4e, 0x49, 0x96, 0x8c, 0xd7, 0x2b, 0x29, 0x28,
  28526. 0x7b, 0xec, 0xf1, 0x46, 0x40, 0xf0, 0xe1, 0xd7,
  28527. 0x48, 0x9e, 0xdf, 0xfd, 0xa6, 0xd0, 0xaa, 0x35,
  28528. 0x94, 0x7a, 0x94, 0x57, 0xf3, 0xd4, 0x15, 0x19,
  28529. 0xd3, 0xc5, 0x35, 0x73, 0xc4, 0xf5, 0x86, 0x0d,
  28530. 0x2a, 0x5b, 0x67, 0x0d, 0x8d, 0xaa, 0x18, 0x3e,
  28531. 0xea, 0x9d, 0x80, 0xe7, 0xf8, 0xbb, 0x23, 0xea,
  28532. 0x5d, 0x1c, 0x4d, 0xb2, 0x58, 0x7e, 0xe5, 0xef,
  28533. 0x80, 0xc1, 0x63, 0x44, 0xaf, 0x1d, 0xed, 0xf6,
  28534. 0x92, 0x05, 0x0c, 0xda, 0xcc, 0x58, 0x39, 0x27,
  28535. 0xdd, 0x24, 0xac, 0x63, 0x23, 0x34, 0xaa, 0x2d,
  28536. 0xd0, 0x5b, 0xd7, 0x7f, 0x6d, 0xcb, 0x64, 0xed,
  28537. 0xb3, 0x9b, 0x05, 0x90, 0x79, 0xc2, 0x25, 0x68,
  28538. 0xed, 0xf6, 0xa8, 0x7e, 0x30, 0x4a, 0x46, 0x44,
  28539. 0xad, 0xc8, 0x12, 0x8d, 0x04, 0xc3, 0x11, 0x83,
  28540. 0x7e, 0x77, 0xef, 0x9c, 0xa2, 0xf9, 0x3b, 0x06,
  28541. 0x84, 0x7f, 0x72, 0xd9, 0x2f, 0x22, 0x95, 0xb7,
  28542. 0x7b, 0x4e, 0x35, 0x6a, 0xfa, 0x73, 0x7d, 0x88,
  28543. 0x5b, 0xac, 0x7b, 0xc5, 0x53, 0xc1, 0xfe, 0x6b,
  28544. 0x7c, 0x05, 0xc3, 0xe4, 0xae, 0x48, 0x1a, 0xea,
  28545. 0x6e, 0x51, 0x46, 0x1e, 0x82, 0x80, 0xde, 0x31,
  28546. 0xe1, 0x41, 0x71, 0x88, 0x41, 0xa7, 0xb2, 0xcd,
  28547. 0x3d, 0xf7, 0x5c, 0x4f, 0x4c, 0xfd, 0x3f, 0x6f,
  28548. 0x6c, 0x82, 0xc1, 0xba, 0xe0, 0xf0, 0xb4, 0x8c,
  28549. 0xd5, 0xb5, 0x32, 0xbf, 0x91, 0x49, 0x7e, 0x39,
  28550. 0x5e, 0x0a, 0xdf, 0x4b, 0xd6, 0x07, 0x72, 0xff,
  28551. 0x58, 0x65, 0x1b, 0x1f, 0xc6, 0x56, 0xd2, 0x00,
  28552. 0xec, 0x60, 0xd1, 0x22, 0xc9, 0x1a, 0xa4, 0xcc,
  28553. 0x26, 0xb4, 0xd1, 0x93, 0xbc, 0xfc, 0x52, 0xdf,
  28554. 0xa1, 0x23, 0x37, 0x9b, 0xa2, 0xa8, 0x8f, 0xf3,
  28555. 0x39, 0x03, 0xa5, 0x4c, 0xf0, 0x68, 0xe5, 0x95,
  28556. 0x62, 0xfb, 0xd8, 0x88, 0x39, 0xf6, 0x02, 0x0a,
  28557. 0x4e, 0x7c, 0xf0, 0xbf, 0x71, 0x99, 0x0f, 0x19,
  28558. 0x61, 0xd9, 0x39, 0xe8, 0x3f, 0x59, 0x22, 0x4a,
  28559. 0xaa, 0xdd, 0x03, 0xf8, 0x09, 0xb8, 0xaf, 0xd9,
  28560. 0xb9, 0x9c, 0x3f, 0xf1, 0xfe, 0x49, 0xae, 0x99,
  28561. 0x2f, 0xa2, 0x22, 0x5a, 0x3c, 0xe9, 0xe9, 0xf7,
  28562. 0xba, 0x2d, 0xeb, 0x1f, 0x6c, 0xa7, 0xe1, 0x87,
  28563. 0x2f, 0xa5, 0xff, 0xcf, 0x1c, 0x22, 0x8d, 0xf2,
  28564. 0x5f, 0x63, 0xf5, 0xbb, 0x36, 0x66, 0xcc, 0x62,
  28565. 0x89, 0x8e, 0xf7, 0x78, 0xc5, 0x97, 0x95, 0xde,
  28566. 0xec, 0x43, 0x39, 0x6e, 0x0d, 0xe0, 0x8e, 0xbd,
  28567. 0x2b, 0x3b, 0xe6, 0xff, 0xf5, 0x8f, 0x90, 0xd2,
  28568. 0xd2, 0xce, 0x3b, 0x6f, 0x78, 0xf5, 0xd3, 0x42,
  28569. 0xf3, 0x0f, 0x27, 0x4b, 0x2b, 0xe4, 0xd8, 0x0d,
  28570. 0x31, 0xfa, 0xba, 0xdc, 0x54, 0x21, 0x9a, 0xbf,
  28571. 0x1e, 0x1d, 0x06, 0x8e, 0xd9, 0x58, 0xce, 0x9a,
  28572. 0x71, 0x79, 0x4d, 0xcb, 0xfb, 0x99, 0x4b, 0x66,
  28573. 0xed, 0xef, 0x75, 0x20, 0x4d, 0x47, 0x9b, 0x40,
  28574. 0xd5, 0xcf, 0xd9, 0x00, 0xfe, 0x32, 0x45, 0xae,
  28575. 0x4b, 0x7e, 0x8e, 0x7b, 0xf9, 0xd4, 0xd4, 0x2e,
  28576. 0x1a, 0x2a, 0xac, 0x73, 0xdb, 0x79, 0xb7, 0x02,
  28577. 0x6a, 0x3d, 0xa2, 0xfe, 0x52, 0x27, 0x25, 0x43,
  28578. 0xd1, 0xb5, 0x48, 0x0e, 0xef, 0xf1, 0x0f, 0xe7,
  28579. 0x27, 0xc2, 0x59, 0x4e, 0x47, 0xe2, 0x12, 0xaa,
  28580. 0x1e, 0xae, 0xbc, 0x86, 0x22, 0x70, 0x33, 0xa5,
  28581. 0x50, 0x3f, 0xed, 0x3c, 0x98, 0xbb, 0xd5, 0xb3,
  28582. 0x3e, 0x43, 0x21, 0x8e, 0x3e, 0x8c, 0xcc, 0x0c,
  28583. 0xcf, 0x50, 0xcd, 0xeb, 0x1b, 0x9d, 0x0c, 0xc9,
  28584. 0xe3, 0x2f, 0xbb, 0x4b, 0x43, 0xfc, 0x37, 0x27,
  28585. 0xcb, 0xc9, 0x5a, 0xe9, 0x45, 0x92, 0x9d, 0xe9,
  28586. 0x60, 0x8f, 0x93, 0x1b, 0xd8, 0x6a, 0x68, 0x86,
  28587. 0xc2, 0x1d, 0x49, 0x92, 0x11, 0x29, 0x62, 0x14,
  28588. 0x15, 0x4c, 0xe9, 0x33, 0xe3, 0x70, 0x2d, 0x6b,
  28589. 0x8b, 0xb5, 0x22, 0x44, 0x82, 0xbe, 0x43, 0xe2,
  28590. 0x80, 0xfb, 0xb5, 0xfa, 0x6a, 0x30, 0x04, 0x20,
  28591. 0xb6, 0x58, 0xe1, 0xf4, 0x8c, 0xe6, 0x4c, 0x7c,
  28592. 0x8d, 0x38, 0xf6, 0xdd, 0x59, 0xfc, 0x5a, 0xd7,
  28593. 0x9f, 0x34, 0x92, 0xcc, 0xde, 0x65, 0x89, 0xa7,
  28594. 0xd9, 0x57, 0xf7, 0xf2, 0x71, 0x39, 0xaf, 0xb6,
  28595. 0x88, 0x02, 0x40, 0x24, 0x8b, 0x4f, 0xc5, 0xfc,
  28596. 0xdc, 0x5c, 0xc0, 0x1d, 0xa6, 0x68, 0x87, 0xe0,
  28597. 0x8f, 0xdc, 0xf0, 0xac, 0xd8, 0x5f, 0x1c, 0xb3,
  28598. 0x07, 0xac, 0x58, 0x97, 0x3f, 0x3e, 0x72, 0x19,
  28599. 0x18, 0x64, 0x55, 0x73, 0x11, 0x71, 0xd1, 0xa4,
  28600. 0xa6, 0x57, 0xb0, 0x27, 0xaf, 0xad, 0x8a, 0xf7,
  28601. 0xdf, 0xde, 0x1e, 0xdb, 0x31, 0xc9, 0x32, 0x85,
  28602. 0x90, 0x40, 0x3d, 0xfe, 0x64, 0x5d, 0xe3, 0x94,
  28603. 0x74, 0x98, 0xa7, 0xed, 0x84, 0x44, 0x13, 0x76,
  28604. 0xba, 0xe9, 0x09, 0x9a, 0x17, 0xe0, 0x38, 0x03,
  28605. 0x3b, 0x7a, 0xa7, 0x0e, 0x74, 0xbd, 0x93, 0xb1,
  28606. 0x85, 0x64, 0xc9, 0xc4, 0x22, 0xb9, 0xdf, 0x80,
  28607. 0xac, 0xa1, 0x17, 0xdb, 0x11, 0xdb, 0xfa, 0xeb,
  28608. 0x90, 0x3c, 0x28, 0xfb, 0xa2, 0x36, 0x76, 0x61,
  28609. 0x20, 0x00, 0x88, 0x15, 0xc0, 0x79, 0x9f, 0x7d,
  28610. 0x9f, 0x90, 0xdb, 0x79, 0xbf, 0x1c, 0xdf, 0x86,
  28611. 0xc9, 0x60, 0x8c, 0xea, 0xa6, 0x24, 0x81, 0xd6,
  28612. 0x6d, 0xd8, 0x8d, 0x17, 0x5f, 0x5c, 0x6d, 0x93,
  28613. 0xbc, 0xed, 0xe5, 0x41, 0x05, 0xbe, 0xc6, 0x0f,
  28614. 0x66, 0x50, 0xc3, 0xce, 0x7e, 0x6c, 0x80, 0x88,
  28615. 0xf5, 0x52, 0x61, 0xaf, 0xdb, 0xc0, 0x80, 0xbe,
  28616. 0x78, 0x49, 0x64, 0x39, 0x54, 0x26, 0xeb, 0xab,
  28617. 0x07, 0x4d, 0x38, 0x66, 0x06, 0x98, 0x58, 0xaa,
  28618. 0x40, 0xc4, 0x89, 0xb2, 0x08, 0x85, 0xf3, 0x14,
  28619. 0x58, 0x5d, 0x36, 0xf7, 0xf0, 0x6b, 0x72, 0x79,
  28620. 0x6d, 0xbe, 0x5e, 0x24, 0x68, 0xf1, 0x3c, 0xa2,
  28621. 0x82, 0x22, 0x6e, 0xc4, 0x46, 0x94, 0x8e, 0x00,
  28622. 0xcb, 0xc0, 0x07, 0x69, 0xa5, 0x6d, 0x57, 0x04,
  28623. 0x79, 0xeb, 0x06, 0x7a, 0x42, 0x20, 0x6e, 0xdc,
  28624. 0xb5, 0xa4, 0xdd, 0x74, 0xb3, 0x92, 0x16, 0x71,
  28625. 0x7d, 0x99, 0xfa, 0x26, 0x35, 0x57, 0xe2, 0x83,
  28626. 0xc2, 0xb6, 0xfb, 0x0a, 0xae, 0x22, 0xed, 0xe3,
  28627. 0x98, 0x65, 0x18, 0x32, 0xf8, 0xe5, 0xed, 0xa9,
  28628. 0xf9, 0x7d, 0xb8, 0xea, 0x21, 0x51, 0x6c, 0x70,
  28629. 0x4c, 0xfa, 0xec, 0x6d, 0x4c, 0xf4, 0xcb, 0x1c,
  28630. 0x43, 0xfb, 0xfc, 0xbb, 0xa9, 0xcb, 0xc5, 0x21,
  28631. 0xb3, 0x89, 0xd6, 0x4c, 0xc4, 0x42, 0xd1, 0x55,
  28632. 0x3d, 0x43, 0x74, 0xbf, 0xb7, 0x47, 0xb3, 0x5b,
  28633. 0x14, 0xc3, 0x8f, 0x42, 0x30, 0x57, 0xb0, 0x22,
  28634. 0x56, 0xbe, 0x8d, 0x88, 0x7e, 0x7d, 0x63, 0xc8,
  28635. 0xec, 0x01, 0x41, 0xd5, 0x9d, 0xb6, 0x7a, 0x3b,
  28636. 0xfe, 0x8b, 0x95, 0x94, 0xdb, 0xca, 0xf1, 0xb4,
  28637. 0x56, 0xd7, 0x83, 0xf4, 0x11, 0x05, 0x65, 0xde,
  28638. 0x7a, 0xa3, 0x5a, 0x7a, 0x70, 0xe4, 0xd2, 0xad,
  28639. 0xc0, 0xff, 0x3f, 0x66, 0x2e, 0x1a, 0x65, 0x38,
  28640. 0xda, 0x1f, 0x3f, 0xac, 0x04, 0x2f, 0x0f, 0xde,
  28641. 0x7e, 0x55, 0x05, 0x12, 0xe9, 0xe7, 0x69, 0xf9,
  28642. 0x34, 0x2c, 0x84, 0x97, 0xa8, 0x86, 0x0c, 0x24,
  28643. 0x32, 0x87, 0xfd, 0xbe, 0x67, 0xd1, 0x02, 0x21,
  28644. 0x3b, 0x33, 0xfd, 0x11, 0xb1, 0xca, 0x4f, 0xeb,
  28645. 0x40, 0x38, 0xf6, 0x19, 0x83, 0x9d, 0x73, 0x44,
  28646. 0x37, 0xd6, 0x69, 0x6d, 0x85, 0xda, 0xf7, 0x69,
  28647. 0xfb, 0x88, 0x2b, 0xe7, 0xe7, 0x3c, 0x18, 0xa8,
  28648. 0x13, 0xb7, 0xee, 0x5c, 0x50, 0x5b, 0xa3, 0x09,
  28649. 0x1c, 0xef, 0x8d, 0x37, 0x89, 0x75, 0x0f, 0x8b,
  28650. 0xea, 0x17, 0x02, 0x47, 0x21, 0xcb, 0xa8, 0x73,
  28651. 0x71, 0x23, 0x4c, 0xf7, 0x50, 0xdd, 0x21, 0xe5,
  28652. 0xdb, 0x40, 0x3a, 0x87, 0x40, 0x8d, 0x60, 0x89,
  28653. 0x9e, 0x20, 0x00, 0x58, 0xeb, 0xbb, 0x24, 0x9b,
  28654. 0x0a, 0x17, 0x8f, 0xf6, 0x56, 0x07, 0x11, 0x5b,
  28655. 0xa7, 0xcd, 0x93, 0x0a, 0x31, 0x3d, 0x1f, 0x45,
  28656. 0xa0, 0x08, 0x8f, 0x88, 0x34, 0xa5, 0x01, 0x3b,
  28657. 0xea, 0x07, 0xa3, 0x7b, 0x66, 0x3e, 0x96, 0xe8,
  28658. 0xf7, 0x4d, 0x63, 0x04, 0x55, 0x89, 0xf1, 0x02,
  28659. 0x1e, 0x4a, 0x21, 0xb1, 0x2b, 0x8c, 0x7f, 0x2e,
  28660. 0x0c, 0x64, 0x26, 0x36, 0xd8, 0x63, 0xab, 0xf5,
  28661. 0x22, 0xaf, 0xa9, 0xfa, 0xfa, 0x21, 0x4b, 0x7e,
  28662. 0x6f, 0x8c, 0xce, 0x98, 0xf2, 0x85, 0x3f, 0x2c,
  28663. 0x07, 0x90, 0xc3, 0x2c, 0x06, 0xc5, 0xde, 0xc8,
  28664. 0xc2, 0x7c, 0xd7, 0x9b, 0x64, 0x25, 0x8a, 0x9b,
  28665. 0x77, 0x07, 0xc7, 0x4c, 0xd7, 0x67, 0xff, 0xe6,
  28666. 0xdb, 0x17, 0xf5, 0xc4, 0x2a, 0x14, 0x44, 0x1a,
  28667. 0xff, 0xda, 0xe0, 0xa7, 0x09, 0x1c, 0xe9, 0x03,
  28668. 0xde, 0x4a, 0x59, 0xe4, 0xdf, 0xa3, 0x0d, 0x3a,
  28669. 0x43, 0xdf, 0x80, 0x82, 0x87, 0xfa, 0x75, 0xf5,
  28670. 0xe8, 0xef, 0x6f, 0xd0, 0x89, 0xdd, 0xa1, 0x75,
  28671. 0x17, 0x5b, 0x71, 0x47, 0xe8, 0x8d, 0xae, 0xf6,
  28672. 0x18, 0x7f, 0xb9, 0x24, 0x68, 0x3f, 0x17, 0x6b,
  28673. 0xa8, 0x30, 0x67, 0x7e, 0x02, 0x9b, 0xf6, 0x4d,
  28674. 0x03, 0xa8, 0xfb, 0x33, 0x2f, 0xb4, 0x65, 0x72,
  28675. 0x2a, 0x30, 0xa6, 0x93, 0x94, 0x7a, 0x41, 0x0f,
  28676. 0xd3, 0x67, 0x0b, 0xba, 0xa4, 0x49, 0x7c, 0xcf,
  28677. 0x1f, 0x59, 0x1e, 0x2e, 0x45, 0xd4, 0xa8, 0xb1,
  28678. 0x98, 0x2b, 0xd7, 0x6f, 0x55, 0xb8, 0xf2, 0x65,
  28679. 0x7b, 0x96, 0x18, 0xf7, 0x2e, 0xde, 0x9c, 0x39,
  28680. 0x7a, 0x08, 0x2e, 0xe7, 0x3c, 0x9e, 0x4a, 0xfe,
  28681. 0xba, 0x49, 0xce, 0xba, 0x65, 0x18, 0xae, 0xae,
  28682. 0x9b, 0xd5, 0xf5, 0xeb, 0xd3, 0xdc, 0xd7, 0x2c,
  28683. 0x92, 0x3c, 0xe2, 0x93, 0xb9, 0x69, 0xf2, 0x20,
  28684. 0xea, 0xbd, 0xa9, 0x01, 0x2b, 0x72, 0x7c, 0x93,
  28685. 0x6c, 0x1f, 0x80, 0x3a, 0xd2, 0x2d, 0xf6, 0xc1,
  28686. 0x31, 0x63, 0xd2, 0x2f, 0x6c, 0x1a, 0x54, 0x1f,
  28687. 0x74, 0xe6, 0xa0, 0xac, 0xb1, 0x04, 0x03, 0xb3,
  28688. 0x22, 0x19, 0x48, 0x0a, 0xa7, 0x55, 0x25, 0xc1,
  28689. 0x77, 0x28, 0xb9, 0xbe, 0xef, 0xa8, 0xc6, 0x2b,
  28690. 0xd5, 0x6c, 0x5d, 0x7b, 0x85, 0xcd, 0x10, 0x2d,
  28691. 0x9e, 0xfd, 0xb8, 0xa5, 0x10, 0x65, 0xf7, 0x29,
  28692. 0xa7, 0x41, 0x18, 0xc8, 0xc2, 0x23, 0xe5, 0xcb,
  28693. 0x96, 0x91, 0x8a, 0x7e, 0x45, 0x30, 0x6b, 0x91,
  28694. 0xf1, 0x88, 0xb3, 0x2e, 0x92, 0x96, 0x0a, 0x42,
  28695. 0x4a, 0x16, 0x9d, 0x0c, 0xa8, 0xa7, 0xe5, 0x64,
  28696. 0x38, 0x8a, 0x53, 0x41, 0x28, 0xbf, 0xd7, 0xa4,
  28697. 0x14, 0x05, 0x59, 0x11, 0x2e, 0x0f, 0xc8, 0x5c,
  28698. 0x97, 0x8d, 0xd3, 0x92, 0xbf, 0xb9, 0x05, 0xfa,
  28699. 0xff, 0x38, 0xbf, 0xd6, 0xc5, 0x22, 0xf8, 0xa4,
  28700. 0x75, 0x30, 0x45, 0x93, 0x14, 0xda, 0xc0, 0x7f,
  28701. 0xea, 0x24, 0xe0, 0x33, 0x68, 0xf2, 0x6d, 0xe1,
  28702. 0xb1, 0x0c, 0x7d, 0x40, 0xaa, 0x16, 0x53, 0xa1,
  28703. 0xf6, 0x26, 0xb1, 0x25, 0xe8, 0x83, 0xe9, 0xea,
  28704. 0xea, 0xd2, 0x5a, 0x24, 0xda, 0xe2, 0x6e, 0xd1,
  28705. 0x2a, 0x87, 0x64, 0x48, 0x13, 0x55, 0xb1, 0x2c,
  28706. 0x1a, 0x58, 0x43, 0x5b, 0x63, 0x14, 0x3e, 0x02,
  28707. 0xf0, 0xcf, 0x61, 0x7d, 0x83, 0x81, 0xb9, 0x65,
  28708. 0x4b, 0x72, 0xee, 0xff, 0xfb, 0x6a, 0xbe, 0x71,
  28709. 0x26, 0x56, 0x28, 0x13, 0x9f, 0x31, 0xda, 0x8c,
  28710. 0x2f, 0xdb, 0x21, 0xbe, 0x4b, 0x66, 0xbb, 0xad,
  28711. 0x7a, 0x13, 0x55, 0x92, 0x7c, 0xb5, 0x6e, 0x5f,
  28712. 0x45, 0x1b, 0x64, 0x2d, 0xad, 0x6d, 0x32, 0x07,
  28713. 0xe4, 0x91, 0xdc, 0x0c, 0x1b, 0x5f, 0xcd, 0x86,
  28714. 0xe2, 0x99, 0x2b, 0xb9, 0x7e, 0x60, 0xbd, 0xad,
  28715. 0xa1, 0x5c, 0xab, 0x7f, 0x76, 0xf3, 0x77, 0xba,
  28716. 0x73, 0x7f, 0x6a, 0x88, 0x4e, 0xff, 0x40, 0x72,
  28717. 0x7a, 0x4d, 0x9b, 0x20, 0x2d, 0xc9, 0x2a, 0x30,
  28718. 0x0f, 0x8f, 0x0f, 0xc9, 0x79, 0xc8, 0xc3, 0x8a,
  28719. 0x83, 0x52, 0xff, 0x66, 0x7a, 0x42, 0x04, 0x08,
  28720. 0x6e, 0x5b, 0x13, 0xda, 0xb9, 0xb6, 0x2d, 0x45,
  28721. 0x77, 0x9a, 0xa0, 0x2b, 0xc1, 0x87, 0xc2, 0xa6,
  28722. 0x35, 0x7f, 0x39, 0x34, 0x2e, 0x95, 0x1e, 0x8c,
  28723. 0xbf, 0x89, 0x6d, 0xcf, 0x82, 0xb8, 0x9f, 0x9b,
  28724. 0xd1, 0xbc, 0xa2, 0x55, 0x83, 0xf4, 0xca, 0x21,
  28725. 0x11, 0x8f, 0x28, 0xa9, 0x5e, 0x28, 0x23, 0xb4,
  28726. 0x43, 0x60, 0xb6, 0x11, 0x1a, 0x6f, 0xb4, 0xd1,
  28727. 0x96, 0xc8, 0x79, 0xf2, 0x39, 0x8b, 0x82, 0xae,
  28728. 0xe0, 0xc2, 0xe4, 0xf9, 0xfb, 0xf8, 0x85, 0x64,
  28729. 0x28, 0xad, 0xb5, 0xfd, 0x37, 0xc5, 0x21, 0x38,
  28730. 0x31, 0x94, 0x0d, 0xbe, 0xd8, 0xaf, 0x9b, 0x8a,
  28731. 0x7d, 0xfb, 0x56, 0xd8, 0x23, 0xf7, 0x55, 0x55,
  28732. 0xe7, 0xd9, 0x63, 0x65, 0xfd, 0x64, 0x2e, 0x8a,
  28733. 0x1d, 0x1b, 0xac, 0x4e, 0x2f, 0xef, 0x1b, 0x77,
  28734. 0xca, 0x01, 0xd6, 0xfc, 0xb0, 0x11, 0xda, 0x6b,
  28735. 0xef, 0x9f, 0x76, 0x81, 0x3e, 0x3f, 0x26, 0x4b,
  28736. 0x3b, 0x97, 0xa0, 0x7d, 0xd6, 0xcf, 0x51, 0x0d,
  28737. 0x06, 0xf7, 0xf5, 0x88, 0x64, 0x34, 0x7a, 0xe3,
  28738. 0xb9, 0x16, 0xc3, 0x06, 0x04, 0xf3, 0xe9, 0x55,
  28739. 0xd2, 0xff, 0x49, 0xec, 0x57, 0x84, 0x1f, 0x39,
  28740. 0x28, 0x71, 0x57, 0x87, 0x40, 0xf2, 0x7a, 0x30,
  28741. 0xa0, 0x88, 0xba, 0x6c, 0xb1, 0x09, 0x30, 0x3a,
  28742. 0x11, 0x75, 0xcf, 0xbe, 0x4c, 0xf7, 0xf7, 0xca,
  28743. 0x44, 0x52, 0x91, 0xd0, 0x4c, 0x12, 0x3e, 0x3a,
  28744. 0x4b, 0x31, 0x20, 0xfe, 0x27, 0xd2, 0x08, 0x5b,
  28745. 0x83, 0x7b, 0x82, 0xd3, 0xa3, 0x72, 0xba, 0x2f,
  28746. 0x5f, 0xa3, 0x71, 0xcd, 0x8d, 0x3f, 0x94, 0xce,
  28747. 0x86, 0xa8, 0x6b, 0x43, 0xb7, 0x06, 0x80, 0x70,
  28748. 0x64, 0x06, 0xab, 0x54, 0xce, 0xb5, 0x29, 0xaf,
  28749. 0x73, 0xf7, 0x0f, 0x65, 0x70, 0xa7, 0x84, 0x1a,
  28750. 0x0b, 0xdb, 0x0c, 0xa9, 0x20, 0xea, 0x06, 0x7a,
  28751. 0xba, 0x80, 0xc6, 0xae, 0x3e, 0x0a, 0x7b, 0xd6,
  28752. 0x21, 0x99, 0xe0, 0xae, 0x6e, 0x8f, 0x80, 0xa9,
  28753. 0x97, 0x27, 0x3d, 0x7e, 0xb2, 0xd8, 0x06, 0x10,
  28754. 0x36, 0x07, 0x64, 0x12, 0xd0, 0xc7, 0x91, 0xd2,
  28755. 0x81, 0x74, 0x22, 0x8b, 0x8f, 0xe0, 0x48, 0xc4,
  28756. 0xe1, 0x9b, 0x05, 0xc8, 0xc5, 0xc3, 0x9a, 0x7b,
  28757. 0x9d, 0xee, 0x23, 0xe0, 0x98, 0xc0, 0xd0, 0x05,
  28758. 0x21, 0x89, 0x9a, 0xf4, 0x45, 0xd1, 0x1d, 0x80,
  28759. 0x79, 0xb7, 0xfe, 0x3c, 0xff, 0x84, 0x86, 0xf0,
  28760. 0x2a, 0x69, 0x8b, 0x2d, 0x3b, 0x82, 0xa0, 0xab,
  28761. 0xee, 0xe6, 0xf4, 0x64, 0x84, 0x2b, 0x7a, 0x42,
  28762. 0x12, 0x8d, 0x10, 0xa6, 0xae, 0x10, 0x6d, 0x03,
  28763. 0xb5, 0x72, 0x09, 0xf8, 0x3f, 0xe4, 0x1c, 0x0a,
  28764. 0x08, 0x0d, 0x1a, 0x45, 0x5b, 0x70, 0x7b, 0x95,
  28765. 0xa1, 0xa7, 0xb4, 0xb6, 0xbf, 0xcc, 0xfc, 0x09,
  28766. 0x1a, 0x30, 0x40, 0x44, 0x5e, 0x69, 0x73, 0x7a,
  28767. 0x81, 0xa5, 0xb9, 0xd7, 0xdd, 0xe3, 0xee, 0xfb,
  28768. 0x16, 0x1a, 0x1d, 0x40, 0x41, 0x4e, 0x8d, 0x90,
  28769. 0x92, 0x9d, 0xaf, 0xb0, 0xbb, 0xc2, 0xe0, 0xfc,
  28770. 0x06, 0x0b, 0x20, 0x37, 0x47, 0x50, 0x53, 0x65,
  28771. 0x87, 0x89, 0x99, 0xa4, 0xb7, 0xdb, 0x00, 0x00,
  28772. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  28773. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  28774. 0x0f, 0x20, 0x30, 0x3e
  28775. };
  28776. #endif
  28777. static int test_wc_dilithium(void)
  28778. {
  28779. EXPECT_DECLS;
  28780. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM)
  28781. dilithium_key* key;
  28782. byte level;
  28783. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28784. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28785. WC_RNG rng;
  28786. #endif
  28787. byte* privKey = NULL;
  28788. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  28789. word32 privKeyLen = DILITHIUM_MAX_KEY_SIZE;
  28790. #endif
  28791. byte* pubKey = NULL;
  28792. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  28793. word32 pubKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  28794. #endif
  28795. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28796. ExpectNotNull(key);
  28797. privKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  28798. DYNAMIC_TYPE_TMP_BUFFER);
  28799. ExpectNotNull(privKey);
  28800. pubKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  28801. DYNAMIC_TYPE_TMP_BUFFER);
  28802. ExpectNotNull(pubKey);
  28803. if (key != NULL) {
  28804. XMEMSET(key, 0, sizeof(*key));
  28805. }
  28806. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28807. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28808. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28809. #endif
  28810. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28811. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28812. ExpectIntEQ(wc_InitRng(&rng), 0);
  28813. #endif
  28814. ExpectIntEQ(wc_dilithium_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28815. ExpectIntEQ(wc_dilithium_init_ex(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28816. wc_dilithium_free(NULL);
  28817. ExpectIntEQ(wc_dilithium_init(key), 0);
  28818. wc_dilithium_free(key);
  28819. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  28820. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  28821. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen),
  28822. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28823. #endif
  28824. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  28825. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  28826. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28827. #endif
  28828. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28829. ExpectIntEQ(wc_dilithium_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28830. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28831. ExpectIntEQ(wc_dilithium_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28832. #endif
  28833. #endif
  28834. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28835. ExpectIntEQ(wc_dilithium_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28836. #endif
  28837. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28838. ExpectIntEQ(wc_dilithium_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28839. #endif
  28840. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28841. ExpectIntEQ(wc_dilithium_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28842. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28843. ExpectIntEQ(wc_dilithium_priv_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28844. #endif
  28845. #endif
  28846. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28847. ExpectIntEQ(wc_dilithium_pub_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28848. #endif
  28849. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28850. ExpectIntEQ(wc_dilithium_sig_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28851. #endif
  28852. ExpectIntEQ(wc_dilithium_set_level(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28853. ExpectIntEQ(wc_dilithium_set_level(key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28854. ExpectIntEQ(wc_dilithium_set_level(NULL, WC_ML_DSA_44), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28855. ExpectIntEQ(wc_dilithium_set_level(key, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28856. ExpectIntEQ(wc_dilithium_set_level(key, 4), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28857. ExpectIntEQ(wc_dilithium_get_level(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28858. ExpectIntEQ(wc_dilithium_get_level(key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28859. ExpectIntEQ(wc_dilithium_get_level(NULL, &level), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28860. ExpectIntEQ(wc_dilithium_get_level(key, &level), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28861. #ifndef WOLFSSL_NO_ML_DSA_87
  28862. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  28863. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  28864. ExpectIntEQ(level, WC_ML_DSA_87);
  28865. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28866. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL5_KEY_SIZE);
  28867. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28868. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL5_PRV_KEY_SIZE);
  28869. #endif
  28870. #endif
  28871. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28872. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  28873. #endif
  28874. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28875. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL5_SIG_SIZE);
  28876. #endif
  28877. #else
  28878. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  28879. #endif
  28880. #ifndef WOLFSSL_NO_ML_DSA_65
  28881. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  28882. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  28883. ExpectIntEQ(level, WC_ML_DSA_65);
  28884. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28885. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL3_KEY_SIZE);
  28886. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28887. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL3_PRV_KEY_SIZE);
  28888. #endif
  28889. #endif
  28890. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28891. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  28892. #endif
  28893. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28894. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL3_SIG_SIZE);
  28895. #endif
  28896. #else
  28897. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  28898. #endif
  28899. #ifndef WOLFSSL_NO_ML_DSA_44
  28900. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  28901. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  28902. ExpectIntEQ(level, WC_ML_DSA_44);
  28903. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28904. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL2_KEY_SIZE);
  28905. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28906. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL2_PRV_KEY_SIZE);
  28907. #endif
  28908. #endif
  28909. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28910. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  28911. #endif
  28912. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28913. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL2_SIG_SIZE);
  28914. #endif
  28915. #else
  28916. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  28917. #endif
  28918. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  28919. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen),
  28920. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28921. #endif
  28922. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  28923. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  28924. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28925. #endif
  28926. wc_dilithium_free(key);
  28927. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28928. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28929. wc_FreeRng(&rng);
  28930. #endif
  28931. XFREE(pubKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28932. XFREE(privKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28933. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28934. #endif
  28935. return EXPECT_RESULT();
  28936. }
  28937. static int test_wc_dilithium_make_key(void)
  28938. {
  28939. EXPECT_DECLS;
  28940. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28941. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  28942. dilithium_key* key;
  28943. WC_RNG rng;
  28944. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28945. ExpectNotNull(key);
  28946. if (key != NULL) {
  28947. XMEMSET(key, 0, sizeof(*key));
  28948. }
  28949. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28950. ExpectIntEQ(wc_InitRng(&rng), 0);
  28951. ExpectIntEQ(wc_dilithium_init(key), 0);
  28952. ExpectIntEQ(wc_dilithium_make_key(key, &rng), WC_NO_ERR_TRACE(BAD_STATE_E));
  28953. #ifndef WOLFSSL_NO_ML_DSA_44
  28954. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  28955. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28956. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  28957. #else
  28958. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  28959. #endif
  28960. ExpectIntEQ(wc_dilithium_make_key(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28961. ExpectIntEQ(wc_dilithium_make_key(key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28962. ExpectIntEQ(wc_dilithium_make_key(NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28963. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  28964. wc_dilithium_free(key);
  28965. wc_FreeRng(&rng);
  28966. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28967. #endif
  28968. return EXPECT_RESULT();
  28969. }
  28970. static int test_wc_dilithium_sign(void)
  28971. {
  28972. EXPECT_DECLS;
  28973. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28974. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28975. dilithium_key* key;
  28976. dilithium_key* importKey = NULL;
  28977. WC_RNG rng;
  28978. byte* privKey = NULL;
  28979. word32 privKeyLen = DILITHIUM_MAX_KEY_SIZE;
  28980. word32 badKeyLen;
  28981. byte msg[32];
  28982. byte* sig = NULL;
  28983. word32 sigLen = DILITHIUM_MAX_SIG_SIZE;
  28984. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28985. ExpectNotNull(key);
  28986. importKey = (dilithium_key*)XMALLOC(sizeof(*key), NULL,
  28987. DYNAMIC_TYPE_TMP_BUFFER);
  28988. ExpectNotNull(importKey);
  28989. privKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  28990. DYNAMIC_TYPE_TMP_BUFFER);
  28991. ExpectNotNull(privKey);
  28992. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL,
  28993. DYNAMIC_TYPE_TMP_BUFFER);
  28994. ExpectNotNull(sig);
  28995. if (key != NULL) {
  28996. XMEMSET(key, 0, sizeof(*key));
  28997. }
  28998. if (importKey != NULL) {
  28999. XMEMSET(importKey, 0, sizeof(*importKey));
  29000. }
  29001. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29002. XMEMSET(msg, 0x55, sizeof(msg));
  29003. ExpectIntEQ(wc_InitRng(&rng), 0);
  29004. ExpectIntEQ(wc_dilithium_init(key), 0);
  29005. #ifndef WOLFSSL_NO_ML_DSA_44
  29006. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  29007. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29008. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  29009. #else
  29010. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  29011. #endif
  29012. #ifdef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  29013. #ifndef WOLFSSL_NO_ML_DSA_44
  29014. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level2_key,
  29015. sizeof_bench_dilithium_level2_key, key), 0);
  29016. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29017. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level3_key,
  29018. sizeof_bench_dilithium_level3_key, key), 0);
  29019. #else
  29020. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level5_key,
  29021. sizeof_bench_dilithium_level5_key, key), 0);
  29022. #endif
  29023. #else
  29024. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29025. #endif
  29026. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, NULL, NULL),
  29027. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29028. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, NULL, NULL, NULL, NULL),
  29029. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29030. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, sig, NULL, NULL, NULL),
  29031. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29032. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, &sigLen, NULL, NULL),
  29033. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29034. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, key, NULL),
  29035. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29036. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, NULL, &rng),
  29037. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29038. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, sig, &sigLen, key, &rng),
  29039. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29040. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, NULL, &sigLen, key, &rng),
  29041. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29042. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, NULL, key, &rng),
  29043. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29044. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, NULL, &rng),
  29045. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29046. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, NULL),
  29047. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29048. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  29049. ExpectIntEQ(wc_dilithium_export_private(NULL, NULL, NULL),
  29050. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29051. ExpectIntEQ(wc_dilithium_export_private(key, NULL, NULL),
  29052. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29053. ExpectIntEQ(wc_dilithium_export_private(NULL, privKey, NULL),
  29054. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29055. ExpectIntEQ(wc_dilithium_export_private(NULL, NULL, &privKeyLen),
  29056. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29057. ExpectIntEQ(wc_dilithium_export_private(NULL, privKey, &privKeyLen),
  29058. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29059. ExpectIntEQ(wc_dilithium_export_private(key, NULL, &privKeyLen),
  29060. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29061. ExpectIntEQ(wc_dilithium_export_private(key, privKey, NULL),
  29062. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29063. badKeyLen = 0;
  29064. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &badKeyLen),
  29065. WC_NO_ERR_TRACE(BUFFER_E));
  29066. #ifndef WOLFSSL_NO_ML_DSA_44
  29067. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL2_KEY_SIZE);
  29068. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29069. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL3_KEY_SIZE);
  29070. #else
  29071. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL5_KEY_SIZE);
  29072. #endif
  29073. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  29074. 0);
  29075. #ifndef WOLFSSL_NO_ML_DSA_44
  29076. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL2_KEY_SIZE);
  29077. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29078. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL3_KEY_SIZE);
  29079. #else
  29080. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL5_KEY_SIZE);
  29081. #endif
  29082. ExpectIntEQ(wc_dilithium_init(importKey), 0);
  29083. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, importKey),
  29084. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29085. #ifndef WOLFSSL_NO_ML_DSA_44
  29086. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_44), 0);
  29087. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29088. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_65), 0);
  29089. #else
  29090. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_87), 0);
  29091. #endif
  29092. ExpectIntEQ(wc_dilithium_import_private(NULL, 0, NULL),
  29093. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29094. ExpectIntEQ(wc_dilithium_import_private(privKey, 0, NULL),
  29095. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29096. ExpectIntEQ(wc_dilithium_import_private(NULL, privKeyLen, NULL),
  29097. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29098. ExpectIntEQ(wc_dilithium_import_private(NULL, 0, importKey),
  29099. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29100. ExpectIntEQ(wc_dilithium_import_private(NULL, privKeyLen, importKey),
  29101. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29102. ExpectIntEQ(wc_dilithium_import_private(privKey, 0, importKey),
  29103. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29104. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, NULL),
  29105. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29106. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, importKey),
  29107. 0);
  29108. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  29109. #ifdef WOLFSSL_DILITHIUM_CHECK_KEY
  29110. ExpectIntEQ(wc_dilithium_check_key(importKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  29111. #endif
  29112. wc_dilithium_free(importKey);
  29113. wc_dilithium_free(key);
  29114. wc_FreeRng(&rng);
  29115. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29116. XFREE(privKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29117. XFREE(importKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29118. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29119. #endif
  29120. return EXPECT_RESULT();
  29121. }
  29122. static int test_wc_dilithium_verify(void)
  29123. {
  29124. EXPECT_DECLS;
  29125. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29126. !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
  29127. (!defined(WOLFSSL_NO_ML_DSA_44) || !defined(WOLFSSL_DILITHIUM_NO_SIGN))
  29128. dilithium_key* key;
  29129. dilithium_key* importKey = NULL;
  29130. WC_RNG rng;
  29131. byte* pubKey = NULL;
  29132. word32 pubKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  29133. word32 badKeyLen;
  29134. byte msg[32];
  29135. byte* sig = NULL;
  29136. word32 sigLen = DILITHIUM_MAX_SIG_SIZE;
  29137. int res;
  29138. #ifndef WOLFSSL_NO_ML_DSA_44
  29139. byte b;
  29140. #endif
  29141. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29142. ExpectNotNull(key);
  29143. importKey = (dilithium_key*)XMALLOC(sizeof(*key), NULL,
  29144. DYNAMIC_TYPE_TMP_BUFFER);
  29145. ExpectNotNull(importKey);
  29146. pubKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  29147. DYNAMIC_TYPE_TMP_BUFFER);
  29148. ExpectNotNull(pubKey);
  29149. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29150. ExpectNotNull(sig);
  29151. if (key != NULL) {
  29152. XMEMSET(key, 0, sizeof(*key));
  29153. }
  29154. if (importKey != NULL) {
  29155. XMEMSET(importKey, 0, sizeof(*importKey));
  29156. }
  29157. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29158. XMEMSET(msg, 0x55, sizeof(msg));
  29159. ExpectIntEQ(wc_InitRng(&rng), 0);
  29160. ExpectIntEQ(wc_dilithium_init(key), 0);
  29161. #ifndef WOLFSSL_NO_ML_DSA_44
  29162. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  29163. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29164. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  29165. #else
  29166. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  29167. #endif
  29168. #if !defined(WOLFSSL_NO_ML_DSA_44)
  29169. ExpectIntEQ(wc_dilithium_import_public(ml_dsa_44_pub_key,
  29170. (word32)sizeof(ml_dsa_44_pub_key), key), 0);
  29171. if (sig != NULL) {
  29172. XMEMCPY(sig, ml_dsa_44_good_sig, sizeof(ml_dsa_44_good_sig));
  29173. }
  29174. sigLen = (word32)sizeof(ml_dsa_44_good_sig);
  29175. #else
  29176. #ifdef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  29177. #ifndef WOLFSSL_NO_ML_DSA_65
  29178. ExpectIntEQ(wc_dilithium_import_public(bench_dilithium_level3_pub_key,
  29179. sizeof_bench_dilithium_level3_pub_key, key), 0);
  29180. #else
  29181. ExpectIntEQ(wc_dilithium_import_public(bench_dilithium_level5_pub_key,
  29182. sizeof_bench_dilithium_level5_pub_key, key), 0);
  29183. #endif /* !WOLFSSL_NO_ML_DSA_65 */
  29184. #else
  29185. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29186. #endif /* WOLFSSL_DILITHIUM_NO_MAKE_KEY */
  29187. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  29188. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  29189. ExpectIntEQ(wc_dilithium_export_public(NULL, NULL, NULL),
  29190. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29191. ExpectIntEQ(wc_dilithium_export_public(key, NULL, NULL),
  29192. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29193. ExpectIntEQ(wc_dilithium_export_public(NULL, pubKey, NULL),
  29194. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29195. ExpectIntEQ(wc_dilithium_export_public(NULL, NULL, &pubKeyLen),
  29196. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29197. ExpectIntEQ(wc_dilithium_export_public(NULL, pubKey, &pubKeyLen),
  29198. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29199. ExpectIntEQ(wc_dilithium_export_public(key, NULL, &pubKeyLen),
  29200. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29201. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, NULL),
  29202. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29203. badKeyLen = 0;
  29204. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &badKeyLen),
  29205. WC_NO_ERR_TRACE(BUFFER_E));
  29206. #ifndef WOLFSSL_NO_ML_DSA_44
  29207. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  29208. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29209. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  29210. #else
  29211. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  29212. #endif
  29213. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen), 0);
  29214. #ifndef WOLFSSL_NO_ML_DSA_44
  29215. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  29216. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29217. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  29218. #else
  29219. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  29220. #endif
  29221. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, NULL, NULL),
  29222. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29223. ExpectIntEQ(wc_dilithium_verify_msg(sig, 0, NULL, 32, NULL, NULL),
  29224. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29225. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, msg, 32, NULL, NULL),
  29226. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29227. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, &res, NULL),
  29228. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29229. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, NULL, key),
  29230. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29231. ExpectIntEQ(wc_dilithium_verify_msg(NULL, sigLen, msg, 32, &res, key),
  29232. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29233. ExpectIntEQ(wc_dilithium_verify_msg(sig, 0, msg, 32, &res, key),
  29234. WC_NO_ERR_TRACE(BUFFER_E));
  29235. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, NULL, 32, &res, key),
  29236. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29237. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, NULL, key),
  29238. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29239. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, NULL),
  29240. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29241. res = 0;
  29242. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key), 0);
  29243. ExpectIntEQ(res, 1);
  29244. ExpectIntEQ(wc_dilithium_init(importKey), 0);
  29245. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, importKey),
  29246. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29247. #ifndef WOLFSSL_NO_ML_DSA_44
  29248. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_44), 0);
  29249. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29250. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_65), 0);
  29251. #else
  29252. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_87), 0);
  29253. #endif
  29254. ExpectIntEQ(wc_dilithium_import_public(NULL, 0, NULL),
  29255. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29256. ExpectIntEQ(wc_dilithium_import_public(pubKey, 0, NULL),
  29257. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29258. ExpectIntEQ(wc_dilithium_import_public(NULL, pubKeyLen, NULL),
  29259. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29260. ExpectIntEQ(wc_dilithium_import_public(NULL, 0, importKey),
  29261. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29262. ExpectIntEQ(wc_dilithium_import_public(NULL, pubKeyLen, importKey),
  29263. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29264. ExpectIntEQ(wc_dilithium_import_public(pubKey, 0, importKey),
  29265. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29266. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, NULL),
  29267. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29268. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, importKey), 0);
  29269. res = 0;
  29270. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, importKey),
  29271. 0);
  29272. ExpectIntEQ(res, 1);
  29273. #ifdef WOLFSSL_DILITHIUM_CHECK_KEY
  29274. ExpectIntEQ(wc_dilithium_check_key(importKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29275. #endif
  29276. wc_dilithium_free(importKey);
  29277. #ifndef WOLFSSL_NO_ML_DSA_44
  29278. if (sig != NULL) {
  29279. if (sig[sigLen - 5] == 0) {
  29280. /* Unused hints meant to be 0. */
  29281. sig[sigLen - 5] = 0xff;
  29282. res = 1;
  29283. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res,
  29284. key), WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29285. ExpectIntEQ(res, 0);
  29286. sig[sigLen - 5] = 0x00;
  29287. }
  29288. /* Last count of hints must be less than PARAMS_ML_DSA_44_OMEGA == 80 */
  29289. b = sig[sigLen - 1];
  29290. sig[sigLen - 1] = 0xff;
  29291. res = 1;
  29292. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29293. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29294. ExpectIntEQ(res, 0);
  29295. sig[sigLen - 1] = b;
  29296. if (sig[sigLen - 4] > 1) {
  29297. /* Index must be less than previous. */
  29298. b = sig[sigLen - 84];
  29299. sig[sigLen - 84] = 0xff;
  29300. res = 1;
  29301. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res,
  29302. key), WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29303. ExpectIntEQ(res, 0);
  29304. sig[sigLen - 84] = b;
  29305. }
  29306. /* Mess up commit hash. */
  29307. sig[0] ^= 0x80;
  29308. res = 1;
  29309. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29310. 0);
  29311. ExpectIntEQ(res, 0);
  29312. sig[0] ^= 0x80;
  29313. /* Mess up z. */
  29314. sig[100] ^= 0x80;
  29315. res = 1;
  29316. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29317. 0);
  29318. ExpectIntEQ(res, 0);
  29319. sig[100] ^= 0x80;
  29320. /* Set all indeces to 0. */
  29321. XMEMSET(sig + sigLen - 4, 0, 4);
  29322. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29323. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29324. ExpectIntEQ(res, 0);
  29325. }
  29326. #endif
  29327. wc_dilithium_free(key);
  29328. wc_FreeRng(&rng);
  29329. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29330. XFREE(pubKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29331. XFREE(importKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29332. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29333. #endif
  29334. return EXPECT_RESULT();
  29335. }
  29336. static int test_wc_dilithium_sign_vfy(void)
  29337. {
  29338. EXPECT_DECLS;
  29339. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29340. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) && \
  29341. !defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  29342. dilithium_key* key;
  29343. WC_RNG rng;
  29344. byte msg[64];
  29345. byte* sig = NULL;
  29346. word32 sigLen;
  29347. byte ctx[10];
  29348. int res;
  29349. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29350. ExpectNotNull(key);
  29351. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29352. ExpectNotNull(sig);
  29353. if (key != NULL) {
  29354. XMEMSET(key, 0, sizeof(*key));
  29355. }
  29356. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29357. XMEMSET(msg, 0xAA, sizeof(msg));
  29358. XMEMSET(ctx, 0x01, sizeof(ctx));
  29359. ExpectIntEQ(wc_InitRng(&rng), 0);
  29360. #ifndef WOLFSSL_NO_ML_DSA_44
  29361. ExpectIntEQ(wc_dilithium_init(key), 0);
  29362. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  29363. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29364. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29365. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  29366. sig, &sigLen, key, &rng), 0);
  29367. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  29368. sizeof(msg), &res, key), 0);
  29369. ExpectIntEQ(res, 1);
  29370. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29371. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  29372. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  29373. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  29374. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  29375. ExpectIntEQ(res, 1);
  29376. wc_dilithium_free(key);
  29377. #endif
  29378. #ifndef WOLFSSL_NO_ML_DSA_65
  29379. ExpectIntEQ(wc_dilithium_init(key), 0);
  29380. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  29381. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29382. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29383. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  29384. sig, &sigLen, key, &rng), 0);
  29385. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  29386. sizeof(msg), &res, key), 0);
  29387. ExpectIntEQ(res, 1);
  29388. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29389. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  29390. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  29391. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  29392. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  29393. ExpectIntEQ(res, 1);
  29394. wc_dilithium_free(key);
  29395. #endif
  29396. #ifndef WOLFSSL_NO_ML_DSA_87
  29397. ExpectIntEQ(wc_dilithium_init(key), 0);
  29398. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  29399. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29400. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29401. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  29402. sig, &sigLen, key, &rng), 0);
  29403. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  29404. sizeof(msg), &res, key), 0);
  29405. ExpectIntEQ(res, 1);
  29406. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29407. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  29408. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  29409. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  29410. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  29411. ExpectIntEQ(res, 1);
  29412. wc_dilithium_free(key);
  29413. #endif
  29414. wc_FreeRng(&rng);
  29415. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29416. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29417. #endif
  29418. return EXPECT_RESULT();
  29419. }
  29420. static int test_wc_dilithium_check_key(void)
  29421. {
  29422. EXPECT_DECLS;
  29423. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29424. defined(WOLFSSL_DILITHIUM_CHECK_KEY) && \
  29425. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  29426. dilithium_key* checkKey;
  29427. WC_RNG rng;
  29428. byte* privCheckKey = NULL;
  29429. word32 privCheckKeyLen = DILITHIUM_MAX_KEY_SIZE;
  29430. byte* pubCheckKey = NULL;
  29431. word32 pubCheckKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  29432. checkKey = (dilithium_key*)XMALLOC(sizeof(*checkKey), NULL,
  29433. DYNAMIC_TYPE_TMP_BUFFER);
  29434. ExpectNotNull(checkKey);
  29435. privCheckKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  29436. DYNAMIC_TYPE_TMP_BUFFER);
  29437. ExpectNotNull(privCheckKey);
  29438. pubCheckKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  29439. DYNAMIC_TYPE_TMP_BUFFER);
  29440. ExpectNotNull(pubCheckKey);
  29441. if (checkKey != NULL) {
  29442. XMEMSET(checkKey, 0, sizeof(*checkKey));
  29443. }
  29444. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29445. ExpectIntEQ(wc_InitRng(&rng), 0);
  29446. ExpectIntEQ(wc_dilithium_check_key(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29447. ExpectIntEQ(wc_dilithium_init(checkKey), 0);
  29448. ExpectIntEQ(wc_dilithium_export_key(NULL, privCheckKey,
  29449. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29450. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29451. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29452. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29453. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29454. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29455. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29456. #ifndef WOLFSSL_NO_ML_DSA_44
  29457. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_44), 0);
  29458. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29459. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_65), 0);
  29460. #else
  29461. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_87), 0);
  29462. #endif
  29463. ExpectIntEQ(wc_dilithium_make_key(checkKey, &rng), 0);
  29464. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, NULL, NULL),
  29465. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29466. ExpectIntEQ(wc_dilithium_export_key(checkKey, NULL, NULL, NULL, NULL),
  29467. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29468. ExpectIntEQ(wc_dilithium_export_key(NULL, privCheckKey, NULL, NULL, NULL),
  29469. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29470. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, &privCheckKeyLen, NULL,
  29471. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29472. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, pubCheckKey, NULL),
  29473. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29474. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, NULL,
  29475. &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29476. ExpectIntEQ(wc_dilithium_export_key(NULL , privCheckKey,
  29477. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29478. ExpectIntEQ(wc_dilithium_export_key(checkKey, NULL ,
  29479. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29480. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29481. NULL , pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29482. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29483. &privCheckKeyLen, NULL , &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29484. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29485. &privCheckKeyLen, pubCheckKey, NULL ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29486. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29487. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), 0);
  29488. /* Modify hash. */
  29489. if (pubCheckKey != NULL) {
  29490. pubCheckKey[0] ^= 0x80;
  29491. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, NULL, 0, NULL),
  29492. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29493. ExpectIntEQ(wc_dilithium_import_key(privCheckKey, 0, NULL, 0, NULL),
  29494. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29495. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, pubCheckKey, 0, NULL),
  29496. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29497. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, NULL, 0, checkKey),
  29498. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29499. ExpectIntEQ(wc_dilithium_import_key(NULL ,
  29500. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey),
  29501. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29502. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29503. 0 , pubCheckKey, pubCheckKeyLen, checkKey),
  29504. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29505. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29506. privCheckKeyLen, NULL , pubCheckKeyLen, checkKey),
  29507. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29508. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29509. privCheckKeyLen, pubCheckKey, 0 , checkKey),
  29510. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29511. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29512. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, NULL ),
  29513. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29514. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29515. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey), 0);
  29516. ExpectIntEQ(wc_dilithium_check_key(checkKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  29517. pubCheckKey[0] ^= 0x80;
  29518. /* Modify encoded t1. */
  29519. pubCheckKey[48] ^= 0x80;
  29520. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29521. privCheckKeyLen,pubCheckKey, pubCheckKeyLen, checkKey), 0);
  29522. ExpectIntEQ(wc_dilithium_check_key(checkKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  29523. pubCheckKey[48] ^= 0x80;
  29524. }
  29525. wc_dilithium_free(checkKey);
  29526. wc_FreeRng(&rng);
  29527. XFREE(pubCheckKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29528. XFREE(privCheckKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29529. XFREE(checkKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29530. #endif
  29531. return EXPECT_RESULT();
  29532. }
  29533. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29534. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  29535. static const unsigned char ml_dsa_public_der[] = {
  29536. #ifndef WOLFSSL_NO_ML_DSA_44
  29537. 0x30, 0x82, 0x05, 0x32, 0x30, 0x0d, 0x06, 0x09,
  29538. 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03,
  29539. 0x11, 0x03, 0x82, 0x05, 0x21, 0x00,
  29540. 0xBC, 0x5F, 0xF8, 0x10, 0xEB, 0x08, 0x90, 0x48,
  29541. 0xB8, 0xAB, 0x30, 0x20, 0xA7, 0xBD, 0x3B, 0x16,
  29542. 0xC0, 0xE0, 0xCA, 0x3D, 0x6B, 0x97, 0xE4, 0x64,
  29543. 0x6C, 0x2C, 0xCA, 0xE0, 0xBB, 0xF1, 0x9E, 0xF7,
  29544. 0x23, 0x0A, 0x19, 0xD7, 0x5A, 0xDB, 0xDE, 0xD5,
  29545. 0x2D, 0xB8, 0x55, 0xE2, 0x52, 0xA7, 0x19, 0xFC,
  29546. 0xBD, 0x14, 0x7B, 0xA6, 0x7B, 0x2F, 0xAD, 0x14,
  29547. 0xED, 0x0E, 0x68, 0xFD, 0xFE, 0x8C, 0x65, 0xBA,
  29548. 0xDE, 0xAC, 0xB0, 0x91, 0x11, 0x93, 0xAD, 0xFA,
  29549. 0x87, 0x94, 0xD7, 0x8F, 0x8E, 0x3D, 0x66, 0x2A,
  29550. 0x1C, 0x49, 0xDA, 0x81, 0x9F, 0xD9, 0x59, 0xE7,
  29551. 0xF0, 0x78, 0xF2, 0x03, 0xC4, 0x56, 0xF8, 0xB6,
  29552. 0xE7, 0xC9, 0x41, 0x58, 0x98, 0xE5, 0x41, 0xC7,
  29553. 0x30, 0x32, 0xDB, 0xD6, 0x19, 0xEA, 0xF6, 0x0F,
  29554. 0x8D, 0x64, 0xF8, 0x68, 0x3D, 0xA9, 0x9E, 0xCA,
  29555. 0x51, 0x22, 0x0B, 0x0A, 0xCA, 0x28, 0x46, 0x40,
  29556. 0x99, 0xF5, 0x47, 0xC0, 0x27, 0x77, 0xBD, 0x37,
  29557. 0xD8, 0x4A, 0x59, 0xBD, 0x37, 0xED, 0x7A, 0x8A,
  29558. 0x92, 0x63, 0x3C, 0x75, 0xD0, 0x7C, 0x79, 0x3F,
  29559. 0xE7, 0x25, 0x2B, 0x58, 0x4A, 0xBF, 0x6A, 0x15,
  29560. 0xEE, 0x14, 0x50, 0x7E, 0x5E, 0x19, 0x3F, 0x89,
  29561. 0x86, 0x4D, 0x09, 0xAC, 0x87, 0x27, 0xA6, 0xD0,
  29562. 0x42, 0x1F, 0x0C, 0x19, 0xF0, 0xE2, 0xFB, 0xFC,
  29563. 0x21, 0x3D, 0x3F, 0xBD, 0x70, 0xF4, 0xF9, 0x76,
  29564. 0x2C, 0xEC, 0xFF, 0x23, 0x1E, 0x9C, 0x8A, 0x76,
  29565. 0x28, 0xD3, 0xF8, 0xB0, 0x85, 0x7B, 0x03, 0x2D,
  29566. 0x32, 0xDE, 0x62, 0xFF, 0x8E, 0xCB, 0xF4, 0x00,
  29567. 0x82, 0x89, 0xBF, 0x34, 0x40, 0x36, 0x65, 0xF8,
  29568. 0x1A, 0x08, 0x1A, 0xD5, 0xA8, 0x5A, 0x28, 0x2F,
  29569. 0x99, 0xBA, 0xB9, 0xE5, 0x38, 0x5A, 0xFB, 0xCC,
  29570. 0xCF, 0x44, 0xB7, 0x4C, 0x01, 0x96, 0xC7, 0x54,
  29571. 0x55, 0x27, 0xEC, 0x30, 0x26, 0xDA, 0x12, 0x80,
  29572. 0xC4, 0xEB, 0x37, 0xD0, 0x9C, 0xFE, 0x3E, 0xC4,
  29573. 0xB4, 0x91, 0x0B, 0x62, 0xEB, 0x98, 0x15, 0xA4,
  29574. 0x25, 0xC6, 0x59, 0x0F, 0xC4, 0xAD, 0x3F, 0xBB,
  29575. 0x22, 0x57, 0x52, 0xCC, 0x1F, 0xC5, 0x69, 0x3F,
  29576. 0x18, 0x7E, 0x7D, 0xEC, 0x4E, 0xEF, 0xBE, 0xB6,
  29577. 0xB9, 0x1B, 0xD9, 0x1C, 0x5E, 0x2E, 0xA6, 0xA9,
  29578. 0x1D, 0x14, 0xD0, 0x97, 0xBE, 0x20, 0x3F, 0xBA,
  29579. 0x0B, 0xF9, 0x37, 0xC9, 0x75, 0x07, 0xDC, 0x00,
  29580. 0x7C, 0x4C, 0xAA, 0x9B, 0x07, 0x85, 0x89, 0x29,
  29581. 0x66, 0xFF, 0x15, 0x90, 0x09, 0x24, 0xE5, 0x79,
  29582. 0xD4, 0xFB, 0xA0, 0x2B, 0xDA, 0x87, 0x55, 0x5F,
  29583. 0x07, 0x3D, 0xAE, 0x00, 0x51, 0x3E, 0x70, 0x80,
  29584. 0x9A, 0xBB, 0xC7, 0x11, 0xFB, 0xA2, 0xE7, 0x64,
  29585. 0x95, 0x77, 0xC4, 0x2A, 0xFD, 0xC2, 0x4B, 0xF7,
  29586. 0x41, 0x3E, 0x51, 0x26, 0x8A, 0xD6, 0xDB, 0x61,
  29587. 0x13, 0xB7, 0xD9, 0x19, 0x1A, 0xF9, 0xD0, 0x61,
  29588. 0xDB, 0xDE, 0xD5, 0xD6, 0x30, 0x87, 0x76, 0x50,
  29589. 0xC1, 0x24, 0xF1, 0x1B, 0xC4, 0xBD, 0xC3, 0xFD,
  29590. 0xC6, 0xA9, 0x00, 0xF6, 0x31, 0x26, 0xF9, 0x21,
  29591. 0xE8, 0x38, 0xAD, 0x0C, 0x22, 0x75, 0xA3, 0x38,
  29592. 0x9A, 0x39, 0xBD, 0x99, 0xA1, 0x34, 0x50, 0x45,
  29593. 0x50, 0x10, 0x1C, 0xD3, 0xE9, 0x5E, 0x6D, 0x14,
  29594. 0x96, 0xBE, 0x7D, 0xE6, 0x62, 0x7D, 0xF4, 0xFD,
  29595. 0x6C, 0x28, 0xBB, 0xF4, 0x0B, 0x30, 0xEF, 0xA9,
  29596. 0xB5, 0xC3, 0xD5, 0xC8, 0x5A, 0xB1, 0x4A, 0x65,
  29597. 0xC0, 0x2D, 0x6D, 0x47, 0x81, 0xFF, 0x13, 0xD3,
  29598. 0x28, 0x60, 0x85, 0x54, 0xB6, 0xD1, 0x5E, 0xD9,
  29599. 0x12, 0x89, 0xA6, 0xD5, 0x5A, 0xAC, 0x0C, 0x38,
  29600. 0xE3, 0x77, 0x06, 0xF7, 0x35, 0x5E, 0x9A, 0x4F,
  29601. 0xDA, 0x61, 0x5B, 0x87, 0x59, 0x26, 0xBF, 0xE5,
  29602. 0xA5, 0x9D, 0x9E, 0xF2, 0x73, 0xBF, 0x94, 0xA0,
  29603. 0x7C, 0xFA, 0x57, 0x31, 0x78, 0xF0, 0xE0, 0x04,
  29604. 0xB6, 0xE1, 0xEF, 0x0A, 0x83, 0x49, 0xE9, 0xBC,
  29605. 0xC0, 0x19, 0x81, 0xF2, 0x46, 0x0F, 0x0A, 0x27,
  29606. 0x43, 0xC2, 0x8D, 0x1E, 0x13, 0x8F, 0xFB, 0x76,
  29607. 0x5E, 0x7E, 0x33, 0x97, 0xB7, 0x91, 0x33, 0x35,
  29608. 0xD4, 0x02, 0xFE, 0x91, 0x80, 0x6A, 0xA8, 0xFC,
  29609. 0x81, 0x92, 0x53, 0xAF, 0x32, 0x69, 0x2F, 0xA6,
  29610. 0x51, 0xE8, 0x67, 0xF5, 0x90, 0x7E, 0xF4, 0x6F,
  29611. 0x00, 0x62, 0x5A, 0x03, 0x0E, 0xC9, 0x04, 0xED,
  29612. 0xAB, 0x21, 0x42, 0x6D, 0x59, 0x11, 0x9D, 0x2C,
  29613. 0xAA, 0x43, 0xBD, 0x93, 0x5D, 0xEC, 0x0A, 0x55,
  29614. 0x0C, 0x61, 0xEE, 0x4B, 0x27, 0x9C, 0x1C, 0xA3,
  29615. 0xA7, 0x9C, 0x79, 0xA6, 0x6E, 0x3F, 0x2D, 0x2F,
  29616. 0xAD, 0xB0, 0x0F, 0x59, 0xA3, 0xA4, 0x38, 0xAA,
  29617. 0x44, 0x57, 0x01, 0x06, 0x07, 0x30, 0x17, 0xFA,
  29618. 0x1C, 0x87, 0x57, 0x50, 0x01, 0x09, 0x72, 0x0D,
  29619. 0x12, 0x5B, 0xBA, 0x23, 0x1A, 0x0C, 0x36, 0x35,
  29620. 0x0C, 0x78, 0x08, 0x6D, 0xFD, 0xC8, 0xD6, 0x13,
  29621. 0xAE, 0xCA, 0x88, 0xC4, 0xCC, 0xAE, 0xB4, 0xA4,
  29622. 0x4D, 0x13, 0xAD, 0xB3, 0xC7, 0x17, 0xD6, 0x5C,
  29623. 0x82, 0xA3, 0x51, 0xB9, 0xB6, 0xEA, 0xBF, 0x6A,
  29624. 0x10, 0xF4, 0xB4, 0xE9, 0x62, 0x3E, 0x3A, 0x95,
  29625. 0xB4, 0xD4, 0x0A, 0x12, 0xA8, 0x18, 0xAC, 0x6B,
  29626. 0x38, 0x22, 0xDB, 0x82, 0xFB, 0x05, 0xDC, 0x42,
  29627. 0x02, 0x64, 0x8B, 0x44, 0x54, 0x68, 0x9A, 0xEB,
  29628. 0x69, 0xEA, 0x32, 0x5F, 0x03, 0xE3, 0x5D, 0xEF,
  29629. 0xA5, 0x47, 0x08, 0x48, 0x14, 0x20, 0xC6, 0xD6,
  29630. 0x97, 0xBB, 0x91, 0x2F, 0xCA, 0x0D, 0x3F, 0x19,
  29631. 0x2E, 0xF2, 0x97, 0xDF, 0xE7, 0x7F, 0xF3, 0x6B,
  29632. 0x21, 0x03, 0xF1, 0xAD, 0x1A, 0xEE, 0xCE, 0xD1,
  29633. 0xC8, 0x14, 0xC2, 0xCD, 0x7E, 0xF1, 0x6B, 0xCE,
  29634. 0x47, 0x6A, 0xD0, 0x4F, 0x94, 0x1A, 0xFC, 0x79,
  29635. 0xE3, 0x29, 0x54, 0x74, 0xA4, 0x10, 0x62, 0x51,
  29636. 0x8C, 0x00, 0x37, 0x86, 0x09, 0x34, 0xF0, 0xE5,
  29637. 0xE6, 0x52, 0xF7, 0x27, 0x49, 0xA6, 0x98, 0x63,
  29638. 0x2A, 0x09, 0x91, 0xF6, 0x13, 0xF5, 0xCB, 0x96,
  29639. 0xCA, 0x11, 0x78, 0xF9, 0x74, 0xF2, 0xC4, 0xAA,
  29640. 0x0C, 0xE6, 0x3D, 0xC2, 0x4E, 0x36, 0x4C, 0x92,
  29641. 0xA6, 0x43, 0xB9, 0x0A, 0x5F, 0x85, 0xA6, 0x2F,
  29642. 0xD4, 0xD8, 0xD2, 0xB1, 0x93, 0xD2, 0x9B, 0x18,
  29643. 0xBE, 0xDE, 0x26, 0x53, 0xFC, 0x5D, 0x3F, 0x24,
  29644. 0xF5, 0xB2, 0xC0, 0x18, 0xDB, 0xBC, 0xB6, 0xEF,
  29645. 0x00, 0xF3, 0x05, 0xBF, 0x93, 0x66, 0x6B, 0xD4,
  29646. 0x7F, 0xEA, 0x91, 0x93, 0xBC, 0x23, 0x3D, 0xB3,
  29647. 0x91, 0x21, 0x44, 0x2E, 0x93, 0x8D, 0xA5, 0xDD,
  29648. 0x07, 0xEE, 0x6E, 0x87, 0x9C, 0x5B, 0x9D, 0xFF,
  29649. 0x41, 0xEC, 0xEE, 0x5E, 0x05, 0x89, 0xAE, 0x61,
  29650. 0x75, 0xFF, 0x5E, 0xC6, 0xF6, 0xD2, 0x62, 0x9F,
  29651. 0x56, 0xB1, 0x8B, 0x4D, 0xE6, 0x6F, 0xCB, 0x13,
  29652. 0xDF, 0x04, 0x00, 0xA7, 0x97, 0xC9, 0x22, 0x70,
  29653. 0xF6, 0x9B, 0xDE, 0xBD, 0xDC, 0xB8, 0x8C, 0x42,
  29654. 0x48, 0x91, 0x9B, 0x56, 0xCD, 0xA7, 0x0B, 0x8A,
  29655. 0xC4, 0xF9, 0x42, 0x9C, 0x29, 0x2D, 0xA9, 0x4D,
  29656. 0x64, 0x78, 0x28, 0x07, 0x64, 0xFE, 0x23, 0x86,
  29657. 0xFC, 0x38, 0xCB, 0x09, 0x31, 0x45, 0x88, 0x39,
  29658. 0xEF, 0x4E, 0x7D, 0xE8, 0xF0, 0x68, 0x9D, 0x99,
  29659. 0x80, 0x59, 0x88, 0xC7, 0xF9, 0x61, 0x11, 0x85,
  29660. 0x2C, 0x89, 0x29, 0xE5, 0xA5, 0x40, 0xD3, 0xB7,
  29661. 0x8D, 0x71, 0x2D, 0xEC, 0xC3, 0x96, 0xFE, 0xF3,
  29662. 0xEC, 0x34, 0x40, 0x21, 0x84, 0xE4, 0xFD, 0x29,
  29663. 0xF3, 0x63, 0xEA, 0x80, 0xF6, 0xFC, 0x50, 0xBA,
  29664. 0x9A, 0x11, 0x35, 0x1A, 0xCE, 0xEA, 0x8F, 0xE6,
  29665. 0x8D, 0x54, 0x1E, 0x1A, 0xA5, 0x84, 0x8D, 0x9F,
  29666. 0x6E, 0x61, 0xDF, 0xB6, 0x2B, 0x2F, 0x23, 0xBC,
  29667. 0x50, 0x81, 0xE8, 0x2F, 0x76, 0x22, 0x6E, 0x03,
  29668. 0x28, 0x49, 0x82, 0xEC, 0x48, 0x48, 0x12, 0x09,
  29669. 0xB1, 0xA7, 0xD4, 0xC8, 0x79, 0x7E, 0x44, 0xBF,
  29670. 0xA8, 0x70, 0xB2, 0x20, 0x04, 0xDB, 0x74, 0xBD,
  29671. 0x7D, 0x47, 0x8D, 0x5B, 0x36, 0x14, 0xD2, 0xB1,
  29672. 0xDA, 0x75, 0x02, 0xB3, 0x98, 0xEB, 0x9D, 0xA8,
  29673. 0x0D, 0x06, 0x46, 0x1E, 0x90, 0xE0, 0x30, 0x60,
  29674. 0x44, 0x6A, 0xB4, 0xA8, 0x23, 0x84, 0x32, 0xBF,
  29675. 0xAF, 0x75, 0x2F, 0x39, 0x17, 0x91, 0x21, 0x4F,
  29676. 0x1E, 0x6B, 0x63, 0x59, 0x0D, 0x53, 0x60, 0x60,
  29677. 0xD1, 0xC2, 0x45, 0x30, 0x7B, 0xC5, 0xC1, 0xBA,
  29678. 0xC4, 0xAA, 0xA0, 0x99, 0xD3, 0x6B, 0xB6, 0xDC,
  29679. 0xBC, 0x97, 0x3C, 0xF2, 0xE6, 0x9F, 0x27, 0x34,
  29680. 0xD0, 0xF2, 0x9A, 0xEE, 0xC4, 0x56, 0x7B, 0x99,
  29681. 0xA1, 0x6B, 0xC1, 0x7C, 0x6C, 0xDD, 0xAC, 0xEF,
  29682. 0xE4, 0x99, 0x27, 0xFB, 0x14, 0xE7, 0xD9, 0x8D,
  29683. 0xD4, 0x26, 0x35, 0x19, 0x46, 0x9C, 0xCA, 0x3D,
  29684. 0xB4, 0x67, 0x9A, 0x68, 0xCE, 0xED, 0xA9, 0x55,
  29685. 0x59, 0x22, 0x10, 0xFC, 0x49, 0xAA, 0x5F, 0xBE,
  29686. 0x93, 0x4C, 0xC7, 0x3D, 0x84, 0xE4, 0xBA, 0x54,
  29687. 0x78, 0x00, 0x2D, 0x68, 0x90, 0x98, 0x90, 0x68,
  29688. 0xEF, 0x8F, 0xC9, 0x8C, 0x25, 0x32, 0xB8, 0x3B,
  29689. 0xF3, 0xCB, 0x9E, 0xF0, 0x28, 0x93, 0xC2, 0x15,
  29690. 0x24, 0x26, 0xB9, 0xD1, 0xA9, 0x47, 0x34, 0xDF,
  29691. 0xB4, 0xF9, 0x11, 0x35, 0x14, 0x3C, 0x9E, 0xED,
  29692. 0x18, 0xFD, 0x51, 0xAE, 0x87, 0x5D, 0x07, 0xA2,
  29693. 0x37, 0x75, 0x60, 0x6A, 0x73, 0x4F, 0xBA, 0x98,
  29694. 0xC0, 0x63, 0xB4, 0xA1, 0x62, 0x2E, 0x7F, 0xF2,
  29695. 0x1A, 0xA7, 0xE6, 0x52, 0xA3, 0xD6, 0xC1, 0x9F,
  29696. 0xE0, 0xDC, 0x67, 0x61, 0xB7, 0xD3, 0x53, 0x02,
  29697. 0xBF, 0x21, 0x4D, 0x30, 0x79, 0xF7, 0x60, 0x51,
  29698. 0x08, 0x2A, 0x87, 0x59, 0x29, 0x92, 0x0D, 0xC3,
  29699. 0xB3, 0xCB, 0x43, 0x21, 0x1A, 0x23, 0xA4, 0x3A,
  29700. 0x50, 0x33, 0x2F, 0xAF, 0x1A, 0xC2, 0x19, 0x1E,
  29701. 0x71, 0x71, 0x25, 0xF6, 0x3E, 0x25, 0x86, 0xC4,
  29702. 0xD8, 0x6D, 0xCA, 0x6B, 0xCD, 0x3D, 0x03, 0x8F,
  29703. 0x9D, 0x3A, 0x7B, 0x66, 0xCB, 0xC7, 0xDF, 0x34
  29704. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29705. 0x30, 0x82, 0x07, 0xb2, 0x30, 0x0d, 0x06, 0x09,
  29706. 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03,
  29707. 0x12, 0x03, 0x82, 0x07, 0xa1, 0x00,
  29708. 0xD2, 0xFD, 0x03, 0xF3, 0xA1, 0xB7, 0xF6, 0x35,
  29709. 0xAF, 0x9F, 0x34, 0xD5, 0x80, 0xA9, 0x8F, 0x52,
  29710. 0x4C, 0x73, 0x5B, 0xD5, 0xBA, 0x23, 0x55, 0xDC,
  29711. 0x6E, 0x03, 0x5B, 0xD2, 0x17, 0x65, 0x58, 0x0C,
  29712. 0xBB, 0x11, 0x19, 0x23, 0xF1, 0x94, 0xA7, 0xCC,
  29713. 0x8A, 0x7B, 0xB2, 0xEB, 0xC5, 0xC0, 0xE7, 0x1A,
  29714. 0xA6, 0x37, 0xCC, 0x80, 0x0E, 0x61, 0x03, 0xB8,
  29715. 0x50, 0xA5, 0x39, 0xB2, 0xA3, 0x9E, 0x1B, 0x6D,
  29716. 0x71, 0x3E, 0x5D, 0xB8, 0x31, 0x4C, 0x9A, 0xE1,
  29717. 0xF8, 0xBF, 0x8A, 0x38, 0xF0, 0x6A, 0xFB, 0x9D,
  29718. 0x73, 0xB1, 0x61, 0xB0, 0xFF, 0xE3, 0xA4, 0x89,
  29719. 0x17, 0x06, 0xAE, 0x26, 0xD5, 0x4F, 0xFB, 0x49,
  29720. 0x6D, 0xF8, 0xDC, 0x0F, 0x19, 0x83, 0x50, 0x95,
  29721. 0x00, 0xC9, 0xAB, 0xBD, 0x28, 0xE5, 0x9B, 0x3F,
  29722. 0xCD, 0xAB, 0xBD, 0xAD, 0xAB, 0xD4, 0x5E, 0xC3,
  29723. 0x14, 0x99, 0x37, 0x8B, 0xDE, 0x84, 0x9E, 0x7C,
  29724. 0x1F, 0x19, 0xB7, 0x04, 0x4D, 0x67, 0xE0, 0x51,
  29725. 0x06, 0xD7, 0x13, 0x6D, 0x95, 0x38, 0x0D, 0x56,
  29726. 0x05, 0xD4, 0x46, 0x5D, 0x87, 0x75, 0x57, 0x06,
  29727. 0x5D, 0xF0, 0xA7, 0x5D, 0x3C, 0x28, 0x54, 0x2F,
  29728. 0x40, 0xFE, 0xED, 0x42, 0xEC, 0x7E, 0x28, 0x06,
  29729. 0x37, 0xB0, 0x83, 0xD9, 0x88, 0xBC, 0xA5, 0xF6,
  29730. 0x39, 0x4E, 0x02, 0x39, 0x6C, 0x46, 0x76, 0x18,
  29731. 0x4F, 0xB6, 0x33, 0x18, 0xDA, 0xFA, 0xF5, 0xBB,
  29732. 0xDD, 0xE0, 0x0E, 0x30, 0x8F, 0xE8, 0x40, 0x19,
  29733. 0xC2, 0x34, 0x0A, 0x3F, 0x3E, 0x1C, 0x08, 0x65,
  29734. 0x62, 0x49, 0x70, 0x71, 0x12, 0x83, 0x35, 0x6A,
  29735. 0xE1, 0x4B, 0xD6, 0xB9, 0x4D, 0x1C, 0x9A, 0xE1,
  29736. 0x88, 0xDE, 0x1A, 0x8A, 0x2C, 0xA8, 0x24, 0xA8,
  29737. 0xEA, 0xE2, 0xFE, 0x6A, 0xFB, 0x38, 0xD8, 0x3A,
  29738. 0x2D, 0x99, 0x99, 0x6A, 0xB2, 0x1F, 0xE3, 0xE8,
  29739. 0x4C, 0x0B, 0xE6, 0xB6, 0xDA, 0x08, 0x87, 0x9B,
  29740. 0x67, 0x73, 0x74, 0xFA, 0x7C, 0x69, 0x1B, 0x13,
  29741. 0xD4, 0x0F, 0xA9, 0xD4, 0xCC, 0x26, 0xB2, 0x28,
  29742. 0x8D, 0x5A, 0x8C, 0x9A, 0x43, 0x72, 0x43, 0x81,
  29743. 0x00, 0x4D, 0x61, 0xB0, 0xD5, 0x7F, 0xF4, 0x00,
  29744. 0x31, 0x4C, 0x8E, 0x30, 0xEE, 0x79, 0x6A, 0xF1,
  29745. 0x0F, 0x7E, 0xE2, 0x1B, 0xF1, 0x3D, 0x08, 0x18,
  29746. 0x04, 0x65, 0xAB, 0xC7, 0x2E, 0xDD, 0xB0, 0x80,
  29747. 0xC6, 0xA0, 0x71, 0x84, 0xE3, 0xEE, 0xDC, 0x47,
  29748. 0xC1, 0x9A, 0xA7, 0xF0, 0x9D, 0x1F, 0x33, 0x09,
  29749. 0xE1, 0x83, 0xA2, 0xBD, 0x9B, 0x05, 0x73, 0xDD,
  29750. 0xE4, 0x74, 0xA8, 0x1B, 0xA4, 0xF7, 0x8D, 0x0C,
  29751. 0x52, 0x3D, 0x0C, 0x04, 0xF9, 0x00, 0x60, 0xFD,
  29752. 0x57, 0x1A, 0x35, 0xC0, 0x37, 0xE0, 0x79, 0xC5,
  29753. 0xE2, 0x10, 0xD7, 0x39, 0x0D, 0xF5, 0x68, 0xF2,
  29754. 0xE2, 0xF0, 0x3C, 0xE4, 0x44, 0x20, 0xC8, 0x2F,
  29755. 0x3F, 0xE6, 0x9E, 0xB9, 0xB4, 0x8E, 0xE9, 0x09,
  29756. 0x62, 0xD6, 0xB0, 0xF2, 0x44, 0x40, 0x64, 0x8F,
  29757. 0x71, 0xED, 0xB2, 0x41, 0xEE, 0x65, 0x66, 0xFC,
  29758. 0x1A, 0x64, 0xCA, 0xBF, 0x66, 0xBE, 0x6F, 0xEC,
  29759. 0xBC, 0xB1, 0x38, 0x7C, 0x82, 0xA7, 0xBC, 0x20,
  29760. 0x2D, 0x9E, 0x36, 0x79, 0x98, 0xE2, 0xA2, 0x91,
  29761. 0xAF, 0x0C, 0xD1, 0x57, 0x06, 0x77, 0xFE, 0x8D,
  29762. 0x63, 0xA3, 0x28, 0x5A, 0x2E, 0xA6, 0xEB, 0x29,
  29763. 0xAF, 0x9D, 0xC1, 0xAE, 0xC1, 0xC3, 0x6C, 0x47,
  29764. 0x06, 0xB1, 0x2B, 0xAA, 0x20, 0x83, 0x96, 0x92,
  29765. 0xF2, 0x86, 0xA6, 0xE0, 0x32, 0x14, 0x68, 0xF7,
  29766. 0x47, 0x93, 0x45, 0xC4, 0xD5, 0x2F, 0xBD, 0xB2,
  29767. 0xF0, 0x67, 0x25, 0xB5, 0x54, 0xB8, 0x9E, 0x24,
  29768. 0x92, 0x61, 0x26, 0x81, 0xAC, 0xEB, 0xC6, 0xC7,
  29769. 0xBA, 0xDA, 0x92, 0x25, 0x81, 0x8D, 0xBC, 0x35,
  29770. 0xD6, 0x4C, 0x22, 0xC4, 0x8B, 0xFF, 0x80, 0xA7,
  29771. 0x30, 0xD0, 0x71, 0x6D, 0xFA, 0xC9, 0x9D, 0xFD,
  29772. 0x5B, 0x89, 0x92, 0x61, 0x1D, 0x0C, 0x93, 0xEE,
  29773. 0x90, 0xBD, 0xB2, 0x60, 0x02, 0x2A, 0xFE, 0x25,
  29774. 0xD9, 0x13, 0xE0, 0x6E, 0xFF, 0xB5, 0x9C, 0xB1,
  29775. 0xF8, 0xA6, 0x0C, 0xBF, 0xA5, 0xAB, 0x2F, 0x45,
  29776. 0x9A, 0x16, 0xF4, 0x67, 0xE9, 0x89, 0x52, 0x5E,
  29777. 0x0A, 0x37, 0xEB, 0xE5, 0x6E, 0x83, 0x3F, 0xDE,
  29778. 0x55, 0xDB, 0x9D, 0x15, 0x30, 0xAD, 0xCF, 0x45,
  29779. 0x84, 0x6D, 0xF2, 0x81, 0xE4, 0x7C, 0xAA, 0x1E,
  29780. 0x0A, 0x27, 0xEF, 0xDE, 0x21, 0x07, 0xD3, 0x54,
  29781. 0xCE, 0xA0, 0xF6, 0xA4, 0x54, 0x69, 0x2F, 0x04,
  29782. 0xCD, 0x83, 0x8E, 0xBD, 0xD4, 0x6E, 0x19, 0x1E,
  29783. 0x5D, 0x9C, 0x11, 0x83, 0x9A, 0x2C, 0x3F, 0x48,
  29784. 0x8A, 0x4F, 0xC7, 0xCD, 0x26, 0x5A, 0x7B, 0x5D,
  29785. 0x32, 0xB0, 0x8C, 0xBD, 0xBF, 0xAB, 0x9D, 0x2C,
  29786. 0xCD, 0x76, 0x22, 0x2C, 0x8E, 0xE3, 0x7D, 0xDC,
  29787. 0xBD, 0x2A, 0xA0, 0x63, 0xED, 0x86, 0x14, 0x73,
  29788. 0xA6, 0x45, 0x4C, 0xAE, 0xA3, 0x77, 0x85, 0x0B,
  29789. 0x1A, 0x2B, 0x9D, 0xDB, 0xBC, 0xB3, 0x74, 0xFA,
  29790. 0xB5, 0xB1, 0x2F, 0x35, 0x1C, 0x8E, 0x58, 0x88,
  29791. 0x87, 0x2E, 0x5C, 0xD1, 0xF6, 0x0A, 0x4F, 0xAE,
  29792. 0x1F, 0xF8, 0x37, 0xD1, 0x92, 0xC2, 0x2B, 0xEB,
  29793. 0x41, 0xEE, 0x6F, 0xA3, 0x92, 0xFC, 0xDF, 0x45,
  29794. 0x50, 0xFF, 0x46, 0xB5, 0xCE, 0x90, 0x6D, 0x01,
  29795. 0x7E, 0xF3, 0x07, 0x7D, 0xF1, 0x32, 0x30, 0x0D,
  29796. 0x8B, 0xBF, 0xA9, 0xBB, 0x03, 0xC7, 0x5E, 0x79,
  29797. 0xE2, 0xF0, 0x4C, 0x28, 0x4A, 0xD0, 0x6A, 0x44,
  29798. 0x39, 0x96, 0x49, 0xC3, 0xE2, 0xA2, 0xA8, 0xD1,
  29799. 0xEF, 0xE9, 0xB7, 0xA4, 0xE0, 0xC2, 0x71, 0x04,
  29800. 0x7A, 0xB7, 0x59, 0x08, 0xBF, 0xF7, 0xDF, 0x9E,
  29801. 0x30, 0xEC, 0xA5, 0x47, 0x74, 0x5B, 0xAE, 0x23,
  29802. 0xA8, 0x6F, 0xF9, 0xA8, 0xB5, 0x8C, 0x25, 0x38,
  29803. 0xB8, 0x8B, 0x86, 0x64, 0x01, 0x07, 0x69, 0x02,
  29804. 0xDC, 0x5F, 0x0B, 0xD7, 0x61, 0x68, 0x7B, 0x49,
  29805. 0xEA, 0xFE, 0x36, 0xD3, 0x50, 0xCB, 0xED, 0xFD,
  29806. 0xD3, 0x6C, 0x12, 0x1C, 0xF2, 0x37, 0x86, 0xBF,
  29807. 0xCF, 0x7E, 0x47, 0x07, 0x64, 0x96, 0xEA, 0xB6,
  29808. 0xBB, 0xDA, 0x77, 0x40, 0x49, 0xC2, 0xEB, 0xAB,
  29809. 0xE2, 0xDE, 0x99, 0xC4, 0xC2, 0x4F, 0x2D, 0xB7,
  29810. 0x36, 0x84, 0x01, 0x5B, 0x37, 0x39, 0x77, 0x49,
  29811. 0x67, 0x60, 0xCF, 0x9A, 0xC2, 0x3D, 0x8B, 0x62,
  29812. 0x31, 0x33, 0xDB, 0x2D, 0xE1, 0x0D, 0x73, 0xFA,
  29813. 0x6A, 0xD1, 0xC6, 0xDA, 0xC8, 0x43, 0x4F, 0x28,
  29814. 0xC6, 0xE2, 0x51, 0xCE, 0x72, 0x93, 0xCF, 0xF3,
  29815. 0xF3, 0xB6, 0x1E, 0xFC, 0xB5, 0xA4, 0x35, 0x12,
  29816. 0x36, 0x70, 0xF2, 0x98, 0x46, 0xA1, 0x3D, 0xF3,
  29817. 0xEE, 0x71, 0x26, 0x04, 0x46, 0x1F, 0x1B, 0xAB,
  29818. 0x8F, 0x4E, 0xBC, 0x83, 0x6D, 0xE0, 0x58, 0x97,
  29819. 0x8A, 0xE7, 0x34, 0x39, 0x6A, 0x98, 0x08, 0x1B,
  29820. 0x35, 0xCC, 0x98, 0x18, 0x8A, 0x86, 0x94, 0x9C,
  29821. 0x99, 0x27, 0x0D, 0x47, 0x09, 0x85, 0x4C, 0x5B,
  29822. 0x35, 0xB1, 0x7F, 0x48, 0xA3, 0x73, 0x13, 0x4C,
  29823. 0x81, 0x4C, 0xC8, 0xA0, 0xF3, 0xE2, 0xFA, 0x80,
  29824. 0x7F, 0x2A, 0x91, 0x85, 0x30, 0x90, 0x78, 0x64,
  29825. 0x77, 0x82, 0x82, 0xD7, 0x5E, 0x03, 0xA4, 0x1B,
  29826. 0x25, 0x04, 0xEE, 0xD8, 0x16, 0xA4, 0x17, 0xA3,
  29827. 0xAC, 0x6B, 0xA1, 0x60, 0x80, 0xC3, 0x9B, 0x73,
  29828. 0x10, 0x19, 0x20, 0x02, 0xA7, 0x28, 0xF7, 0xF2,
  29829. 0x03, 0x95, 0x00, 0x9A, 0x9E, 0x16, 0x76, 0x7C,
  29830. 0xE1, 0x97, 0x1F, 0x5D, 0xE7, 0xD2, 0x29, 0xA5,
  29831. 0x06, 0x13, 0x36, 0x9E, 0x43, 0x82, 0x04, 0x5A,
  29832. 0x8E, 0x81, 0x90, 0x1F, 0x4D, 0xBA, 0x81, 0x02,
  29833. 0xF3, 0xD4, 0x13, 0xFE, 0x35, 0xB3, 0x26, 0xA8,
  29834. 0x74, 0xF2, 0x33, 0xB7, 0x19, 0xA7, 0x13, 0x76,
  29835. 0x00, 0xD3, 0x5D, 0x33, 0xAE, 0xB6, 0xB7, 0x25,
  29836. 0x96, 0x24, 0x08, 0x3A, 0xA9, 0x68, 0x73, 0x0C,
  29837. 0x8F, 0x78, 0x29, 0x2A, 0xD2, 0x8F, 0x14, 0xEE,
  29838. 0xAB, 0xE6, 0x60, 0x83, 0x59, 0x84, 0xFE, 0x69,
  29839. 0xEF, 0x23, 0xDE, 0xC8, 0xC3, 0x27, 0xC0, 0xEB,
  29840. 0x0B, 0x88, 0x2D, 0x58, 0x7E, 0x1E, 0xC4, 0x33,
  29841. 0xDA, 0x85, 0xC9, 0xFD, 0x1E, 0x0A, 0x34, 0x99,
  29842. 0x4D, 0xEA, 0x24, 0x0C, 0x85, 0x44, 0x52, 0xD1,
  29843. 0x8C, 0x30, 0xF4, 0x96, 0xE4, 0x9E, 0xC9, 0x04,
  29844. 0xB6, 0x02, 0xE0, 0xF5, 0x06, 0x2E, 0xDC, 0xDA,
  29845. 0x03, 0x28, 0x0A, 0x53, 0xB4, 0x31, 0x35, 0x74,
  29846. 0xCC, 0x2C, 0x0D, 0x54, 0x71, 0xBC, 0x96, 0x13,
  29847. 0xBD, 0xFD, 0x66, 0x41, 0xF5, 0xBD, 0x12, 0x7B,
  29848. 0xAB, 0x5B, 0x5E, 0xB3, 0xD4, 0x99, 0xA3, 0x31,
  29849. 0x14, 0x04, 0x82, 0x20, 0xE8, 0x19, 0xF8, 0xEE,
  29850. 0x12, 0xCA, 0x92, 0x2C, 0x8F, 0x17, 0xD9, 0xC9,
  29851. 0xF5, 0x1A, 0xD5, 0xBD, 0x68, 0x83, 0xB1, 0x0E,
  29852. 0x6A, 0xA2, 0x48, 0x3B, 0xA4, 0x9D, 0xC5, 0x47,
  29853. 0xDA, 0x76, 0x86, 0x15, 0x13, 0x44, 0xF4, 0xE9,
  29854. 0x09, 0x9B, 0x38, 0xE4, 0x30, 0xB5, 0x22, 0x6B,
  29855. 0x05, 0x98, 0x32, 0xCF, 0x03, 0xDB, 0x48, 0xFB,
  29856. 0x02, 0xDB, 0xA4, 0xE6, 0x15, 0x93, 0xDC, 0x45,
  29857. 0x76, 0x36, 0x04, 0x91, 0x89, 0x0E, 0x53, 0xEC,
  29858. 0x0E, 0x6A, 0xC7, 0x3C, 0xF3, 0x2B, 0x25, 0xD8,
  29859. 0x23, 0xB3, 0x84, 0x56, 0xE2, 0x86, 0x50, 0x5A,
  29860. 0x54, 0x1E, 0x5A, 0xEE, 0xE9, 0x6B, 0x19, 0x14,
  29861. 0xF5, 0xF7, 0x66, 0x87, 0xCE, 0x2B, 0x01, 0x60,
  29862. 0x22, 0x7A, 0xBE, 0xD7, 0x79, 0x93, 0x59, 0x4B,
  29863. 0xCD, 0x83, 0x13, 0x66, 0x20, 0x6D, 0x75, 0x71,
  29864. 0x40, 0x82, 0xF1, 0xC4, 0x6F, 0x1F, 0x44, 0x39,
  29865. 0xAC, 0x81, 0xA5, 0x7A, 0xF3, 0x1C, 0x81, 0xC5,
  29866. 0x55, 0x30, 0x7A, 0x07, 0x0F, 0xFA, 0x94, 0xE0,
  29867. 0x47, 0x9B, 0x78, 0x4B, 0xBD, 0x88, 0xA6, 0x0C,
  29868. 0xD4, 0xC7, 0xCF, 0xD9, 0x4E, 0x6A, 0xFE, 0x02,
  29869. 0xF6, 0xB2, 0x1F, 0x72, 0xAF, 0x0D, 0xCD, 0x66,
  29870. 0x09, 0xD4, 0x0C, 0x96, 0x5C, 0x14, 0xE5, 0xF2,
  29871. 0x38, 0x91, 0x83, 0xE5, 0x3D, 0xE9, 0x30, 0xF7,
  29872. 0xDE, 0x1D, 0x44, 0x21, 0x5C, 0xF4, 0x91, 0x44,
  29873. 0x84, 0x4E, 0x8B, 0x87, 0xF7, 0x8A, 0x7F, 0x13,
  29874. 0x2A, 0xEF, 0xE2, 0x2B, 0xE8, 0x0B, 0x4E, 0x3A,
  29875. 0x05, 0xEE, 0x3A, 0x68, 0xCC, 0xF6, 0x09, 0xEF,
  29876. 0x44, 0x04, 0x74, 0x02, 0xE4, 0x49, 0x30, 0x46,
  29877. 0xE6, 0xF9, 0xC7, 0x67, 0xFF, 0x8A, 0x75, 0xE2,
  29878. 0x8B, 0x3C, 0xE0, 0x77, 0xFD, 0xE7, 0xE7, 0xEE,
  29879. 0xD3, 0x13, 0xB5, 0xBF, 0x7E, 0x46, 0x01, 0x27,
  29880. 0xCA, 0x81, 0x82, 0xE9, 0xBC, 0x79, 0x4C, 0x0D,
  29881. 0xFA, 0x73, 0x0F, 0xB9, 0x20, 0x08, 0x05, 0x75,
  29882. 0xA7, 0x51, 0xB5, 0xCA, 0xEC, 0x85, 0xA1, 0x09,
  29883. 0xB4, 0x42, 0x2B, 0xA2, 0x66, 0x74, 0x3F, 0x0D,
  29884. 0x03, 0x2B, 0xDA, 0x8F, 0x1C, 0xA6, 0x24, 0x8C,
  29885. 0xDB, 0x91, 0x75, 0x30, 0xDF, 0x13, 0x02, 0xA5,
  29886. 0xF8, 0xC1, 0x8D, 0xC6, 0x42, 0xD5, 0x24, 0x78,
  29887. 0xC9, 0x8C, 0x12, 0xA3, 0xF1, 0x6E, 0xF2, 0xB6,
  29888. 0x2B, 0x4F, 0x59, 0xEA, 0x1B, 0xB5, 0x8D, 0xE7,
  29889. 0xB6, 0x5B, 0x3C, 0x71, 0x53, 0xCE, 0x6D, 0xA5,
  29890. 0xE4, 0x95, 0x07, 0x46, 0xF8, 0x0E, 0x08, 0x7A,
  29891. 0x0E, 0x35, 0x86, 0xD0, 0x97, 0x79, 0x1B, 0xF3,
  29892. 0x6D, 0xEF, 0x86, 0x5D, 0x68, 0x59, 0x1D, 0x39,
  29893. 0xD0, 0x90, 0x37, 0x73, 0xEE, 0xA9, 0x62, 0x14,
  29894. 0x7F, 0x34, 0x70, 0x41, 0x38, 0xB5, 0x4D, 0xF7,
  29895. 0x92, 0x4C, 0xDD, 0x8C, 0x33, 0x3D, 0xB5, 0xE1,
  29896. 0xA4, 0x09, 0xCC, 0xB2, 0xB3, 0x4E, 0x2C, 0x3C,
  29897. 0x8C, 0x7F, 0xDD, 0x3F, 0xD8, 0xD0, 0x12, 0xCB,
  29898. 0xF3, 0x82, 0xAA, 0xA8, 0x5E, 0x83, 0xA1, 0x2F,
  29899. 0x23, 0x5A, 0x2D, 0x14, 0x7D, 0x03, 0x5B, 0x7B,
  29900. 0x28, 0xB3, 0x4B, 0x6F, 0x57, 0x94, 0x9F, 0x32,
  29901. 0x24, 0x82, 0xA7, 0xD4, 0xD3, 0xB1, 0x50, 0x45,
  29902. 0xC4, 0x20, 0xD5, 0xAD, 0xDC, 0x7F, 0x0E, 0x69,
  29903. 0xB4, 0xDC, 0x1C, 0xBA, 0x58, 0xB0, 0x1D, 0x87,
  29904. 0x24, 0x80, 0xB0, 0x6A, 0x26, 0x0D, 0x82, 0x7D,
  29905. 0x89, 0x1B, 0x13, 0xC4, 0xC5, 0xCA, 0x50, 0xC7,
  29906. 0x48, 0xDE, 0x3C, 0x77, 0x1B, 0xE6, 0x1E, 0x9A,
  29907. 0xA1, 0x70, 0x16, 0x5C, 0xB0, 0x1F, 0x4B, 0xF5,
  29908. 0xDA, 0x27, 0xA7, 0x79, 0x1D, 0x3A, 0xD3, 0xF6,
  29909. 0x26, 0x7B, 0x4C, 0xB4, 0xE6, 0x1B, 0x28, 0xFA,
  29910. 0x17, 0x08, 0x41, 0x8D, 0x93, 0x2D, 0xFC, 0x41,
  29911. 0x61, 0x88, 0x0C, 0x5D, 0x3B, 0x17, 0xA9, 0x66,
  29912. 0x3A, 0x90, 0x61, 0xFA, 0x8F, 0x18, 0x04, 0x31,
  29913. 0x58, 0x50, 0xFE, 0x4E, 0x73, 0x06, 0xC8, 0x82,
  29914. 0xB3, 0x82, 0x27, 0xE8, 0x67, 0xF8, 0x08, 0x72,
  29915. 0xCD, 0xC1, 0x94, 0x4D, 0x47, 0x26, 0x15, 0xEA,
  29916. 0x49, 0x00, 0xEF, 0x7D, 0x27, 0x0B, 0x88, 0x1D,
  29917. 0x41, 0x30, 0xF5, 0x6C, 0x5C, 0xC9, 0x80, 0xD9,
  29918. 0x2A, 0x47, 0xAD, 0xA6, 0x65, 0x7E, 0xB6, 0xF3,
  29919. 0x7A, 0x38, 0x5D, 0x2D, 0x8C, 0xC9, 0x93, 0xE1,
  29920. 0x44, 0x2E, 0xB0, 0x52, 0x81, 0x85, 0x36, 0x36,
  29921. 0x99, 0x1E, 0x34, 0xAA, 0xDC, 0x68, 0x95, 0x4D,
  29922. 0x04, 0xE7, 0xAD, 0xEF, 0x76, 0xBF, 0x88, 0x0F,
  29923. 0x05, 0x9B, 0x0C, 0xBB, 0x55, 0xD9, 0x15, 0xA4,
  29924. 0xB1, 0x23, 0xE2, 0xF1, 0x33, 0x9A, 0x07, 0x3C,
  29925. 0xBF, 0xBC, 0x40, 0x9B, 0xEF, 0xF6, 0x40, 0x0A,
  29926. 0xE0, 0x96, 0xD5, 0xAE, 0x18, 0xEC, 0x42, 0xCF,
  29927. 0xFA, 0xD5, 0xB4, 0x98, 0x0F, 0xA3, 0x5B, 0xF0,
  29928. 0x34, 0x13, 0xAD, 0xB5, 0xD7, 0xE6, 0x87, 0x6A,
  29929. 0xC3, 0x55, 0xD1, 0xC9, 0xED, 0x70, 0xCA, 0x2B,
  29930. 0x97, 0x39, 0x54, 0xD1, 0x2B, 0x3C, 0xDD, 0x76,
  29931. 0xAC, 0x68, 0x35, 0xDB, 0x96, 0x00, 0x3E, 0xD8,
  29932. 0xC4, 0xE2, 0x88, 0xB7, 0x1F, 0xD7, 0x7D, 0xBA,
  29933. 0xA7, 0x63, 0x57, 0x20, 0xE1, 0x2A, 0xE0, 0xA3,
  29934. 0x17, 0xDE, 0x80, 0x8C, 0x66, 0x4E, 0x31, 0x7F,
  29935. 0x55, 0x27, 0x57, 0x91, 0xF3, 0x24, 0x5C, 0xA4,
  29936. 0xFE, 0x5D, 0x4D, 0x41, 0x07, 0x7F, 0xC1, 0x50,
  29937. 0xA6, 0xE4, 0x03, 0xD5, 0xA2, 0x08, 0xE4, 0x6E,
  29938. 0xAD, 0xBE, 0x8F, 0x2C, 0xFB, 0x8A, 0xF4, 0x72,
  29939. 0xF4, 0xA0, 0xCE, 0xAC, 0x01, 0x52, 0x19, 0x47,
  29940. 0x8E, 0x6B, 0x86, 0xC9, 0x58, 0xCF, 0x86, 0x52,
  29941. 0x5B, 0x74, 0x85, 0xC1, 0x73, 0x4C, 0x7E, 0xF0,
  29942. 0x0E, 0x90, 0x68, 0x3F, 0xFF, 0x5D, 0xBD, 0x0A,
  29943. 0x7D, 0x41, 0x3A, 0x85, 0x50, 0x21, 0x02, 0x6A,
  29944. 0x1B, 0x32, 0x01, 0x3A, 0x46, 0x16, 0xCB, 0xCD,
  29945. 0x37, 0x00, 0xAC, 0xBC, 0x70, 0x5B, 0xE3, 0xEF,
  29946. 0xBA, 0x62, 0x5C, 0x69, 0xA0, 0x25, 0x26, 0x7B,
  29947. 0xCE, 0x9D, 0x13, 0x5E, 0x3F, 0x5B, 0x5C, 0xC8,
  29948. 0xC4, 0x39, 0x56, 0x40, 0x7E, 0x84, 0xB6, 0x66,
  29949. 0x31, 0x03, 0xE2, 0x9C, 0x24, 0x20, 0x35, 0x55,
  29950. 0x1A, 0xE7, 0x97, 0xF5, 0x6C, 0x63, 0x74, 0xBE,
  29951. 0x0C, 0x79, 0x8C, 0x0C, 0xF3, 0x98, 0xF1, 0xED
  29952. #else
  29953. 0x30, 0x82, 0x0a, 0x32, 0x30, 0x0d, 0x06, 0x09,
  29954. 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03,
  29955. 0x13, 0x03, 0x82, 0x0a, 0x21, 0x00,
  29956. 0x69, 0x24, 0xBB, 0x42, 0x57, 0xA7, 0xB9, 0xAF,
  29957. 0xF0, 0x95, 0xC3, 0x0B, 0xB3, 0x5C, 0x6A, 0xE4,
  29958. 0x19, 0x82, 0x63, 0x12, 0x0F, 0x80, 0x39, 0xAA,
  29959. 0x4E, 0x78, 0xE1, 0x74, 0xA7, 0x86, 0xCE, 0x00,
  29960. 0x83, 0x01, 0xE6, 0x66, 0xF5, 0x9D, 0x3E, 0xC5,
  29961. 0x04, 0x4D, 0xE4, 0x56, 0x78, 0x8F, 0xDE, 0x19,
  29962. 0xEB, 0x39, 0x67, 0x7B, 0x5F, 0x9F, 0xE1, 0x41,
  29963. 0x50, 0xDA, 0x46, 0x3A, 0x70, 0x6F, 0x3B, 0xAF,
  29964. 0x71, 0x5B, 0x95, 0x33, 0x6B, 0x2D, 0x68, 0x5A,
  29965. 0x7C, 0xD7, 0x88, 0x07, 0x13, 0xE4, 0x58, 0x7B,
  29966. 0xF7, 0xD8, 0x57, 0xBF, 0x7E, 0x31, 0x56, 0x96,
  29967. 0xB8, 0xD0, 0xD9, 0xD4, 0x9E, 0x14, 0x29, 0x18,
  29968. 0xBF, 0x09, 0x74, 0xE7, 0xF4, 0x32, 0x37, 0xD4,
  29969. 0xBE, 0x3A, 0xD3, 0x94, 0x59, 0x9E, 0x3D, 0x39,
  29970. 0xBB, 0x76, 0x49, 0x93, 0x25, 0x53, 0x44, 0x7E,
  29971. 0x5D, 0x5A, 0xCC, 0x34, 0x99, 0x93, 0x01, 0x76,
  29972. 0xEC, 0xD3, 0xA8, 0x44, 0xA4, 0x25, 0xF5, 0x0D,
  29973. 0x05, 0x11, 0xC9, 0x22, 0x6C, 0x4B, 0x9A, 0x24,
  29974. 0xF2, 0xA0, 0x11, 0xCD, 0x88, 0xD3, 0x23, 0x08,
  29975. 0xE0, 0x31, 0x2A, 0x0C, 0x87, 0xCC, 0x34, 0xA9,
  29976. 0x95, 0x82, 0x3C, 0x65, 0xF4, 0xF0, 0xF9, 0x8E,
  29977. 0x50, 0xC3, 0x77, 0x88, 0xCE, 0x38, 0xDC, 0x28,
  29978. 0xFB, 0x8B, 0x9B, 0xFA, 0xAF, 0xA9, 0x04, 0xB5,
  29979. 0x41, 0xEE, 0x71, 0x2F, 0x6A, 0x04, 0x1E, 0x06,
  29980. 0x11, 0x37, 0x4F, 0x6B, 0xF1, 0x7E, 0xAC, 0x0B,
  29981. 0xD5, 0x6F, 0x3B, 0x6B, 0xF3, 0x36, 0xDA, 0x92,
  29982. 0x42, 0x07, 0x0C, 0x24, 0x69, 0xA2, 0x0C, 0x4D,
  29983. 0x16, 0x16, 0x14, 0x9A, 0x61, 0x59, 0x25, 0x20,
  29984. 0x11, 0xD2, 0x99, 0xF9, 0x3F, 0x98, 0x6D, 0x87,
  29985. 0x5D, 0xD3, 0x0B, 0x38, 0xA2, 0x25, 0x49, 0x17,
  29986. 0x45, 0x70, 0x13, 0x8C, 0x2B, 0xB3, 0xAA, 0x9C,
  29987. 0xBE, 0xA9, 0x19, 0x74, 0xF3, 0xD8, 0x9B, 0xF5,
  29988. 0xAE, 0x32, 0xBE, 0x9E, 0x58, 0xB8, 0x54, 0xA2,
  29989. 0xF8, 0xE8, 0x6F, 0xF7, 0x67, 0x80, 0xC0, 0x34,
  29990. 0x90, 0xF4, 0x67, 0xDB, 0x06, 0x51, 0xC2, 0x0B,
  29991. 0x1D, 0xF6, 0x0E, 0xB9, 0x7A, 0x3C, 0x99, 0xD9,
  29992. 0xBD, 0x66, 0x4B, 0xE6, 0xA5, 0xE4, 0xC8, 0xA8,
  29993. 0xAD, 0x4C, 0xC3, 0x63, 0x90, 0xD7, 0x00, 0x4E,
  29994. 0x4B, 0xB4, 0x21, 0xDA, 0xED, 0x65, 0x4C, 0x35,
  29995. 0x7D, 0xA4, 0xD6, 0x84, 0x98, 0x93, 0x3E, 0xC7,
  29996. 0x17, 0x77, 0xAD, 0x64, 0xC2, 0xAE, 0x01, 0x3C,
  29997. 0x73, 0xEB, 0x45, 0x7C, 0x68, 0xEF, 0x9A, 0x74,
  29998. 0x5A, 0xDE, 0xEB, 0x4F, 0xDF, 0xC8, 0x79, 0xE7,
  29999. 0x74, 0xD0, 0x3F, 0xAF, 0x6B, 0x14, 0xAA, 0xB1,
  30000. 0x07, 0x52, 0xE2, 0x4B, 0x52, 0xD0, 0xF2, 0xD9,
  30001. 0x4D, 0x54, 0x0A, 0x1E, 0xBE, 0x10, 0xF5, 0x97,
  30002. 0xE5, 0x14, 0x44, 0x2D, 0x6C, 0x13, 0xC2, 0xE2,
  30003. 0x49, 0x8E, 0x8A, 0xF3, 0x01, 0x7C, 0x52, 0xDB,
  30004. 0x23, 0x3A, 0x90, 0x71, 0x7D, 0xF2, 0x5B, 0x4D,
  30005. 0x07, 0x2B, 0x7D, 0x88, 0xEE, 0x87, 0x31, 0xD1,
  30006. 0x68, 0x24, 0xC9, 0x5D, 0x1F, 0xB9, 0x83, 0xC4,
  30007. 0x49, 0xDE, 0xB4, 0x66, 0x27, 0x60, 0x60, 0xFE,
  30008. 0xE4, 0xC7, 0xEE, 0x38, 0x14, 0x51, 0xF2, 0x32,
  30009. 0xC2, 0x9C, 0x7C, 0x32, 0x20, 0x85, 0x0C, 0x61,
  30010. 0xD1, 0xC3, 0xC0, 0x0D, 0xB1, 0xCD, 0x97, 0x26,
  30011. 0xA0, 0x2A, 0x56, 0x60, 0x9F, 0x3A, 0x65, 0xD3,
  30012. 0xD1, 0x64, 0x60, 0x45, 0x88, 0xCD, 0x9B, 0x43,
  30013. 0x14, 0x12, 0xF1, 0xAD, 0xD9, 0x14, 0xC5, 0xC2,
  30014. 0xDA, 0xBB, 0xC9, 0x04, 0x67, 0xC0, 0xC4, 0xEA,
  30015. 0x5F, 0x76, 0xE2, 0x4A, 0xA6, 0x18, 0x76, 0x5F,
  30016. 0x8B, 0x06, 0x36, 0xD7, 0xB0, 0x65, 0xE1, 0xF4,
  30017. 0xE6, 0xF6, 0x22, 0xEA, 0xE1, 0x71, 0x52, 0x45,
  30018. 0x8C, 0x76, 0x65, 0x86, 0x77, 0x2D, 0x36, 0x3F,
  30019. 0xA9, 0x92, 0x14, 0xF4, 0x72, 0xB0, 0xDB, 0x8A,
  30020. 0x1E, 0x49, 0xD8, 0x2D, 0x02, 0x78, 0xF2, 0x95,
  30021. 0x8B, 0x0A, 0xAA, 0x15, 0x86, 0xDB, 0x13, 0x4B,
  30022. 0xDF, 0xD2, 0x43, 0x87, 0x42, 0x49, 0x50, 0x07,
  30023. 0xE2, 0xFE, 0x5B, 0x60, 0xE2, 0x46, 0x39, 0x92,
  30024. 0x26, 0x94, 0x7A, 0x12, 0xEA, 0x17, 0x63, 0x1C,
  30025. 0xAA, 0x53, 0x46, 0x87, 0xCB, 0x75, 0xC0, 0x60,
  30026. 0xB4, 0x79, 0x7E, 0xAB, 0x82, 0x77, 0xCC, 0x4F,
  30027. 0x8A, 0x7A, 0x20, 0x38, 0x76, 0x06, 0xEF, 0xE2,
  30028. 0xDB, 0xD3, 0xE7, 0x36, 0x24, 0x92, 0x77, 0xD9,
  30029. 0x0F, 0xCA, 0xB9, 0x92, 0xA8, 0xC9, 0x9E, 0x85,
  30030. 0xAB, 0x03, 0xEB, 0x4C, 0xAC, 0x5D, 0x88, 0x55,
  30031. 0x39, 0x58, 0x52, 0x8A, 0xF9, 0x29, 0x74, 0x71,
  30032. 0x81, 0x35, 0xF1, 0xD0, 0xC7, 0x93, 0xEB, 0x00,
  30033. 0x0E, 0xA0, 0xAE, 0xC3, 0xEC, 0x18, 0x58, 0xFD,
  30034. 0xD1, 0x86, 0x88, 0xD1, 0xDA, 0x27, 0x27, 0x8D,
  30035. 0xEB, 0xF2, 0xCA, 0x81, 0x10, 0xBA, 0x4A, 0x20,
  30036. 0x4F, 0x79, 0x30, 0xE1, 0xC8, 0xCE, 0xEC, 0xAF,
  30037. 0xB7, 0x3F, 0x75, 0xDD, 0xB3, 0x4C, 0x5C, 0x55,
  30038. 0x96, 0x8A, 0x79, 0x33, 0x05, 0x84, 0x26, 0xB5,
  30039. 0x5D, 0x03, 0x9F, 0x72, 0x92, 0xAC, 0x43, 0xF6,
  30040. 0x45, 0x84, 0xF6, 0xDF, 0x18, 0x7A, 0x1D, 0x6B,
  30041. 0x00, 0x3F, 0x51, 0x4C, 0xC1, 0x3B, 0x26, 0xC2,
  30042. 0xF3, 0x48, 0x19, 0x5A, 0xA3, 0x21, 0xDE, 0x6A,
  30043. 0x27, 0xEC, 0x11, 0x34, 0x8D, 0xE5, 0x0D, 0x82,
  30044. 0x5A, 0x29, 0x64, 0xC6, 0x31, 0x99, 0x2E, 0x4B,
  30045. 0x0B, 0x42, 0x5B, 0x1B, 0xEB, 0x4F, 0x96, 0x00,
  30046. 0xE3, 0xAD, 0xC4, 0x43, 0x1C, 0xF2, 0xE8, 0x8B,
  30047. 0x42, 0x23, 0xD2, 0xDB, 0x66, 0x3C, 0x3C, 0xE7,
  30048. 0x0E, 0xF8, 0x5D, 0xDD, 0x56, 0xA9, 0xBA, 0xF1,
  30049. 0x38, 0xA9, 0xD7, 0xED, 0xD8, 0x94, 0x13, 0x1C,
  30050. 0x3A, 0x8F, 0x41, 0xA0, 0x4E, 0xF9, 0xF8, 0x67,
  30051. 0x52, 0xB7, 0x21, 0x81, 0xFA, 0xBB, 0x37, 0xC8,
  30052. 0x6B, 0x87, 0x7E, 0x61, 0xD6, 0x0E, 0xED, 0x95,
  30053. 0xEE, 0xFF, 0xAB, 0xE6, 0x37, 0x6E, 0x14, 0xAC,
  30054. 0xA8, 0x17, 0xC5, 0xF4, 0x19, 0x61, 0xAF, 0x8A,
  30055. 0x78, 0x49, 0xBA, 0xC0, 0x94, 0x91, 0x7B, 0x2D,
  30056. 0x13, 0x22, 0x76, 0xB6, 0xB3, 0x48, 0x6A, 0xFF,
  30057. 0x95, 0x0D, 0x23, 0xD4, 0xAA, 0xDC, 0x24, 0xCE,
  30058. 0x98, 0xA5, 0x26, 0x9E, 0x1C, 0x69, 0x91, 0x79,
  30059. 0x60, 0xA3, 0x1E, 0xE0, 0x9A, 0x52, 0x7C, 0x35,
  30060. 0x81, 0x75, 0xCA, 0xA0, 0xCB, 0x1B, 0x01, 0x8E,
  30061. 0x95, 0x26, 0xD9, 0x35, 0x34, 0xEA, 0xDB, 0xAC,
  30062. 0xB5, 0x2B, 0x27, 0x3D, 0x73, 0x5E, 0x22, 0xDD,
  30063. 0x0D, 0x5C, 0x28, 0xFA, 0x3E, 0x47, 0xCF, 0xE9,
  30064. 0x0B, 0x52, 0x15, 0xAE, 0x24, 0xF1, 0x46, 0xC3,
  30065. 0x46, 0x4B, 0xFE, 0xAF, 0x01, 0xD2, 0x8D, 0xAA,
  30066. 0x55, 0x3C, 0x1E, 0x94, 0x42, 0x8A, 0x10, 0x4A,
  30067. 0x9D, 0x78, 0xAE, 0xC7, 0x62, 0x59, 0x1E, 0x88,
  30068. 0x79, 0xF7, 0x68, 0x51, 0xCF, 0xB4, 0x64, 0x85,
  30069. 0x66, 0x72, 0x1B, 0x0C, 0xAC, 0x1F, 0x14, 0xFE,
  30070. 0x16, 0x14, 0x9A, 0x9D, 0x82, 0x10, 0xCC, 0x8F,
  30071. 0x2F, 0x50, 0xDE, 0xF7, 0xB4, 0x6C, 0x84, 0x3B,
  30072. 0xE9, 0x3B, 0xD8, 0xD5, 0x56, 0x02, 0x49, 0x33,
  30073. 0x50, 0xAB, 0x56, 0x0E, 0xA5, 0xBA, 0x17, 0x71,
  30074. 0x64, 0x23, 0xBE, 0x0E, 0xB8, 0x36, 0x0A, 0xB1,
  30075. 0x09, 0xD8, 0xFB, 0x18, 0xBF, 0xEA, 0x04, 0x08,
  30076. 0x47, 0xB7, 0x33, 0x51, 0x45, 0xD4, 0xF2, 0x00,
  30077. 0xD1, 0x9C, 0xF6, 0xFE, 0x7B, 0xAC, 0x91, 0x7F,
  30078. 0x42, 0x6C, 0x9B, 0x3D, 0x39, 0xA9, 0xCA, 0x43,
  30079. 0x29, 0x81, 0x8F, 0x24, 0x0E, 0x7D, 0xA3, 0x82,
  30080. 0x76, 0x10, 0x72, 0xF4, 0xA6, 0x50, 0x5E, 0xA8,
  30081. 0xE7, 0x6C, 0x1E, 0x44, 0x6F, 0xEB, 0x66, 0x25,
  30082. 0xE3, 0x8D, 0xDB, 0xCD, 0x3C, 0xDA, 0x81, 0xE8,
  30083. 0x3B, 0xF7, 0x68, 0xF3, 0xE0, 0x1D, 0x9D, 0x26,
  30084. 0x3B, 0x36, 0x73, 0x03, 0xAE, 0x15, 0x6C, 0x0B,
  30085. 0x71, 0x83, 0x36, 0x4A, 0x1E, 0x79, 0x41, 0xA0,
  30086. 0x92, 0x98, 0xA3, 0xAD, 0xF7, 0xBD, 0x23, 0x1E,
  30087. 0x61, 0x14, 0xB9, 0xDC, 0xE7, 0x95, 0x2B, 0x11,
  30088. 0x3F, 0x78, 0x16, 0x31, 0x38, 0xB9, 0x26, 0x6F,
  30089. 0x84, 0x3F, 0x1E, 0xD9, 0x7D, 0x9C, 0x2B, 0x16,
  30090. 0x3A, 0x6E, 0x8B, 0xD4, 0xC1, 0xAB, 0x4E, 0x17,
  30091. 0x93, 0x67, 0xC5, 0xAC, 0x96, 0xCE, 0xCF, 0x50,
  30092. 0x50, 0xFE, 0x82, 0x1F, 0xDF, 0xA4, 0x4E, 0x9E,
  30093. 0x68, 0x0B, 0x61, 0xC6, 0x01, 0x89, 0x32, 0xDF,
  30094. 0x71, 0x78, 0x11, 0x45, 0x9A, 0xF2, 0x54, 0x2E,
  30095. 0x2C, 0xDE, 0x77, 0x17, 0x8C, 0x2E, 0x98, 0x80,
  30096. 0xF0, 0x11, 0xE4, 0x05, 0xEA, 0xFA, 0x59, 0xC8,
  30097. 0xCB, 0xBE, 0xD7, 0x6E, 0x5A, 0x19, 0x41, 0x10,
  30098. 0x4B, 0x1B, 0x9D, 0x3A, 0x60, 0x49, 0x1C, 0x95,
  30099. 0x47, 0x55, 0xE0, 0x2E, 0x89, 0x41, 0x03, 0xF1,
  30100. 0xF4, 0x97, 0x74, 0x75, 0xE9, 0xEA, 0x36, 0x60,
  30101. 0x9F, 0xD6, 0x7C, 0x9D, 0xE3, 0x18, 0xED, 0xA2,
  30102. 0x37, 0x0D, 0xCC, 0xDB, 0xB9, 0xCE, 0xF7, 0xAE,
  30103. 0x63, 0x60, 0x90, 0x5E, 0xC2, 0x20, 0x83, 0x8C,
  30104. 0x97, 0x69, 0x82, 0x34, 0x41, 0xCD, 0xD0, 0xDA,
  30105. 0x8E, 0xF0, 0xAB, 0xE5, 0xF2, 0xD1, 0xD7, 0x6E,
  30106. 0x2F, 0xE0, 0x8F, 0xEF, 0x53, 0xDE, 0x1D, 0x61,
  30107. 0x66, 0xAB, 0x1A, 0x92, 0xB1, 0xAC, 0x09, 0x3E,
  30108. 0x5A, 0xBF, 0x76, 0x58, 0xC4, 0xB5, 0x72, 0x87,
  30109. 0xF2, 0xD1, 0xFD, 0x7B, 0x82, 0xDE, 0xDA, 0xF8,
  30110. 0xD5, 0xA4, 0xFB, 0xAC, 0x4B, 0x35, 0xD5, 0x82,
  30111. 0x31, 0x69, 0x4E, 0x16, 0x24, 0x97, 0x57, 0x8A,
  30112. 0xBD, 0x7A, 0xA7, 0xC8, 0xFE, 0x7B, 0x35, 0x41,
  30113. 0xA7, 0xF1, 0x8E, 0x54, 0xE8, 0xB7, 0xF0, 0x87,
  30114. 0x64, 0xC5, 0xE6, 0x84, 0x49, 0xDF, 0x65, 0x59,
  30115. 0x01, 0x54, 0x98, 0x32, 0xD6, 0x28, 0xFA, 0x63,
  30116. 0xD2, 0xB2, 0xC5, 0xA1, 0x50, 0x93, 0x39, 0x94,
  30117. 0xA9, 0x86, 0x33, 0x17, 0xAD, 0x40, 0xD7, 0x78,
  30118. 0xD9, 0xD2, 0xC0, 0x5C, 0x78, 0x98, 0x85, 0x0B,
  30119. 0x90, 0x17, 0x32, 0x23, 0xC7, 0xA0, 0xAF, 0x89,
  30120. 0x0F, 0xD7, 0xE6, 0x62, 0x21, 0xB6, 0xF0, 0x63,
  30121. 0x18, 0xB2, 0xED, 0x5E, 0x19, 0x9C, 0xB4, 0x24,
  30122. 0x88, 0x5A, 0xB8, 0x41, 0xE7, 0xA4, 0x72, 0x6F,
  30123. 0xAB, 0xA2, 0xF9, 0xBB, 0x53, 0xBC, 0x32, 0x36,
  30124. 0x43, 0x4C, 0x35, 0xFB, 0xBE, 0x4B, 0x1A, 0x0F,
  30125. 0x93, 0xF5, 0x0C, 0x37, 0x89, 0x6C, 0x29, 0xF8,
  30126. 0xE3, 0x02, 0xAD, 0x31, 0xED, 0x33, 0x31, 0xD6,
  30127. 0x20, 0xE3, 0xB6, 0x29, 0x45, 0x51, 0x01, 0xA1,
  30128. 0xF1, 0xCC, 0x7B, 0xA5, 0xE4, 0x6E, 0x68, 0xED,
  30129. 0x4A, 0x8C, 0xCC, 0x87, 0xB4, 0xDC, 0x75, 0xBC,
  30130. 0x01, 0x62, 0xB6, 0x33, 0x0F, 0x83, 0x3F, 0xBA,
  30131. 0x25, 0x75, 0xDF, 0xAF, 0x5B, 0x5F, 0x28, 0xBC,
  30132. 0x54, 0xFF, 0x2B, 0xA8, 0x1E, 0x7A, 0x47, 0x31,
  30133. 0x3C, 0x15, 0x48, 0x2B, 0x60, 0x5E, 0x66, 0xBB,
  30134. 0x38, 0xC6, 0x19, 0x8F, 0x13, 0x92, 0x10, 0x40,
  30135. 0x80, 0xFB, 0xE7, 0x8B, 0x86, 0xB1, 0xBC, 0x9A,
  30136. 0x6F, 0xB8, 0x81, 0xF5, 0xC7, 0x82, 0x01, 0x47,
  30137. 0xE6, 0xBA, 0x14, 0xB8, 0x1A, 0xCC, 0xF2, 0x0C,
  30138. 0xAE, 0x96, 0x64, 0x10, 0x94, 0xC2, 0x16, 0x90,
  30139. 0x2E, 0xA5, 0xC1, 0x25, 0xF6, 0xC9, 0x35, 0xA1,
  30140. 0x50, 0xD7, 0xC9, 0xAC, 0xC5, 0xD9, 0xE2, 0xE5,
  30141. 0xD9, 0x0E, 0x38, 0xC0, 0x50, 0x3A, 0xA9, 0x42,
  30142. 0x60, 0x17, 0xC7, 0x6A, 0xAF, 0xCD, 0x52, 0x61,
  30143. 0xB5, 0x06, 0x27, 0x4E, 0xC1, 0x3A, 0x96, 0x79,
  30144. 0xFB, 0x09, 0x79, 0x60, 0x27, 0xA4, 0xBB, 0x75,
  30145. 0x9D, 0x92, 0x82, 0x79, 0xB9, 0x4D, 0x84, 0x1A,
  30146. 0x09, 0x73, 0x93, 0xBF, 0x7E, 0x5B, 0xD6, 0x9A,
  30147. 0x49, 0x6C, 0xC3, 0xDE, 0xCD, 0x2B, 0x0F, 0x07,
  30148. 0xF8, 0x33, 0x92, 0xAA, 0xDE, 0x33, 0xDC, 0x51,
  30149. 0xB2, 0xA8, 0x4F, 0x6A, 0x07, 0x63, 0x5D, 0xC0,
  30150. 0xEF, 0x57, 0xA9, 0xAD, 0x59, 0x59, 0xB6, 0xA5,
  30151. 0x0B, 0x7B, 0xA5, 0x09, 0xAD, 0x5B, 0x11, 0xFA,
  30152. 0xD2, 0x6B, 0x41, 0x9F, 0x9F, 0x1E, 0x3F, 0x9C,
  30153. 0x73, 0x29, 0xB5, 0xA9, 0x53, 0xD7, 0xCC, 0x87,
  30154. 0xB2, 0xDE, 0x21, 0x06, 0x11, 0xCF, 0x52, 0xA6,
  30155. 0x39, 0xEF, 0x2B, 0x39, 0x08, 0x01, 0x2C, 0xB8,
  30156. 0x8E, 0x1D, 0x6F, 0x57, 0x62, 0x50, 0x79, 0xCB,
  30157. 0x10, 0x3D, 0x6C, 0x98, 0x10, 0x1A, 0x11, 0xBD,
  30158. 0x22, 0x33, 0xB6, 0x56, 0x02, 0xCA, 0x30, 0x49,
  30159. 0xBD, 0x32, 0x05, 0x20, 0x41, 0x9F, 0x76, 0xB0,
  30160. 0x61, 0xE3, 0x59, 0x8D, 0xE3, 0x81, 0x52, 0xC8,
  30161. 0x87, 0x67, 0xD1, 0xA2, 0x4F, 0xBD, 0x02, 0xBB,
  30162. 0x10, 0xC3, 0x8E, 0xAC, 0xAE, 0x31, 0x7D, 0xE6,
  30163. 0xBB, 0x28, 0x7B, 0x4D, 0x2C, 0xAE, 0x5D, 0xA0,
  30164. 0x21, 0x49, 0x65, 0xD8, 0x77, 0x37, 0x78, 0x62,
  30165. 0x6E, 0x9B, 0x97, 0x28, 0x59, 0xD8, 0x48, 0x2B,
  30166. 0x8D, 0x05, 0x47, 0xE4, 0xF5, 0x6D, 0xFF, 0x87,
  30167. 0x68, 0x1D, 0x5B, 0xC5, 0x12, 0x0F, 0x61, 0x3F,
  30168. 0xBB, 0xD9, 0x1E, 0x1F, 0x14, 0xE6, 0xDE, 0xFE,
  30169. 0x67, 0x2E, 0x2A, 0x7E, 0xAB, 0xCB, 0xBB, 0x9B,
  30170. 0x11, 0x08, 0x2C, 0x5E, 0x70, 0x0A, 0xA0, 0xB1,
  30171. 0xF7, 0xC1, 0x78, 0x5F, 0xCE, 0xD1, 0x9A, 0x93,
  30172. 0xAF, 0xE7, 0xC5, 0x9F, 0xA2, 0x51, 0x9B, 0xCD,
  30173. 0xEB, 0x49, 0x4C, 0x3D, 0x13, 0xB2, 0x12, 0x5F,
  30174. 0x38, 0x53, 0x23, 0xB8, 0x16, 0xC6, 0x8F, 0x8F,
  30175. 0x56, 0x28, 0xC7, 0xC2, 0xAB, 0xFD, 0x02, 0x78,
  30176. 0xA3, 0x37, 0x07, 0x3D, 0xA7, 0x4D, 0x16, 0x09,
  30177. 0x96, 0x98, 0xC4, 0xB1, 0x14, 0xE8, 0xA8, 0xCE,
  30178. 0x34, 0x4E, 0x0A, 0x15, 0xD0, 0xFC, 0x7E, 0xD4,
  30179. 0x97, 0xB0, 0x01, 0xD5, 0x3D, 0x4C, 0x96, 0xDC,
  30180. 0x39, 0x54, 0xD3, 0xB4, 0xB9, 0x56, 0xCB, 0x9D,
  30181. 0x2A, 0x27, 0x2C, 0x51, 0xF1, 0x55, 0x9B, 0x22,
  30182. 0x90, 0x4B, 0x40, 0xCC, 0x85, 0x31, 0xE4, 0x0C,
  30183. 0xC4, 0x12, 0xC6, 0x8C, 0xB6, 0xEE, 0xA4, 0xA4,
  30184. 0x09, 0x0B, 0x38, 0xE2, 0x79, 0x73, 0x29, 0x98,
  30185. 0x54, 0x67, 0xE8, 0x18, 0xA5, 0x24, 0xD3, 0x22,
  30186. 0x8E, 0xAC, 0xAE, 0x78, 0x25, 0xD3, 0xDA, 0xD2,
  30187. 0xEA, 0xA4, 0x22, 0xFD, 0xC7, 0x7A, 0xED, 0x71,
  30188. 0xA2, 0x05, 0xDA, 0x78, 0x38, 0xD9, 0x45, 0xE7,
  30189. 0xFE, 0xC3, 0x7E, 0x4D, 0xCA, 0x67, 0xE5, 0x04,
  30190. 0xCE, 0x35, 0xE5, 0xB0, 0x45, 0xF5, 0x6F, 0x1E,
  30191. 0x8D, 0x75, 0x29, 0xEB, 0xD6, 0xF1, 0xAF, 0x7B,
  30192. 0x6E, 0x93, 0x9E, 0x2B, 0x7A, 0xB4, 0x02, 0x7D,
  30193. 0x37, 0xA5, 0x13, 0x5D, 0x17, 0x2D, 0xA1, 0xAF,
  30194. 0x9C, 0xA2, 0xF7, 0x28, 0xA6, 0xF3, 0x7D, 0xE6,
  30195. 0x0D, 0xD2, 0x3D, 0x97, 0xD1, 0x1E, 0x75, 0xAB,
  30196. 0x1F, 0xD5, 0x1F, 0x8E, 0x9A, 0x13, 0x97, 0xE5,
  30197. 0x82, 0x21, 0x59, 0xDB, 0x58, 0x38, 0x02, 0xB3,
  30198. 0x2E, 0xEB, 0xB4, 0x56, 0x7E, 0xCE, 0x37, 0x46,
  30199. 0xD1, 0xAE, 0x33, 0x31, 0x47, 0x85, 0x64, 0x3D,
  30200. 0xD2, 0xA0, 0x74, 0x1E, 0x7F, 0x1B, 0xF2, 0xD2,
  30201. 0x61, 0xF2, 0x21, 0x24, 0xE8, 0xDD, 0xD0, 0x8C,
  30202. 0x64, 0x0A, 0x48, 0xB5, 0x47, 0x17, 0x51, 0x7C,
  30203. 0x21, 0xCD, 0x32, 0x53, 0x28, 0xBC, 0x23, 0x9C,
  30204. 0xA0, 0x28, 0xB2, 0x63, 0x0D, 0x06, 0x3C, 0x8C,
  30205. 0xC2, 0x0B, 0xE9, 0xBD, 0xB4, 0x85, 0x02, 0xDA,
  30206. 0xDD, 0xE7, 0x3F, 0xFE, 0xD5, 0x96, 0x38, 0x16,
  30207. 0x53, 0x3E, 0x02, 0x0A, 0xED, 0x12, 0x08, 0x53,
  30208. 0x62, 0x55, 0xB1, 0xCC, 0xE9, 0x85, 0x43, 0x31,
  30209. 0x27, 0xFF, 0x4F, 0x04, 0xD5, 0xB1, 0xE2, 0xF2,
  30210. 0x10, 0x87, 0x04, 0xB8, 0xB9, 0x66, 0x58, 0x8C,
  30211. 0x01, 0x56, 0xAF, 0xC2, 0xAE, 0x19, 0x29, 0x86,
  30212. 0xFB, 0xEC, 0x44, 0x3B, 0xAE, 0xF6, 0xCB, 0x85,
  30213. 0xA6, 0xF2, 0x9C, 0x77, 0x92, 0x40, 0x5A, 0x24,
  30214. 0x11, 0x47, 0x10, 0xAE, 0x1C, 0x74, 0x64, 0x44,
  30215. 0xFD, 0xF5, 0xFB, 0x65, 0x9E, 0x5E, 0x34, 0x68,
  30216. 0x26, 0x20, 0x7B, 0x8C, 0x54, 0x46, 0x3A, 0x06,
  30217. 0x17, 0xCE, 0x17, 0xFF, 0x33, 0xE4, 0x0F, 0x93,
  30218. 0x1F, 0xE5, 0x76, 0x71, 0x5C, 0x93, 0x2E, 0xF2,
  30219. 0x9F, 0xD7, 0x6B, 0x04, 0xA6, 0x9B, 0x58, 0xE0,
  30220. 0x30, 0x3D, 0x8E, 0xF2, 0x56, 0x78, 0xC8, 0xB7,
  30221. 0x0A, 0xF1, 0x2E, 0x90, 0x45, 0x59, 0x1C, 0x04,
  30222. 0xE8, 0xB7, 0x71, 0x06, 0x94, 0x04, 0x15, 0x17,
  30223. 0x7E, 0x86, 0x85, 0x93, 0xA0, 0x9C, 0x7E, 0x14,
  30224. 0x61, 0x9A, 0x4B, 0x33, 0x2F, 0x9A, 0xDC, 0x3A,
  30225. 0x65, 0x8B, 0x86, 0x01, 0x7F, 0x32, 0x65, 0x6C,
  30226. 0x54, 0x29, 0xC1, 0x15, 0xE1, 0x10, 0x03, 0x7A,
  30227. 0x8C, 0xC7, 0xE5, 0x44, 0x67, 0x7D, 0x2D, 0xD2,
  30228. 0x39, 0xA5, 0x9D, 0x54, 0xD0, 0xF3, 0xC7, 0x46,
  30229. 0x0E, 0xC1, 0x52, 0x08, 0x34, 0x6B, 0xA5, 0x6D,
  30230. 0xF5, 0x08, 0x6C, 0x5D, 0xBC, 0xC4, 0x1E, 0x0C,
  30231. 0x95, 0xFC, 0xB6, 0x86, 0x1C, 0x2C, 0x0C, 0x32,
  30232. 0xAA, 0xF3, 0x45, 0x4E, 0xFE, 0xE2, 0xFF, 0xBA,
  30233. 0x21, 0x4B, 0x43, 0x0E, 0xF2, 0x48, 0xA5, 0x9B,
  30234. 0x32, 0x44, 0x4D, 0x8D, 0x0D, 0x3D, 0xB8, 0x7C,
  30235. 0x9D, 0x4B, 0x15, 0x36, 0xD1, 0x57, 0x72, 0x8E,
  30236. 0xE7, 0x58, 0x5E, 0xF5, 0x32, 0x77, 0x6A, 0x00,
  30237. 0x3A, 0x02, 0x3C, 0x0A, 0xB0, 0xE9, 0xFF, 0x55,
  30238. 0x71, 0x08, 0xC3, 0x90, 0x68, 0x4D, 0x56, 0x5A,
  30239. 0x66, 0x50, 0x63, 0x26, 0x6A, 0xE6, 0x67, 0x0E,
  30240. 0xD5, 0x3B, 0x0F, 0xAF, 0x8F, 0xF6, 0x78, 0x29,
  30241. 0xBB, 0x73, 0x78, 0x25, 0xB1, 0x53, 0xA9, 0x33,
  30242. 0x8C, 0xBE, 0x3D, 0xF1, 0xA4, 0x62, 0x84, 0x9B,
  30243. 0x93, 0xA8, 0x1F, 0x84, 0xED, 0x07, 0xBE, 0x6D,
  30244. 0x62, 0x40, 0x00, 0x32, 0x74, 0x73, 0x7F, 0x61,
  30245. 0x8D, 0xCB, 0x26, 0xE4, 0x82, 0x52, 0xCE, 0x42,
  30246. 0x04, 0xDD, 0x31, 0x39, 0xFF, 0x68, 0x76, 0xF4,
  30247. 0x3B, 0x30, 0x5D, 0x83, 0x56, 0x20, 0xFE, 0xDF,
  30248. 0x79, 0xAA, 0x67, 0x43, 0x3D, 0xC2, 0x52, 0x87,
  30249. 0x32, 0x0E, 0x99, 0x17, 0x96, 0x7B, 0x70, 0xB2,
  30250. 0xD8, 0x66, 0xD1, 0x7B, 0x69, 0x8B, 0xFF, 0xF2,
  30251. 0xB3, 0xAB, 0x95, 0x14, 0x94, 0x9E, 0x58, 0xB5,
  30252. 0x7C, 0x68, 0xA4, 0x54, 0x12, 0xC1, 0xFC, 0x42,
  30253. 0x1C, 0x76, 0x8B, 0xF5, 0xEE, 0x8A, 0x10, 0xC8,
  30254. 0xAE, 0xF5, 0x69, 0x26, 0xF5, 0x1E, 0xC6, 0x2C,
  30255. 0x11, 0x56, 0x9F, 0x31, 0xAA, 0x51, 0x78, 0x68,
  30256. 0xE5, 0xCA, 0xD8, 0x9E, 0x95, 0x80, 0x66, 0xEB,
  30257. 0x9E, 0xDD, 0x72, 0x71, 0xB3, 0x1C, 0xB4, 0xB1,
  30258. 0xD6, 0xCE, 0x21, 0x12, 0x25, 0xAE, 0xB5, 0xB5,
  30259. 0x7F, 0x74, 0x97, 0x19, 0xDA, 0x07, 0xEC, 0xBE,
  30260. 0xFE, 0x03, 0x88, 0x1D, 0xDE, 0x3D, 0x81, 0xE4,
  30261. 0x13, 0x5F, 0x2D, 0xC8, 0x1A, 0xF7, 0x79, 0x77,
  30262. 0x6C, 0x1B, 0x80, 0x57, 0x16, 0x2A, 0x6C, 0x98,
  30263. 0x2F, 0xBB, 0x4D, 0xA6, 0xA9, 0xAD, 0x28, 0x4A,
  30264. 0xB1, 0x0C, 0x70, 0x02, 0x20, 0x44, 0xF4, 0x6D,
  30265. 0x40, 0x0B, 0xF6, 0xAD, 0x71, 0x82, 0xD1, 0x97,
  30266. 0x78, 0x99, 0x83, 0xBE, 0x99, 0x22, 0x79, 0x79,
  30267. 0xA1, 0x33, 0x4B, 0xA1, 0x49, 0xD8, 0x69, 0xBA,
  30268. 0x1C, 0x40, 0x88, 0x12, 0x34, 0x35, 0xBF, 0x97,
  30269. 0x85, 0x41, 0x35, 0x6D, 0xAF, 0x17, 0x1F, 0x33,
  30270. 0xAD, 0xB1, 0xC9, 0x79, 0x07, 0xA0, 0xFB, 0x58,
  30271. 0x45, 0x07, 0x4A, 0x85, 0xD2, 0x6F, 0x54, 0x61,
  30272. 0x35, 0xAE, 0xD0, 0xF9, 0x1B, 0xE4, 0x53, 0x9C,
  30273. 0x12, 0xBF, 0x94, 0x11, 0xE4, 0xB5, 0x56, 0xF6,
  30274. 0x87, 0xD0, 0x69, 0xDB, 0x6B, 0x21, 0xFE, 0x2B,
  30275. 0x7F, 0x32, 0x18, 0x87, 0x44, 0x8C, 0xEA, 0x55,
  30276. 0xDB, 0x19, 0xFB, 0xB8, 0xB0, 0x48, 0x2A, 0x55,
  30277. 0xAE, 0xC1, 0x67, 0x38, 0xD7, 0x4C, 0xD2, 0x65,
  30278. 0x09, 0x38, 0x36, 0xBE, 0x99, 0xD4, 0xFB, 0x53,
  30279. 0xE9, 0xB0, 0x14, 0xB0, 0x37, 0xCD, 0xBF, 0xE9
  30280. #endif
  30281. };
  30282. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  30283. static const unsigned char dilithium_public_der[] = {
  30284. #ifndef WOLFSSL_NO_ML_DSA_44
  30285. 0x30, 0x82, 0x05, 0x34, 0x30, 0x0d, 0x06, 0x0b,
  30286. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  30287. 0x0c, 0x04, 0x04, 0x03, 0x82, 0x05, 0x21, 0x00,
  30288. 0x0a, 0xf7, 0xc8, 0xa4, 0x96, 0x01, 0xa7, 0xb2,
  30289. 0x2e, 0x4d, 0xc9, 0xd9, 0x1c, 0xa1, 0x86, 0x09,
  30290. 0xce, 0x14, 0x6f, 0xe8, 0x33, 0x3c, 0x7b, 0xdb,
  30291. 0x19, 0x9c, 0x56, 0x39, 0x6a, 0x6c, 0x5d, 0x1f,
  30292. 0xe4, 0x26, 0xcb, 0x16, 0x91, 0x4d, 0xeb, 0x5a,
  30293. 0x36, 0x22, 0xee, 0xda, 0xdf, 0x46, 0x3e, 0xa1,
  30294. 0x4f, 0x9a, 0x30, 0xb5, 0x3f, 0x60, 0xf7, 0x75,
  30295. 0x47, 0xdc, 0x55, 0xf1, 0xbe, 0xbc, 0x87, 0x6c,
  30296. 0x50, 0x7c, 0x21, 0x55, 0x35, 0xad, 0xa7, 0xf9,
  30297. 0x1c, 0xf8, 0xa1, 0x92, 0x79, 0x10, 0x52, 0x7a,
  30298. 0xc3, 0xba, 0xd3, 0x9d, 0xc6, 0x9b, 0xf4, 0xcb,
  30299. 0x1b, 0xa2, 0xde, 0x83, 0x86, 0xa6, 0x35, 0xea,
  30300. 0xf2, 0x8c, 0xdc, 0xba, 0x3e, 0xef, 0x9c, 0xf5,
  30301. 0x8e, 0xc3, 0xb0, 0xc0, 0x5b, 0xcc, 0x35, 0x6a,
  30302. 0x81, 0xe5, 0x17, 0xb3, 0x9a, 0x57, 0xa6, 0x4a,
  30303. 0x87, 0xb1, 0xa7, 0xf5, 0xa2, 0x96, 0x40, 0x8b,
  30304. 0xc1, 0x62, 0xb2, 0xd9, 0x76, 0xe8, 0x51, 0x33,
  30305. 0x44, 0x3d, 0xeb, 0x14, 0x86, 0x88, 0x2c, 0xc1,
  30306. 0x47, 0xba, 0x2b, 0x85, 0x3b, 0x72, 0xcb, 0x9f,
  30307. 0x40, 0xba, 0x19, 0x58, 0xa4, 0x34, 0x0a, 0xd2,
  30308. 0x8c, 0x97, 0xbd, 0x3d, 0x09, 0xb0, 0x4a, 0xeb,
  30309. 0xaa, 0xee, 0x58, 0x1e, 0xc1, 0x19, 0x26, 0x70,
  30310. 0x15, 0xa5, 0x17, 0x7e, 0xd0, 0xa1, 0x08, 0xf9,
  30311. 0x6d, 0xcf, 0x20, 0x62, 0x95, 0x8e, 0x61, 0xf4,
  30312. 0x29, 0x96, 0x6f, 0x38, 0x1c, 0x67, 0xd5, 0xa6,
  30313. 0x4c, 0xf5, 0x1f, 0xda, 0x12, 0x22, 0x24, 0x6b,
  30314. 0x0d, 0xb7, 0x6a, 0xe5, 0xaf, 0x6c, 0x89, 0x52,
  30315. 0xc2, 0x85, 0x85, 0x5f, 0x16, 0x33, 0x0c, 0xc6,
  30316. 0x7a, 0xe0, 0xa8, 0xed, 0x13, 0x58, 0xf3, 0xa0,
  30317. 0x80, 0x42, 0x3c, 0xe3, 0x57, 0xd1, 0xe2, 0x66,
  30318. 0xc4, 0xe0, 0x3d, 0x49, 0x32, 0x21, 0xd9, 0xa1,
  30319. 0x3c, 0x93, 0x0a, 0xf7, 0x5f, 0x34, 0x65, 0xa4,
  30320. 0x30, 0xf9, 0xe7, 0x8a, 0x96, 0x04, 0xdb, 0xc5,
  30321. 0x16, 0x15, 0x10, 0x74, 0x4f, 0xc9, 0x6b, 0x4b,
  30322. 0x66, 0x29, 0xb0, 0xd1, 0x3b, 0xdd, 0x41, 0x0a,
  30323. 0xfe, 0xdf, 0x5f, 0x72, 0x91, 0xbc, 0x99, 0x2f,
  30324. 0x8d, 0x72, 0x3a, 0x4a, 0xde, 0x11, 0x3a, 0x20,
  30325. 0xb2, 0x56, 0xb5, 0x73, 0x89, 0xb4, 0x63, 0x37,
  30326. 0x86, 0xbd, 0x99, 0x8b, 0x03, 0x56, 0x50, 0x21,
  30327. 0x11, 0x78, 0x8c, 0xd5, 0xc1, 0x92, 0x33, 0x72,
  30328. 0x6e, 0x8d, 0x88, 0x2d, 0x10, 0x8f, 0x31, 0xd3,
  30329. 0x23, 0xe5, 0xaa, 0x1f, 0xe1, 0x37, 0xec, 0x34,
  30330. 0x42, 0x30, 0x75, 0xff, 0xb2, 0x1a, 0x8e, 0x29,
  30331. 0x03, 0x4c, 0xfd, 0xdf, 0x53, 0xf2, 0x0b, 0x2d,
  30332. 0xf9, 0x1c, 0x9e, 0xb6, 0x5a, 0x6c, 0x5e, 0x88,
  30333. 0x48, 0x29, 0x89, 0x42, 0xfc, 0x97, 0xfb, 0x27,
  30334. 0x1c, 0x99, 0x2a, 0xbf, 0x7f, 0x04, 0xb2, 0xcd,
  30335. 0xc9, 0x3a, 0x39, 0xfe, 0x4f, 0x47, 0x92, 0x0b,
  30336. 0x85, 0xfc, 0x92, 0x57, 0xc5, 0x0b, 0x23, 0x1f,
  30337. 0x0b, 0x72, 0xb4, 0xde, 0xfe, 0xbe, 0xb7, 0x39,
  30338. 0xb3, 0xd7, 0x48, 0x03, 0xed, 0x76, 0xac, 0x63,
  30339. 0xf7, 0x2a, 0x58, 0xef, 0xdb, 0x63, 0x5a, 0x56,
  30340. 0x68, 0xcc, 0xb2, 0x8b, 0x22, 0xac, 0xdf, 0xc4,
  30341. 0xad, 0x6f, 0xad, 0x24, 0xfd, 0x30, 0xfb, 0xed,
  30342. 0x6e, 0xde, 0x65, 0x2b, 0xb4, 0x57, 0x35, 0x49,
  30343. 0xc1, 0xc9, 0x82, 0xf4, 0x72, 0x69, 0xef, 0x34,
  30344. 0xc0, 0x37, 0x8b, 0x8b, 0xd3, 0xd3, 0x25, 0xcc,
  30345. 0xe5, 0xf5, 0xf6, 0x9c, 0xa3, 0xe7, 0x88, 0xd7,
  30346. 0x55, 0x73, 0x31, 0x4c, 0xb1, 0x7b, 0x64, 0xb3,
  30347. 0x38, 0xde, 0x47, 0x9a, 0xfc, 0xf1, 0xfa, 0xf8,
  30348. 0x6e, 0xc5, 0x95, 0xb9, 0xaf, 0x6a, 0x7a, 0x94,
  30349. 0x80, 0x0d, 0x29, 0x62, 0x99, 0x0a, 0x34, 0xa2,
  30350. 0x8f, 0xa1, 0x5e, 0x98, 0x7c, 0x4e, 0x18, 0xcd,
  30351. 0x63, 0x68, 0x0e, 0xfa, 0x6f, 0x49, 0x01, 0x02,
  30352. 0xcd, 0xf1, 0xc1, 0x09, 0x57, 0xa3, 0x03, 0xec,
  30353. 0x94, 0x36, 0xab, 0xc6, 0x1c, 0xc0, 0x98, 0x22,
  30354. 0x15, 0x5b, 0x5b, 0x61, 0x3c, 0xc2, 0x5b, 0x6f,
  30355. 0x1c, 0x82, 0x41, 0x39, 0x87, 0xde, 0x92, 0xa9,
  30356. 0xe4, 0x12, 0x74, 0x3b, 0x31, 0x36, 0xac, 0x92,
  30357. 0xb0, 0x23, 0x26, 0xfa, 0xd8, 0xa3, 0xe8, 0x84,
  30358. 0xfc, 0x52, 0xc5, 0x7b, 0xd1, 0x4b, 0xe2, 0x1a,
  30359. 0x33, 0xdd, 0x3c, 0xdf, 0x27, 0x50, 0x6f, 0x12,
  30360. 0xd3, 0x17, 0x66, 0xd7, 0x54, 0x33, 0x30, 0x2b,
  30361. 0xe8, 0xd1, 0x1f, 0x2d, 0xf3, 0x37, 0x81, 0xa0,
  30362. 0x3c, 0x21, 0x8c, 0xea, 0x95, 0xa5, 0x5b, 0x3a,
  30363. 0x24, 0xed, 0xf7, 0x67, 0x7b, 0x72, 0x3a, 0xda,
  30364. 0x31, 0xbd, 0xa7, 0x63, 0xa6, 0x6f, 0xf9, 0xdf,
  30365. 0x06, 0x36, 0xb4, 0xe2, 0x35, 0x4b, 0xa5, 0x8e,
  30366. 0x29, 0x8e, 0x6c, 0x02, 0xc5, 0x06, 0x9b, 0x98,
  30367. 0x6e, 0x5e, 0x00, 0x6a, 0x42, 0x09, 0x4b, 0xc3,
  30368. 0x09, 0x37, 0x67, 0x19, 0x58, 0x6d, 0x40, 0x50,
  30369. 0xb0, 0x62, 0x5b, 0xd6, 0x63, 0x7f, 0xed, 0xb0,
  30370. 0x97, 0x80, 0x9e, 0x91, 0x3f, 0x82, 0xfd, 0x83,
  30371. 0x36, 0xce, 0x06, 0xc4, 0xdc, 0xa4, 0x1e, 0x70,
  30372. 0xd4, 0x94, 0xfc, 0x6e, 0x46, 0xa3, 0xc8, 0xed,
  30373. 0x34, 0x0a, 0xb1, 0x9a, 0x66, 0x5d, 0xc0, 0xce,
  30374. 0x73, 0xd3, 0x65, 0xcb, 0xfb, 0x79, 0xdd, 0xf6,
  30375. 0x19, 0xf6, 0xd8, 0xa9, 0xe6, 0x34, 0x15, 0x86,
  30376. 0x7a, 0x30, 0x79, 0xde, 0x2b, 0x06, 0xa4, 0xc0,
  30377. 0xc8, 0xa2, 0xc1, 0x41, 0xb3, 0x4c, 0xf6, 0xdb,
  30378. 0x16, 0xcd, 0xd2, 0x8b, 0xf1, 0x18, 0x5a, 0xc8,
  30379. 0x3e, 0xd9, 0x54, 0x40, 0xd4, 0xce, 0x88, 0xbb,
  30380. 0x66, 0xf1, 0x74, 0x20, 0xa2, 0x3c, 0x31, 0x09,
  30381. 0xba, 0xac, 0x61, 0x15, 0x9f, 0x73, 0x5f, 0xa7,
  30382. 0xe5, 0x0d, 0xb3, 0xab, 0xa2, 0x72, 0x25, 0xc9,
  30383. 0x87, 0x9b, 0x18, 0xdb, 0xff, 0xfb, 0x39, 0x84,
  30384. 0x8d, 0xf8, 0x97, 0x47, 0xab, 0xc4, 0xfb, 0xc2,
  30385. 0xd8, 0xe8, 0xce, 0x6e, 0x65, 0x76, 0x88, 0x4a,
  30386. 0x22, 0x2f, 0xdd, 0x43, 0xa7, 0xc4, 0x8d, 0x32,
  30387. 0x12, 0x75, 0x0b, 0x72, 0xd6, 0xb7, 0x43, 0x84,
  30388. 0xc8, 0x59, 0xa8, 0xb7, 0x8b, 0x84, 0x33, 0x92,
  30389. 0x8f, 0x94, 0xe8, 0xd0, 0xaf, 0x11, 0x35, 0xde,
  30390. 0xb7, 0x63, 0xb8, 0x91, 0x4c, 0x96, 0x4e, 0x9c,
  30391. 0x62, 0x28, 0xa2, 0xbc, 0x0b, 0x90, 0xae, 0x94,
  30392. 0x90, 0xe9, 0x32, 0xeb, 0xe3, 0x77, 0x60, 0x5f,
  30393. 0x87, 0x48, 0x4b, 0xb0, 0x78, 0x0e, 0xe2, 0x85,
  30394. 0x47, 0x06, 0xa4, 0xc9, 0x26, 0xac, 0x8f, 0xe7,
  30395. 0xc2, 0xc7, 0xce, 0xf5, 0xd1, 0x20, 0xa8, 0x56,
  30396. 0xe1, 0x4f, 0x50, 0x90, 0xb3, 0xc1, 0x03, 0x57,
  30397. 0xd3, 0x62, 0x0e, 0x2a, 0xe8, 0x86, 0xf4, 0x94,
  30398. 0x0e, 0xa5, 0x8b, 0x4e, 0x73, 0xa2, 0x76, 0xac,
  30399. 0x00, 0x29, 0xe5, 0x80, 0x26, 0x02, 0x13, 0xd1,
  30400. 0xb2, 0x68, 0x72, 0x23, 0x38, 0x55, 0xfc, 0x4d,
  30401. 0x05, 0x60, 0x49, 0x7b, 0xfb, 0xaa, 0x17, 0x8f,
  30402. 0x26, 0x0a, 0x08, 0x33, 0x8d, 0x7f, 0x4e, 0xe5,
  30403. 0x6e, 0xf8, 0x84, 0x9b, 0x9f, 0xcb, 0xa2, 0x2b,
  30404. 0xfb, 0xaf, 0xad, 0x21, 0xe2, 0x4f, 0x6f, 0x55,
  30405. 0xc1, 0x78, 0x46, 0xe3, 0xb5, 0x63, 0x06, 0x9b,
  30406. 0x93, 0x7d, 0xac, 0xd4, 0xe0, 0x64, 0x01, 0x8d,
  30407. 0xac, 0x30, 0x8b, 0x8b, 0x55, 0xb7, 0x8a, 0x16,
  30408. 0x3f, 0xc9, 0x82, 0x7f, 0xb5, 0x3b, 0x0d, 0xc0,
  30409. 0x46, 0x89, 0x5c, 0x6c, 0x45, 0x21, 0x78, 0xda,
  30410. 0x84, 0x1f, 0xc8, 0xcf, 0xf1, 0x1e, 0x79, 0x71,
  30411. 0x3b, 0xc8, 0xe2, 0x8b, 0x41, 0xfe, 0xaf, 0x2f,
  30412. 0x3b, 0x23, 0x13, 0xc5, 0x46, 0x87, 0xc6, 0x24,
  30413. 0x37, 0x21, 0x68, 0x8a, 0x3e, 0x45, 0x61, 0xf4,
  30414. 0xad, 0xf5, 0x1c, 0x23, 0x45, 0xa3, 0x42, 0xf2,
  30415. 0xa9, 0xac, 0x94, 0x50, 0xc9, 0x3d, 0x5e, 0x70,
  30416. 0x33, 0x2b, 0x78, 0xd1, 0x5c, 0x13, 0x35, 0xe6,
  30417. 0x13, 0x80, 0x5e, 0x55, 0xa7, 0xcc, 0x67, 0xb0,
  30418. 0x6c, 0xfe, 0xa2, 0x24, 0x02, 0x6d, 0xb3, 0xcb,
  30419. 0x9e, 0x94, 0xb3, 0xc6, 0x01, 0xf3, 0x01, 0x3a,
  30420. 0xe4, 0xa7, 0xa3, 0xdf, 0x56, 0x4c, 0x30, 0xce,
  30421. 0xb1, 0xd5, 0x1b, 0x68, 0x9b, 0x75, 0xae, 0xf4,
  30422. 0xb9, 0x2a, 0xe5, 0x8b, 0x7b, 0xe5, 0x99, 0x46,
  30423. 0x5f, 0x29, 0xf6, 0x82, 0xd0, 0x42, 0xb1, 0x45,
  30424. 0x09, 0x16, 0x5b, 0x32, 0x11, 0xca, 0x48, 0xea,
  30425. 0x51, 0x12, 0x0a, 0x9f, 0x6e, 0x3f, 0x74, 0xe6,
  30426. 0xe0, 0xfe, 0xf8, 0xa5, 0xc0, 0xfd, 0x15, 0x6e,
  30427. 0x2b, 0x4a, 0xd5, 0x76, 0xa8, 0x3d, 0xe3, 0x0d,
  30428. 0xfe, 0x44, 0x11, 0x5e, 0x7a, 0xde, 0x12, 0x29,
  30429. 0x5a, 0x5a, 0x25, 0xc0, 0x8e, 0x98, 0xd1, 0x11,
  30430. 0xc8, 0x00, 0x65, 0xb2, 0xf4, 0xd7, 0x56, 0x32,
  30431. 0x46, 0x2b, 0x4f, 0x7e, 0xc3, 0x4e, 0xf1, 0x17,
  30432. 0xff, 0x03, 0x32, 0xae, 0xe3, 0xbe, 0x0b, 0xab,
  30433. 0xfb, 0x43, 0x0f, 0x6d, 0xa5, 0xc6, 0x44, 0xba,
  30434. 0xc9, 0xe3, 0x3d, 0x40, 0xe7, 0x6c, 0xe8, 0x21,
  30435. 0xb2, 0x46, 0x7b, 0x3b, 0x3d, 0xde, 0x80, 0xc8,
  30436. 0xea, 0xf4, 0x6b, 0xf3, 0x53, 0xca, 0x51, 0x84,
  30437. 0xcf, 0xad, 0x7e, 0xce, 0xce, 0xc2, 0x65, 0xfc,
  30438. 0x03, 0x8c, 0xcb, 0xfa, 0xcb, 0x37, 0x89, 0x82,
  30439. 0x59, 0x5e, 0x36, 0x52, 0xe4, 0xbc, 0x8d, 0x47,
  30440. 0x7c, 0xb8, 0x3f, 0x63, 0x59, 0xdc, 0xd3, 0x74,
  30441. 0x11, 0x33, 0xb4, 0x69, 0x74, 0x40, 0x0d, 0x42,
  30442. 0x63, 0x1d, 0xe6, 0x5c, 0x1b, 0xca, 0x41, 0xff,
  30443. 0x23, 0x4e, 0xe8, 0x3d, 0x14, 0xa8, 0x17, 0x18,
  30444. 0xd0, 0x78, 0x08, 0x87, 0x7d, 0x5e, 0xdc, 0x3a,
  30445. 0x07, 0xba, 0x12, 0x8e, 0x8e, 0x56, 0x0a, 0xcb,
  30446. 0x37, 0xf6, 0x54, 0xeb, 0x55, 0x16, 0x8f, 0x06,
  30447. 0x15, 0x28, 0x6b, 0xfb, 0xed, 0x38, 0x9e, 0x9b,
  30448. 0x98, 0x5b, 0xdc, 0x67, 0x33, 0x0e, 0x02, 0x36,
  30449. 0x1b, 0x7a, 0x9a, 0x43, 0xcd, 0xf2, 0x65, 0xef,
  30450. 0x37, 0x19, 0x24, 0x6f, 0x4b, 0xb9, 0x4d, 0x3e,
  30451. 0x0b, 0x47, 0xd1, 0x67, 0x50, 0x6a, 0x7f, 0x07
  30452. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  30453. 0x30, 0x82, 0x07, 0xb4, 0x30, 0x0d, 0x06, 0x0b,
  30454. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  30455. 0x0c, 0x06, 0x05, 0x03, 0x82, 0x07, 0xa1, 0x00,
  30456. 0xff, 0x89, 0xee, 0xad, 0x20, 0x8f, 0x61, 0xa4,
  30457. 0x07, 0x1c, 0x54, 0x98, 0x8c, 0xf4, 0x2e, 0xd9,
  30458. 0xe6, 0x0f, 0xcb, 0x0e, 0xab, 0xa1, 0x37, 0x4d,
  30459. 0xc0, 0x48, 0x24, 0x78, 0xd6, 0x2d, 0x9b, 0x6f,
  30460. 0x0f, 0x17, 0x08, 0x71, 0xc3, 0xd1, 0xc8, 0x7a,
  30461. 0xe7, 0x32, 0xcb, 0xcd, 0xd6, 0xb5, 0x90, 0x08,
  30462. 0xe1, 0xda, 0xaa, 0x89, 0x3e, 0x4a, 0x62, 0x98,
  30463. 0x3d, 0xc6, 0x71, 0x30, 0xb4, 0x63, 0xa5, 0x3b,
  30464. 0xb3, 0x69, 0x75, 0x10, 0xaf, 0x5e, 0x72, 0x78,
  30465. 0xa2, 0xef, 0x63, 0x63, 0x21, 0xe7, 0xf4, 0xa7,
  30466. 0x9c, 0x50, 0x74, 0x14, 0x3e, 0xdd, 0x73, 0x9e,
  30467. 0x97, 0x65, 0xdd, 0xdf, 0x3c, 0x40, 0x4d, 0x03,
  30468. 0x49, 0xe4, 0xbf, 0x65, 0xe7, 0x44, 0x8f, 0x59,
  30469. 0x00, 0xe2, 0x98, 0xb5, 0x66, 0xa3, 0x3b, 0x11,
  30470. 0x9f, 0xc7, 0xc2, 0x16, 0x61, 0xf0, 0x1e, 0x89,
  30471. 0xc8, 0x96, 0x8d, 0x18, 0xac, 0x86, 0xa0, 0xe2,
  30472. 0xd9, 0x8c, 0xef, 0x53, 0x6d, 0x4e, 0x74, 0xc9,
  30473. 0x66, 0x28, 0x16, 0xf3, 0x62, 0xc4, 0x6f, 0x2b,
  30474. 0x6e, 0x36, 0x03, 0xad, 0xc5, 0xe4, 0x8f, 0x0b,
  30475. 0x90, 0x8c, 0x8f, 0xff, 0x5d, 0xdf, 0x7a, 0xe6,
  30476. 0xaf, 0x9a, 0x43, 0xbc, 0xd4, 0x73, 0x22, 0xdc,
  30477. 0x5f, 0x08, 0xa1, 0x17, 0x97, 0x89, 0x79, 0xf5,
  30478. 0xdc, 0xed, 0x4f, 0x85, 0x8e, 0x0c, 0x23, 0x35,
  30479. 0x3c, 0x34, 0x19, 0x65, 0xf5, 0xd6, 0xc9, 0x2d,
  30480. 0x7a, 0x2e, 0x67, 0xd5, 0xf1, 0x82, 0x97, 0xaa,
  30481. 0x05, 0x26, 0x84, 0x25, 0x47, 0x58, 0x2c, 0xe6,
  30482. 0x59, 0xc7, 0x98, 0x7a, 0xdb, 0x40, 0x45, 0x1c,
  30483. 0x71, 0x55, 0x2e, 0xea, 0x3f, 0x6e, 0x7c, 0x82,
  30484. 0x52, 0x6a, 0x19, 0x3a, 0xd3, 0xa1, 0x3c, 0xce,
  30485. 0x00, 0x06, 0xec, 0xed, 0x97, 0xce, 0xd8, 0xdf,
  30486. 0xde, 0xa3, 0xed, 0xe7, 0x81, 0x62, 0x02, 0x9c,
  30487. 0x1b, 0x51, 0xa1, 0xf4, 0x9d, 0x1b, 0x28, 0x76,
  30488. 0x93, 0x96, 0x20, 0x55, 0x60, 0x1f, 0xaf, 0x52,
  30489. 0xc3, 0xce, 0xb9, 0x12, 0x66, 0xf5, 0x64, 0x22,
  30490. 0x87, 0x86, 0x29, 0x80, 0x8f, 0x18, 0x33, 0xba,
  30491. 0x48, 0x71, 0x1d, 0x00, 0xfe, 0xa5, 0xfc, 0xc6,
  30492. 0x87, 0xbe, 0x44, 0x3c, 0xc9, 0x49, 0xfb, 0x68,
  30493. 0x3c, 0xdf, 0xca, 0xef, 0xa7, 0xdc, 0x67, 0xb8,
  30494. 0x28, 0xd6, 0xad, 0x18, 0xaf, 0xad, 0x1f, 0x4c,
  30495. 0x85, 0xa3, 0x64, 0xac, 0x3f, 0xa9, 0x39, 0x28,
  30496. 0xef, 0x8a, 0x45, 0x7e, 0xb0, 0xf4, 0x89, 0x72,
  30497. 0xf7, 0xb1, 0xef, 0x9d, 0x1c, 0x3c, 0x93, 0xcb,
  30498. 0xa0, 0xfb, 0x2a, 0x90, 0xe2, 0x1d, 0x49, 0x8e,
  30499. 0x36, 0xb8, 0x07, 0xf4, 0xb3, 0x09, 0xf0, 0x6f,
  30500. 0x3c, 0xd9, 0x37, 0x19, 0x57, 0xd4, 0x1e, 0x2a,
  30501. 0xa2, 0xa7, 0x2e, 0xc1, 0xcd, 0x8d, 0x48, 0x47,
  30502. 0xb5, 0x8a, 0x12, 0x93, 0x34, 0xb8, 0xec, 0x32,
  30503. 0x07, 0x49, 0xb6, 0x8d, 0x73, 0xd4, 0x2c, 0x6a,
  30504. 0xa0, 0x33, 0x29, 0x21, 0x5d, 0x37, 0xa9, 0x39,
  30505. 0x40, 0xbe, 0x71, 0x29, 0xbe, 0xd1, 0x4b, 0xbc,
  30506. 0x9a, 0x17, 0x93, 0x52, 0xb8, 0x81, 0xee, 0xc5,
  30507. 0xff, 0x25, 0x78, 0x2f, 0x52, 0x0a, 0x8f, 0xb2,
  30508. 0xef, 0xf3, 0x1d, 0x68, 0x56, 0x31, 0x29, 0x84,
  30509. 0x55, 0x47, 0x32, 0x34, 0x0f, 0x60, 0x07, 0xd6,
  30510. 0x2b, 0xb9, 0x29, 0xaf, 0x0f, 0xcd, 0x1c, 0xc0,
  30511. 0x77, 0x4c, 0xc6, 0x31, 0xdb, 0xf4, 0x17, 0xbe,
  30512. 0x3d, 0xf8, 0x8c, 0xf1, 0x02, 0x7c, 0x6b, 0xd4,
  30513. 0xaf, 0x03, 0xb2, 0xf4, 0x78, 0x8d, 0xd3, 0x4e,
  30514. 0x5c, 0x04, 0xb9, 0x01, 0xe3, 0x73, 0xb4, 0x67,
  30515. 0xe9, 0xa8, 0x77, 0x6f, 0x87, 0x2b, 0xe2, 0x00,
  30516. 0x98, 0x5f, 0x02, 0x43, 0x85, 0x03, 0x4c, 0x71,
  30517. 0xd2, 0xe7, 0x61, 0x03, 0x22, 0x9e, 0xe5, 0xc2,
  30518. 0xa7, 0x66, 0x42, 0x7c, 0x9f, 0xf4, 0xb8, 0x6b,
  30519. 0x2d, 0xe4, 0xaa, 0x51, 0xda, 0x08, 0x73, 0x75,
  30520. 0x26, 0x45, 0xdc, 0xa6, 0x20, 0xd7, 0xcb, 0x00,
  30521. 0xfc, 0xe4, 0xdb, 0x28, 0x92, 0xf8, 0xb0, 0xc7,
  30522. 0xf0, 0x4b, 0x6d, 0xe8, 0xc1, 0x84, 0x38, 0xed,
  30523. 0x1a, 0xd4, 0x66, 0x69, 0xc4, 0x96, 0x40, 0xc4,
  30524. 0x7d, 0xfa, 0x58, 0x70, 0x7e, 0x70, 0x40, 0xba,
  30525. 0xfc, 0x95, 0xb6, 0x4c, 0x7c, 0x58, 0xbc, 0xb3,
  30526. 0x59, 0x08, 0x14, 0x03, 0x35, 0xf3, 0xf1, 0xaa,
  30527. 0xd5, 0xa2, 0x57, 0x70, 0xb6, 0x20, 0x75, 0x0a,
  30528. 0x58, 0x66, 0x74, 0xf7, 0x1c, 0xfd, 0x99, 0x7c,
  30529. 0x20, 0xda, 0xe7, 0x76, 0xcb, 0xf4, 0xa3, 0x9b,
  30530. 0xbc, 0x8f, 0x74, 0xef, 0xe2, 0x46, 0x5a, 0x72,
  30531. 0x33, 0x06, 0x32, 0x1e, 0xbd, 0x4e, 0x4c, 0xf6,
  30532. 0x16, 0x43, 0xa5, 0xa5, 0xa5, 0x6c, 0x76, 0x33,
  30533. 0x35, 0x63, 0xdc, 0xe4, 0xec, 0x7f, 0x8a, 0xfa,
  30534. 0xc3, 0x53, 0x69, 0x28, 0xf7, 0xd6, 0x97, 0xb9,
  30535. 0x3a, 0xf4, 0x15, 0x90, 0x50, 0xd3, 0xdf, 0xf5,
  30536. 0xd3, 0xcf, 0x15, 0x76, 0xe3, 0x3d, 0x24, 0x14,
  30537. 0xfd, 0xd3, 0x01, 0x25, 0x82, 0xb4, 0xe3, 0xd8,
  30538. 0x68, 0x89, 0x86, 0xa8, 0x26, 0x02, 0x5f, 0xc6,
  30539. 0xf4, 0x99, 0x3b, 0x97, 0xa8, 0x65, 0xed, 0x18,
  30540. 0xbb, 0x3c, 0x43, 0x4a, 0x6e, 0xaa, 0xbc, 0x83,
  30541. 0x85, 0x19, 0x9f, 0x9b, 0xb8, 0xa4, 0xa3, 0xb2,
  30542. 0xb7, 0x56, 0x07, 0x6c, 0xbf, 0x7d, 0xff, 0x5d,
  30543. 0xb5, 0x1e, 0x83, 0xc8, 0x74, 0x70, 0x98, 0x17,
  30544. 0x40, 0xe0, 0x2d, 0xad, 0x31, 0x00, 0x8e, 0x42,
  30545. 0xd5, 0xb2, 0x25, 0xaa, 0x82, 0xaf, 0x33, 0xd8,
  30546. 0x5b, 0xe2, 0x07, 0xed, 0xda, 0x84, 0xe9, 0xa2,
  30547. 0xff, 0xbb, 0xa5, 0x47, 0x95, 0x6e, 0xa1, 0x8d,
  30548. 0x59, 0x52, 0xeb, 0xf3, 0x3c, 0x18, 0x29, 0x92,
  30549. 0x72, 0x27, 0x18, 0xfc, 0x95, 0xb9, 0xde, 0x46,
  30550. 0xda, 0xcc, 0x4c, 0x31, 0x1d, 0x78, 0x86, 0xd2,
  30551. 0x8c, 0x38, 0x9c, 0x32, 0xab, 0xf7, 0xca, 0x73,
  30552. 0x85, 0xa5, 0xf1, 0xe0, 0x25, 0x06, 0xf9, 0x18,
  30553. 0x14, 0xab, 0x3b, 0x73, 0x26, 0xee, 0xa0, 0xfd,
  30554. 0x15, 0xac, 0xd6, 0x4e, 0x6b, 0xdb, 0x01, 0xa1,
  30555. 0xdc, 0xd1, 0x2f, 0xd2, 0xb7, 0x5e, 0x12, 0x4f,
  30556. 0x4b, 0x59, 0xd8, 0x03, 0x12, 0x60, 0xc9, 0x81,
  30557. 0xb7, 0x06, 0x23, 0x09, 0xc4, 0xd9, 0xa8, 0x93,
  30558. 0x6e, 0x96, 0xf4, 0x93, 0x53, 0xf0, 0x3d, 0xde,
  30559. 0x10, 0x88, 0xb1, 0xd0, 0xcc, 0xad, 0x2c, 0xbf,
  30560. 0x88, 0x98, 0x8f, 0x25, 0x76, 0xd7, 0x65, 0x77,
  30561. 0xcc, 0x36, 0x1d, 0x1b, 0x6b, 0x60, 0x58, 0xc4,
  30562. 0xfe, 0xe6, 0xca, 0xa8, 0x29, 0x33, 0x69, 0x36,
  30563. 0xb8, 0x12, 0x95, 0x38, 0xd9, 0xd4, 0x16, 0xe9,
  30564. 0x3e, 0x40, 0x8c, 0xc7, 0xae, 0x04, 0x11, 0xdf,
  30565. 0x51, 0xd3, 0xdd, 0xbf, 0xa9, 0x41, 0x43, 0x4c,
  30566. 0xff, 0x87, 0x2f, 0xea, 0x0f, 0x13, 0x66, 0x2a,
  30567. 0x2b, 0x18, 0xe8, 0xc4, 0xff, 0xa0, 0x1c, 0x78,
  30568. 0x79, 0x21, 0xf8, 0xaa, 0x8a, 0xf8, 0x92, 0xdf,
  30569. 0x7b, 0x5f, 0x6a, 0x71, 0x60, 0x67, 0x5d, 0x94,
  30570. 0xf6, 0xbb, 0x1d, 0x90, 0x7c, 0x51, 0x70, 0x1d,
  30571. 0x87, 0xde, 0xf8, 0x91, 0xcb, 0x42, 0x9f, 0xc7,
  30572. 0x4b, 0xa0, 0x16, 0xee, 0xb4, 0x73, 0xe8, 0xe0,
  30573. 0x0b, 0xa5, 0xd3, 0x26, 0x9e, 0x52, 0xda, 0x4a,
  30574. 0x1f, 0xae, 0x76, 0xbf, 0xbb, 0x4d, 0x74, 0x98,
  30575. 0xa6, 0xae, 0xc0, 0x60, 0x96, 0xc5, 0xad, 0x9b,
  30576. 0x91, 0x31, 0xb9, 0x50, 0x3d, 0x9a, 0x0f, 0xe1,
  30577. 0x93, 0xef, 0x08, 0x72, 0xb2, 0x66, 0xe5, 0x5d,
  30578. 0xe4, 0x15, 0x53, 0x8e, 0xb0, 0xb3, 0xf8, 0x78,
  30579. 0xfc, 0x5d, 0x44, 0xc5, 0xbf, 0xf5, 0x01, 0x54,
  30580. 0xc5, 0x45, 0xa9, 0x30, 0xa4, 0xf1, 0x49, 0x79,
  30581. 0x4e, 0xab, 0xfc, 0xb2, 0x93, 0xe7, 0x3a, 0xe1,
  30582. 0x7f, 0x1f, 0x2f, 0x45, 0x3a, 0x53, 0x2b, 0x68,
  30583. 0xb3, 0xa4, 0xac, 0x23, 0x54, 0xb7, 0x5d, 0x25,
  30584. 0xa3, 0xe3, 0x90, 0x8a, 0xb0, 0x02, 0xfb, 0x7f,
  30585. 0x2d, 0xeb, 0x80, 0xc2, 0x5c, 0x62, 0xe1, 0x36,
  30586. 0x5a, 0x82, 0x8f, 0x4e, 0x74, 0xeb, 0x7d, 0x70,
  30587. 0xaf, 0x23, 0x92, 0x65, 0x3a, 0x11, 0xc0, 0x29,
  30588. 0xdb, 0xf7, 0x9a, 0xdc, 0x81, 0x45, 0x25, 0x0c,
  30589. 0x2e, 0x4f, 0x88, 0x41, 0x34, 0x53, 0xc6, 0x08,
  30590. 0x21, 0x77, 0xc1, 0xbb, 0x61, 0x48, 0x20, 0x69,
  30591. 0x1a, 0xbb, 0x71, 0x1b, 0x56, 0x18, 0x79, 0x75,
  30592. 0x16, 0x9a, 0xb3, 0x79, 0x31, 0x11, 0xa2, 0x89,
  30593. 0x8d, 0xea, 0x10, 0xb0, 0x04, 0x7f, 0xf8, 0x6e,
  30594. 0xdc, 0x08, 0x9b, 0x51, 0xa7, 0x64, 0xbd, 0x8d,
  30595. 0xd4, 0xd0, 0x1e, 0x38, 0x50, 0x1a, 0xa8, 0x7e,
  30596. 0x20, 0xae, 0xee, 0x8c, 0xa7, 0x72, 0x94, 0xc9,
  30597. 0xba, 0xf0, 0x67, 0xbd, 0x25, 0x1a, 0x3a, 0xdf,
  30598. 0x75, 0x39, 0xb7, 0xd3, 0x83, 0x3b, 0x89, 0xdf,
  30599. 0xb5, 0x2d, 0xd3, 0x12, 0x24, 0x21, 0x7c, 0x9e,
  30600. 0x92, 0x1c, 0x19, 0xae, 0x28, 0xcb, 0x2e, 0x2e,
  30601. 0x3c, 0xa9, 0x9b, 0xbd, 0xf9, 0x33, 0x30, 0xb2,
  30602. 0xbd, 0x8b, 0xbf, 0xc1, 0x8b, 0x32, 0xf1, 0x20,
  30603. 0xa1, 0x00, 0xfd, 0x11, 0x7d, 0x9a, 0xa8, 0x14,
  30604. 0x2c, 0xce, 0x16, 0x16, 0x4b, 0xdd, 0x56, 0x91,
  30605. 0x15, 0x36, 0x83, 0xcb, 0x01, 0x58, 0x35, 0xe1,
  30606. 0xdc, 0x22, 0x3d, 0xf8, 0xc2, 0x06, 0x54, 0x68,
  30607. 0x77, 0xd1, 0x47, 0x28, 0xdc, 0x09, 0x2a, 0x86,
  30608. 0x13, 0x80, 0xa6, 0xe9, 0xd0, 0xb4, 0xa3, 0x41,
  30609. 0x47, 0xf4, 0x71, 0x24, 0x10, 0x4c, 0x9f, 0xb7,
  30610. 0x57, 0x34, 0x48, 0x1b, 0xb4, 0xed, 0x0e, 0x89,
  30611. 0x4c, 0xf1, 0x73, 0x44, 0xff, 0x35, 0xb6, 0xe0,
  30612. 0x8f, 0x02, 0xa3, 0xa3, 0x81, 0x55, 0x38, 0xb5,
  30613. 0xc1, 0x99, 0xb3, 0x88, 0x84, 0x0d, 0xd9, 0x73,
  30614. 0x77, 0x65, 0x0b, 0xd7, 0xf8, 0x03, 0x88, 0xcb,
  30615. 0xdf, 0x25, 0xaf, 0xc6, 0xf1, 0xfa, 0x5c, 0x4d,
  30616. 0xfa, 0xc3, 0x7b, 0x8f, 0xb8, 0x38, 0x5d, 0x29,
  30617. 0xbb, 0x3d, 0x3e, 0x62, 0x1c, 0xdd, 0xe6, 0x97,
  30618. 0xe6, 0xe9, 0xbe, 0x6e, 0xd2, 0xb7, 0x7a, 0x9a,
  30619. 0x8e, 0xaf, 0xb3, 0xc8, 0x9e, 0x19, 0xee, 0x3d,
  30620. 0x5b, 0x1f, 0xec, 0x34, 0x3a, 0x1c, 0x27, 0x90,
  30621. 0xbd, 0x1e, 0x49, 0x72, 0x25, 0x2e, 0x38, 0x48,
  30622. 0x7d, 0xe1, 0x85, 0x46, 0xa7, 0x1b, 0x4a, 0xd5,
  30623. 0x23, 0x75, 0x6d, 0x8b, 0xc3, 0xf1, 0x87, 0xec,
  30624. 0x8b, 0x45, 0xf0, 0x9b, 0xb2, 0x14, 0x7a, 0x7c,
  30625. 0x8d, 0x78, 0x9c, 0x82, 0x64, 0x14, 0xfe, 0x01,
  30626. 0xfa, 0x04, 0x33, 0x96, 0xdd, 0x5f, 0x56, 0xbc,
  30627. 0xb2, 0x03, 0xe3, 0x0c, 0xa1, 0x09, 0x66, 0xa0,
  30628. 0x5e, 0x44, 0xde, 0x21, 0xae, 0x7d, 0x7a, 0x0e,
  30629. 0x81, 0x27, 0xd2, 0xfb, 0x85, 0xed, 0x27, 0x27,
  30630. 0xac, 0x11, 0x1c, 0xa1, 0x6d, 0xe9, 0xc1, 0xca,
  30631. 0xf6, 0x40, 0x7c, 0x95, 0x01, 0xb7, 0xa8, 0x29,
  30632. 0x9a, 0xd2, 0xcc, 0x62, 0x70, 0x1c, 0x7d, 0x0e,
  30633. 0xe5, 0x60, 0xcb, 0x79, 0xa3, 0xd7, 0x5d, 0x48,
  30634. 0x4b, 0x3c, 0xf8, 0x12, 0xe8, 0x7a, 0x7e, 0x83,
  30635. 0xab, 0x24, 0x33, 0x0f, 0x7b, 0x0a, 0x38, 0xae,
  30636. 0xb1, 0xfc, 0xc3, 0x50, 0x5c, 0x83, 0x53, 0xfd,
  30637. 0x15, 0xd6, 0x49, 0x54, 0xb6, 0x40, 0xe5, 0xe8,
  30638. 0x55, 0xba, 0x08, 0x2f, 0x21, 0xd7, 0x0e, 0x71,
  30639. 0x8a, 0xb2, 0xe1, 0x6b, 0xc6, 0x7e, 0x0f, 0x1c,
  30640. 0x4d, 0x41, 0x9f, 0x38, 0xc2, 0xce, 0x41, 0x41,
  30641. 0x48, 0xcd, 0xec, 0x16, 0x1d, 0x23, 0x8e, 0x41,
  30642. 0xcd, 0x5e, 0xf9, 0x5f, 0x01, 0x5e, 0x73, 0xa2,
  30643. 0xa1, 0xef, 0xe9, 0x57, 0xe0, 0xba, 0xe6, 0xbb,
  30644. 0x2b, 0xff, 0x3e, 0xb8, 0xad, 0xd5, 0x12, 0xc1,
  30645. 0x54, 0x49, 0xca, 0x93, 0xb0, 0x7d, 0x7b, 0xcf,
  30646. 0xf0, 0xc5, 0x94, 0x43, 0x30, 0x94, 0x11, 0x8d,
  30647. 0x15, 0x79, 0x2e, 0x57, 0xb8, 0x24, 0xcd, 0x2e,
  30648. 0xc2, 0x49, 0x3d, 0x92, 0x44, 0x23, 0x0c, 0x3e,
  30649. 0xa0, 0xf9, 0xa5, 0xad, 0x2a, 0x56, 0xec, 0xf4,
  30650. 0x6d, 0x0f, 0x5b, 0xb5, 0xd4, 0x2a, 0x3f, 0x2b,
  30651. 0x17, 0x9f, 0x5d, 0x33, 0x97, 0x42, 0xd4, 0x1e,
  30652. 0x14, 0x49, 0x01, 0xfb, 0xb6, 0x72, 0xbc, 0x14,
  30653. 0x5b, 0x79, 0xf4, 0x0a, 0xc5, 0x49, 0xe1, 0x76,
  30654. 0x44, 0x78, 0x87, 0xd1, 0x8e, 0x5b, 0xd5, 0x95,
  30655. 0xad, 0x19, 0x7c, 0x0d, 0x39, 0x7f, 0x41, 0x2e,
  30656. 0xd7, 0x9e, 0xbc, 0xfd, 0x2c, 0xde, 0xfa, 0x01,
  30657. 0x7d, 0x2b, 0x04, 0xef, 0x4d, 0xf9, 0xf4, 0x5b,
  30658. 0xed, 0x05, 0x9a, 0x50, 0x35, 0xe7, 0xb0, 0xba,
  30659. 0x24, 0xea, 0x16, 0x51, 0xe1, 0x6f, 0x32, 0x08,
  30660. 0x94, 0xd6, 0x19, 0x9d, 0x0e, 0x4c, 0xc1, 0xbb,
  30661. 0x01, 0x87, 0xa5, 0x90, 0x5f, 0x6f, 0xc4, 0xed,
  30662. 0xa1, 0x4c, 0x06, 0x4d, 0x2c, 0x47, 0x24, 0xda,
  30663. 0xae, 0xd2, 0x41, 0x92, 0x1f, 0x46, 0xce, 0xec,
  30664. 0xb1, 0xcc, 0x80, 0x1e, 0xb2, 0xcb, 0x66, 0x48,
  30665. 0x22, 0xec, 0x0e, 0x47, 0xfc, 0xad, 0x17, 0xfe,
  30666. 0x7b, 0xc5, 0x4d, 0x34, 0x95, 0x40, 0xd0, 0x02,
  30667. 0x7e, 0x90, 0xaa, 0x92, 0xaf, 0x48, 0x64, 0xc5,
  30668. 0xc1, 0x56, 0xd8, 0x9b, 0x6c, 0x5f, 0x2e, 0xfa,
  30669. 0xd7, 0x84, 0xdc, 0x71, 0x65, 0x1b, 0xfb, 0xbc,
  30670. 0x21, 0xc7, 0x57, 0xf4, 0x71, 0x2e, 0x6f, 0x34,
  30671. 0x85, 0x99, 0xa8, 0x5c, 0x6f, 0x34, 0x22, 0x44,
  30672. 0x89, 0x01, 0xf9, 0x48, 0xd2, 0xe2, 0xe4, 0x71,
  30673. 0x9d, 0x48, 0x07, 0x97, 0xd4, 0x66, 0xe4, 0x4d,
  30674. 0x48, 0xa3, 0x08, 0x7f, 0x6e, 0xaa, 0x7b, 0xe9,
  30675. 0x93, 0x81, 0x03, 0x0c, 0xd2, 0x48, 0xcf, 0x3f,
  30676. 0x5f, 0xbe, 0x03, 0xfb, 0x0f, 0xad, 0xc3, 0x81,
  30677. 0xd9, 0xce, 0x88, 0x0b, 0xfa, 0xed, 0x29, 0x7e,
  30678. 0x0b, 0xa1, 0x6f, 0x4c, 0x7d, 0xe4, 0x36, 0xff,
  30679. 0xdf, 0x94, 0x1a, 0x24, 0xb3, 0x7b, 0xca, 0x24,
  30680. 0x7e, 0x3a, 0x19, 0x53, 0x13, 0x4a, 0x17, 0x58,
  30681. 0xe7, 0x16, 0x9b, 0x50, 0xd8, 0xda, 0xcc, 0x6e,
  30682. 0x05, 0x25, 0xfe, 0x16, 0xcb, 0x5b, 0xd5, 0x35,
  30683. 0x76, 0x40, 0x44, 0x96, 0x23, 0x97, 0xe2, 0x4a,
  30684. 0x72, 0x0c, 0x54, 0x43, 0xc0, 0x09, 0x85, 0x8e,
  30685. 0x15, 0x85, 0xaf, 0x3c, 0x5e, 0x5f, 0x3c, 0x2d,
  30686. 0x21, 0x42, 0x75, 0xb7, 0xe4, 0x50, 0xf9, 0x00,
  30687. 0xa3, 0x4f, 0xb1, 0x7c, 0xfe, 0x62, 0xd0, 0xe9,
  30688. 0x6d, 0x51, 0xcc, 0x83, 0xc1, 0xdc, 0x37, 0x10,
  30689. 0x90, 0x0a, 0x15, 0xd8, 0xd5, 0x02, 0xf7, 0x74,
  30690. 0xb8, 0x46, 0x84, 0xc3, 0x61, 0x17, 0x26, 0x0f,
  30691. 0xe4, 0xde, 0x1a, 0xcf, 0x42, 0x53, 0x63, 0x2f,
  30692. 0x8d, 0xf7, 0x06, 0x07, 0xc3, 0x33, 0x39, 0x59,
  30693. 0xe9, 0x17, 0xc8, 0x05, 0xd2, 0xa2, 0xae, 0x53,
  30694. 0x2c, 0x7e, 0xd0, 0x9d, 0x5c, 0xb5, 0x42, 0x9f,
  30695. 0x84, 0xd7, 0xfe, 0x93, 0x74, 0xfb, 0xbb, 0xd2,
  30696. 0x1e, 0x57, 0x4e, 0x7f, 0x79, 0xaf, 0xd2, 0xf9,
  30697. 0x5e, 0x41, 0x9e, 0x63, 0x54, 0x61, 0x47, 0x0c,
  30698. 0x92, 0x4c, 0xc9, 0xfe, 0x4f, 0xcb, 0xe5, 0x8e,
  30699. 0x65, 0xb3, 0x97, 0x1b, 0xd8, 0xd1, 0x62, 0xfd
  30700. #else
  30701. 0x30, 0x82, 0x0a, 0x34, 0x30, 0x0d, 0x06, 0x0b,
  30702. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  30703. 0x0c, 0x08, 0x07, 0x03, 0x82, 0x0a, 0x21, 0x00,
  30704. 0x7f, 0x5f, 0x63, 0x81, 0x6f, 0x04, 0x4c, 0xec,
  30705. 0xa8, 0xaf, 0x7b, 0x99, 0x41, 0xc6, 0xff, 0xdf,
  30706. 0x77, 0x66, 0x28, 0xc0, 0xe2, 0x58, 0xea, 0x9c,
  30707. 0x60, 0xbb, 0x03, 0x3e, 0xca, 0xa8, 0x38, 0x64,
  30708. 0xfb, 0xf7, 0x1b, 0x3f, 0xec, 0xfd, 0x0f, 0xf1,
  30709. 0x9c, 0xe4, 0xfd, 0xad, 0x83, 0xf7, 0x03, 0x66,
  30710. 0x6e, 0x7f, 0x4d, 0x42, 0xab, 0x6b, 0x73, 0x26,
  30711. 0xde, 0x6f, 0x8c, 0xc4, 0xca, 0x21, 0x66, 0x31,
  30712. 0x79, 0x57, 0x88, 0xcb, 0x1e, 0xab, 0xda, 0x1d,
  30713. 0x56, 0x70, 0xd9, 0x83, 0xa1, 0xb4, 0x83, 0xce,
  30714. 0xcc, 0x0f, 0xeb, 0xd6, 0x63, 0xbd, 0xf6, 0x02,
  30715. 0x5d, 0x5b, 0x0c, 0x17, 0x3c, 0x3e, 0x15, 0x02,
  30716. 0x22, 0xa1, 0x5d, 0xb5, 0xc5, 0x81, 0x28, 0x95,
  30717. 0x0b, 0x34, 0x2b, 0x96, 0x0a, 0xae, 0x6a, 0xa8,
  30718. 0xb5, 0x1d, 0x56, 0xbb, 0x7d, 0x83, 0x9a, 0x15,
  30719. 0xad, 0x63, 0x9e, 0x86, 0x8c, 0x6e, 0x6a, 0xa8,
  30720. 0xde, 0x55, 0xd0, 0xce, 0xc0, 0x2e, 0x05, 0xfe,
  30721. 0x1f, 0x4d, 0xd7, 0x12, 0xa4, 0x5a, 0xe9, 0x04,
  30722. 0x0d, 0x20, 0x84, 0x90, 0xb9, 0xca, 0x64, 0xe4,
  30723. 0xad, 0x2e, 0x74, 0x4b, 0x1d, 0x2f, 0xcc, 0xac,
  30724. 0xd8, 0x1a, 0x5e, 0xb2, 0x78, 0xbe, 0x61, 0xf7,
  30725. 0x36, 0xa3, 0xd1, 0x93, 0x86, 0xb5, 0x15, 0xf1,
  30726. 0x74, 0xf8, 0x9f, 0x6d, 0x6a, 0x8f, 0x6d, 0x86,
  30727. 0x8b, 0x36, 0x61, 0x10, 0xc9, 0x1a, 0x31, 0x39,
  30728. 0x09, 0xe6, 0x15, 0xa0, 0xb1, 0xfa, 0x69, 0xd4,
  30729. 0xc2, 0xb2, 0x56, 0x4c, 0x06, 0x33, 0x13, 0xc4,
  30730. 0x78, 0x53, 0x16, 0xfc, 0x52, 0x99, 0xe6, 0x27,
  30731. 0xc9, 0x3b, 0x24, 0x5c, 0x3e, 0x85, 0x73, 0x76,
  30732. 0x61, 0xa3, 0x61, 0xf0, 0x95, 0xd5, 0xb2, 0xf5,
  30733. 0x21, 0xe7, 0x09, 0xc3, 0x0c, 0x5c, 0xb0, 0x36,
  30734. 0xce, 0x45, 0x68, 0x41, 0x45, 0xcb, 0x1c, 0x36,
  30735. 0x2f, 0x3a, 0x00, 0x07, 0x56, 0xbe, 0x61, 0xd2,
  30736. 0x77, 0x37, 0x63, 0xa4, 0xdb, 0xfa, 0xa9, 0x6b,
  30737. 0x37, 0x90, 0x35, 0xd1, 0x1e, 0x27, 0x5b, 0x3e,
  30738. 0xc0, 0x0a, 0x02, 0x64, 0xe4, 0x58, 0x49, 0xab,
  30739. 0x2d, 0xc1, 0x38, 0x29, 0x3d, 0x44, 0xf9, 0xac,
  30740. 0xb7, 0x65, 0xd1, 0x5f, 0xf8, 0xce, 0x52, 0x76,
  30741. 0x22, 0x15, 0x61, 0x02, 0x1f, 0xa7, 0xcd, 0xff,
  30742. 0xeb, 0xa6, 0x7f, 0x6b, 0xba, 0x75, 0xe3, 0x09,
  30743. 0x01, 0x06, 0x41, 0x20, 0x88, 0x75, 0x64, 0x6b,
  30744. 0x97, 0x38, 0x13, 0xab, 0x4c, 0x0a, 0xd4, 0x7e,
  30745. 0xd2, 0xfa, 0x78, 0xe8, 0x9f, 0x5d, 0xf9, 0x53,
  30746. 0x30, 0x17, 0xf1, 0x10, 0x9e, 0x4a, 0x32, 0x17,
  30747. 0x3a, 0x9b, 0xb9, 0x25, 0x8e, 0xeb, 0xd9, 0x41,
  30748. 0x01, 0xa2, 0xc6, 0x58, 0x4a, 0x9f, 0xc3, 0x73,
  30749. 0xfd, 0xe2, 0xe4, 0x2c, 0x92, 0xb4, 0xa2, 0x3d,
  30750. 0x0f, 0x1f, 0x37, 0x64, 0xf1, 0x17, 0x2a, 0x8c,
  30751. 0xc6, 0xb5, 0xb0, 0x69, 0x7d, 0xfe, 0x08, 0xe0,
  30752. 0x8e, 0xaa, 0xe0, 0x08, 0xd5, 0x28, 0x92, 0x51,
  30753. 0x73, 0x8a, 0x2f, 0x7a, 0x4a, 0xbf, 0x52, 0x8d,
  30754. 0x3e, 0x9b, 0x36, 0x6a, 0xfb, 0x19, 0xf0, 0xea,
  30755. 0xfe, 0x05, 0xbd, 0x2d, 0xa9, 0x58, 0x48, 0x02,
  30756. 0xa8, 0x20, 0x9e, 0xdc, 0x04, 0x57, 0xc2, 0x0c,
  30757. 0xae, 0xc1, 0x03, 0xe7, 0x17, 0x48, 0x80, 0x00,
  30758. 0x8d, 0x1b, 0xd0, 0xc5, 0xdc, 0x2a, 0x02, 0x6e,
  30759. 0x8e, 0x54, 0xf3, 0x79, 0x31, 0x02, 0x93, 0xc5,
  30760. 0xf2, 0x55, 0xea, 0x61, 0xd0, 0xb2, 0x8e, 0xc9,
  30761. 0x74, 0x17, 0x0d, 0x38, 0xf8, 0xab, 0xf4, 0x42,
  30762. 0xd4, 0xc2, 0xdc, 0xf7, 0x1b, 0xdb, 0x65, 0x36,
  30763. 0x9f, 0x56, 0xe2, 0xeb, 0xf7, 0xe5, 0x2d, 0x45,
  30764. 0xae, 0xc0, 0x95, 0xbc, 0xe4, 0x1f, 0x22, 0xdc,
  30765. 0x0f, 0x54, 0xed, 0x14, 0xb8, 0xf1, 0x2f, 0x5d,
  30766. 0xd1, 0x79, 0xa0, 0x81, 0x17, 0x71, 0xa1, 0xd6,
  30767. 0xf0, 0x88, 0x9c, 0x1c, 0xc7, 0x95, 0x07, 0xb0,
  30768. 0xea, 0xf7, 0xd3, 0xa2, 0x55, 0xfe, 0x85, 0x65,
  30769. 0x42, 0x06, 0xec, 0xd2, 0xbe, 0x03, 0x8f, 0x63,
  30770. 0x84, 0x4b, 0xb1, 0x47, 0x48, 0x20, 0x71, 0xd2,
  30771. 0xdf, 0xc9, 0x59, 0xb0, 0x24, 0x8a, 0x6e, 0xf9,
  30772. 0x4a, 0xa1, 0x7b, 0xed, 0x11, 0xb6, 0xf9, 0x9b,
  30773. 0xf7, 0x93, 0x0e, 0xcb, 0x7a, 0x32, 0x22, 0x23,
  30774. 0x4e, 0x86, 0xce, 0xad, 0x9d, 0x1b, 0x84, 0x57,
  30775. 0xaf, 0xa5, 0x04, 0x03, 0x0a, 0xc9, 0x04, 0x97,
  30776. 0xd0, 0xce, 0x8e, 0x2a, 0x9a, 0x00, 0x15, 0xeb,
  30777. 0xac, 0x96, 0x57, 0xde, 0xe6, 0xc1, 0x2d, 0xbd,
  30778. 0xfc, 0xd6, 0x95, 0x0f, 0x5f, 0x19, 0xac, 0xaf,
  30779. 0x6c, 0xd8, 0xa6, 0x1e, 0xd8, 0xdb, 0x14, 0xfd,
  30780. 0xba, 0x0f, 0xd0, 0x3f, 0x61, 0xe3, 0x76, 0xfc,
  30781. 0x47, 0x61, 0x07, 0x24, 0x49, 0x17, 0xca, 0x24,
  30782. 0x31, 0x16, 0x26, 0x4f, 0xdc, 0x2b, 0x39, 0xae,
  30783. 0x5f, 0xfa, 0x4f, 0x82, 0xef, 0xe1, 0x41, 0x8c,
  30784. 0x3e, 0x8e, 0xa7, 0x6c, 0xf2, 0x51, 0xf7, 0x85,
  30785. 0x35, 0x6c, 0xad, 0xea, 0x32, 0x35, 0xf3, 0xc0,
  30786. 0x14, 0x17, 0xe2, 0x98, 0x27, 0x36, 0x7e, 0x60,
  30787. 0x2f, 0x01, 0x60, 0x3e, 0x18, 0xf4, 0x4e, 0xe0,
  30788. 0xf5, 0x14, 0x21, 0x81, 0x05, 0x78, 0x1c, 0x5f,
  30789. 0x4e, 0x89, 0xbb, 0x23, 0x60, 0xb1, 0x8f, 0x07,
  30790. 0x53, 0x16, 0x6e, 0xfb, 0x86, 0x07, 0x90, 0xff,
  30791. 0xa6, 0x27, 0x60, 0xe6, 0x3e, 0x92, 0x2a, 0x3c,
  30792. 0xa3, 0x57, 0xec, 0x97, 0x23, 0xaf, 0xd2, 0x44,
  30793. 0xac, 0x09, 0x87, 0xb0, 0x54, 0xe9, 0x5b, 0x50,
  30794. 0x37, 0xfa, 0x12, 0xa4, 0xcb, 0x6f, 0xed, 0x9f,
  30795. 0x29, 0x73, 0xa7, 0x09, 0x29, 0x91, 0x93, 0x5c,
  30796. 0x54, 0xf4, 0x44, 0xc2, 0x04, 0x64, 0xfc, 0xd2,
  30797. 0xf2, 0x0a, 0x0b, 0x45, 0x1f, 0xc5, 0x18, 0xf0,
  30798. 0xff, 0x10, 0x1f, 0x3a, 0x97, 0xf8, 0xb1, 0x83,
  30799. 0x0e, 0x08, 0xe2, 0x55, 0x75, 0x6a, 0x45, 0x96,
  30800. 0xf8, 0x1b, 0xdc, 0xb6, 0x57, 0x83, 0x8c, 0x28,
  30801. 0xc0, 0x4a, 0x57, 0xc6, 0xfb, 0x27, 0x3d, 0xfa,
  30802. 0x5a, 0x0d, 0x69, 0x56, 0x23, 0x66, 0x02, 0x78,
  30803. 0xca, 0xf1, 0xfa, 0xcb, 0xc1, 0xf6, 0x92, 0x1c,
  30804. 0xa0, 0xe3, 0x09, 0x7d, 0x48, 0x5e, 0x86, 0xa0,
  30805. 0x82, 0xa8, 0xf1, 0x1e, 0xe1, 0xfe, 0xc6, 0x9d,
  30806. 0x4f, 0x2e, 0xf4, 0xfc, 0xc6, 0x48, 0x1d, 0xc1,
  30807. 0x2a, 0x6a, 0xb7, 0xea, 0x46, 0x89, 0x04, 0xe9,
  30808. 0xbd, 0xf1, 0xed, 0x16, 0x76, 0xd8, 0x4b, 0x42,
  30809. 0xd5, 0x43, 0xa4, 0xfb, 0x02, 0x01, 0x54, 0x00,
  30810. 0xaf, 0x55, 0x52, 0x27, 0xff, 0x00, 0xe2, 0xbb,
  30811. 0x4a, 0xf2, 0x69, 0xb4, 0x4e, 0x6c, 0x6b, 0xa3,
  30812. 0x96, 0x4f, 0xf4, 0x65, 0x90, 0x2d, 0xc8, 0x57,
  30813. 0x1f, 0xb2, 0xf0, 0x86, 0x7b, 0x93, 0x09, 0x49,
  30814. 0x31, 0xc4, 0xf4, 0x8f, 0xc8, 0x2d, 0xac, 0x1d,
  30815. 0xfc, 0xba, 0xa4, 0xa5, 0x41, 0x90, 0x76, 0x7d,
  30816. 0x9e, 0x47, 0xdc, 0x10, 0xe6, 0x0c, 0xf7, 0x0f,
  30817. 0xa4, 0xba, 0x4f, 0xe2, 0x46, 0x38, 0x4c, 0x28,
  30818. 0xa0, 0x57, 0xb5, 0x3c, 0xb3, 0x4b, 0x8f, 0x03,
  30819. 0x04, 0xff, 0xf6, 0xec, 0x60, 0x90, 0x62, 0xfe,
  30820. 0x74, 0x76, 0x48, 0xb3, 0xf4, 0x0a, 0x6a, 0x5a,
  30821. 0x5b, 0xad, 0xc8, 0x54, 0x62, 0x11, 0x52, 0xd9,
  30822. 0x84, 0x1a, 0x09, 0x4b, 0xca, 0x66, 0xaa, 0x3c,
  30823. 0x36, 0x08, 0x9d, 0x58, 0xd0, 0x4a, 0x3a, 0x8b,
  30824. 0x24, 0xe0, 0x80, 0x9f, 0xe3, 0x76, 0xb6, 0x07,
  30825. 0xb1, 0xbc, 0x00, 0x98, 0xb0, 0xc1, 0xe0, 0xf6,
  30826. 0x1f, 0x4d, 0xa8, 0xd1, 0x69, 0x44, 0x9c, 0x33,
  30827. 0xb0, 0x0f, 0x9c, 0xc9, 0x0c, 0x8c, 0xbc, 0x03,
  30828. 0x58, 0x81, 0x76, 0xab, 0x0d, 0xef, 0x25, 0x5a,
  30829. 0xf6, 0xab, 0x3b, 0xf1, 0x1f, 0x97, 0x12, 0x8e,
  30830. 0x7f, 0x28, 0x77, 0x26, 0x18, 0xc4, 0xc4, 0xda,
  30831. 0x2c, 0x43, 0x57, 0xd2, 0x1f, 0x67, 0x95, 0x40,
  30832. 0x2c, 0x94, 0x41, 0x69, 0x22, 0x8a, 0x24, 0xd9,
  30833. 0xc7, 0xfc, 0xea, 0x49, 0x83, 0x8f, 0x5d, 0x2e,
  30834. 0x9d, 0xac, 0x17, 0xb6, 0xe0, 0xc4, 0xe7, 0xe6,
  30835. 0xd5, 0xc2, 0x73, 0xa1, 0x8f, 0x33, 0x14, 0x02,
  30836. 0xae, 0x01, 0x9f, 0x6f, 0x40, 0x92, 0x4e, 0x03,
  30837. 0xc2, 0xa9, 0xf1, 0x36, 0x78, 0xe4, 0xde, 0x39,
  30838. 0x4d, 0x29, 0x2e, 0xc2, 0x00, 0x93, 0x79, 0xe4,
  30839. 0xb2, 0x29, 0x4b, 0x81, 0x5c, 0x06, 0x06, 0xbc,
  30840. 0xc1, 0x01, 0x1c, 0xa7, 0x08, 0xf7, 0x47, 0x1f,
  30841. 0x52, 0x4f, 0xdf, 0x94, 0x1e, 0xe6, 0x89, 0xe6,
  30842. 0x26, 0x71, 0x2e, 0xa2, 0xd2, 0xfe, 0x04, 0xf2,
  30843. 0x12, 0x4c, 0x06, 0x78, 0x34, 0xc0, 0xb9, 0x76,
  30844. 0x62, 0x3b, 0x72, 0x25, 0x8c, 0x0d, 0x73, 0x24,
  30845. 0xcf, 0x4b, 0x4c, 0x47, 0x20, 0x9d, 0x04, 0x7f,
  30846. 0x86, 0x2c, 0x45, 0xb8, 0xfe, 0xb2, 0xaa, 0x36,
  30847. 0xf8, 0xe0, 0x24, 0x25, 0x05, 0x23, 0x12, 0x16,
  30848. 0xbf, 0x64, 0x10, 0xdd, 0xe4, 0xc0, 0xb0, 0x85,
  30849. 0xa7, 0xd3, 0xd1, 0x18, 0x1b, 0x81, 0x6b, 0x94,
  30850. 0xfd, 0x07, 0x43, 0xdd, 0x12, 0x37, 0x78, 0x69,
  30851. 0xec, 0x8c, 0xd0, 0x41, 0x2c, 0x42, 0x94, 0x3e,
  30852. 0x9f, 0xe3, 0x49, 0xb3, 0xb8, 0x45, 0x0b, 0x1d,
  30853. 0xc1, 0x9b, 0x4d, 0x21, 0x85, 0x62, 0xea, 0xd1,
  30854. 0xc9, 0x12, 0x30, 0x8c, 0x4b, 0x63, 0xeb, 0x7d,
  30855. 0x02, 0x52, 0x15, 0xa1, 0x95, 0x48, 0x9f, 0xc2,
  30856. 0xce, 0xf3, 0x4b, 0xff, 0x5a, 0xb6, 0x8f, 0xce,
  30857. 0xcd, 0x42, 0x21, 0x40, 0x82, 0xad, 0x08, 0x99,
  30858. 0x4d, 0x24, 0x58, 0x25, 0xf3, 0x7e, 0x42, 0x86,
  30859. 0x06, 0x33, 0x1f, 0x53, 0xbb, 0x07, 0x33, 0xca,
  30860. 0xc0, 0x02, 0x18, 0x30, 0x3c, 0xc5, 0x67, 0x1c,
  30861. 0x32, 0x3f, 0x2d, 0x58, 0x4c, 0x24, 0x6e, 0x60,
  30862. 0x96, 0x1a, 0xf4, 0xd0, 0x55, 0xb8, 0x84, 0xf0,
  30863. 0xb9, 0x83, 0xbf, 0x3d, 0x37, 0xe4, 0xa6, 0x06,
  30864. 0x1c, 0xd1, 0xd7, 0x91, 0x24, 0xdc, 0x3f, 0xcc,
  30865. 0x71, 0xf3, 0x0c, 0x90, 0x2c, 0x1d, 0x2f, 0x90,
  30866. 0xc8, 0x3c, 0x6f, 0x2c, 0x5d, 0xad, 0x8c, 0xdf,
  30867. 0xbb, 0x0d, 0x2a, 0x7f, 0x4a, 0x34, 0x5a, 0xd9,
  30868. 0x83, 0xfd, 0x61, 0x36, 0xe0, 0x0a, 0xb3, 0xf6,
  30869. 0x69, 0xb1, 0xaf, 0x81, 0x22, 0xd6, 0x9e, 0x9a,
  30870. 0xf8, 0xa6, 0x24, 0x8e, 0x0c, 0xcb, 0x25, 0xc2,
  30871. 0xfc, 0xc5, 0x94, 0xbd, 0x23, 0x9c, 0xa9, 0xbd,
  30872. 0x76, 0x28, 0xa4, 0x55, 0x92, 0x7c, 0xe6, 0x76,
  30873. 0xf7, 0x30, 0xf8, 0x7d, 0xdc, 0x0a, 0x93, 0x9e,
  30874. 0x7c, 0x39, 0x0a, 0x70, 0xa0, 0xb2, 0x77, 0xe0,
  30875. 0x7a, 0x89, 0x50, 0xce, 0x75, 0xca, 0x2f, 0xa4,
  30876. 0x12, 0x0e, 0xcb, 0x75, 0x1f, 0x0a, 0x83, 0xe8,
  30877. 0x14, 0x80, 0xa7, 0xb0, 0xe8, 0x11, 0xca, 0x12,
  30878. 0x5e, 0xf7, 0x31, 0x65, 0xbd, 0x20, 0x3d, 0x8c,
  30879. 0xa6, 0x89, 0x83, 0x68, 0x66, 0x03, 0x28, 0x49,
  30880. 0x17, 0xc4, 0x3f, 0x43, 0x02, 0x9b, 0xf8, 0xed,
  30881. 0xae, 0x8e, 0x68, 0xbc, 0x8e, 0x39, 0xe7, 0x15,
  30882. 0x32, 0x45, 0x66, 0x2c, 0x1f, 0xce, 0x56, 0xc7,
  30883. 0xc0, 0x15, 0x52, 0x19, 0x40, 0xcf, 0x87, 0x20,
  30884. 0xcd, 0x3d, 0xec, 0x90, 0x8d, 0x04, 0x01, 0x31,
  30885. 0x0b, 0x74, 0x80, 0x6e, 0x61, 0xa7, 0xf3, 0x4c,
  30886. 0xb2, 0x16, 0x00, 0xd5, 0xdb, 0xcc, 0xbb, 0x2c,
  30887. 0x9f, 0xb6, 0x02, 0x4a, 0xcf, 0x71, 0x06, 0xfd,
  30888. 0x60, 0xe0, 0x00, 0xbe, 0x22, 0xba, 0x39, 0x36,
  30889. 0xa8, 0x7e, 0xe5, 0xcb, 0xea, 0x87, 0xb1, 0xee,
  30890. 0xa2, 0x6c, 0x85, 0x94, 0x18, 0x6c, 0xab, 0x9a,
  30891. 0x93, 0xa7, 0xab, 0x4e, 0x3b, 0x85, 0xf3, 0xef,
  30892. 0x8f, 0x15, 0x74, 0x21, 0x9f, 0x5d, 0x9c, 0x22,
  30893. 0x32, 0x71, 0xb5, 0x4d, 0x7f, 0xaa, 0x85, 0xe0,
  30894. 0x05, 0x2a, 0x53, 0xbb, 0x3c, 0xab, 0xc3, 0xd2,
  30895. 0x73, 0x6e, 0x97, 0xa3, 0xfd, 0x05, 0x58, 0xaa,
  30896. 0x49, 0xc8, 0x69, 0xa9, 0x0b, 0x73, 0xd4, 0xe9,
  30897. 0x1d, 0x84, 0x60, 0x34, 0x2a, 0x09, 0xb3, 0x0f,
  30898. 0x08, 0x13, 0x67, 0x77, 0xb3, 0x24, 0xdf, 0xad,
  30899. 0xbf, 0x51, 0x71, 0x2b, 0xbe, 0x4f, 0x5d, 0xf4,
  30900. 0xe7, 0x25, 0x4c, 0x24, 0xa2, 0x4a, 0x22, 0xec,
  30901. 0xcc, 0x7c, 0x6c, 0x62, 0xee, 0x47, 0x12, 0x43,
  30902. 0x88, 0xe4, 0x71, 0xaa, 0x63, 0xaa, 0x2b, 0xed,
  30903. 0x70, 0xbf, 0x26, 0x37, 0xcc, 0xa4, 0xff, 0xe9,
  30904. 0xb6, 0x65, 0x31, 0x4d, 0x0d, 0x32, 0xd6, 0x84,
  30905. 0xb8, 0xab, 0x98, 0xa7, 0x10, 0x44, 0x77, 0xc7,
  30906. 0x2a, 0x60, 0xf0, 0xf5, 0xd5, 0xd4, 0x3a, 0x73,
  30907. 0x11, 0xa5, 0x1b, 0x18, 0x3c, 0x13, 0xfb, 0xda,
  30908. 0x76, 0x9d, 0xeb, 0x3e, 0xb9, 0x7a, 0xce, 0x02,
  30909. 0xa7, 0x5e, 0x25, 0x96, 0xd2, 0xbc, 0x85, 0x1a,
  30910. 0xd1, 0xa4, 0xe2, 0x02, 0x15, 0x08, 0x49, 0x16,
  30911. 0x7c, 0xaf, 0xc6, 0x38, 0x7b, 0x95, 0xf9, 0x37,
  30912. 0xc0, 0x87, 0x73, 0x6f, 0x01, 0xcd, 0x2b, 0xf1,
  30913. 0xe7, 0x6e, 0x47, 0x18, 0x30, 0xb8, 0x16, 0x87,
  30914. 0x1d, 0x23, 0x62, 0x22, 0x85, 0x92, 0x69, 0x46,
  30915. 0x9c, 0x65, 0xd8, 0xf1, 0x27, 0x32, 0xe4, 0x16,
  30916. 0x7f, 0x9a, 0xba, 0x46, 0x61, 0x60, 0x34, 0xe5,
  30917. 0xc0, 0x14, 0xb5, 0xde, 0x4d, 0xd1, 0x71, 0x39,
  30918. 0x26, 0xdc, 0x0c, 0x0a, 0x53, 0x9e, 0x31, 0x10,
  30919. 0x45, 0x7a, 0xf9, 0xc8, 0xfa, 0x1d, 0x69, 0x5e,
  30920. 0x25, 0xc1, 0xe2, 0x00, 0xbf, 0x94, 0xa3, 0xa2,
  30921. 0x97, 0xca, 0xb4, 0x6a, 0x89, 0x68, 0xdd, 0xed,
  30922. 0x6b, 0x99, 0x5a, 0x87, 0x9e, 0xe9, 0x68, 0xe4,
  30923. 0xf2, 0xc2, 0x7e, 0x37, 0x02, 0xdf, 0x96, 0x1a,
  30924. 0x5b, 0xed, 0xa1, 0xe8, 0xdf, 0x3c, 0xf7, 0xd2,
  30925. 0x25, 0xac, 0xf7, 0x4a, 0x7f, 0x10, 0x27, 0x2b,
  30926. 0x02, 0xc7, 0x95, 0x10, 0x5a, 0xb5, 0xb0, 0xcd,
  30927. 0xa9, 0xe1, 0x36, 0xe2, 0x1c, 0x87, 0x99, 0x0e,
  30928. 0x0a, 0x44, 0xec, 0x97, 0x75, 0xa7, 0x03, 0x27,
  30929. 0x38, 0x3b, 0x16, 0x30, 0x00, 0x98, 0xbe, 0x77,
  30930. 0xfe, 0x3a, 0xac, 0x6f, 0x8f, 0x4d, 0xe1, 0xa9,
  30931. 0x9c, 0xba, 0x39, 0x52, 0xe8, 0xf7, 0xe4, 0xe6,
  30932. 0xf9, 0xe9, 0xb3, 0x57, 0x82, 0xb2, 0x23, 0xd6,
  30933. 0xa5, 0x14, 0xc0, 0x78, 0xb4, 0xa0, 0xf9, 0x96,
  30934. 0xe4, 0x03, 0xe8, 0x6c, 0x27, 0xd8, 0x37, 0x7c,
  30935. 0x8f, 0xf4, 0x80, 0x09, 0x09, 0xc9, 0x32, 0x15,
  30936. 0xe0, 0x3f, 0x37, 0xa7, 0x1a, 0x5f, 0x8c, 0xfb,
  30937. 0xdd, 0xfe, 0x6b, 0x34, 0x28, 0x53, 0x03, 0x4b,
  30938. 0x39, 0x91, 0xf2, 0x48, 0x4c, 0x2a, 0x45, 0xfe,
  30939. 0x66, 0xf7, 0x23, 0x74, 0xb8, 0x30, 0x70, 0xb4,
  30940. 0x0c, 0x2c, 0x65, 0xb1, 0x4e, 0x32, 0x0f, 0x50,
  30941. 0xbb, 0x46, 0x9b, 0x03, 0x34, 0x38, 0xfb, 0xe4,
  30942. 0x25, 0x37, 0x8d, 0x0f, 0xa1, 0x41, 0x50, 0x85,
  30943. 0x92, 0x07, 0x71, 0xff, 0x3c, 0xe6, 0xd9, 0x1d,
  30944. 0x55, 0xb7, 0x10, 0x9c, 0xea, 0x70, 0x5f, 0xa3,
  30945. 0xba, 0x84, 0x99, 0x91, 0x30, 0x3d, 0x4c, 0x98,
  30946. 0x0b, 0x1f, 0x1f, 0xcc, 0x17, 0x94, 0xdd, 0x78,
  30947. 0x7d, 0x50, 0xe5, 0xf5, 0x21, 0x88, 0x5a, 0x52,
  30948. 0x76, 0x5a, 0x97, 0xbe, 0xba, 0xa9, 0xfe, 0x82,
  30949. 0x8a, 0xb5, 0x46, 0xcf, 0x9c, 0xbe, 0xe8, 0x2f,
  30950. 0x01, 0x2f, 0x6a, 0x03, 0x8a, 0xfa, 0x4b, 0x0b,
  30951. 0xdc, 0x78, 0x79, 0x9c, 0x49, 0xc4, 0x01, 0x26,
  30952. 0x16, 0x58, 0xc6, 0xb8, 0xee, 0x6c, 0xc9, 0xa9,
  30953. 0x38, 0x7c, 0xcf, 0xf3, 0xf8, 0xd0, 0x6b, 0x99,
  30954. 0x43, 0x13, 0xe0, 0x43, 0x8e, 0xfb, 0xb2, 0xdb,
  30955. 0x61, 0x67, 0xf4, 0xfc, 0x01, 0x21, 0xd9, 0xb1,
  30956. 0x1e, 0x6c, 0x6f, 0x2a, 0x9a, 0x4b, 0x86, 0x3c,
  30957. 0x62, 0x03, 0x53, 0x83, 0x11, 0x18, 0x1a, 0x59,
  30958. 0x9e, 0x25, 0xfe, 0xdb, 0x85, 0xd0, 0xee, 0x7c,
  30959. 0x97, 0x72, 0xca, 0xf3, 0x0d, 0xd4, 0x19, 0x66,
  30960. 0x14, 0xaf, 0x46, 0x68, 0x75, 0xdb, 0x8f, 0x5f,
  30961. 0x77, 0x7f, 0xfe, 0xa9, 0xe6, 0xa1, 0x9e, 0x46,
  30962. 0x5e, 0x92, 0xda, 0xea, 0xdd, 0x89, 0x01, 0xd9,
  30963. 0xab, 0x25, 0x7d, 0xb4, 0x64, 0x50, 0x8f, 0xa3,
  30964. 0xbe, 0xe2, 0x03, 0xd5, 0xc6, 0x9c, 0xc2, 0xf8,
  30965. 0xac, 0xa4, 0x36, 0xa9, 0x37, 0x10, 0x59, 0x00,
  30966. 0x45, 0xbb, 0x55, 0x33, 0xb9, 0x6f, 0xbc, 0xa2,
  30967. 0x02, 0x9e, 0xa3, 0x1d, 0xf4, 0x17, 0x78, 0x9b,
  30968. 0xbc, 0x42, 0x4e, 0x21, 0xc3, 0xde, 0xb5, 0x70,
  30969. 0x4a, 0x23, 0x1e, 0xd4, 0x36, 0x5d, 0x7a, 0x08,
  30970. 0x37, 0x55, 0x98, 0x07, 0xa0, 0x16, 0xa3, 0x4e,
  30971. 0xa1, 0x2b, 0x96, 0x8b, 0x51, 0x63, 0x48, 0xab,
  30972. 0xc9, 0x19, 0x6f, 0x5f, 0x25, 0x9d, 0xe7, 0x25,
  30973. 0x63, 0xf0, 0x8e, 0xdb, 0x06, 0x2d, 0x42, 0x31,
  30974. 0xfd, 0x14, 0x2b, 0x7a, 0x31, 0x43, 0x04, 0xd5,
  30975. 0xe2, 0x89, 0x2e, 0xa8, 0xe4, 0x6e, 0xd5, 0xa5,
  30976. 0x21, 0x67, 0x9b, 0x92, 0x61, 0x79, 0xdd, 0xe5,
  30977. 0x44, 0x43, 0x45, 0x57, 0x13, 0xec, 0x04, 0xc1,
  30978. 0x41, 0xa3, 0x14, 0x70, 0x86, 0xda, 0x76, 0x5d,
  30979. 0xe8, 0x61, 0xd2, 0xfb, 0x7b, 0xe4, 0x71, 0x46,
  30980. 0xa3, 0x52, 0xbf, 0xf2, 0xa0, 0x3c, 0xc1, 0x90,
  30981. 0x0c, 0x2e, 0xeb, 0xb3, 0x38, 0xae, 0x13, 0x27,
  30982. 0x84, 0xe9, 0x7a, 0xd6, 0x02, 0x40, 0x84, 0xff,
  30983. 0x87, 0x1f, 0x37, 0x44, 0xd8, 0x2e, 0x93, 0xf7,
  30984. 0x0a, 0xff, 0x5b, 0x4d, 0x07, 0x82, 0xfd, 0x6e,
  30985. 0x44, 0xcc, 0x19, 0xc3, 0x7d, 0x7c, 0x31, 0xf9,
  30986. 0x0e, 0xa8, 0x1c, 0x0d, 0xcb, 0x8e, 0xe8, 0x33,
  30987. 0xb2, 0xff, 0x9e, 0x1d, 0x99, 0x7c, 0x46, 0x5b,
  30988. 0xc7, 0x28, 0xec, 0x01, 0x62, 0x82, 0xfe, 0x2a,
  30989. 0x22, 0xa3, 0x86, 0x4e, 0x47, 0xe2, 0x57, 0xf1,
  30990. 0xb4, 0x58, 0x94, 0x89, 0xe5, 0xf1, 0xcd, 0x4d,
  30991. 0x90, 0xd1, 0xa4, 0x4c, 0x34, 0x5d, 0xde, 0xdc,
  30992. 0x39, 0x63, 0x8b, 0x85, 0xfd, 0x02, 0x21, 0xf1,
  30993. 0x12, 0xa3, 0x6d, 0x65, 0x0f, 0x8d, 0xe5, 0xcd,
  30994. 0x70, 0xd5, 0x1d, 0xf8, 0x65, 0x99, 0xfb, 0xe8,
  30995. 0xb5, 0x5a, 0x09, 0x39, 0x9e, 0x09, 0x45, 0x62,
  30996. 0x22, 0x1d, 0xa2, 0x46, 0xbf, 0x75, 0x20, 0xd1,
  30997. 0xe7, 0xb0, 0x06, 0x68, 0xc3, 0x50, 0x48, 0xfc,
  30998. 0xf8, 0x5c, 0x67, 0x69, 0x68, 0x66, 0xb6, 0x81,
  30999. 0x95, 0x91, 0x81, 0x3d, 0xf6, 0x34, 0xd9, 0x4b,
  31000. 0x06, 0x35, 0x17, 0x59, 0x89, 0x18, 0x74, 0x32,
  31001. 0x50, 0xcf, 0x81, 0x16, 0x8e, 0x53, 0x9d, 0x1c,
  31002. 0xad, 0x2d, 0x8e, 0x16, 0x41, 0xda, 0xca, 0xab,
  31003. 0x78, 0x0d, 0xc9, 0x49, 0x61, 0xaa, 0x18, 0xf4,
  31004. 0x56, 0x48, 0x29, 0x8c, 0xe3, 0x9a, 0x7d, 0x58,
  31005. 0xf8, 0x99, 0x72, 0xf1, 0x78, 0xa8, 0x5a, 0x97,
  31006. 0xe3, 0x2a, 0xc6, 0xa9, 0x59, 0xde, 0xcc, 0x62,
  31007. 0xfb, 0xab, 0xc5, 0x9a, 0x0b, 0xc7, 0x16, 0x8f,
  31008. 0x18, 0x20, 0x6e, 0x01, 0x7e, 0x04, 0xef, 0x72,
  31009. 0x83, 0x61, 0xb8, 0x1a, 0x77, 0x0f, 0xd1, 0xa9,
  31010. 0x75, 0xe0, 0x4a, 0x11, 0x69, 0x9d, 0xb6, 0xc9,
  31011. 0x2e, 0xd3, 0xbf, 0xe2, 0x5b, 0x24, 0x77, 0x30,
  31012. 0x85, 0x91, 0xef, 0xa8, 0x93, 0x4e, 0xad, 0x99,
  31013. 0xad, 0xcb, 0x6d, 0x9d, 0x8f, 0xd8, 0x0f, 0xe5,
  31014. 0x41, 0xd9, 0x9e, 0x0b, 0xce, 0x33, 0xd9, 0xbb,
  31015. 0x87, 0x66, 0x2c, 0xa3, 0x0b, 0x68, 0x1b, 0xb0,
  31016. 0x71, 0x30, 0xfa, 0x15, 0x2e, 0xe8, 0xc1, 0x99,
  31017. 0x71, 0x01, 0xcc, 0xdb, 0x6f, 0x9f, 0x8a, 0xfd,
  31018. 0xb4, 0x0f, 0x35, 0xa1, 0x36, 0xf4, 0x3a, 0xc4,
  31019. 0x17, 0x77, 0x43, 0x60, 0x10, 0x18, 0xb4, 0xc2,
  31020. 0xe5, 0xc0, 0x64, 0xd8, 0x38, 0x7c, 0x05, 0x9a,
  31021. 0xfb, 0x2b, 0xb3, 0x9b, 0x9e, 0x34, 0x6b, 0x4b,
  31022. 0xc8, 0x3b, 0x77, 0xe0, 0x6f, 0x08, 0xa1, 0x7b,
  31023. 0x66, 0x69, 0x2f, 0xdb, 0x34, 0x9e, 0x98, 0x90,
  31024. 0x5b, 0x4d, 0x7b, 0xa2, 0x32, 0x8e, 0x64, 0xe6,
  31025. 0x0d, 0x75, 0xc9, 0x96, 0xe3, 0x57, 0xba, 0xad,
  31026. 0x3e, 0x3b, 0x23, 0xfb, 0x9e, 0x7f, 0xc0, 0x3c,
  31027. 0xd5, 0x41, 0x9c, 0xfb, 0xbc, 0xb3, 0x52, 0x49
  31028. #endif
  31029. };
  31030. #endif
  31031. #endif
  31032. static int test_wc_dilithium_public_der_decode(void)
  31033. {
  31034. EXPECT_DECLS;
  31035. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  31036. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  31037. dilithium_key* key;
  31038. word32 idx = 0;
  31039. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  31040. ExpectNotNull(key);
  31041. if (key != NULL) {
  31042. XMEMSET(key, 0, sizeof(*key));
  31043. }
  31044. ExpectIntEQ(wc_dilithium_init(key), 0);
  31045. #ifndef WOLFSSL_NO_ML_DSA_44
  31046. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  31047. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  31048. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  31049. #else
  31050. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  31051. #endif
  31052. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(ml_dsa_public_der, &idx, key,
  31053. (word32)sizeof(ml_dsa_public_der)), 0);
  31054. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  31055. idx = 0;
  31056. #ifndef WOLFSSL_NO_ML_DSA_44
  31057. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44_DRAFT), 0);
  31058. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  31059. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65_DRAFT), 0);
  31060. #else
  31061. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87_DRAFT), 0);
  31062. #endif
  31063. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(dilithium_public_der, &idx, key,
  31064. (word32)sizeof(dilithium_public_der)), 0);
  31065. #endif
  31066. wc_dilithium_free(key);
  31067. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  31068. #endif
  31069. return EXPECT_RESULT();
  31070. }
  31071. static int test_wc_dilithium_der(void)
  31072. {
  31073. EXPECT_DECLS;
  31074. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  31075. !defined(WOLFSSL_DILITHIUM_NO_ASN1) && \
  31076. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  31077. #define DILITHIUM_MAX_DER_SIZE 8192
  31078. dilithium_key* key;
  31079. WC_RNG rng;
  31080. byte* der = NULL;
  31081. int len;
  31082. int pubLen;
  31083. int pubDerLen;
  31084. int privDerLen;
  31085. int keyDerLen;
  31086. word32 idx;
  31087. #ifndef WOLFSSL_NO_ML_DSA_44
  31088. pubLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE;
  31089. pubDerLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE + 22;
  31090. privDerLen = DILITHIUM_LEVEL2_KEY_SIZE + 28;
  31091. keyDerLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE + DILITHIUM_LEVEL2_KEY_SIZE + 32;
  31092. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  31093. pubLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE;
  31094. pubDerLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE + 22;
  31095. privDerLen = DILITHIUM_LEVEL3_KEY_SIZE + 28;
  31096. keyDerLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE + DILITHIUM_LEVEL3_KEY_SIZE + 32;
  31097. #else
  31098. pubLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE;
  31099. pubDerLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE + 22;
  31100. privDerLen = DILITHIUM_LEVEL5_KEY_SIZE + 28;
  31101. keyDerLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE + DILITHIUM_LEVEL5_KEY_SIZE + 32;
  31102. #endif
  31103. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  31104. ExpectNotNull(key);
  31105. der = (byte*)XMALLOC(DILITHIUM_MAX_DER_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  31106. ExpectNotNull(der);
  31107. if (key != NULL) {
  31108. XMEMSET(key, 0, sizeof(*key));
  31109. }
  31110. XMEMSET(&rng, 0, sizeof(WC_RNG));
  31111. ExpectIntEQ(wc_InitRng(&rng), 0);
  31112. ExpectIntEQ(wc_dilithium_init(key), 0);
  31113. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  31114. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31115. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  31116. 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31117. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  31118. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31119. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der, &idx, key, pubDerLen),
  31120. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31121. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, privDerLen),
  31122. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31123. #ifndef WOLFSSL_NO_ML_DSA_44
  31124. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  31125. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  31126. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  31127. #else
  31128. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  31129. #endif
  31130. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  31131. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31132. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  31133. 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31134. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  31135. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31136. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  31137. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, NULL, 0 ,
  31138. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31139. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, der , 0 ,
  31140. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31141. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, NULL, DILITHIUM_MAX_DER_SIZE,
  31142. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31143. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, der , DILITHIUM_MAX_DER_SIZE,
  31144. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31145. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , der , 0 ,
  31146. 0), WC_NO_ERR_TRACE(BUFFER_E));
  31147. /* Get length only. */
  31148. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, 0 ,
  31149. 0), pubLen);
  31150. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE,
  31151. 0), pubLen);
  31152. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, 0 ,
  31153. 1), pubDerLen);
  31154. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE,
  31155. 1), pubDerLen);
  31156. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, NULL,
  31157. 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31158. ExpectIntGT(wc_Dilithium_PrivateKeyToDer(key , NULL,
  31159. 0 ), 0);
  31160. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, der ,
  31161. 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31162. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, NULL,
  31163. DILITHIUM_MAX_DER_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31164. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, der ,
  31165. DILITHIUM_MAX_DER_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31166. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key , der ,
  31167. 0 ), WC_NO_ERR_TRACE(BUFFER_E));
  31168. /* Get length only. */
  31169. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key , NULL,
  31170. DILITHIUM_MAX_DER_SIZE), privDerLen);
  31171. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, NULL, 0 ),
  31172. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31173. ExpectIntGT(wc_Dilithium_KeyToDer(key , NULL, 0 ),
  31174. 0 );
  31175. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, der , 0 ),
  31176. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31177. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, NULL, DILITHIUM_MAX_DER_SIZE),
  31178. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31179. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, der , DILITHIUM_MAX_DER_SIZE),
  31180. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31181. ExpectIntEQ(wc_Dilithium_KeyToDer(key , der , 0 ),
  31182. WC_NO_ERR_TRACE(BUFFER_E));
  31183. /* Get length only. */
  31184. ExpectIntEQ(wc_Dilithium_KeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE),
  31185. keyDerLen);
  31186. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, NULL, 0 ),
  31187. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31188. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , NULL, NULL, 0 ),
  31189. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31190. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, &idx, NULL, 0 ),
  31191. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31192. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, key , 0 ),
  31193. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31194. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, NULL, pubDerLen),
  31195. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31196. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, &idx, key , pubDerLen),
  31197. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31198. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , NULL, key , pubDerLen),
  31199. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31200. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , &idx, NULL, pubDerLen),
  31201. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31202. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , &idx, key , 0 ),
  31203. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31204. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, NULL, 0 ),
  31205. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31206. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , NULL, NULL, 0 ),
  31207. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31208. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, &idx, NULL, 0 ),
  31209. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31210. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, key , 0 ),
  31211. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31212. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, NULL, privDerLen),
  31213. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31214. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, &idx, key , privDerLen),
  31215. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31216. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , NULL, key , privDerLen),
  31217. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31218. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , &idx, NULL, privDerLen),
  31219. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31220. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , &idx, key , 0 ),
  31221. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31222. ExpectIntEQ(len = wc_Dilithium_PublicKeyToDer(key, der,
  31223. DILITHIUM_MAX_DER_SIZE, 0), pubLen);
  31224. ExpectIntEQ(wc_dilithium_import_public(der, len, key), 0);
  31225. ExpectIntEQ(len = wc_Dilithium_PublicKeyToDer(key, der,
  31226. DILITHIUM_MAX_DER_SIZE, 1), pubDerLen);
  31227. idx = 0;
  31228. {
  31229. fprintf(stderr, "\n");
  31230. for (int ii = 0; ii < pubDerLen; ii++) {
  31231. if ((ii % 8) == 0) fprintf(stderr, " ");
  31232. fprintf(stderr, "0x%02x,", der[ii]);
  31233. if ((ii % 8) == 7) fprintf(stderr, "\n");
  31234. else fprintf(stderr, " ");
  31235. }
  31236. }
  31237. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der, &idx, key, len), 0);
  31238. ExpectIntEQ(len = wc_Dilithium_PrivateKeyToDer(key, der,
  31239. DILITHIUM_MAX_DER_SIZE), privDerLen);
  31240. idx = 0;
  31241. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, len), 0);
  31242. ExpectIntEQ(len = wc_Dilithium_KeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  31243. keyDerLen);
  31244. idx = 0;
  31245. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, len), 0);
  31246. wc_dilithium_free(key);
  31247. wc_FreeRng(&rng);
  31248. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  31249. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  31250. #endif
  31251. return EXPECT_RESULT();
  31252. }
  31253. static int test_wc_dilithium_make_key_from_seed(void)
  31254. {
  31255. EXPECT_DECLS;
  31256. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  31257. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  31258. dilithium_key* key;
  31259. #ifndef WOLFSSL_NO_ML_DSA_44
  31260. static const byte seed_44[] = {
  31261. 0x93, 0xEF, 0x2E, 0x6E, 0xF1, 0xFB, 0x08, 0x99,
  31262. 0x9D, 0x14, 0x2A, 0xBE, 0x02, 0x95, 0x48, 0x23,
  31263. 0x70, 0xD3, 0xF4, 0x3B, 0xDB, 0x25, 0x4A, 0x78,
  31264. 0xE2, 0xB0, 0xD5, 0x16, 0x8E, 0xCA, 0x06, 0x5F
  31265. };
  31266. static const byte pk_44[] = {
  31267. 0xBC, 0x5F, 0xF8, 0x10, 0xEB, 0x08, 0x90, 0x48,
  31268. 0xB8, 0xAB, 0x30, 0x20, 0xA7, 0xBD, 0x3B, 0x16,
  31269. 0xC0, 0xE0, 0xCA, 0x3D, 0x6B, 0x97, 0xE4, 0x64,
  31270. 0x6C, 0x2C, 0xCA, 0xE0, 0xBB, 0xF1, 0x9E, 0xF7,
  31271. 0x23, 0x0A, 0x19, 0xD7, 0x5A, 0xDB, 0xDE, 0xD5,
  31272. 0x2D, 0xB8, 0x55, 0xE2, 0x52, 0xA7, 0x19, 0xFC,
  31273. 0xBD, 0x14, 0x7B, 0xA6, 0x7B, 0x2F, 0xAD, 0x14,
  31274. 0xED, 0x0E, 0x68, 0xFD, 0xFE, 0x8C, 0x65, 0xBA,
  31275. 0xDE, 0xAC, 0xB0, 0x91, 0x11, 0x93, 0xAD, 0xFA,
  31276. 0x87, 0x94, 0xD7, 0x8F, 0x8E, 0x3D, 0x66, 0x2A,
  31277. 0x1C, 0x49, 0xDA, 0x81, 0x9F, 0xD9, 0x59, 0xE7,
  31278. 0xF0, 0x78, 0xF2, 0x03, 0xC4, 0x56, 0xF8, 0xB6,
  31279. 0xE7, 0xC9, 0x41, 0x58, 0x98, 0xE5, 0x41, 0xC7,
  31280. 0x30, 0x32, 0xDB, 0xD6, 0x19, 0xEA, 0xF6, 0x0F,
  31281. 0x8D, 0x64, 0xF8, 0x68, 0x3D, 0xA9, 0x9E, 0xCA,
  31282. 0x51, 0x22, 0x0B, 0x0A, 0xCA, 0x28, 0x46, 0x40,
  31283. 0x99, 0xF5, 0x47, 0xC0, 0x27, 0x77, 0xBD, 0x37,
  31284. 0xD8, 0x4A, 0x59, 0xBD, 0x37, 0xED, 0x7A, 0x8A,
  31285. 0x92, 0x63, 0x3C, 0x75, 0xD0, 0x7C, 0x79, 0x3F,
  31286. 0xE7, 0x25, 0x2B, 0x58, 0x4A, 0xBF, 0x6A, 0x15,
  31287. 0xEE, 0x14, 0x50, 0x7E, 0x5E, 0x19, 0x3F, 0x89,
  31288. 0x86, 0x4D, 0x09, 0xAC, 0x87, 0x27, 0xA6, 0xD0,
  31289. 0x42, 0x1F, 0x0C, 0x19, 0xF0, 0xE2, 0xFB, 0xFC,
  31290. 0x21, 0x3D, 0x3F, 0xBD, 0x70, 0xF4, 0xF9, 0x76,
  31291. 0x2C, 0xEC, 0xFF, 0x23, 0x1E, 0x9C, 0x8A, 0x76,
  31292. 0x28, 0xD3, 0xF8, 0xB0, 0x85, 0x7B, 0x03, 0x2D,
  31293. 0x32, 0xDE, 0x62, 0xFF, 0x8E, 0xCB, 0xF4, 0x00,
  31294. 0x82, 0x89, 0xBF, 0x34, 0x40, 0x36, 0x65, 0xF8,
  31295. 0x1A, 0x08, 0x1A, 0xD5, 0xA8, 0x5A, 0x28, 0x2F,
  31296. 0x99, 0xBA, 0xB9, 0xE5, 0x38, 0x5A, 0xFB, 0xCC,
  31297. 0xCF, 0x44, 0xB7, 0x4C, 0x01, 0x96, 0xC7, 0x54,
  31298. 0x55, 0x27, 0xEC, 0x30, 0x26, 0xDA, 0x12, 0x80,
  31299. 0xC4, 0xEB, 0x37, 0xD0, 0x9C, 0xFE, 0x3E, 0xC4,
  31300. 0xB4, 0x91, 0x0B, 0x62, 0xEB, 0x98, 0x15, 0xA4,
  31301. 0x25, 0xC6, 0x59, 0x0F, 0xC4, 0xAD, 0x3F, 0xBB,
  31302. 0x22, 0x57, 0x52, 0xCC, 0x1F, 0xC5, 0x69, 0x3F,
  31303. 0x18, 0x7E, 0x7D, 0xEC, 0x4E, 0xEF, 0xBE, 0xB6,
  31304. 0xB9, 0x1B, 0xD9, 0x1C, 0x5E, 0x2E, 0xA6, 0xA9,
  31305. 0x1D, 0x14, 0xD0, 0x97, 0xBE, 0x20, 0x3F, 0xBA,
  31306. 0x0B, 0xF9, 0x37, 0xC9, 0x75, 0x07, 0xDC, 0x00,
  31307. 0x7C, 0x4C, 0xAA, 0x9B, 0x07, 0x85, 0x89, 0x29,
  31308. 0x66, 0xFF, 0x15, 0x90, 0x09, 0x24, 0xE5, 0x79,
  31309. 0xD4, 0xFB, 0xA0, 0x2B, 0xDA, 0x87, 0x55, 0x5F,
  31310. 0x07, 0x3D, 0xAE, 0x00, 0x51, 0x3E, 0x70, 0x80,
  31311. 0x9A, 0xBB, 0xC7, 0x11, 0xFB, 0xA2, 0xE7, 0x64,
  31312. 0x95, 0x77, 0xC4, 0x2A, 0xFD, 0xC2, 0x4B, 0xF7,
  31313. 0x41, 0x3E, 0x51, 0x26, 0x8A, 0xD6, 0xDB, 0x61,
  31314. 0x13, 0xB7, 0xD9, 0x19, 0x1A, 0xF9, 0xD0, 0x61,
  31315. 0xDB, 0xDE, 0xD5, 0xD6, 0x30, 0x87, 0x76, 0x50,
  31316. 0xC1, 0x24, 0xF1, 0x1B, 0xC4, 0xBD, 0xC3, 0xFD,
  31317. 0xC6, 0xA9, 0x00, 0xF6, 0x31, 0x26, 0xF9, 0x21,
  31318. 0xE8, 0x38, 0xAD, 0x0C, 0x22, 0x75, 0xA3, 0x38,
  31319. 0x9A, 0x39, 0xBD, 0x99, 0xA1, 0x34, 0x50, 0x45,
  31320. 0x50, 0x10, 0x1C, 0xD3, 0xE9, 0x5E, 0x6D, 0x14,
  31321. 0x96, 0xBE, 0x7D, 0xE6, 0x62, 0x7D, 0xF4, 0xFD,
  31322. 0x6C, 0x28, 0xBB, 0xF4, 0x0B, 0x30, 0xEF, 0xA9,
  31323. 0xB5, 0xC3, 0xD5, 0xC8, 0x5A, 0xB1, 0x4A, 0x65,
  31324. 0xC0, 0x2D, 0x6D, 0x47, 0x81, 0xFF, 0x13, 0xD3,
  31325. 0x28, 0x60, 0x85, 0x54, 0xB6, 0xD1, 0x5E, 0xD9,
  31326. 0x12, 0x89, 0xA6, 0xD5, 0x5A, 0xAC, 0x0C, 0x38,
  31327. 0xE3, 0x77, 0x06, 0xF7, 0x35, 0x5E, 0x9A, 0x4F,
  31328. 0xDA, 0x61, 0x5B, 0x87, 0x59, 0x26, 0xBF, 0xE5,
  31329. 0xA5, 0x9D, 0x9E, 0xF2, 0x73, 0xBF, 0x94, 0xA0,
  31330. 0x7C, 0xFA, 0x57, 0x31, 0x78, 0xF0, 0xE0, 0x04,
  31331. 0xB6, 0xE1, 0xEF, 0x0A, 0x83, 0x49, 0xE9, 0xBC,
  31332. 0xC0, 0x19, 0x81, 0xF2, 0x46, 0x0F, 0x0A, 0x27,
  31333. 0x43, 0xC2, 0x8D, 0x1E, 0x13, 0x8F, 0xFB, 0x76,
  31334. 0x5E, 0x7E, 0x33, 0x97, 0xB7, 0x91, 0x33, 0x35,
  31335. 0xD4, 0x02, 0xFE, 0x91, 0x80, 0x6A, 0xA8, 0xFC,
  31336. 0x81, 0x92, 0x53, 0xAF, 0x32, 0x69, 0x2F, 0xA6,
  31337. 0x51, 0xE8, 0x67, 0xF5, 0x90, 0x7E, 0xF4, 0x6F,
  31338. 0x00, 0x62, 0x5A, 0x03, 0x0E, 0xC9, 0x04, 0xED,
  31339. 0xAB, 0x21, 0x42, 0x6D, 0x59, 0x11, 0x9D, 0x2C,
  31340. 0xAA, 0x43, 0xBD, 0x93, 0x5D, 0xEC, 0x0A, 0x55,
  31341. 0x0C, 0x61, 0xEE, 0x4B, 0x27, 0x9C, 0x1C, 0xA3,
  31342. 0xA7, 0x9C, 0x79, 0xA6, 0x6E, 0x3F, 0x2D, 0x2F,
  31343. 0xAD, 0xB0, 0x0F, 0x59, 0xA3, 0xA4, 0x38, 0xAA,
  31344. 0x44, 0x57, 0x01, 0x06, 0x07, 0x30, 0x17, 0xFA,
  31345. 0x1C, 0x87, 0x57, 0x50, 0x01, 0x09, 0x72, 0x0D,
  31346. 0x12, 0x5B, 0xBA, 0x23, 0x1A, 0x0C, 0x36, 0x35,
  31347. 0x0C, 0x78, 0x08, 0x6D, 0xFD, 0xC8, 0xD6, 0x13,
  31348. 0xAE, 0xCA, 0x88, 0xC4, 0xCC, 0xAE, 0xB4, 0xA4,
  31349. 0x4D, 0x13, 0xAD, 0xB3, 0xC7, 0x17, 0xD6, 0x5C,
  31350. 0x82, 0xA3, 0x51, 0xB9, 0xB6, 0xEA, 0xBF, 0x6A,
  31351. 0x10, 0xF4, 0xB4, 0xE9, 0x62, 0x3E, 0x3A, 0x95,
  31352. 0xB4, 0xD4, 0x0A, 0x12, 0xA8, 0x18, 0xAC, 0x6B,
  31353. 0x38, 0x22, 0xDB, 0x82, 0xFB, 0x05, 0xDC, 0x42,
  31354. 0x02, 0x64, 0x8B, 0x44, 0x54, 0x68, 0x9A, 0xEB,
  31355. 0x69, 0xEA, 0x32, 0x5F, 0x03, 0xE3, 0x5D, 0xEF,
  31356. 0xA5, 0x47, 0x08, 0x48, 0x14, 0x20, 0xC6, 0xD6,
  31357. 0x97, 0xBB, 0x91, 0x2F, 0xCA, 0x0D, 0x3F, 0x19,
  31358. 0x2E, 0xF2, 0x97, 0xDF, 0xE7, 0x7F, 0xF3, 0x6B,
  31359. 0x21, 0x03, 0xF1, 0xAD, 0x1A, 0xEE, 0xCE, 0xD1,
  31360. 0xC8, 0x14, 0xC2, 0xCD, 0x7E, 0xF1, 0x6B, 0xCE,
  31361. 0x47, 0x6A, 0xD0, 0x4F, 0x94, 0x1A, 0xFC, 0x79,
  31362. 0xE3, 0x29, 0x54, 0x74, 0xA4, 0x10, 0x62, 0x51,
  31363. 0x8C, 0x00, 0x37, 0x86, 0x09, 0x34, 0xF0, 0xE5,
  31364. 0xE6, 0x52, 0xF7, 0x27, 0x49, 0xA6, 0x98, 0x63,
  31365. 0x2A, 0x09, 0x91, 0xF6, 0x13, 0xF5, 0xCB, 0x96,
  31366. 0xCA, 0x11, 0x78, 0xF9, 0x74, 0xF2, 0xC4, 0xAA,
  31367. 0x0C, 0xE6, 0x3D, 0xC2, 0x4E, 0x36, 0x4C, 0x92,
  31368. 0xA6, 0x43, 0xB9, 0x0A, 0x5F, 0x85, 0xA6, 0x2F,
  31369. 0xD4, 0xD8, 0xD2, 0xB1, 0x93, 0xD2, 0x9B, 0x18,
  31370. 0xBE, 0xDE, 0x26, 0x53, 0xFC, 0x5D, 0x3F, 0x24,
  31371. 0xF5, 0xB2, 0xC0, 0x18, 0xDB, 0xBC, 0xB6, 0xEF,
  31372. 0x00, 0xF3, 0x05, 0xBF, 0x93, 0x66, 0x6B, 0xD4,
  31373. 0x7F, 0xEA, 0x91, 0x93, 0xBC, 0x23, 0x3D, 0xB3,
  31374. 0x91, 0x21, 0x44, 0x2E, 0x93, 0x8D, 0xA5, 0xDD,
  31375. 0x07, 0xEE, 0x6E, 0x87, 0x9C, 0x5B, 0x9D, 0xFF,
  31376. 0x41, 0xEC, 0xEE, 0x5E, 0x05, 0x89, 0xAE, 0x61,
  31377. 0x75, 0xFF, 0x5E, 0xC6, 0xF6, 0xD2, 0x62, 0x9F,
  31378. 0x56, 0xB1, 0x8B, 0x4D, 0xE6, 0x6F, 0xCB, 0x13,
  31379. 0xDF, 0x04, 0x00, 0xA7, 0x97, 0xC9, 0x22, 0x70,
  31380. 0xF6, 0x9B, 0xDE, 0xBD, 0xDC, 0xB8, 0x8C, 0x42,
  31381. 0x48, 0x91, 0x9B, 0x56, 0xCD, 0xA7, 0x0B, 0x8A,
  31382. 0xC4, 0xF9, 0x42, 0x9C, 0x29, 0x2D, 0xA9, 0x4D,
  31383. 0x64, 0x78, 0x28, 0x07, 0x64, 0xFE, 0x23, 0x86,
  31384. 0xFC, 0x38, 0xCB, 0x09, 0x31, 0x45, 0x88, 0x39,
  31385. 0xEF, 0x4E, 0x7D, 0xE8, 0xF0, 0x68, 0x9D, 0x99,
  31386. 0x80, 0x59, 0x88, 0xC7, 0xF9, 0x61, 0x11, 0x85,
  31387. 0x2C, 0x89, 0x29, 0xE5, 0xA5, 0x40, 0xD3, 0xB7,
  31388. 0x8D, 0x71, 0x2D, 0xEC, 0xC3, 0x96, 0xFE, 0xF3,
  31389. 0xEC, 0x34, 0x40, 0x21, 0x84, 0xE4, 0xFD, 0x29,
  31390. 0xF3, 0x63, 0xEA, 0x80, 0xF6, 0xFC, 0x50, 0xBA,
  31391. 0x9A, 0x11, 0x35, 0x1A, 0xCE, 0xEA, 0x8F, 0xE6,
  31392. 0x8D, 0x54, 0x1E, 0x1A, 0xA5, 0x84, 0x8D, 0x9F,
  31393. 0x6E, 0x61, 0xDF, 0xB6, 0x2B, 0x2F, 0x23, 0xBC,
  31394. 0x50, 0x81, 0xE8, 0x2F, 0x76, 0x22, 0x6E, 0x03,
  31395. 0x28, 0x49, 0x82, 0xEC, 0x48, 0x48, 0x12, 0x09,
  31396. 0xB1, 0xA7, 0xD4, 0xC8, 0x79, 0x7E, 0x44, 0xBF,
  31397. 0xA8, 0x70, 0xB2, 0x20, 0x04, 0xDB, 0x74, 0xBD,
  31398. 0x7D, 0x47, 0x8D, 0x5B, 0x36, 0x14, 0xD2, 0xB1,
  31399. 0xDA, 0x75, 0x02, 0xB3, 0x98, 0xEB, 0x9D, 0xA8,
  31400. 0x0D, 0x06, 0x46, 0x1E, 0x90, 0xE0, 0x30, 0x60,
  31401. 0x44, 0x6A, 0xB4, 0xA8, 0x23, 0x84, 0x32, 0xBF,
  31402. 0xAF, 0x75, 0x2F, 0x39, 0x17, 0x91, 0x21, 0x4F,
  31403. 0x1E, 0x6B, 0x63, 0x59, 0x0D, 0x53, 0x60, 0x60,
  31404. 0xD1, 0xC2, 0x45, 0x30, 0x7B, 0xC5, 0xC1, 0xBA,
  31405. 0xC4, 0xAA, 0xA0, 0x99, 0xD3, 0x6B, 0xB6, 0xDC,
  31406. 0xBC, 0x97, 0x3C, 0xF2, 0xE6, 0x9F, 0x27, 0x34,
  31407. 0xD0, 0xF2, 0x9A, 0xEE, 0xC4, 0x56, 0x7B, 0x99,
  31408. 0xA1, 0x6B, 0xC1, 0x7C, 0x6C, 0xDD, 0xAC, 0xEF,
  31409. 0xE4, 0x99, 0x27, 0xFB, 0x14, 0xE7, 0xD9, 0x8D,
  31410. 0xD4, 0x26, 0x35, 0x19, 0x46, 0x9C, 0xCA, 0x3D,
  31411. 0xB4, 0x67, 0x9A, 0x68, 0xCE, 0xED, 0xA9, 0x55,
  31412. 0x59, 0x22, 0x10, 0xFC, 0x49, 0xAA, 0x5F, 0xBE,
  31413. 0x93, 0x4C, 0xC7, 0x3D, 0x84, 0xE4, 0xBA, 0x54,
  31414. 0x78, 0x00, 0x2D, 0x68, 0x90, 0x98, 0x90, 0x68,
  31415. 0xEF, 0x8F, 0xC9, 0x8C, 0x25, 0x32, 0xB8, 0x3B,
  31416. 0xF3, 0xCB, 0x9E, 0xF0, 0x28, 0x93, 0xC2, 0x15,
  31417. 0x24, 0x26, 0xB9, 0xD1, 0xA9, 0x47, 0x34, 0xDF,
  31418. 0xB4, 0xF9, 0x11, 0x35, 0x14, 0x3C, 0x9E, 0xED,
  31419. 0x18, 0xFD, 0x51, 0xAE, 0x87, 0x5D, 0x07, 0xA2,
  31420. 0x37, 0x75, 0x60, 0x6A, 0x73, 0x4F, 0xBA, 0x98,
  31421. 0xC0, 0x63, 0xB4, 0xA1, 0x62, 0x2E, 0x7F, 0xF2,
  31422. 0x1A, 0xA7, 0xE6, 0x52, 0xA3, 0xD6, 0xC1, 0x9F,
  31423. 0xE0, 0xDC, 0x67, 0x61, 0xB7, 0xD3, 0x53, 0x02,
  31424. 0xBF, 0x21, 0x4D, 0x30, 0x79, 0xF7, 0x60, 0x51,
  31425. 0x08, 0x2A, 0x87, 0x59, 0x29, 0x92, 0x0D, 0xC3,
  31426. 0xB3, 0xCB, 0x43, 0x21, 0x1A, 0x23, 0xA4, 0x3A,
  31427. 0x50, 0x33, 0x2F, 0xAF, 0x1A, 0xC2, 0x19, 0x1E,
  31428. 0x71, 0x71, 0x25, 0xF6, 0x3E, 0x25, 0x86, 0xC4,
  31429. 0xD8, 0x6D, 0xCA, 0x6B, 0xCD, 0x3D, 0x03, 0x8F,
  31430. 0x9D, 0x3A, 0x7B, 0x66, 0xCB, 0xC7, 0xDF, 0x34
  31431. };
  31432. static const byte sk_44[] = {
  31433. 0xBC, 0x5F, 0xF8, 0x10, 0xEB, 0x08, 0x90, 0x48,
  31434. 0xB8, 0xAB, 0x30, 0x20, 0xA7, 0xBD, 0x3B, 0x16,
  31435. 0xC0, 0xE0, 0xCA, 0x3D, 0x6B, 0x97, 0xE4, 0x64,
  31436. 0x6C, 0x2C, 0xCA, 0xE0, 0xBB, 0xF1, 0x9E, 0xF7,
  31437. 0xBA, 0x2B, 0x57, 0xC4, 0x46, 0x55, 0x6E, 0xE2,
  31438. 0xB7, 0x2C, 0x78, 0xB9, 0x6B, 0xB7, 0xA8, 0x50,
  31439. 0x3D, 0xE4, 0x0A, 0xFB, 0x54, 0x18, 0x4E, 0x3B,
  31440. 0x54, 0x63, 0xC2, 0x1A, 0xF7, 0x48, 0x53, 0x23,
  31441. 0xDF, 0x98, 0xF0, 0x16, 0x0A, 0xE5, 0xD1, 0x37,
  31442. 0x51, 0x27, 0x25, 0xF8, 0x9D, 0x56, 0x3B, 0xC9,
  31443. 0xA1, 0x89, 0xD3, 0x1D, 0x20, 0xB3, 0xB3, 0xC8,
  31444. 0xFF, 0xAA, 0xF5, 0xE4, 0x86, 0xE7, 0x90, 0x51,
  31445. 0xF6, 0xF3, 0x60, 0x5C, 0xCA, 0x25, 0x69, 0xFD,
  31446. 0xB4, 0x6B, 0x33, 0x18, 0xD2, 0x38, 0x42, 0xCE,
  31447. 0x40, 0xD6, 0x43, 0x86, 0x13, 0xF6, 0x8B, 0x45,
  31448. 0x5B, 0x0D, 0x3B, 0xCA, 0x0E, 0x05, 0x0D, 0x4D,
  31449. 0x11, 0x99, 0x88, 0xA2, 0xC4, 0x80, 0x1B, 0x90,
  31450. 0x84, 0xE0, 0xB0, 0x48, 0xC9, 0x28, 0x09, 0x22,
  31451. 0x30, 0x90, 0x24, 0x06, 0x49, 0x98, 0x40, 0x65,
  31452. 0x5A, 0x26, 0x8A, 0xDA, 0x32, 0x90, 0xDA, 0x48,
  31453. 0x08, 0x22, 0x81, 0x90, 0xC8, 0x14, 0x61, 0xDC,
  31454. 0x16, 0x6A, 0x21, 0x47, 0x8E, 0x08, 0xB2, 0x21,
  31455. 0xE3, 0x08, 0x68, 0x1A, 0x02, 0x44, 0x14, 0xC6,
  31456. 0x65, 0xE1, 0x98, 0x71, 0x90, 0xC6, 0x69, 0x0C,
  31457. 0x15, 0x44, 0xC9, 0xA0, 0x11, 0xCC, 0x34, 0x71,
  31458. 0x83, 0x40, 0x45, 0x00, 0x12, 0x4D, 0x91, 0x08,
  31459. 0x00, 0x83, 0x36, 0x84, 0x12, 0x85, 0x4C, 0xCC,
  31460. 0x00, 0x41, 0x09, 0x90, 0x70, 0x18, 0x95, 0x00,
  31461. 0xA2, 0xB2, 0x85, 0x94, 0x26, 0x41, 0x0B, 0x00,
  31462. 0x41, 0x0A, 0xB9, 0x80, 0xC0, 0xC6, 0x10, 0x0C,
  31463. 0x33, 0x29, 0xA3, 0xA6, 0x28, 0x1C, 0x26, 0x10,
  31464. 0x1A, 0x37, 0x49, 0x13, 0x35, 0x8A, 0x0B, 0x29,
  31465. 0x2E, 0x82, 0xA2, 0x70, 0x8B, 0x38, 0x49, 0x94,
  31466. 0x04, 0x80, 0x9B, 0x26, 0x10, 0xA4, 0x80, 0x30,
  31467. 0x04, 0x37, 0x0C, 0x48, 0xB2, 0x60, 0x04, 0x17,
  31468. 0x2E, 0x19, 0x49, 0x64, 0xC8, 0xC4, 0x64, 0x1A,
  31469. 0x96, 0x60, 0x10, 0x83, 0x6D, 0x20, 0x38, 0x22,
  31470. 0x49, 0x06, 0x08, 0x1B, 0xB7, 0x20, 0x01, 0x48,
  31471. 0x4D, 0xE1, 0x10, 0x49, 0x08, 0x38, 0x44, 0x4C,
  31472. 0x16, 0x8E, 0x04, 0xB2, 0x2C, 0x09, 0x91, 0x50,
  31473. 0x83, 0x36, 0x06, 0x5C, 0x02, 0x8C, 0x8A, 0x38,
  31474. 0x05, 0x1A, 0xB5, 0x81, 0x82, 0xC0, 0x09, 0x51,
  31475. 0x12, 0x72, 0x22, 0x10, 0x0D, 0x04, 0x08, 0x2A,
  31476. 0xA4, 0x84, 0x10, 0x58, 0x08, 0x52, 0x08, 0x26,
  31477. 0x0A, 0x02, 0xB6, 0x2D, 0x8A, 0x12, 0x0E, 0x14,
  31478. 0x22, 0x10, 0x48, 0x44, 0x0A, 0x14, 0x23, 0x91,
  31479. 0x50, 0x40, 0x90, 0x0A, 0x27, 0x92, 0xA4, 0xB0,
  31480. 0x60, 0x08, 0x84, 0x11, 0xC4, 0x40, 0x22, 0x63,
  31481. 0x46, 0x2A, 0xDA, 0xA6, 0x90, 0xC1, 0xB2, 0x30,
  31482. 0x50, 0x10, 0x00, 0xA0, 0xB4, 0x6C, 0x53, 0xB4,
  31483. 0x50, 0x13, 0x05, 0x8D, 0x02, 0x31, 0x0E, 0x08,
  31484. 0x20, 0x10, 0x91, 0xC8, 0x4C, 0x22, 0xA7, 0x50,
  31485. 0xC2, 0xA6, 0x70, 0x92, 0x46, 0x41, 0x63, 0x16,
  31486. 0x8C, 0x84, 0x00, 0x11, 0x0B, 0x81, 0x90, 0x13,
  31487. 0x83, 0x71, 0x21, 0x85, 0x30, 0x1B, 0x18, 0x46,
  31488. 0xA3, 0x10, 0x84, 0x14, 0x43, 0x40, 0x80, 0x98,
  31489. 0x25, 0x0C, 0x27, 0x2C, 0x94, 0x42, 0x41, 0xA2,
  31490. 0x88, 0x45, 0x02, 0x13, 0x05, 0x44, 0xB6, 0x44,
  31491. 0x52, 0x22, 0x92, 0xD0, 0x80, 0x50, 0x4B, 0xA6,
  31492. 0x04, 0x84, 0x36, 0x70, 0x09, 0xB2, 0x4D, 0x19,
  31493. 0xA8, 0x84, 0x24, 0x93, 0x49, 0x94, 0xA2, 0x80,
  31494. 0x49, 0xB4, 0x48, 0x91, 0x28, 0x64, 0xA1, 0xC8,
  31495. 0x65, 0x4B, 0x82, 0x85, 0x93, 0x30, 0x06, 0x63,
  31496. 0x12, 0x66, 0x10, 0x37, 0x01, 0x4A, 0x40, 0x80,
  31497. 0x18, 0x18, 0x90, 0x44, 0xC4, 0x0D, 0x4B, 0x28,
  31498. 0x81, 0xA2, 0x06, 0x40, 0xD4, 0x30, 0x2C, 0x1B,
  31499. 0x96, 0x4C, 0xE1, 0xB2, 0x60, 0x44, 0x28, 0x41,
  31500. 0xD8, 0x30, 0x65, 0x24, 0x09, 0x04, 0x64, 0x00,
  31501. 0x89, 0x63, 0xC2, 0x24, 0xC0, 0x00, 0x49, 0x92,
  31502. 0x16, 0x52, 0x23, 0xC1, 0x29, 0x42, 0x26, 0x91,
  31503. 0xD0, 0x38, 0x31, 0x83, 0x28, 0x28, 0x4C, 0x28,
  31504. 0x61, 0x1A, 0xB2, 0x88, 0x80, 0x26, 0x2D, 0x0C,
  31505. 0x19, 0x52, 0x5B, 0x22, 0x60, 0x8A, 0x92, 0x28,
  31506. 0xA2, 0x18, 0x90, 0xD9, 0x42, 0x52, 0xCB, 0x40,
  31507. 0x8E, 0x9B, 0x16, 0x06, 0x4B, 0xC8, 0x05, 0xE0,
  31508. 0x06, 0x6C, 0x49, 0xC2, 0x25, 0xD4, 0x22, 0x69,
  31509. 0x14, 0x11, 0x69, 0x1C, 0x34, 0x90, 0x0C, 0x85,
  31510. 0x8D, 0x1C, 0x84, 0x49, 0x63, 0x10, 0x85, 0x08,
  31511. 0x34, 0x89, 0x58, 0x16, 0x66, 0xA0, 0x38, 0x68,
  31512. 0x0B, 0xA2, 0x50, 0xE0, 0x84, 0x61, 0xC1, 0x26,
  31513. 0x6E, 0xC9, 0x14, 0x6A, 0xC0, 0xC0, 0x31, 0x84,
  31514. 0x18, 0x2E, 0xDC, 0x16, 0x52, 0x14, 0x18, 0x91,
  31515. 0x0A, 0x39, 0x2C, 0x83, 0xA6, 0x8D, 0x12, 0x29,
  31516. 0x62, 0x92, 0xA6, 0x60, 0x08, 0xA5, 0x10, 0xD9,
  31517. 0xC8, 0x4D, 0x24, 0x48, 0x24, 0x83, 0x98, 0x24,
  31518. 0x1A, 0x44, 0x42, 0x08, 0x08, 0x48, 0xC8, 0x96,
  31519. 0x2D, 0xA1, 0x10, 0x20, 0x60, 0x24, 0x51, 0x9C,
  31520. 0x30, 0x11, 0xDB, 0xC8, 0x04, 0x11, 0x22, 0x51,
  31521. 0x18, 0x04, 0x68, 0xE2, 0x24, 0x4E, 0x10, 0xC4,
  31522. 0x0D, 0x18, 0x37, 0x29, 0x11, 0xB7, 0x84, 0x43,
  31523. 0x84, 0x8D, 0x54, 0x40, 0x70, 0x64, 0x80, 0x70,
  31524. 0x21, 0xB0, 0x4D, 0x00, 0x26, 0x62, 0x00, 0x45,
  31525. 0x25, 0x1B, 0x83, 0x84, 0x84, 0x80, 0x70, 0x19,
  31526. 0xB0, 0x04, 0x0A, 0xC9, 0x28, 0xCA, 0x80, 0x05,
  31527. 0x1B, 0x21, 0x4E, 0xD4, 0xB0, 0x49, 0x8C, 0x96,
  31528. 0x6C, 0xD0, 0x96, 0x25, 0x48, 0x32, 0x72, 0x54,
  31529. 0x12, 0x05, 0x09, 0x98, 0x8C, 0x8A, 0x32, 0x6D,
  31530. 0xC0, 0x04, 0x31, 0x63, 0xC8, 0x61, 0xC8, 0xC2,
  31531. 0x68, 0x9B, 0xB4, 0x8C, 0x5B, 0xC0, 0x2D, 0xC3,
  31532. 0xA8, 0x8D, 0x1B, 0x16, 0x6C, 0xD8, 0x96, 0x41,
  31533. 0x98, 0x34, 0x02, 0x44, 0x14, 0x2C, 0xD3, 0x86,
  31534. 0x44, 0x0A, 0x18, 0x8A, 0x1A, 0x46, 0x92, 0x1A,
  31535. 0xB7, 0x08, 0x4C, 0x34, 0x24, 0x21, 0x91, 0x0D,
  31536. 0x9A, 0x96, 0x2D, 0xCB, 0x24, 0x22, 0x92, 0x86,
  31537. 0x08, 0x98, 0xA0, 0x50, 0xDA, 0x44, 0x6A, 0x19,
  31538. 0xB1, 0x05, 0x8B, 0x20, 0x6E, 0x24, 0xC4, 0x81,
  31539. 0xC9, 0x98, 0x40, 0x22, 0x19, 0x32, 0x11, 0x05,
  31540. 0x69, 0xD3, 0x94, 0x91, 0x08, 0xA7, 0x71, 0xDB,
  31541. 0xC0, 0x70, 0x02, 0xB8, 0x28, 0x83, 0xB4, 0x49,
  31542. 0xA0, 0x44, 0x8A, 0x0B, 0xB4, 0x10, 0x61, 0x02,
  31543. 0x48, 0x1C, 0xA6, 0x11, 0xE3, 0x20, 0x66, 0x40,
  31544. 0xB4, 0x70, 0x03, 0xB6, 0x04, 0x60, 0x48, 0x21,
  31545. 0x5B, 0x21, 0x83, 0x39, 0x88, 0xDB, 0x67, 0x4A,
  31546. 0x61, 0xE7, 0xC2, 0x08, 0xDE, 0xBE, 0x8D, 0xAE,
  31547. 0x41, 0x19, 0xAF, 0xB0, 0x26, 0x61, 0xA6, 0x9A,
  31548. 0xBC, 0x8B, 0xDD, 0x24, 0x5B, 0x5D, 0x0F, 0xB1,
  31549. 0xA2, 0x67, 0x01, 0xC9, 0xB9, 0xC9, 0xA8, 0xF7,
  31550. 0xD9, 0xFC, 0xD4, 0xC2, 0x87, 0xFF, 0x3D, 0x60,
  31551. 0x8C, 0xF2, 0x58, 0x28, 0x2A, 0x1E, 0xB2, 0x9F,
  31552. 0x93, 0x04, 0xE8, 0x9C, 0x14, 0xF3, 0xE1, 0xCE,
  31553. 0x56, 0x12, 0x89, 0x1C, 0x60, 0x29, 0x34, 0x52,
  31554. 0x60, 0x06, 0xC9, 0x9B, 0x4A, 0xA2, 0x39, 0x9B,
  31555. 0xF4, 0x94, 0xBC, 0xF8, 0xDF, 0x61, 0xD6, 0xDF,
  31556. 0x4C, 0x69, 0xBC, 0x93, 0xE0, 0x2D, 0x49, 0x95,
  31557. 0xE2, 0xF7, 0x6E, 0x9F, 0xDA, 0x4E, 0xF6, 0x7E,
  31558. 0xB7, 0x25, 0x6C, 0xA8, 0x9A, 0x3F, 0x38, 0xFE,
  31559. 0xB2, 0xE9, 0xDF, 0x6A, 0x01, 0x0D, 0xC1, 0xC1,
  31560. 0x50, 0x02, 0xFB, 0xD4, 0x56, 0xFA, 0xE8, 0x84,
  31561. 0x82, 0x1A, 0x34, 0x16, 0x6B, 0x06, 0x58, 0xA2,
  31562. 0x41, 0x25, 0x95, 0x71, 0x8E, 0x14, 0x9B, 0xBC,
  31563. 0x6E, 0x22, 0x0A, 0xEE, 0x26, 0x8D, 0x4D, 0x82,
  31564. 0x18, 0xC2, 0x5F, 0x6A, 0x95, 0x7D, 0xE5, 0xB2,
  31565. 0x6C, 0xEA, 0x7B, 0x14, 0xCB, 0x32, 0x0D, 0x89,
  31566. 0xE1, 0x69, 0x9A, 0xD9, 0xF2, 0xB3, 0x89, 0xC6,
  31567. 0x7E, 0xF9, 0x33, 0x86, 0xA2, 0xC6, 0x5F, 0x2C,
  31568. 0x32, 0x23, 0x33, 0x67, 0xD7, 0x6A, 0xE4, 0xAB,
  31569. 0x2A, 0xBB, 0xD4, 0x22, 0xE9, 0x8E, 0x49, 0x3D,
  31570. 0xCC, 0x3C, 0xC5, 0xDA, 0xF6, 0x89, 0xB6, 0x5C,
  31571. 0xC4, 0xBC, 0x3F, 0xA5, 0x1C, 0x9C, 0x59, 0xEE,
  31572. 0xAF, 0x07, 0x55, 0x17, 0x0C, 0x24, 0x95, 0x80,
  31573. 0x4D, 0x02, 0xA6, 0x07, 0xC5, 0xBF, 0x88, 0x7C,
  31574. 0xD8, 0x6A, 0x03, 0x89, 0xF2, 0x8F, 0xC9, 0x72,
  31575. 0x5E, 0xF4, 0x60, 0x03, 0xF1, 0x3B, 0x01, 0x87,
  31576. 0x68, 0x4B, 0xEA, 0xB1, 0xF2, 0x4A, 0x29, 0xF5,
  31577. 0x31, 0x96, 0x01, 0xF3, 0x09, 0xC9, 0x1D, 0x2A,
  31578. 0x33, 0x3D, 0x1B, 0x88, 0xDF, 0x20, 0x5A, 0x51,
  31579. 0x20, 0xC4, 0xCF, 0xDC, 0x22, 0x38, 0x12, 0x4E,
  31580. 0x4E, 0x2B, 0x47, 0xD0, 0xB5, 0xE6, 0x6A, 0x65,
  31581. 0x4F, 0xE4, 0xCC, 0xCB, 0x07, 0x8F, 0x07, 0xCB,
  31582. 0xD4, 0x55, 0xD1, 0x5D, 0x3E, 0xEC, 0x7D, 0xA2,
  31583. 0x74, 0xD2, 0x4A, 0x2E, 0x57, 0x18, 0x84, 0xDE,
  31584. 0x41, 0xC3, 0xA9, 0xA4, 0xFD, 0xB3, 0xF6, 0x09,
  31585. 0x8A, 0x17, 0x2C, 0x30, 0x96, 0x80, 0x39, 0xBD,
  31586. 0x0E, 0x4E, 0xB3, 0xE2, 0xFB, 0x6D, 0x6E, 0xEE,
  31587. 0xD3, 0x9E, 0x0B, 0x63, 0x62, 0xD5, 0x4E, 0x7B,
  31588. 0x88, 0x95, 0x98, 0x69, 0xDD, 0xD5, 0xD8, 0x73,
  31589. 0xD9, 0x65, 0x24, 0x01, 0xA2, 0x9F, 0x27, 0xA2,
  31590. 0x8E, 0xA6, 0x6D, 0x32, 0xCC, 0xB0, 0xEF, 0x3B,
  31591. 0xF4, 0x60, 0x0F, 0x75, 0x57, 0xEE, 0x8D, 0x54,
  31592. 0xBF, 0x1D, 0xAD, 0x18, 0xF4, 0x5D, 0xDC, 0xD4,
  31593. 0xC9, 0xED, 0x57, 0xB1, 0x3E, 0x44, 0x5B, 0xF1,
  31594. 0x22, 0xA4, 0x3F, 0x53, 0x94, 0x03, 0x89, 0xBF,
  31595. 0x87, 0x14, 0xFF, 0xAC, 0x72, 0x1E, 0x59, 0x31,
  31596. 0x7E, 0x4B, 0x70, 0x50, 0x0A, 0xD0, 0xD1, 0xB9,
  31597. 0xA6, 0x27, 0x05, 0x4D, 0x31, 0x93, 0x20, 0x8C,
  31598. 0x77, 0x4E, 0x0B, 0x20, 0xED, 0x04, 0x1A, 0x8C,
  31599. 0x05, 0x5E, 0x75, 0xEE, 0xCD, 0x37, 0x38, 0xF0,
  31600. 0x07, 0x15, 0x8F, 0xAD, 0xDF, 0xCA, 0x5F, 0x43,
  31601. 0x56, 0x2D, 0x63, 0x6A, 0x5A, 0xCF, 0x3A, 0x39,
  31602. 0x83, 0xD3, 0xCF, 0xEB, 0xCA, 0x10, 0xB8, 0x13,
  31603. 0xF9, 0xF6, 0x52, 0x65, 0x19, 0x19, 0x9A, 0x03,
  31604. 0x13, 0xCD, 0x1D, 0xE1, 0x3F, 0x06, 0xAD, 0x53,
  31605. 0x86, 0xE1, 0xE1, 0x20, 0x79, 0x5F, 0xD2, 0x67,
  31606. 0xB7, 0xF4, 0x20, 0x19, 0xD8, 0x4D, 0xF6, 0xCD,
  31607. 0x1B, 0xF9, 0x19, 0x30, 0xFC, 0xA7, 0xAF, 0xD5,
  31608. 0x2E, 0x80, 0x70, 0x0F, 0x4C, 0xF5, 0xCD, 0xC3,
  31609. 0x8A, 0x5F, 0x7A, 0x57, 0x49, 0x79, 0x1C, 0x2F,
  31610. 0xDF, 0xFC, 0x4A, 0x10, 0x75, 0x3C, 0x24, 0xDB,
  31611. 0x19, 0xE8, 0xEB, 0x65, 0x1C, 0x5B, 0x36, 0x32,
  31612. 0x00, 0xF0, 0xB5, 0xD1, 0x69, 0x94, 0x70, 0x26,
  31613. 0xE9, 0xF7, 0x4F, 0x01, 0x2D, 0xC7, 0xC5, 0xB3,
  31614. 0x39, 0xDD, 0x49, 0xD2, 0x61, 0xCA, 0x1D, 0x37,
  31615. 0xF8, 0xF2, 0x83, 0x46, 0xE6, 0x19, 0x78, 0x05,
  31616. 0x4F, 0x45, 0xAE, 0xE4, 0x36, 0xDC, 0xCB, 0xE7,
  31617. 0xBF, 0xAF, 0xE0, 0x7C, 0xE9, 0xA8, 0xB8, 0x3C,
  31618. 0x90, 0xA2, 0x68, 0x6F, 0xA9, 0x54, 0x02, 0x85,
  31619. 0x09, 0x25, 0xC8, 0x58, 0x2B, 0xC9, 0xB7, 0x34,
  31620. 0xE4, 0xEC, 0xA1, 0xF7, 0xB2, 0x0B, 0x08, 0x6F,
  31621. 0x12, 0x9F, 0x27, 0x7A, 0x5C, 0xBD, 0xAA, 0x96,
  31622. 0x3C, 0x92, 0x71, 0x7E, 0xF7, 0x0E, 0xC1, 0x9B,
  31623. 0xF3, 0xDB, 0xC6, 0xDA, 0x20, 0x3A, 0xD9, 0x0F,
  31624. 0x3B, 0x13, 0xBB, 0xC2, 0x2F, 0xBD, 0x98, 0x0B,
  31625. 0xB1, 0xB9, 0xD3, 0xA3, 0x44, 0x52, 0xB3, 0x35,
  31626. 0x70, 0x21, 0xCE, 0x36, 0x13, 0x58, 0x4E, 0x09,
  31627. 0x36, 0xBF, 0x1D, 0x09, 0x42, 0x09, 0x37, 0x81,
  31628. 0x5E, 0x11, 0xCC, 0x5D, 0x5D, 0xDB, 0x4B, 0xF1,
  31629. 0xD8, 0x30, 0xC4, 0xF8, 0x3F, 0x30, 0xE5, 0x15,
  31630. 0x92, 0x1C, 0x78, 0x4D, 0x87, 0xBB, 0x20, 0xC0,
  31631. 0x9E, 0x3C, 0x64, 0xBD, 0xCE, 0x9A, 0xB1, 0xC6,
  31632. 0x9F, 0xD3, 0x07, 0xEF, 0xE3, 0x59, 0xC7, 0xF9,
  31633. 0x38, 0x56, 0x6C, 0x9F, 0x25, 0x17, 0xB0, 0x63,
  31634. 0x38, 0x51, 0x67, 0xE2, 0x47, 0xF3, 0x10, 0x81,
  31635. 0x11, 0x9B, 0xAC, 0x6B, 0x55, 0xA0, 0xBD, 0xD7,
  31636. 0x14, 0x25, 0x51, 0x0F, 0xFA, 0x2A, 0xBD, 0xFA,
  31637. 0x88, 0x83, 0x76, 0xA3, 0x7F, 0x20, 0xC2, 0x48,
  31638. 0x01, 0x52, 0xBB, 0x36, 0x16, 0x34, 0x52, 0x00,
  31639. 0x07, 0xC5, 0xB3, 0x4B, 0xF2, 0x28, 0x17, 0xCB,
  31640. 0x2E, 0x67, 0xAC, 0x1A, 0x82, 0x67, 0x0B, 0x71,
  31641. 0xF1, 0x96, 0xC8, 0x9F, 0x23, 0xBA, 0x31, 0x4B,
  31642. 0x16, 0xA9, 0x48, 0x49, 0x93, 0x04, 0xEF, 0x5C,
  31643. 0x03, 0xDC, 0xF5, 0x8E, 0x52, 0xBE, 0x31, 0x48,
  31644. 0x63, 0xE7, 0x23, 0xC5, 0x6D, 0x3A, 0xEB, 0x34,
  31645. 0x0B, 0xFF, 0x18, 0xAB, 0xFA, 0x20, 0xDC, 0x03,
  31646. 0x44, 0x20, 0x30, 0x23, 0x05, 0x33, 0xD9, 0x12,
  31647. 0x9B, 0x83, 0xED, 0x22, 0xC3, 0x51, 0xF2, 0x32,
  31648. 0x81, 0x72, 0xE3, 0x63, 0x44, 0x74, 0x44, 0xAE,
  31649. 0x5C, 0x69, 0x02, 0xB7, 0x92, 0x79, 0x9F, 0x54,
  31650. 0x44, 0x50, 0x78, 0x71, 0x19, 0x61, 0x2E, 0x9B,
  31651. 0xB4, 0x13, 0x0A, 0x33, 0xA2, 0xA5, 0x96, 0x2A,
  31652. 0xC0, 0x9D, 0x57, 0x7D, 0x6D, 0xDC, 0x88, 0x1F,
  31653. 0xE6, 0x61, 0x61, 0x26, 0xD8, 0xA0, 0xA7, 0xDF,
  31654. 0x2B, 0x22, 0x53, 0xBC, 0x8E, 0xC4, 0xE3, 0x53,
  31655. 0x86, 0xEA, 0x55, 0x11, 0xF0, 0xF1, 0x58, 0x87,
  31656. 0x14, 0x5B, 0x6C, 0x23, 0xAB, 0x3D, 0x40, 0x33,
  31657. 0x39, 0xE4, 0x04, 0x07, 0x3E, 0xD9, 0xC6, 0xA8,
  31658. 0x96, 0xA2, 0xF9, 0xEC, 0x70, 0xC4, 0x4B, 0xD2,
  31659. 0xAE, 0xC1, 0x0F, 0xC4, 0x36, 0x0E, 0x87, 0x63,
  31660. 0x6B, 0xE1, 0x55, 0xB6, 0xA6, 0x7B, 0x7E, 0xDF,
  31661. 0x38, 0xCF, 0x73, 0x00, 0x48, 0x13, 0xC9, 0xE7,
  31662. 0xD2, 0xC6, 0x54, 0xC2, 0x53, 0x0A, 0x71, 0xE5,
  31663. 0xF8, 0xC1, 0x09, 0x42, 0xFB, 0x6D, 0x88, 0x41,
  31664. 0x53, 0x5A, 0xB1, 0xDA, 0x43, 0xE8, 0xCB, 0x0B,
  31665. 0xB8, 0x9E, 0x78, 0xEC, 0x91, 0xF8, 0xDE, 0x15,
  31666. 0x31, 0xA0, 0x36, 0x65, 0xCC, 0xD5, 0xA7, 0x5B,
  31667. 0xDA, 0x0E, 0xD0, 0xE5, 0x98, 0x64, 0xEE, 0xEF,
  31668. 0x51, 0xA8, 0x3F, 0xA5, 0x53, 0xAF, 0x66, 0x2A,
  31669. 0xEE, 0x00, 0xD1, 0xF8, 0x36, 0x7B, 0x4D, 0x5D,
  31670. 0xDD, 0xC3, 0x45, 0x54, 0x4C, 0x6B, 0xD5, 0x14,
  31671. 0xF8, 0x88, 0xE6, 0x03, 0x3C, 0x25, 0x5D, 0xB6,
  31672. 0x50, 0xDA, 0x73, 0x4A, 0xD3, 0x3A, 0x3C, 0xF8,
  31673. 0x4B, 0xD3, 0xF0, 0x6F, 0xA1, 0xA7, 0xCA, 0x02,
  31674. 0xE4, 0xB8, 0xE9, 0x93, 0xAE, 0x7A, 0xE6, 0x34,
  31675. 0x20, 0xA4, 0x6B, 0xA8, 0xA3, 0x81, 0x3D, 0x1E,
  31676. 0x9D, 0x29, 0x66, 0xBB, 0x85, 0x60, 0xD7, 0x1C,
  31677. 0x62, 0xA0, 0x44, 0xEA, 0x94, 0x17, 0x9F, 0x4E,
  31678. 0xB1, 0xB6, 0xED, 0x60, 0x71, 0x9D, 0x51, 0xE0,
  31679. 0xEE, 0xF6, 0xCD, 0x07, 0x91, 0x52, 0xF6, 0xBE,
  31680. 0x48, 0x8E, 0xC9, 0x19, 0x11, 0xC6, 0xD3, 0xF1,
  31681. 0xD1, 0x17, 0x3C, 0x54, 0x1F, 0x9D, 0x25, 0xBF,
  31682. 0x34, 0x2F, 0xCA, 0xA3, 0xFF, 0x46, 0xC1, 0x8F,
  31683. 0x2A, 0x04, 0x41, 0xD8, 0x3B, 0xDE, 0x35, 0x46,
  31684. 0xA9, 0x82, 0x6C, 0x34, 0x96, 0xE0, 0x6F, 0x2F,
  31685. 0x2B, 0x0E, 0xEB, 0x9D, 0x5B, 0xE8, 0x73, 0x9F,
  31686. 0x83, 0xA4, 0x2D, 0x3B, 0x30, 0x0E, 0x70, 0xEE,
  31687. 0x84, 0xDF, 0xFF, 0xB2, 0x07, 0x64, 0xA0, 0x60,
  31688. 0x21, 0x2F, 0x05, 0x8C, 0x8A, 0x5F, 0xFA, 0x9A,
  31689. 0x34, 0xE9, 0x28, 0xD6, 0xA7, 0xE0, 0x77, 0x08,
  31690. 0xFE, 0x53, 0x93, 0xE3, 0x01, 0x7C, 0xE4, 0x70,
  31691. 0xEB, 0x96, 0x58, 0xA7, 0x4E, 0x49, 0x51, 0xE6,
  31692. 0xFA, 0x48, 0x54, 0xC9, 0xE9, 0xC2, 0x89, 0x88,
  31693. 0x81, 0x2E, 0x44, 0x18, 0xA2, 0xE8, 0x32, 0x58,
  31694. 0x0B, 0x4A, 0x27, 0x03, 0x72, 0xBC, 0x69, 0x67,
  31695. 0x68, 0x89, 0xD0, 0xCC, 0x43, 0x24, 0x0E, 0xDA,
  31696. 0xBC, 0x1D, 0x31, 0x14, 0xD8, 0xF3, 0x5A, 0xB2,
  31697. 0xE9, 0xEA, 0x95, 0x30, 0x82, 0xE9, 0x53, 0x62,
  31698. 0x79, 0xAC, 0xB3, 0xBE, 0x16, 0xD3, 0xA2, 0x05,
  31699. 0xF4, 0x6C, 0xB6, 0x7B, 0x22, 0x14, 0x96, 0x93,
  31700. 0x5A, 0xC0, 0x42, 0x92, 0xBB, 0xFB, 0x9A, 0x61,
  31701. 0xC0, 0xA0, 0x3E, 0xF4, 0xC9, 0xB6, 0x82, 0x04,
  31702. 0x95, 0xF3, 0xD8, 0x0E, 0x4A, 0x6F, 0xB7, 0xE1,
  31703. 0xC6, 0x99, 0x03, 0xFA, 0x22, 0x6E, 0x02, 0x3E,
  31704. 0x95, 0xBA, 0x41, 0x6D, 0xF2, 0xE5, 0xE4, 0x54,
  31705. 0x1E, 0x15, 0xDC, 0xC0, 0x00, 0xB5, 0xE6, 0x5C,
  31706. 0x97, 0x20, 0xDA, 0xF6, 0x96, 0x01, 0x2F, 0xA2,
  31707. 0xA6, 0xCF, 0x75, 0x8E, 0xD6, 0xD2, 0x25, 0xA3,
  31708. 0xE4, 0xFE, 0xE4, 0x5A, 0xC5, 0xFB, 0x48, 0x70,
  31709. 0x7F, 0xAE, 0x13, 0x3D, 0x59, 0x2C, 0xFD, 0x2E,
  31710. 0x8C, 0x43, 0xC2, 0x12, 0x6F, 0x65, 0x2B, 0xEE,
  31711. 0x9B, 0xAB, 0x43, 0xA1, 0xA1, 0x0B, 0xE2, 0x41,
  31712. 0x1A, 0x67, 0x94, 0xB2, 0x6C, 0xB5, 0x5C, 0xC2,
  31713. 0x17, 0xEB, 0x7B, 0x0B, 0x14, 0x6D, 0x23, 0xF7,
  31714. 0x92, 0x2D, 0x32, 0x22, 0xAE, 0x5E, 0xE8, 0xC6,
  31715. 0xD3, 0x8E, 0x83, 0x99, 0xBA, 0x51, 0xC6, 0x81,
  31716. 0xB8, 0x38, 0x16, 0xFC, 0xF7, 0x44, 0x38, 0x82,
  31717. 0x59, 0x20, 0xF9, 0xCE, 0x8A, 0x20, 0x2A, 0x8F,
  31718. 0x6D, 0x94, 0x2D, 0xA8, 0x62, 0x38, 0xFB, 0x4C,
  31719. 0x9F, 0x21, 0x98, 0xEA, 0x8D, 0xFF, 0x81, 0xC1,
  31720. 0x72, 0x86, 0xE0, 0x18, 0xDF, 0x4B, 0x7F, 0xE3,
  31721. 0x88, 0x4D, 0x17, 0x59, 0xE4, 0xC5, 0x9B, 0xB5,
  31722. 0x26, 0x17, 0xAE, 0xD4, 0xE7, 0x8E, 0x4E, 0x7C,
  31723. 0x4E, 0x9A, 0x36, 0xE4, 0xE9, 0x96, 0xD3, 0x23,
  31724. 0x91, 0xA3, 0x4A, 0x0D, 0xAA, 0xAB, 0x6B, 0x54,
  31725. 0x08, 0x15, 0xA3, 0x4D, 0x20, 0x40, 0x7A, 0xEF,
  31726. 0x81, 0x94, 0x9B, 0xE6, 0x7B, 0x90, 0x69, 0x50,
  31727. 0xD8, 0x9B, 0xE9, 0xF0, 0x85, 0xE9, 0x9E, 0xB5,
  31728. 0x87, 0x26, 0x95, 0x17, 0x3B, 0x3E, 0xFA, 0xCA,
  31729. 0xE9, 0x45, 0x5D, 0x2B, 0x2C, 0xD4, 0xF7, 0x10,
  31730. 0xB8, 0x72, 0xCF, 0x66, 0x2B, 0x73, 0x62, 0x16,
  31731. 0xB1, 0xBB, 0xFB, 0x1F, 0x5F, 0x3D, 0x48, 0x6C,
  31732. 0x7B, 0x4B, 0x87, 0x56, 0x12, 0x33, 0x3F, 0x8E,
  31733. 0x4B, 0xA9, 0x33, 0xDC, 0x79, 0xF0, 0xED, 0xFD,
  31734. 0x7B, 0xAA, 0xDE, 0x2C, 0x16, 0xF2, 0x14, 0x6A,
  31735. 0x49, 0x6F, 0x79, 0xC4, 0x2A, 0x4D, 0x6B, 0x52,
  31736. 0x39, 0xA3, 0x0D, 0xD3, 0xC4, 0x8B, 0xEB, 0x09,
  31737. 0x2C, 0xA0, 0x75, 0x00, 0x10, 0xF6, 0x9E, 0xD4,
  31738. 0xB9, 0x23, 0x20, 0x14, 0x7D, 0xBB, 0xE2, 0x08,
  31739. 0xF6, 0xE8, 0xEB, 0x1C, 0xF2, 0x47, 0xD2, 0x1A,
  31740. 0x3A, 0x3B, 0x01, 0xDF, 0x58, 0xC0, 0xAA, 0x62,
  31741. 0x94, 0x4D, 0xA0, 0xEF, 0x04, 0x50, 0xE8, 0xCE,
  31742. 0x48, 0xAA, 0x13, 0x7E, 0x7E, 0x15, 0x16, 0xC1,
  31743. 0xD5, 0xC8, 0x6E, 0xEA, 0x17, 0xFD, 0xFA, 0xC1,
  31744. 0x69, 0x07, 0x46, 0xE7, 0x26, 0x70, 0x45, 0xA3,
  31745. 0xE9, 0x05, 0x96, 0xBD, 0xB7, 0x5D, 0x50, 0xB6,
  31746. 0xDD, 0x5C, 0x34, 0xE5, 0xC8, 0xD8, 0x9D, 0xC6,
  31747. 0xF2, 0xF1, 0xD2, 0x44, 0x40, 0xE5, 0x7B, 0x47,
  31748. 0x59, 0xB8, 0x62, 0x5F, 0x72, 0xBC, 0x4A, 0x7B,
  31749. 0x10, 0xD5, 0x19, 0xD3, 0x31, 0xF9, 0xC4, 0x00,
  31750. 0xAA, 0xE1, 0xE5, 0x0D, 0x48, 0x0C, 0xAA, 0xE5,
  31751. 0xA1, 0xC0, 0xFA, 0x99, 0xD7, 0x79, 0x24, 0xCF,
  31752. 0x8D, 0xFE, 0x56, 0xCD, 0x70, 0x92, 0xE7, 0xB9
  31753. };
  31754. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  31755. #ifndef WOLFSSL_NO_ML_DSA_65
  31756. static const byte seed_65[] = {
  31757. 0x70, 0xCE, 0xFB, 0x9A, 0xED, 0x5B, 0x68, 0xE0,
  31758. 0x18, 0xB0, 0x79, 0xDA, 0x82, 0x84, 0xB9, 0xD5,
  31759. 0xCA, 0xD5, 0x49, 0x9E, 0xD9, 0xC2, 0x65, 0xFF,
  31760. 0x73, 0x58, 0x80, 0x05, 0xD8, 0x5C, 0x22, 0x5C
  31761. };
  31762. static const byte pk_65[] = {
  31763. 0xD2, 0xFD, 0x03, 0xF3, 0xA1, 0xB7, 0xF6, 0x35,
  31764. 0xAF, 0x9F, 0x34, 0xD5, 0x80, 0xA9, 0x8F, 0x52,
  31765. 0x4C, 0x73, 0x5B, 0xD5, 0xBA, 0x23, 0x55, 0xDC,
  31766. 0x6E, 0x03, 0x5B, 0xD2, 0x17, 0x65, 0x58, 0x0C,
  31767. 0xBB, 0x11, 0x19, 0x23, 0xF1, 0x94, 0xA7, 0xCC,
  31768. 0x8A, 0x7B, 0xB2, 0xEB, 0xC5, 0xC0, 0xE7, 0x1A,
  31769. 0xA6, 0x37, 0xCC, 0x80, 0x0E, 0x61, 0x03, 0xB8,
  31770. 0x50, 0xA5, 0x39, 0xB2, 0xA3, 0x9E, 0x1B, 0x6D,
  31771. 0x71, 0x3E, 0x5D, 0xB8, 0x31, 0x4C, 0x9A, 0xE1,
  31772. 0xF8, 0xBF, 0x8A, 0x38, 0xF0, 0x6A, 0xFB, 0x9D,
  31773. 0x73, 0xB1, 0x61, 0xB0, 0xFF, 0xE3, 0xA4, 0x89,
  31774. 0x17, 0x06, 0xAE, 0x26, 0xD5, 0x4F, 0xFB, 0x49,
  31775. 0x6D, 0xF8, 0xDC, 0x0F, 0x19, 0x83, 0x50, 0x95,
  31776. 0x00, 0xC9, 0xAB, 0xBD, 0x28, 0xE5, 0x9B, 0x3F,
  31777. 0xCD, 0xAB, 0xBD, 0xAD, 0xAB, 0xD4, 0x5E, 0xC3,
  31778. 0x14, 0x99, 0x37, 0x8B, 0xDE, 0x84, 0x9E, 0x7C,
  31779. 0x1F, 0x19, 0xB7, 0x04, 0x4D, 0x67, 0xE0, 0x51,
  31780. 0x06, 0xD7, 0x13, 0x6D, 0x95, 0x38, 0x0D, 0x56,
  31781. 0x05, 0xD4, 0x46, 0x5D, 0x87, 0x75, 0x57, 0x06,
  31782. 0x5D, 0xF0, 0xA7, 0x5D, 0x3C, 0x28, 0x54, 0x2F,
  31783. 0x40, 0xFE, 0xED, 0x42, 0xEC, 0x7E, 0x28, 0x06,
  31784. 0x37, 0xB0, 0x83, 0xD9, 0x88, 0xBC, 0xA5, 0xF6,
  31785. 0x39, 0x4E, 0x02, 0x39, 0x6C, 0x46, 0x76, 0x18,
  31786. 0x4F, 0xB6, 0x33, 0x18, 0xDA, 0xFA, 0xF5, 0xBB,
  31787. 0xDD, 0xE0, 0x0E, 0x30, 0x8F, 0xE8, 0x40, 0x19,
  31788. 0xC2, 0x34, 0x0A, 0x3F, 0x3E, 0x1C, 0x08, 0x65,
  31789. 0x62, 0x49, 0x70, 0x71, 0x12, 0x83, 0x35, 0x6A,
  31790. 0xE1, 0x4B, 0xD6, 0xB9, 0x4D, 0x1C, 0x9A, 0xE1,
  31791. 0x88, 0xDE, 0x1A, 0x8A, 0x2C, 0xA8, 0x24, 0xA8,
  31792. 0xEA, 0xE2, 0xFE, 0x6A, 0xFB, 0x38, 0xD8, 0x3A,
  31793. 0x2D, 0x99, 0x99, 0x6A, 0xB2, 0x1F, 0xE3, 0xE8,
  31794. 0x4C, 0x0B, 0xE6, 0xB6, 0xDA, 0x08, 0x87, 0x9B,
  31795. 0x67, 0x73, 0x74, 0xFA, 0x7C, 0x69, 0x1B, 0x13,
  31796. 0xD4, 0x0F, 0xA9, 0xD4, 0xCC, 0x26, 0xB2, 0x28,
  31797. 0x8D, 0x5A, 0x8C, 0x9A, 0x43, 0x72, 0x43, 0x81,
  31798. 0x00, 0x4D, 0x61, 0xB0, 0xD5, 0x7F, 0xF4, 0x00,
  31799. 0x31, 0x4C, 0x8E, 0x30, 0xEE, 0x79, 0x6A, 0xF1,
  31800. 0x0F, 0x7E, 0xE2, 0x1B, 0xF1, 0x3D, 0x08, 0x18,
  31801. 0x04, 0x65, 0xAB, 0xC7, 0x2E, 0xDD, 0xB0, 0x80,
  31802. 0xC6, 0xA0, 0x71, 0x84, 0xE3, 0xEE, 0xDC, 0x47,
  31803. 0xC1, 0x9A, 0xA7, 0xF0, 0x9D, 0x1F, 0x33, 0x09,
  31804. 0xE1, 0x83, 0xA2, 0xBD, 0x9B, 0x05, 0x73, 0xDD,
  31805. 0xE4, 0x74, 0xA8, 0x1B, 0xA4, 0xF7, 0x8D, 0x0C,
  31806. 0x52, 0x3D, 0x0C, 0x04, 0xF9, 0x00, 0x60, 0xFD,
  31807. 0x57, 0x1A, 0x35, 0xC0, 0x37, 0xE0, 0x79, 0xC5,
  31808. 0xE2, 0x10, 0xD7, 0x39, 0x0D, 0xF5, 0x68, 0xF2,
  31809. 0xE2, 0xF0, 0x3C, 0xE4, 0x44, 0x20, 0xC8, 0x2F,
  31810. 0x3F, 0xE6, 0x9E, 0xB9, 0xB4, 0x8E, 0xE9, 0x09,
  31811. 0x62, 0xD6, 0xB0, 0xF2, 0x44, 0x40, 0x64, 0x8F,
  31812. 0x71, 0xED, 0xB2, 0x41, 0xEE, 0x65, 0x66, 0xFC,
  31813. 0x1A, 0x64, 0xCA, 0xBF, 0x66, 0xBE, 0x6F, 0xEC,
  31814. 0xBC, 0xB1, 0x38, 0x7C, 0x82, 0xA7, 0xBC, 0x20,
  31815. 0x2D, 0x9E, 0x36, 0x79, 0x98, 0xE2, 0xA2, 0x91,
  31816. 0xAF, 0x0C, 0xD1, 0x57, 0x06, 0x77, 0xFE, 0x8D,
  31817. 0x63, 0xA3, 0x28, 0x5A, 0x2E, 0xA6, 0xEB, 0x29,
  31818. 0xAF, 0x9D, 0xC1, 0xAE, 0xC1, 0xC3, 0x6C, 0x47,
  31819. 0x06, 0xB1, 0x2B, 0xAA, 0x20, 0x83, 0x96, 0x92,
  31820. 0xF2, 0x86, 0xA6, 0xE0, 0x32, 0x14, 0x68, 0xF7,
  31821. 0x47, 0x93, 0x45, 0xC4, 0xD5, 0x2F, 0xBD, 0xB2,
  31822. 0xF0, 0x67, 0x25, 0xB5, 0x54, 0xB8, 0x9E, 0x24,
  31823. 0x92, 0x61, 0x26, 0x81, 0xAC, 0xEB, 0xC6, 0xC7,
  31824. 0xBA, 0xDA, 0x92, 0x25, 0x81, 0x8D, 0xBC, 0x35,
  31825. 0xD6, 0x4C, 0x22, 0xC4, 0x8B, 0xFF, 0x80, 0xA7,
  31826. 0x30, 0xD0, 0x71, 0x6D, 0xFA, 0xC9, 0x9D, 0xFD,
  31827. 0x5B, 0x89, 0x92, 0x61, 0x1D, 0x0C, 0x93, 0xEE,
  31828. 0x90, 0xBD, 0xB2, 0x60, 0x02, 0x2A, 0xFE, 0x25,
  31829. 0xD9, 0x13, 0xE0, 0x6E, 0xFF, 0xB5, 0x9C, 0xB1,
  31830. 0xF8, 0xA6, 0x0C, 0xBF, 0xA5, 0xAB, 0x2F, 0x45,
  31831. 0x9A, 0x16, 0xF4, 0x67, 0xE9, 0x89, 0x52, 0x5E,
  31832. 0x0A, 0x37, 0xEB, 0xE5, 0x6E, 0x83, 0x3F, 0xDE,
  31833. 0x55, 0xDB, 0x9D, 0x15, 0x30, 0xAD, 0xCF, 0x45,
  31834. 0x84, 0x6D, 0xF2, 0x81, 0xE4, 0x7C, 0xAA, 0x1E,
  31835. 0x0A, 0x27, 0xEF, 0xDE, 0x21, 0x07, 0xD3, 0x54,
  31836. 0xCE, 0xA0, 0xF6, 0xA4, 0x54, 0x69, 0x2F, 0x04,
  31837. 0xCD, 0x83, 0x8E, 0xBD, 0xD4, 0x6E, 0x19, 0x1E,
  31838. 0x5D, 0x9C, 0x11, 0x83, 0x9A, 0x2C, 0x3F, 0x48,
  31839. 0x8A, 0x4F, 0xC7, 0xCD, 0x26, 0x5A, 0x7B, 0x5D,
  31840. 0x32, 0xB0, 0x8C, 0xBD, 0xBF, 0xAB, 0x9D, 0x2C,
  31841. 0xCD, 0x76, 0x22, 0x2C, 0x8E, 0xE3, 0x7D, 0xDC,
  31842. 0xBD, 0x2A, 0xA0, 0x63, 0xED, 0x86, 0x14, 0x73,
  31843. 0xA6, 0x45, 0x4C, 0xAE, 0xA3, 0x77, 0x85, 0x0B,
  31844. 0x1A, 0x2B, 0x9D, 0xDB, 0xBC, 0xB3, 0x74, 0xFA,
  31845. 0xB5, 0xB1, 0x2F, 0x35, 0x1C, 0x8E, 0x58, 0x88,
  31846. 0x87, 0x2E, 0x5C, 0xD1, 0xF6, 0x0A, 0x4F, 0xAE,
  31847. 0x1F, 0xF8, 0x37, 0xD1, 0x92, 0xC2, 0x2B, 0xEB,
  31848. 0x41, 0xEE, 0x6F, 0xA3, 0x92, 0xFC, 0xDF, 0x45,
  31849. 0x50, 0xFF, 0x46, 0xB5, 0xCE, 0x90, 0x6D, 0x01,
  31850. 0x7E, 0xF3, 0x07, 0x7D, 0xF1, 0x32, 0x30, 0x0D,
  31851. 0x8B, 0xBF, 0xA9, 0xBB, 0x03, 0xC7, 0x5E, 0x79,
  31852. 0xE2, 0xF0, 0x4C, 0x28, 0x4A, 0xD0, 0x6A, 0x44,
  31853. 0x39, 0x96, 0x49, 0xC3, 0xE2, 0xA2, 0xA8, 0xD1,
  31854. 0xEF, 0xE9, 0xB7, 0xA4, 0xE0, 0xC2, 0x71, 0x04,
  31855. 0x7A, 0xB7, 0x59, 0x08, 0xBF, 0xF7, 0xDF, 0x9E,
  31856. 0x30, 0xEC, 0xA5, 0x47, 0x74, 0x5B, 0xAE, 0x23,
  31857. 0xA8, 0x6F, 0xF9, 0xA8, 0xB5, 0x8C, 0x25, 0x38,
  31858. 0xB8, 0x8B, 0x86, 0x64, 0x01, 0x07, 0x69, 0x02,
  31859. 0xDC, 0x5F, 0x0B, 0xD7, 0x61, 0x68, 0x7B, 0x49,
  31860. 0xEA, 0xFE, 0x36, 0xD3, 0x50, 0xCB, 0xED, 0xFD,
  31861. 0xD3, 0x6C, 0x12, 0x1C, 0xF2, 0x37, 0x86, 0xBF,
  31862. 0xCF, 0x7E, 0x47, 0x07, 0x64, 0x96, 0xEA, 0xB6,
  31863. 0xBB, 0xDA, 0x77, 0x40, 0x49, 0xC2, 0xEB, 0xAB,
  31864. 0xE2, 0xDE, 0x99, 0xC4, 0xC2, 0x4F, 0x2D, 0xB7,
  31865. 0x36, 0x84, 0x01, 0x5B, 0x37, 0x39, 0x77, 0x49,
  31866. 0x67, 0x60, 0xCF, 0x9A, 0xC2, 0x3D, 0x8B, 0x62,
  31867. 0x31, 0x33, 0xDB, 0x2D, 0xE1, 0x0D, 0x73, 0xFA,
  31868. 0x6A, 0xD1, 0xC6, 0xDA, 0xC8, 0x43, 0x4F, 0x28,
  31869. 0xC6, 0xE2, 0x51, 0xCE, 0x72, 0x93, 0xCF, 0xF3,
  31870. 0xF3, 0xB6, 0x1E, 0xFC, 0xB5, 0xA4, 0x35, 0x12,
  31871. 0x36, 0x70, 0xF2, 0x98, 0x46, 0xA1, 0x3D, 0xF3,
  31872. 0xEE, 0x71, 0x26, 0x04, 0x46, 0x1F, 0x1B, 0xAB,
  31873. 0x8F, 0x4E, 0xBC, 0x83, 0x6D, 0xE0, 0x58, 0x97,
  31874. 0x8A, 0xE7, 0x34, 0x39, 0x6A, 0x98, 0x08, 0x1B,
  31875. 0x35, 0xCC, 0x98, 0x18, 0x8A, 0x86, 0x94, 0x9C,
  31876. 0x99, 0x27, 0x0D, 0x47, 0x09, 0x85, 0x4C, 0x5B,
  31877. 0x35, 0xB1, 0x7F, 0x48, 0xA3, 0x73, 0x13, 0x4C,
  31878. 0x81, 0x4C, 0xC8, 0xA0, 0xF3, 0xE2, 0xFA, 0x80,
  31879. 0x7F, 0x2A, 0x91, 0x85, 0x30, 0x90, 0x78, 0x64,
  31880. 0x77, 0x82, 0x82, 0xD7, 0x5E, 0x03, 0xA4, 0x1B,
  31881. 0x25, 0x04, 0xEE, 0xD8, 0x16, 0xA4, 0x17, 0xA3,
  31882. 0xAC, 0x6B, 0xA1, 0x60, 0x80, 0xC3, 0x9B, 0x73,
  31883. 0x10, 0x19, 0x20, 0x02, 0xA7, 0x28, 0xF7, 0xF2,
  31884. 0x03, 0x95, 0x00, 0x9A, 0x9E, 0x16, 0x76, 0x7C,
  31885. 0xE1, 0x97, 0x1F, 0x5D, 0xE7, 0xD2, 0x29, 0xA5,
  31886. 0x06, 0x13, 0x36, 0x9E, 0x43, 0x82, 0x04, 0x5A,
  31887. 0x8E, 0x81, 0x90, 0x1F, 0x4D, 0xBA, 0x81, 0x02,
  31888. 0xF3, 0xD4, 0x13, 0xFE, 0x35, 0xB3, 0x26, 0xA8,
  31889. 0x74, 0xF2, 0x33, 0xB7, 0x19, 0xA7, 0x13, 0x76,
  31890. 0x00, 0xD3, 0x5D, 0x33, 0xAE, 0xB6, 0xB7, 0x25,
  31891. 0x96, 0x24, 0x08, 0x3A, 0xA9, 0x68, 0x73, 0x0C,
  31892. 0x8F, 0x78, 0x29, 0x2A, 0xD2, 0x8F, 0x14, 0xEE,
  31893. 0xAB, 0xE6, 0x60, 0x83, 0x59, 0x84, 0xFE, 0x69,
  31894. 0xEF, 0x23, 0xDE, 0xC8, 0xC3, 0x27, 0xC0, 0xEB,
  31895. 0x0B, 0x88, 0x2D, 0x58, 0x7E, 0x1E, 0xC4, 0x33,
  31896. 0xDA, 0x85, 0xC9, 0xFD, 0x1E, 0x0A, 0x34, 0x99,
  31897. 0x4D, 0xEA, 0x24, 0x0C, 0x85, 0x44, 0x52, 0xD1,
  31898. 0x8C, 0x30, 0xF4, 0x96, 0xE4, 0x9E, 0xC9, 0x04,
  31899. 0xB6, 0x02, 0xE0, 0xF5, 0x06, 0x2E, 0xDC, 0xDA,
  31900. 0x03, 0x28, 0x0A, 0x53, 0xB4, 0x31, 0x35, 0x74,
  31901. 0xCC, 0x2C, 0x0D, 0x54, 0x71, 0xBC, 0x96, 0x13,
  31902. 0xBD, 0xFD, 0x66, 0x41, 0xF5, 0xBD, 0x12, 0x7B,
  31903. 0xAB, 0x5B, 0x5E, 0xB3, 0xD4, 0x99, 0xA3, 0x31,
  31904. 0x14, 0x04, 0x82, 0x20, 0xE8, 0x19, 0xF8, 0xEE,
  31905. 0x12, 0xCA, 0x92, 0x2C, 0x8F, 0x17, 0xD9, 0xC9,
  31906. 0xF5, 0x1A, 0xD5, 0xBD, 0x68, 0x83, 0xB1, 0x0E,
  31907. 0x6A, 0xA2, 0x48, 0x3B, 0xA4, 0x9D, 0xC5, 0x47,
  31908. 0xDA, 0x76, 0x86, 0x15, 0x13, 0x44, 0xF4, 0xE9,
  31909. 0x09, 0x9B, 0x38, 0xE4, 0x30, 0xB5, 0x22, 0x6B,
  31910. 0x05, 0x98, 0x32, 0xCF, 0x03, 0xDB, 0x48, 0xFB,
  31911. 0x02, 0xDB, 0xA4, 0xE6, 0x15, 0x93, 0xDC, 0x45,
  31912. 0x76, 0x36, 0x04, 0x91, 0x89, 0x0E, 0x53, 0xEC,
  31913. 0x0E, 0x6A, 0xC7, 0x3C, 0xF3, 0x2B, 0x25, 0xD8,
  31914. 0x23, 0xB3, 0x84, 0x56, 0xE2, 0x86, 0x50, 0x5A,
  31915. 0x54, 0x1E, 0x5A, 0xEE, 0xE9, 0x6B, 0x19, 0x14,
  31916. 0xF5, 0xF7, 0x66, 0x87, 0xCE, 0x2B, 0x01, 0x60,
  31917. 0x22, 0x7A, 0xBE, 0xD7, 0x79, 0x93, 0x59, 0x4B,
  31918. 0xCD, 0x83, 0x13, 0x66, 0x20, 0x6D, 0x75, 0x71,
  31919. 0x40, 0x82, 0xF1, 0xC4, 0x6F, 0x1F, 0x44, 0x39,
  31920. 0xAC, 0x81, 0xA5, 0x7A, 0xF3, 0x1C, 0x81, 0xC5,
  31921. 0x55, 0x30, 0x7A, 0x07, 0x0F, 0xFA, 0x94, 0xE0,
  31922. 0x47, 0x9B, 0x78, 0x4B, 0xBD, 0x88, 0xA6, 0x0C,
  31923. 0xD4, 0xC7, 0xCF, 0xD9, 0x4E, 0x6A, 0xFE, 0x02,
  31924. 0xF6, 0xB2, 0x1F, 0x72, 0xAF, 0x0D, 0xCD, 0x66,
  31925. 0x09, 0xD4, 0x0C, 0x96, 0x5C, 0x14, 0xE5, 0xF2,
  31926. 0x38, 0x91, 0x83, 0xE5, 0x3D, 0xE9, 0x30, 0xF7,
  31927. 0xDE, 0x1D, 0x44, 0x21, 0x5C, 0xF4, 0x91, 0x44,
  31928. 0x84, 0x4E, 0x8B, 0x87, 0xF7, 0x8A, 0x7F, 0x13,
  31929. 0x2A, 0xEF, 0xE2, 0x2B, 0xE8, 0x0B, 0x4E, 0x3A,
  31930. 0x05, 0xEE, 0x3A, 0x68, 0xCC, 0xF6, 0x09, 0xEF,
  31931. 0x44, 0x04, 0x74, 0x02, 0xE4, 0x49, 0x30, 0x46,
  31932. 0xE6, 0xF9, 0xC7, 0x67, 0xFF, 0x8A, 0x75, 0xE2,
  31933. 0x8B, 0x3C, 0xE0, 0x77, 0xFD, 0xE7, 0xE7, 0xEE,
  31934. 0xD3, 0x13, 0xB5, 0xBF, 0x7E, 0x46, 0x01, 0x27,
  31935. 0xCA, 0x81, 0x82, 0xE9, 0xBC, 0x79, 0x4C, 0x0D,
  31936. 0xFA, 0x73, 0x0F, 0xB9, 0x20, 0x08, 0x05, 0x75,
  31937. 0xA7, 0x51, 0xB5, 0xCA, 0xEC, 0x85, 0xA1, 0x09,
  31938. 0xB4, 0x42, 0x2B, 0xA2, 0x66, 0x74, 0x3F, 0x0D,
  31939. 0x03, 0x2B, 0xDA, 0x8F, 0x1C, 0xA6, 0x24, 0x8C,
  31940. 0xDB, 0x91, 0x75, 0x30, 0xDF, 0x13, 0x02, 0xA5,
  31941. 0xF8, 0xC1, 0x8D, 0xC6, 0x42, 0xD5, 0x24, 0x78,
  31942. 0xC9, 0x8C, 0x12, 0xA3, 0xF1, 0x6E, 0xF2, 0xB6,
  31943. 0x2B, 0x4F, 0x59, 0xEA, 0x1B, 0xB5, 0x8D, 0xE7,
  31944. 0xB6, 0x5B, 0x3C, 0x71, 0x53, 0xCE, 0x6D, 0xA5,
  31945. 0xE4, 0x95, 0x07, 0x46, 0xF8, 0x0E, 0x08, 0x7A,
  31946. 0x0E, 0x35, 0x86, 0xD0, 0x97, 0x79, 0x1B, 0xF3,
  31947. 0x6D, 0xEF, 0x86, 0x5D, 0x68, 0x59, 0x1D, 0x39,
  31948. 0xD0, 0x90, 0x37, 0x73, 0xEE, 0xA9, 0x62, 0x14,
  31949. 0x7F, 0x34, 0x70, 0x41, 0x38, 0xB5, 0x4D, 0xF7,
  31950. 0x92, 0x4C, 0xDD, 0x8C, 0x33, 0x3D, 0xB5, 0xE1,
  31951. 0xA4, 0x09, 0xCC, 0xB2, 0xB3, 0x4E, 0x2C, 0x3C,
  31952. 0x8C, 0x7F, 0xDD, 0x3F, 0xD8, 0xD0, 0x12, 0xCB,
  31953. 0xF3, 0x82, 0xAA, 0xA8, 0x5E, 0x83, 0xA1, 0x2F,
  31954. 0x23, 0x5A, 0x2D, 0x14, 0x7D, 0x03, 0x5B, 0x7B,
  31955. 0x28, 0xB3, 0x4B, 0x6F, 0x57, 0x94, 0x9F, 0x32,
  31956. 0x24, 0x82, 0xA7, 0xD4, 0xD3, 0xB1, 0x50, 0x45,
  31957. 0xC4, 0x20, 0xD5, 0xAD, 0xDC, 0x7F, 0x0E, 0x69,
  31958. 0xB4, 0xDC, 0x1C, 0xBA, 0x58, 0xB0, 0x1D, 0x87,
  31959. 0x24, 0x80, 0xB0, 0x6A, 0x26, 0x0D, 0x82, 0x7D,
  31960. 0x89, 0x1B, 0x13, 0xC4, 0xC5, 0xCA, 0x50, 0xC7,
  31961. 0x48, 0xDE, 0x3C, 0x77, 0x1B, 0xE6, 0x1E, 0x9A,
  31962. 0xA1, 0x70, 0x16, 0x5C, 0xB0, 0x1F, 0x4B, 0xF5,
  31963. 0xDA, 0x27, 0xA7, 0x79, 0x1D, 0x3A, 0xD3, 0xF6,
  31964. 0x26, 0x7B, 0x4C, 0xB4, 0xE6, 0x1B, 0x28, 0xFA,
  31965. 0x17, 0x08, 0x41, 0x8D, 0x93, 0x2D, 0xFC, 0x41,
  31966. 0x61, 0x88, 0x0C, 0x5D, 0x3B, 0x17, 0xA9, 0x66,
  31967. 0x3A, 0x90, 0x61, 0xFA, 0x8F, 0x18, 0x04, 0x31,
  31968. 0x58, 0x50, 0xFE, 0x4E, 0x73, 0x06, 0xC8, 0x82,
  31969. 0xB3, 0x82, 0x27, 0xE8, 0x67, 0xF8, 0x08, 0x72,
  31970. 0xCD, 0xC1, 0x94, 0x4D, 0x47, 0x26, 0x15, 0xEA,
  31971. 0x49, 0x00, 0xEF, 0x7D, 0x27, 0x0B, 0x88, 0x1D,
  31972. 0x41, 0x30, 0xF5, 0x6C, 0x5C, 0xC9, 0x80, 0xD9,
  31973. 0x2A, 0x47, 0xAD, 0xA6, 0x65, 0x7E, 0xB6, 0xF3,
  31974. 0x7A, 0x38, 0x5D, 0x2D, 0x8C, 0xC9, 0x93, 0xE1,
  31975. 0x44, 0x2E, 0xB0, 0x52, 0x81, 0x85, 0x36, 0x36,
  31976. 0x99, 0x1E, 0x34, 0xAA, 0xDC, 0x68, 0x95, 0x4D,
  31977. 0x04, 0xE7, 0xAD, 0xEF, 0x76, 0xBF, 0x88, 0x0F,
  31978. 0x05, 0x9B, 0x0C, 0xBB, 0x55, 0xD9, 0x15, 0xA4,
  31979. 0xB1, 0x23, 0xE2, 0xF1, 0x33, 0x9A, 0x07, 0x3C,
  31980. 0xBF, 0xBC, 0x40, 0x9B, 0xEF, 0xF6, 0x40, 0x0A,
  31981. 0xE0, 0x96, 0xD5, 0xAE, 0x18, 0xEC, 0x42, 0xCF,
  31982. 0xFA, 0xD5, 0xB4, 0x98, 0x0F, 0xA3, 0x5B, 0xF0,
  31983. 0x34, 0x13, 0xAD, 0xB5, 0xD7, 0xE6, 0x87, 0x6A,
  31984. 0xC3, 0x55, 0xD1, 0xC9, 0xED, 0x70, 0xCA, 0x2B,
  31985. 0x97, 0x39, 0x54, 0xD1, 0x2B, 0x3C, 0xDD, 0x76,
  31986. 0xAC, 0x68, 0x35, 0xDB, 0x96, 0x00, 0x3E, 0xD8,
  31987. 0xC4, 0xE2, 0x88, 0xB7, 0x1F, 0xD7, 0x7D, 0xBA,
  31988. 0xA7, 0x63, 0x57, 0x20, 0xE1, 0x2A, 0xE0, 0xA3,
  31989. 0x17, 0xDE, 0x80, 0x8C, 0x66, 0x4E, 0x31, 0x7F,
  31990. 0x55, 0x27, 0x57, 0x91, 0xF3, 0x24, 0x5C, 0xA4,
  31991. 0xFE, 0x5D, 0x4D, 0x41, 0x07, 0x7F, 0xC1, 0x50,
  31992. 0xA6, 0xE4, 0x03, 0xD5, 0xA2, 0x08, 0xE4, 0x6E,
  31993. 0xAD, 0xBE, 0x8F, 0x2C, 0xFB, 0x8A, 0xF4, 0x72,
  31994. 0xF4, 0xA0, 0xCE, 0xAC, 0x01, 0x52, 0x19, 0x47,
  31995. 0x8E, 0x6B, 0x86, 0xC9, 0x58, 0xCF, 0x86, 0x52,
  31996. 0x5B, 0x74, 0x85, 0xC1, 0x73, 0x4C, 0x7E, 0xF0,
  31997. 0x0E, 0x90, 0x68, 0x3F, 0xFF, 0x5D, 0xBD, 0x0A,
  31998. 0x7D, 0x41, 0x3A, 0x85, 0x50, 0x21, 0x02, 0x6A,
  31999. 0x1B, 0x32, 0x01, 0x3A, 0x46, 0x16, 0xCB, 0xCD,
  32000. 0x37, 0x00, 0xAC, 0xBC, 0x70, 0x5B, 0xE3, 0xEF,
  32001. 0xBA, 0x62, 0x5C, 0x69, 0xA0, 0x25, 0x26, 0x7B,
  32002. 0xCE, 0x9D, 0x13, 0x5E, 0x3F, 0x5B, 0x5C, 0xC8,
  32003. 0xC4, 0x39, 0x56, 0x40, 0x7E, 0x84, 0xB6, 0x66,
  32004. 0x31, 0x03, 0xE2, 0x9C, 0x24, 0x20, 0x35, 0x55,
  32005. 0x1A, 0xE7, 0x97, 0xF5, 0x6C, 0x63, 0x74, 0xBE,
  32006. 0x0C, 0x79, 0x8C, 0x0C, 0xF3, 0x98, 0xF1, 0xED
  32007. };
  32008. static const byte sk_65[] = {
  32009. 0xD2, 0xFD, 0x03, 0xF3, 0xA1, 0xB7, 0xF6, 0x35,
  32010. 0xAF, 0x9F, 0x34, 0xD5, 0x80, 0xA9, 0x8F, 0x52,
  32011. 0x4C, 0x73, 0x5B, 0xD5, 0xBA, 0x23, 0x55, 0xDC,
  32012. 0x6E, 0x03, 0x5B, 0xD2, 0x17, 0x65, 0x58, 0x0C,
  32013. 0xE3, 0x8D, 0x1C, 0x14, 0xF6, 0x46, 0x7C, 0x35,
  32014. 0xA9, 0xF3, 0x80, 0xD2, 0x7D, 0xE6, 0x1F, 0x7C,
  32015. 0x75, 0x03, 0x15, 0x69, 0xEA, 0x2E, 0xC8, 0x26,
  32016. 0x0E, 0xEE, 0x91, 0x05, 0x26, 0x1B, 0x7F, 0xE1,
  32017. 0x60, 0xC9, 0x13, 0x44, 0xB0, 0xC6, 0x76, 0x4C,
  32018. 0x20, 0x4E, 0x5B, 0x8D, 0x42, 0x46, 0x50, 0xBE,
  32019. 0xC0, 0x6B, 0x9E, 0x2E, 0x62, 0x5A, 0xF0, 0x7E,
  32020. 0x23, 0xF4, 0x95, 0x0C, 0xA2, 0x4F, 0xB4, 0xD6,
  32021. 0xEC, 0x2C, 0x8B, 0x3A, 0x71, 0x7C, 0x93, 0x11,
  32022. 0xEB, 0x87, 0x27, 0x9F, 0xE2, 0x5E, 0x31, 0x1F,
  32023. 0x48, 0xB8, 0x25, 0x65, 0x01, 0xF6, 0x46, 0x34,
  32024. 0x12, 0xB5, 0x0D, 0xBC, 0x89, 0xA8, 0x69, 0xBA,
  32025. 0x22, 0x41, 0x11, 0x26, 0x48, 0x40, 0x07, 0x38,
  32026. 0x73, 0x02, 0x12, 0x44, 0x25, 0x44, 0x57, 0x54,
  32027. 0x83, 0x72, 0x50, 0x33, 0x35, 0x62, 0x58, 0x42,
  32028. 0x32, 0x01, 0x62, 0x11, 0x83, 0x61, 0x02, 0x45,
  32029. 0x66, 0x56, 0x48, 0x35, 0x61, 0x20, 0x84, 0x52,
  32030. 0x60, 0x68, 0x50, 0x45, 0x65, 0x55, 0x12, 0x72,
  32031. 0x47, 0x47, 0x21, 0x21, 0x25, 0x40, 0x22, 0x21,
  32032. 0x42, 0x81, 0x17, 0x65, 0x03, 0x06, 0x42, 0x61,
  32033. 0x52, 0x13, 0x43, 0x25, 0x24, 0x33, 0x82, 0x12,
  32034. 0x11, 0x35, 0x62, 0x33, 0x32, 0x07, 0x47, 0x86,
  32035. 0x22, 0x31, 0x50, 0x83, 0x70, 0x84, 0x26, 0x43,
  32036. 0x45, 0x64, 0x51, 0x48, 0x31, 0x14, 0x86, 0x24,
  32037. 0x66, 0x86, 0x74, 0x33, 0x71, 0x36, 0x67, 0x26,
  32038. 0x01, 0x47, 0x07, 0x72, 0x11, 0x61, 0x58, 0x85,
  32039. 0x58, 0x38, 0x71, 0x83, 0x80, 0x67, 0x01, 0x65,
  32040. 0x78, 0x70, 0x64, 0x77, 0x85, 0x60, 0x02, 0x88,
  32041. 0x53, 0x48, 0x46, 0x62, 0x25, 0x83, 0x54, 0x88,
  32042. 0x04, 0x74, 0x40, 0x12, 0x57, 0x43, 0x71, 0x07,
  32043. 0x75, 0x44, 0x38, 0x71, 0x21, 0x14, 0x22, 0x08,
  32044. 0x88, 0x72, 0x23, 0x58, 0x87, 0x46, 0x14, 0x85,
  32045. 0x53, 0x71, 0x67, 0x73, 0x82, 0x28, 0x22, 0x74,
  32046. 0x14, 0x03, 0x57, 0x73, 0x28, 0x71, 0x83, 0x80,
  32047. 0x78, 0x14, 0x34, 0x87, 0x52, 0x07, 0x64, 0x74,
  32048. 0x01, 0x60, 0x75, 0x61, 0x06, 0x08, 0x61, 0x32,
  32049. 0x21, 0x46, 0x15, 0x65, 0x42, 0x67, 0x08, 0x20,
  32050. 0x84, 0x10, 0x73, 0x13, 0x03, 0x61, 0x02, 0x86,
  32051. 0x50, 0x45, 0x26, 0x12, 0x16, 0x68, 0x33, 0x55,
  32052. 0x25, 0x84, 0x73, 0x53, 0x54, 0x52, 0x65, 0x17,
  32053. 0x10, 0x60, 0x00, 0x38, 0x57, 0x77, 0x81, 0x24,
  32054. 0x26, 0x80, 0x41, 0x46, 0x43, 0x26, 0x67, 0x41,
  32055. 0x06, 0x03, 0x55, 0x41, 0x28, 0x33, 0x37, 0x25,
  32056. 0x23, 0x06, 0x77, 0x82, 0x15, 0x16, 0x31, 0x73,
  32057. 0x00, 0x08, 0x75, 0x26, 0x58, 0x46, 0x34, 0x63,
  32058. 0x88, 0x08, 0x84, 0x64, 0x51, 0x11, 0x24, 0x05,
  32059. 0x32, 0x10, 0x11, 0x18, 0x18, 0x64, 0x78, 0x22,
  32060. 0x41, 0x00, 0x38, 0x55, 0x75, 0x42, 0x10, 0x46,
  32061. 0x83, 0x43, 0x73, 0x38, 0x80, 0x07, 0x83, 0x43,
  32062. 0x78, 0x74, 0x13, 0x57, 0x62, 0x32, 0x68, 0x80,
  32063. 0x65, 0x86, 0x48, 0x53, 0x48, 0x35, 0x51, 0x58,
  32064. 0x50, 0x74, 0x46, 0x05, 0x88, 0x70, 0x07, 0x72,
  32065. 0x01, 0x31, 0x00, 0x87, 0x54, 0x88, 0x14, 0x20,
  32066. 0x84, 0x16, 0x61, 0x15, 0x60, 0x56, 0x85, 0x11,
  32067. 0x58, 0x08, 0x05, 0x88, 0x63, 0x01, 0x82, 0x86,
  32068. 0x13, 0x14, 0x17, 0x22, 0x01, 0x68, 0x17, 0x17,
  32069. 0x86, 0x58, 0x53, 0x10, 0x62, 0x28, 0x52, 0x82,
  32070. 0x26, 0x15, 0x04, 0x31, 0x42, 0x88, 0x54, 0x31,
  32071. 0x78, 0x05, 0x80, 0x11, 0x50, 0x45, 0x68, 0x82,
  32072. 0x33, 0x66, 0x36, 0x36, 0x40, 0x65, 0x15, 0x24,
  32073. 0x47, 0x67, 0x06, 0x45, 0x36, 0x42, 0x26, 0x86,
  32074. 0x75, 0x06, 0x35, 0x41, 0x33, 0x47, 0x85, 0x12,
  32075. 0x17, 0x80, 0x83, 0x87, 0x65, 0x51, 0x42, 0x31,
  32076. 0x38, 0x87, 0x56, 0x62, 0x05, 0x17, 0x40, 0x85,
  32077. 0x28, 0x14, 0x17, 0x21, 0x38, 0x12, 0x60, 0x81,
  32078. 0x24, 0x41, 0x45, 0x75, 0x01, 0x82, 0x87, 0x10,
  32079. 0x10, 0x02, 0x13, 0x25, 0x57, 0x04, 0x21, 0x72,
  32080. 0x42, 0x78, 0x61, 0x11, 0x70, 0x05, 0x30, 0x47,
  32081. 0x72, 0x13, 0x20, 0x30, 0x21, 0x67, 0x44, 0x31,
  32082. 0x57, 0x71, 0x45, 0x57, 0x10, 0x54, 0x16, 0x65,
  32083. 0x74, 0x15, 0x24, 0x02, 0x43, 0x71, 0x51, 0x20,
  32084. 0x55, 0x11, 0x67, 0x83, 0x67, 0x82, 0x52, 0x53,
  32085. 0x35, 0x66, 0x42, 0x46, 0x13, 0x70, 0x22, 0x32,
  32086. 0x74, 0x00, 0x07, 0x06, 0x81, 0x87, 0x17, 0x57,
  32087. 0x80, 0x28, 0x68, 0x01, 0x72, 0x10, 0x04, 0x27,
  32088. 0x55, 0x22, 0x86, 0x42, 0x53, 0x15, 0x81, 0x76,
  32089. 0x30, 0x86, 0x40, 0x83, 0x11, 0x43, 0x30, 0x53,
  32090. 0x82, 0x73, 0x53, 0x03, 0x72, 0x35, 0x68, 0x70,
  32091. 0x45, 0x41, 0x15, 0x73, 0x14, 0x12, 0x31, 0x64,
  32092. 0x32, 0x66, 0x63, 0x56, 0x21, 0x51, 0x50, 0x82,
  32093. 0x10, 0x30, 0x23, 0x38, 0x17, 0x21, 0x27, 0x10,
  32094. 0x23, 0x14, 0x22, 0x75, 0x77, 0x28, 0x37, 0x71,
  32095. 0x62, 0x75, 0x06, 0x88, 0x72, 0x14, 0x18, 0x73,
  32096. 0x13, 0x03, 0x01, 0x50, 0x71, 0x58, 0x62, 0x86,
  32097. 0x62, 0x88, 0x86, 0x86, 0x03, 0x27, 0x01, 0x46,
  32098. 0x17, 0x22, 0x71, 0x38, 0x53, 0x81, 0x70, 0x33,
  32099. 0x88, 0x68, 0x13, 0x78, 0x81, 0x04, 0x86, 0x57,
  32100. 0x30, 0x16, 0x52, 0x31, 0x40, 0x83, 0x07, 0x56,
  32101. 0x82, 0x10, 0x32, 0x31, 0x28, 0x50, 0x06, 0x50,
  32102. 0x81, 0x63, 0x06, 0x75, 0x76, 0x65, 0x11, 0x60,
  32103. 0x14, 0x17, 0x12, 0x12, 0x55, 0x56, 0x48, 0x11,
  32104. 0x41, 0x13, 0x28, 0x82, 0x62, 0x07, 0x47, 0x64,
  32105. 0x24, 0x48, 0x23, 0x24, 0x77, 0x53, 0x26, 0x08,
  32106. 0x17, 0x58, 0x11, 0x56, 0x37, 0x48, 0x35, 0x51,
  32107. 0x47, 0x86, 0x85, 0x66, 0x66, 0x81, 0x73, 0x20,
  32108. 0x21, 0x36, 0x75, 0x22, 0x74, 0x66, 0x83, 0x44,
  32109. 0x57, 0x00, 0x66, 0x64, 0x77, 0x20, 0x47, 0x22,
  32110. 0x28, 0x56, 0x87, 0x12, 0x47, 0x02, 0x48, 0x07,
  32111. 0x02, 0x54, 0x23, 0x01, 0x25, 0x71, 0x37, 0x36,
  32112. 0x75, 0x36, 0x00, 0x52, 0x68, 0x15, 0x33, 0x35,
  32113. 0x82, 0x06, 0x13, 0x73, 0x24, 0x08, 0x71, 0x76,
  32114. 0x15, 0x22, 0x42, 0x60, 0x18, 0x53, 0x43, 0x11,
  32115. 0x64, 0x57, 0x76, 0x17, 0x61, 0x56, 0x68, 0x76,
  32116. 0x60, 0x65, 0x54, 0x78, 0x10, 0x33, 0x63, 0x14,
  32117. 0x21, 0x83, 0x21, 0x60, 0x15, 0x55, 0x80, 0x42,
  32118. 0x38, 0x42, 0x03, 0x13, 0x12, 0x34, 0x36, 0x25,
  32119. 0x27, 0x30, 0x82, 0x81, 0x25, 0x47, 0x51, 0x35,
  32120. 0x44, 0x12, 0x67, 0x35, 0x00, 0x10, 0x01, 0x83,
  32121. 0x85, 0x74, 0x42, 0x40, 0x13, 0x03, 0x61, 0x27,
  32122. 0x81, 0x26, 0x26, 0x81, 0x18, 0x87, 0x43, 0x51,
  32123. 0x20, 0x62, 0x71, 0x27, 0x51, 0x56, 0x10, 0x22,
  32124. 0x22, 0x81, 0x11, 0x81, 0x41, 0x66, 0x66, 0x38,
  32125. 0x20, 0x86, 0x75, 0x56, 0x12, 0x40, 0x06, 0x54,
  32126. 0x61, 0x12, 0x74, 0x40, 0x34, 0x58, 0x58, 0x78,
  32127. 0x10, 0x07, 0x85, 0x25, 0x72, 0x88, 0x57, 0x22,
  32128. 0x22, 0x25, 0x50, 0x84, 0x00, 0x41, 0x26, 0x08,
  32129. 0x36, 0x46, 0x28, 0x78, 0x46, 0x78, 0x05, 0x02,
  32130. 0x28, 0x20, 0x77, 0x13, 0x60, 0x75, 0x14, 0x43,
  32131. 0x68, 0x78, 0x64, 0x31, 0x38, 0x77, 0x73, 0x73,
  32132. 0x55, 0x41, 0x27, 0x00, 0x54, 0x07, 0x08, 0x28,
  32133. 0x68, 0x80, 0x04, 0x53, 0x83, 0x43, 0x22, 0x81,
  32134. 0x00, 0x64, 0x35, 0x48, 0x67, 0x66, 0x50, 0x17,
  32135. 0x75, 0x76, 0x12, 0x75, 0x43, 0x81, 0x62, 0x40,
  32136. 0x33, 0x43, 0x45, 0x38, 0x87, 0x21, 0x66, 0x14,
  32137. 0x70, 0x48, 0x41, 0x43, 0x14, 0x66, 0x58, 0x78,
  32138. 0x45, 0x82, 0x02, 0x25, 0x45, 0x73, 0x15, 0x21,
  32139. 0x32, 0x03, 0x02, 0x48, 0x80, 0x80, 0x13, 0x71,
  32140. 0x25, 0x54, 0x32, 0x72, 0x05, 0x68, 0x65, 0x24,
  32141. 0x68, 0x04, 0x06, 0x16, 0x83, 0x50, 0x54, 0x53,
  32142. 0x37, 0x37, 0x27, 0x22, 0x20, 0x68, 0x08, 0x25,
  32143. 0x50, 0x84, 0x72, 0x86, 0x74, 0x22, 0x36, 0x16,
  32144. 0x80, 0x07, 0x55, 0x18, 0x12, 0x17, 0x84, 0x44,
  32145. 0x81, 0x15, 0x64, 0x50, 0x71, 0x10, 0x58, 0x15,
  32146. 0x51, 0x10, 0x10, 0x47, 0x16, 0x21, 0x07, 0x58,
  32147. 0x61, 0x18, 0x78, 0x00, 0x52, 0x72, 0x64, 0x52,
  32148. 0x17, 0x43, 0x23, 0x40, 0x76, 0x48, 0x67, 0x30,
  32149. 0x77, 0x63, 0x64, 0x87, 0x51, 0x31, 0x63, 0x84,
  32150. 0x68, 0x74, 0x53, 0x63, 0x84, 0x23, 0x54, 0x66,
  32151. 0x10, 0x48, 0x36, 0x33, 0x85, 0x21, 0x48, 0x42,
  32152. 0x03, 0x82, 0x51, 0x10, 0x33, 0x57, 0x46, 0x80,
  32153. 0x16, 0x43, 0x34, 0x02, 0x07, 0x03, 0x53, 0x22,
  32154. 0x12, 0x75, 0x73, 0x34, 0x65, 0x83, 0x33, 0x87,
  32155. 0x43, 0x85, 0x17, 0x50, 0x36, 0x60, 0x88, 0x02,
  32156. 0x58, 0x75, 0x80, 0x88, 0x31, 0x63, 0x60, 0x18,
  32157. 0x21, 0x32, 0x26, 0x15, 0x68, 0x74, 0x11, 0x10,
  32158. 0x33, 0x14, 0x13, 0x05, 0x34, 0x16, 0x72, 0x65,
  32159. 0x35, 0x50, 0x13, 0x34, 0x80, 0x87, 0x10, 0x26,
  32160. 0x48, 0x68, 0x84, 0x52, 0x71, 0x44, 0x23, 0x58,
  32161. 0x80, 0x35, 0x57, 0x70, 0x54, 0x84, 0x28, 0x70,
  32162. 0x55, 0x88, 0x86, 0x83, 0x86, 0x25, 0x21, 0x82,
  32163. 0x72, 0x61, 0x17, 0x78, 0x85, 0x17, 0x67, 0x73,
  32164. 0x00, 0x57, 0x71, 0x11, 0x78, 0x51, 0x10, 0x65,
  32165. 0x63, 0x57, 0x02, 0x87, 0x40, 0x13, 0x40, 0x01,
  32166. 0x26, 0x53, 0x45, 0x12, 0x05, 0x46, 0x75, 0x18,
  32167. 0x80, 0x70, 0x33, 0x35, 0x66, 0x22, 0x62, 0x00,
  32168. 0x70, 0x23, 0x26, 0x87, 0x72, 0x63, 0x11, 0x13,
  32169. 0x33, 0x33, 0x81, 0x41, 0x70, 0x62, 0x28, 0x61,
  32170. 0x51, 0x47, 0x31, 0x30, 0x25, 0x46, 0x51, 0x17,
  32171. 0x61, 0x58, 0x07, 0x41, 0x61, 0x37, 0x37, 0x06,
  32172. 0x14, 0x00, 0x54, 0x88, 0x77, 0x75, 0x67, 0x77,
  32173. 0x66, 0x53, 0x16, 0x72, 0x66, 0x66, 0x88, 0x76,
  32174. 0x43, 0x58, 0x31, 0x04, 0x87, 0x57, 0x06, 0x76,
  32175. 0x47, 0x00, 0x43, 0x63, 0x58, 0x60, 0x52, 0x03,
  32176. 0x44, 0x27, 0x36, 0x48, 0x61, 0x23, 0x72, 0x16,
  32177. 0x10, 0x62, 0x42, 0x08, 0x60, 0x83, 0x23, 0x54,
  32178. 0x03, 0x55, 0x55, 0x73, 0x00, 0x61, 0x03, 0x65,
  32179. 0x34, 0x27, 0x14, 0x15, 0x86, 0x62, 0x55, 0x80,
  32180. 0x16, 0x53, 0x10, 0x18, 0x26, 0x11, 0x35, 0x46,
  32181. 0x82, 0x46, 0x13, 0x25, 0x83, 0x47, 0x70, 0x50,
  32182. 0x06, 0x01, 0x56, 0x02, 0x11, 0x68, 0x54, 0x53,
  32183. 0x03, 0x68, 0x73, 0x36, 0x41, 0x88, 0x86, 0x33,
  32184. 0x42, 0x52, 0x01, 0x58, 0x33, 0x42, 0x32, 0x88,
  32185. 0x56, 0x81, 0x77, 0x55, 0x51, 0x48, 0x48, 0x12,
  32186. 0x01, 0x58, 0x13, 0x85, 0x04, 0x14, 0x71, 0x83,
  32187. 0x57, 0x07, 0x54, 0x55, 0x54, 0x55, 0x28, 0x27,
  32188. 0x31, 0x36, 0x02, 0x12, 0x32, 0x68, 0x32, 0x13,
  32189. 0x82, 0x58, 0x70, 0x28, 0x58, 0x53, 0x44, 0x86,
  32190. 0x72, 0x73, 0x42, 0x84, 0x18, 0x22, 0x08, 0x83,
  32191. 0x61, 0x02, 0x14, 0x16, 0x17, 0x12, 0x41, 0x57,
  32192. 0x48, 0x85, 0x25, 0x10, 0x26, 0x07, 0x36, 0x76,
  32193. 0x12, 0x66, 0x17, 0x21, 0x32, 0x36, 0x03, 0x25,
  32194. 0x41, 0x10, 0x11, 0x22, 0x66, 0x60, 0x16, 0x16,
  32195. 0x32, 0x64, 0x26, 0x05, 0x18, 0x63, 0x51, 0x58,
  32196. 0x51, 0x31, 0x42, 0x53, 0x84, 0x56, 0x66, 0x27,
  32197. 0x83, 0x33, 0x54, 0x50, 0x76, 0x46, 0x50, 0x80,
  32198. 0x25, 0x43, 0x41, 0x57, 0x35, 0x78, 0x25, 0x43,
  32199. 0x02, 0x82, 0x38, 0x47, 0x45, 0x70, 0x15, 0x67,
  32200. 0x51, 0x77, 0x47, 0x80, 0x31, 0x52, 0x75, 0x00,
  32201. 0x00, 0x94, 0x7B, 0xCA, 0x93, 0xC2, 0x7D, 0x58,
  32202. 0x4E, 0x2C, 0x66, 0xEA, 0xC9, 0xC7, 0x64, 0x0C,
  32203. 0x1C, 0xA2, 0x17, 0xEE, 0xF6, 0x6D, 0xAB, 0xBC,
  32204. 0xB2, 0x60, 0xB4, 0xC3, 0x43, 0x00, 0xFA, 0x05,
  32205. 0x13, 0x57, 0x82, 0x0F, 0x57, 0x39, 0x25, 0x44,
  32206. 0x98, 0x2F, 0xD1, 0x10, 0x57, 0xDE, 0x23, 0x3E,
  32207. 0x6D, 0x2D, 0xD8, 0x49, 0x72, 0xA7, 0xE4, 0x7D,
  32208. 0x4D, 0xBA, 0x99, 0xBC, 0x30, 0xCF, 0x8F, 0x2A,
  32209. 0xD5, 0xA2, 0xC0, 0x24, 0x31, 0x95, 0xED, 0x27,
  32210. 0x30, 0xFF, 0xA9, 0x2D, 0x22, 0x7D, 0x15, 0x30,
  32211. 0x95, 0x97, 0x2D, 0x4B, 0x34, 0x47, 0xFF, 0xAC,
  32212. 0x45, 0xA2, 0x3E, 0xB4, 0x1C, 0xBC, 0x87, 0xCD,
  32213. 0xD1, 0x25, 0x0A, 0x8A, 0x47, 0x8B, 0x0F, 0x7A,
  32214. 0x1D, 0x5B, 0x39, 0xAA, 0x22, 0x06, 0xE4, 0x86,
  32215. 0x45, 0x58, 0x4F, 0xE7, 0xBF, 0x7A, 0x13, 0x16,
  32216. 0x8F, 0x48, 0x27, 0x65, 0xE5, 0x7B, 0xB9, 0x24,
  32217. 0xAC, 0x6D, 0x9A, 0x11, 0x36, 0x9F, 0x4A, 0x6A,
  32218. 0xFF, 0xCD, 0x16, 0x9B, 0x7D, 0x75, 0x12, 0x9B,
  32219. 0x35, 0xD5, 0x13, 0x4A, 0x31, 0x76, 0x1B, 0xB8,
  32220. 0x35, 0x5A, 0xEE, 0xED, 0x27, 0xE2, 0x01, 0xA0,
  32221. 0x63, 0x13, 0x01, 0x3E, 0x30, 0x7A, 0x01, 0xA7,
  32222. 0x3A, 0xEA, 0x79, 0x55, 0xC0, 0x57, 0x8C, 0x8C,
  32223. 0x5E, 0x5A, 0x1A, 0x2D, 0x2F, 0xA4, 0x59, 0x3F,
  32224. 0xAC, 0xD9, 0x04, 0xC6, 0x20, 0x40, 0xBD, 0xB9,
  32225. 0xF3, 0x29, 0x93, 0x35, 0x36, 0xBF, 0x8D, 0x81,
  32226. 0xC4, 0x25, 0x6B, 0xAA, 0xE8, 0x72, 0x3F, 0xD4,
  32227. 0xDC, 0x66, 0xBB, 0x5E, 0x7F, 0x9C, 0xA4, 0x90,
  32228. 0x31, 0xA1, 0x93, 0xEC, 0xEC, 0xBB, 0x5D, 0xC3,
  32229. 0x90, 0xEC, 0x6D, 0x55, 0x13, 0xC7, 0x9A, 0x05,
  32230. 0x2B, 0x3F, 0xD4, 0x36, 0x12, 0xFB, 0x73, 0x75,
  32231. 0x31, 0x5D, 0x80, 0x91, 0xF7, 0x9B, 0xAB, 0x13,
  32232. 0x18, 0xF1, 0x78, 0x54, 0x56, 0x1B, 0xC9, 0x3A,
  32233. 0xE0, 0xE5, 0xCD, 0x6D, 0x13, 0x1E, 0x56, 0x2C,
  32234. 0x81, 0x14, 0x81, 0x0C, 0x93, 0x9A, 0xE5, 0x63,
  32235. 0xAA, 0x10, 0xB4, 0x7C, 0xE4, 0x48, 0x43, 0x17,
  32236. 0xF3, 0x4A, 0xBD, 0x02, 0xD0, 0xCC, 0xAD, 0x58,
  32237. 0xDD, 0x29, 0xBC, 0xF6, 0x57, 0xBB, 0xD9, 0x25,
  32238. 0x4B, 0x01, 0xCA, 0x97, 0x26, 0x09, 0x19, 0x38,
  32239. 0xED, 0x32, 0x05, 0x4B, 0x37, 0xDD, 0x61, 0x72,
  32240. 0x40, 0xF4, 0x43, 0x4C, 0x1A, 0x4A, 0x87, 0x11,
  32241. 0xAA, 0x3A, 0x39, 0x9A, 0x8A, 0x53, 0x88, 0x33,
  32242. 0x0B, 0x70, 0x59, 0xEC, 0xCB, 0xB6, 0xB1, 0xB9,
  32243. 0xCF, 0x71, 0x87, 0xAD, 0xF1, 0x0B, 0x0C, 0x91,
  32244. 0x71, 0xD3, 0xC0, 0xF6, 0xE2, 0xD4, 0x60, 0xA4,
  32245. 0x19, 0x24, 0x76, 0x72, 0xE3, 0xB9, 0xFE, 0xA2,
  32246. 0xC9, 0x59, 0x10, 0xBF, 0x2F, 0xB6, 0xA5, 0xD6,
  32247. 0x1F, 0x25, 0x74, 0x53, 0xB0, 0x7A, 0xFB, 0x64,
  32248. 0xB0, 0xBA, 0x27, 0x58, 0xBC, 0xD7, 0x35, 0x75,
  32249. 0x1F, 0x2D, 0x53, 0x51, 0x5E, 0x23, 0x6F, 0xE8,
  32250. 0xA5, 0xB4, 0x39, 0x3B, 0x80, 0xBF, 0x06, 0xDF,
  32251. 0x97, 0xBD, 0xC6, 0x38, 0x00, 0x87, 0xE6, 0xAA,
  32252. 0x8D, 0xDE, 0x6E, 0x09, 0x81, 0x11, 0xA7, 0x34,
  32253. 0x3F, 0xCD, 0xD1, 0xE9, 0x03, 0x70, 0x8E, 0x63,
  32254. 0x7E, 0xBF, 0x28, 0x32, 0x3C, 0xDA, 0x6B, 0x94,
  32255. 0x05, 0x81, 0x0E, 0xDC, 0xFB, 0x36, 0x91, 0x14,
  32256. 0x9E, 0xCF, 0x22, 0x4C, 0x50, 0xF8, 0xDF, 0x92,
  32257. 0xA9, 0x4A, 0xA4, 0x77, 0x0A, 0x0E, 0x91, 0x46,
  32258. 0x61, 0x94, 0xBB, 0x0E, 0x27, 0xBF, 0x1C, 0xAB,
  32259. 0xF1, 0x6A, 0xDF, 0xD3, 0x51, 0x22, 0x00, 0x33,
  32260. 0xF7, 0x6F, 0x59, 0x25, 0x55, 0x7B, 0xCF, 0x96,
  32261. 0x34, 0xE9, 0x46, 0x13, 0x59, 0x62, 0x1D, 0x80,
  32262. 0xB4, 0xBB, 0xAD, 0x7E, 0x2A, 0x6E, 0x43, 0x2D,
  32263. 0xC4, 0x3B, 0x12, 0x6C, 0xA4, 0x2A, 0xB8, 0x8A,
  32264. 0xA8, 0x8F, 0x0A, 0x84, 0xAF, 0x58, 0x02, 0x9C,
  32265. 0x99, 0xA0, 0x24, 0x8F, 0x0C, 0x45, 0x40, 0x71,
  32266. 0xF3, 0x5B, 0x83, 0x1F, 0xED, 0x12, 0x54, 0xD6,
  32267. 0xF4, 0xE2, 0x72, 0x04, 0x85, 0x78, 0x62, 0x15,
  32268. 0xF7, 0xC7, 0xF0, 0xC4, 0xED, 0x15, 0xFA, 0x85,
  32269. 0x3C, 0xD3, 0xAA, 0x07, 0x25, 0x9B, 0x39, 0x24,
  32270. 0x0A, 0x82, 0x13, 0x5C, 0x29, 0x23, 0xA7, 0x2B,
  32271. 0x87, 0x6F, 0xAB, 0xB3, 0xF0, 0xF2, 0xC0, 0x96,
  32272. 0x13, 0xDE, 0x39, 0xD4, 0x59, 0xA0, 0x7C, 0x14,
  32273. 0xE7, 0xBA, 0x43, 0x7D, 0x80, 0x41, 0x49, 0x1F,
  32274. 0xCE, 0xC1, 0x43, 0x34, 0x04, 0xBA, 0xD1, 0xDA,
  32275. 0x9E, 0xE9, 0x47, 0x1E, 0x17, 0xCB, 0x69, 0x1B,
  32276. 0x2A, 0x35, 0x37, 0x10, 0xC9, 0xFF, 0xA4, 0xE5,
  32277. 0x17, 0x81, 0x12, 0x02, 0x77, 0x64, 0xEB, 0x7D,
  32278. 0xE8, 0x09, 0xC3, 0xE1, 0xF1, 0xFA, 0x41, 0x78,
  32279. 0xA5, 0xD4, 0xDC, 0x9E, 0xE2, 0x78, 0x57, 0xEF,
  32280. 0xF2, 0x6B, 0x91, 0x71, 0x1F, 0xC1, 0x44, 0xD5,
  32281. 0xA7, 0x75, 0xB8, 0xB5, 0x0D, 0x5D, 0xB9, 0x39,
  32282. 0xBA, 0x32, 0x07, 0x68, 0x0C, 0x24, 0x2F, 0xC8,
  32283. 0x21, 0x94, 0x7F, 0x93, 0x4C, 0x8D, 0xAE, 0xE2,
  32284. 0x03, 0x56, 0x3D, 0x28, 0x60, 0x6B, 0xE6, 0x24,
  32285. 0xA3, 0x29, 0x01, 0x93, 0x2D, 0xAE, 0x85, 0x71,
  32286. 0x2A, 0xF6, 0xC8, 0x01, 0x60, 0x26, 0x92, 0x7E,
  32287. 0x9B, 0x81, 0x29, 0x57, 0x4B, 0xE3, 0xCB, 0x1E,
  32288. 0x95, 0x33, 0x2B, 0x05, 0x27, 0x07, 0xAC, 0x8A,
  32289. 0xA8, 0xF4, 0x35, 0xE8, 0x8B, 0x7E, 0x56, 0x8D,
  32290. 0x49, 0x87, 0xC6, 0xAC, 0x0E, 0x90, 0x2B, 0x06,
  32291. 0x09, 0xA0, 0x2D, 0x91, 0xB3, 0xF5, 0xFD, 0x3F,
  32292. 0xD9, 0x01, 0xDD, 0xD0, 0xDB, 0x98, 0x73, 0xBD,
  32293. 0x7C, 0x71, 0xED, 0x92, 0x1D, 0x45, 0x77, 0xA7,
  32294. 0x8C, 0x4F, 0xCC, 0x9B, 0xF0, 0x75, 0x20, 0x3D,
  32295. 0x38, 0xF5, 0xE7, 0x6E, 0x74, 0xF2, 0x77, 0x48,
  32296. 0x4E, 0x05, 0x7B, 0x61, 0x89, 0x00, 0x41, 0x31,
  32297. 0xB0, 0xC9, 0xB1, 0xA1, 0x55, 0x29, 0x4D, 0x1C,
  32298. 0xD3, 0xD5, 0x20, 0x8E, 0x26, 0x69, 0x01, 0xD7,
  32299. 0xD3, 0x14, 0xFA, 0xCC, 0xE7, 0xE2, 0xAA, 0x58,
  32300. 0x45, 0x83, 0xA1, 0x1E, 0x4D, 0x7C, 0x21, 0xB9,
  32301. 0x4A, 0x32, 0xE5, 0x08, 0xED, 0xDB, 0xBD, 0x7A,
  32302. 0x65, 0xAA, 0x86, 0xB4, 0xFD, 0xFA, 0x6B, 0xC2,
  32303. 0x85, 0xD4, 0xCF, 0xF5, 0x39, 0x26, 0xC7, 0x17,
  32304. 0x3F, 0xBE, 0x1F, 0x89, 0xCC, 0x30, 0x32, 0x34,
  32305. 0xB8, 0x78, 0xC6, 0xB8, 0x10, 0x1F, 0x58, 0xAC,
  32306. 0x8D, 0x3E, 0x5E, 0x1B, 0xF5, 0xAB, 0x6B, 0x26,
  32307. 0x29, 0x7C, 0xC9, 0x7B, 0x95, 0x95, 0x4A, 0xAB,
  32308. 0xDB, 0x25, 0xBE, 0x00, 0x8A, 0x3F, 0x47, 0xE5,
  32309. 0x64, 0x87, 0xB0, 0x0D, 0x3D, 0xED, 0xA8, 0x90,
  32310. 0xD9, 0x2C, 0x83, 0x95, 0x7F, 0xEA, 0xC6, 0xB8,
  32311. 0x29, 0x1A, 0xF6, 0x59, 0x59, 0xE1, 0xD1, 0xFC,
  32312. 0xA3, 0xBD, 0x19, 0x6E, 0x9F, 0xC9, 0xE6, 0x7E,
  32313. 0x06, 0x07, 0x09, 0x48, 0x22, 0xE5, 0xB4, 0x19,
  32314. 0x1D, 0xB9, 0x68, 0x24, 0xB9, 0xF0, 0x3F, 0x2E,
  32315. 0xF5, 0x7F, 0x52, 0x38, 0xBA, 0x7E, 0x1E, 0x84,
  32316. 0xED, 0x55, 0xB7, 0xDF, 0xF3, 0xD6, 0xC2, 0xC1,
  32317. 0x27, 0x36, 0x92, 0xA9, 0xA1, 0x92, 0x72, 0x16,
  32318. 0x61, 0x30, 0xDB, 0x89, 0xFC, 0x67, 0xDC, 0x94,
  32319. 0xDB, 0x61, 0x4E, 0x3E, 0x82, 0xBA, 0x3A, 0x35,
  32320. 0x12, 0xB0, 0x12, 0xD5, 0x1F, 0xB4, 0x86, 0xB5,
  32321. 0xA3, 0x15, 0x0B, 0x78, 0xE7, 0x24, 0xE2, 0xA1,
  32322. 0x2D, 0xE0, 0x7D, 0x86, 0x71, 0xFB, 0xA2, 0xDA,
  32323. 0x7F, 0xD5, 0xD1, 0x47, 0x20, 0x8F, 0xC3, 0xAF,
  32324. 0x65, 0x3E, 0x65, 0x20, 0xFC, 0x40, 0x87, 0x1A,
  32325. 0xF2, 0x17, 0x7E, 0x65, 0xCB, 0xD0, 0xEA, 0xF3,
  32326. 0x04, 0x21, 0x7B, 0x36, 0x7A, 0x66, 0x5F, 0x22,
  32327. 0x4C, 0xAE, 0xDF, 0xE9, 0x30, 0x06, 0xAC, 0x1E,
  32328. 0x14, 0xBC, 0xD6, 0x7A, 0x88, 0xD1, 0x71, 0xF3,
  32329. 0xD8, 0xF3, 0xE3, 0x58, 0xA7, 0x19, 0x26, 0xBA,
  32330. 0x3E, 0x5C, 0x23, 0x9A, 0x53, 0x12, 0x63, 0xEC,
  32331. 0x94, 0x37, 0xBF, 0x2A, 0x03, 0x3B, 0x8B, 0x55,
  32332. 0xB2, 0xC0, 0xCB, 0x6E, 0x7E, 0x97, 0x31, 0x6E,
  32333. 0x22, 0xDF, 0x77, 0xCA, 0xD9, 0x10, 0xD2, 0x0E,
  32334. 0xEC, 0xE1, 0xC5, 0x09, 0x10, 0xA5, 0xCC, 0x32,
  32335. 0xAD, 0xAB, 0x09, 0x37, 0x75, 0x50, 0xF9, 0x2D,
  32336. 0x5B, 0xB1, 0xF4, 0xC0, 0x7F, 0x4A, 0x28, 0x22,
  32337. 0x33, 0x8E, 0x2C, 0xFF, 0x53, 0x48, 0xDF, 0x77,
  32338. 0xCF, 0x8E, 0xF8, 0xE6, 0x65, 0x7D, 0xED, 0x1E,
  32339. 0x0C, 0xE0, 0x58, 0xE3, 0xCC, 0xFB, 0xF3, 0x9B,
  32340. 0x3F, 0x16, 0x6E, 0x30, 0x3D, 0x33, 0xC3, 0x55,
  32341. 0x6C, 0x9A, 0xC8, 0xEC, 0xB3, 0xDF, 0x7C, 0x74,
  32342. 0xAB, 0x36, 0xD0, 0xF2, 0x79, 0x44, 0x41, 0xBA,
  32343. 0x98, 0x08, 0x82, 0x7B, 0x57, 0x8F, 0xB5, 0xC2,
  32344. 0x9E, 0x49, 0x4E, 0x21, 0x53, 0x9A, 0xD3, 0xAB,
  32345. 0x2B, 0x41, 0xBF, 0x16, 0x1D, 0x7F, 0x69, 0x58,
  32346. 0x9D, 0x45, 0x24, 0xC5, 0x4C, 0x89, 0xB4, 0x86,
  32347. 0xF7, 0x5D, 0x25, 0x2F, 0x54, 0x1C, 0xC6, 0x3B,
  32348. 0x9E, 0x70, 0x6D, 0x64, 0xA1, 0x28, 0x9A, 0x23,
  32349. 0x06, 0xC5, 0x95, 0x36, 0x3C, 0xB6, 0xFB, 0xEF,
  32350. 0x0A, 0x1B, 0x5B, 0x17, 0xAB, 0x5B, 0x17, 0x94,
  32351. 0xBF, 0x27, 0x03, 0x6F, 0x64, 0xEA, 0xF0, 0xBD,
  32352. 0x43, 0x0D, 0xD5, 0x8D, 0x80, 0x01, 0x0C, 0xCD,
  32353. 0xAD, 0xA4, 0xA5, 0xA3, 0xA1, 0xE4, 0x1A, 0x6F,
  32354. 0xBF, 0x12, 0x9D, 0x73, 0x77, 0x9A, 0x37, 0xAE,
  32355. 0x5C, 0x8D, 0x68, 0x41, 0xA9, 0x99, 0x3C, 0x51,
  32356. 0xE3, 0x64, 0xE0, 0x4F, 0xAC, 0x8E, 0x25, 0xA4,
  32357. 0xE6, 0x87, 0x2F, 0x6C, 0x86, 0x0F, 0xA2, 0x65,
  32358. 0xC1, 0xC4, 0x42, 0x6A, 0xD9, 0xC2, 0x1D, 0x26,
  32359. 0xDA, 0x8C, 0x27, 0x85, 0x46, 0xAD, 0xCD, 0x83,
  32360. 0x1F, 0x2B, 0x8B, 0x26, 0xD4, 0xE1, 0xF6, 0x70,
  32361. 0x62, 0x3D, 0x95, 0xC8, 0x36, 0x2D, 0xA6, 0x62,
  32362. 0xD1, 0xFF, 0x0A, 0xB6, 0x87, 0x50, 0x3F, 0x32,
  32363. 0x8D, 0xE0, 0x95, 0x81, 0x0E, 0xDE, 0x12, 0xB4,
  32364. 0x9E, 0xAD, 0x15, 0x33, 0x51, 0x95, 0x58, 0xC1,
  32365. 0xE9, 0x40, 0xB4, 0x6E, 0x4E, 0xDB, 0x02, 0x7B,
  32366. 0xE9, 0xDA, 0x20, 0x39, 0xB2, 0x5D, 0xCF, 0x73,
  32367. 0x57, 0xE1, 0x9E, 0x54, 0x16, 0xAE, 0x26, 0x8C,
  32368. 0x14, 0xFB, 0x3A, 0x8B, 0xAB, 0xCB, 0x3D, 0x23,
  32369. 0xF7, 0x0C, 0xC9, 0xD5, 0x96, 0x81, 0xC5, 0xD8,
  32370. 0x33, 0xAC, 0x22, 0xE6, 0x53, 0xD8, 0x6E, 0x22,
  32371. 0xCE, 0x82, 0x25, 0x40, 0x75, 0x5D, 0x8D, 0x24,
  32372. 0x3C, 0x15, 0x21, 0x3D, 0x07, 0x6C, 0x6B, 0x26,
  32373. 0x43, 0x6D, 0xDC, 0x07, 0xC7, 0xE0, 0x01, 0x34,
  32374. 0x7B, 0x0C, 0xB8, 0x78, 0x3D, 0xFE, 0xFE, 0xDF,
  32375. 0x27, 0x5F, 0xEC, 0x47, 0x92, 0x68, 0x67, 0x34,
  32376. 0x00, 0x7F, 0x0F, 0xF8, 0x54, 0x08, 0x11, 0xC2,
  32377. 0xAF, 0xE6, 0xCA, 0x15, 0x14, 0x20, 0x53, 0x2F,
  32378. 0xA5, 0x52, 0x6A, 0x10, 0x74, 0xC3, 0xD7, 0x89,
  32379. 0xF2, 0x93, 0x2D, 0xE4, 0x2E, 0x3A, 0xCF, 0xBF,
  32380. 0x94, 0x76, 0x0F, 0x42, 0x6D, 0x96, 0xCF, 0x03,
  32381. 0x3F, 0xA4, 0x9E, 0x2F, 0x45, 0x8F, 0x9A, 0x9C,
  32382. 0x2E, 0x71, 0xDA, 0xCF, 0xE0, 0x09, 0xDD, 0x9C,
  32383. 0x3F, 0x3C, 0x8A, 0xB3, 0x28, 0x2D, 0x6F, 0x38,
  32384. 0x3B, 0x98, 0x1C, 0x82, 0xD6, 0x36, 0x4F, 0x0E,
  32385. 0x4B, 0xDB, 0x2A, 0xF6, 0xA9, 0x5B, 0xA6, 0x1F,
  32386. 0x47, 0x41, 0x50, 0xCA, 0xD7, 0x23, 0x3F, 0x89,
  32387. 0x03, 0xDF, 0x97, 0x2D, 0xBB, 0x03, 0x28, 0xC0,
  32388. 0xCB, 0x9D, 0x0C, 0xCB, 0xEF, 0x88, 0x3D, 0x2E,
  32389. 0x6A, 0xDD, 0x18, 0x0E, 0xCA, 0x1B, 0x66, 0x2F,
  32390. 0xC1, 0xD2, 0xDB, 0xBD, 0xDB, 0x36, 0x34, 0x21,
  32391. 0x9E, 0x1E, 0xFF, 0x38, 0xB1, 0xE5, 0x28, 0x75,
  32392. 0x35, 0x6C, 0x03, 0xEA, 0xDE, 0x94, 0x20, 0x55,
  32393. 0xF4, 0x83, 0x50, 0x4B, 0xBB, 0xCB, 0x43, 0x02,
  32394. 0xA4, 0x17, 0xCF, 0x6D, 0x32, 0x8E, 0xD7, 0x93,
  32395. 0xB1, 0xA3, 0xC0, 0x96, 0x9B, 0x7B, 0x34, 0x18,
  32396. 0xF5, 0x0A, 0xB3, 0x9F, 0x83, 0xC5, 0x66, 0x6C,
  32397. 0x90, 0xE3, 0x83, 0x56, 0xF7, 0xF9, 0xD4, 0x94,
  32398. 0xA6, 0xDC, 0xB6, 0x3D, 0x67, 0xC3, 0x4E, 0x3D,
  32399. 0x14, 0xA4, 0xE1, 0x55, 0x96, 0x49, 0x79, 0x26,
  32400. 0xC8, 0x56, 0x8D, 0x8E, 0xC3, 0xDB, 0xD9, 0xC2,
  32401. 0xE8, 0x2C, 0x38, 0x5B, 0xCF, 0xB8, 0xD9, 0x67,
  32402. 0x48, 0x63, 0xBD, 0x4F, 0xBF, 0x17, 0x57, 0xDB,
  32403. 0x44, 0x7B, 0xF8, 0x04, 0xAE, 0x95, 0x01, 0x47,
  32404. 0xC9, 0x1F, 0xBF, 0x9A, 0xA1, 0x78, 0x91, 0x04,
  32405. 0x4C, 0xCA, 0xA7, 0x3B, 0x45, 0x52, 0x85, 0x97,
  32406. 0x46, 0x2C, 0xED, 0x75, 0x1D, 0x01, 0x5E, 0xBB,
  32407. 0xA9, 0xE2, 0xB7, 0xCD, 0xCB, 0xE6, 0xDC, 0x05,
  32408. 0xAA, 0x9E, 0xAE, 0x0C, 0x86, 0x84, 0x8A, 0x34,
  32409. 0x75, 0xBB, 0x1C, 0x57, 0x44, 0xF5, 0x90, 0x3E,
  32410. 0xE4, 0xA8, 0x42, 0xA4, 0x69, 0xCC, 0x18, 0x12,
  32411. 0x71, 0xF2, 0x45, 0xAD, 0x70, 0xD0, 0x2A, 0x48,
  32412. 0x37, 0x86, 0x3B, 0x29, 0x6B, 0x4A, 0xDB, 0x4E,
  32413. 0x8D, 0x03, 0xD8, 0x2B, 0x64, 0xAA, 0x11, 0xDD,
  32414. 0x31, 0xCD, 0xF2, 0x1E, 0xDF, 0x1D, 0xFE, 0x32,
  32415. 0x76, 0xC4, 0xDB, 0xC8, 0x77, 0xE3, 0x5B, 0x15,
  32416. 0xFB, 0x28, 0x35, 0xEC, 0x3A, 0x1C, 0x45, 0x31,
  32417. 0x68, 0xA3, 0x8C, 0xA8, 0xE5, 0x63, 0xCF, 0x3E,
  32418. 0x9A, 0x00, 0x73, 0x6C, 0xD5, 0xCF, 0xBD, 0x28,
  32419. 0x41, 0xD1, 0x0F, 0x94, 0xAD, 0x55, 0x79, 0x9C,
  32420. 0x29, 0x27, 0xE5, 0x46, 0x1B, 0x28, 0xBA, 0xC5,
  32421. 0x17, 0x4D, 0x0C, 0xE3, 0xF8, 0xF7, 0xCD, 0x76,
  32422. 0x09, 0xFB, 0xC8, 0xDA, 0x0C, 0x38, 0xCC, 0x21,
  32423. 0x69, 0x5C, 0xED, 0xAD, 0x12, 0xF8, 0xD2, 0xE6,
  32424. 0x49, 0x51, 0xA8, 0x99, 0x6E, 0x51, 0x0D, 0x6D,
  32425. 0x52, 0x79, 0x7C, 0x5B, 0xA0, 0xEB, 0x4A, 0xFA,
  32426. 0x6B, 0xF2, 0xCC, 0x43, 0xDA, 0x09, 0xDE, 0x31,
  32427. 0x79, 0xE8, 0x99, 0xBD, 0x71, 0x88, 0xB3, 0x2A,
  32428. 0x98, 0xA4, 0x99, 0xD3, 0x72, 0xF3, 0x70, 0x7C,
  32429. 0xED, 0x47, 0x9B, 0x09, 0x81, 0xCB, 0x50, 0xC0,
  32430. 0xC0, 0x53, 0x9C, 0xF7, 0xE3, 0x10, 0x0B, 0x72,
  32431. 0x0E, 0x46, 0x66, 0x52, 0xA4, 0xF4, 0x99, 0xC2,
  32432. 0xBA, 0x3A, 0x17, 0xF5, 0x23, 0x22, 0x68, 0x73,
  32433. 0x0B, 0x96, 0x2B, 0xC5, 0x72, 0xC0, 0xDE, 0x96,
  32434. 0xE8, 0xC9, 0xE2, 0x8F, 0x7E, 0x35, 0x32, 0xC2,
  32435. 0x22, 0x41, 0x96, 0xAA, 0x9E, 0x27, 0x68, 0x8D,
  32436. 0xD0, 0x50, 0xD7, 0xCB, 0x78, 0x54, 0xFB, 0x3C,
  32437. 0x35, 0xF9, 0xC6, 0x2E, 0xFB, 0x10, 0xDA, 0x84,
  32438. 0x83, 0x3F, 0x29, 0xBB, 0x1B, 0xE5, 0xEF, 0x3B,
  32439. 0x53, 0x36, 0x38, 0xEE, 0xF7, 0x43, 0xD8, 0x11,
  32440. 0x9D, 0xDC, 0x29, 0x0B, 0xDF, 0x08, 0xB6, 0xF0,
  32441. 0xF9, 0xE4, 0xE1, 0xE1, 0x34, 0x46, 0xC5, 0x3E,
  32442. 0xD6, 0x98, 0x05, 0xDA, 0x26, 0x90, 0x8A, 0x15,
  32443. 0xDF, 0x1C, 0x48, 0xE0, 0x09, 0xEC, 0x12, 0x53,
  32444. 0xBD, 0x5A, 0x58, 0x98, 0xEB, 0xB5, 0x12, 0x1C,
  32445. 0xC2, 0x49, 0x04, 0xC8, 0xB1, 0x0E, 0x24, 0xE6,
  32446. 0x80, 0xE5, 0x65, 0x98, 0x50, 0x76, 0xFD, 0xA1,
  32447. 0x1D, 0x13, 0xFF, 0xDF, 0xA4, 0xDB, 0x28, 0xAC,
  32448. 0x9F, 0x0A, 0xEA, 0x2F, 0x81, 0xFD, 0x7E, 0xD4,
  32449. 0xDC, 0xA8, 0xD3, 0xB2, 0xE3, 0x84, 0x8B, 0x4D,
  32450. 0x60, 0x46, 0xF6, 0xE0, 0xDE, 0x3A, 0x4F, 0x68,
  32451. 0x3F, 0x25, 0xE0, 0x60, 0x5E, 0x84, 0xB3, 0x6F,
  32452. 0x48, 0x3C, 0x40, 0x4E, 0xF8, 0x99, 0xCB, 0x3F,
  32453. 0xCC, 0xBE, 0x8C, 0xB2, 0xA6, 0xF0, 0xA7, 0xE1,
  32454. 0x0B, 0x19, 0x48, 0xCD, 0x4F, 0x93, 0xF1, 0x81,
  32455. 0x55, 0x5F, 0x66, 0x1D, 0x31, 0xD4, 0x26, 0x80,
  32456. 0x8B, 0xBF, 0x9F, 0x66, 0xFD, 0x60, 0xD6, 0x49,
  32457. 0x26, 0x9C, 0xA3, 0xFE, 0x99, 0x1B, 0x22, 0x42,
  32458. 0x8C, 0x37, 0xAD, 0x2A, 0x08, 0x68, 0x0F, 0x74,
  32459. 0x7C, 0xC0, 0x36, 0x0C, 0xCD, 0x37, 0x3D, 0xC6,
  32460. 0xA9, 0xF4, 0x3A, 0x66, 0x47, 0x0E, 0x01, 0x4E,
  32461. 0x72, 0xB3, 0xD8, 0xC3, 0x8E, 0x02, 0x04, 0x42,
  32462. 0xD8, 0xAA, 0xB9, 0x74, 0xE6, 0x04, 0x93, 0x74,
  32463. 0x14, 0x5B, 0x04, 0xCB, 0x7F, 0x30, 0x44, 0xAA,
  32464. 0xC1, 0xEF, 0xDA, 0xB2, 0xA1, 0x8B, 0xB4, 0x64,
  32465. 0xD4, 0xF2, 0xF2, 0xD8, 0x14, 0x39, 0x74, 0xC9,
  32466. 0x5E, 0xEE, 0x85, 0x6D, 0x59, 0xEC, 0x00, 0x28,
  32467. 0x8E, 0xD4, 0x3F, 0xF5, 0xCC, 0x88, 0x03, 0x00,
  32468. 0x6C, 0x99, 0x55, 0x14, 0xA2, 0xCC, 0x9C, 0xA6,
  32469. 0x22, 0xB6, 0x1B, 0xCD, 0x75, 0xEC, 0x51, 0xC2,
  32470. 0x02, 0xA9, 0x17, 0x10, 0x5B, 0x4A, 0x4B, 0xED,
  32471. 0x1B, 0x80, 0x14, 0x68, 0x31, 0xDC, 0xED, 0x07,
  32472. 0xEF, 0xD2, 0xED, 0x25, 0x73, 0x9F, 0x54, 0x09,
  32473. 0x69, 0x11, 0xB1, 0x50, 0xD3, 0x07, 0x7C, 0xCD,
  32474. 0x73, 0x1A, 0x03, 0x61, 0x68, 0x27, 0x25, 0xD5,
  32475. 0x38, 0x03, 0xF8, 0xFC, 0xEA, 0xA8, 0x39, 0x19,
  32476. 0x29, 0x1E, 0xDB, 0x44, 0x93, 0xEC, 0x84, 0xCC,
  32477. 0xE1, 0xD0, 0xF8, 0x2A, 0x67, 0x92, 0x36, 0xEA,
  32478. 0xD1, 0x00, 0x2A, 0xE8, 0x01, 0x8C, 0xAC, 0x9F,
  32479. 0xDB, 0xD2, 0x46, 0xFF, 0x09, 0x3D, 0x80, 0x3C,
  32480. 0x0D, 0xE3, 0x32, 0x6A, 0x57, 0x90, 0x7B, 0x0D,
  32481. 0xD6, 0xB0, 0x1D, 0x08, 0x14, 0x58, 0xC7, 0x57,
  32482. 0x28, 0xC6, 0x00, 0x82, 0x99, 0x28, 0x89, 0x0A,
  32483. 0x56, 0xAA, 0xAF, 0xEF, 0xCF, 0x74, 0x23, 0xB7,
  32484. 0x0A, 0x6D, 0x86, 0xB4, 0x15, 0xB8, 0x35, 0x8D,
  32485. 0xD0, 0x44, 0xAB, 0xEE, 0x00, 0xB9, 0xC9, 0x79,
  32486. 0x5F, 0xC8, 0xF6, 0x1A, 0x64, 0x68, 0x6D, 0xF5,
  32487. 0xF8, 0x76, 0xA8, 0xF3, 0x30, 0x61, 0x59, 0x9A,
  32488. 0xE8, 0x30, 0xF7, 0xEB, 0x4C, 0x4B, 0xFF, 0x87,
  32489. 0x5F, 0x4A, 0x93, 0x6C, 0x40, 0x3C, 0x5D, 0x16,
  32490. 0x0D, 0xE5, 0xD3, 0x3C, 0xAE, 0xE4, 0x0F, 0xB7,
  32491. 0x18, 0xDD, 0xA4, 0x47, 0x8A, 0xC6, 0xF5, 0x1C,
  32492. 0x59, 0xC2, 0x15, 0x52, 0x54, 0xBD, 0x77, 0x67,
  32493. 0x11, 0x18, 0x41, 0x1E, 0x26, 0x09, 0xD0, 0x00,
  32494. 0x30, 0x6F, 0xC9, 0x50, 0x70, 0x04, 0xA3, 0x1E,
  32495. 0x89, 0x57, 0xEA, 0x40, 0xC2, 0x56, 0x4B, 0x83,
  32496. 0xC3, 0xAB, 0xB7, 0x1A, 0x87, 0xC1, 0x1B, 0xD1,
  32497. 0x8D, 0x78, 0x91, 0xC4, 0x49, 0xDB, 0xBE, 0x79,
  32498. 0xB4, 0xA4, 0xFB, 0x04, 0x83, 0x07, 0xCE, 0x0E,
  32499. 0x81, 0x2B, 0x2C, 0x68, 0xEC, 0xAB, 0x77, 0xFD,
  32500. 0x11, 0x11, 0x52, 0x6A, 0xB0, 0x81, 0x73, 0x06,
  32501. 0xCE, 0xBC, 0xB0, 0x49, 0x7C, 0x55, 0x24, 0x31,
  32502. 0xCE, 0x15, 0xE4, 0xAB, 0x52, 0x28, 0x3F, 0x67,
  32503. 0x94, 0x80, 0xD6, 0x9D, 0xDD, 0xE1, 0xF2, 0x57,
  32504. 0x9C, 0xFD, 0xBE, 0x0B, 0xCA, 0x95, 0xFC, 0x5B,
  32505. 0x2D, 0xB0, 0xC5, 0xCC, 0x76, 0xA3, 0x19, 0x50,
  32506. 0xF5, 0x11, 0x6A, 0xAE, 0x5F, 0x02, 0xD4, 0x67,
  32507. 0x10, 0xE4, 0x25, 0x7A, 0x75, 0xFD, 0xED, 0xF2,
  32508. 0xF4, 0x7C, 0xE3, 0x7C, 0x20, 0x3E, 0x7F, 0x24,
  32509. 0xD3, 0xC9, 0x17, 0x97, 0x13, 0xC5, 0xD8, 0x07,
  32510. 0xC2, 0x96, 0x14, 0x9A, 0x75, 0xCC, 0xB4, 0x44,
  32511. 0xF0, 0xC6, 0xF6, 0xAB, 0xDD, 0x2D, 0xBB, 0x29,
  32512. 0x85, 0xFE, 0x26, 0x74, 0x82, 0x85, 0x8A, 0x1E
  32513. };
  32514. #endif /* WOLFSSL_NO_ML_DSA_65 */
  32515. #ifndef WOLFSSL_NO_ML_DSA_87
  32516. static const byte seed_87[] = {
  32517. 0x38, 0x35, 0x9F, 0xBC, 0xD7, 0x95, 0x82, 0xCF,
  32518. 0xFE, 0x60, 0x9E, 0x13, 0x7E, 0xE2, 0xEF, 0xE8,
  32519. 0xA8, 0xDB, 0xCB, 0xAD, 0x18, 0xBA, 0x92, 0xBB,
  32520. 0x43, 0x3A, 0xB4, 0xF0, 0x9B, 0x49, 0x29, 0x9D
  32521. };
  32522. static const byte pk_87[] = {
  32523. 0x69, 0x24, 0xBB, 0x42, 0x57, 0xA7, 0xB9, 0xAF,
  32524. 0xF0, 0x95, 0xC3, 0x0B, 0xB3, 0x5C, 0x6A, 0xE4,
  32525. 0x19, 0x82, 0x63, 0x12, 0x0F, 0x80, 0x39, 0xAA,
  32526. 0x4E, 0x78, 0xE1, 0x74, 0xA7, 0x86, 0xCE, 0x00,
  32527. 0x83, 0x01, 0xE6, 0x66, 0xF5, 0x9D, 0x3E, 0xC5,
  32528. 0x04, 0x4D, 0xE4, 0x56, 0x78, 0x8F, 0xDE, 0x19,
  32529. 0xEB, 0x39, 0x67, 0x7B, 0x5F, 0x9F, 0xE1, 0x41,
  32530. 0x50, 0xDA, 0x46, 0x3A, 0x70, 0x6F, 0x3B, 0xAF,
  32531. 0x71, 0x5B, 0x95, 0x33, 0x6B, 0x2D, 0x68, 0x5A,
  32532. 0x7C, 0xD7, 0x88, 0x07, 0x13, 0xE4, 0x58, 0x7B,
  32533. 0xF7, 0xD8, 0x57, 0xBF, 0x7E, 0x31, 0x56, 0x96,
  32534. 0xB8, 0xD0, 0xD9, 0xD4, 0x9E, 0x14, 0x29, 0x18,
  32535. 0xBF, 0x09, 0x74, 0xE7, 0xF4, 0x32, 0x37, 0xD4,
  32536. 0xBE, 0x3A, 0xD3, 0x94, 0x59, 0x9E, 0x3D, 0x39,
  32537. 0xBB, 0x76, 0x49, 0x93, 0x25, 0x53, 0x44, 0x7E,
  32538. 0x5D, 0x5A, 0xCC, 0x34, 0x99, 0x93, 0x01, 0x76,
  32539. 0xEC, 0xD3, 0xA8, 0x44, 0xA4, 0x25, 0xF5, 0x0D,
  32540. 0x05, 0x11, 0xC9, 0x22, 0x6C, 0x4B, 0x9A, 0x24,
  32541. 0xF2, 0xA0, 0x11, 0xCD, 0x88, 0xD3, 0x23, 0x08,
  32542. 0xE0, 0x31, 0x2A, 0x0C, 0x87, 0xCC, 0x34, 0xA9,
  32543. 0x95, 0x82, 0x3C, 0x65, 0xF4, 0xF0, 0xF9, 0x8E,
  32544. 0x50, 0xC3, 0x77, 0x88, 0xCE, 0x38, 0xDC, 0x28,
  32545. 0xFB, 0x8B, 0x9B, 0xFA, 0xAF, 0xA9, 0x04, 0xB5,
  32546. 0x41, 0xEE, 0x71, 0x2F, 0x6A, 0x04, 0x1E, 0x06,
  32547. 0x11, 0x37, 0x4F, 0x6B, 0xF1, 0x7E, 0xAC, 0x0B,
  32548. 0xD5, 0x6F, 0x3B, 0x6B, 0xF3, 0x36, 0xDA, 0x92,
  32549. 0x42, 0x07, 0x0C, 0x24, 0x69, 0xA2, 0x0C, 0x4D,
  32550. 0x16, 0x16, 0x14, 0x9A, 0x61, 0x59, 0x25, 0x20,
  32551. 0x11, 0xD2, 0x99, 0xF9, 0x3F, 0x98, 0x6D, 0x87,
  32552. 0x5D, 0xD3, 0x0B, 0x38, 0xA2, 0x25, 0x49, 0x17,
  32553. 0x45, 0x70, 0x13, 0x8C, 0x2B, 0xB3, 0xAA, 0x9C,
  32554. 0xBE, 0xA9, 0x19, 0x74, 0xF3, 0xD8, 0x9B, 0xF5,
  32555. 0xAE, 0x32, 0xBE, 0x9E, 0x58, 0xB8, 0x54, 0xA2,
  32556. 0xF8, 0xE8, 0x6F, 0xF7, 0x67, 0x80, 0xC0, 0x34,
  32557. 0x90, 0xF4, 0x67, 0xDB, 0x06, 0x51, 0xC2, 0x0B,
  32558. 0x1D, 0xF6, 0x0E, 0xB9, 0x7A, 0x3C, 0x99, 0xD9,
  32559. 0xBD, 0x66, 0x4B, 0xE6, 0xA5, 0xE4, 0xC8, 0xA8,
  32560. 0xAD, 0x4C, 0xC3, 0x63, 0x90, 0xD7, 0x00, 0x4E,
  32561. 0x4B, 0xB4, 0x21, 0xDA, 0xED, 0x65, 0x4C, 0x35,
  32562. 0x7D, 0xA4, 0xD6, 0x84, 0x98, 0x93, 0x3E, 0xC7,
  32563. 0x17, 0x77, 0xAD, 0x64, 0xC2, 0xAE, 0x01, 0x3C,
  32564. 0x73, 0xEB, 0x45, 0x7C, 0x68, 0xEF, 0x9A, 0x74,
  32565. 0x5A, 0xDE, 0xEB, 0x4F, 0xDF, 0xC8, 0x79, 0xE7,
  32566. 0x74, 0xD0, 0x3F, 0xAF, 0x6B, 0x14, 0xAA, 0xB1,
  32567. 0x07, 0x52, 0xE2, 0x4B, 0x52, 0xD0, 0xF2, 0xD9,
  32568. 0x4D, 0x54, 0x0A, 0x1E, 0xBE, 0x10, 0xF5, 0x97,
  32569. 0xE5, 0x14, 0x44, 0x2D, 0x6C, 0x13, 0xC2, 0xE2,
  32570. 0x49, 0x8E, 0x8A, 0xF3, 0x01, 0x7C, 0x52, 0xDB,
  32571. 0x23, 0x3A, 0x90, 0x71, 0x7D, 0xF2, 0x5B, 0x4D,
  32572. 0x07, 0x2B, 0x7D, 0x88, 0xEE, 0x87, 0x31, 0xD1,
  32573. 0x68, 0x24, 0xC9, 0x5D, 0x1F, 0xB9, 0x83, 0xC4,
  32574. 0x49, 0xDE, 0xB4, 0x66, 0x27, 0x60, 0x60, 0xFE,
  32575. 0xE4, 0xC7, 0xEE, 0x38, 0x14, 0x51, 0xF2, 0x32,
  32576. 0xC2, 0x9C, 0x7C, 0x32, 0x20, 0x85, 0x0C, 0x61,
  32577. 0xD1, 0xC3, 0xC0, 0x0D, 0xB1, 0xCD, 0x97, 0x26,
  32578. 0xA0, 0x2A, 0x56, 0x60, 0x9F, 0x3A, 0x65, 0xD3,
  32579. 0xD1, 0x64, 0x60, 0x45, 0x88, 0xCD, 0x9B, 0x43,
  32580. 0x14, 0x12, 0xF1, 0xAD, 0xD9, 0x14, 0xC5, 0xC2,
  32581. 0xDA, 0xBB, 0xC9, 0x04, 0x67, 0xC0, 0xC4, 0xEA,
  32582. 0x5F, 0x76, 0xE2, 0x4A, 0xA6, 0x18, 0x76, 0x5F,
  32583. 0x8B, 0x06, 0x36, 0xD7, 0xB0, 0x65, 0xE1, 0xF4,
  32584. 0xE6, 0xF6, 0x22, 0xEA, 0xE1, 0x71, 0x52, 0x45,
  32585. 0x8C, 0x76, 0x65, 0x86, 0x77, 0x2D, 0x36, 0x3F,
  32586. 0xA9, 0x92, 0x14, 0xF4, 0x72, 0xB0, 0xDB, 0x8A,
  32587. 0x1E, 0x49, 0xD8, 0x2D, 0x02, 0x78, 0xF2, 0x95,
  32588. 0x8B, 0x0A, 0xAA, 0x15, 0x86, 0xDB, 0x13, 0x4B,
  32589. 0xDF, 0xD2, 0x43, 0x87, 0x42, 0x49, 0x50, 0x07,
  32590. 0xE2, 0xFE, 0x5B, 0x60, 0xE2, 0x46, 0x39, 0x92,
  32591. 0x26, 0x94, 0x7A, 0x12, 0xEA, 0x17, 0x63, 0x1C,
  32592. 0xAA, 0x53, 0x46, 0x87, 0xCB, 0x75, 0xC0, 0x60,
  32593. 0xB4, 0x79, 0x7E, 0xAB, 0x82, 0x77, 0xCC, 0x4F,
  32594. 0x8A, 0x7A, 0x20, 0x38, 0x76, 0x06, 0xEF, 0xE2,
  32595. 0xDB, 0xD3, 0xE7, 0x36, 0x24, 0x92, 0x77, 0xD9,
  32596. 0x0F, 0xCA, 0xB9, 0x92, 0xA8, 0xC9, 0x9E, 0x85,
  32597. 0xAB, 0x03, 0xEB, 0x4C, 0xAC, 0x5D, 0x88, 0x55,
  32598. 0x39, 0x58, 0x52, 0x8A, 0xF9, 0x29, 0x74, 0x71,
  32599. 0x81, 0x35, 0xF1, 0xD0, 0xC7, 0x93, 0xEB, 0x00,
  32600. 0x0E, 0xA0, 0xAE, 0xC3, 0xEC, 0x18, 0x58, 0xFD,
  32601. 0xD1, 0x86, 0x88, 0xD1, 0xDA, 0x27, 0x27, 0x8D,
  32602. 0xEB, 0xF2, 0xCA, 0x81, 0x10, 0xBA, 0x4A, 0x20,
  32603. 0x4F, 0x79, 0x30, 0xE1, 0xC8, 0xCE, 0xEC, 0xAF,
  32604. 0xB7, 0x3F, 0x75, 0xDD, 0xB3, 0x4C, 0x5C, 0x55,
  32605. 0x96, 0x8A, 0x79, 0x33, 0x05, 0x84, 0x26, 0xB5,
  32606. 0x5D, 0x03, 0x9F, 0x72, 0x92, 0xAC, 0x43, 0xF6,
  32607. 0x45, 0x84, 0xF6, 0xDF, 0x18, 0x7A, 0x1D, 0x6B,
  32608. 0x00, 0x3F, 0x51, 0x4C, 0xC1, 0x3B, 0x26, 0xC2,
  32609. 0xF3, 0x48, 0x19, 0x5A, 0xA3, 0x21, 0xDE, 0x6A,
  32610. 0x27, 0xEC, 0x11, 0x34, 0x8D, 0xE5, 0x0D, 0x82,
  32611. 0x5A, 0x29, 0x64, 0xC6, 0x31, 0x99, 0x2E, 0x4B,
  32612. 0x0B, 0x42, 0x5B, 0x1B, 0xEB, 0x4F, 0x96, 0x00,
  32613. 0xE3, 0xAD, 0xC4, 0x43, 0x1C, 0xF2, 0xE8, 0x8B,
  32614. 0x42, 0x23, 0xD2, 0xDB, 0x66, 0x3C, 0x3C, 0xE7,
  32615. 0x0E, 0xF8, 0x5D, 0xDD, 0x56, 0xA9, 0xBA, 0xF1,
  32616. 0x38, 0xA9, 0xD7, 0xED, 0xD8, 0x94, 0x13, 0x1C,
  32617. 0x3A, 0x8F, 0x41, 0xA0, 0x4E, 0xF9, 0xF8, 0x67,
  32618. 0x52, 0xB7, 0x21, 0x81, 0xFA, 0xBB, 0x37, 0xC8,
  32619. 0x6B, 0x87, 0x7E, 0x61, 0xD6, 0x0E, 0xED, 0x95,
  32620. 0xEE, 0xFF, 0xAB, 0xE6, 0x37, 0x6E, 0x14, 0xAC,
  32621. 0xA8, 0x17, 0xC5, 0xF4, 0x19, 0x61, 0xAF, 0x8A,
  32622. 0x78, 0x49, 0xBA, 0xC0, 0x94, 0x91, 0x7B, 0x2D,
  32623. 0x13, 0x22, 0x76, 0xB6, 0xB3, 0x48, 0x6A, 0xFF,
  32624. 0x95, 0x0D, 0x23, 0xD4, 0xAA, 0xDC, 0x24, 0xCE,
  32625. 0x98, 0xA5, 0x26, 0x9E, 0x1C, 0x69, 0x91, 0x79,
  32626. 0x60, 0xA3, 0x1E, 0xE0, 0x9A, 0x52, 0x7C, 0x35,
  32627. 0x81, 0x75, 0xCA, 0xA0, 0xCB, 0x1B, 0x01, 0x8E,
  32628. 0x95, 0x26, 0xD9, 0x35, 0x34, 0xEA, 0xDB, 0xAC,
  32629. 0xB5, 0x2B, 0x27, 0x3D, 0x73, 0x5E, 0x22, 0xDD,
  32630. 0x0D, 0x5C, 0x28, 0xFA, 0x3E, 0x47, 0xCF, 0xE9,
  32631. 0x0B, 0x52, 0x15, 0xAE, 0x24, 0xF1, 0x46, 0xC3,
  32632. 0x46, 0x4B, 0xFE, 0xAF, 0x01, 0xD2, 0x8D, 0xAA,
  32633. 0x55, 0x3C, 0x1E, 0x94, 0x42, 0x8A, 0x10, 0x4A,
  32634. 0x9D, 0x78, 0xAE, 0xC7, 0x62, 0x59, 0x1E, 0x88,
  32635. 0x79, 0xF7, 0x68, 0x51, 0xCF, 0xB4, 0x64, 0x85,
  32636. 0x66, 0x72, 0x1B, 0x0C, 0xAC, 0x1F, 0x14, 0xFE,
  32637. 0x16, 0x14, 0x9A, 0x9D, 0x82, 0x10, 0xCC, 0x8F,
  32638. 0x2F, 0x50, 0xDE, 0xF7, 0xB4, 0x6C, 0x84, 0x3B,
  32639. 0xE9, 0x3B, 0xD8, 0xD5, 0x56, 0x02, 0x49, 0x33,
  32640. 0x50, 0xAB, 0x56, 0x0E, 0xA5, 0xBA, 0x17, 0x71,
  32641. 0x64, 0x23, 0xBE, 0x0E, 0xB8, 0x36, 0x0A, 0xB1,
  32642. 0x09, 0xD8, 0xFB, 0x18, 0xBF, 0xEA, 0x04, 0x08,
  32643. 0x47, 0xB7, 0x33, 0x51, 0x45, 0xD4, 0xF2, 0x00,
  32644. 0xD1, 0x9C, 0xF6, 0xFE, 0x7B, 0xAC, 0x91, 0x7F,
  32645. 0x42, 0x6C, 0x9B, 0x3D, 0x39, 0xA9, 0xCA, 0x43,
  32646. 0x29, 0x81, 0x8F, 0x24, 0x0E, 0x7D, 0xA3, 0x82,
  32647. 0x76, 0x10, 0x72, 0xF4, 0xA6, 0x50, 0x5E, 0xA8,
  32648. 0xE7, 0x6C, 0x1E, 0x44, 0x6F, 0xEB, 0x66, 0x25,
  32649. 0xE3, 0x8D, 0xDB, 0xCD, 0x3C, 0xDA, 0x81, 0xE8,
  32650. 0x3B, 0xF7, 0x68, 0xF3, 0xE0, 0x1D, 0x9D, 0x26,
  32651. 0x3B, 0x36, 0x73, 0x03, 0xAE, 0x15, 0x6C, 0x0B,
  32652. 0x71, 0x83, 0x36, 0x4A, 0x1E, 0x79, 0x41, 0xA0,
  32653. 0x92, 0x98, 0xA3, 0xAD, 0xF7, 0xBD, 0x23, 0x1E,
  32654. 0x61, 0x14, 0xB9, 0xDC, 0xE7, 0x95, 0x2B, 0x11,
  32655. 0x3F, 0x78, 0x16, 0x31, 0x38, 0xB9, 0x26, 0x6F,
  32656. 0x84, 0x3F, 0x1E, 0xD9, 0x7D, 0x9C, 0x2B, 0x16,
  32657. 0x3A, 0x6E, 0x8B, 0xD4, 0xC1, 0xAB, 0x4E, 0x17,
  32658. 0x93, 0x67, 0xC5, 0xAC, 0x96, 0xCE, 0xCF, 0x50,
  32659. 0x50, 0xFE, 0x82, 0x1F, 0xDF, 0xA4, 0x4E, 0x9E,
  32660. 0x68, 0x0B, 0x61, 0xC6, 0x01, 0x89, 0x32, 0xDF,
  32661. 0x71, 0x78, 0x11, 0x45, 0x9A, 0xF2, 0x54, 0x2E,
  32662. 0x2C, 0xDE, 0x77, 0x17, 0x8C, 0x2E, 0x98, 0x80,
  32663. 0xF0, 0x11, 0xE4, 0x05, 0xEA, 0xFA, 0x59, 0xC8,
  32664. 0xCB, 0xBE, 0xD7, 0x6E, 0x5A, 0x19, 0x41, 0x10,
  32665. 0x4B, 0x1B, 0x9D, 0x3A, 0x60, 0x49, 0x1C, 0x95,
  32666. 0x47, 0x55, 0xE0, 0x2E, 0x89, 0x41, 0x03, 0xF1,
  32667. 0xF4, 0x97, 0x74, 0x75, 0xE9, 0xEA, 0x36, 0x60,
  32668. 0x9F, 0xD6, 0x7C, 0x9D, 0xE3, 0x18, 0xED, 0xA2,
  32669. 0x37, 0x0D, 0xCC, 0xDB, 0xB9, 0xCE, 0xF7, 0xAE,
  32670. 0x63, 0x60, 0x90, 0x5E, 0xC2, 0x20, 0x83, 0x8C,
  32671. 0x97, 0x69, 0x82, 0x34, 0x41, 0xCD, 0xD0, 0xDA,
  32672. 0x8E, 0xF0, 0xAB, 0xE5, 0xF2, 0xD1, 0xD7, 0x6E,
  32673. 0x2F, 0xE0, 0x8F, 0xEF, 0x53, 0xDE, 0x1D, 0x61,
  32674. 0x66, 0xAB, 0x1A, 0x92, 0xB1, 0xAC, 0x09, 0x3E,
  32675. 0x5A, 0xBF, 0x76, 0x58, 0xC4, 0xB5, 0x72, 0x87,
  32676. 0xF2, 0xD1, 0xFD, 0x7B, 0x82, 0xDE, 0xDA, 0xF8,
  32677. 0xD5, 0xA4, 0xFB, 0xAC, 0x4B, 0x35, 0xD5, 0x82,
  32678. 0x31, 0x69, 0x4E, 0x16, 0x24, 0x97, 0x57, 0x8A,
  32679. 0xBD, 0x7A, 0xA7, 0xC8, 0xFE, 0x7B, 0x35, 0x41,
  32680. 0xA7, 0xF1, 0x8E, 0x54, 0xE8, 0xB7, 0xF0, 0x87,
  32681. 0x64, 0xC5, 0xE6, 0x84, 0x49, 0xDF, 0x65, 0x59,
  32682. 0x01, 0x54, 0x98, 0x32, 0xD6, 0x28, 0xFA, 0x63,
  32683. 0xD2, 0xB2, 0xC5, 0xA1, 0x50, 0x93, 0x39, 0x94,
  32684. 0xA9, 0x86, 0x33, 0x17, 0xAD, 0x40, 0xD7, 0x78,
  32685. 0xD9, 0xD2, 0xC0, 0x5C, 0x78, 0x98, 0x85, 0x0B,
  32686. 0x90, 0x17, 0x32, 0x23, 0xC7, 0xA0, 0xAF, 0x89,
  32687. 0x0F, 0xD7, 0xE6, 0x62, 0x21, 0xB6, 0xF0, 0x63,
  32688. 0x18, 0xB2, 0xED, 0x5E, 0x19, 0x9C, 0xB4, 0x24,
  32689. 0x88, 0x5A, 0xB8, 0x41, 0xE7, 0xA4, 0x72, 0x6F,
  32690. 0xAB, 0xA2, 0xF9, 0xBB, 0x53, 0xBC, 0x32, 0x36,
  32691. 0x43, 0x4C, 0x35, 0xFB, 0xBE, 0x4B, 0x1A, 0x0F,
  32692. 0x93, 0xF5, 0x0C, 0x37, 0x89, 0x6C, 0x29, 0xF8,
  32693. 0xE3, 0x02, 0xAD, 0x31, 0xED, 0x33, 0x31, 0xD6,
  32694. 0x20, 0xE3, 0xB6, 0x29, 0x45, 0x51, 0x01, 0xA1,
  32695. 0xF1, 0xCC, 0x7B, 0xA5, 0xE4, 0x6E, 0x68, 0xED,
  32696. 0x4A, 0x8C, 0xCC, 0x87, 0xB4, 0xDC, 0x75, 0xBC,
  32697. 0x01, 0x62, 0xB6, 0x33, 0x0F, 0x83, 0x3F, 0xBA,
  32698. 0x25, 0x75, 0xDF, 0xAF, 0x5B, 0x5F, 0x28, 0xBC,
  32699. 0x54, 0xFF, 0x2B, 0xA8, 0x1E, 0x7A, 0x47, 0x31,
  32700. 0x3C, 0x15, 0x48, 0x2B, 0x60, 0x5E, 0x66, 0xBB,
  32701. 0x38, 0xC6, 0x19, 0x8F, 0x13, 0x92, 0x10, 0x40,
  32702. 0x80, 0xFB, 0xE7, 0x8B, 0x86, 0xB1, 0xBC, 0x9A,
  32703. 0x6F, 0xB8, 0x81, 0xF5, 0xC7, 0x82, 0x01, 0x47,
  32704. 0xE6, 0xBA, 0x14, 0xB8, 0x1A, 0xCC, 0xF2, 0x0C,
  32705. 0xAE, 0x96, 0x64, 0x10, 0x94, 0xC2, 0x16, 0x90,
  32706. 0x2E, 0xA5, 0xC1, 0x25, 0xF6, 0xC9, 0x35, 0xA1,
  32707. 0x50, 0xD7, 0xC9, 0xAC, 0xC5, 0xD9, 0xE2, 0xE5,
  32708. 0xD9, 0x0E, 0x38, 0xC0, 0x50, 0x3A, 0xA9, 0x42,
  32709. 0x60, 0x17, 0xC7, 0x6A, 0xAF, 0xCD, 0x52, 0x61,
  32710. 0xB5, 0x06, 0x27, 0x4E, 0xC1, 0x3A, 0x96, 0x79,
  32711. 0xFB, 0x09, 0x79, 0x60, 0x27, 0xA4, 0xBB, 0x75,
  32712. 0x9D, 0x92, 0x82, 0x79, 0xB9, 0x4D, 0x84, 0x1A,
  32713. 0x09, 0x73, 0x93, 0xBF, 0x7E, 0x5B, 0xD6, 0x9A,
  32714. 0x49, 0x6C, 0xC3, 0xDE, 0xCD, 0x2B, 0x0F, 0x07,
  32715. 0xF8, 0x33, 0x92, 0xAA, 0xDE, 0x33, 0xDC, 0x51,
  32716. 0xB2, 0xA8, 0x4F, 0x6A, 0x07, 0x63, 0x5D, 0xC0,
  32717. 0xEF, 0x57, 0xA9, 0xAD, 0x59, 0x59, 0xB6, 0xA5,
  32718. 0x0B, 0x7B, 0xA5, 0x09, 0xAD, 0x5B, 0x11, 0xFA,
  32719. 0xD2, 0x6B, 0x41, 0x9F, 0x9F, 0x1E, 0x3F, 0x9C,
  32720. 0x73, 0x29, 0xB5, 0xA9, 0x53, 0xD7, 0xCC, 0x87,
  32721. 0xB2, 0xDE, 0x21, 0x06, 0x11, 0xCF, 0x52, 0xA6,
  32722. 0x39, 0xEF, 0x2B, 0x39, 0x08, 0x01, 0x2C, 0xB8,
  32723. 0x8E, 0x1D, 0x6F, 0x57, 0x62, 0x50, 0x79, 0xCB,
  32724. 0x10, 0x3D, 0x6C, 0x98, 0x10, 0x1A, 0x11, 0xBD,
  32725. 0x22, 0x33, 0xB6, 0x56, 0x02, 0xCA, 0x30, 0x49,
  32726. 0xBD, 0x32, 0x05, 0x20, 0x41, 0x9F, 0x76, 0xB0,
  32727. 0x61, 0xE3, 0x59, 0x8D, 0xE3, 0x81, 0x52, 0xC8,
  32728. 0x87, 0x67, 0xD1, 0xA2, 0x4F, 0xBD, 0x02, 0xBB,
  32729. 0x10, 0xC3, 0x8E, 0xAC, 0xAE, 0x31, 0x7D, 0xE6,
  32730. 0xBB, 0x28, 0x7B, 0x4D, 0x2C, 0xAE, 0x5D, 0xA0,
  32731. 0x21, 0x49, 0x65, 0xD8, 0x77, 0x37, 0x78, 0x62,
  32732. 0x6E, 0x9B, 0x97, 0x28, 0x59, 0xD8, 0x48, 0x2B,
  32733. 0x8D, 0x05, 0x47, 0xE4, 0xF5, 0x6D, 0xFF, 0x87,
  32734. 0x68, 0x1D, 0x5B, 0xC5, 0x12, 0x0F, 0x61, 0x3F,
  32735. 0xBB, 0xD9, 0x1E, 0x1F, 0x14, 0xE6, 0xDE, 0xFE,
  32736. 0x67, 0x2E, 0x2A, 0x7E, 0xAB, 0xCB, 0xBB, 0x9B,
  32737. 0x11, 0x08, 0x2C, 0x5E, 0x70, 0x0A, 0xA0, 0xB1,
  32738. 0xF7, 0xC1, 0x78, 0x5F, 0xCE, 0xD1, 0x9A, 0x93,
  32739. 0xAF, 0xE7, 0xC5, 0x9F, 0xA2, 0x51, 0x9B, 0xCD,
  32740. 0xEB, 0x49, 0x4C, 0x3D, 0x13, 0xB2, 0x12, 0x5F,
  32741. 0x38, 0x53, 0x23, 0xB8, 0x16, 0xC6, 0x8F, 0x8F,
  32742. 0x56, 0x28, 0xC7, 0xC2, 0xAB, 0xFD, 0x02, 0x78,
  32743. 0xA3, 0x37, 0x07, 0x3D, 0xA7, 0x4D, 0x16, 0x09,
  32744. 0x96, 0x98, 0xC4, 0xB1, 0x14, 0xE8, 0xA8, 0xCE,
  32745. 0x34, 0x4E, 0x0A, 0x15, 0xD0, 0xFC, 0x7E, 0xD4,
  32746. 0x97, 0xB0, 0x01, 0xD5, 0x3D, 0x4C, 0x96, 0xDC,
  32747. 0x39, 0x54, 0xD3, 0xB4, 0xB9, 0x56, 0xCB, 0x9D,
  32748. 0x2A, 0x27, 0x2C, 0x51, 0xF1, 0x55, 0x9B, 0x22,
  32749. 0x90, 0x4B, 0x40, 0xCC, 0x85, 0x31, 0xE4, 0x0C,
  32750. 0xC4, 0x12, 0xC6, 0x8C, 0xB6, 0xEE, 0xA4, 0xA4,
  32751. 0x09, 0x0B, 0x38, 0xE2, 0x79, 0x73, 0x29, 0x98,
  32752. 0x54, 0x67, 0xE8, 0x18, 0xA5, 0x24, 0xD3, 0x22,
  32753. 0x8E, 0xAC, 0xAE, 0x78, 0x25, 0xD3, 0xDA, 0xD2,
  32754. 0xEA, 0xA4, 0x22, 0xFD, 0xC7, 0x7A, 0xED, 0x71,
  32755. 0xA2, 0x05, 0xDA, 0x78, 0x38, 0xD9, 0x45, 0xE7,
  32756. 0xFE, 0xC3, 0x7E, 0x4D, 0xCA, 0x67, 0xE5, 0x04,
  32757. 0xCE, 0x35, 0xE5, 0xB0, 0x45, 0xF5, 0x6F, 0x1E,
  32758. 0x8D, 0x75, 0x29, 0xEB, 0xD6, 0xF1, 0xAF, 0x7B,
  32759. 0x6E, 0x93, 0x9E, 0x2B, 0x7A, 0xB4, 0x02, 0x7D,
  32760. 0x37, 0xA5, 0x13, 0x5D, 0x17, 0x2D, 0xA1, 0xAF,
  32761. 0x9C, 0xA2, 0xF7, 0x28, 0xA6, 0xF3, 0x7D, 0xE6,
  32762. 0x0D, 0xD2, 0x3D, 0x97, 0xD1, 0x1E, 0x75, 0xAB,
  32763. 0x1F, 0xD5, 0x1F, 0x8E, 0x9A, 0x13, 0x97, 0xE5,
  32764. 0x82, 0x21, 0x59, 0xDB, 0x58, 0x38, 0x02, 0xB3,
  32765. 0x2E, 0xEB, 0xB4, 0x56, 0x7E, 0xCE, 0x37, 0x46,
  32766. 0xD1, 0xAE, 0x33, 0x31, 0x47, 0x85, 0x64, 0x3D,
  32767. 0xD2, 0xA0, 0x74, 0x1E, 0x7F, 0x1B, 0xF2, 0xD2,
  32768. 0x61, 0xF2, 0x21, 0x24, 0xE8, 0xDD, 0xD0, 0x8C,
  32769. 0x64, 0x0A, 0x48, 0xB5, 0x47, 0x17, 0x51, 0x7C,
  32770. 0x21, 0xCD, 0x32, 0x53, 0x28, 0xBC, 0x23, 0x9C,
  32771. 0xA0, 0x28, 0xB2, 0x63, 0x0D, 0x06, 0x3C, 0x8C,
  32772. 0xC2, 0x0B, 0xE9, 0xBD, 0xB4, 0x85, 0x02, 0xDA,
  32773. 0xDD, 0xE7, 0x3F, 0xFE, 0xD5, 0x96, 0x38, 0x16,
  32774. 0x53, 0x3E, 0x02, 0x0A, 0xED, 0x12, 0x08, 0x53,
  32775. 0x62, 0x55, 0xB1, 0xCC, 0xE9, 0x85, 0x43, 0x31,
  32776. 0x27, 0xFF, 0x4F, 0x04, 0xD5, 0xB1, 0xE2, 0xF2,
  32777. 0x10, 0x87, 0x04, 0xB8, 0xB9, 0x66, 0x58, 0x8C,
  32778. 0x01, 0x56, 0xAF, 0xC2, 0xAE, 0x19, 0x29, 0x86,
  32779. 0xFB, 0xEC, 0x44, 0x3B, 0xAE, 0xF6, 0xCB, 0x85,
  32780. 0xA6, 0xF2, 0x9C, 0x77, 0x92, 0x40, 0x5A, 0x24,
  32781. 0x11, 0x47, 0x10, 0xAE, 0x1C, 0x74, 0x64, 0x44,
  32782. 0xFD, 0xF5, 0xFB, 0x65, 0x9E, 0x5E, 0x34, 0x68,
  32783. 0x26, 0x20, 0x7B, 0x8C, 0x54, 0x46, 0x3A, 0x06,
  32784. 0x17, 0xCE, 0x17, 0xFF, 0x33, 0xE4, 0x0F, 0x93,
  32785. 0x1F, 0xE5, 0x76, 0x71, 0x5C, 0x93, 0x2E, 0xF2,
  32786. 0x9F, 0xD7, 0x6B, 0x04, 0xA6, 0x9B, 0x58, 0xE0,
  32787. 0x30, 0x3D, 0x8E, 0xF2, 0x56, 0x78, 0xC8, 0xB7,
  32788. 0x0A, 0xF1, 0x2E, 0x90, 0x45, 0x59, 0x1C, 0x04,
  32789. 0xE8, 0xB7, 0x71, 0x06, 0x94, 0x04, 0x15, 0x17,
  32790. 0x7E, 0x86, 0x85, 0x93, 0xA0, 0x9C, 0x7E, 0x14,
  32791. 0x61, 0x9A, 0x4B, 0x33, 0x2F, 0x9A, 0xDC, 0x3A,
  32792. 0x65, 0x8B, 0x86, 0x01, 0x7F, 0x32, 0x65, 0x6C,
  32793. 0x54, 0x29, 0xC1, 0x15, 0xE1, 0x10, 0x03, 0x7A,
  32794. 0x8C, 0xC7, 0xE5, 0x44, 0x67, 0x7D, 0x2D, 0xD2,
  32795. 0x39, 0xA5, 0x9D, 0x54, 0xD0, 0xF3, 0xC7, 0x46,
  32796. 0x0E, 0xC1, 0x52, 0x08, 0x34, 0x6B, 0xA5, 0x6D,
  32797. 0xF5, 0x08, 0x6C, 0x5D, 0xBC, 0xC4, 0x1E, 0x0C,
  32798. 0x95, 0xFC, 0xB6, 0x86, 0x1C, 0x2C, 0x0C, 0x32,
  32799. 0xAA, 0xF3, 0x45, 0x4E, 0xFE, 0xE2, 0xFF, 0xBA,
  32800. 0x21, 0x4B, 0x43, 0x0E, 0xF2, 0x48, 0xA5, 0x9B,
  32801. 0x32, 0x44, 0x4D, 0x8D, 0x0D, 0x3D, 0xB8, 0x7C,
  32802. 0x9D, 0x4B, 0x15, 0x36, 0xD1, 0x57, 0x72, 0x8E,
  32803. 0xE7, 0x58, 0x5E, 0xF5, 0x32, 0x77, 0x6A, 0x00,
  32804. 0x3A, 0x02, 0x3C, 0x0A, 0xB0, 0xE9, 0xFF, 0x55,
  32805. 0x71, 0x08, 0xC3, 0x90, 0x68, 0x4D, 0x56, 0x5A,
  32806. 0x66, 0x50, 0x63, 0x26, 0x6A, 0xE6, 0x67, 0x0E,
  32807. 0xD5, 0x3B, 0x0F, 0xAF, 0x8F, 0xF6, 0x78, 0x29,
  32808. 0xBB, 0x73, 0x78, 0x25, 0xB1, 0x53, 0xA9, 0x33,
  32809. 0x8C, 0xBE, 0x3D, 0xF1, 0xA4, 0x62, 0x84, 0x9B,
  32810. 0x93, 0xA8, 0x1F, 0x84, 0xED, 0x07, 0xBE, 0x6D,
  32811. 0x62, 0x40, 0x00, 0x32, 0x74, 0x73, 0x7F, 0x61,
  32812. 0x8D, 0xCB, 0x26, 0xE4, 0x82, 0x52, 0xCE, 0x42,
  32813. 0x04, 0xDD, 0x31, 0x39, 0xFF, 0x68, 0x76, 0xF4,
  32814. 0x3B, 0x30, 0x5D, 0x83, 0x56, 0x20, 0xFE, 0xDF,
  32815. 0x79, 0xAA, 0x67, 0x43, 0x3D, 0xC2, 0x52, 0x87,
  32816. 0x32, 0x0E, 0x99, 0x17, 0x96, 0x7B, 0x70, 0xB2,
  32817. 0xD8, 0x66, 0xD1, 0x7B, 0x69, 0x8B, 0xFF, 0xF2,
  32818. 0xB3, 0xAB, 0x95, 0x14, 0x94, 0x9E, 0x58, 0xB5,
  32819. 0x7C, 0x68, 0xA4, 0x54, 0x12, 0xC1, 0xFC, 0x42,
  32820. 0x1C, 0x76, 0x8B, 0xF5, 0xEE, 0x8A, 0x10, 0xC8,
  32821. 0xAE, 0xF5, 0x69, 0x26, 0xF5, 0x1E, 0xC6, 0x2C,
  32822. 0x11, 0x56, 0x9F, 0x31, 0xAA, 0x51, 0x78, 0x68,
  32823. 0xE5, 0xCA, 0xD8, 0x9E, 0x95, 0x80, 0x66, 0xEB,
  32824. 0x9E, 0xDD, 0x72, 0x71, 0xB3, 0x1C, 0xB4, 0xB1,
  32825. 0xD6, 0xCE, 0x21, 0x12, 0x25, 0xAE, 0xB5, 0xB5,
  32826. 0x7F, 0x74, 0x97, 0x19, 0xDA, 0x07, 0xEC, 0xBE,
  32827. 0xFE, 0x03, 0x88, 0x1D, 0xDE, 0x3D, 0x81, 0xE4,
  32828. 0x13, 0x5F, 0x2D, 0xC8, 0x1A, 0xF7, 0x79, 0x77,
  32829. 0x6C, 0x1B, 0x80, 0x57, 0x16, 0x2A, 0x6C, 0x98,
  32830. 0x2F, 0xBB, 0x4D, 0xA6, 0xA9, 0xAD, 0x28, 0x4A,
  32831. 0xB1, 0x0C, 0x70, 0x02, 0x20, 0x44, 0xF4, 0x6D,
  32832. 0x40, 0x0B, 0xF6, 0xAD, 0x71, 0x82, 0xD1, 0x97,
  32833. 0x78, 0x99, 0x83, 0xBE, 0x99, 0x22, 0x79, 0x79,
  32834. 0xA1, 0x33, 0x4B, 0xA1, 0x49, 0xD8, 0x69, 0xBA,
  32835. 0x1C, 0x40, 0x88, 0x12, 0x34, 0x35, 0xBF, 0x97,
  32836. 0x85, 0x41, 0x35, 0x6D, 0xAF, 0x17, 0x1F, 0x33,
  32837. 0xAD, 0xB1, 0xC9, 0x79, 0x07, 0xA0, 0xFB, 0x58,
  32838. 0x45, 0x07, 0x4A, 0x85, 0xD2, 0x6F, 0x54, 0x61,
  32839. 0x35, 0xAE, 0xD0, 0xF9, 0x1B, 0xE4, 0x53, 0x9C,
  32840. 0x12, 0xBF, 0x94, 0x11, 0xE4, 0xB5, 0x56, 0xF6,
  32841. 0x87, 0xD0, 0x69, 0xDB, 0x6B, 0x21, 0xFE, 0x2B,
  32842. 0x7F, 0x32, 0x18, 0x87, 0x44, 0x8C, 0xEA, 0x55,
  32843. 0xDB, 0x19, 0xFB, 0xB8, 0xB0, 0x48, 0x2A, 0x55,
  32844. 0xAE, 0xC1, 0x67, 0x38, 0xD7, 0x4C, 0xD2, 0x65,
  32845. 0x09, 0x38, 0x36, 0xBE, 0x99, 0xD4, 0xFB, 0x53,
  32846. 0xE9, 0xB0, 0x14, 0xB0, 0x37, 0xCD, 0xBF, 0xE9
  32847. };
  32848. static const byte sk_87[] = {
  32849. 0x69, 0x24, 0xBB, 0x42, 0x57, 0xA7, 0xB9, 0xAF,
  32850. 0xF0, 0x95, 0xC3, 0x0B, 0xB3, 0x5C, 0x6A, 0xE4,
  32851. 0x19, 0x82, 0x63, 0x12, 0x0F, 0x80, 0x39, 0xAA,
  32852. 0x4E, 0x78, 0xE1, 0x74, 0xA7, 0x86, 0xCE, 0x00,
  32853. 0x3B, 0x9A, 0xC2, 0xC1, 0x42, 0x2A, 0x1A, 0xE8,
  32854. 0x02, 0xDD, 0xD7, 0x46, 0x4D, 0x3F, 0x32, 0x72,
  32855. 0x9A, 0x3C, 0x7D, 0xE8, 0x94, 0xD5, 0x06, 0xAC,
  32856. 0xAD, 0x25, 0xCE, 0xB3, 0x72, 0xEA, 0x31, 0x49,
  32857. 0xC9, 0x87, 0x80, 0xDC, 0xD1, 0x31, 0x4B, 0xAA,
  32858. 0x29, 0xB9, 0xB8, 0x07, 0x75, 0x4C, 0x47, 0xDE,
  32859. 0x5D, 0xCA, 0x95, 0x40, 0x64, 0xF2, 0x85, 0x28,
  32860. 0xB8, 0x15, 0xFE, 0x27, 0xB7, 0x9A, 0xC5, 0x06,
  32861. 0xB3, 0xAD, 0x76, 0x29, 0xD2, 0xC9, 0x71, 0xAB,
  32862. 0x8F, 0x28, 0x2E, 0x0C, 0x6E, 0x7E, 0x55, 0x48,
  32863. 0xEE, 0x0E, 0x11, 0x32, 0x42, 0xB7, 0xA0, 0xE0,
  32864. 0x64, 0xA6, 0xDB, 0xCE, 0x30, 0xC5, 0x61, 0x9B,
  32865. 0x19, 0x80, 0x08, 0x89, 0xA0, 0x44, 0x04, 0xB5,
  32866. 0x00, 0x13, 0xC0, 0x88, 0xC1, 0x30, 0x29, 0x62,
  32867. 0x12, 0x4C, 0xD3, 0xB4, 0x91, 0x0A, 0x35, 0x2C,
  32868. 0x43, 0x12, 0x31, 0x19, 0x99, 0x65, 0x22, 0x18,
  32869. 0x52, 0x02, 0xC3, 0x85, 0x23, 0x44, 0x0D, 0x90,
  32870. 0x24, 0x4A, 0x1A, 0x30, 0x22, 0x44, 0x28, 0x61,
  32871. 0x81, 0x06, 0x29, 0x18, 0x97, 0x68, 0x0A, 0x20,
  32872. 0x09, 0x08, 0x32, 0x6A, 0x44, 0xA4, 0x4C, 0x44,
  32873. 0x90, 0x21, 0x8A, 0x16, 0x68, 0x9A, 0xA8, 0x51,
  32874. 0x1A, 0xA5, 0x2C, 0x62, 0x46, 0x8D, 0x04, 0xC3,
  32875. 0x40, 0xD3, 0x86, 0x28, 0x60, 0xA4, 0x60, 0x13,
  32876. 0x18, 0x70, 0x84, 0x94, 0x8C, 0x63, 0xC0, 0x44,
  32877. 0x04, 0xA9, 0x28, 0x20, 0x08, 0x20, 0x43, 0x16,
  32878. 0x2A, 0x23, 0x29, 0x2D, 0x1A, 0xB1, 0x29, 0x48,
  32879. 0xB6, 0x09, 0x21, 0x88, 0x31, 0x00, 0xC5, 0x30,
  32880. 0x00, 0xC4, 0x8C, 0xD9, 0x82, 0x68, 0xE1, 0x30,
  32881. 0x4C, 0x63, 0x32, 0x45, 0x0C, 0x32, 0x86, 0x18,
  32882. 0x08, 0x31, 0x91, 0x98, 0x0D, 0x10, 0xB8, 0x70,
  32883. 0x9B, 0x30, 0x22, 0x64, 0x04, 0x08, 0x93, 0xA4,
  32884. 0x8C, 0x21, 0xC9, 0x70, 0x0C, 0x35, 0x71, 0x5B,
  32885. 0x00, 0x0D, 0x14, 0x31, 0x22, 0xCC, 0x98, 0x10,
  32886. 0x21, 0x04, 0x80, 0x9B, 0x28, 0x64, 0x1C, 0x30,
  32887. 0x80, 0x21, 0x30, 0x71, 0x18, 0x33, 0x50, 0x24,
  32888. 0x25, 0x44, 0x08, 0x17, 0x8C, 0xC0, 0x08, 0x48,
  32889. 0x84, 0x44, 0x90, 0x48, 0x98, 0x30, 0xCA, 0x44,
  32890. 0x00, 0x09, 0x19, 0x51, 0x19, 0x23, 0x0C, 0x52,
  32891. 0x20, 0x0E, 0x49, 0x06, 0x32, 0x1C, 0x15, 0x4E,
  32892. 0x19, 0x48, 0x85, 0x13, 0x25, 0x49, 0xA3, 0x00,
  32893. 0x04, 0x08, 0x15, 0x6D, 0x20, 0x41, 0x0C, 0xDA,
  32894. 0x42, 0x52, 0xC1, 0x34, 0x8C, 0x00, 0x31, 0x69,
  32895. 0x43, 0x82, 0x24, 0x64, 0x94, 0x6D, 0x1C, 0x81,
  32896. 0x11, 0x01, 0x96, 0x21, 0x4B, 0x02, 0x00, 0xCA,
  32897. 0x28, 0x84, 0xCC, 0x46, 0x64, 0x51, 0x18, 0x6A,
  32898. 0x18, 0x10, 0x00, 0xA4, 0x98, 0x21, 0x60, 0xB0,
  32899. 0x68, 0x03, 0x94, 0x6C, 0x94, 0x48, 0x51, 0x80,
  32900. 0x40, 0x46, 0x92, 0x22, 0x2C, 0x23, 0x44, 0x69,
  32901. 0x98, 0x26, 0x4D, 0x1C, 0x01, 0x08, 0x52, 0x02,
  32902. 0x20, 0x8A, 0xA6, 0x08, 0x0A, 0x31, 0x61, 0x93,
  32903. 0x40, 0x0E, 0x9C, 0xC8, 0x11, 0x81, 0x32, 0x2E,
  32904. 0x21, 0x15, 0x84, 0x84, 0xC2, 0x41, 0x00, 0x22,
  32905. 0x72, 0x54, 0x22, 0x62, 0x58, 0x06, 0x92, 0x48,
  32906. 0x48, 0x44, 0x11, 0x27, 0x04, 0x04, 0xC0, 0x11,
  32907. 0x92, 0x82, 0x45, 0xA1, 0xC6, 0x8C, 0xE3, 0x32,
  32908. 0x66, 0xC1, 0x38, 0x72, 0x5A, 0x86, 0x01, 0x0C,
  32909. 0xC9, 0x90, 0x84, 0x34, 0x08, 0x58, 0xA8, 0x60,
  32910. 0x80, 0xC0, 0x70, 0xD0, 0x26, 0x62, 0x9B, 0x30,
  32911. 0x2A, 0x04, 0x29, 0x69, 0x04, 0x10, 0x8D, 0x0B,
  32912. 0xB9, 0x04, 0x50, 0x46, 0x28, 0x50, 0x48, 0x24,
  32913. 0xD0, 0x48, 0x05, 0xA2, 0x48, 0x02, 0xC3, 0x20,
  32914. 0x8C, 0xA0, 0x14, 0x00, 0x41, 0x38, 0x21, 0x4B,
  32915. 0x24, 0x01, 0x04, 0xB5, 0x49, 0x42, 0x00, 0x00,
  32916. 0x0C, 0x24, 0x28, 0x12, 0x40, 0x84, 0xA2, 0x20,
  32917. 0x44, 0x9B, 0x06, 0x90, 0x63, 0xC0, 0x88, 0x8C,
  32918. 0x14, 0x21, 0x49, 0x12, 0x10, 0x54, 0x16, 0x24,
  32919. 0x20, 0x87, 0x44, 0x50, 0x10, 0x85, 0x0C, 0xB5,
  32920. 0x64, 0xDB, 0x24, 0x41, 0xD0, 0x42, 0x29, 0x9A,
  32921. 0x16, 0x8A, 0x21, 0xB4, 0x4C, 0x13, 0xB7, 0x70,
  32922. 0x10, 0xC0, 0x85, 0x19, 0x02, 0x69, 0xCC, 0x40,
  32923. 0x61, 0x1C, 0x48, 0x46, 0x98, 0x06, 0x25, 0x60,
  32924. 0x14, 0x46, 0xE4, 0x22, 0x62, 0x24, 0x27, 0x22,
  32925. 0x62, 0x24, 0x29, 0x44, 0xC6, 0x2D, 0x08, 0x31,
  32926. 0x84, 0x20, 0x32, 0x21, 0x04, 0xB4, 0x61, 0x0A,
  32927. 0x38, 0x12, 0xD9, 0x28, 0x44, 0xA4, 0x08, 0x20,
  32928. 0xCC, 0xA8, 0x29, 0x0B, 0x21, 0x31, 0x0A, 0x34,
  32929. 0x29, 0x03, 0x21, 0x40, 0xC1, 0xA2, 0x6C, 0x8A,
  32930. 0x16, 0x12, 0x52, 0xA6, 0x64, 0xA3, 0xB2, 0x51,
  32931. 0x04, 0x29, 0x51, 0xC4, 0x04, 0x91, 0x63, 0xB0,
  32932. 0x2D, 0x14, 0x44, 0x30, 0x8C, 0x40, 0x66, 0x0C,
  32933. 0x40, 0x0C, 0x01, 0xA5, 0x2C, 0x09, 0x94, 0x2D,
  32934. 0x62, 0xC6, 0x11, 0x03, 0x98, 0x50, 0x19, 0x10,
  32935. 0x4D, 0x19, 0xA8, 0x28, 0xD3, 0x86, 0x40, 0xC0,
  32936. 0x30, 0x65, 0x54, 0xA6, 0x71, 0xE0, 0xB4, 0x85,
  32937. 0x9B, 0x86, 0x10, 0x04, 0x36, 0x69, 0xD0, 0x46,
  32938. 0x29, 0x18, 0xA3, 0x71, 0x40, 0x22, 0x49, 0x00,
  32939. 0x43, 0x85, 0xCB, 0x40, 0x28, 0x89, 0x36, 0x66,
  32940. 0x41, 0x22, 0x69, 0xA4, 0x28, 0x51, 0xD9, 0x80,
  32941. 0x29, 0x14, 0x07, 0x21, 0xDA, 0x80, 0x91, 0x1B,
  32942. 0x26, 0x50, 0x5B, 0xA0, 0x60, 0x99, 0x42, 0x71,
  32943. 0x50, 0x88, 0x49, 0x10, 0x23, 0x09, 0x5A, 0x90,
  32944. 0x21, 0x22, 0x27, 0x8E, 0x43, 0xB2, 0x70, 0x0C,
  32945. 0xC9, 0x4C, 0xA4, 0x02, 0x70, 0x92, 0x40, 0x10,
  32946. 0x0A, 0x39, 0x70, 0x02, 0x36, 0x0E, 0x11, 0x30,
  32947. 0x41, 0xD8, 0x40, 0x2D, 0x1B, 0x24, 0x6D, 0xC3,
  32948. 0x92, 0x61, 0x4C, 0x86, 0x8D, 0x21, 0xB8, 0x00,
  32949. 0xD3, 0x24, 0x22, 0x12, 0xC8, 0x21, 0x12, 0x99,
  32950. 0x85, 0x09, 0x16, 0x0C, 0x5A, 0xA2, 0x24, 0x09,
  32951. 0x34, 0x42, 0x10, 0xA2, 0x24, 0x03, 0x42, 0x8C,
  32952. 0xC0, 0xB2, 0x8D, 0x12, 0xB6, 0x69, 0x63, 0x34,
  32953. 0x0D, 0xCC, 0xB0, 0x65, 0xA1, 0x12, 0x11, 0x4A,
  32954. 0x38, 0x69, 0xCC, 0x14, 0x81, 0x58, 0x44, 0x09,
  32955. 0x54, 0xA6, 0x80, 0x0C, 0xA8, 0x05, 0xC4, 0x38,
  32956. 0x8A, 0x84, 0x06, 0x01, 0x9B, 0x32, 0x2D, 0x83,
  32957. 0x12, 0x90, 0x09, 0x02, 0x60, 0xA1, 0x28, 0x88,
  32958. 0x58, 0x10, 0x41, 0x24, 0x40, 0x02, 0x19, 0x34,
  32959. 0x48, 0x18, 0xA0, 0x4D, 0x00, 0x10, 0x62, 0x13,
  32960. 0x22, 0x50, 0xE3, 0x38, 0x21, 0x9A, 0x96, 0x21,
  32961. 0x53, 0x08, 0x80, 0x51, 0x26, 0x01, 0x99, 0xC4,
  32962. 0x28, 0x1B, 0xB9, 0x71, 0x04, 0x97, 0x84, 0x04,
  32963. 0x05, 0x2C, 0xA0, 0xC2, 0x10, 0xD3, 0x42, 0x81,
  32964. 0x81, 0x42, 0x4D, 0x61, 0x84, 0x6C, 0x5A, 0x30,
  32965. 0x49, 0x1B, 0xC2, 0x24, 0xC0, 0x20, 0x28, 0xCA,
  32966. 0x92, 0x2D, 0x4A, 0x90, 0x10, 0x04, 0x27, 0x86,
  32967. 0x4C, 0x96, 0x21, 0x09, 0x19, 0x45, 0x14, 0x82,
  32968. 0x2C, 0x11, 0xA6, 0x91, 0x13, 0xB8, 0x04, 0x03,
  32969. 0x18, 0x70, 0x01, 0xA2, 0x51, 0x52, 0x14, 0x49,
  32970. 0x5A, 0x02, 0x30, 0xCB, 0x30, 0x2C, 0x94, 0x10,
  32971. 0x2C, 0x00, 0x49, 0x86, 0x09, 0xA0, 0x25, 0xC2,
  32972. 0x12, 0x4C, 0x1B, 0x02, 0x69, 0x40, 0xA4, 0x44,
  32973. 0x41, 0x16, 0x62, 0x02, 0x25, 0x28, 0xDC, 0xA2,
  32974. 0x2D, 0x00, 0x16, 0x42, 0x58, 0x30, 0x66, 0x5B,
  32975. 0x86, 0x24, 0xD4, 0x24, 0x48, 0xDB, 0x26, 0x0C,
  32976. 0x4C, 0x08, 0x85, 0x01, 0x90, 0x49, 0x21, 0x24,
  32977. 0x41, 0x54, 0x06, 0x84, 0x02, 0x43, 0x4A, 0x24,
  32978. 0x42, 0x05, 0x40, 0x14, 0x48, 0xCA, 0x44, 0x84,
  32979. 0xC0, 0x42, 0x0C, 0x98, 0x26, 0x04, 0x9C, 0xA2,
  32980. 0x05, 0xD1, 0xC2, 0x51, 0x13, 0x01, 0x86, 0x1C,
  32981. 0xA1, 0x50, 0xD9, 0x02, 0x50, 0x0C, 0x39, 0x86,
  32982. 0x8C, 0x00, 0x31, 0x22, 0x05, 0x48, 0xD3, 0x10,
  32983. 0x81, 0x12, 0x48, 0x05, 0xD1, 0x08, 0x69, 0x62,
  32984. 0x38, 0x2C, 0x0A, 0x23, 0x70, 0x9B, 0x44, 0x72,
  32985. 0xE3, 0x48, 0x6E, 0x22, 0x96, 0x70, 0x14, 0x33,
  32986. 0x6C, 0xD8, 0x90, 0x29, 0x03, 0x00, 0x49, 0x63,
  32987. 0x20, 0x8A, 0x03, 0x91, 0x25, 0x08, 0x89, 0x21,
  32988. 0xC0, 0x82, 0x0C, 0x99, 0x40, 0x32, 0xC2, 0x34,
  32989. 0x4E, 0x4B, 0x98, 0x69, 0x09, 0x80, 0x44, 0xE4,
  32990. 0x04, 0x69, 0x94, 0x20, 0x09, 0x99, 0x24, 0x6D,
  32991. 0x09, 0xA9, 0x60, 0x01, 0x29, 0x2D, 0xC8, 0x42,
  32992. 0x28, 0x8A, 0x34, 0x02, 0xE4, 0x08, 0x70, 0x0C,
  32993. 0x23, 0x6E, 0x0A, 0x05, 0x49, 0x64, 0x44, 0x2A,
  32994. 0x82, 0xC8, 0x00, 0x02, 0x48, 0x31, 0xCB, 0x90,
  32995. 0x50, 0x1C, 0x05, 0x68, 0x12, 0x12, 0x2C, 0xD0,
  32996. 0x80, 0x0C, 0x59, 0x48, 0x61, 0xCB, 0xA6, 0x09,
  32997. 0x9C, 0xC0, 0x81, 0x42, 0xB8, 0x00, 0x24, 0x41,
  32998. 0x8A, 0x94, 0x20, 0x40, 0x42, 0x14, 0x4D, 0x19,
  32999. 0x46, 0x62, 0x18, 0x05, 0x09, 0x24, 0x33, 0x6A,
  33000. 0xD4, 0x00, 0x61, 0x12, 0x48, 0x32, 0x8A, 0x04,
  33001. 0x72, 0x93, 0xB4, 0x69, 0x62, 0xC2, 0x71, 0x41,
  33002. 0xA6, 0x89, 0x44, 0x96, 0x31, 0x62, 0x30, 0x46,
  33003. 0x83, 0x42, 0x6C, 0x00, 0x19, 0x22, 0x09, 0x46,
  33004. 0x4D, 0x8B, 0x06, 0x49, 0xE1, 0xB0, 0x70, 0x42,
  33005. 0x44, 0x31, 0xC1, 0x80, 0x65, 0x9C, 0x00, 0x24,
  33006. 0x11, 0xA8, 0x31, 0x13, 0x21, 0x2C, 0x4B, 0x46,
  33007. 0x28, 0x1B, 0x18, 0x0D, 0x88, 0x42, 0x70, 0xD1,
  33008. 0xB0, 0x0D, 0x90, 0xC8, 0x45, 0xDA, 0xC2, 0x48,
  33009. 0x59, 0x14, 0x26, 0x22, 0x44, 0x00, 0xC2, 0x94,
  33010. 0x41, 0x50, 0xC8, 0x04, 0x18, 0x00, 0x00, 0xCB,
  33011. 0xA6, 0x24, 0x19, 0x02, 0x10, 0x10, 0x89, 0x0C,
  33012. 0x18, 0x22, 0x21, 0x62, 0xA8, 0x81, 0xC8, 0x92,
  33013. 0x48, 0xD3, 0x94, 0x20, 0x82, 0x06, 0x72, 0x09,
  33014. 0xA8, 0x90, 0x0C, 0x49, 0x8A, 0x41, 0x86, 0x28,
  33015. 0x19, 0xC5, 0x80, 0x9A, 0x18, 0x4D, 0x14, 0x10,
  33016. 0x2E, 0x22, 0x12, 0x52, 0x00, 0x08, 0x12, 0x0C,
  33017. 0x33, 0x45, 0x63, 0xC6, 0x30, 0x10, 0x93, 0x4C,
  33018. 0x60, 0xC6, 0x31, 0xDC, 0x40, 0x0E, 0x98, 0x82,
  33019. 0x50, 0x60, 0x02, 0x2A, 0xD2, 0x22, 0x40, 0xE4,
  33020. 0x06, 0x2D, 0xDB, 0x32, 0x0E, 0xCA, 0x32, 0x4E,
  33021. 0xD4, 0x18, 0x24, 0x08, 0xC3, 0x28, 0x4A, 0xC2,
  33022. 0x68, 0xE2, 0x80, 0x40, 0xA1, 0xC8, 0x64, 0x51,
  33023. 0xC2, 0x65, 0xCB, 0x16, 0x60, 0x23, 0x09, 0x4C,
  33024. 0x82, 0x04, 0x68, 0xD9, 0x22, 0x2E, 0x1C, 0x49,
  33025. 0x92, 0x42, 0x24, 0x21, 0x00, 0x37, 0x0E, 0xC8,
  33026. 0x12, 0x72, 0x64, 0x08, 0x25, 0x0A, 0x20, 0x2A,
  33027. 0x58, 0x24, 0x04, 0x59, 0x16, 0x4C, 0x08, 0x17,
  33028. 0x30, 0x00, 0x46, 0x05, 0x12, 0x90, 0x40, 0x03,
  33029. 0x07, 0x21, 0x52, 0xC0, 0x64, 0x1C, 0x83, 0x6D,
  33030. 0x9C, 0x32, 0x2E, 0x11, 0x15, 0x8A, 0x10, 0x35,
  33031. 0x88, 0x5A, 0xA0, 0x8D, 0xD9, 0x80, 0x48, 0x03,
  33032. 0xB6, 0x4C, 0x01, 0x10, 0x65, 0x10, 0x86, 0x40,
  33033. 0x11, 0x01, 0x42, 0x0A, 0xC1, 0x64, 0xDB, 0x22,
  33034. 0x4D, 0x64, 0xB2, 0x51, 0x02, 0x36, 0x0D, 0x93,
  33035. 0x46, 0x31, 0x14, 0xB6, 0x68, 0x63, 0x84, 0x29,
  33036. 0xC8, 0x10, 0x24, 0x94, 0x30, 0x08, 0x19, 0x37,
  33037. 0x02, 0x14, 0x82, 0x45, 0x88, 0x28, 0x40, 0x54,
  33038. 0xA8, 0x29, 0x90, 0x14, 0x12, 0x61, 0x36, 0x12,
  33039. 0x0B, 0x09, 0x8C, 0xA4, 0x98, 0x28, 0xC2, 0x92,
  33040. 0x45, 0x4C, 0x00, 0x60, 0x63, 0xC4, 0x81, 0xC0,
  33041. 0x36, 0x25, 0xCA, 0x88, 0x2D, 0x24, 0x40, 0x30,
  33042. 0xD3, 0xA8, 0x2D, 0xC9, 0xC8, 0x25, 0xD2, 0x84,
  33043. 0x48, 0x00, 0x32, 0x92, 0x50, 0xA2, 0x71, 0xD3,
  33044. 0x44, 0x0D, 0x22, 0x34, 0x60, 0x12, 0x13, 0x12,
  33045. 0x86, 0x8C, 0x5F, 0x86, 0x20, 0x79, 0x4A, 0x05,
  33046. 0x0E, 0x20, 0xD0, 0xE1, 0x01, 0x17, 0x86, 0x24,
  33047. 0x0E, 0xA6, 0x64, 0xF2, 0xF6, 0x9B, 0xB1, 0xB7,
  33048. 0xE3, 0x0E, 0xC6, 0x6B, 0x1A, 0x4A, 0x0B, 0xE5,
  33049. 0x9B, 0x79, 0xF2, 0x19, 0x8A, 0xD9, 0x80, 0x44,
  33050. 0x83, 0xE4, 0x75, 0xE5, 0x3B, 0x3C, 0x49, 0xCB,
  33051. 0x0C, 0xE5, 0xEF, 0x92, 0x91, 0x2A, 0xF4, 0x40,
  33052. 0xF2, 0x3B, 0x99, 0x58, 0x13, 0xD1, 0x1B, 0x59,
  33053. 0xF7, 0x98, 0xE9, 0x3C, 0x9D, 0x13, 0x53, 0x98,
  33054. 0x17, 0xC7, 0xAC, 0x68, 0xCA, 0xD1, 0xAA, 0x1A,
  33055. 0xC2, 0x76, 0x56, 0xBD, 0x0C, 0x47, 0x97, 0xE9,
  33056. 0xC8, 0xEC, 0x17, 0x78, 0x4C, 0x1A, 0x32, 0x7A,
  33057. 0x9D, 0xFE, 0xAF, 0x4D, 0x61, 0x91, 0xEE, 0xCD,
  33058. 0xAF, 0xE0, 0x49, 0xB7, 0x33, 0xFE, 0x39, 0xD5,
  33059. 0xEB, 0x40, 0x00, 0x93, 0x6F, 0xEE, 0xFC, 0xF8,
  33060. 0x29, 0x28, 0xE9, 0xF9, 0x4C, 0xFD, 0x5C, 0xF4,
  33061. 0xC1, 0xE3, 0xDE, 0xB1, 0x43, 0x3A, 0x47, 0xF6,
  33062. 0xD3, 0x28, 0xB5, 0xE8, 0x3D, 0xD1, 0x56, 0xD0,
  33063. 0x18, 0x2D, 0xC6, 0x92, 0x34, 0x75, 0x91, 0xAA,
  33064. 0x6F, 0x73, 0x2C, 0xFB, 0xE9, 0x82, 0x93, 0x5F,
  33065. 0xD1, 0x84, 0x6C, 0xAC, 0xF4, 0xCB, 0x85, 0x15,
  33066. 0xC5, 0x5A, 0xB8, 0x5E, 0xE5, 0xAD, 0x44, 0xCB,
  33067. 0x09, 0xD3, 0x26, 0x9E, 0x2E, 0x6D, 0x11, 0x78,
  33068. 0x09, 0x61, 0xFD, 0x13, 0x1D, 0x5E, 0x6F, 0xBF,
  33069. 0x89, 0x84, 0x9F, 0x47, 0xF2, 0xB7, 0x1D, 0x82,
  33070. 0x83, 0xFF, 0x25, 0x38, 0x5E, 0x52, 0xB0, 0x7D,
  33071. 0xBB, 0x26, 0x6C, 0x67, 0x4C, 0xEE, 0x3D, 0x0B,
  33072. 0x5D, 0xF5, 0xA5, 0x6D, 0x8B, 0xDC, 0xDC, 0xFA,
  33073. 0xAE, 0xE6, 0xA2, 0x48, 0xE7, 0x1D, 0xB1, 0x34,
  33074. 0x5A, 0xFC, 0x59, 0x7C, 0xA8, 0x30, 0xA1, 0xA3,
  33075. 0x5B, 0x43, 0x96, 0xEF, 0x4C, 0x1A, 0xDF, 0x9E,
  33076. 0xD0, 0x1B, 0xCE, 0x9B, 0x6E, 0xB6, 0x37, 0xFA,
  33077. 0x24, 0xAA, 0x16, 0x0B, 0x90, 0x76, 0xBA, 0xE3,
  33078. 0x05, 0x59, 0xF8, 0xB2, 0x9D, 0xED, 0xB3, 0xD2,
  33079. 0x5B, 0x79, 0x06, 0x4A, 0xB0, 0xCF, 0x8B, 0x8D,
  33080. 0x70, 0xAD, 0xDD, 0xEB, 0x8B, 0x17, 0x42, 0x48,
  33081. 0xD5, 0xAE, 0xA4, 0xD1, 0x8D, 0xE4, 0x3B, 0x89,
  33082. 0x38, 0xCD, 0xD2, 0xAC, 0xBA, 0x54, 0x77, 0xBD,
  33083. 0x4A, 0xAC, 0xC3, 0xCE, 0x59, 0x5E, 0x5D, 0x26,
  33084. 0x9F, 0xE6, 0x75, 0x21, 0x0D, 0x23, 0x15, 0x2B,
  33085. 0x04, 0x71, 0x0F, 0x36, 0x84, 0x28, 0x79, 0x4A,
  33086. 0x75, 0xF4, 0x9B, 0x68, 0x3E, 0xD2, 0x0D, 0xD6,
  33087. 0x47, 0x51, 0x57, 0x77, 0x95, 0x5A, 0x8C, 0xB3,
  33088. 0x8A, 0x36, 0xAF, 0xCD, 0x2C, 0xE0, 0xAC, 0xEC,
  33089. 0x4F, 0x0D, 0xFE, 0x80, 0x77, 0x02, 0xD1, 0xEB,
  33090. 0x3B, 0xDE, 0x72, 0xE9, 0xE0, 0x85, 0xAA, 0x4E,
  33091. 0x09, 0xEB, 0x1B, 0x09, 0x47, 0x41, 0x38, 0x52,
  33092. 0xEC, 0x3C, 0x0A, 0xC5, 0x2F, 0x06, 0xCB, 0x95,
  33093. 0x9C, 0x85, 0x39, 0x4E, 0xB3, 0x74, 0x81, 0x19,
  33094. 0xED, 0xBE, 0x6C, 0x80, 0xD2, 0xD8, 0xF7, 0x92,
  33095. 0xCE, 0x0D, 0x91, 0x5E, 0x4F, 0x4B, 0x15, 0x1E,
  33096. 0xFB, 0x13, 0x5E, 0x7F, 0x4D, 0xC9, 0x7D, 0x85,
  33097. 0x81, 0x41, 0xC5, 0x7F, 0x70, 0x41, 0x7B, 0x43,
  33098. 0xA6, 0xA1, 0x26, 0x95, 0x69, 0x78, 0xD7, 0x8E,
  33099. 0xFB, 0x9F, 0x03, 0x72, 0x43, 0xB4, 0xCB, 0x41,
  33100. 0xDF, 0x96, 0x8B, 0x7E, 0xE5, 0xB5, 0x20, 0x87,
  33101. 0xF0, 0x5A, 0xA9, 0xFE, 0x48, 0x7B, 0xD1, 0x6C,
  33102. 0x03, 0x47, 0xCF, 0x13, 0x35, 0x76, 0x0B, 0xD2,
  33103. 0x39, 0x8A, 0xD5, 0x4D, 0xDA, 0x00, 0xA5, 0xAA,
  33104. 0xC4, 0x46, 0xD8, 0x0B, 0x1C, 0x79, 0x98, 0xC6,
  33105. 0x02, 0x19, 0x2A, 0xDA, 0xFC, 0xB8, 0x09, 0xD1,
  33106. 0x4E, 0xE3, 0x28, 0x64, 0x1B, 0xA3, 0xAA, 0x00,
  33107. 0xF8, 0xD2, 0x9C, 0x3A, 0x84, 0x8A, 0xCB, 0xDC,
  33108. 0x19, 0x46, 0xBC, 0x0D, 0x35, 0xE0, 0xBE, 0x0F,
  33109. 0x8F, 0x7E, 0x3D, 0xA3, 0xF6, 0x8D, 0x9F, 0xA9,
  33110. 0x76, 0x8F, 0x5C, 0xF2, 0x75, 0x53, 0x4A, 0x0E,
  33111. 0xCA, 0x9E, 0x60, 0xFC, 0xEA, 0x38, 0xF1, 0xE0,
  33112. 0x42, 0xC3, 0x16, 0x14, 0x3A, 0x76, 0x7B, 0x33,
  33113. 0xAC, 0xCA, 0xD8, 0xC8, 0xD6, 0x6C, 0x70, 0xC7,
  33114. 0x5F, 0xD1, 0xF0, 0xB2, 0x58, 0x6B, 0x65, 0x3A,
  33115. 0xD4, 0xAF, 0x54, 0xE5, 0x6E, 0xF0, 0x69, 0x33,
  33116. 0xEA, 0xD3, 0x1D, 0xE3, 0x65, 0xD1, 0x10, 0xB9,
  33117. 0xC4, 0xA2, 0xA9, 0x8B, 0xCB, 0xA1, 0x65, 0xCA,
  33118. 0xFE, 0x38, 0x6F, 0x88, 0x7C, 0x72, 0x15, 0x6E,
  33119. 0xB1, 0x4F, 0xF0, 0xDA, 0xD6, 0x65, 0x61, 0x6C,
  33120. 0xE3, 0xCE, 0x65, 0xC1, 0x90, 0x4F, 0x2C, 0x17,
  33121. 0x47, 0xB2, 0xEC, 0x2B, 0x5C, 0x9D, 0x67, 0x76,
  33122. 0xBC, 0xD7, 0x9E, 0x5A, 0xC6, 0x4B, 0x79, 0x33,
  33123. 0xBD, 0xDE, 0xDE, 0xDD, 0xBB, 0xC7, 0x25, 0xBF,
  33124. 0xDB, 0xCC, 0xDE, 0x2F, 0xB3, 0x75, 0xAE, 0x2B,
  33125. 0xE3, 0x53, 0x7B, 0xDF, 0x89, 0xBF, 0x4C, 0x25,
  33126. 0xF8, 0x3A, 0x49, 0xD6, 0xA6, 0xA8, 0xD0, 0x76,
  33127. 0x1C, 0xF3, 0x9D, 0x62, 0x0C, 0x53, 0xED, 0x83,
  33128. 0x7D, 0x19, 0x82, 0x55, 0xCF, 0x5B, 0x91, 0x0A,
  33129. 0x6D, 0xB5, 0x78, 0x77, 0xDF, 0x92, 0xD8, 0xBB,
  33130. 0x6E, 0x9C, 0x52, 0x6B, 0x8C, 0x4E, 0xC9, 0x31,
  33131. 0x00, 0xDE, 0xE0, 0x50, 0x0A, 0x21, 0x0C, 0x98,
  33132. 0x45, 0x83, 0xE1, 0x53, 0x81, 0x60, 0xED, 0xAC,
  33133. 0x2C, 0x6F, 0x86, 0x6E, 0x7F, 0x5D, 0x99, 0xD7,
  33134. 0xB1, 0xB8, 0x15, 0x82, 0xF5, 0xD0, 0xEB, 0xBF,
  33135. 0x27, 0x86, 0xE3, 0xF5, 0x56, 0x01, 0x3B, 0xA9,
  33136. 0xB6, 0xF6, 0x56, 0xEB, 0x79, 0x88, 0x38, 0xEA,
  33137. 0x05, 0x79, 0x20, 0x1A, 0x95, 0xD5, 0x6B, 0xBC,
  33138. 0x3B, 0xCD, 0xB9, 0x51, 0x1A, 0xFB, 0xD4, 0xD8,
  33139. 0x12, 0x88, 0x89, 0x6F, 0x87, 0x10, 0x8C, 0x07,
  33140. 0x7F, 0x1A, 0x81, 0xA3, 0xBD, 0x29, 0x7B, 0xB1,
  33141. 0x24, 0xA8, 0x00, 0x86, 0x89, 0x02, 0x42, 0x99,
  33142. 0x5E, 0x03, 0xCF, 0x42, 0xA0, 0xC2, 0x1E, 0x27,
  33143. 0x2A, 0x9A, 0xFA, 0x1D, 0xC1, 0x03, 0x46, 0x3D,
  33144. 0x2A, 0xB4, 0x94, 0xF7, 0xD0, 0x17, 0x68, 0x6D,
  33145. 0x31, 0x89, 0x4D, 0xD2, 0xF6, 0xEB, 0xB0, 0xC3,
  33146. 0xCB, 0x62, 0x23, 0xEC, 0x79, 0xC6, 0x5D, 0x45,
  33147. 0xC1, 0xB0, 0xD4, 0xEF, 0x19, 0x61, 0xF1, 0x6D,
  33148. 0x65, 0x3F, 0xCF, 0x25, 0x97, 0x7B, 0x65, 0x1E,
  33149. 0xC5, 0x1A, 0x13, 0xAE, 0x8D, 0x4A, 0x34, 0x72,
  33150. 0xEE, 0x71, 0x96, 0x9A, 0x7A, 0x93, 0x6F, 0x5D,
  33151. 0xBB, 0xB9, 0x39, 0x6A, 0x46, 0xD9, 0x76, 0x42,
  33152. 0x35, 0x8C, 0xAF, 0x48, 0x94, 0xC9, 0xA6, 0xDF,
  33153. 0x84, 0xA5, 0x9C, 0x59, 0x62, 0xA6, 0x99, 0x0A,
  33154. 0x76, 0xF0, 0x61, 0x48, 0x90, 0x16, 0x9F, 0x00,
  33155. 0x18, 0x70, 0xD4, 0x9C, 0xF2, 0xE7, 0x50, 0x08,
  33156. 0xCC, 0x4A, 0x5D, 0x85, 0xE7, 0x2D, 0xE2, 0xD6,
  33157. 0xCF, 0x3F, 0xA7, 0x18, 0x52, 0x25, 0x35, 0x22,
  33158. 0xFE, 0x8B, 0x0E, 0x42, 0x3C, 0xB4, 0x17, 0xA3,
  33159. 0x8E, 0xB7, 0x8C, 0x87, 0x63, 0xC3, 0x72, 0x0C,
  33160. 0x04, 0xE6, 0x7F, 0xF8, 0x89, 0x79, 0xEB, 0xA0,
  33161. 0x9E, 0x34, 0x53, 0x8B, 0xB5, 0x23, 0xB9, 0x9B,
  33162. 0x8E, 0x34, 0x16, 0x74, 0x12, 0xF7, 0x7A, 0xEA,
  33163. 0x89, 0x4D, 0x83, 0xAC, 0xF9, 0x46, 0xFC, 0x05,
  33164. 0x4D, 0x0A, 0xF4, 0x72, 0x95, 0xE5, 0x1E, 0xD8,
  33165. 0x3F, 0x74, 0x86, 0x94, 0x0A, 0x4D, 0x41, 0xC0,
  33166. 0x4A, 0xD7, 0xEB, 0xEE, 0x61, 0x0B, 0xF1, 0xD0,
  33167. 0x3F, 0xA5, 0x40, 0x71, 0xD5, 0x1A, 0x15, 0x09,
  33168. 0xE4, 0xF4, 0x91, 0x63, 0xA2, 0x50, 0x81, 0xBE,
  33169. 0x87, 0x90, 0xD0, 0x87, 0xF5, 0xF4, 0xF0, 0x5C,
  33170. 0x88, 0x55, 0x0F, 0xCA, 0x9B, 0xF9, 0x9C, 0x9B,
  33171. 0xE5, 0x95, 0x3D, 0x51, 0xDD, 0x08, 0x45, 0xC9,
  33172. 0x3E, 0x41, 0xEE, 0xEF, 0x62, 0xE0, 0x79, 0x4B,
  33173. 0x29, 0x27, 0xC4, 0xF5, 0xED, 0x9B, 0xD3, 0xE3,
  33174. 0x4E, 0xA9, 0x20, 0x0A, 0x79, 0xDD, 0xEB, 0x4B,
  33175. 0x2D, 0x8F, 0x30, 0x5F, 0xE0, 0x5F, 0x82, 0x7C,
  33176. 0x7E, 0x2E, 0xD1, 0x86, 0x34, 0x1C, 0xB5, 0xD1,
  33177. 0x15, 0x2F, 0xC8, 0x01, 0x04, 0xE0, 0xE1, 0x36,
  33178. 0x83, 0xD9, 0x41, 0x29, 0x4C, 0x77, 0x84, 0x17,
  33179. 0x16, 0x4B, 0x68, 0x4A, 0x97, 0x6E, 0x56, 0xE7,
  33180. 0x8D, 0xA4, 0xD1, 0x7C, 0x3C, 0x73, 0x22, 0x93,
  33181. 0x14, 0x87, 0x0B, 0x85, 0xC4, 0x55, 0xC2, 0x3B,
  33182. 0x83, 0x0B, 0x9A, 0x28, 0xA3, 0xD8, 0xC0, 0xB5,
  33183. 0x66, 0x42, 0x6D, 0xC1, 0x69, 0xF3, 0x26, 0xAB,
  33184. 0xCE, 0x2E, 0xFF, 0xF3, 0x9E, 0x9B, 0x19, 0x9A,
  33185. 0xE5, 0xC1, 0x29, 0x2B, 0x6F, 0x2E, 0xF3, 0x7A,
  33186. 0xF1, 0xDE, 0xA9, 0x27, 0x2C, 0x8D, 0x54, 0x23,
  33187. 0xDF, 0x8A, 0x56, 0x32, 0xF9, 0x91, 0xE1, 0x4D,
  33188. 0xCA, 0x25, 0x14, 0x78, 0x8B, 0x62, 0xBE, 0x16,
  33189. 0x48, 0x28, 0xE9, 0xAC, 0xB8, 0x93, 0xDD, 0xA6,
  33190. 0x02, 0xA5, 0xE2, 0xFB, 0x9E, 0xFC, 0xBE, 0xFD,
  33191. 0x95, 0xAB, 0xFB, 0x82, 0xD2, 0xB0, 0x2D, 0x49,
  33192. 0xCC, 0x53, 0x08, 0x4A, 0x49, 0xAB, 0x1B, 0xEC,
  33193. 0x23, 0xE5, 0xB4, 0xC8, 0xE7, 0x14, 0xCB, 0x03,
  33194. 0x40, 0x5F, 0x1B, 0xCF, 0x7E, 0x11, 0xBB, 0x59,
  33195. 0x72, 0x9D, 0xDC, 0x0B, 0x7B, 0xEF, 0xB2, 0x91,
  33196. 0x27, 0x6D, 0xCE, 0xDA, 0xCA, 0xAD, 0x39, 0xA2,
  33197. 0xF0, 0x1C, 0x7D, 0xC9, 0x8B, 0x9E, 0x06, 0x5E,
  33198. 0xAF, 0xED, 0x1C, 0xC8, 0xCE, 0x3E, 0x84, 0x80,
  33199. 0x80, 0xA2, 0xFC, 0x5B, 0x98, 0xC9, 0xF6, 0xBF,
  33200. 0x50, 0x40, 0x27, 0x33, 0x42, 0xF0, 0x31, 0x2F,
  33201. 0x8B, 0x98, 0x44, 0x59, 0x4A, 0x50, 0x3D, 0xD3,
  33202. 0xE6, 0xAF, 0x1C, 0x9E, 0x35, 0xC1, 0x03, 0x2A,
  33203. 0x4A, 0x8A, 0x5E, 0x7B, 0xF3, 0x3A, 0x82, 0xF3,
  33204. 0x5E, 0x16, 0xED, 0xF8, 0xC6, 0x0C, 0x90, 0x02,
  33205. 0x1D, 0x8C, 0x0B, 0xA4, 0xC3, 0x86, 0x24, 0x5D,
  33206. 0xFE, 0xF0, 0x94, 0x48, 0x43, 0x1D, 0x8C, 0x00,
  33207. 0xD1, 0xE2, 0x6E, 0xE4, 0xD8, 0xC7, 0x7D, 0xAA,
  33208. 0x1A, 0x70, 0x5E, 0xD4, 0x79, 0x2A, 0xCB, 0x4E,
  33209. 0xA2, 0x7C, 0x15, 0x66, 0xFB, 0x56, 0x68, 0x3C,
  33210. 0x43, 0xBF, 0x67, 0x84, 0x2E, 0x67, 0x53, 0x4C,
  33211. 0xB3, 0xF9, 0x67, 0x7C, 0x8A, 0xB9, 0xD0, 0xEE,
  33212. 0xE7, 0x82, 0x7C, 0xDE, 0xFC, 0x22, 0x3A, 0xC9,
  33213. 0x48, 0xB8, 0x80, 0xB5, 0xF1, 0xCE, 0x95, 0x37,
  33214. 0x27, 0x29, 0x32, 0x00, 0x2C, 0x1A, 0x4D, 0xD2,
  33215. 0x18, 0xF5, 0x27, 0x16, 0x6E, 0xBF, 0xB2, 0xB2,
  33216. 0xFA, 0x2B, 0xF3, 0x72, 0x46, 0xEC, 0xDF, 0xDF,
  33217. 0xA7, 0x2B, 0x6D, 0xA1, 0x1C, 0x30, 0xD1, 0xC7,
  33218. 0xD2, 0x48, 0xAD, 0x64, 0x81, 0x8F, 0x69, 0x1D,
  33219. 0x59, 0xB7, 0x55, 0xDA, 0xF7, 0x1B, 0xED, 0x9A,
  33220. 0xB5, 0xFB, 0x52, 0xE0, 0x36, 0x22, 0xA9, 0x00,
  33221. 0xD6, 0x6B, 0x4C, 0x63, 0x84, 0x16, 0x9B, 0xDF,
  33222. 0x9E, 0xB6, 0x1C, 0x02, 0xDF, 0x45, 0xFB, 0x76,
  33223. 0xB1, 0xA2, 0x6F, 0x34, 0xE9, 0x38, 0xB1, 0x90,
  33224. 0x86, 0x17, 0x45, 0xC0, 0x21, 0xFA, 0x87, 0x62,
  33225. 0x00, 0xC7, 0xFC, 0x8E, 0x22, 0x2D, 0xDB, 0xFA,
  33226. 0xD8, 0xBE, 0x78, 0x1B, 0x18, 0x54, 0x24, 0xAA,
  33227. 0xAF, 0xC6, 0x58, 0x62, 0xDB, 0x13, 0x2B, 0xEC,
  33228. 0x6D, 0x18, 0x83, 0x7A, 0x1F, 0x58, 0xA8, 0x76,
  33229. 0xC9, 0x9E, 0x63, 0xF5, 0x14, 0x20, 0xB8, 0x3F,
  33230. 0x45, 0x96, 0x75, 0x61, 0x2F, 0x7A, 0xCF, 0x80,
  33231. 0xB4, 0xEB, 0x1D, 0xD0, 0x72, 0x1C, 0xAA, 0x1B,
  33232. 0x49, 0x70, 0xDA, 0x60, 0x86, 0x79, 0xC6, 0x38,
  33233. 0x3E, 0x81, 0x7F, 0xE1, 0x6B, 0x66, 0xB1, 0x91,
  33234. 0x81, 0xED, 0xFC, 0x39, 0x27, 0x0C, 0x7E, 0x91,
  33235. 0x7B, 0x1F, 0x10, 0xEB, 0x7A, 0x01, 0x19, 0x97,
  33236. 0xE9, 0x67, 0x85, 0x3B, 0x78, 0xE0, 0x0C, 0xFD,
  33237. 0x58, 0xD2, 0x24, 0xD9, 0x33, 0xCC, 0x5A, 0x99,
  33238. 0x55, 0x32, 0xDC, 0xD4, 0xE5, 0x32, 0xE4, 0x03,
  33239. 0x05, 0x15, 0xF4, 0xA0, 0x5B, 0x33, 0x1D, 0x57,
  33240. 0x5D, 0xDA, 0xC2, 0x9B, 0xAB, 0x06, 0x9F, 0x09,
  33241. 0xAF, 0x0D, 0x17, 0x33, 0x73, 0xDB, 0x1E, 0xC2,
  33242. 0xB6, 0x36, 0x6B, 0xB3, 0x71, 0x00, 0x8A, 0x23,
  33243. 0x86, 0xFD, 0x88, 0xBE, 0x77, 0xF5, 0xED, 0x5E,
  33244. 0x19, 0x8C, 0xBE, 0x88, 0xDF, 0x24, 0xBC, 0x6E,
  33245. 0x39, 0x3F, 0xEB, 0xC1, 0x0C, 0x47, 0x0A, 0x72,
  33246. 0xD4, 0x7C, 0x0F, 0x83, 0x46, 0x53, 0xC9, 0xAE,
  33247. 0x80, 0x0E, 0x89, 0x3C, 0x6B, 0xA6, 0x8E, 0xA2,
  33248. 0x8A, 0x83, 0x8F, 0xCB, 0xB6, 0x9C, 0x3E, 0x96,
  33249. 0x4A, 0x5F, 0xAF, 0xC2, 0x06, 0x7D, 0xD4, 0x06,
  33250. 0xB2, 0x57, 0xC9, 0x8D, 0xD3, 0x97, 0x9E, 0xC7,
  33251. 0xC7, 0xEC, 0xBE, 0x96, 0xA3, 0x3D, 0x85, 0x51,
  33252. 0x5D, 0xA2, 0xCB, 0x6A, 0xA5, 0xE1, 0xFF, 0xF2,
  33253. 0x04, 0xAF, 0x62, 0xDD, 0x41, 0x19, 0xA0, 0xE4,
  33254. 0x8C, 0x04, 0xA3, 0xF2, 0xB3, 0x86, 0x60, 0xF5,
  33255. 0x29, 0x64, 0xD8, 0xD4, 0xAE, 0xE1, 0x46, 0xA9,
  33256. 0xC5, 0x3C, 0x31, 0x90, 0x6D, 0xAD, 0x0F, 0xD9,
  33257. 0x0B, 0x5D, 0x83, 0xB3, 0xE3, 0x1B, 0x69, 0x0A,
  33258. 0x4C, 0x49, 0x35, 0x24, 0x99, 0x81, 0xBE, 0x1F,
  33259. 0x1A, 0x85, 0xEC, 0x6E, 0x0F, 0xEE, 0x4C, 0x88,
  33260. 0xF2, 0xD8, 0x9E, 0x29, 0x69, 0xAB, 0x8C, 0xBB,
  33261. 0xEB, 0x50, 0x19, 0x16, 0x55, 0x8D, 0x29, 0xEA,
  33262. 0x7C, 0x3E, 0xCF, 0x1C, 0x9E, 0xF1, 0xA0, 0x43,
  33263. 0x50, 0x63, 0x3B, 0x4C, 0xDA, 0x73, 0x7D, 0xFB,
  33264. 0x15, 0x1C, 0xB5, 0xE7, 0x36, 0x11, 0x73, 0xF3,
  33265. 0xAE, 0xDD, 0xDF, 0x52, 0x7D, 0x73, 0xF2, 0xF9,
  33266. 0xD5, 0xB6, 0x21, 0x3A, 0xA6, 0x8F, 0x88, 0x3E,
  33267. 0x9A, 0x26, 0x33, 0x78, 0x5E, 0xC6, 0xBE, 0x64,
  33268. 0x2A, 0x9F, 0xD0, 0xF2, 0x1A, 0x42, 0xF6, 0xB9,
  33269. 0xDA, 0xAB, 0xDC, 0xD1, 0xE6, 0xAD, 0xBE, 0xF6,
  33270. 0x48, 0x41, 0xB5, 0x96, 0x86, 0xEA, 0xE3, 0xEC,
  33271. 0x88, 0xEE, 0xF0, 0xA9, 0xCB, 0xC1, 0x2B, 0xC0,
  33272. 0x12, 0x62, 0x2D, 0xF2, 0xDD, 0x93, 0xA8, 0x62,
  33273. 0x29, 0x04, 0x4A, 0xF2, 0xF2, 0x60, 0xD2, 0x18,
  33274. 0x3F, 0x51, 0xE8, 0x33, 0xEE, 0x92, 0xD9, 0x8F,
  33275. 0x02, 0x51, 0xE3, 0xF8, 0x5F, 0xAB, 0x74, 0xCE,
  33276. 0x36, 0x7B, 0x8B, 0x7A, 0xA6, 0x3D, 0x3C, 0xF8,
  33277. 0xC8, 0xBF, 0x4D, 0x78, 0x35, 0x8B, 0xAE, 0x0A,
  33278. 0x02, 0x41, 0xE2, 0x10, 0xAC, 0x69, 0x35, 0x30,
  33279. 0x87, 0xCC, 0x73, 0x31, 0x35, 0x7E, 0xB4, 0x45,
  33280. 0x0F, 0x95, 0x09, 0xCF, 0xE5, 0x95, 0xF5, 0x40,
  33281. 0x32, 0xEE, 0x05, 0x77, 0x54, 0xA8, 0xED, 0xD7,
  33282. 0x46, 0xCB, 0x92, 0x82, 0xE7, 0x68, 0xDC, 0x6B,
  33283. 0x83, 0x0C, 0x5B, 0x4A, 0x21, 0x93, 0x43, 0xAD,
  33284. 0x12, 0x4E, 0xDB, 0x3B, 0xBC, 0x42, 0x50, 0x55,
  33285. 0x66, 0xA7, 0x03, 0x8C, 0x95, 0x9B, 0xC3, 0x55,
  33286. 0x85, 0xB6, 0x05, 0x5F, 0x19, 0x68, 0xDA, 0x24,
  33287. 0x3F, 0x77, 0x8F, 0x4E, 0x46, 0xDB, 0x46, 0x2A,
  33288. 0xBE, 0xB9, 0x3B, 0x81, 0x24, 0x3C, 0x31, 0xEB,
  33289. 0x59, 0x62, 0x2E, 0xDF, 0x81, 0xF0, 0x6C, 0xCC,
  33290. 0x61, 0xD2, 0xA6, 0xEA, 0x73, 0xE1, 0x09, 0xC3,
  33291. 0x87, 0x91, 0x5F, 0x27, 0x7B, 0xCF, 0x1F, 0xC1,
  33292. 0x11, 0x05, 0xBB, 0xA7, 0x02, 0x93, 0xC0, 0xFA,
  33293. 0xB5, 0xC0, 0x65, 0xF2, 0x3B, 0xAA, 0x19, 0x29,
  33294. 0x0A, 0x30, 0x2F, 0x08, 0x09, 0x11, 0x07, 0xA4,
  33295. 0xB1, 0xD5, 0x68, 0x85, 0x26, 0x22, 0x09, 0x83,
  33296. 0x83, 0x42, 0x77, 0x60, 0xEF, 0x8F, 0x29, 0x28,
  33297. 0x62, 0x5B, 0xDD, 0xA5, 0xF5, 0x14, 0xC5, 0xAD,
  33298. 0xE9, 0x59, 0x89, 0x1E, 0xF2, 0x95, 0x9F, 0x24,
  33299. 0x8A, 0x35, 0x32, 0xBF, 0x9D, 0x30, 0xE7, 0x14,
  33300. 0x05, 0x9E, 0xBD, 0xEC, 0x95, 0x87, 0x08, 0xF8,
  33301. 0xA8, 0x3C, 0x26, 0x8B, 0xEF, 0x26, 0x82, 0xD6,
  33302. 0x03, 0xCA, 0x88, 0x63, 0x47, 0xE1, 0x98, 0xFD,
  33303. 0x68, 0x23, 0x39, 0x99, 0xC7, 0x7D, 0x30, 0xD7,
  33304. 0x45, 0x5D, 0xE6, 0xBC, 0xFD, 0x01, 0x44, 0x27,
  33305. 0x70, 0x62, 0xB3, 0x04, 0xBE, 0xF0, 0xE3, 0x4C,
  33306. 0x5A, 0x9D, 0x8D, 0x78, 0x0D, 0x29, 0xEC, 0x23,
  33307. 0x21, 0xE0, 0x73, 0x40, 0x77, 0x1C, 0x46, 0x36,
  33308. 0x04, 0x83, 0xAD, 0xCA, 0xF1, 0x2D, 0x5B, 0x79,
  33309. 0xFD, 0xBF, 0xE2, 0x85, 0x6A, 0xCE, 0x88, 0x59,
  33310. 0xF6, 0xB1, 0x24, 0x14, 0xB3, 0xF7, 0xE8, 0xBB,
  33311. 0x58, 0x13, 0x49, 0x89, 0x60, 0xF3, 0x4F, 0xDC,
  33312. 0x64, 0xFC, 0x84, 0x85, 0x79, 0xCA, 0xF9, 0xDC,
  33313. 0xCF, 0x19, 0xB4, 0xFB, 0x82, 0x5E, 0xD5, 0x71,
  33314. 0x6D, 0xCC, 0xCD, 0x68, 0x72, 0xCB, 0xDE, 0x38,
  33315. 0x31, 0xD6, 0x73, 0x84, 0x94, 0x2C, 0xD8, 0xA9,
  33316. 0xEC, 0x4B, 0xBF, 0xEF, 0x57, 0x06, 0xB8, 0xF9,
  33317. 0xF0, 0x5F, 0xE1, 0xE8, 0xFE, 0x69, 0xD3, 0xEA,
  33318. 0x6A, 0x86, 0x21, 0xC2, 0x21, 0x44, 0x17, 0x7B,
  33319. 0x1C, 0x12, 0x59, 0xE1, 0xA7, 0x9D, 0xFD, 0xF8,
  33320. 0x97, 0x28, 0x88, 0x7B, 0xEF, 0x1A, 0x70, 0x48,
  33321. 0x25, 0x56, 0x83, 0x1B, 0x67, 0x24, 0x40, 0xE1,
  33322. 0x3F, 0xE3, 0xE3, 0xFC, 0x82, 0x04, 0xA0, 0x2E,
  33323. 0xA1, 0xEF, 0xF1, 0x9D, 0x95, 0x25, 0x38, 0x87,
  33324. 0x28, 0x5B, 0xFB, 0xEA, 0x16, 0xA0, 0xF2, 0x19,
  33325. 0xEF, 0xBC, 0xEC, 0x30, 0xA8, 0xAE, 0x86, 0x58,
  33326. 0x9A, 0x57, 0x03, 0x10, 0x3A, 0x8A, 0x39, 0x3F,
  33327. 0xA6, 0xF6, 0xB6, 0x57, 0x70, 0x4A, 0xC6, 0x77,
  33328. 0xC1, 0x4C, 0xD1, 0x0D, 0x3D, 0x62, 0xD1, 0x3F,
  33329. 0xBD, 0x37, 0x8C, 0x2D, 0xDA, 0x32, 0x5B, 0x61,
  33330. 0xB8, 0x59, 0x52, 0xD5, 0x12, 0x93, 0x87, 0x1E,
  33331. 0x1F, 0xCD, 0xC9, 0x48, 0xC7, 0x7B, 0xEA, 0xE9,
  33332. 0xA6, 0xF0, 0xE8, 0x7C, 0xE1, 0xA8, 0x05, 0x1C,
  33333. 0x8F, 0x80, 0x87, 0x68, 0x5C, 0x12, 0x62, 0x4B,
  33334. 0xDF, 0x58, 0x38, 0x0E, 0xD6, 0x6F, 0x55, 0xB4,
  33335. 0x3D, 0xDD, 0x6D, 0x36, 0x21, 0x73, 0xA5, 0xBD,
  33336. 0x38, 0x98, 0x59, 0xC1, 0x7D, 0x95, 0xEC, 0xE3,
  33337. 0xAB, 0x73, 0x26, 0x39, 0xFF, 0xE4, 0x51, 0xCD,
  33338. 0x10, 0x3E, 0xE4, 0x85, 0x4D, 0xB2, 0xF3, 0x96,
  33339. 0x14, 0xF6, 0x58, 0xBA, 0xA3, 0x84, 0xBC, 0x99,
  33340. 0x48, 0xD0, 0x71, 0x4E, 0xB4, 0x8A, 0x88, 0x71,
  33341. 0x43, 0xE7, 0xA1, 0xFA, 0x4B, 0x69, 0x0C, 0x22,
  33342. 0xB4, 0x92, 0xA7, 0x0C, 0x61, 0x2B, 0x59, 0xFF,
  33343. 0xD2, 0xD6, 0xB3, 0xB5, 0xE9, 0x9C, 0x20, 0x03,
  33344. 0xE2, 0xC3, 0x59, 0xB1, 0xE6, 0x2D, 0xCB, 0x62,
  33345. 0x0C, 0x7A, 0x24, 0x6A, 0x7B, 0x9B, 0x32, 0x46,
  33346. 0x13, 0x15, 0x56, 0xF2, 0xF3, 0xD5, 0x13, 0xA2,
  33347. 0x3C, 0x6A, 0x9F, 0xD2, 0x28, 0x0E, 0xD6, 0x86,
  33348. 0xD7, 0x67, 0xCC, 0xD0, 0x17, 0x54, 0xEB, 0x4C,
  33349. 0x99, 0x69, 0x2F, 0x2B, 0x38, 0x0C, 0x36, 0x08,
  33350. 0x13, 0x44, 0xC1, 0xD3, 0x5E, 0xE1, 0x94, 0x97,
  33351. 0x36, 0xB6, 0x97, 0x6F, 0x48, 0x52, 0xCF, 0xBE,
  33352. 0x64, 0xFA, 0xBC, 0xF1, 0x1B, 0x9A, 0xFB, 0x82,
  33353. 0x85, 0x76, 0xB4, 0xF9, 0x78, 0x7A, 0xA7, 0xD0,
  33354. 0x3E, 0x84, 0x59, 0x8A, 0x71, 0x43, 0xEF, 0x73,
  33355. 0x11, 0xFA, 0xF2, 0x97, 0x0E, 0x23, 0xED, 0x4C,
  33356. 0x17, 0x3F, 0x98, 0x5D, 0x64, 0x50, 0x16, 0x5A,
  33357. 0xE3, 0xE2, 0x41, 0xA1, 0x82, 0x34, 0xE7, 0x4F,
  33358. 0xF3, 0xDD, 0xB9, 0x21, 0xA5, 0x30, 0x0B, 0x1C,
  33359. 0x4F, 0xB6, 0xE4, 0x32, 0xE6, 0x98, 0xF5, 0x3F,
  33360. 0x66, 0xE3, 0x8C, 0x07, 0xBC, 0xD6, 0xE7, 0x76,
  33361. 0x05, 0xDF, 0x46, 0x24, 0xD5, 0x79, 0x07, 0x62,
  33362. 0x92, 0xDE, 0x1C, 0xE6, 0xFC, 0x6F, 0x00, 0x81,
  33363. 0xA3, 0x8B, 0xD9, 0x2D, 0x39, 0xB2, 0x4B, 0x73,
  33364. 0xBA, 0xC1, 0xC5, 0x2B, 0xD6, 0x8E, 0x91, 0x81,
  33365. 0xD3, 0xDC, 0xD0, 0xAC, 0x75, 0x34, 0xDB, 0x48,
  33366. 0x90, 0x1E, 0x59, 0x84, 0xF9, 0x90, 0x25, 0x57,
  33367. 0xBF, 0xA2, 0x31, 0xB2, 0xEA, 0x28, 0xC3, 0x18,
  33368. 0x32, 0x62, 0xA1, 0xB2, 0x22, 0x1F, 0x74, 0x26,
  33369. 0xEA, 0x88, 0xA5, 0x81, 0x60, 0x93, 0xA5, 0xCA,
  33370. 0xE2, 0xCD, 0x5D, 0x59, 0xA9, 0x39, 0x0F, 0xC9,
  33371. 0x3A, 0x29, 0x56, 0x94, 0x4B, 0x06, 0x4C, 0xF0,
  33372. 0x13, 0xBC, 0xDB, 0x67, 0xFB, 0x42, 0x3D, 0x13,
  33373. 0x28, 0xD2, 0xC6, 0xD7, 0xBA, 0x32, 0x90, 0x13,
  33374. 0xFA, 0x2D, 0x30, 0xEF, 0xD6, 0x9F, 0xDC, 0xA1,
  33375. 0xA9, 0x5E, 0xA6, 0xD0, 0x6C, 0x73, 0x63, 0x53,
  33376. 0x4B, 0x2F, 0x3F, 0x7D, 0xAA, 0xFA, 0x29, 0x6E,
  33377. 0xAA, 0x09, 0xB3, 0x66, 0x8E, 0x9C, 0xF8, 0x2D,
  33378. 0x9B, 0xA9, 0x59, 0xB3, 0x2F, 0x3C, 0xAD, 0x3C,
  33379. 0x10, 0xC6, 0xEA, 0x48, 0x61, 0x15, 0x54, 0x53,
  33380. 0x9C, 0x37, 0xDF, 0x6B, 0xCA, 0x33, 0x85, 0xEA,
  33381. 0xD3, 0xFC, 0xFF, 0x96, 0xD3, 0x72, 0xB4, 0x23,
  33382. 0x93, 0xB7, 0x3C, 0x8D, 0xAA, 0xAA, 0x31, 0x50,
  33383. 0x6E, 0xE0, 0x52, 0x7B, 0x7F, 0xB3, 0xE5, 0x93,
  33384. 0xDC, 0xCC, 0xA5, 0x7C, 0x8F, 0xBB, 0xD4, 0xA3,
  33385. 0xC7, 0xF8, 0xA5, 0x38, 0x99, 0x86, 0x91, 0x32,
  33386. 0xFB, 0xC3, 0xE4, 0x05, 0x06, 0x07, 0xBB, 0xFE,
  33387. 0x29, 0xC6, 0x75, 0xE3, 0x94, 0x5E, 0x74, 0xA3,
  33388. 0x1C, 0xD5, 0x31, 0xBA, 0x7A, 0xEB, 0x2E, 0x2F,
  33389. 0x0C, 0xD9, 0x90, 0xB8, 0xF9, 0x83, 0xA9, 0x0D,
  33390. 0xFE, 0xA0, 0x56, 0x8F, 0x06, 0x77, 0xEA, 0x95,
  33391. 0x63, 0xF7, 0xC4, 0x79, 0xDE, 0x96, 0x89, 0x40,
  33392. 0xCF, 0x24, 0x29, 0x92, 0x69, 0x28, 0x65, 0xCF,
  33393. 0xDA, 0x89, 0xFA, 0x07, 0x8B, 0xBE, 0xF4, 0x9C,
  33394. 0xE4, 0x57, 0x5B, 0xDF, 0xB3, 0x80, 0x36, 0x60,
  33395. 0x11, 0xC8, 0x43, 0x5F, 0x12, 0xB4, 0x2D, 0x9A,
  33396. 0xB9, 0x9A, 0xB6, 0xA3, 0x19, 0x12, 0xC4, 0x35,
  33397. 0x41, 0x49, 0xD7, 0x23, 0x10, 0x1D, 0x13, 0x65,
  33398. 0xA6, 0x5E, 0x7C, 0xC6, 0x8D, 0x82, 0xE3, 0x05,
  33399. 0x17, 0x77, 0x39, 0x02, 0xFB, 0x38, 0xDD, 0xA2,
  33400. 0xB3, 0x24, 0xE7, 0x20, 0x8E, 0x98, 0x7E, 0xD2,
  33401. 0x87, 0xD0, 0x92, 0xE7, 0x66, 0x2A, 0x43, 0x02,
  33402. 0x41, 0xBF, 0xCA, 0x55, 0x2D, 0x31, 0x41, 0x27,
  33403. 0xE3, 0x8C, 0x85, 0x97, 0xA8, 0x95, 0x19, 0xD4,
  33404. 0xF1, 0xE6, 0x2A, 0x79, 0x46, 0x5A, 0xD5, 0xF4,
  33405. 0xEA, 0xA3, 0xFA, 0x77, 0xCD, 0x98, 0x32, 0x6D,
  33406. 0x2F, 0x92, 0xCE, 0x98, 0x52, 0x05, 0x5C, 0xEC,
  33407. 0xCF, 0x62, 0xD6, 0x3C, 0xB9, 0xD7, 0xF1, 0x98,
  33408. 0xAE, 0x08, 0x5E, 0x4D, 0x45, 0xC8, 0xE4, 0x8F,
  33409. 0xCF, 0xFE, 0x59, 0x3A, 0xD6, 0x52, 0xD9, 0x15,
  33410. 0x41, 0x67, 0xBF, 0x3E, 0x61, 0x95, 0x81, 0x0A,
  33411. 0x44, 0x5A, 0xE1, 0x58, 0xF1, 0xF9, 0xA6, 0x79,
  33412. 0x33, 0x63, 0xAF, 0xC1, 0xF2, 0x2C, 0xA8, 0x82,
  33413. 0xFE, 0xED, 0x3A, 0x5F, 0x57, 0x27, 0xCA, 0x76,
  33414. 0x47, 0x7C, 0x5F, 0x23, 0xF0, 0xFC, 0x87, 0x00,
  33415. 0xCD, 0xC6, 0xA5, 0xBC, 0xB2, 0xB2, 0x0B, 0x4F,
  33416. 0x92, 0x66, 0x35, 0x1D, 0x30, 0x4A, 0x96, 0xA8,
  33417. 0x2B, 0xF5, 0xF3, 0x14, 0xAF, 0x68, 0x5C, 0x1C,
  33418. 0x70, 0x7C, 0x92, 0xE3, 0xE8, 0x47, 0xB7, 0x04,
  33419. 0x7D, 0x68, 0x9C, 0x70, 0xB2, 0x5E, 0x55, 0x01,
  33420. 0xCA, 0xEC, 0x99, 0x19, 0x62, 0x6F, 0x4A, 0x0F,
  33421. 0xC8, 0x15, 0x86, 0xAF, 0x1E, 0xC8, 0x88, 0x89,
  33422. 0xB4, 0x23, 0x38, 0x7D, 0x5D, 0x95, 0x48, 0x26,
  33423. 0x18, 0xA6, 0x50, 0xE8, 0x0B, 0x53, 0xB0, 0x7C,
  33424. 0xAC, 0xE3, 0x22, 0x89, 0x40, 0x60, 0x2E, 0x3D,
  33425. 0xB4, 0x74, 0x66, 0xCE, 0x9B, 0xCC, 0xB6, 0xE4,
  33426. 0xD8, 0xAA, 0x61, 0xC8, 0x91, 0x25, 0x83, 0xE8,
  33427. 0x10, 0xB3, 0xB2, 0xE7, 0xE9, 0xCB, 0x48, 0xBD,
  33428. 0x40, 0x3E, 0xCF, 0x08, 0xD2, 0x8C, 0x70, 0xAE,
  33429. 0x0B, 0x62, 0x08, 0x59, 0xC1, 0xF0, 0x9B, 0x61,
  33430. 0x13, 0x14, 0x04, 0xC3, 0xD5, 0xBF, 0xFC, 0xD8,
  33431. 0x60, 0xE0, 0xF4, 0x2A, 0xB2, 0x99, 0x00, 0x62,
  33432. 0x30, 0xB2, 0x87, 0x6D, 0x77, 0xDD, 0xA9, 0x1C,
  33433. 0x8C, 0x62, 0xBD, 0x93, 0xA8, 0x44, 0xE4, 0xB3,
  33434. 0x44, 0xE3, 0x25, 0x5E, 0xEA, 0x53, 0x1C, 0x6C,
  33435. 0x45, 0x8D, 0x04, 0xAB, 0xDB, 0x0F, 0xAE, 0xF2,
  33436. 0xD1, 0xC0, 0xB4, 0xC5, 0x5F, 0x57, 0x0A, 0x5A,
  33437. 0x51, 0x02, 0x3F, 0x4D, 0x4E, 0xFF, 0xF5, 0x9F,
  33438. 0x9A, 0xBE, 0x17, 0x92, 0x2F, 0xE7, 0x32, 0xCA,
  33439. 0x71, 0xBC, 0xD4, 0x34, 0xAD, 0x77, 0x10, 0xB8,
  33440. 0x4C, 0xD4, 0xAC, 0x9F, 0x25, 0x07, 0xA0, 0x68,
  33441. 0x26, 0x56, 0x2A, 0xD7, 0xF6, 0x47, 0x82, 0x6F,
  33442. 0x9D, 0xBB, 0xE4, 0xED, 0xD2, 0x3F, 0x12, 0x43,
  33443. 0x69, 0xDB, 0x85, 0x26, 0xFC, 0x2B, 0x4D, 0x52,
  33444. 0xF0, 0x74, 0x14, 0x15, 0xF9, 0x72, 0xBE, 0xF6,
  33445. 0xA9, 0x35, 0xBD, 0x81, 0x2A, 0x56, 0xC8, 0x22,
  33446. 0x1B, 0x7D, 0xEF, 0x0F, 0x51, 0x06, 0xBC, 0x01,
  33447. 0xE9, 0x13, 0xE3, 0xD4, 0x3D, 0xB8, 0x6C, 0x2B,
  33448. 0xB4, 0xC7, 0xE0, 0x76, 0x26, 0x63, 0xC6, 0xDE,
  33449. 0x78, 0x87, 0x21, 0xC2, 0xAA, 0x07, 0xF8, 0x95,
  33450. 0x48, 0x87, 0xE2, 0x14, 0x2F, 0x2E, 0x91, 0x4A,
  33451. 0x09, 0x9E, 0xFC, 0x0A, 0xEE, 0x13, 0x39, 0x21,
  33452. 0x0D, 0x3E, 0x53, 0xDA, 0x3E, 0xCF, 0x88, 0x62,
  33453. 0x4B, 0x11, 0x19, 0xBE, 0x34, 0x01, 0x0B, 0x88,
  33454. 0x6C, 0x80, 0xF5, 0x1D, 0x18, 0x50, 0x83, 0x8F,
  33455. 0x21, 0x50, 0xE7, 0x2B, 0x04, 0x2A, 0xF3, 0x28,
  33456. 0x99, 0xC0, 0xD3, 0xD7, 0xB0, 0x2A, 0x57, 0xF8,
  33457. 0xCF, 0x26, 0x3A, 0x36, 0x95, 0x62, 0xE4, 0xE9,
  33458. 0x45, 0xA3, 0x12, 0x82, 0xA5, 0x02, 0xA9, 0x5E,
  33459. 0xE9, 0xBB, 0x03, 0x16, 0xC6, 0x86, 0x10, 0x06,
  33460. 0xDA, 0xC1, 0x7F, 0x93, 0x6F, 0x54, 0xC4, 0xC7
  33461. };
  33462. #endif /* WOLFSSL_NO_ML_DSA_87 */
  33463. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  33464. #ifndef WOLFSSL_NO_ML_DSA_44
  33465. static const byte seed_44_draft[] = {
  33466. 0xBA, 0xC0, 0x59, 0x52, 0x75, 0x5B, 0x26, 0x47,
  33467. 0x01, 0xCA, 0x7D, 0x80, 0x6D, 0xFA, 0x08, 0x35,
  33468. 0x10, 0x28, 0xF6, 0x7B, 0x0E, 0x83, 0xC4, 0x24,
  33469. 0x01, 0x6F, 0x66, 0xCC, 0x83, 0x87, 0xD4, 0x69
  33470. };
  33471. static const byte pk_44_draft[] = {
  33472. 0x86, 0xF0, 0x0C, 0x20, 0xE0, 0xDA, 0xEE, 0x5E,
  33473. 0x1E, 0xDE, 0x71, 0x39, 0x49, 0x0C, 0xC8, 0xCF,
  33474. 0xEF, 0xC9, 0xAB, 0x62, 0x3B, 0x8D, 0xEF, 0x0B,
  33475. 0xD8, 0x03, 0x12, 0x5B, 0x4A, 0xB2, 0x83, 0x61,
  33476. 0xED, 0x7E, 0xA9, 0xED, 0x2D, 0xED, 0x5A, 0x71,
  33477. 0xDD, 0xAE, 0x4A, 0x06, 0xE0, 0x2A, 0x5A, 0xAF,
  33478. 0x99, 0x69, 0x89, 0xC6, 0xAF, 0xE3, 0x2A, 0xFE,
  33479. 0x3D, 0x6E, 0x0A, 0x46, 0x71, 0x48, 0xD7, 0x17,
  33480. 0x99, 0x20, 0x01, 0x78, 0xD5, 0x8B, 0x40, 0xCB,
  33481. 0x81, 0xA0, 0x33, 0x38, 0xAE, 0x2B, 0x83, 0x4A,
  33482. 0xFD, 0x5F, 0xE0, 0xB7, 0xEE, 0xA0, 0xC4, 0x3D,
  33483. 0xB6, 0xA4, 0xD5, 0x59, 0x4B, 0xDD, 0x87, 0x1A,
  33484. 0xFC, 0x03, 0x30, 0xA0, 0xB3, 0xAD, 0x75, 0x3C,
  33485. 0xD4, 0x47, 0x72, 0x59, 0xCE, 0xB7, 0x80, 0xFD,
  33486. 0x34, 0x35, 0x5E, 0x96, 0xC8, 0x42, 0xD9, 0xDD,
  33487. 0x6C, 0xF1, 0xAB, 0xEF, 0x48, 0xD1, 0xA8, 0x02,
  33488. 0x02, 0x0F, 0x5B, 0x71, 0x4D, 0x36, 0x1E, 0x0D,
  33489. 0xC2, 0x09, 0x46, 0x7B, 0xF9, 0xEA, 0x24, 0x8F,
  33490. 0x7C, 0xCF, 0xB8, 0x9C, 0xF7, 0x49, 0x15, 0x8E,
  33491. 0x16, 0x49, 0x7E, 0xC5, 0x54, 0xF5, 0x03, 0x1D,
  33492. 0x16, 0x12, 0x02, 0x72, 0x1B, 0x38, 0x2D, 0x58,
  33493. 0x53, 0x15, 0x5E, 0xB6, 0x72, 0xCC, 0xA1, 0x09,
  33494. 0xB0, 0x2F, 0x10, 0xFA, 0x21, 0x45, 0x46, 0x37,
  33495. 0xD4, 0xFA, 0x7F, 0xFB, 0xB0, 0xD9, 0x20, 0xE2,
  33496. 0xCB, 0x56, 0xB3, 0x1E, 0xDF, 0x82, 0x67, 0x25,
  33497. 0x09, 0xD1, 0x8F, 0xFF, 0xE0, 0x43, 0xBD, 0x37,
  33498. 0x2B, 0x73, 0x0E, 0x13, 0x08, 0xC9, 0x49, 0x88,
  33499. 0x69, 0x69, 0xD9, 0x8C, 0x86, 0xE4, 0x7E, 0x63,
  33500. 0x35, 0xC5, 0xE1, 0xD0, 0x14, 0x9A, 0x89, 0x27,
  33501. 0x28, 0x17, 0xB0, 0x5B, 0x7A, 0x8F, 0xDD, 0x72,
  33502. 0x8B, 0x0A, 0x0D, 0x49, 0x58, 0x59, 0x2F, 0x0D,
  33503. 0x8F, 0x3D, 0x16, 0xCE, 0x7B, 0x11, 0xC7, 0x06,
  33504. 0x5D, 0xD5, 0x6D, 0x7B, 0x96, 0xED, 0x1E, 0x1A,
  33505. 0xF4, 0x10, 0x85, 0xDA, 0xDE, 0x84, 0x2F, 0x2B,
  33506. 0xBA, 0xFB, 0xA2, 0x5F, 0x33, 0x7D, 0x7C, 0x18,
  33507. 0x6B, 0xDF, 0x43, 0x3C, 0xE9, 0xEB, 0xB4, 0xC5,
  33508. 0x8E, 0x52, 0xF5, 0x7E, 0x4C, 0x3E, 0x6A, 0x33,
  33509. 0x41, 0x4C, 0x14, 0x05, 0x8E, 0x2C, 0x19, 0x0E,
  33510. 0x86, 0x91, 0x66, 0xDE, 0xF6, 0x4B, 0x35, 0xC2,
  33511. 0xDF, 0x3D, 0x4C, 0x7B, 0xC5, 0x58, 0x5E, 0x86,
  33512. 0x89, 0x6A, 0xFC, 0x86, 0x48, 0x75, 0xD1, 0x18,
  33513. 0xD1, 0xCB, 0x41, 0xC0, 0xF6, 0xD8, 0x87, 0x79,
  33514. 0xD9, 0xA2, 0x56, 0x2E, 0x83, 0x26, 0x11, 0xC1,
  33515. 0x4B, 0x53, 0x37, 0x85, 0x62, 0xFF, 0x6A, 0x67,
  33516. 0xFD, 0x18, 0x79, 0xD7, 0x55, 0x9B, 0xF7, 0x64,
  33517. 0xA9, 0x21, 0xB6, 0x1B, 0xF6, 0x11, 0x85, 0xF8,
  33518. 0xC0, 0x68, 0xDE, 0x61, 0x0C, 0x61, 0x7E, 0x8E,
  33519. 0xED, 0x9E, 0x58, 0x84, 0x16, 0x1A, 0x28, 0xC5,
  33520. 0x41, 0x63, 0xB3, 0xF0, 0x82, 0xAA, 0xE8, 0x36,
  33521. 0x81, 0x5C, 0xD3, 0xB7, 0xFB, 0x92, 0xF4, 0x7A,
  33522. 0x1E, 0x85, 0xA2, 0xB7, 0x21, 0xD5, 0xFA, 0xC8,
  33523. 0xE8, 0x02, 0x43, 0x5B, 0x56, 0x42, 0x03, 0x17,
  33524. 0x67, 0xEE, 0x3E, 0x31, 0x23, 0x63, 0xC7, 0x33,
  33525. 0x95, 0xDE, 0x07, 0xF6, 0x11, 0x3A, 0x2C, 0x3F,
  33526. 0x7B, 0xBB, 0x2D, 0x5C, 0x23, 0xF9, 0x2F, 0x9C,
  33527. 0x51, 0x19, 0x9F, 0x35, 0xC3, 0x18, 0x9F, 0x83,
  33528. 0x6E, 0xA8, 0x03, 0xF1, 0x79, 0x1F, 0xB0, 0xC8,
  33529. 0x2F, 0xF4, 0x2E, 0x9A, 0x26, 0xF3, 0x44, 0x02,
  33530. 0x8F, 0x45, 0x8B, 0xB0, 0x25, 0x1D, 0xF2, 0xD4,
  33531. 0x55, 0xB7, 0x65, 0xEF, 0xDB, 0x3D, 0x8E, 0x92,
  33532. 0xC8, 0xA0, 0x63, 0x4C, 0x38, 0xA3, 0x54, 0xD3,
  33533. 0xC2, 0x5A, 0x2A, 0x6A, 0x15, 0x27, 0x2A, 0xE2,
  33534. 0xFC, 0x25, 0xB6, 0xC8, 0x68, 0xEB, 0xED, 0x2D,
  33535. 0x23, 0xE8, 0x6D, 0x5C, 0xDD, 0x3F, 0x18, 0xB4,
  33536. 0x6E, 0x79, 0x36, 0xC9, 0x1C, 0xB4, 0x92, 0x41,
  33537. 0xAD, 0x35, 0xD4, 0x15, 0xE4, 0x64, 0x1C, 0x51,
  33538. 0xCB, 0x0C, 0x41, 0xB7, 0xFD, 0xC1, 0x09, 0x3E,
  33539. 0xD2, 0x4D, 0x38, 0x88, 0x77, 0x1C, 0x71, 0x91,
  33540. 0x74, 0xD3, 0x28, 0xE0, 0xCE, 0x9A, 0x11, 0x8D,
  33541. 0xBF, 0x4D, 0x8D, 0xF0, 0x44, 0xF6, 0x79, 0xFC,
  33542. 0x4C, 0xAD, 0x17, 0x88, 0xC0, 0x8C, 0x0B, 0x7A,
  33543. 0x90, 0x01, 0x53, 0x6C, 0x6B, 0x44, 0xF6, 0xE5,
  33544. 0x2E, 0xEC, 0x44, 0x4F, 0xB8, 0x9B, 0x10, 0xBE,
  33545. 0xCF, 0x55, 0x55, 0x29, 0x83, 0xB8, 0xD0, 0x25,
  33546. 0x5B, 0xCE, 0x8F, 0xA5, 0xB7, 0x6C, 0xA7, 0x47,
  33547. 0x65, 0xA9, 0xE9, 0x9B, 0xA5, 0xBC, 0x28, 0x1D,
  33548. 0x9F, 0x1F, 0x5E, 0x97, 0x42, 0x10, 0x84, 0x92,
  33549. 0xFB, 0x38, 0x0B, 0x2E, 0xAC, 0x79, 0x0A, 0x7D,
  33550. 0x00, 0x2C, 0x35, 0xD0, 0x54, 0x0D, 0x28, 0xE7,
  33551. 0xAB, 0x06, 0x02, 0xDA, 0x89, 0xA3, 0x06, 0x8E,
  33552. 0x13, 0x9A, 0xA7, 0xCA, 0x48, 0x09, 0xB0, 0x48,
  33553. 0x37, 0x08, 0xA7, 0x7D, 0xDA, 0xEB, 0x58, 0x64,
  33554. 0x39, 0xB3, 0xF3, 0xB2, 0x4C, 0x00, 0x4B, 0xCB,
  33555. 0x94, 0x36, 0xD4, 0x7C, 0x73, 0x45, 0xC8, 0x93,
  33556. 0xE5, 0x2A, 0x11, 0xF0, 0xEF, 0x0C, 0xED, 0x5F,
  33557. 0x8B, 0x0C, 0x86, 0xAD, 0x3A, 0x01, 0x07, 0x1A,
  33558. 0xC0, 0x34, 0xE8, 0x74, 0x21, 0x27, 0x73, 0x56,
  33559. 0x93, 0x76, 0x5D, 0x80, 0x59, 0xB4, 0xA4, 0xDC,
  33560. 0x80, 0xE7, 0xCE, 0x70, 0x0E, 0x0F, 0xEC, 0x56,
  33561. 0x42, 0x6E, 0x9C, 0x76, 0x3D, 0xF6, 0xB4, 0x41,
  33562. 0xE2, 0x3E, 0xAC, 0x25, 0xE7, 0x86, 0xA7, 0xA7,
  33563. 0x0A, 0x0D, 0x5D, 0x04, 0x1F, 0x45, 0xD4, 0x5B,
  33564. 0x42, 0x38, 0x4C, 0x60, 0xE7, 0xB7, 0x0D, 0xC7,
  33565. 0x28, 0x4F, 0xA5, 0x4E, 0x0C, 0x1B, 0xC4, 0xDA,
  33566. 0x50, 0x1A, 0xA0, 0x93, 0xAE, 0x10, 0x9A, 0x1A,
  33567. 0xC8, 0xC6, 0x56, 0xFC, 0x0A, 0xEA, 0x89, 0x3A,
  33568. 0x28, 0x21, 0xE9, 0x52, 0x9D, 0xEB, 0x07, 0x68,
  33569. 0xC1, 0x57, 0x32, 0x25, 0x1F, 0x93, 0x5D, 0x35,
  33570. 0xB2, 0x4B, 0x58, 0x30, 0xAF, 0x51, 0xC6, 0x7D,
  33571. 0x47, 0xD1, 0xA2, 0xAD, 0xDE, 0x75, 0x48, 0x84,
  33572. 0x74, 0x19, 0x74, 0x18, 0xA0, 0x2C, 0xD8, 0xB2,
  33573. 0xFE, 0x44, 0x78, 0x95, 0x6A, 0xBF, 0x56, 0x4D,
  33574. 0x20, 0x79, 0xE7, 0xE2, 0xE3, 0x56, 0x69, 0xB3,
  33575. 0xFA, 0xE1, 0xEB, 0xE6, 0x11, 0xAC, 0x18, 0xB3,
  33576. 0x98, 0xC1, 0x04, 0x20, 0x96, 0x4B, 0xAD, 0xDE,
  33577. 0x5B, 0x18, 0xEB, 0x7B, 0xBC, 0x15, 0x11, 0x57,
  33578. 0x29, 0x10, 0xE5, 0x80, 0x78, 0x4A, 0xF0, 0x87,
  33579. 0xF6, 0xD1, 0x3C, 0x23, 0xC5, 0xF4, 0x2D, 0xD7,
  33580. 0xAB, 0xA4, 0xD7, 0xB8, 0x45, 0x8E, 0x04, 0x1B,
  33581. 0x78, 0x59, 0x9F, 0x81, 0xE6, 0x04, 0xDF, 0x70,
  33582. 0x2B, 0x14, 0x74, 0x16, 0x49, 0xDA, 0xF0, 0xE1,
  33583. 0xC8, 0x29, 0xCC, 0x87, 0x8C, 0x2F, 0xFB, 0x18,
  33584. 0x3B, 0x47, 0xFC, 0x79, 0x04, 0x84, 0xCB, 0x0A,
  33585. 0xD2, 0x64, 0xBF, 0x86, 0xEA, 0x01, 0xAC, 0xE0,
  33586. 0xBD, 0xEC, 0x3B, 0xE1, 0xA7, 0x6C, 0xDE, 0x1D,
  33587. 0x58, 0x76, 0xCC, 0x53, 0x9E, 0xF6, 0xC6, 0xD4,
  33588. 0x2C, 0x87, 0x92, 0xA2, 0x89, 0x27, 0x31, 0x33,
  33589. 0x01, 0xA5, 0xA2, 0xE8, 0x8F, 0x13, 0x19, 0x0F,
  33590. 0xFD, 0x73, 0xB9, 0x91, 0xBD, 0xB8, 0x80, 0x9A,
  33591. 0xA3, 0xB1, 0x21, 0x6C, 0x91, 0x13, 0x8A, 0xAE,
  33592. 0xC7, 0xCB, 0x67, 0x14, 0xD1, 0xC0, 0x28, 0x89,
  33593. 0x04, 0x8C, 0x9F, 0xDE, 0xA0, 0x9A, 0x99, 0xA8,
  33594. 0x61, 0xE6, 0x8F, 0x8E, 0x39, 0xEF, 0x6B, 0x5E,
  33595. 0x84, 0x5F, 0x5D, 0x24, 0x37, 0x73, 0x9D, 0x75,
  33596. 0xC4, 0xEF, 0xE2, 0xA1, 0xF2, 0xBC, 0x0D, 0xE1,
  33597. 0x0D, 0xEC, 0xFA, 0xEE, 0xC1, 0x63, 0xC8, 0x2E,
  33598. 0x7D, 0x85, 0x65, 0xC3, 0xF2, 0x0D, 0x8B, 0x73,
  33599. 0xF9, 0x3B, 0x0B, 0x3D, 0x49, 0x8B, 0xFB, 0x16,
  33600. 0x5B, 0x75, 0x48, 0x9B, 0x56, 0x0A, 0x83, 0x4C,
  33601. 0x0D, 0x13, 0xB2, 0xB4, 0x25, 0xC7, 0x2C, 0xCB,
  33602. 0xA7, 0x9E, 0xCA, 0x41, 0x44, 0x14, 0x9A, 0x03,
  33603. 0xD3, 0x01, 0x8C, 0xB0, 0xD5, 0xA9, 0x36, 0xA4,
  33604. 0x16, 0x21, 0x49, 0x0A, 0x99, 0xA1, 0x89, 0xA5,
  33605. 0x91, 0x10, 0xA2, 0x1B, 0x3F, 0x98, 0x1E, 0x1C,
  33606. 0x43, 0xAA, 0x9C, 0x16, 0x5A, 0xF0, 0x18, 0x64,
  33607. 0x0F, 0x6A, 0xE3, 0x97, 0x83, 0x31, 0x4E, 0x84,
  33608. 0xC9, 0xEA, 0xD8, 0x9F, 0xEA, 0x9E, 0xD6, 0xF2,
  33609. 0x0E, 0x15, 0xA5, 0x48, 0x15, 0x8B, 0x10, 0x1D,
  33610. 0x77, 0x78, 0x1B, 0x54, 0x03, 0xC1, 0x2C, 0xB1,
  33611. 0xC8, 0x22, 0x11, 0x9D, 0xB8, 0x82, 0x94, 0x26,
  33612. 0xA0, 0xED, 0x6C, 0xAD, 0xA8, 0x03, 0xC2, 0xED,
  33613. 0x02, 0x74, 0x3E, 0x54, 0xBD, 0x77, 0xA6, 0x0B,
  33614. 0x37, 0xFE, 0x04, 0xCD, 0x25, 0x10, 0x2D, 0x52,
  33615. 0xC2, 0xD4, 0x5B, 0x9B, 0xAE, 0xFE, 0x35, 0x73,
  33616. 0x16, 0x61, 0x84, 0x25, 0x1D, 0xBE, 0x95, 0x34,
  33617. 0xA4, 0xF6, 0xB9, 0xA4, 0xF9, 0xAA, 0x5D, 0x1E,
  33618. 0x49, 0xBB, 0x19, 0xD9, 0x64, 0xD7, 0x48, 0x1A,
  33619. 0x0A, 0x93, 0xC3, 0x69, 0x13, 0x12, 0x68, 0xBB,
  33620. 0x97, 0x97, 0xBD, 0x99, 0x69, 0xCE, 0xE6, 0xF5,
  33621. 0x84, 0x7B, 0xCC, 0xE4, 0x7D, 0xD3, 0xCD, 0x8A,
  33622. 0x7A, 0x4B, 0x98, 0xF4, 0x09, 0x9D, 0xEA, 0x5D,
  33623. 0x4E, 0x1F, 0xE1, 0x1E, 0x6C, 0x48, 0xD3, 0x5E,
  33624. 0x67, 0xD9, 0xFF, 0x64, 0x4D, 0xA7, 0x64, 0x7A,
  33625. 0x01, 0xB2, 0xE9, 0x63, 0x14, 0x10, 0xB7, 0x08,
  33626. 0x0C, 0xF9, 0x4D, 0x66, 0x48, 0x46, 0xE3, 0xC2,
  33627. 0x48, 0x6B, 0x47, 0xCE, 0x00, 0x98, 0x92, 0x83,
  33628. 0xF7, 0xE0, 0x1F, 0x96, 0xFA, 0x53, 0xD5, 0x49,
  33629. 0x1C, 0xC7, 0x89, 0xB4, 0xA5, 0x4B, 0x63, 0xBF,
  33630. 0xD2, 0x00, 0x79, 0xDD, 0xC1, 0x60, 0xAA, 0xF2,
  33631. 0x0F, 0x47, 0xB9, 0x4F, 0x8A, 0x66, 0x05, 0x3D,
  33632. 0x96, 0x36, 0x64, 0x48, 0x5F, 0x7E, 0x56, 0x2B,
  33633. 0xB3, 0x47, 0xE2, 0x76, 0x64, 0x21, 0x65, 0x34,
  33634. 0xFC, 0xDD, 0x2D, 0x4C, 0xE2, 0x99, 0x33, 0x04,
  33635. 0xE4, 0x26, 0x15, 0x37, 0x6C, 0x32, 0xB9, 0x17
  33636. };
  33637. static const byte sk_44_draft[] = {
  33638. 0x86, 0xF0, 0x0C, 0x20, 0xE0, 0xDA, 0xEE, 0x5E,
  33639. 0x1E, 0xDE, 0x71, 0x39, 0x49, 0x0C, 0xC8, 0xCF,
  33640. 0xEF, 0xC9, 0xAB, 0x62, 0x3B, 0x8D, 0xEF, 0x0B,
  33641. 0xD8, 0x03, 0x12, 0x5B, 0x4A, 0xB2, 0x83, 0x61,
  33642. 0x73, 0x61, 0x49, 0x01, 0x0F, 0x94, 0x08, 0x30,
  33643. 0x26, 0x02, 0x12, 0x63, 0x64, 0x15, 0x7A, 0x4D,
  33644. 0xBA, 0xF5, 0x25, 0xA7, 0xAA, 0x0B, 0x7C, 0x3D,
  33645. 0xCE, 0x05, 0x91, 0x95, 0xEF, 0x17, 0x2F, 0xE2,
  33646. 0x5A, 0x03, 0x5E, 0x2E, 0x4D, 0xFA, 0xE7, 0x5F,
  33647. 0xCD, 0x61, 0x34, 0xFB, 0x3D, 0x3C, 0x5C, 0x60,
  33648. 0x1A, 0x6F, 0x09, 0xB5, 0x9D, 0xDD, 0x90, 0x53,
  33649. 0xF6, 0x89, 0x50, 0xC2, 0xE1, 0xED, 0x0A, 0x61,
  33650. 0x8F, 0xFA, 0xDC, 0x2D, 0xB2, 0x8B, 0xA1, 0x56,
  33651. 0xAC, 0x5E, 0x0E, 0xF1, 0x3B, 0x1E, 0x22, 0x9F,
  33652. 0xAA, 0x05, 0x96, 0xA3, 0x5E, 0x44, 0x86, 0xA8,
  33653. 0xBA, 0x15, 0xD1, 0x11, 0x7D, 0xAA, 0xD0, 0xAA,
  33654. 0x01, 0x27, 0x25, 0x04, 0x82, 0x89, 0xA4, 0x22,
  33655. 0x2E, 0xDB, 0x80, 0x45, 0xD2, 0x30, 0x45, 0x59,
  33656. 0x16, 0x64, 0xE2, 0x08, 0x86, 0x50, 0x00, 0x8E,
  33657. 0xCA, 0x08, 0x51, 0x5A, 0x06, 0x01, 0x54, 0x82,
  33658. 0x20, 0xC4, 0x92, 0x30, 0x02, 0x21, 0x4E, 0x0A,
  33659. 0x93, 0x89, 0x84, 0xB8, 0x70, 0x24, 0x40, 0x51,
  33660. 0x24, 0xB3, 0x44, 0xDB, 0x08, 0x40, 0x1B, 0x37,
  33661. 0x44, 0x21, 0x22, 0x8E, 0x8C, 0x16, 0x42, 0x10,
  33662. 0x22, 0x0E, 0xA1, 0xB2, 0x8D, 0x18, 0x49, 0x30,
  33663. 0xC1, 0x32, 0x69, 0x21, 0x03, 0x8E, 0x49, 0x44,
  33664. 0x08, 0xD3, 0x16, 0x89, 0x10, 0xA4, 0x25, 0x5C,
  33665. 0x22, 0x8A, 0xC0, 0xC8, 0x08, 0xC1, 0x04, 0x6A,
  33666. 0xD2, 0xA0, 0x50, 0x8A, 0x02, 0x52, 0x92, 0x16,
  33667. 0x44, 0x54, 0x30, 0x4A, 0x92, 0x32, 0x0C, 0x4C,
  33668. 0x44, 0x2D, 0x04, 0x15, 0x2A, 0x99, 0x24, 0x42,
  33669. 0x52, 0xA8, 0x30, 0x53, 0x24, 0x85, 0x9A, 0xB8,
  33670. 0x01, 0xE2, 0x08, 0x09, 0x23, 0x28, 0x08, 0xC4,
  33671. 0x98, 0x85, 0x0B, 0xB9, 0x40, 0x60, 0x26, 0x28,
  33672. 0x0A, 0x45, 0x12, 0x0C, 0x43, 0x84, 0x82, 0x16,
  33673. 0x89, 0xC4, 0x48, 0x28, 0x58, 0x18, 0x2A, 0x20,
  33674. 0x07, 0x02, 0xD3, 0x82, 0x45, 0x50, 0xB0, 0x50,
  33675. 0x64, 0x36, 0x91, 0x52, 0x02, 0x45, 0x5A, 0x42,
  33676. 0x26, 0x01, 0x28, 0x71, 0xD4, 0x86, 0x10, 0x19,
  33677. 0xC4, 0x68, 0xC4, 0x30, 0x66, 0xE0, 0x02, 0x49,
  33678. 0x18, 0x34, 0x05, 0x04, 0x02, 0x04, 0x90, 0x94,
  33679. 0x4C, 0x01, 0xA7, 0x80, 0x12, 0x97, 0x08, 0x19,
  33680. 0xC5, 0x41, 0x24, 0xC1, 0x61, 0x08, 0xB0, 0x0C,
  33681. 0x21, 0xC1, 0x49, 0x9B, 0x42, 0x51, 0x62, 0x18,
  33682. 0x22, 0x54, 0x06, 0x06, 0x93, 0x26, 0x70, 0x49,
  33683. 0x86, 0x91, 0x00, 0x28, 0x6C, 0x02, 0xC9, 0x60,
  33684. 0x13, 0xC3, 0x09, 0xCB, 0x14, 0x66, 0x09, 0x17,
  33685. 0x25, 0x1C, 0x16, 0x89, 0x01, 0xB6, 0x01, 0x60,
  33686. 0x86, 0x71, 0x58, 0x96, 0x04, 0x82, 0x38, 0x61,
  33687. 0x43, 0x40, 0x72, 0xCC, 0x46, 0x71, 0x81, 0x20,
  33688. 0x2C, 0x18, 0x20, 0x6E, 0x03, 0x91, 0x11, 0x9A,
  33689. 0x08, 0x89, 0x43, 0x06, 0x48, 0x64, 0x02, 0x6C,
  33690. 0x21, 0x33, 0x8D, 0x48, 0x16, 0x66, 0x9B, 0xA4,
  33691. 0x2D, 0x01, 0x10, 0x66, 0xDC, 0xB0, 0x25, 0x40,
  33692. 0xA0, 0x24, 0xA2, 0xB4, 0x44, 0xC8, 0x26, 0x61,
  33693. 0x0A, 0x10, 0x4E, 0xD0, 0x04, 0x11, 0x4A, 0x82,
  33694. 0x51, 0x03, 0x04, 0x6C, 0x18, 0x88, 0x6C, 0xE0,
  33695. 0x98, 0x41, 0x11, 0x29, 0x06, 0x62, 0x12, 0x8E,
  33696. 0xDA, 0x42, 0x91, 0x09, 0x48, 0x60, 0xD1, 0xB4,
  33697. 0x80, 0x10, 0x30, 0x30, 0x80, 0x38, 0x82, 0xD0,
  33698. 0x84, 0x0D, 0x08, 0x14, 0x92, 0x24, 0x41, 0x40,
  33699. 0x0C, 0x10, 0x89, 0xCC, 0x38, 0x8A, 0x13, 0xB6,
  33700. 0x89, 0x1A, 0xA7, 0x24, 0x5C, 0x10, 0x12, 0x1B,
  33701. 0x21, 0x50, 0x91, 0xB4, 0x29, 0x99, 0xB6, 0x51,
  33702. 0x04, 0xB1, 0x91, 0x59, 0xA6, 0x05, 0x19, 0x08,
  33703. 0x4A, 0x4A, 0x84, 0x6C, 0x1C, 0x49, 0x02, 0x44,
  33704. 0x20, 0x85, 0x14, 0xB1, 0x89, 0x09, 0x44, 0x2C,
  33705. 0x10, 0x02, 0x22, 0xE1, 0xB4, 0x25, 0x01, 0x21,
  33706. 0x71, 0x53, 0xC2, 0x85, 0x82, 0x88, 0x28, 0xC0,
  33707. 0x02, 0x52, 0x19, 0xC5, 0x51, 0x19, 0xA5, 0x09,
  33708. 0xC0, 0x82, 0x91, 0x21, 0x47, 0x0D, 0x1C, 0x30,
  33709. 0x69, 0xDC, 0xB8, 0x6C, 0x04, 0x41, 0x6A, 0x91,
  33710. 0x16, 0x40, 0xA0, 0xC8, 0x24, 0x1A, 0x10, 0x01,
  33711. 0x04, 0x39, 0x25, 0x80, 0x16, 0x02, 0x63, 0x36,
  33712. 0x71, 0x90, 0xB0, 0x8D, 0x44, 0x16, 0x8E, 0xDA,
  33713. 0x16, 0x2E, 0xCB, 0x44, 0x20, 0x54, 0x38, 0x06,
  33714. 0x54, 0xC4, 0x01, 0x51, 0x40, 0x86, 0x52, 0x44,
  33715. 0x0E, 0x82, 0x02, 0x32, 0x21, 0x38, 0x89, 0x19,
  33716. 0x04, 0x40, 0xD8, 0x12, 0x68, 0x21, 0x98, 0x11,
  33717. 0x03, 0x33, 0x8A, 0x18, 0x00, 0x45, 0xCB, 0x22,
  33718. 0x32, 0xC3, 0x04, 0x46, 0x09, 0x18, 0x51, 0x22,
  33719. 0x44, 0x89, 0x13, 0x16, 0x6E, 0xDA, 0x46, 0x45,
  33720. 0x09, 0x19, 0x41, 0x81, 0x10, 0x01, 0xDC, 0x18,
  33721. 0x8E, 0xC8, 0x44, 0x4C, 0x00, 0x17, 0x82, 0x9C,
  33722. 0xA6, 0x4D, 0xC8, 0x08, 0x10, 0x24, 0x42, 0x6D,
  33723. 0x91, 0x38, 0x89, 0x8C, 0x40, 0x6E, 0x00, 0x35,
  33724. 0x11, 0xD3, 0x24, 0x09, 0x1A, 0x01, 0x65, 0x88,
  33725. 0x48, 0x45, 0x09, 0x01, 0x71, 0x43, 0xB8, 0x80,
  33726. 0x11, 0x82, 0x2C, 0x84, 0xB8, 0x49, 0x58, 0x14,
  33727. 0x28, 0x92, 0x20, 0x32, 0x09, 0x12, 0x05, 0x20,
  33728. 0x81, 0x2D, 0x5B, 0x86, 0x11, 0x04, 0x90, 0x45,
  33729. 0x49, 0x80, 0x40, 0xD1, 0xC8, 0x24, 0x98, 0xC2,
  33730. 0x2C, 0x99, 0xA2, 0x30, 0x04, 0x98, 0x8C, 0x53,
  33731. 0x24, 0x02, 0x8A, 0x04, 0x01, 0x4C, 0x28, 0x71,
  33732. 0xC3, 0x86, 0x6C, 0x24, 0x49, 0x81, 0x04, 0x02,
  33733. 0x28, 0x62, 0x44, 0x32, 0x61, 0x20, 0x28, 0x01,
  33734. 0x04, 0x11, 0x0C, 0x09, 0x08, 0x90, 0x98, 0x84,
  33735. 0x63, 0xB2, 0x45, 0x63, 0x38, 0x2E, 0x04, 0xA4,
  33736. 0x0C, 0x18, 0x05, 0x4E, 0xCC, 0x86, 0x90, 0x43,
  33737. 0x40, 0x91, 0x54, 0x02, 0x21, 0x43, 0x28, 0x42,
  33738. 0x23, 0x94, 0x29, 0xC8, 0xA6, 0x91, 0x02, 0x09,
  33739. 0x80, 0xE3, 0x82, 0x00, 0xC1, 0x34, 0x08, 0xD1,
  33740. 0x34, 0x84, 0x12, 0x45, 0x8C, 0x02, 0xC6, 0x81,
  33741. 0x41, 0xC6, 0x6C, 0x1B, 0x12, 0x24, 0x04, 0x08,
  33742. 0x0D, 0x02, 0x00, 0x0C, 0x9C, 0xA2, 0x05, 0x49,
  33743. 0x34, 0x65, 0x00, 0x06, 0x89, 0x88, 0x34, 0x00,
  33744. 0xD8, 0x82, 0x29, 0x92, 0x12, 0x91, 0xE3, 0x36,
  33745. 0x86, 0xD1, 0x80, 0x71, 0x98, 0xB0, 0x50, 0x48,
  33746. 0xC6, 0x11, 0x14, 0x80, 0x0D, 0xA0, 0x12, 0x4D,
  33747. 0x9B, 0xB2, 0x40, 0x21, 0x41, 0x50, 0x4B, 0x36,
  33748. 0x05, 0x52, 0x10, 0x26, 0x19, 0xB2, 0x60, 0x92,
  33749. 0xA2, 0x24, 0xCB, 0x08, 0x00, 0x14, 0x22, 0x49,
  33750. 0x5A, 0xD0, 0x55, 0xBD, 0x2B, 0x45, 0xE4, 0x31,
  33751. 0x41, 0xA8, 0xC3, 0xA3, 0xAD, 0xBD, 0xB6, 0x37,
  33752. 0x92, 0x06, 0x95, 0x6B, 0x3D, 0xD8, 0xE5, 0x33,
  33753. 0x71, 0xB6, 0x62, 0xB7, 0x67, 0x6C, 0x77, 0x84,
  33754. 0x63, 0x2F, 0x41, 0x1D, 0xBA, 0x51, 0x27, 0xE1,
  33755. 0x24, 0x5D, 0xC2, 0x38, 0x71, 0x65, 0x9E, 0x8E,
  33756. 0xE4, 0xEB, 0xBB, 0x1D, 0x89, 0xEB, 0x18, 0xCA,
  33757. 0x0C, 0xA6, 0x86, 0xA3, 0x4D, 0x7C, 0x7A, 0x02,
  33758. 0xAC, 0xDD, 0x34, 0xCE, 0x05, 0x3B, 0x1B, 0x49,
  33759. 0xF4, 0x6D, 0x12, 0x33, 0xBC, 0x52, 0x70, 0x59,
  33760. 0xDF, 0xBC, 0x5D, 0x49, 0x42, 0x6A, 0xED, 0xC7,
  33761. 0xF1, 0x8C, 0xF5, 0x6D, 0x1F, 0xBC, 0xE4, 0xBD,
  33762. 0x45, 0x5D, 0x59, 0xF8, 0xCE, 0x9A, 0x39, 0xB5,
  33763. 0x96, 0x32, 0xFD, 0x93, 0x65, 0x8E, 0x92, 0xF1,
  33764. 0x8F, 0xB0, 0x99, 0xF3, 0x80, 0x0F, 0x66, 0x14,
  33765. 0xFE, 0xEB, 0x23, 0x17, 0x2D, 0x4C, 0x8F, 0x41,
  33766. 0x9A, 0x9B, 0xD1, 0x5B, 0x5B, 0xC0, 0x3D, 0xA6,
  33767. 0x0E, 0xF3, 0xE0, 0xA1, 0x04, 0xDC, 0x24, 0x18,
  33768. 0x9D, 0x90, 0xC6, 0x89, 0x5A, 0x7F, 0x10, 0x1E,
  33769. 0x4B, 0x21, 0xEC, 0x91, 0xD8, 0x5D, 0x65, 0xDB,
  33770. 0xCF, 0x90, 0x62, 0x85, 0xE9, 0x58, 0xA3, 0x47,
  33771. 0x92, 0x1C, 0xD0, 0x0C, 0xA3, 0xF3, 0x3E, 0x36,
  33772. 0xDB, 0x24, 0xA6, 0x98, 0xAB, 0xA7, 0x89, 0x2B,
  33773. 0x71, 0x6C, 0x4D, 0x00, 0xB0, 0xD5, 0xA0, 0xCA,
  33774. 0x1A, 0x76, 0x8E, 0x80, 0xB7, 0xAE, 0x83, 0x89,
  33775. 0x50, 0xF8, 0xA7, 0x52, 0x8B, 0x94, 0xD2, 0x2B,
  33776. 0x9F, 0x49, 0x92, 0x3D, 0x54, 0x0D, 0xB8, 0xD1,
  33777. 0x19, 0x49, 0xAC, 0x91, 0xAF, 0xDB, 0xE9, 0x24,
  33778. 0x4D, 0xD8, 0xE1, 0xD5, 0x16, 0x0E, 0xB1, 0x39,
  33779. 0x40, 0x7D, 0x5F, 0xF5, 0x92, 0xB4, 0xAF, 0xC3,
  33780. 0x76, 0x2B, 0xDB, 0x7D, 0x52, 0x97, 0x62, 0x9F,
  33781. 0xCF, 0x32, 0x19, 0x5F, 0xE6, 0x32, 0xFB, 0x8E,
  33782. 0x39, 0x24, 0xB4, 0xEB, 0xE9, 0x17, 0x9E, 0x47,
  33783. 0x69, 0x4D, 0x92, 0x82, 0x96, 0x88, 0x38, 0x11,
  33784. 0xCE, 0xD6, 0xBF, 0x18, 0xE3, 0x51, 0x40, 0x81,
  33785. 0x11, 0xA0, 0x74, 0xDA, 0x0D, 0x5E, 0xEC, 0xD8,
  33786. 0x5D, 0x33, 0x22, 0x1E, 0xB9, 0x5D, 0xBF, 0x79,
  33787. 0xB0, 0xA1, 0xEF, 0xD1, 0x2D, 0xA0, 0x5F, 0xA1,
  33788. 0xC7, 0x6E, 0xD5, 0x08, 0xB8, 0xD0, 0xC1, 0x95,
  33789. 0x51, 0x9B, 0x07, 0xC3, 0x4A, 0x0A, 0xB5, 0xA1,
  33790. 0x28, 0xFE, 0x95, 0x95, 0x0A, 0xCF, 0x83, 0xA8,
  33791. 0xEB, 0x8F, 0xFB, 0x18, 0xD5, 0xBD, 0x69, 0x50,
  33792. 0xF1, 0xDF, 0x06, 0xFA, 0x9A, 0x65, 0x47, 0xBB,
  33793. 0x56, 0xE9, 0xCB, 0x8F, 0x69, 0x5F, 0xE0, 0xAD,
  33794. 0x19, 0x3A, 0x70, 0xE5, 0x66, 0x42, 0xD7, 0x1C,
  33795. 0x0C, 0xB4, 0x03, 0x89, 0x7D, 0x47, 0x4D, 0x29,
  33796. 0x67, 0x8C, 0x41, 0x73, 0xAB, 0x7D, 0xFD, 0x69,
  33797. 0x15, 0xAD, 0xE3, 0xB7, 0xF8, 0x98, 0x3B, 0xCA,
  33798. 0x8F, 0x27, 0x37, 0x7B, 0x72, 0x2C, 0x5F, 0x23,
  33799. 0x73, 0x15, 0xE2, 0xB6, 0xBD, 0xDE, 0x84, 0xF8,
  33800. 0x7E, 0x22, 0xB9, 0xFD, 0xD3, 0x4D, 0x62, 0x80,
  33801. 0xBA, 0xC5, 0x57, 0x29, 0x30, 0x1B, 0x06, 0x4D,
  33802. 0x20, 0xB1, 0x53, 0x86, 0xCB, 0x6A, 0x4A, 0xE3,
  33803. 0xC1, 0xA9, 0x88, 0xCF, 0xEB, 0x15, 0x2F, 0xA8,
  33804. 0xA8, 0x6F, 0xFC, 0x2A, 0xA8, 0x0E, 0xD9, 0xFA,
  33805. 0xEA, 0xD7, 0x3B, 0xCE, 0xF8, 0x5B, 0xD8, 0x92,
  33806. 0x22, 0x6A, 0x1A, 0x8E, 0x5E, 0x91, 0x37, 0x2C,
  33807. 0x21, 0x05, 0xC4, 0xAC, 0xF7, 0x62, 0x83, 0xBA,
  33808. 0x55, 0xD5, 0x2C, 0xCE, 0xA1, 0x19, 0x93, 0x0E,
  33809. 0xDE, 0xB6, 0xB8, 0x78, 0x0F, 0xBF, 0x4C, 0xA4,
  33810. 0x66, 0xAD, 0x97, 0x2F, 0xEE, 0x34, 0xE9, 0xA2,
  33811. 0xB6, 0x1D, 0x3C, 0x60, 0xFB, 0xB8, 0x7F, 0xF8,
  33812. 0xFD, 0x34, 0x8C, 0xC5, 0xC7, 0x38, 0x72, 0x74,
  33813. 0x19, 0xA9, 0xCF, 0x54, 0x49, 0x5B, 0xBA, 0x70,
  33814. 0x12, 0xC1, 0x61, 0xDC, 0x32, 0x61, 0x49, 0x66,
  33815. 0xF3, 0x57, 0xAA, 0x0F, 0xE6, 0x44, 0x9E, 0x8A,
  33816. 0x19, 0x9C, 0x6B, 0x63, 0x2C, 0x14, 0x1E, 0xDD,
  33817. 0x00, 0x27, 0xE3, 0x95, 0xE3, 0xE7, 0xD9, 0xFF,
  33818. 0x30, 0x2D, 0x14, 0x19, 0x4F, 0x49, 0x20, 0x0B,
  33819. 0x58, 0x2A, 0x23, 0x1C, 0xE2, 0xAD, 0x6B, 0x9C,
  33820. 0x7B, 0xB6, 0x20, 0x63, 0x08, 0x24, 0x55, 0x04,
  33821. 0x58, 0x1F, 0x0E, 0xBE, 0x2A, 0x6F, 0x79, 0x90,
  33822. 0x9E, 0x15, 0x8F, 0x4B, 0xDB, 0xE2, 0xBE, 0xBC,
  33823. 0x28, 0xB1, 0xC8, 0xFE, 0x00, 0x6D, 0x71, 0xCC,
  33824. 0x91, 0x6A, 0xCC, 0xF8, 0x12, 0x8B, 0xEC, 0xF3,
  33825. 0x46, 0x53, 0xB1, 0x7F, 0xB3, 0x79, 0xF0, 0xC7,
  33826. 0xD7, 0xA5, 0xCF, 0x2C, 0xC3, 0x09, 0x66, 0x82,
  33827. 0x53, 0x43, 0xFD, 0xAC, 0xDE, 0xD5, 0x85, 0xB3,
  33828. 0x79, 0x74, 0x55, 0xE8, 0xF6, 0xE5, 0xFB, 0xF0,
  33829. 0x63, 0x0C, 0x36, 0x63, 0x65, 0x10, 0x43, 0xC9,
  33830. 0x60, 0x99, 0xD6, 0x0C, 0xB9, 0x66, 0x1C, 0xA9,
  33831. 0x97, 0x4D, 0xDB, 0xA8, 0x13, 0x9E, 0xAE, 0xCA,
  33832. 0x7A, 0x5F, 0xE3, 0x24, 0xA0, 0xEE, 0x8A, 0x9D,
  33833. 0x7F, 0x03, 0x53, 0x21, 0x6B, 0xAF, 0x3D, 0xF9,
  33834. 0x38, 0xF3, 0x7A, 0x1D, 0xDA, 0xE2, 0xEF, 0xBA,
  33835. 0x86, 0x21, 0x85, 0x1F, 0x36, 0x08, 0x0B, 0xDA,
  33836. 0x37, 0x5A, 0x0A, 0xD7, 0x55, 0x41, 0xD5, 0x84,
  33837. 0x1B, 0x36, 0xA2, 0x50, 0x65, 0xD7, 0xF3, 0xA3,
  33838. 0xEB, 0xE1, 0xDE, 0x0F, 0x85, 0xAA, 0xF6, 0x2F,
  33839. 0xAB, 0xBB, 0xC8, 0xF1, 0x2A, 0xD1, 0x0A, 0x9B,
  33840. 0xE4, 0x7B, 0xBC, 0x4D, 0x42, 0xD8, 0xA3, 0x4C,
  33841. 0x07, 0x6A, 0x60, 0x3E, 0xE2, 0xDA, 0xE7, 0x00,
  33842. 0xDF, 0x27, 0x94, 0xEF, 0x90, 0x99, 0x88, 0x2C,
  33843. 0xCF, 0xAA, 0xE1, 0x71, 0x2D, 0xFD, 0x00, 0x9C,
  33844. 0x55, 0xBF, 0xC4, 0x7A, 0x55, 0xE9, 0xE0, 0xB4,
  33845. 0x7F, 0x3D, 0xE9, 0xB0, 0x01, 0xA7, 0x27, 0x23,
  33846. 0x27, 0x58, 0x31, 0x0E, 0x8E, 0x80, 0xD8, 0xEB,
  33847. 0x64, 0xA0, 0xC3, 0xC9, 0xEA, 0x69, 0x9C, 0x74,
  33848. 0x5E, 0xAF, 0xD5, 0xEF, 0x5C, 0x4E, 0x40, 0x71,
  33849. 0xD6, 0x57, 0x77, 0xE2, 0xAF, 0x0E, 0x1D, 0xB8,
  33850. 0x5A, 0x91, 0x20, 0x4C, 0x33, 0x4D, 0xD8, 0x4F,
  33851. 0x98, 0xE0, 0x86, 0x1D, 0x02, 0xA0, 0xDA, 0x06,
  33852. 0x17, 0xC4, 0x5D, 0x2E, 0x49, 0x31, 0xE6, 0xE4,
  33853. 0xDC, 0x18, 0x23, 0x26, 0xF3, 0x61, 0xF5, 0x8D,
  33854. 0x26, 0x2C, 0x18, 0x4C, 0xDF, 0x71, 0x90, 0x24,
  33855. 0x96, 0xD3, 0xD4, 0x1A, 0x6F, 0x08, 0xAB, 0x29,
  33856. 0x7D, 0xFF, 0x4E, 0x27, 0x6D, 0x39, 0x83, 0x17,
  33857. 0x90, 0xA4, 0x07, 0x8A, 0xDE, 0x79, 0x53, 0xF6,
  33858. 0x99, 0x2E, 0xA6, 0x39, 0x47, 0xC3, 0xBE, 0x12,
  33859. 0xC7, 0xA5, 0x7E, 0xA2, 0x19, 0x57, 0x04, 0x45,
  33860. 0xBE, 0x44, 0x62, 0x92, 0xCA, 0x56, 0xE1, 0xF0,
  33861. 0x45, 0x3B, 0xA4, 0xF8, 0xF5, 0xCD, 0xC7, 0xD2,
  33862. 0xB2, 0x46, 0x57, 0x51, 0x0B, 0x06, 0xDA, 0x54,
  33863. 0x03, 0x9E, 0x52, 0xA2, 0x78, 0x69, 0x25, 0x2E,
  33864. 0x75, 0x83, 0x25, 0x3F, 0xA3, 0x62, 0x27, 0xB9,
  33865. 0xA6, 0x59, 0x7A, 0xB1, 0xB6, 0xE9, 0xC1, 0xDD,
  33866. 0x2F, 0x22, 0x2D, 0x3B, 0xA3, 0x22, 0xD6, 0x11,
  33867. 0x7B, 0x08, 0x27, 0x92, 0x83, 0x7A, 0x5D, 0x0D,
  33868. 0x6B, 0x9D, 0x5B, 0xEB, 0xE9, 0xC0, 0x88, 0xDE,
  33869. 0x44, 0x55, 0xBA, 0x69, 0xC1, 0x7A, 0x4D, 0xE6,
  33870. 0x35, 0x67, 0x6F, 0x99, 0x9B, 0x07, 0xD8, 0x04,
  33871. 0xAA, 0xEA, 0x7D, 0xFF, 0x8E, 0xB8, 0xAA, 0x4C,
  33872. 0x79, 0xE2, 0x88, 0xA8, 0x1D, 0xE8, 0xA6, 0x77,
  33873. 0xCA, 0x06, 0xC0, 0xDF, 0x0E, 0x2B, 0xCB, 0xFF,
  33874. 0x9F, 0x64, 0x67, 0x11, 0xF1, 0xB9, 0x38, 0x83,
  33875. 0x19, 0x05, 0x30, 0x9B, 0x01, 0x11, 0x55, 0x03,
  33876. 0xAD, 0x44, 0x7D, 0x3C, 0x07, 0xEF, 0x88, 0x19,
  33877. 0x92, 0xC0, 0xFE, 0xE1, 0xAB, 0xDB, 0x24, 0x18,
  33878. 0x17, 0xD0, 0x03, 0x5C, 0x91, 0xD4, 0xA6, 0x2A,
  33879. 0xF1, 0xE9, 0x72, 0x62, 0x58, 0x22, 0x7D, 0x55,
  33880. 0x15, 0xE2, 0xA1, 0x70, 0x14, 0x5E, 0x34, 0xB9,
  33881. 0x5A, 0xB7, 0x5D, 0x3F, 0xB8, 0xB5, 0x45, 0x44,
  33882. 0xD2, 0x50, 0xD1, 0xC6, 0x7E, 0xE7, 0x3D, 0xF4,
  33883. 0xD3, 0xEC, 0xFB, 0x97, 0x32, 0x11, 0x72, 0x51,
  33884. 0xB7, 0x4A, 0xC8, 0x38, 0x96, 0xFC, 0x6F, 0x69,
  33885. 0xC2, 0xD5, 0xD3, 0x28, 0xE9, 0x63, 0x14, 0x14,
  33886. 0xFE, 0xB1, 0xA4, 0x02, 0x80, 0x65, 0x73, 0xD3,
  33887. 0x57, 0x07, 0x95, 0x21, 0x40, 0x00, 0x77, 0xA7,
  33888. 0x6D, 0x44, 0x2B, 0x0D, 0x77, 0x07, 0x92, 0x64,
  33889. 0xD4, 0x3A, 0xE2, 0x7F, 0xF2, 0x1C, 0x14, 0x08,
  33890. 0x60, 0x74, 0x8F, 0xFC, 0x0B, 0xE8, 0xEC, 0xA9,
  33891. 0xB7, 0x97, 0xA7, 0x85, 0x8A, 0xEF, 0xD7, 0x7E,
  33892. 0xD5, 0x15, 0xF7, 0x45, 0x8D, 0x9C, 0xBF, 0x23,
  33893. 0xEB, 0x8C, 0x4D, 0xD2, 0x28, 0x7E, 0x0A, 0x61,
  33894. 0x2E, 0xBA, 0xBE, 0x89, 0x1D, 0x64, 0x45, 0x22,
  33895. 0x70, 0x9D, 0x48, 0xEB, 0x2F, 0x96, 0xF1, 0xA7,
  33896. 0xDE, 0xD3, 0x28, 0x4C, 0xC9, 0xFB, 0xF2, 0x9C,
  33897. 0x5B, 0xFC, 0xBE, 0xBE, 0xF4, 0x38, 0xC9, 0x43,
  33898. 0xC3, 0x66, 0x53, 0xA9, 0x06, 0xE5, 0x71, 0x16,
  33899. 0xA4, 0xBB, 0x3B, 0x50, 0x53, 0xCF, 0xF4, 0x1F,
  33900. 0xD6, 0x00, 0x07, 0x46, 0xFB, 0x97, 0x0B, 0xF9,
  33901. 0x3D, 0xF4, 0xC6, 0x60, 0xD0, 0x37, 0x70, 0xC0,
  33902. 0x2D, 0xD1, 0x9F, 0xA5, 0x78, 0xF3, 0x1F, 0x03,
  33903. 0x81, 0xB1, 0x93, 0xBA, 0xE5, 0x82, 0xE6, 0xD1,
  33904. 0x66, 0x93, 0x83, 0x5B, 0xB9, 0xAD, 0xD9, 0x01,
  33905. 0xA5, 0xB6, 0x5C, 0x69, 0x82, 0xD7, 0x2F, 0x35,
  33906. 0x35, 0x98, 0xEE, 0xE9, 0xA0, 0x74, 0xC1, 0x91,
  33907. 0x44, 0x0A, 0x04, 0xCD, 0x97, 0xBE, 0x6B, 0x60,
  33908. 0x90, 0x9A, 0x48, 0x7B, 0x83, 0xA2, 0x28, 0x97,
  33909. 0xB5, 0xBA, 0xB1, 0x4D, 0x35, 0x8B, 0x34, 0x0A,
  33910. 0xA1, 0xCB, 0xA5, 0xC2, 0xA4, 0x6A, 0x36, 0xB3,
  33911. 0x12, 0x46, 0x59, 0xDB, 0x63, 0xE5, 0xF9, 0xF1,
  33912. 0x7F, 0xAD, 0x42, 0xF4, 0x24, 0xF0, 0x02, 0x3D,
  33913. 0x1E, 0x6C, 0xD5, 0xB3, 0x06, 0x8F, 0x1F, 0x59,
  33914. 0x79, 0xCC, 0xF9, 0x5B, 0x4F, 0x8B, 0xD6, 0x03,
  33915. 0xC7, 0x53, 0xE6, 0xCE, 0xBB, 0xD8, 0x52, 0x89,
  33916. 0x70, 0x5D, 0x98, 0x86, 0xA5, 0x9E, 0x44, 0xA9,
  33917. 0xC8, 0x17, 0xA2, 0x6F, 0x43, 0x2D, 0x8D, 0xA7,
  33918. 0xDE, 0x3E, 0xFA, 0xE7, 0x98, 0x7B, 0xB5, 0xBE,
  33919. 0x7B, 0x10, 0xB8, 0xB8, 0xA5, 0x3D, 0x3E, 0xCD,
  33920. 0x94, 0x19, 0x5E, 0x06, 0x51, 0xB8, 0x58, 0x1E,
  33921. 0x0E, 0xCF, 0xFE, 0xE5, 0xED, 0x84, 0xB5, 0xF5,
  33922. 0x0F, 0x34, 0x32, 0xAC, 0x0A, 0x7F, 0x03, 0xF0,
  33923. 0xF8, 0xFC, 0x69, 0xA0, 0x26, 0x0D, 0x2E, 0xFA,
  33924. 0x62, 0x49, 0x5C, 0xC4, 0xE5, 0xF6, 0x8B, 0xC5,
  33925. 0x26, 0x21, 0x23, 0x3B, 0xBD, 0x9A, 0x23, 0x95,
  33926. 0x69, 0xA7, 0x48, 0x94, 0x30, 0x1E, 0xC3, 0x82,
  33927. 0xB6, 0x75, 0x30, 0xA6, 0xF3, 0x1E, 0xBB, 0xBC,
  33928. 0xF7, 0x21, 0x27, 0x12, 0x2C, 0x51, 0x50, 0x55,
  33929. 0x87, 0x0D, 0xF1, 0xCC, 0x6C, 0xFF, 0xEA, 0x7E,
  33930. 0x2C, 0xDA, 0x8B, 0x9B, 0x20, 0xF4, 0x75, 0xFB,
  33931. 0xC2, 0x3F, 0xBE, 0x09, 0xA6, 0xC9, 0x26, 0xE7,
  33932. 0xB5, 0xC7, 0xE6, 0xB9, 0x35, 0x8C, 0xAF, 0xFA,
  33933. 0xC0, 0x8D, 0x43, 0x33, 0x25, 0xBA, 0xAA, 0xDC,
  33934. 0xCF, 0xBC, 0xE4, 0xC4, 0xC6, 0x26, 0x4A, 0x0D,
  33935. 0x9D, 0xCC, 0x2A, 0xE0, 0x5B, 0x1E, 0xC9, 0x78,
  33936. 0xF8, 0xA2, 0xB5, 0x46, 0xE5, 0x49, 0xB8, 0x4C,
  33937. 0xC2, 0x22, 0x40, 0xCE, 0x97, 0x9A, 0x95, 0x40,
  33938. 0xF7, 0xD6, 0x52, 0x54, 0x3B, 0xBB, 0x42, 0xC5,
  33939. 0x6F, 0x00, 0x7F, 0x83, 0xDD, 0x88, 0x71, 0xF7,
  33940. 0xD4, 0x1B, 0x3D, 0x81, 0xC4, 0xB1, 0x49, 0x9B,
  33941. 0xF3, 0x68, 0x15, 0xC5, 0x15, 0x97, 0x0F, 0xC5,
  33942. 0x43, 0xDD, 0x07, 0xBE, 0x98, 0x43, 0x2C, 0xB3,
  33943. 0xEF, 0x08, 0xCA, 0xDC, 0x9C, 0x27, 0x58, 0xFE,
  33944. 0x49, 0xE9, 0x77, 0xD9, 0x1C, 0x62, 0xA4, 0xA2,
  33945. 0xF9, 0x78, 0xCC, 0xB3, 0x21, 0x06, 0x10, 0xDE,
  33946. 0x5A, 0x52, 0xA3, 0x67, 0xBD, 0x5E, 0xBC, 0x9B,
  33947. 0x4E, 0x40, 0x87, 0x93, 0xCF, 0x0E, 0x27, 0x0E,
  33948. 0xE3, 0x11, 0x4B, 0xB3, 0xE0, 0xCE, 0x24, 0xB6,
  33949. 0x0A, 0x53, 0x03, 0xF8, 0x01, 0x6A, 0x7E, 0xFE,
  33950. 0xC8, 0x66, 0x9F, 0x29, 0xF3, 0x45, 0x94, 0xD6,
  33951. 0x0E, 0x30, 0xB5, 0x61, 0xA9, 0xEC, 0x8F, 0x71,
  33952. 0xF7, 0x36, 0xD6, 0x43, 0x4B, 0x0C, 0xCD, 0x45,
  33953. 0xBB, 0xA4, 0xBD, 0xE9, 0xA9, 0xC3, 0xC1, 0x95,
  33954. 0x1E, 0xF9, 0x42, 0x07, 0x18, 0xEA, 0xF5, 0x0B,
  33955. 0x27, 0xB6, 0xDE, 0xEF, 0x67, 0x33, 0x83, 0x0D,
  33956. 0xD9, 0x5E, 0x3A, 0x93, 0xD2, 0xD0, 0xDB, 0xB9,
  33957. 0x98, 0xF0, 0x25, 0x21, 0xF3, 0xDF, 0x0B, 0x1E
  33958. };
  33959. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  33960. #ifndef WOLFSSL_NO_ML_DSA_65
  33961. static const byte seed_65_draft[] = {
  33962. 0x41, 0xAF, 0x98, 0x7B, 0x02, 0x6E, 0x47, 0x5F,
  33963. 0x37, 0x91, 0x7F, 0x2A, 0x6A, 0x9A, 0x87, 0xE7,
  33964. 0x51, 0xAD, 0xF9, 0x5B, 0x92, 0x7F, 0x2D, 0xCE,
  33965. 0xF0, 0xD4, 0xF3, 0xDA, 0x8F, 0x8C, 0x86, 0x6B
  33966. };
  33967. static const byte pk_65_draft[] = {
  33968. 0xDC, 0x38, 0xE5, 0x5F, 0xDF, 0x2E, 0x9D, 0xD4,
  33969. 0x34, 0x5C, 0xAE, 0x1A, 0x7D, 0xF4, 0x2E, 0x2E,
  33970. 0xBC, 0x58, 0x57, 0x80, 0x55, 0x02, 0xE4, 0x3F,
  33971. 0xA5, 0x19, 0x41, 0xE4, 0x44, 0x58, 0x66, 0x41,
  33972. 0x39, 0x5D, 0xF9, 0x20, 0x6C, 0x36, 0x0D, 0x4F,
  33973. 0x83, 0x43, 0xBE, 0x86, 0xEF, 0x6C, 0x43, 0xD0,
  33974. 0x3E, 0xD0, 0x63, 0x0A, 0x5B, 0x92, 0x8D, 0x31,
  33975. 0x19, 0x1D, 0xA9, 0x51, 0x61, 0x48, 0xE6, 0x26,
  33976. 0x50, 0x07, 0x54, 0x9B, 0xB0, 0xB7, 0x62, 0x54,
  33977. 0xDB, 0x80, 0x4E, 0x48, 0x7F, 0x48, 0xC5, 0x11,
  33978. 0x91, 0xFC, 0xA9, 0x26, 0x25, 0x08, 0xA5, 0x99,
  33979. 0xA0, 0x3C, 0xB9, 0x0C, 0xCF, 0x6C, 0xCD, 0x83,
  33980. 0x9A, 0x38, 0x6D, 0x22, 0xDE, 0x0A, 0xC3, 0x8F,
  33981. 0xF7, 0xD0, 0x57, 0x40, 0x53, 0xE9, 0xE9, 0x4E,
  33982. 0x73, 0xFA, 0x58, 0x40, 0x9F, 0x6D, 0x8A, 0xD3,
  33983. 0x6F, 0x86, 0x84, 0x4D, 0x18, 0xD7, 0x4C, 0x76,
  33984. 0x39, 0x57, 0x9E, 0xC0, 0xC7, 0xE4, 0xEE, 0x54,
  33985. 0xF4, 0xAD, 0x10, 0xC5, 0x69, 0x59, 0xE0, 0xBC,
  33986. 0x9B, 0xF4, 0x20, 0x8F, 0xBA, 0x0A, 0x94, 0x10,
  33987. 0x55, 0x07, 0x7E, 0xD1, 0xF9, 0x20, 0xCC, 0x2F,
  33988. 0xA9, 0xAE, 0x9D, 0xF5, 0xE4, 0x29, 0x40, 0x7E,
  33989. 0x44, 0xA4, 0xDF, 0xB2, 0xE9, 0x25, 0xE0, 0xBA,
  33990. 0x8D, 0x6C, 0x33, 0x88, 0x9C, 0xEE, 0x27, 0xDB,
  33991. 0xC7, 0x0A, 0x6E, 0x5A, 0x08, 0x92, 0x9B, 0x53,
  33992. 0xF8, 0xFD, 0xF9, 0x5B, 0xEB, 0x03, 0x8E, 0x45,
  33993. 0xCB, 0x91, 0x19, 0x4E, 0x6B, 0x1E, 0xA0, 0xA4,
  33994. 0xF0, 0x43, 0xC9, 0x8F, 0xDF, 0x93, 0x5E, 0x86,
  33995. 0xB0, 0x09, 0xD3, 0x47, 0x38, 0x7C, 0x8E, 0x78,
  33996. 0x85, 0x71, 0x3D, 0x07, 0x2E, 0x2E, 0x12, 0x6F,
  33997. 0x06, 0x97, 0x0E, 0x54, 0xAD, 0x71, 0x09, 0xEF,
  33998. 0xA5, 0x55, 0x0A, 0x39, 0x86, 0xE6, 0x17, 0x17,
  33999. 0x70, 0x9A, 0xA7, 0xA7, 0x1B, 0xCE, 0x78, 0x06,
  34000. 0x2C, 0x61, 0x1A, 0xB9, 0x48, 0x22, 0x41, 0x45,
  34001. 0x15, 0xEB, 0x10, 0x3C, 0x6E, 0x24, 0x37, 0xA4,
  34002. 0xB5, 0xE8, 0x82, 0x4D, 0x6D, 0xCC, 0x44, 0xC6,
  34003. 0xB0, 0x5D, 0xBE, 0x46, 0xDA, 0x5F, 0x00, 0x36,
  34004. 0x5B, 0xBD, 0x87, 0x65, 0x3A, 0x96, 0x21, 0x58,
  34005. 0x45, 0x65, 0xDB, 0xD8, 0x77, 0x76, 0x7B, 0x25,
  34006. 0xC3, 0x78, 0x6E, 0xD9, 0x14, 0xA7, 0x19, 0x69,
  34007. 0x4F, 0xBB, 0x1B, 0xDB, 0x37, 0xCE, 0xAF, 0x8C,
  34008. 0x88, 0x2E, 0x9E, 0x30, 0xF6, 0xAE, 0x43, 0xCC,
  34009. 0x59, 0x0F, 0x67, 0x8A, 0xCB, 0x4F, 0x08, 0x20,
  34010. 0x6D, 0x99, 0xD7, 0xA9, 0xDE, 0xE5, 0xE5, 0xB3,
  34011. 0xFF, 0xAA, 0x45, 0x3C, 0xF1, 0xE3, 0x02, 0x7D,
  34012. 0x2F, 0xEE, 0x69, 0x04, 0x81, 0x73, 0x01, 0x37,
  34013. 0x51, 0x68, 0xC8, 0x0B, 0x51, 0xFD, 0x05, 0xB4,
  34014. 0x05, 0xBB, 0xA1, 0xDB, 0x1D, 0xF6, 0x5F, 0x70,
  34015. 0xD3, 0x0A, 0x37, 0x4B, 0x9C, 0xC4, 0x45, 0x30,
  34016. 0x11, 0x36, 0xE2, 0x48, 0x9F, 0xC4, 0x2E, 0x4E,
  34017. 0x0C, 0x0C, 0xA1, 0x04, 0x41, 0x75, 0x95, 0xAA,
  34018. 0xED, 0xAC, 0xD4, 0xB2, 0xE7, 0x85, 0x7E, 0xE1,
  34019. 0xA6, 0xFE, 0x2A, 0x09, 0x19, 0x09, 0x3D, 0x7C,
  34020. 0x20, 0x1E, 0x98, 0x3D, 0x6E, 0x02, 0xC1, 0xCA,
  34021. 0xBB, 0x24, 0x82, 0x9F, 0x45, 0x1D, 0x26, 0x99,
  34022. 0xAE, 0x02, 0x82, 0xF9, 0x86, 0x3B, 0x67, 0x8C,
  34023. 0xBD, 0xFE, 0xF1, 0xD0, 0xB6, 0xB8, 0xAB, 0x00,
  34024. 0x0F, 0xEC, 0x30, 0xDC, 0x27, 0x58, 0xE2, 0x29,
  34025. 0x18, 0x05, 0x5A, 0x66, 0xA5, 0x88, 0x39, 0x8E,
  34026. 0x49, 0x5B, 0xB9, 0x52, 0x43, 0x84, 0xDC, 0xA9,
  34027. 0x50, 0x2B, 0x83, 0x3C, 0x84, 0x81, 0x37, 0x52,
  34028. 0x30, 0x79, 0xBD, 0x04, 0xB8, 0xDD, 0x47, 0xC1,
  34029. 0x02, 0x2E, 0xEC, 0x24, 0xD0, 0x56, 0x23, 0xE1,
  34030. 0x92, 0xD0, 0x65, 0x7F, 0xC7, 0xC2, 0xF7, 0x60,
  34031. 0x73, 0xB8, 0xAF, 0x0A, 0xF4, 0xEF, 0xFC, 0x1B,
  34032. 0xC2, 0xB9, 0x76, 0x87, 0x8A, 0xA6, 0xC2, 0x3F,
  34033. 0xD3, 0x9F, 0x1F, 0x2D, 0x94, 0xBC, 0x89, 0x4E,
  34034. 0x31, 0x8D, 0x28, 0xD0, 0x90, 0xB5, 0x5B, 0x60,
  34035. 0x30, 0xC6, 0x0B, 0x37, 0x63, 0x5D, 0xDC, 0xC6,
  34036. 0xE0, 0x1A, 0xBA, 0x6B, 0x23, 0xCD, 0x2E, 0x09,
  34037. 0x2D, 0x6A, 0x7E, 0x0C, 0xD9, 0x4F, 0xB1, 0xE2,
  34038. 0x89, 0x67, 0xE7, 0xB1, 0x54, 0x08, 0xB2, 0xFA,
  34039. 0x83, 0x43, 0x7C, 0x77, 0x06, 0xED, 0xE2, 0x29,
  34040. 0x53, 0xB7, 0x09, 0xC4, 0x1B, 0x81, 0x55, 0x12,
  34041. 0x41, 0x8E, 0x8B, 0x03, 0x36, 0xEE, 0x45, 0x70,
  34042. 0x57, 0xA8, 0x73, 0xEF, 0x70, 0x7B, 0x1F, 0x63,
  34043. 0xB0, 0xE8, 0x00, 0xBD, 0x1E, 0xE6, 0xA9, 0x93,
  34044. 0x9D, 0x03, 0x19, 0x22, 0xDF, 0xE1, 0x01, 0xF2,
  34045. 0xA9, 0x6B, 0x90, 0x5C, 0xD2, 0xC1, 0xAC, 0x9F,
  34046. 0xB2, 0x21, 0x1C, 0x2D, 0xC6, 0x80, 0x9A, 0xB5,
  34047. 0x1E, 0x46, 0x95, 0x6C, 0xCE, 0x47, 0x3E, 0x67,
  34048. 0xCD, 0xD6, 0xC9, 0xB9, 0x81, 0x74, 0x7F, 0x17,
  34049. 0xA3, 0xF7, 0x48, 0x99, 0xF3, 0x36, 0x84, 0xF3,
  34050. 0x16, 0x41, 0x55, 0x5F, 0xA7, 0xBF, 0x4B, 0x69,
  34051. 0x8D, 0xA3, 0x3D, 0x1E, 0xEA, 0xF5, 0x1E, 0xC6,
  34052. 0xB8, 0x1C, 0xD6, 0x89, 0x45, 0x68, 0xFA, 0xE7,
  34053. 0xCA, 0x86, 0xE4, 0xB1, 0xC9, 0x9C, 0xB2, 0xAB,
  34054. 0x89, 0x03, 0xE7, 0x19, 0x7B, 0xA9, 0xF2, 0x6B,
  34055. 0x4A, 0x43, 0x1D, 0x90, 0xAF, 0xA4, 0xE3, 0xBC,
  34056. 0xEF, 0xD4, 0x37, 0xC5, 0x55, 0x5C, 0x9E, 0x14,
  34057. 0xC6, 0x18, 0xDD, 0x45, 0x3F, 0x80, 0x49, 0x1C,
  34058. 0x93, 0xFF, 0xBD, 0xDD, 0x75, 0x54, 0x0B, 0xD1,
  34059. 0xA9, 0xF6, 0xBC, 0x89, 0x98, 0x7D, 0x6F, 0x03,
  34060. 0x7B, 0x06, 0xD5, 0x40, 0x7D, 0x85, 0x48, 0x2E,
  34061. 0x11, 0x3E, 0xF0, 0x47, 0x77, 0xD0, 0xBA, 0x03,
  34062. 0x33, 0x58, 0xC4, 0x8F, 0x76, 0xF8, 0x72, 0x47,
  34063. 0x04, 0x21, 0x5E, 0x85, 0x5A, 0x0F, 0x35, 0x77,
  34064. 0xFB, 0x96, 0x29, 0x81, 0x2D, 0x55, 0x6E, 0x53,
  34065. 0xC6, 0x13, 0x1E, 0xFA, 0x4D, 0xCE, 0xA9, 0x36,
  34066. 0x1D, 0x8F, 0xAB, 0xAC, 0x13, 0x19, 0x94, 0xFC,
  34067. 0x4B, 0xCD, 0x36, 0x4C, 0x6E, 0x21, 0xAE, 0xF1,
  34068. 0x13, 0xA4, 0xF7, 0x64, 0x8E, 0xE1, 0xAF, 0x50,
  34069. 0x6A, 0x63, 0x0E, 0xCA, 0x2F, 0xE9, 0x0C, 0x8A,
  34070. 0xE7, 0xF2, 0xE3, 0x68, 0x03, 0xE0, 0x40, 0x1C,
  34071. 0x64, 0xAB, 0xC3, 0xEC, 0xC0, 0x92, 0xE9, 0x57,
  34072. 0x3E, 0x66, 0x72, 0x36, 0x39, 0x22, 0x4E, 0xCD,
  34073. 0x13, 0x08, 0xBA, 0xF8, 0x2B, 0xA1, 0xF2, 0x69,
  34074. 0x44, 0x7E, 0x90, 0x5C, 0xC8, 0xEC, 0xB6, 0xBE,
  34075. 0x8C, 0x30, 0xE0, 0x69, 0xB7, 0x97, 0xA1, 0x1C,
  34076. 0x18, 0xE5, 0x54, 0x62, 0xC3, 0x29, 0x99, 0x21,
  34077. 0x16, 0xD9, 0x78, 0x1C, 0x4C, 0x9C, 0x88, 0x4C,
  34078. 0xA5, 0xE1, 0x11, 0x66, 0x5B, 0x6E, 0x71, 0xE7,
  34079. 0xE2, 0xE7, 0xE4, 0x02, 0xDD, 0x1A, 0x8D, 0x0C,
  34080. 0xF5, 0x32, 0xFD, 0x41, 0x28, 0x35, 0x75, 0xD0,
  34081. 0x0C, 0x5F, 0x06, 0x6A, 0x5A, 0x61, 0x49, 0x59,
  34082. 0xC1, 0x0C, 0xD4, 0x9E, 0xD6, 0x29, 0xE2, 0x37,
  34083. 0xDF, 0x2B, 0x3D, 0xE8, 0x98, 0xB9, 0xDF, 0x8E,
  34084. 0xA0, 0xC4, 0xE2, 0xFC, 0x45, 0x70, 0xE8, 0x1B,
  34085. 0xF4, 0xFA, 0xC5, 0xE6, 0xA7, 0xCF, 0x4F, 0xA2,
  34086. 0xDA, 0x3D, 0x90, 0x49, 0x24, 0x8F, 0x61, 0x54,
  34087. 0xD5, 0x50, 0x8E, 0xE8, 0x0C, 0x14, 0xAD, 0x6F,
  34088. 0x65, 0x88, 0x3A, 0xF6, 0x92, 0xDB, 0x35, 0x5D,
  34089. 0xFF, 0x21, 0x20, 0xAC, 0x01, 0x16, 0x0B, 0xEC,
  34090. 0x84, 0x15, 0x3B, 0xA9, 0x93, 0x92, 0x75, 0xB3,
  34091. 0x73, 0xF1, 0x23, 0x69, 0x94, 0x10, 0xF5, 0xFE,
  34092. 0x20, 0xA8, 0xAF, 0x05, 0x87, 0x49, 0x4E, 0x9C,
  34093. 0xEB, 0x21, 0x0A, 0xCF, 0x0B, 0xA1, 0x65, 0x38,
  34094. 0xA6, 0x18, 0x4D, 0xF7, 0xD8, 0xC1, 0x2C, 0x14,
  34095. 0x4C, 0xD9, 0x40, 0xC2, 0xF7, 0xBF, 0xE3, 0x07,
  34096. 0x79, 0x55, 0xAE, 0xB9, 0xB6, 0x50, 0x06, 0x92,
  34097. 0x94, 0x8C, 0x6A, 0x0E, 0x22, 0x14, 0xE2, 0xCC,
  34098. 0x65, 0xBA, 0x0C, 0x4D, 0xB6, 0x5C, 0x4A, 0xE9,
  34099. 0x0A, 0x08, 0x0C, 0xF9, 0x26, 0xA2, 0x51, 0x85,
  34100. 0x36, 0xE2, 0xC1, 0xF1, 0x0A, 0x66, 0x51, 0x66,
  34101. 0x7A, 0x98, 0x9B, 0x2C, 0x30, 0x1A, 0x0D, 0x49,
  34102. 0x3C, 0x1E, 0xEC, 0x63, 0x53, 0x5E, 0xD9, 0xDD,
  34103. 0x84, 0x69, 0xCD, 0x7E, 0x79, 0x58, 0x3D, 0x6E,
  34104. 0xD9, 0x98, 0x58, 0xD8, 0x0A, 0x48, 0xB5, 0x13,
  34105. 0x3F, 0x72, 0x4C, 0x11, 0x90, 0x15, 0x12, 0x74,
  34106. 0xFF, 0x5C, 0x0D, 0xC6, 0x20, 0x8C, 0xC1, 0x99,
  34107. 0xCA, 0x8E, 0xFC, 0xA2, 0xE8, 0xB8, 0xEE, 0xAA,
  34108. 0x27, 0xC2, 0x97, 0x8D, 0xFA, 0xBE, 0xE0, 0x43,
  34109. 0x99, 0xB6, 0x90, 0x60, 0x00, 0x7C, 0x33, 0xD4,
  34110. 0x87, 0x71, 0x7B, 0x56, 0x6C, 0xAA, 0xE0, 0xAC,
  34111. 0x9D, 0x7E, 0x7E, 0xA3, 0xCF, 0xBB, 0xB3, 0xA0,
  34112. 0x5F, 0xD4, 0xC4, 0x3A, 0xA7, 0xB9, 0x0C, 0xCE,
  34113. 0xF3, 0x05, 0x09, 0x91, 0xA7, 0xE9, 0x11, 0x55,
  34114. 0x32, 0x45, 0xA6, 0x08, 0x0E, 0x10, 0x37, 0x91,
  34115. 0xF3, 0xBF, 0xED, 0x64, 0x26, 0xEB, 0x39, 0xC2,
  34116. 0x57, 0xAE, 0x64, 0x79, 0x33, 0x7C, 0x51, 0xB2,
  34117. 0xC8, 0x85, 0xE0, 0xF9, 0x6D, 0x10, 0x52, 0x9F,
  34118. 0x72, 0xF4, 0xD1, 0x5B, 0x54, 0x5B, 0x93, 0x28,
  34119. 0x36, 0xA8, 0xCD, 0xB3, 0x30, 0x5B, 0x7A, 0xB0,
  34120. 0xB6, 0xF0, 0xD8, 0xA0, 0xBA, 0x24, 0x59, 0x5F,
  34121. 0x43, 0x02, 0x01, 0x57, 0x91, 0x7B, 0x94, 0x07,
  34122. 0x63, 0x23, 0x12, 0x94, 0xFB, 0x9F, 0xF2, 0xC1,
  34123. 0xD6, 0x80, 0x8F, 0x4E, 0xA7, 0x9E, 0x11, 0xD8,
  34124. 0xB3, 0x08, 0xB6, 0x3B, 0x3B, 0xF2, 0xEE, 0x14,
  34125. 0xA5, 0xDB, 0xB0, 0xBB, 0x17, 0xA5, 0x96, 0x3C,
  34126. 0x2F, 0xB9, 0xE7, 0x4A, 0xD7, 0x52, 0x34, 0x98,
  34127. 0xCB, 0x0C, 0xEB, 0x42, 0x5B, 0x2D, 0x2D, 0x2B,
  34128. 0x0D, 0x94, 0x66, 0xD3, 0xAD, 0x08, 0x0A, 0x28,
  34129. 0xF6, 0x0E, 0xDA, 0xD4, 0x54, 0xFD, 0xC6, 0x48,
  34130. 0x08, 0xA1, 0x8D, 0xB0, 0x30, 0xFD, 0x18, 0xB1,
  34131. 0x50, 0xB1, 0xFD, 0xE0, 0x6E, 0x33, 0x25, 0x0D,
  34132. 0x90, 0xB1, 0xC1, 0xE7, 0x88, 0x74, 0x87, 0x05,
  34133. 0xE7, 0xBE, 0xBD, 0xAA, 0x8C, 0x6D, 0xC2, 0x3D,
  34134. 0x6F, 0x95, 0x84, 0xFA, 0x03, 0x74, 0x85, 0xE1,
  34135. 0xED, 0xE5, 0xF4, 0xE8, 0x26, 0x4A, 0x0B, 0x20,
  34136. 0x87, 0xB6, 0xE1, 0x10, 0x75, 0x6D, 0x9F, 0x95,
  34137. 0x39, 0x4C, 0x0F, 0x50, 0x1B, 0xA8, 0x69, 0x82,
  34138. 0xBB, 0xE2, 0xD6, 0x11, 0xD7, 0xBE, 0xFB, 0x4F,
  34139. 0x60, 0xD3, 0x16, 0xC6, 0x04, 0x3A, 0x5A, 0xF5,
  34140. 0x78, 0x9B, 0x0B, 0x21, 0xA1, 0x00, 0x96, 0xCD,
  34141. 0x63, 0x78, 0x1D, 0x2D, 0x4F, 0x6E, 0x50, 0xEE,
  34142. 0x62, 0x2D, 0x88, 0x62, 0x01, 0xF6, 0xB4, 0x17,
  34143. 0x4F, 0x8C, 0xAD, 0xCB, 0x4B, 0xF9, 0xF6, 0x9D,
  34144. 0xC7, 0xD8, 0xCC, 0xBF, 0x96, 0x1B, 0x1B, 0x79,
  34145. 0xF3, 0x25, 0x85, 0x23, 0x10, 0x63, 0x30, 0x8D,
  34146. 0xA8, 0x3A, 0x4B, 0x92, 0x1B, 0x88, 0x53, 0x24,
  34147. 0x2D, 0x29, 0xA5, 0x2E, 0x7A, 0xD5, 0x58, 0xEB,
  34148. 0x1B, 0x1C, 0xE6, 0xB8, 0x94, 0x0C, 0x58, 0x96,
  34149. 0x5B, 0xA0, 0x2C, 0xBF, 0xE2, 0x99, 0xA0, 0x1F,
  34150. 0x0C, 0xCC, 0xBD, 0x83, 0x72, 0x56, 0xBB, 0x13,
  34151. 0x61, 0x5A, 0xC2, 0x04, 0x27, 0x29, 0x1F, 0xD4,
  34152. 0xE4, 0x3D, 0x8A, 0x87, 0xE3, 0x81, 0x91, 0x07,
  34153. 0xD3, 0x9B, 0xBC, 0xA9, 0xB3, 0xBA, 0xF5, 0x8B,
  34154. 0x6A, 0xAD, 0xDE, 0xB0, 0x54, 0x3E, 0xFE, 0xCC,
  34155. 0xD3, 0xCB, 0x2C, 0x69, 0xF0, 0x58, 0xD7, 0xEF,
  34156. 0xA9, 0xC0, 0x15, 0x9B, 0x5A, 0xDF, 0x71, 0x25,
  34157. 0x38, 0x44, 0xEC, 0xA9, 0x18, 0x47, 0x41, 0xCE,
  34158. 0x3D, 0x53, 0x10, 0x12, 0xC3, 0x1B, 0x59, 0x9A,
  34159. 0x93, 0xA1, 0xEA, 0xBE, 0x3E, 0xBA, 0x74, 0xF6,
  34160. 0x2D, 0x40, 0x9D, 0xCB, 0x9E, 0xA1, 0xA5, 0x85,
  34161. 0xFF, 0xDC, 0xC5, 0x60, 0x6F, 0x61, 0xE8, 0x17,
  34162. 0x6C, 0x36, 0x9F, 0x7A, 0x48, 0x47, 0xDD, 0xF1,
  34163. 0xF4, 0x43, 0x21, 0xCB, 0xB3, 0x55, 0x86, 0xD0,
  34164. 0xE9, 0x46, 0x7D, 0xB5, 0x3D, 0x90, 0x34, 0x1E,
  34165. 0xBB, 0x40, 0xD3, 0x2A, 0xEB, 0xE6, 0x4C, 0x46,
  34166. 0x42, 0xA2, 0x8A, 0xBF, 0x90, 0xE7, 0x4B, 0x6D,
  34167. 0x5C, 0x94, 0x97, 0xD2, 0xF0, 0x97, 0x74, 0x4C,
  34168. 0x76, 0x03, 0xAC, 0x3D, 0xDE, 0x15, 0x96, 0x0C,
  34169. 0xEF, 0x18, 0x9D, 0xBD, 0x1A, 0x20, 0x35, 0x7E,
  34170. 0x2A, 0x70, 0x9D, 0xEA, 0x2E, 0x11, 0xDF, 0xF3,
  34171. 0x2F, 0xFE, 0x23, 0xA9, 0xB6, 0xCF, 0xB7, 0xB9,
  34172. 0x3F, 0x4F, 0x30, 0x6B, 0x3B, 0x0D, 0x3B, 0xED,
  34173. 0xCD, 0x77, 0xD4, 0xBF, 0xEE, 0xDD, 0xB6, 0x56,
  34174. 0x24, 0xD4, 0x29, 0x83, 0xDE, 0xDB, 0xC1, 0xFB,
  34175. 0x6A, 0xCE, 0x7F, 0x47, 0xD2, 0xC5, 0xF1, 0x78,
  34176. 0x5C, 0x2C, 0x5A, 0x28, 0x3E, 0x05, 0x50, 0x2E,
  34177. 0xD9, 0xAE, 0x9B, 0x95, 0x64, 0xC7, 0xD2, 0x7B,
  34178. 0xCB, 0xC5, 0x91, 0x80, 0xEB, 0x79, 0xC7, 0xCC,
  34179. 0xA8, 0x06, 0xC8, 0xF9, 0xDF, 0x2A, 0x49, 0x4A,
  34180. 0xF8, 0xFE, 0xBA, 0xA5, 0x85, 0x67, 0x1B, 0xDA,
  34181. 0x51, 0x3B, 0xC2, 0x04, 0xA6, 0xA3, 0xFF, 0x99,
  34182. 0x21, 0xE8, 0x17, 0x91, 0x33, 0x9B, 0x83, 0x75,
  34183. 0x20, 0x5E, 0x95, 0xBE, 0x49, 0xDF, 0x53, 0xFC,
  34184. 0x05, 0xA2, 0x3C, 0xAA, 0x5A, 0x22, 0x15, 0xA5,
  34185. 0x56, 0xE0, 0x51, 0x30, 0x4E, 0x32, 0x14, 0xF2,
  34186. 0x9F, 0x03, 0x51, 0x8E, 0xDD, 0x8B, 0x39, 0x19,
  34187. 0x1E, 0x39, 0xC5, 0xA7, 0x1C, 0xC6, 0xA4, 0xE1,
  34188. 0x77, 0xCA, 0x8C, 0x9D, 0x27, 0xBC, 0xCC, 0x16,
  34189. 0xD6, 0xFC, 0x59, 0x10, 0x23, 0xFF, 0x64, 0x90,
  34190. 0x9C, 0x23, 0x5A, 0xFF, 0x7E, 0x27, 0x1B, 0xC7,
  34191. 0x7F, 0x21, 0x3B, 0x41, 0xDB, 0xBC, 0x96, 0x60,
  34192. 0x0B, 0x35, 0xA1, 0xF3, 0xF8, 0x51, 0x0A, 0x65,
  34193. 0xCF, 0xDF, 0x7A, 0xB8, 0x04, 0x56, 0x49, 0xD7,
  34194. 0xD3, 0xC5, 0x0B, 0x4A, 0x1F, 0x60, 0xE1, 0x86,
  34195. 0x36, 0x53, 0x8E, 0x6C, 0x3E, 0xAF, 0x5B, 0xC1,
  34196. 0xCA, 0xCB, 0x22, 0x1A, 0x07, 0xDA, 0x54, 0xEC,
  34197. 0xAA, 0x06, 0x72, 0x17, 0xCF, 0x80, 0xC4, 0x89,
  34198. 0x56, 0x24, 0x1B, 0xD4, 0xFF, 0x50, 0x6B, 0x51,
  34199. 0x55, 0x4D, 0x6E, 0x79, 0x7E, 0xEC, 0x61, 0xC6,
  34200. 0xE4, 0x21, 0xC8, 0x0E, 0x10, 0x3F, 0x8C, 0x85,
  34201. 0x3A, 0x27, 0xEA, 0x91, 0x07, 0xCB, 0x37, 0x18,
  34202. 0x14, 0xB5, 0x63, 0x6E, 0x00, 0xBC, 0x0F, 0x36,
  34203. 0xF9, 0x54, 0x75, 0xE7, 0x0B, 0xDC, 0xE7, 0xA0,
  34204. 0x59, 0xF0, 0x64, 0xFB, 0x73, 0x07, 0x0E, 0xFE,
  34205. 0x57, 0x7F, 0x0D, 0x12, 0xBC, 0xB0, 0xBF, 0xA2,
  34206. 0x3A, 0x18, 0x08, 0x7E, 0xD5, 0x6C, 0xF0, 0x6F,
  34207. 0xF8, 0x98, 0xFB, 0xA5, 0x10, 0x7B, 0x10, 0x5F,
  34208. 0x6B, 0xC8, 0x6D, 0xDE, 0x2F, 0x1F, 0xE0, 0xC8,
  34209. 0x19, 0xEE, 0xC2, 0x03, 0x39, 0x49, 0x70, 0x3E,
  34210. 0x36, 0xE3, 0x3C, 0x70, 0xE3, 0xEA, 0xAC, 0x34,
  34211. 0x32, 0xB7, 0x0D, 0xBA, 0x7C, 0xAB, 0xE6, 0x18
  34212. };
  34213. static const byte sk_65_draft[] = {
  34214. 0xDC, 0x38, 0xE5, 0x5F, 0xDF, 0x2E, 0x9D, 0xD4,
  34215. 0x34, 0x5C, 0xAE, 0x1A, 0x7D, 0xF4, 0x2E, 0x2E,
  34216. 0xBC, 0x58, 0x57, 0x80, 0x55, 0x02, 0xE4, 0x3F,
  34217. 0xA5, 0x19, 0x41, 0xE4, 0x44, 0x58, 0x66, 0x41,
  34218. 0x52, 0x8D, 0xA0, 0xC7, 0xD2, 0x80, 0xDD, 0x49,
  34219. 0x0D, 0x5E, 0xB7, 0x65, 0xDB, 0x32, 0x33, 0x15,
  34220. 0x0F, 0x9E, 0xC8, 0xEB, 0xC9, 0x6E, 0xE8, 0xE8,
  34221. 0x5C, 0xBD, 0x18, 0x4F, 0xDC, 0xF8, 0xA8, 0xD9,
  34222. 0xC5, 0x33, 0x84, 0x79, 0x5A, 0x5E, 0xB7, 0x3C,
  34223. 0x6D, 0x82, 0xCA, 0xB9, 0xBA, 0x94, 0xB6, 0x46,
  34224. 0xAE, 0x3A, 0xD9, 0x19, 0x6C, 0xB4, 0xDA, 0xE2,
  34225. 0xF1, 0x4B, 0xB6, 0x43, 0xF0, 0x24, 0x08, 0xE5,
  34226. 0xF7, 0x9A, 0x41, 0xF1, 0x15, 0x9C, 0xA8, 0x08,
  34227. 0x79, 0x9F, 0xB8, 0x26, 0xD4, 0x08, 0x32, 0x47,
  34228. 0xC8, 0xF0, 0xD5, 0x31, 0xA1, 0xC1, 0x19, 0x04,
  34229. 0x02, 0x06, 0x2B, 0x4D, 0x46, 0xAE, 0x43, 0x6A,
  34230. 0x25, 0x82, 0x75, 0x41, 0x70, 0x36, 0x42, 0x48,
  34231. 0x78, 0x06, 0x36, 0x50, 0x23, 0x84, 0x68, 0x10,
  34232. 0x87, 0x08, 0x62, 0x00, 0x08, 0x34, 0x20, 0x73,
  34233. 0x32, 0x13, 0x36, 0x61, 0x87, 0x61, 0x43, 0x50,
  34234. 0x30, 0x02, 0x26, 0x07, 0x65, 0x45, 0x32, 0x00,
  34235. 0x25, 0x75, 0x01, 0x04, 0x88, 0x81, 0x58, 0x64,
  34236. 0x52, 0x40, 0x84, 0x22, 0x88, 0x42, 0x82, 0x56,
  34237. 0x47, 0x50, 0x05, 0x21, 0x88, 0x25, 0x32, 0x25,
  34238. 0x12, 0x85, 0x14, 0x52, 0x87, 0x77, 0x67, 0x18,
  34239. 0x46, 0x54, 0x63, 0x07, 0x88, 0x67, 0x37, 0x26,
  34240. 0x72, 0x62, 0x41, 0x02, 0x00, 0x01, 0x17, 0x84,
  34241. 0x33, 0x64, 0x32, 0x57, 0x06, 0x20, 0x05, 0x44,
  34242. 0x88, 0x57, 0x33, 0x45, 0x70, 0x55, 0x14, 0x43,
  34243. 0x12, 0x54, 0x04, 0x38, 0x37, 0x08, 0x42, 0x57,
  34244. 0x36, 0x05, 0x30, 0x03, 0x86, 0x53, 0x02, 0x53,
  34245. 0x75, 0x22, 0x62, 0x13, 0x38, 0x82, 0x48, 0x30,
  34246. 0x83, 0x83, 0x64, 0x83, 0x13, 0x74, 0x57, 0x32,
  34247. 0x46, 0x70, 0x06, 0x05, 0x82, 0x52, 0x73, 0x55,
  34248. 0x25, 0x77, 0x21, 0x78, 0x57, 0x83, 0x66, 0x20,
  34249. 0x38, 0x53, 0x21, 0x41, 0x77, 0x56, 0x77, 0x46,
  34250. 0x34, 0x42, 0x58, 0x31, 0x08, 0x06, 0x03, 0x62,
  34251. 0x20, 0x35, 0x11, 0x42, 0x35, 0x38, 0x63, 0x86,
  34252. 0x64, 0x13, 0x13, 0x75, 0x40, 0x01, 0x53, 0x74,
  34253. 0x41, 0x31, 0x56, 0x64, 0x38, 0x17, 0x14, 0x16,
  34254. 0x62, 0x33, 0x22, 0x12, 0x64, 0x40, 0x67, 0x11,
  34255. 0x62, 0x42, 0x25, 0x60, 0x38, 0x05, 0x83, 0x13,
  34256. 0x51, 0x00, 0x28, 0x36, 0x62, 0x56, 0x41, 0x43,
  34257. 0x58, 0x37, 0x51, 0x22, 0x70, 0x25, 0x82, 0x82,
  34258. 0x35, 0x24, 0x06, 0x83, 0x48, 0x58, 0x81, 0x78,
  34259. 0x07, 0x86, 0x23, 0x15, 0x75, 0x32, 0x46, 0x75,
  34260. 0x35, 0x40, 0x08, 0x43, 0x10, 0x66, 0x74, 0x05,
  34261. 0x13, 0x72, 0x74, 0x08, 0x83, 0x41, 0x81, 0x08,
  34262. 0x75, 0x87, 0x83, 0x28, 0x56, 0x66, 0x20, 0x01,
  34263. 0x18, 0x83, 0x57, 0x22, 0x14, 0x64, 0x18, 0x05,
  34264. 0x27, 0x75, 0x22, 0x84, 0x12, 0x38, 0x87, 0x52,
  34265. 0x32, 0x25, 0x28, 0x08, 0x14, 0x41, 0x81, 0x14,
  34266. 0x03, 0x24, 0x54, 0x23, 0x04, 0x81, 0x40, 0x36,
  34267. 0x38, 0x38, 0x64, 0x42, 0x46, 0x36, 0x68, 0x11,
  34268. 0x55, 0x00, 0x11, 0x25, 0x76, 0x16, 0x43, 0x07,
  34269. 0x23, 0x03, 0x34, 0x10, 0x46, 0x41, 0x14, 0x02,
  34270. 0x26, 0x10, 0x74, 0x38, 0x38, 0x72, 0x07, 0x87,
  34271. 0x54, 0x11, 0x12, 0x83, 0x75, 0x05, 0x82, 0x17,
  34272. 0x45, 0x20, 0x38, 0x41, 0x37, 0x20, 0x00, 0x08,
  34273. 0x32, 0x18, 0x16, 0x25, 0x58, 0x85, 0x16, 0x88,
  34274. 0x71, 0x82, 0x45, 0x60, 0x33, 0x11, 0x13, 0x42,
  34275. 0x43, 0x37, 0x68, 0x11, 0x16, 0x54, 0x04, 0x08,
  34276. 0x52, 0x78, 0x13, 0x56, 0x83, 0x52, 0x15, 0x24,
  34277. 0x03, 0x61, 0x78, 0x44, 0x13, 0x70, 0x67, 0x36,
  34278. 0x74, 0x86, 0x52, 0x50, 0x15, 0x41, 0x88, 0x74,
  34279. 0x53, 0x00, 0x05, 0x18, 0x65, 0x62, 0x14, 0x84,
  34280. 0x12, 0x32, 0x01, 0x88, 0x40, 0x42, 0x34, 0x05,
  34281. 0x32, 0x80, 0x72, 0x55, 0x20, 0x68, 0x16, 0x43,
  34282. 0x14, 0x15, 0x15, 0x38, 0x43, 0x85, 0x27, 0x60,
  34283. 0x70, 0x18, 0x27, 0x35, 0x53, 0x01, 0x28, 0x73,
  34284. 0x27, 0x84, 0x10, 0x53, 0x67, 0x10, 0x45, 0x40,
  34285. 0x81, 0x52, 0x86, 0x06, 0x11, 0x18, 0x04, 0x31,
  34286. 0x57, 0x25, 0x22, 0x44, 0x47, 0x81, 0x45, 0x44,
  34287. 0x55, 0x04, 0x72, 0x57, 0x06, 0x46, 0x76, 0x23,
  34288. 0x38, 0x85, 0x65, 0x30, 0x08, 0x48, 0x20, 0x13,
  34289. 0x22, 0x77, 0x44, 0x60, 0x43, 0x14, 0x15, 0x27,
  34290. 0x86, 0x22, 0x37, 0x37, 0x27, 0x04, 0x27, 0x50,
  34291. 0x74, 0x31, 0x10, 0x82, 0x00, 0x75, 0x80, 0x44,
  34292. 0x38, 0x10, 0x58, 0x40, 0x86, 0x60, 0x63, 0x13,
  34293. 0x65, 0x18, 0x33, 0x70, 0x57, 0x68, 0x05, 0x10,
  34294. 0x81, 0x03, 0x42, 0x05, 0x25, 0x65, 0x33, 0x57,
  34295. 0x38, 0x05, 0x65, 0x34, 0x46, 0x53, 0x68, 0x11,
  34296. 0x75, 0x10, 0x04, 0x54, 0x18, 0x47, 0x52, 0x24,
  34297. 0x63, 0x23, 0x74, 0x45, 0x11, 0x34, 0x68, 0x32,
  34298. 0x35, 0x38, 0x52, 0x85, 0x28, 0x08, 0x71, 0x78,
  34299. 0x37, 0x38, 0x27, 0x10, 0x80, 0x54, 0x26, 0x33,
  34300. 0x31, 0x82, 0x44, 0x88, 0x33, 0x24, 0x62, 0x86,
  34301. 0x32, 0x82, 0x73, 0x31, 0x28, 0x14, 0x73, 0x87,
  34302. 0x06, 0x35, 0x80, 0x36, 0x67, 0x02, 0x33, 0x75,
  34303. 0x27, 0x36, 0x38, 0x16, 0x35, 0x70, 0x52, 0x16,
  34304. 0x87, 0x58, 0x85, 0x17, 0x22, 0x13, 0x54, 0x85,
  34305. 0x07, 0x53, 0x31, 0x26, 0x78, 0x01, 0x85, 0x18,
  34306. 0x08, 0x68, 0x38, 0x52, 0x11, 0x73, 0x32, 0x25,
  34307. 0x58, 0x82, 0x70, 0x70, 0x36, 0x30, 0x50, 0x38,
  34308. 0x65, 0x12, 0x78, 0x31, 0x77, 0x72, 0x18, 0x41,
  34309. 0x05, 0x42, 0x32, 0x26, 0x26, 0x50, 0x52, 0x86,
  34310. 0x15, 0x76, 0x28, 0x66, 0x88, 0x03, 0x78, 0x28,
  34311. 0x70, 0x33, 0x36, 0x27, 0x16, 0x61, 0x43, 0x56,
  34312. 0x62, 0x81, 0x85, 0x75, 0x47, 0x60, 0x63, 0x38,
  34313. 0x66, 0x81, 0x51, 0x78, 0x03, 0x42, 0x60, 0x38,
  34314. 0x01, 0x24, 0x73, 0x63, 0x81, 0x12, 0x01, 0x27,
  34315. 0x63, 0x13, 0x11, 0x78, 0x36, 0x37, 0x15, 0x03,
  34316. 0x84, 0x58, 0x17, 0x25, 0x67, 0x87, 0x57, 0x83,
  34317. 0x71, 0x85, 0x37, 0x53, 0x86, 0x22, 0x33, 0x28,
  34318. 0x77, 0x30, 0x18, 0x15, 0x01, 0x37, 0x85, 0x40,
  34319. 0x15, 0x38, 0x51, 0x33, 0x17, 0x42, 0x64, 0x04,
  34320. 0x56, 0x27, 0x50, 0x45, 0x11, 0x27, 0x20, 0x17,
  34321. 0x76, 0x55, 0x33, 0x37, 0x58, 0x88, 0x88, 0x45,
  34322. 0x16, 0x55, 0x08, 0x53, 0x52, 0x48, 0x72, 0x85,
  34323. 0x30, 0x15, 0x23, 0x44, 0x22, 0x02, 0x43, 0x45,
  34324. 0x41, 0x10, 0x00, 0x52, 0x32, 0x73, 0x05, 0x75,
  34325. 0x72, 0x16, 0x08, 0x11, 0x51, 0x36, 0x20, 0x04,
  34326. 0x76, 0x48, 0x78, 0x56, 0x60, 0x88, 0x07, 0x47,
  34327. 0x70, 0x20, 0x46, 0x40, 0x43, 0x26, 0x04, 0x37,
  34328. 0x17, 0x51, 0x58, 0x46, 0x72, 0x44, 0x50, 0x23,
  34329. 0x67, 0x63, 0x60, 0x84, 0x30, 0x51, 0x52, 0x53,
  34330. 0x21, 0x74, 0x85, 0x45, 0x74, 0x43, 0x11, 0x72,
  34331. 0x52, 0x65, 0x76, 0x08, 0x78, 0x63, 0x14, 0x27,
  34332. 0x41, 0x34, 0x67, 0x07, 0x45, 0x15, 0x10, 0x83,
  34333. 0x24, 0x02, 0x80, 0x53, 0x07, 0x21, 0x58, 0x10,
  34334. 0x34, 0x20, 0x54, 0x12, 0x58, 0x44, 0x25, 0x53,
  34335. 0x33, 0x46, 0x02, 0x38, 0x60, 0x17, 0x70, 0x64,
  34336. 0x18, 0x52, 0x62, 0x26, 0x65, 0x61, 0x42, 0x31,
  34337. 0x22, 0x57, 0x34, 0x57, 0x02, 0x34, 0x62, 0x76,
  34338. 0x74, 0x38, 0x73, 0x21, 0x68, 0x71, 0x07, 0x21,
  34339. 0x61, 0x05, 0x20, 0x20, 0x86, 0x83, 0x30, 0x25,
  34340. 0x50, 0x50, 0x83, 0x30, 0x31, 0x56, 0x30, 0x31,
  34341. 0x76, 0x04, 0x54, 0x80, 0x75, 0x18, 0x82, 0x23,
  34342. 0x61, 0x87, 0x58, 0x25, 0x13, 0x63, 0x21, 0x51,
  34343. 0x48, 0x02, 0x67, 0x37, 0x12, 0x88, 0x70, 0x60,
  34344. 0x07, 0x36, 0x18, 0x15, 0x87, 0x74, 0x55, 0x60,
  34345. 0x00, 0x54, 0x37, 0x11, 0x01, 0x37, 0x14, 0x17,
  34346. 0x11, 0x72, 0x14, 0x55, 0x31, 0x75, 0x77, 0x48,
  34347. 0x10, 0x23, 0x83, 0x20, 0x00, 0x04, 0x32, 0x64,
  34348. 0x66, 0x61, 0x71, 0x31, 0x03, 0x15, 0x44, 0x32,
  34349. 0x57, 0x25, 0x64, 0x31, 0x28, 0x15, 0x33, 0x67,
  34350. 0x86, 0x87, 0x37, 0x03, 0x12, 0x78, 0x86, 0x13,
  34351. 0x47, 0x80, 0x61, 0x42, 0x50, 0x40, 0x23, 0x37,
  34352. 0x01, 0x01, 0x66, 0x24, 0x06, 0x57, 0x82, 0x02,
  34353. 0x22, 0x42, 0x41, 0x02, 0x26, 0x06, 0x41, 0x35,
  34354. 0x64, 0x16, 0x44, 0x42, 0x38, 0x30, 0x86, 0x88,
  34355. 0x47, 0x71, 0x62, 0x33, 0x24, 0x02, 0x12, 0x37,
  34356. 0x42, 0x33, 0x20, 0x81, 0x80, 0x53, 0x07, 0x65,
  34357. 0x71, 0x27, 0x13, 0x53, 0x15, 0x43, 0x76, 0x38,
  34358. 0x71, 0x30, 0x07, 0x87, 0x25, 0x63, 0x03, 0x33,
  34359. 0x70, 0x56, 0x18, 0x13, 0x83, 0x51, 0x44, 0x40,
  34360. 0x04, 0x80, 0x62, 0x24, 0x20, 0x64, 0x54, 0x40,
  34361. 0x20, 0x73, 0x61, 0x45, 0x01, 0x24, 0x47, 0x78,
  34362. 0x23, 0x34, 0x56, 0x10, 0x25, 0x32, 0x02, 0x70,
  34363. 0x08, 0x02, 0x23, 0x24, 0x80, 0x43, 0x04, 0x02,
  34364. 0x81, 0x11, 0x23, 0x82, 0x03, 0x61, 0x30, 0x33,
  34365. 0x15, 0x36, 0x25, 0x32, 0x14, 0x73, 0x22, 0x46,
  34366. 0x81, 0x25, 0x16, 0x13, 0x52, 0x58, 0x71, 0x61,
  34367. 0x67, 0x08, 0x38, 0x76, 0x71, 0x15, 0x88, 0x47,
  34368. 0x31, 0x25, 0x27, 0x18, 0x31, 0x50, 0x40, 0x71,
  34369. 0x06, 0x87, 0x37, 0x30, 0x85, 0x64, 0x62, 0x78,
  34370. 0x32, 0x74, 0x18, 0x83, 0x67, 0x40, 0x37, 0x44,
  34371. 0x56, 0x02, 0x72, 0x61, 0x27, 0x28, 0x38, 0x38,
  34372. 0x67, 0x17, 0x58, 0x04, 0x61, 0x28, 0x67, 0x37,
  34373. 0x46, 0x50, 0x38, 0x15, 0x45, 0x12, 0x71, 0x44,
  34374. 0x22, 0x02, 0x34, 0x83, 0x40, 0x70, 0x55, 0x75,
  34375. 0x54, 0x26, 0x88, 0x07, 0x25, 0x58, 0x73, 0x60,
  34376. 0x58, 0x61, 0x45, 0x63, 0x35, 0x05, 0x48, 0x63,
  34377. 0x48, 0x57, 0x03, 0x31, 0x28, 0x14, 0x05, 0x01,
  34378. 0x57, 0x34, 0x64, 0x50, 0x23, 0x86, 0x75, 0x85,
  34379. 0x18, 0x75, 0x56, 0x88, 0x08, 0x26, 0x01, 0x34,
  34380. 0x01, 0x57, 0x05, 0x28, 0x35, 0x48, 0x17, 0x57,
  34381. 0x71, 0x81, 0x41, 0x33, 0x77, 0x86, 0x07, 0x77,
  34382. 0x02, 0x25, 0x71, 0x74, 0x37, 0x31, 0x20, 0x14,
  34383. 0x32, 0x54, 0x20, 0x35, 0x54, 0x76, 0x83, 0x15,
  34384. 0x80, 0x73, 0x27, 0x23, 0x00, 0x58, 0x22, 0x84,
  34385. 0x64, 0x56, 0x14, 0x84, 0x38, 0x34, 0x16, 0x21,
  34386. 0x77, 0x07, 0x34, 0x81, 0x66, 0x87, 0x40, 0x11,
  34387. 0x62, 0x46, 0x45, 0x01, 0x20, 0x53, 0x21, 0x73,
  34388. 0x07, 0x76, 0x44, 0x15, 0x61, 0x50, 0x83, 0x48,
  34389. 0x58, 0x58, 0x45, 0x33, 0x25, 0x36, 0x07, 0x42,
  34390. 0x70, 0x24, 0x07, 0x41, 0x08, 0x35, 0x00, 0x78,
  34391. 0x41, 0x47, 0x02, 0x56, 0x07, 0x14, 0x68, 0x33,
  34392. 0x55, 0x77, 0x32, 0x40, 0x55, 0x24, 0x50, 0x26,
  34393. 0x47, 0x12, 0x65, 0x58, 0x43, 0x05, 0x52, 0x55,
  34394. 0x75, 0x50, 0x18, 0x46, 0x65, 0x48, 0x03, 0x32,
  34395. 0x85, 0x31, 0x16, 0x52, 0x71, 0x57, 0x87, 0x46,
  34396. 0x76, 0x14, 0x42, 0x81, 0x28, 0x74, 0x60, 0x34,
  34397. 0x35, 0x55, 0x52, 0x16, 0x58, 0x48, 0x61, 0x75,
  34398. 0x80, 0x88, 0x15, 0x32, 0x72, 0x26, 0x31, 0x03,
  34399. 0x05, 0x03, 0x16, 0x04, 0x07, 0x37, 0x37, 0x73,
  34400. 0x43, 0x81, 0x57, 0x31, 0x88, 0x04, 0x72, 0x76,
  34401. 0x01, 0x61, 0x81, 0x17, 0x37, 0x65, 0x44, 0x38,
  34402. 0x61, 0x23, 0x16, 0x26, 0x52, 0x45, 0x00, 0x73,
  34403. 0x83, 0x63, 0x64, 0x62, 0x26, 0x74, 0x60, 0x11,
  34404. 0x81, 0x08, 0x06, 0x30, 0x36, 0x05, 0x10, 0x48,
  34405. 0x47, 0x35, 0x10, 0x85, 0x30, 0x86, 0x71, 0x38,
  34406. 0x16, 0x37, 0x6F, 0x3B, 0x1C, 0x18, 0xB1, 0xE3,
  34407. 0xE8, 0xEE, 0x83, 0x3E, 0x8D, 0x38, 0x43, 0x9E,
  34408. 0x78, 0x1C, 0xA3, 0xB8, 0x94, 0x06, 0x54, 0xEF,
  34409. 0x44, 0x6C, 0x9A, 0xAC, 0xC3, 0xF1, 0xD3, 0x0E,
  34410. 0xE0, 0x10, 0x5B, 0x8F, 0x63, 0xEB, 0x89, 0x74,
  34411. 0x6E, 0xF4, 0xBE, 0xB5, 0x4C, 0xFC, 0xE8, 0x81,
  34412. 0x2C, 0xF9, 0x47, 0xCF, 0x54, 0x54, 0xFB, 0x1C,
  34413. 0xA5, 0x5F, 0x25, 0xA0, 0xFE, 0x57, 0xF5, 0xFC,
  34414. 0xFD, 0x73, 0xB0, 0xDA, 0x04, 0xB0, 0xBF, 0x28,
  34415. 0x92, 0x92, 0xAF, 0x39, 0x74, 0x72, 0x56, 0x69,
  34416. 0xC3, 0x00, 0x03, 0xE0, 0x50, 0x9F, 0xED, 0xC8,
  34417. 0x0F, 0x6C, 0x89, 0x4B, 0xB0, 0x47, 0xC2, 0xE2,
  34418. 0xAF, 0x48, 0x5C, 0xAD, 0x68, 0xC2, 0x1D, 0x80,
  34419. 0xEF, 0x33, 0xB0, 0xC4, 0xFD, 0xA6, 0x7B, 0x85,
  34420. 0x31, 0xA1, 0x58, 0x87, 0x67, 0x54, 0x71, 0x3F,
  34421. 0xF8, 0xA8, 0xA6, 0x8D, 0x9A, 0xBD, 0xC4, 0x81,
  34422. 0x6B, 0x24, 0xB4, 0xA3, 0x6A, 0x8A, 0x2B, 0xB1,
  34423. 0xFD, 0x1C, 0x2C, 0x25, 0xC3, 0x72, 0xC4, 0xB7,
  34424. 0x75, 0xF8, 0xCC, 0x17, 0x39, 0xCF, 0x2C, 0xE9,
  34425. 0xA4, 0x54, 0x58, 0xE4, 0x1A, 0xAE, 0xC6, 0x4A,
  34426. 0xEE, 0xDE, 0x75, 0x7C, 0xE7, 0x38, 0xBC, 0xDF,
  34427. 0x4D, 0xA0, 0xEE, 0x2B, 0xDD, 0x5F, 0x80, 0x5C,
  34428. 0xCF, 0xF7, 0x2A, 0x5F, 0x73, 0x8B, 0xAC, 0x12,
  34429. 0x34, 0x2E, 0xE3, 0xF1, 0x4C, 0xB7, 0x22, 0x68,
  34430. 0xC2, 0xD6, 0x36, 0x7D, 0xF1, 0x7F, 0x20, 0x46,
  34431. 0xA2, 0x4B, 0x47, 0x4B, 0x32, 0x58, 0xF7, 0xB0,
  34432. 0x88, 0x54, 0x6C, 0x99, 0x3B, 0x0D, 0xA1, 0xE2,
  34433. 0x92, 0x92, 0xEB, 0x72, 0x1E, 0xE7, 0xE5, 0xA1,
  34434. 0xF8, 0x6E, 0x14, 0xA5, 0x39, 0xB0, 0x63, 0x6F,
  34435. 0x78, 0x82, 0xA1, 0x9C, 0x8D, 0x79, 0x02, 0x85,
  34436. 0xA6, 0xDF, 0x7D, 0xEE, 0xCE, 0x17, 0x4D, 0x63,
  34437. 0xCF, 0xF3, 0xB2, 0xFF, 0x85, 0x68, 0x81, 0xCB,
  34438. 0x38, 0x6B, 0x1B, 0x38, 0xA2, 0xE0, 0xF2, 0x4C,
  34439. 0x31, 0xE0, 0x91, 0x93, 0xDD, 0xF3, 0x71, 0x47,
  34440. 0xF2, 0x69, 0xD9, 0x4C, 0xDE, 0xF9, 0x90, 0x61,
  34441. 0x34, 0x62, 0x07, 0x71, 0x79, 0xD0, 0xDD, 0x09,
  34442. 0x32, 0x64, 0x39, 0x49, 0x93, 0x1A, 0x02, 0xBA,
  34443. 0xFA, 0x80, 0x17, 0x6E, 0xDF, 0x97, 0xB6, 0xA2,
  34444. 0x31, 0x34, 0x71, 0xF0, 0xB1, 0x9B, 0x3B, 0x59,
  34445. 0xF4, 0x3B, 0xD2, 0x2A, 0x05, 0x49, 0x3E, 0xFB,
  34446. 0x0C, 0xF8, 0xB5, 0xD7, 0xB6, 0x25, 0x2B, 0x09,
  34447. 0x8B, 0x4B, 0xFA, 0x39, 0x5B, 0xF9, 0xA2, 0x09,
  34448. 0xE9, 0xBB, 0x46, 0x01, 0x30, 0x00, 0x90, 0x32,
  34449. 0x58, 0xA6, 0x9B, 0x67, 0xF5, 0x94, 0x11, 0xC8,
  34450. 0x35, 0x95, 0xFA, 0x6E, 0x67, 0x42, 0x8D, 0x96,
  34451. 0x6D, 0x20, 0xFC, 0xD3, 0x09, 0x61, 0x11, 0x86,
  34452. 0x77, 0xC0, 0x86, 0xA3, 0x54, 0xAE, 0x6D, 0x41,
  34453. 0xEE, 0x17, 0xDC, 0xA1, 0xB0, 0xB7, 0x50, 0x43,
  34454. 0xD6, 0xCE, 0x23, 0xBD, 0xB0, 0x1E, 0x02, 0xE5,
  34455. 0x9E, 0xCF, 0xC6, 0x2E, 0x8C, 0x39, 0x71, 0xB1,
  34456. 0x45, 0x02, 0x75, 0xBA, 0x7F, 0x60, 0xB0, 0x8B,
  34457. 0x1C, 0x33, 0xBA, 0x0C, 0xFF, 0x54, 0x63, 0xE3,
  34458. 0x47, 0x5B, 0x07, 0x77, 0x77, 0xC5, 0x72, 0x24,
  34459. 0x60, 0xFA, 0xDB, 0x0B, 0xF6, 0x41, 0x82, 0x69,
  34460. 0x3C, 0x68, 0x37, 0xF5, 0xFD, 0x45, 0x4A, 0x66,
  34461. 0x6C, 0xD7, 0x01, 0x10, 0x78, 0x4A, 0xED, 0x09,
  34462. 0xAE, 0x49, 0x0A, 0x60, 0xC7, 0x78, 0x56, 0x51,
  34463. 0x15, 0xE3, 0x4A, 0xB5, 0xAE, 0xAD, 0x09, 0xD1,
  34464. 0x71, 0xA8, 0xCA, 0x3C, 0x8A, 0xE6, 0xCA, 0x39,
  34465. 0x43, 0x60, 0x56, 0x83, 0x3C, 0x58, 0x04, 0xD4,
  34466. 0xB4, 0x62, 0xDD, 0x53, 0x05, 0xC8, 0x51, 0xAF,
  34467. 0x59, 0xF6, 0x4F, 0x04, 0xC3, 0x1E, 0x69, 0xFF,
  34468. 0x82, 0xBF, 0xD7, 0x89, 0xD2, 0x30, 0x9F, 0xF2,
  34469. 0xE6, 0x38, 0x05, 0x9C, 0xD5, 0x08, 0xB8, 0x25,
  34470. 0xF3, 0x3B, 0x99, 0x85, 0x4E, 0x40, 0xF8, 0x40,
  34471. 0xF2, 0x4B, 0x5C, 0x3A, 0xA8, 0x64, 0x41, 0x92,
  34472. 0xEA, 0xCA, 0x9A, 0x7B, 0xCF, 0xBA, 0x1F, 0xDE,
  34473. 0xE0, 0x9D, 0xCA, 0xAD, 0xB4, 0x0C, 0x90, 0xFF,
  34474. 0xE1, 0x6C, 0xEC, 0xDD, 0x32, 0x38, 0x2A, 0xF7,
  34475. 0x19, 0x20, 0x39, 0xCB, 0x29, 0x67, 0x2F, 0x70,
  34476. 0x71, 0x12, 0x10, 0xB6, 0xB8, 0x3E, 0x8D, 0xFD,
  34477. 0xB5, 0xFB, 0xBD, 0xBF, 0xA8, 0xCA, 0x19, 0xC4,
  34478. 0xC6, 0xAC, 0x37, 0x31, 0xFC, 0x33, 0xC2, 0x7F,
  34479. 0xA2, 0xA2, 0x6D, 0xEB, 0x15, 0x2E, 0xA1, 0x90,
  34480. 0xF8, 0x29, 0xC6, 0x34, 0xD1, 0x39, 0x30, 0x24,
  34481. 0x1C, 0xB9, 0x26, 0xAC, 0xDD, 0xE5, 0x24, 0x9C,
  34482. 0xDD, 0x35, 0x60, 0x7E, 0x38, 0x0C, 0xC1, 0x2A,
  34483. 0x7D, 0x1E, 0xA9, 0xBA, 0xA5, 0x58, 0x4C, 0xDD,
  34484. 0x26, 0x86, 0x09, 0xDC, 0xC3, 0xB0, 0x1F, 0xCD,
  34485. 0xC9, 0xAD, 0xCB, 0x4A, 0x7E, 0x51, 0x67, 0xE5,
  34486. 0xED, 0x5A, 0xD2, 0x21, 0xDB, 0x2E, 0xAB, 0xD9,
  34487. 0x0A, 0xEC, 0xAE, 0x71, 0xFA, 0x23, 0x7A, 0xEF,
  34488. 0x98, 0xDF, 0x53, 0x89, 0x93, 0xE8, 0x71, 0xD7,
  34489. 0x35, 0xDA, 0x6B, 0x88, 0x31, 0xAF, 0x67, 0xF2,
  34490. 0x97, 0x29, 0x1C, 0x39, 0x67, 0xEB, 0xAF, 0x60,
  34491. 0xD9, 0x53, 0xC4, 0x0F, 0x7A, 0x46, 0x4E, 0xF3,
  34492. 0x2F, 0x8E, 0xAE, 0xFA, 0x64, 0x2E, 0x37, 0xDE,
  34493. 0xA9, 0x74, 0x73, 0x5D, 0xDD, 0xBB, 0x83, 0x54,
  34494. 0x27, 0xB9, 0x7A, 0x63, 0x2B, 0x19, 0x8B, 0x26,
  34495. 0x22, 0x28, 0x84, 0xA0, 0x58, 0x00, 0x2D, 0x55,
  34496. 0xEA, 0x2A, 0x80, 0x0D, 0x6C, 0x97, 0x0E, 0x8B,
  34497. 0xF7, 0x67, 0xB2, 0x8B, 0x2D, 0xDE, 0x8F, 0x58,
  34498. 0xFE, 0x97, 0x81, 0xE7, 0xE2, 0x58, 0x8D, 0x7E,
  34499. 0x1B, 0xAB, 0xE5, 0x15, 0x9D, 0x54, 0xF4, 0x00,
  34500. 0x34, 0x1D, 0x12, 0x1B, 0x03, 0x23, 0x2B, 0x06,
  34501. 0x2E, 0x8C, 0xD0, 0x0A, 0xDC, 0x19, 0xA1, 0x69,
  34502. 0x1D, 0x72, 0x91, 0xB4, 0xED, 0x0E, 0x81, 0xF7,
  34503. 0x05, 0x99, 0x84, 0xFC, 0x74, 0x0F, 0x7D, 0xF8,
  34504. 0x9B, 0x3E, 0x7F, 0x63, 0x7C, 0x73, 0xEB, 0xF5,
  34505. 0x36, 0xB3, 0x24, 0x22, 0xAA, 0x33, 0x0C, 0x30,
  34506. 0x42, 0xC3, 0xE2, 0x04, 0x6B, 0x3F, 0x2A, 0x0D,
  34507. 0xAB, 0xE8, 0x5A, 0x9A, 0x09, 0xD7, 0xB6, 0xAA,
  34508. 0x9C, 0x3E, 0xD0, 0x9E, 0xB5, 0x9B, 0x52, 0x7B,
  34509. 0xAF, 0x2D, 0x6B, 0xE0, 0x40, 0x12, 0x34, 0xBE,
  34510. 0x49, 0xAB, 0xD2, 0xC8, 0xB5, 0x89, 0x1B, 0x79,
  34511. 0xEC, 0xAE, 0x88, 0x89, 0x3C, 0x05, 0xC7, 0x75,
  34512. 0xC5, 0x84, 0xF7, 0x10, 0x49, 0x48, 0x92, 0x69,
  34513. 0x9E, 0xD5, 0x56, 0xB2, 0x1E, 0x81, 0x18, 0x78,
  34514. 0xCB, 0x93, 0x5D, 0x70, 0x3A, 0xB2, 0x67, 0xD1,
  34515. 0xCC, 0x8F, 0x83, 0x03, 0xB9, 0x64, 0x46, 0x22,
  34516. 0x78, 0x0D, 0x55, 0x67, 0x22, 0x58, 0x0E, 0x22,
  34517. 0x6B, 0xBA, 0x01, 0xD4, 0x77, 0x05, 0xA7, 0xAC,
  34518. 0xB7, 0xE5, 0xFC, 0xE6, 0x11, 0xCC, 0x92, 0x5A,
  34519. 0x8C, 0xC0, 0x08, 0x24, 0xAF, 0xCC, 0x4D, 0xBD,
  34520. 0x79, 0xD3, 0x5C, 0x52, 0x2C, 0xFF, 0x1A, 0x48,
  34521. 0xBB, 0x91, 0x59, 0x6A, 0x80, 0x32, 0x8C, 0x75,
  34522. 0x7C, 0xD2, 0xC1, 0x94, 0x94, 0xA8, 0x55, 0x4B,
  34523. 0xF2, 0x96, 0xF7, 0x86, 0xF7, 0x53, 0x4F, 0x54,
  34524. 0x74, 0x05, 0x5C, 0xEF, 0x02, 0xA0, 0x8A, 0xD1,
  34525. 0x88, 0x72, 0xEB, 0x1B, 0x82, 0xF9, 0xFB, 0xDA,
  34526. 0xBC, 0xB9, 0x90, 0x98, 0xF2, 0x4B, 0x9A, 0xA6,
  34527. 0x89, 0xD5, 0xB3, 0xD8, 0x7B, 0x94, 0xE3, 0x1F,
  34528. 0x17, 0x4F, 0xEB, 0x24, 0x06, 0x2B, 0xAB, 0x5F,
  34529. 0x27, 0x9B, 0xCD, 0xCE, 0x50, 0x06, 0x40, 0xDD,
  34530. 0x7A, 0x8C, 0x67, 0xF0, 0x8E, 0x07, 0xB4, 0x1C,
  34531. 0x3C, 0x13, 0xB2, 0x07, 0x6A, 0x38, 0x59, 0x94,
  34532. 0x2C, 0xB1, 0x72, 0xA8, 0x77, 0x5B, 0x15, 0x8F,
  34533. 0x88, 0xC4, 0x5C, 0xDC, 0x92, 0xCA, 0xC0, 0xED,
  34534. 0x02, 0xFF, 0x1D, 0x57, 0x25, 0xBE, 0x67, 0x3E,
  34535. 0x4C, 0xE8, 0x95, 0x2A, 0x80, 0xB2, 0x5D, 0xBC,
  34536. 0xFA, 0x17, 0xA9, 0x35, 0x0A, 0x6B, 0x07, 0xC8,
  34537. 0x8F, 0x88, 0x8D, 0xBC, 0x97, 0x84, 0xE2, 0x07,
  34538. 0x57, 0x92, 0x99, 0x4B, 0xE8, 0xDD, 0xD7, 0xA4,
  34539. 0x58, 0xCB, 0x61, 0xCE, 0x16, 0xFC, 0x22, 0xCD,
  34540. 0x4B, 0x1A, 0x08, 0xC9, 0xAD, 0x3D, 0xB1, 0xF2,
  34541. 0xA9, 0x1B, 0x8E, 0xD0, 0xC7, 0xBC, 0xCE, 0xF9,
  34542. 0x0A, 0x7A, 0x4D, 0xBE, 0x82, 0x0A, 0xBD, 0x6C,
  34543. 0x42, 0x99, 0xBF, 0x86, 0x65, 0x53, 0xAA, 0x04,
  34544. 0x79, 0xD6, 0x6D, 0x7E, 0x0F, 0x40, 0xFA, 0xEE,
  34545. 0xCE, 0x38, 0x3B, 0x1C, 0x2F, 0xA4, 0x45, 0xA3,
  34546. 0x78, 0x2B, 0xA0, 0x29, 0xC5, 0xAA, 0xA9, 0x09,
  34547. 0x29, 0x51, 0xDC, 0x5B, 0xB5, 0x95, 0xE4, 0xCE,
  34548. 0xC8, 0x50, 0x71, 0x2D, 0xE9, 0x32, 0x12, 0xA0,
  34549. 0x7C, 0x88, 0x6B, 0xED, 0xE4, 0x38, 0xB7, 0x92,
  34550. 0xCA, 0xE4, 0xDC, 0xD4, 0x05, 0x3B, 0x2B, 0x84,
  34551. 0x95, 0x07, 0xFF, 0xF4, 0x79, 0xFF, 0x1E, 0x73,
  34552. 0x1B, 0x8E, 0xDF, 0xA3, 0x15, 0xBD, 0x56, 0xAC,
  34553. 0xDA, 0xAD, 0x73, 0x95, 0xC2, 0xD3, 0x72, 0xA8,
  34554. 0xF0, 0x8E, 0x6C, 0xE3, 0x7D, 0xBE, 0x4C, 0x87,
  34555. 0xFC, 0x0F, 0xA6, 0x3B, 0xED, 0xA4, 0x0F, 0x4F,
  34556. 0xF1, 0x5D, 0xF2, 0x56, 0x54, 0xD1, 0xCE, 0x6C,
  34557. 0xCA, 0x1C, 0xCB, 0xC2, 0x45, 0x7F, 0x90, 0x61,
  34558. 0x0E, 0x3D, 0xCE, 0xBB, 0x5E, 0x41, 0x38, 0x2B,
  34559. 0xD4, 0x41, 0x7C, 0x67, 0x7C, 0x71, 0x95, 0x34,
  34560. 0xD7, 0xED, 0x4D, 0xAC, 0x6E, 0xF1, 0x46, 0xEA,
  34561. 0x7D, 0xA4, 0x4C, 0x69, 0x0B, 0x9C, 0x2F, 0xAA,
  34562. 0xF1, 0x17, 0x90, 0x1B, 0xF4, 0x4C, 0x03, 0xBE,
  34563. 0x9D, 0x56, 0xCE, 0x0C, 0xCF, 0xE0, 0x87, 0x44,
  34564. 0xBE, 0x2C, 0x52, 0xD3, 0xBC, 0xAE, 0x02, 0x30,
  34565. 0xC7, 0x26, 0x06, 0x88, 0xA6, 0xAA, 0x9D, 0x50,
  34566. 0xF1, 0x94, 0x58, 0xC7, 0x60, 0xF3, 0xA0, 0x6F,
  34567. 0x53, 0x66, 0x53, 0xCD, 0x1D, 0xBE, 0xD1, 0xF2,
  34568. 0x39, 0xBA, 0x1F, 0xE8, 0x40, 0x84, 0xCD, 0x1C,
  34569. 0x8F, 0x3D, 0xB7, 0xD1, 0x51, 0x00, 0xDE, 0xB8,
  34570. 0x11, 0xD9, 0x66, 0xAD, 0xD5, 0xE9, 0x33, 0x09,
  34571. 0xE1, 0xA8, 0x00, 0x58, 0x65, 0xF1, 0xC1, 0x67,
  34572. 0xB4, 0x3A, 0xA7, 0x98, 0x90, 0x6A, 0xDB, 0x91,
  34573. 0xDB, 0x4A, 0x16, 0x35, 0xDC, 0x3D, 0x69, 0xEB,
  34574. 0x7B, 0xDE, 0xCC, 0x91, 0x1B, 0x8D, 0xE6, 0x46,
  34575. 0x61, 0x8E, 0x3F, 0x4C, 0x88, 0x81, 0x85, 0x4A,
  34576. 0x73, 0x08, 0x56, 0x52, 0xAE, 0xE6, 0x4A, 0x60,
  34577. 0x4A, 0x2E, 0x0C, 0x9A, 0x93, 0x76, 0x35, 0xC9,
  34578. 0x36, 0x28, 0x0C, 0x72, 0x19, 0xAD, 0x33, 0xCF,
  34579. 0x2B, 0xFB, 0xCE, 0x1A, 0x7D, 0xAC, 0xAA, 0x75,
  34580. 0x15, 0x76, 0x81, 0x52, 0x55, 0xCC, 0xB9, 0x39,
  34581. 0x07, 0xA3, 0x39, 0x12, 0x8D, 0x6F, 0x53, 0xAF,
  34582. 0xC7, 0x14, 0x7F, 0xC7, 0x96, 0x5A, 0x49, 0x3C,
  34583. 0x5C, 0xB0, 0x26, 0x47, 0xF4, 0x9D, 0xCA, 0x23,
  34584. 0xA6, 0x7D, 0xA6, 0x61, 0xC4, 0xA3, 0x26, 0x40,
  34585. 0x0F, 0xA7, 0x27, 0x09, 0xBC, 0x39, 0xFD, 0xA7,
  34586. 0x75, 0x38, 0x74, 0xD0, 0x9D, 0x29, 0x15, 0x97,
  34587. 0xDE, 0x25, 0x60, 0x4D, 0x19, 0x36, 0x04, 0xFB,
  34588. 0xA5, 0x2C, 0xB0, 0xC8, 0xB5, 0xFE, 0xE5, 0x94,
  34589. 0x7C, 0xE2, 0x1F, 0x84, 0xBB, 0xFB, 0x78, 0x9E,
  34590. 0xA5, 0x7C, 0x5D, 0x4A, 0xB2, 0x48, 0x6F, 0x6E,
  34591. 0x67, 0x95, 0x16, 0x5F, 0x01, 0x2A, 0xF8, 0x70,
  34592. 0x95, 0xCB, 0x06, 0x93, 0x26, 0x6E, 0x7A, 0x75,
  34593. 0xB5, 0xE5, 0x4E, 0x27, 0x1D, 0x8B, 0x30, 0xA6,
  34594. 0x67, 0x67, 0xD6, 0xE2, 0xD6, 0xD1, 0x99, 0xA4,
  34595. 0x55, 0x73, 0x19, 0x32, 0xF6, 0x0B, 0x6B, 0x4A,
  34596. 0xEE, 0x23, 0x33, 0x38, 0x30, 0x68, 0x6F, 0x8E,
  34597. 0x60, 0xA9, 0x60, 0x97, 0x3E, 0xEA, 0x5D, 0xE1,
  34598. 0x40, 0x6F, 0x0C, 0x76, 0x84, 0xCF, 0xAF, 0x86,
  34599. 0x8D, 0x36, 0xE5, 0x7D, 0xAE, 0x9A, 0x13, 0x70,
  34600. 0x22, 0x2A, 0x31, 0xFE, 0xC2, 0xFB, 0xE1, 0x58,
  34601. 0xA5, 0x4E, 0xEF, 0x10, 0x5B, 0x5E, 0xD4, 0x39,
  34602. 0xFC, 0xF9, 0x15, 0x64, 0x78, 0x43, 0x7D, 0x03,
  34603. 0x9F, 0x5B, 0xCB, 0x86, 0xD2, 0xEF, 0x28, 0xBD,
  34604. 0x14, 0xCB, 0x8A, 0x04, 0x1D, 0x59, 0x23, 0x53,
  34605. 0x4D, 0x13, 0xF9, 0x93, 0xFE, 0x19, 0x9C, 0xC3,
  34606. 0x3F, 0xD9, 0xC1, 0x12, 0x94, 0x84, 0x13, 0x95,
  34607. 0x8F, 0xD9, 0x10, 0xAB, 0x37, 0x69, 0x08, 0x04,
  34608. 0x4A, 0x97, 0x82, 0x28, 0x75, 0xBB, 0xC9, 0xF4,
  34609. 0x3F, 0x19, 0x6B, 0x00, 0x4C, 0x56, 0x16, 0x1F,
  34610. 0x50, 0x82, 0xD1, 0x45, 0xFF, 0x0C, 0x37, 0x28,
  34611. 0x04, 0xBB, 0x6C, 0x00, 0x97, 0x3A, 0x79, 0x2D,
  34612. 0x9A, 0xB9, 0xA5, 0x16, 0x52, 0x02, 0xA3, 0x86,
  34613. 0x81, 0xAA, 0x3A, 0x31, 0xE5, 0xB5, 0x44, 0x2D,
  34614. 0x34, 0xE2, 0x7A, 0xD8, 0xFE, 0xA1, 0x36, 0xC0,
  34615. 0x36, 0x65, 0x73, 0x12, 0x9F, 0x61, 0x3F, 0x59,
  34616. 0xC9, 0x68, 0xB6, 0x34, 0x41, 0x40, 0x25, 0xD6,
  34617. 0xE7, 0xAD, 0x25, 0x7D, 0xCB, 0xF1, 0x2A, 0xD8,
  34618. 0x53, 0x48, 0x9D, 0xBF, 0xB5, 0xD5, 0x61, 0x18,
  34619. 0x0E, 0x2A, 0x21, 0x3E, 0x61, 0x18, 0x07, 0x8E,
  34620. 0x6F, 0x9A, 0x96, 0xA8, 0x61, 0xFE, 0x8D, 0x66,
  34621. 0x1A, 0x21, 0x99, 0xD9, 0x60, 0x8B, 0xAC, 0x85,
  34622. 0x84, 0x3D, 0x41, 0xF9, 0x93, 0x35, 0x24, 0x32,
  34623. 0xFF, 0xC0, 0x8A, 0xFA, 0xBC, 0xA7, 0x85, 0x57,
  34624. 0x3C, 0x16, 0x83, 0xAE, 0x90, 0xDE, 0x40, 0x12,
  34625. 0xE4, 0x2B, 0xA2, 0x47, 0xA4, 0x92, 0x73, 0x54,
  34626. 0x6C, 0xA5, 0xB7, 0xEE, 0x62, 0xEA, 0x62, 0x37,
  34627. 0xD9, 0xD7, 0x73, 0x58, 0x43, 0xDB, 0x20, 0x60,
  34628. 0x8C, 0x4F, 0x87, 0x58, 0xB2, 0x2B, 0xC3, 0x40,
  34629. 0xB0, 0xC1, 0xB6, 0xB6, 0xA9, 0xCD, 0xCC, 0x05,
  34630. 0x4F, 0x38, 0x5F, 0x08, 0xB3, 0x3B, 0x08, 0x4D,
  34631. 0x78, 0x6B, 0x0D, 0x40, 0x46, 0xB9, 0x20, 0xDE,
  34632. 0x29, 0x6F, 0x23, 0x96, 0xDA, 0x02, 0xF5, 0x1C,
  34633. 0x1A, 0x1A, 0x36, 0xA3, 0x3A, 0xFA, 0x1D, 0x80,
  34634. 0x36, 0x3C, 0xF6, 0xB4, 0xDC, 0x2C, 0x88, 0x54,
  34635. 0xF7, 0x86, 0xC6, 0xF2, 0x15, 0xF8, 0x85, 0x33,
  34636. 0xFB, 0x21, 0x20, 0x59, 0xCE, 0x60, 0x4B, 0xE8,
  34637. 0xF1, 0xB7, 0x54, 0x17, 0x1E, 0x83, 0xCD, 0x82,
  34638. 0x39, 0x40, 0x14, 0x31, 0xEC, 0x89, 0xC8, 0xE2,
  34639. 0x6A, 0xAE, 0x3F, 0x49, 0x5B, 0x38, 0xE7, 0xCD,
  34640. 0xE2, 0xF6, 0xEF, 0x90, 0x51, 0x10, 0x83, 0x79,
  34641. 0x27, 0x80, 0x2F, 0x45, 0x78, 0x67, 0xAF, 0xF4,
  34642. 0x65, 0x95, 0x2D, 0xFE, 0x00, 0xF3, 0x2A, 0x60,
  34643. 0x00, 0xF7, 0x26, 0xFA, 0x3C, 0xAD, 0xA9, 0xAF,
  34644. 0xCA, 0xF6, 0x69, 0x48, 0x03, 0xBE, 0x18, 0x73,
  34645. 0x54, 0x06, 0x06, 0x3E, 0x4E, 0xAD, 0xFC, 0x8B,
  34646. 0xC3, 0x43, 0x24, 0x5D, 0xE9, 0xDE, 0x78, 0xDC,
  34647. 0xD0, 0xA7, 0x04, 0x77, 0xF0, 0x0D, 0xA3, 0x37,
  34648. 0x8C, 0x5F, 0x8B, 0xDF, 0xBE, 0x90, 0x1F, 0xA6,
  34649. 0xB3, 0x17, 0x9D, 0x68, 0x36, 0x45, 0x11, 0x60,
  34650. 0xFF, 0xF9, 0xBA, 0xDA, 0x80, 0xAA, 0x37, 0x57,
  34651. 0xDD, 0x34, 0x30, 0x42, 0x7A, 0x9C, 0x86, 0xB4,
  34652. 0x91, 0x30, 0xB8, 0xC0, 0xC4, 0x29, 0x15, 0x31,
  34653. 0xF3, 0x9A, 0xB0, 0xCD, 0xAC, 0x8C, 0x7C, 0x8C,
  34654. 0x4A, 0xDC, 0x76, 0xB6, 0x31, 0x30, 0xDE, 0x2D,
  34655. 0x81, 0x04, 0xC7, 0x48, 0x73, 0x69, 0x02, 0x40,
  34656. 0x30, 0x19, 0x66, 0x94, 0x21, 0x65, 0x13, 0x18,
  34657. 0xC2, 0x09, 0x14, 0x5F, 0xC4, 0x2F, 0xC4, 0xD6,
  34658. 0xA6, 0x05, 0x37, 0xAF, 0x72, 0x0C, 0x47, 0x02,
  34659. 0x29, 0x95, 0x08, 0x9D, 0xC9, 0x07, 0x31, 0x38,
  34660. 0xA9, 0xB5, 0xDA, 0x21, 0x76, 0x1D, 0x84, 0xD0,
  34661. 0x15, 0xAF, 0x2A, 0xA3, 0x69, 0x0A, 0xE9, 0x4F,
  34662. 0x75, 0x8A, 0x50, 0xA5, 0x11, 0xD4, 0x5F, 0xAF,
  34663. 0x70, 0x43, 0xCB, 0xD7, 0x03, 0x9E, 0xB0, 0xBD,
  34664. 0x19, 0x47, 0x94, 0x58, 0x22, 0x86, 0xC6, 0xE3,
  34665. 0x62, 0xD8, 0x63, 0x05, 0xD9, 0xE2, 0xE5, 0x4A,
  34666. 0x04, 0x54, 0x5A, 0x55, 0x25, 0xAD, 0x15, 0x5C,
  34667. 0x4B, 0x71, 0x25, 0xE1, 0x50, 0xE3, 0x62, 0x1B,
  34668. 0xD2, 0x43, 0x28, 0xD2, 0x84, 0xE4, 0xE2, 0x05,
  34669. 0xE3, 0x01, 0x4C, 0x8F, 0x38, 0x17, 0x49, 0xFD,
  34670. 0x3B, 0x52, 0x1A, 0x55, 0xB3, 0x1D, 0x69, 0x83,
  34671. 0xAB, 0x9E, 0xC4, 0x73, 0xEE, 0x64, 0x7A, 0x73,
  34672. 0x19, 0xEF, 0xCD, 0x7D, 0xB7, 0xF4, 0x2E, 0xCB,
  34673. 0x55, 0x2A, 0x8A, 0xCC, 0x8F, 0xF8, 0x4E, 0xFB,
  34674. 0xD2, 0x63, 0x8F, 0xF1, 0x10, 0x89, 0x02, 0x93,
  34675. 0x3E, 0xAC, 0xA4, 0xB4, 0x89, 0xC7, 0xF7, 0x8B,
  34676. 0x3E, 0xE1, 0xE8, 0x93, 0xB9, 0x8E, 0x36, 0x25,
  34677. 0xC1, 0xC0, 0xD9, 0x44, 0x81, 0xC0, 0x99, 0x3C,
  34678. 0x2B, 0x89, 0xF7, 0xDF, 0xDB, 0xD8, 0xCC, 0x84,
  34679. 0xE6, 0xFF, 0xFE, 0xAC, 0x21, 0x16, 0xF1, 0xE2,
  34680. 0xEF, 0x0A, 0x32, 0xA7, 0xDE, 0x87, 0x51, 0xEC,
  34681. 0xB1, 0x0C, 0x0B, 0xC7, 0x07, 0xD9, 0x9A, 0xF8,
  34682. 0xE8, 0xB0, 0xFE, 0xA5, 0x67, 0xAF, 0x53, 0x9F,
  34683. 0xEF, 0x23, 0xEF, 0x7D, 0xFF, 0xA8, 0x8E, 0xDE,
  34684. 0x97, 0x93, 0x32, 0xA6, 0x7C, 0xCF, 0x49, 0xBC,
  34685. 0x36, 0x0D, 0x88, 0x90, 0x89, 0x39, 0x76, 0xA8,
  34686. 0x82, 0x19, 0x02, 0xB6, 0x02, 0x82, 0xFE, 0xED,
  34687. 0x9C, 0x28, 0x8D, 0xB0, 0x1E, 0x2B, 0x2A, 0xCF,
  34688. 0xF3, 0x94, 0xFF, 0x66, 0x33, 0x93, 0x31, 0xD6,
  34689. 0xFC, 0xAF, 0xE7, 0xC5, 0x98, 0x01, 0x46, 0xCD,
  34690. 0xCB, 0xC4, 0x41, 0x13, 0x6D, 0x42, 0xF5, 0x13,
  34691. 0xDF, 0xF9, 0x97, 0x65, 0xD4, 0x7B, 0x6E, 0x10,
  34692. 0x79, 0x5D, 0x5A, 0x82, 0xA2, 0x49, 0x53, 0xA7,
  34693. 0x6D, 0x9C, 0xDD, 0x0A, 0x80, 0x98, 0x58, 0x07,
  34694. 0x30, 0xBF, 0x0B, 0x30, 0xAC, 0x24, 0x9E, 0xA0,
  34695. 0xE8, 0xE4, 0x7A, 0x0D, 0xD0, 0x50, 0x82, 0xAE,
  34696. 0xBB, 0xEC, 0x15, 0x30, 0x2A, 0xF2, 0xA7, 0xA6,
  34697. 0x6A, 0xC8, 0xAE, 0x1E, 0x14, 0x80, 0x7C, 0x18,
  34698. 0xE7, 0x2B, 0x88, 0x65, 0xB7, 0x93, 0x12, 0xB3,
  34699. 0xC1, 0x2A, 0x20, 0xAD, 0x3B, 0x2E, 0x84, 0xC4,
  34700. 0x0D, 0xA7, 0x62, 0x5C, 0x79, 0x52, 0x5D, 0x59,
  34701. 0xA4, 0x69, 0x5C, 0x26, 0xFD, 0x4F, 0x80, 0xCC,
  34702. 0xFE, 0x8E, 0x70, 0x72, 0xB1, 0x41, 0xE1, 0x75,
  34703. 0x53, 0x51, 0xCF, 0x4C, 0x0B, 0x57, 0xF2, 0xB8,
  34704. 0x59, 0x76, 0xE6, 0xEF, 0x6D, 0x74, 0xA6, 0x73,
  34705. 0x69, 0x7F, 0x7C, 0xB2, 0x35, 0xFE, 0x8A, 0x02,
  34706. 0x2F, 0xBE, 0x7C, 0x4D, 0x02, 0xBE, 0x8F, 0xFB,
  34707. 0x7A, 0x58, 0x45, 0xEC, 0xBA, 0x1B, 0xC6, 0xB9,
  34708. 0x8D, 0xF5, 0xB0, 0x82, 0xD1, 0xB4, 0x97, 0x86,
  34709. 0x9B, 0x33, 0x54, 0x49, 0x5B, 0x88, 0xD9, 0xB5,
  34710. 0xD0, 0x93, 0x8A, 0x00, 0x5D, 0x0F, 0x37, 0x88,
  34711. 0x57, 0xE3, 0xFA, 0x7E, 0x7B, 0xFA, 0x43, 0x74,
  34712. 0x8D, 0x64, 0x07, 0xD7, 0x07, 0x85, 0x4D, 0x49,
  34713. 0xBC, 0x83, 0xF5, 0xD4, 0x95, 0x3E, 0x3E, 0x09,
  34714. 0x65, 0xF3, 0xFC, 0x88, 0xA7, 0xF0, 0x46, 0x61,
  34715. 0x44, 0x7D, 0x76, 0xED, 0xC9, 0x8D, 0x0F, 0x8D,
  34716. 0xDA, 0x0D, 0x01, 0xC8, 0xB1, 0xA8, 0x9B, 0x4A,
  34717. 0xF0, 0xA3, 0x88, 0x54, 0xC1, 0xD6, 0x52, 0x97
  34718. };
  34719. #endif /* WOLFSSL_NO_ML_DSA_65 */
  34720. #ifndef WOLFSSL_NO_ML_DSA_87
  34721. static const byte seed_87_draft[] = {
  34722. 0x22, 0x5F, 0x77, 0x07, 0x5E, 0x66, 0xCE, 0x1C,
  34723. 0x99, 0xBA, 0x95, 0xB4, 0xFC, 0xDF, 0x25, 0x8B,
  34724. 0xBB, 0x6F, 0xA5, 0xFE, 0x9C, 0x34, 0x9F, 0x0F,
  34725. 0xDE, 0x3F, 0x71, 0xD5, 0x33, 0x9F, 0x6F, 0xD8
  34726. };
  34727. static const byte pk_87_draft[] = {
  34728. 0x8C, 0x52, 0x4B, 0xD9, 0xAC, 0x48, 0x5C, 0xC6,
  34729. 0x9A, 0xA0, 0x75, 0x64, 0xE1, 0x4F, 0x0F, 0x60,
  34730. 0x13, 0x0E, 0xDE, 0x34, 0x08, 0xA5, 0xD4, 0x81,
  34731. 0xFD, 0x76, 0xC2, 0x51, 0x74, 0x75, 0xA8, 0xFB,
  34732. 0x24, 0xBF, 0x9E, 0x97, 0x9C, 0xD2, 0x3E, 0xDA,
  34733. 0x8A, 0x1B, 0xB6, 0x76, 0xDA, 0x7D, 0x7F, 0x44,
  34734. 0xAD, 0x6B, 0xB9, 0xB0, 0x70, 0xD3, 0xD6, 0x44,
  34735. 0x7F, 0xBE, 0x6C, 0x0C, 0x71, 0x37, 0xC6, 0xFB,
  34736. 0x7B, 0x39, 0x83, 0x63, 0x9C, 0x41, 0x5C, 0xF2,
  34737. 0xC9, 0x15, 0xFF, 0xD4, 0x18, 0xEA, 0xA1, 0x4D,
  34738. 0xA9, 0xD1, 0xAD, 0x3C, 0x09, 0x8E, 0xA9, 0x05,
  34739. 0x34, 0x6C, 0xAA, 0x75, 0x78, 0xF8, 0x6B, 0x6E,
  34740. 0x52, 0xE6, 0x57, 0x55, 0x16, 0xF4, 0x92, 0x3E,
  34741. 0x74, 0x3F, 0x96, 0xA3, 0x2A, 0xD0, 0x0E, 0xEE,
  34742. 0xA1, 0xCE, 0x8A, 0x33, 0xF4, 0x87, 0xB9, 0xF3,
  34743. 0x22, 0x5D, 0x2D, 0x84, 0xCD, 0x27, 0x57, 0xCC,
  34744. 0xCF, 0xE6, 0xA3, 0x66, 0x24, 0x53, 0x0E, 0x52,
  34745. 0x8A, 0x2F, 0x64, 0xFC, 0xE7, 0x04, 0xE7, 0xA7,
  34746. 0x6C, 0x2E, 0x6A, 0xDC, 0x00, 0xEF, 0x9B, 0xEC,
  34747. 0x91, 0x07, 0xB9, 0x69, 0x8F, 0x11, 0x59, 0xFC,
  34748. 0x52, 0xEF, 0x4C, 0x36, 0x5A, 0xFD, 0xB1, 0x50,
  34749. 0xED, 0xC3, 0x43, 0x5E, 0x03, 0xBB, 0x70, 0x26,
  34750. 0x00, 0x6E, 0x5A, 0x55, 0x13, 0x51, 0xA4, 0xB1,
  34751. 0x5F, 0xB8, 0x9F, 0xD2, 0xE9, 0x98, 0x38, 0xE8,
  34752. 0xCF, 0x41, 0x73, 0xFD, 0x0D, 0xF1, 0xF6, 0x80,
  34753. 0x89, 0xE1, 0x51, 0x8D, 0xD4, 0xB5, 0x79, 0x27,
  34754. 0x76, 0xBD, 0xD9, 0x2F, 0xC7, 0xC7, 0x9B, 0xC7,
  34755. 0x99, 0x7F, 0x78, 0x84, 0xD2, 0xB8, 0x80, 0xC5,
  34756. 0xD2, 0xB7, 0xEE, 0xC8, 0x0A, 0xFE, 0x35, 0x59,
  34757. 0x84, 0x5D, 0x39, 0x08, 0x39, 0xBE, 0x5E, 0xBF,
  34758. 0x95, 0x93, 0xA7, 0x3E, 0xD0, 0x1E, 0xF6, 0x7D,
  34759. 0x50, 0x3F, 0xFB, 0x74, 0x47, 0x04, 0xA2, 0xDC,
  34760. 0x49, 0x48, 0x76, 0x2B, 0xC8, 0x43, 0x45, 0x75,
  34761. 0x72, 0x84, 0x4D, 0x15, 0x74, 0xE3, 0xEB, 0x37,
  34762. 0x83, 0x0A, 0x3B, 0x7C, 0xD4, 0x02, 0xC7, 0x6E,
  34763. 0xD5, 0xB4, 0xFC, 0x15, 0xF0, 0x5E, 0x76, 0x03,
  34764. 0x4C, 0xBB, 0x6A, 0x29, 0xDE, 0xBC, 0x7E, 0x2B,
  34765. 0x34, 0xB2, 0x14, 0x2A, 0x57, 0xCF, 0x1B, 0x39,
  34766. 0x73, 0xE5, 0x8B, 0xFF, 0x47, 0x50, 0x42, 0xDC,
  34767. 0x22, 0x6C, 0x7E, 0x13, 0x71, 0xF3, 0x37, 0x51,
  34768. 0x40, 0xF2, 0x90, 0x57, 0xAC, 0xB4, 0x64, 0x7C,
  34769. 0x5F, 0x92, 0x6D, 0x3F, 0xDC, 0xCC, 0xC8, 0xD2,
  34770. 0xE1, 0x6B, 0x81, 0xA9, 0xED, 0xCD, 0x0C, 0x8B,
  34771. 0x5B, 0x2E, 0x11, 0x89, 0x87, 0x42, 0x4B, 0xEC,
  34772. 0xAD, 0x40, 0xA5, 0xE5, 0xB4, 0x6D, 0x1C, 0xB4,
  34773. 0x01, 0x0A, 0x8E, 0x9F, 0x6F, 0x25, 0x92, 0x5D,
  34774. 0xFE, 0x6B, 0x6F, 0x24, 0x64, 0x5F, 0x9C, 0x88,
  34775. 0x86, 0x96, 0xE8, 0x79, 0x64, 0x5B, 0x6A, 0x3A,
  34776. 0x76, 0x21, 0x90, 0xCC, 0xB7, 0xD6, 0x26, 0x9D,
  34777. 0x35, 0x54, 0x79, 0xDF, 0x71, 0x90, 0x55, 0x2A,
  34778. 0x38, 0x52, 0xD1, 0xE9, 0x56, 0x73, 0xE7, 0x19,
  34779. 0x44, 0x6A, 0xD3, 0x10, 0x24, 0xB9, 0x4B, 0xF8,
  34780. 0xBB, 0xC9, 0x7B, 0x04, 0x66, 0x39, 0xCE, 0x12,
  34781. 0x3F, 0xDE, 0xC3, 0x75, 0xAF, 0x9F, 0x8D, 0x4C,
  34782. 0xF7, 0x16, 0x9B, 0xEB, 0x5F, 0xE5, 0x1B, 0xBF,
  34783. 0x82, 0x2C, 0x53, 0xBA, 0x2D, 0x98, 0xA4, 0xA0,
  34784. 0x14, 0xA2, 0xDE, 0x69, 0x7F, 0x03, 0x3C, 0x9E,
  34785. 0x4A, 0x57, 0xC6, 0xED, 0xF6, 0x10, 0x6A, 0x76,
  34786. 0x2A, 0x81, 0x92, 0x9F, 0x3E, 0xF0, 0xFD, 0xE9,
  34787. 0xB7, 0xB3, 0x8A, 0xF6, 0x1A, 0x19, 0x9A, 0x16,
  34788. 0x0F, 0x09, 0x45, 0xBD, 0xBB, 0x96, 0x7C, 0x72,
  34789. 0x40, 0xFE, 0x94, 0xBD, 0xE1, 0x60, 0x50, 0x53,
  34790. 0x13, 0xC9, 0x2B, 0xFA, 0x52, 0x40, 0xA2, 0xA7,
  34791. 0xF0, 0x8C, 0x85, 0x78, 0xDB, 0xD6, 0x7F, 0x21,
  34792. 0x39, 0xB5, 0x06, 0x72, 0xEE, 0x99, 0xA1, 0xBD,
  34793. 0x78, 0x1F, 0xA4, 0xE9, 0x54, 0xF4, 0xFA, 0xDF,
  34794. 0xA7, 0x9E, 0xDD, 0x8E, 0xB1, 0xCF, 0xA8, 0x48,
  34795. 0x84, 0x5D, 0x70, 0xCB, 0x2D, 0xA9, 0x66, 0x09,
  34796. 0x0B, 0x75, 0x75, 0xA2, 0x32, 0xFE, 0xDF, 0x96,
  34797. 0x33, 0x84, 0xA7, 0x84, 0x48, 0x1A, 0xFA, 0x82,
  34798. 0x79, 0x0A, 0x87, 0xE1, 0x1F, 0x11, 0x74, 0xD4,
  34799. 0x3C, 0xC0, 0x8D, 0x4F, 0xD2, 0x5D, 0xBB, 0x40,
  34800. 0x10, 0xB2, 0x6F, 0x23, 0xD2, 0xD6, 0xF4, 0xA5,
  34801. 0x87, 0xEF, 0x7D, 0xE8, 0xC6, 0xF7, 0xC6, 0x0F,
  34802. 0xF9, 0x6F, 0xF8, 0x4C, 0x39, 0xE4, 0x82, 0x1E,
  34803. 0x1E, 0x6A, 0x80, 0x2F, 0xEC, 0x22, 0xD6, 0xA0,
  34804. 0xAA, 0xB6, 0x2C, 0xCB, 0x16, 0x43, 0x68, 0xC2,
  34805. 0x27, 0xF6, 0xA2, 0x31, 0x62, 0x66, 0xEC, 0x2F,
  34806. 0xFF, 0x8D, 0xB4, 0x19, 0x51, 0x19, 0xA0, 0x8C,
  34807. 0x67, 0xE2, 0x04, 0x04, 0xB9, 0x1F, 0x08, 0x70,
  34808. 0x9E, 0xAA, 0xC2, 0xDE, 0xCB, 0x96, 0x19, 0x8F,
  34809. 0x02, 0x74, 0x10, 0xCC, 0x1B, 0x82, 0x5D, 0x9C,
  34810. 0x07, 0x00, 0xE5, 0xD7, 0x04, 0x51, 0xBA, 0x7F,
  34811. 0x67, 0xF9, 0x64, 0x0C, 0xA3, 0x6B, 0xF3, 0x12,
  34812. 0x21, 0x80, 0x68, 0xD6, 0xA2, 0xCA, 0xFF, 0x59,
  34813. 0x33, 0x43, 0x7D, 0x67, 0xBF, 0xD4, 0x88, 0x4A,
  34814. 0x6E, 0x92, 0xBA, 0x41, 0xE1, 0x28, 0xDA, 0xEB,
  34815. 0xE1, 0xEA, 0x25, 0x60, 0xE1, 0x2F, 0xED, 0x2C,
  34816. 0xD4, 0x4B, 0xC9, 0x4E, 0x9E, 0x9D, 0xFA, 0xBB,
  34817. 0xF9, 0x61, 0x41, 0x4C, 0x24, 0x24, 0xFC, 0x9B,
  34818. 0x62, 0xFE, 0x73, 0x74, 0xF6, 0xB8, 0x9B, 0xA9,
  34819. 0x02, 0x96, 0xF4, 0x90, 0x18, 0xA7, 0xF5, 0x49,
  34820. 0xC1, 0xA3, 0x94, 0xB8, 0xED, 0xBD, 0x0B, 0xF3,
  34821. 0xDB, 0xF3, 0xBC, 0x10, 0x6A, 0x6B, 0x3F, 0x79,
  34822. 0x07, 0xF2, 0x11, 0x09, 0xD5, 0x42, 0x8F, 0xA9,
  34823. 0x09, 0x94, 0xBE, 0xF2, 0x0D, 0x3A, 0x91, 0x33,
  34824. 0x01, 0x31, 0x34, 0xBF, 0x0A, 0xCA, 0xF1, 0x3E,
  34825. 0x66, 0x18, 0xA6, 0x69, 0xEC, 0xEA, 0xC5, 0xE9,
  34826. 0x8B, 0x80, 0xFE, 0x4D, 0x93, 0x7B, 0xD4, 0xE5,
  34827. 0x74, 0x90, 0xFA, 0xFD, 0xCE, 0x45, 0xE8, 0xD7,
  34828. 0xD8, 0x8F, 0x08, 0x8B, 0x3A, 0xA8, 0x01, 0xA2,
  34829. 0xB4, 0xE5, 0xF2, 0x29, 0x41, 0x02, 0xBD, 0xCB,
  34830. 0xF9, 0x4A, 0x62, 0x54, 0x99, 0x94, 0x61, 0xB7,
  34831. 0x8F, 0xA5, 0x8A, 0x7F, 0xDC, 0xAD, 0xD2, 0xF2,
  34832. 0x28, 0x1E, 0xF3, 0x18, 0xAE, 0x21, 0x81, 0xF7,
  34833. 0xE9, 0xE5, 0xBF, 0x2B, 0xC2, 0x98, 0x24, 0xB1,
  34834. 0x45, 0x56, 0x57, 0x31, 0xA1, 0x48, 0xAB, 0x39,
  34835. 0xC2, 0x04, 0x29, 0x1B, 0x5B, 0xD3, 0x23, 0x35,
  34836. 0xCC, 0x5A, 0x58, 0x10, 0x11, 0x5B, 0xD5, 0x88,
  34837. 0xC2, 0x60, 0x37, 0x3D, 0x1C, 0x1C, 0x7B, 0x09,
  34838. 0x95, 0xB5, 0x05, 0x12, 0xD8, 0x52, 0x8D, 0xF5,
  34839. 0xBD, 0x4A, 0xA5, 0x45, 0x6F, 0x3D, 0x55, 0x9D,
  34840. 0x90, 0xAD, 0xD7, 0xA9, 0xD0, 0x25, 0x0B, 0xD7,
  34841. 0x55, 0x11, 0x5C, 0x60, 0xBF, 0xBD, 0xFB, 0x9D,
  34842. 0x2A, 0xCE, 0x4F, 0xE6, 0xB8, 0x36, 0x3A, 0x4D,
  34843. 0xE7, 0xB6, 0xFF, 0x6B, 0xD8, 0xBA, 0xD4, 0xEE,
  34844. 0x95, 0x9A, 0x0A, 0x47, 0xD4, 0x76, 0xE0, 0xF7,
  34845. 0xAC, 0x02, 0xB6, 0xA8, 0x10, 0x1E, 0xA5, 0x98,
  34846. 0xC0, 0xF4, 0x68, 0x5E, 0x55, 0xC1, 0x67, 0xCD,
  34847. 0x16, 0x31, 0xBD, 0xA2, 0x86, 0xF3, 0xF8, 0xC0,
  34848. 0xED, 0x4A, 0xFF, 0xE8, 0xF5, 0x2C, 0xFA, 0xD2,
  34849. 0x06, 0x78, 0x6D, 0x34, 0xBE, 0xF9, 0x15, 0x84,
  34850. 0x6D, 0xE5, 0x5F, 0xA4, 0xAC, 0x84, 0x3B, 0x3A,
  34851. 0xA6, 0x2D, 0xC2, 0x01, 0xE0, 0x63, 0x92, 0xC7,
  34852. 0x77, 0xB5, 0x4E, 0x2C, 0x40, 0x90, 0x48, 0xAF,
  34853. 0x8B, 0xE9, 0x6C, 0x1E, 0xEE, 0x16, 0x8F, 0x4E,
  34854. 0x4F, 0xFF, 0x35, 0x15, 0xE5, 0x51, 0xF4, 0xB2,
  34855. 0x23, 0x1C, 0x6A, 0xCE, 0x05, 0xDC, 0xDC, 0xAD,
  34856. 0x7F, 0x9D, 0xDA, 0xB3, 0x0C, 0xAD, 0x9C, 0x62,
  34857. 0x68, 0xD6, 0x84, 0x00, 0x76, 0xFF, 0xD3, 0x01,
  34858. 0x18, 0xB0, 0xC4, 0xE5, 0xE5, 0x0D, 0x87, 0x8E,
  34859. 0xAF, 0x77, 0xEE, 0xCB, 0x56, 0x88, 0x7F, 0xED,
  34860. 0xC5, 0x7C, 0x54, 0xD6, 0x28, 0x46, 0xE0, 0x8C,
  34861. 0xE6, 0x87, 0xF2, 0x4D, 0x0D, 0x2F, 0x12, 0x62,
  34862. 0x06, 0xDF, 0xB2, 0x4E, 0x03, 0x04, 0x78, 0x0B,
  34863. 0x03, 0x4C, 0xCE, 0x86, 0xD1, 0xCD, 0x53, 0x00,
  34864. 0xED, 0xC6, 0xF8, 0x9A, 0xCB, 0x59, 0x14, 0xA6,
  34865. 0x0C, 0x87, 0x35, 0x92, 0x66, 0x0D, 0x02, 0xA9,
  34866. 0xEF, 0x0D, 0x7D, 0xC6, 0x45, 0xF3, 0x11, 0xEF,
  34867. 0x1F, 0x55, 0x72, 0x1F, 0x1B, 0x45, 0xD2, 0xE4,
  34868. 0x8F, 0x3F, 0x9F, 0xEB, 0x27, 0x02, 0xD8, 0x2C,
  34869. 0xEF, 0xAD, 0x7E, 0x7E, 0x10, 0xDD, 0x91, 0x5E,
  34870. 0x39, 0x06, 0x7C, 0x39, 0xEA, 0x61, 0xB9, 0xCC,
  34871. 0xF1, 0x45, 0x56, 0x81, 0x53, 0x55, 0x42, 0xD4,
  34872. 0x37, 0x0F, 0x53, 0xF0, 0x7F, 0xA0, 0xC6, 0x50,
  34873. 0x9B, 0x1D, 0xC6, 0x7E, 0x9F, 0x1D, 0x89, 0x3B,
  34874. 0xEB, 0x85, 0x59, 0x6D, 0x9C, 0x12, 0xEE, 0xAC,
  34875. 0xFC, 0xAE, 0xC0, 0xAE, 0x5F, 0xD4, 0x9C, 0x62,
  34876. 0xE7, 0x09, 0x8C, 0xFA, 0x80, 0x1A, 0x19, 0x09,
  34877. 0x0F, 0x8D, 0x68, 0x9E, 0x45, 0x33, 0xE2, 0x58,
  34878. 0x7B, 0xEF, 0xC7, 0x6A, 0xDC, 0x38, 0x33, 0x3E,
  34879. 0x5C, 0x53, 0xB5, 0x99, 0xDB, 0x04, 0xA7, 0xEA,
  34880. 0xFB, 0x07, 0x9B, 0x25, 0x47, 0xED, 0xAC, 0x5A,
  34881. 0xAA, 0x1E, 0xE5, 0x23, 0xDE, 0x64, 0xE5, 0x87,
  34882. 0x46, 0x8C, 0x41, 0x52, 0xC9, 0x4F, 0x90, 0x48,
  34883. 0x1C, 0xAA, 0xA6, 0xB0, 0x3A, 0x1E, 0xC9, 0x08,
  34884. 0xF7, 0x82, 0x71, 0x13, 0x76, 0x6B, 0x9E, 0x52,
  34885. 0x22, 0x32, 0xE0, 0xC6, 0xF7, 0xD7, 0x4C, 0xBD,
  34886. 0xC3, 0x1C, 0x18, 0xAF, 0xA0, 0x12, 0xD3, 0x22,
  34887. 0x6A, 0xFC, 0x71, 0x8A, 0x64, 0x24, 0xAC, 0x19,
  34888. 0x4E, 0x85, 0x3C, 0x51, 0xE6, 0xA3, 0xAD, 0xA9,
  34889. 0x59, 0x94, 0xD2, 0x7F, 0xC4, 0x9D, 0x93, 0x5B,
  34890. 0x51, 0xD7, 0xF3, 0x03, 0xE7, 0x7D, 0x5B, 0x13,
  34891. 0x0E, 0xCD, 0x7D, 0x0F, 0x77, 0x3E, 0x84, 0xD7,
  34892. 0x4E, 0x69, 0x57, 0x1B, 0x73, 0x99, 0xC9, 0x4D,
  34893. 0xC0, 0x19, 0x6B, 0x9D, 0x5F, 0xBA, 0x69, 0xEE,
  34894. 0x11, 0xBD, 0x7C, 0x45, 0xD9, 0xA9, 0x65, 0x88,
  34895. 0xA7, 0x0E, 0x16, 0xBF, 0xB3, 0x82, 0x5E, 0x5E,
  34896. 0x56, 0x13, 0x02, 0x7D, 0xB1, 0xDC, 0xF5, 0x4A,
  34897. 0x82, 0x73, 0x72, 0x35, 0x9B, 0x91, 0xAC, 0x04,
  34898. 0x69, 0xE9, 0xEA, 0x19, 0xC9, 0xD8, 0x59, 0xEB,
  34899. 0x8F, 0x22, 0x5F, 0x43, 0x11, 0x0C, 0xCF, 0xB4,
  34900. 0x16, 0x6C, 0x7D, 0x60, 0xCE, 0x14, 0x24, 0xAD,
  34901. 0xD7, 0x07, 0xC2, 0x4E, 0x98, 0xA0, 0xDE, 0x9E,
  34902. 0xE6, 0x31, 0xED, 0xF8, 0x5B, 0x9C, 0xAF, 0xF7,
  34903. 0x57, 0x59, 0x10, 0xA9, 0x92, 0xDC, 0x4F, 0x0C,
  34904. 0x2B, 0x88, 0x75, 0x19, 0x1D, 0xB3, 0xBF, 0x70,
  34905. 0x23, 0x17, 0xD5, 0x1A, 0x50, 0x30, 0x18, 0x14,
  34906. 0x1A, 0x14, 0xE6, 0x1D, 0x4F, 0x8A, 0x96, 0x3E,
  34907. 0xD8, 0x6E, 0xD9, 0xBF, 0x94, 0x4E, 0xDE, 0xB8,
  34908. 0xFF, 0xE1, 0x6F, 0xFD, 0x31, 0xE8, 0xFE, 0x43,
  34909. 0xC2, 0x40, 0x82, 0x45, 0x50, 0xFE, 0x1B, 0xBC,
  34910. 0x77, 0x4B, 0xB4, 0x30, 0xA7, 0xD4, 0x46, 0x32,
  34911. 0x6A, 0xF7, 0xC5, 0x92, 0xDA, 0x70, 0xB1, 0xB7,
  34912. 0xA1, 0x5A, 0x5D, 0x17, 0x3B, 0xDB, 0x2F, 0x28,
  34913. 0x8A, 0x6E, 0xEC, 0xDA, 0xC4, 0xF7, 0x2E, 0xCB,
  34914. 0xEB, 0x96, 0x60, 0x92, 0x1B, 0xDD, 0xD6, 0x13,
  34915. 0x7C, 0x85, 0x9F, 0x8A, 0x9A, 0xE9, 0x5F, 0xC4,
  34916. 0x24, 0xFD, 0x33, 0xDF, 0xB3, 0x98, 0x66, 0xF7,
  34917. 0xA1, 0x5A, 0xDC, 0x01, 0xC9, 0xFA, 0x37, 0xF1,
  34918. 0x7B, 0xD0, 0xF6, 0x66, 0x8A, 0x26, 0x7C, 0xC2,
  34919. 0x1B, 0xFF, 0x62, 0xBC, 0xFD, 0xCD, 0x47, 0xDA,
  34920. 0xEE, 0x75, 0xF2, 0xAC, 0x60, 0x69, 0x87, 0x26,
  34921. 0xCC, 0x92, 0x10, 0x1C, 0x92, 0xC1, 0x43, 0x09,
  34922. 0xE9, 0xCE, 0x7D, 0x05, 0x5C, 0x64, 0x55, 0xCB,
  34923. 0xBB, 0x7A, 0xAE, 0x05, 0xDB, 0x38, 0xD3, 0xD5,
  34924. 0xBB, 0xD9, 0x9F, 0xCB, 0xCF, 0xB7, 0x9C, 0xEF,
  34925. 0x7E, 0x7B, 0x2A, 0x6F, 0x84, 0x4E, 0x6A, 0x7F,
  34926. 0xD3, 0x5F, 0xF3, 0xB3, 0xC1, 0xF0, 0x02, 0x9C,
  34927. 0xA2, 0x4C, 0x86, 0x0E, 0x6B, 0xE2, 0x2B, 0x1D,
  34928. 0x1D, 0xB4, 0x55, 0x7F, 0x85, 0x54, 0x2D, 0x85,
  34929. 0x64, 0x89, 0x92, 0x19, 0x65, 0x44, 0xD7, 0x95,
  34930. 0x48, 0x2C, 0x46, 0x8D, 0x0E, 0xBA, 0xFB, 0x13,
  34931. 0x63, 0x52, 0x2E, 0x22, 0x19, 0x3F, 0x7F, 0xFB,
  34932. 0x54, 0x4D, 0x73, 0xA1, 0x3C, 0x22, 0xD6, 0x5D,
  34933. 0x2B, 0x4A, 0xBD, 0xD7, 0xBB, 0x72, 0x55, 0x80,
  34934. 0xD4, 0x57, 0x4E, 0xDC, 0xF2, 0x8B, 0xB3, 0x09,
  34935. 0x6A, 0xF9, 0x1A, 0xD3, 0x41, 0x0E, 0x72, 0x95,
  34936. 0x49, 0xE7, 0xD1, 0xDC, 0x05, 0x22, 0xC3, 0x3E,
  34937. 0x26, 0x95, 0x00, 0x01, 0x8C, 0xE1, 0x54, 0x47,
  34938. 0x84, 0x10, 0xA7, 0x67, 0x45, 0xBB, 0xB9, 0x7B,
  34939. 0x0B, 0xB4, 0x74, 0x82, 0xED, 0x6C, 0x26, 0x6E,
  34940. 0xF2, 0x56, 0xCA, 0x1A, 0xD1, 0x10, 0x68, 0x40,
  34941. 0x28, 0x23, 0xD5, 0x98, 0xB3, 0x6B, 0x75, 0x16,
  34942. 0x13, 0x87, 0xE1, 0xF2, 0x3F, 0xAB, 0xC0, 0x2A,
  34943. 0xF0, 0x16, 0x59, 0x85, 0x1A, 0x5B, 0x41, 0xB7,
  34944. 0x52, 0xB1, 0x79, 0x46, 0x20, 0xDF, 0x59, 0xFB,
  34945. 0x33, 0xB3, 0x05, 0xF1, 0x12, 0x8B, 0xDB, 0x7C,
  34946. 0x51, 0x90, 0xC9, 0x8A, 0xC9, 0x48, 0x10, 0x54,
  34947. 0xF4, 0x0F, 0x88, 0x1D, 0xDB, 0x40, 0x1B, 0x3A,
  34948. 0xD7, 0x62, 0xD1, 0x75, 0x73, 0xD6, 0xCA, 0x23,
  34949. 0x26, 0xB2, 0xBF, 0x4C, 0xCA, 0x22, 0xDD, 0xF6,
  34950. 0xAF, 0x22, 0xB8, 0x4F, 0xC2, 0xC3, 0xB3, 0xD3,
  34951. 0xED, 0xFA, 0xBA, 0x2E, 0x38, 0x28, 0x6A, 0xAE,
  34952. 0x60, 0xE9, 0x2D, 0x11, 0x33, 0xED, 0x7E, 0xE9,
  34953. 0x29, 0x8E, 0x01, 0xB0, 0x0F, 0x13, 0x83, 0x44,
  34954. 0x17, 0xFA, 0xB6, 0x54, 0x7C, 0xAC, 0x1F, 0xED,
  34955. 0xC9, 0x22, 0xF2, 0x4F, 0x69, 0x24, 0x04, 0xFE,
  34956. 0xC2, 0x6A, 0xEB, 0xB0, 0xE4, 0xF5, 0x03, 0xCB,
  34957. 0xB3, 0x99, 0x50, 0x66, 0x1F, 0x6B, 0xF3, 0xFE,
  34958. 0xB7, 0xBF, 0x8D, 0xBA, 0x59, 0x75, 0x75, 0x51,
  34959. 0xB0, 0xA5, 0xB9, 0x66, 0xC8, 0xDD, 0x35, 0xAE,
  34960. 0x20, 0x66, 0x21, 0x9B, 0x04, 0x3F, 0xC6, 0x90,
  34961. 0x6F, 0x2B, 0x5C, 0x78, 0x49, 0x3C, 0x40, 0xE6,
  34962. 0xF9, 0x6B, 0x1A, 0xEF, 0xCE, 0x5A, 0xC1, 0x68,
  34963. 0xD3, 0x34, 0x05, 0xD0, 0x21, 0x6C, 0xF8, 0xA8,
  34964. 0x55, 0xE4, 0x6E, 0x80, 0x9B, 0xAD, 0xA5, 0xC3,
  34965. 0x55, 0x0B, 0x28, 0xBB, 0x54, 0x02, 0xD4, 0xF6,
  34966. 0x82, 0x73, 0xAB, 0x56, 0x0B, 0xB1, 0x5F, 0x94,
  34967. 0xC3, 0xDA, 0x24, 0x1E, 0x7F, 0x62, 0x6B, 0x98,
  34968. 0x6B, 0x2A, 0xF3, 0x92, 0x37, 0x3A, 0xB9, 0xE6,
  34969. 0x27, 0xC4, 0xBB, 0xAB, 0xE4, 0x9A, 0x60, 0xD2,
  34970. 0xAE, 0xCE, 0xFD, 0x44, 0xEB, 0x1C, 0xCF, 0x74,
  34971. 0x54, 0xFC, 0xEC, 0x4F, 0xC2, 0xBA, 0xF4, 0x3B,
  34972. 0xAC, 0x03, 0xC7, 0x2E, 0xE6, 0x62, 0x44, 0x61,
  34973. 0x42, 0xC8, 0xAE, 0xF1, 0xB2, 0xA9, 0xAC, 0xE0,
  34974. 0xCE, 0x23, 0xAF, 0xCC, 0x86, 0x61, 0xFE, 0xC5,
  34975. 0xCB, 0xAC, 0x4A, 0x1B, 0x5C, 0xC7, 0x2B, 0xFF,
  34976. 0x8A, 0x20, 0x62, 0x0E, 0xB9, 0x1D, 0xDD, 0x93,
  34977. 0x19, 0x29, 0xE4, 0xD9, 0x13, 0x1D, 0x28, 0x32,
  34978. 0x03, 0x5A, 0xA6, 0x8E, 0x20, 0xC7, 0xD6, 0xC6,
  34979. 0x4D, 0x19, 0x17, 0xCC, 0x65, 0xB8, 0x84, 0x0C,
  34980. 0x38, 0xB4, 0xA9, 0x45, 0x2B, 0x91, 0x61, 0x79,
  34981. 0x87, 0x08, 0xA6, 0xBD, 0x28, 0x9A, 0x58, 0x48,
  34982. 0xD5, 0x58, 0xC6, 0xCE, 0xC2, 0xC5, 0x72, 0x16,
  34983. 0xD9, 0xF4, 0xED, 0x66, 0xAC, 0xFA, 0x93, 0xE8,
  34984. 0x26, 0x10, 0x3B, 0x3D, 0x8F, 0xEA, 0x51, 0xCC,
  34985. 0x82, 0xC0, 0xDB, 0xDF, 0xA7, 0x13, 0xFB, 0x1B,
  34986. 0x77, 0x7E, 0x6F, 0x9E, 0x3C, 0xC5, 0x86, 0x35,
  34987. 0x92, 0x5B, 0x6F, 0x76, 0xA1, 0x71, 0x0D, 0x8C,
  34988. 0xDC, 0x95, 0x9F, 0xAC, 0x2C, 0x8E, 0x21, 0x01,
  34989. 0x37, 0x06, 0x28, 0x64, 0x4C, 0x23, 0xE2, 0x75,
  34990. 0x0B, 0xA7, 0xA4, 0xF5, 0x90, 0x87, 0xD2, 0x43,
  34991. 0x71, 0x59, 0x7C, 0x8C, 0xCA, 0x77, 0x3B, 0xC5,
  34992. 0x36, 0x46, 0xF7, 0x2F, 0xD3, 0x47, 0x18, 0xD7,
  34993. 0xC9, 0x4E, 0x56, 0x2D, 0x49, 0x82, 0xAC, 0x7D,
  34994. 0xD7, 0x3D, 0xF1, 0xDD, 0x73, 0x8B, 0xE4, 0xA1,
  34995. 0x10, 0x85, 0xB6, 0x94, 0xBE, 0x6A, 0x5E, 0xEE,
  34996. 0xBD, 0x60, 0xEB, 0x95, 0x76, 0xA8, 0x52, 0xE1,
  34997. 0x47, 0x57, 0xA1, 0x9C, 0xEC, 0x44, 0xE5, 0x6F,
  34998. 0x68, 0x34, 0x7E, 0x19, 0xBE, 0xCE, 0x56, 0xC9,
  34999. 0xBE, 0xCE, 0xFC, 0xB8, 0x32, 0x6D, 0xCB, 0x84,
  35000. 0x59, 0xBF, 0x4D, 0xF6, 0xE1, 0x53, 0x41, 0x61,
  35001. 0x5C, 0xFB, 0xD2, 0x48, 0xA6, 0x7F, 0x05, 0xB2,
  35002. 0xFC, 0xE8, 0xB2, 0x8A, 0x55, 0x7D, 0x19, 0xC0,
  35003. 0x69, 0x3B, 0x91, 0x5D, 0x71, 0xE7, 0xBB, 0x72,
  35004. 0x7D, 0xB9, 0x64, 0x6E, 0x8B, 0x5B, 0x70, 0x51,
  35005. 0xB5, 0x69, 0x8C, 0xC0, 0xFC, 0x95, 0xB2, 0x43,
  35006. 0x08, 0xF8, 0x70, 0xE4, 0x6F, 0x87, 0xA7, 0xDF,
  35007. 0x23, 0x84, 0xEE, 0xCF, 0x73, 0x38, 0xDE, 0x99,
  35008. 0x4C, 0xF8, 0xF1, 0x2D, 0xA2, 0x68, 0x99, 0xE3,
  35009. 0x9B, 0xB8, 0xF6, 0xC1, 0x5C, 0x83, 0x07, 0xE9,
  35010. 0xB9, 0xE2, 0x51, 0x62, 0xC8, 0x53, 0xF1, 0xC2,
  35011. 0xF7, 0x57, 0x8A, 0xA0, 0x42, 0x3C, 0x18, 0x36,
  35012. 0xF3, 0x99, 0xFD, 0x34, 0xB2, 0xF0, 0x1D, 0xBA,
  35013. 0x43, 0xEA, 0x72, 0x1C, 0x0B, 0x37, 0x47, 0xBC,
  35014. 0xAF, 0xDA, 0x22, 0x1F, 0x1C, 0x08, 0x16, 0x13,
  35015. 0xBD, 0xAA, 0x07, 0xFD, 0x7E, 0xCA, 0x70, 0x57,
  35016. 0x74, 0xDF, 0x68, 0x6B, 0x9F, 0x2D, 0x56, 0xBD,
  35017. 0x21, 0x89, 0xFA, 0x09, 0x04, 0xCA, 0x09, 0xBD,
  35018. 0x4F, 0xE6, 0x15, 0xF5, 0x89, 0xAB, 0xAC, 0xB2,
  35019. 0xC9, 0xBF, 0xC8, 0xBB, 0x87, 0x83, 0xB4, 0xD3,
  35020. 0xDC, 0xB1, 0x25, 0x9B, 0xAE, 0xC5, 0x75, 0x0C,
  35021. 0x9E, 0x6A, 0x83, 0x41, 0x85, 0x9D, 0x4B, 0xBF,
  35022. 0x62, 0x0C, 0x7D, 0x77, 0xC9, 0x89, 0xA6, 0xE1,
  35023. 0x28, 0xBD, 0x13, 0x5D, 0x41, 0x26, 0x80, 0x75,
  35024. 0x23, 0x57, 0xE7, 0x4F, 0x4D, 0x02, 0x8E, 0x0F,
  35025. 0x43, 0x67, 0xF6, 0xA6, 0xE6, 0xB6, 0x84, 0x8D,
  35026. 0xF5, 0x7B, 0x6A, 0x95, 0x73, 0x27, 0x86, 0x02,
  35027. 0x72, 0xCB, 0xDF, 0x77, 0x1C, 0x6C, 0x5E, 0xD3,
  35028. 0xF0, 0x1C, 0x82, 0x7A, 0x0D, 0xBB, 0x70, 0xA3,
  35029. 0x98, 0x8B, 0x7B, 0x4A, 0xFE, 0x2D, 0xB1, 0x5C,
  35030. 0x61, 0x89, 0x34, 0x4C, 0x81, 0x4B, 0x52, 0x17,
  35031. 0x03, 0x81, 0x54, 0x4F, 0x9E, 0x9E, 0x07, 0x16,
  35032. 0xF3, 0xD9, 0x18, 0x01, 0x11, 0xFD, 0x67, 0x18,
  35033. 0xA2, 0x64, 0x35, 0x42, 0x81, 0x80, 0x4A, 0xBA,
  35034. 0xCB, 0xD5, 0xF5, 0x4A, 0x10, 0x7F, 0xE2, 0xCF,
  35035. 0xA5, 0x1E, 0xCB, 0x0C, 0xAB, 0x3E, 0x03, 0x98,
  35036. 0x73, 0x89, 0xA4, 0x10, 0x75, 0xD5, 0xAC, 0x3D,
  35037. 0xCF, 0x56, 0x75, 0xD8, 0x86, 0xC2, 0x21, 0x42,
  35038. 0x99, 0x8D, 0x1B, 0x49, 0x09, 0xFE, 0x86, 0x41,
  35039. 0xC9, 0xDC, 0x87, 0x8D, 0x5A, 0xF0, 0xF5, 0xBE,
  35040. 0xF5, 0x49, 0x64, 0x5A, 0x7A, 0xC3, 0x5D, 0xE4,
  35041. 0xD6, 0xB7, 0x30, 0x92, 0x2A, 0x15, 0x86, 0x02,
  35042. 0xBE, 0xBA, 0x6E, 0xF6, 0x3D, 0x2D, 0x70, 0x89,
  35043. 0xFB, 0xB5, 0x1E, 0xBA, 0xDA, 0x20, 0x12, 0x49,
  35044. 0x22, 0xA0, 0xD8, 0x33, 0x9E, 0x4C, 0xC0, 0x27,
  35045. 0x0F, 0x9C, 0x1F, 0xD2, 0xA9, 0xF4, 0xD2, 0xA9,
  35046. 0x6D, 0xC5, 0x32, 0x16, 0x35, 0x9F, 0x19, 0x88,
  35047. 0xC1, 0xAA, 0xA4, 0x66, 0x33, 0xE6, 0x2C, 0x6A,
  35048. 0x6E, 0xA2, 0x1B, 0x33, 0xCB, 0xC3, 0x7E, 0xC5,
  35049. 0x31, 0x4D, 0x5C, 0x17, 0x4C, 0x33, 0x7F, 0x09,
  35050. 0x01, 0x33, 0x82, 0x84, 0x37, 0x03, 0xEB, 0x0E,
  35051. 0xB1, 0x5F, 0x1B, 0x60, 0x8A, 0x2C, 0x9F, 0x39
  35052. };
  35053. static const byte sk_87_draft[] = {
  35054. 0x8C, 0x52, 0x4B, 0xD9, 0xAC, 0x48, 0x5C, 0xC6,
  35055. 0x9A, 0xA0, 0x75, 0x64, 0xE1, 0x4F, 0x0F, 0x60,
  35056. 0x13, 0x0E, 0xDE, 0x34, 0x08, 0xA5, 0xD4, 0x81,
  35057. 0xFD, 0x76, 0xC2, 0x51, 0x74, 0x75, 0xA8, 0xFB,
  35058. 0x9A, 0xFE, 0xF5, 0x92, 0x58, 0xBB, 0x3C, 0xEB,
  35059. 0x4C, 0x5E, 0x83, 0xF9, 0xFF, 0xBC, 0x3B, 0x49,
  35060. 0xAE, 0xE1, 0xFC, 0x4B, 0x94, 0x4B, 0x8C, 0x75,
  35061. 0xD4, 0x67, 0x75, 0x66, 0x7D, 0x6B, 0xA4, 0xF2,
  35062. 0xDA, 0xC2, 0xB7, 0xC4, 0xD8, 0x50, 0x25, 0xCB,
  35063. 0x5A, 0xDB, 0xA4, 0xAD, 0xBB, 0x44, 0x20, 0x24,
  35064. 0x90, 0xEA, 0xA5, 0x2C, 0xAE, 0x80, 0x22, 0xC9,
  35065. 0x59, 0x02, 0xB7, 0x10, 0xB0, 0x5E, 0x1E, 0x5F,
  35066. 0x52, 0x7D, 0x88, 0xDA, 0xE2, 0x04, 0xBF, 0x45,
  35067. 0xA7, 0xA8, 0x49, 0x97, 0x7D, 0xAD, 0x7C, 0x7C,
  35068. 0x9E, 0x9C, 0x4A, 0xCC, 0x36, 0x33, 0x0F, 0x30,
  35069. 0xFA, 0xDE, 0x52, 0xE9, 0xAE, 0x23, 0x29, 0x13,
  35070. 0x10, 0x17, 0x8A, 0xD0, 0x08, 0x8E, 0xE1, 0x10,
  35071. 0x30, 0xD0, 0x84, 0x65, 0x92, 0x12, 0x2A, 0x81,
  35072. 0x26, 0x2E, 0x11, 0x14, 0x30, 0x61, 0x38, 0x61,
  35073. 0x64, 0x42, 0x05, 0x08, 0x91, 0x90, 0x4C, 0x06,
  35074. 0x82, 0xCC, 0x90, 0x45, 0x10, 0x39, 0x90, 0x22,
  35075. 0x40, 0x2A, 0x9B, 0x16, 0x26, 0x9A, 0xA8, 0x50,
  35076. 0x91, 0x12, 0x70, 0x91, 0x20, 0x4D, 0xC0, 0x34,
  35077. 0x90, 0x18, 0x28, 0x31, 0x10, 0x02, 0x11, 0x22,
  35078. 0xB3, 0x6C, 0x8B, 0xB8, 0x2C, 0x22, 0xB0, 0x69,
  35079. 0x53, 0x36, 0x31, 0x61, 0x42, 0x6C, 0xD9, 0x06,
  35080. 0x6A, 0xD9, 0x04, 0x45, 0xDB, 0x18, 0x05, 0x12,
  35081. 0x37, 0x4A, 0xD4, 0x06, 0x64, 0xD3, 0xA2, 0x85,
  35082. 0xA0, 0x38, 0x8A, 0x14, 0xA5, 0x85, 0x50, 0x20,
  35083. 0x85, 0xE4, 0xA8, 0x24, 0xC3, 0xC6, 0x31, 0xC9,
  35084. 0x34, 0x4E, 0xD2, 0x14, 0x68, 0x82, 0x90, 0x85,
  35085. 0xC4, 0x02, 0x61, 0x24, 0x38, 0x05, 0x01, 0xA3,
  35086. 0x50, 0x48, 0x08, 0x62, 0x20, 0xB0, 0x25, 0x5B,
  35087. 0xA6, 0x4D, 0x98, 0x92, 0x11, 0xC2, 0x06, 0x00,
  35088. 0xD1, 0xB0, 0x4D, 0x21, 0xA4, 0x8C, 0x01, 0x16,
  35089. 0x72, 0x11, 0xA6, 0x20, 0xD0, 0x16, 0x45, 0x10,
  35090. 0x31, 0x8E, 0xCB, 0xC2, 0x69, 0x02, 0x08, 0x91,
  35091. 0xD4, 0x30, 0x89, 0x03, 0x41, 0x05, 0x93, 0x16,
  35092. 0x8E, 0x5A, 0x18, 0x04, 0x41, 0x10, 0x6D, 0x18,
  35093. 0x42, 0x70, 0x53, 0x16, 0x31, 0x52, 0x30, 0x8E,
  35094. 0x0C, 0x49, 0x66, 0x0C, 0x90, 0x0C, 0xA4, 0x08,
  35095. 0x2E, 0x41, 0x92, 0x05, 0x24, 0x07, 0x30, 0x12,
  35096. 0x46, 0x72, 0x13, 0x99, 0x20, 0xE0, 0xA2, 0x4C,
  35097. 0x1B, 0x14, 0x52, 0x5A, 0x90, 0x05, 0x08, 0x82,
  35098. 0x31, 0x53, 0xC2, 0x90, 0xCC, 0x42, 0x68, 0x18,
  35099. 0xB0, 0x2C, 0x00, 0x80, 0x65, 0x58, 0x12, 0x84,
  35100. 0x19, 0x90, 0x08, 0x44, 0x26, 0x4A, 0x10, 0xA9,
  35101. 0x0C, 0x12, 0x25, 0x0C, 0x9C, 0x10, 0x25, 0x0C,
  35102. 0x28, 0x25, 0xD8, 0x46, 0x84, 0x1A, 0x22, 0x71,
  35103. 0x5B, 0x28, 0x6E, 0x98, 0x02, 0x51, 0x61, 0xB4,
  35104. 0x51, 0x01, 0xA1, 0x21, 0x24, 0x39, 0x12, 0xC8,
  35105. 0x08, 0x85, 0xD1, 0x34, 0x64, 0xA4, 0xA8, 0x04,
  35106. 0xA2, 0xC0, 0x09, 0x44, 0x48, 0x48, 0x03, 0x37,
  35107. 0x00, 0x20, 0x05, 0x4D, 0x20, 0xA4, 0x05, 0x11,
  35108. 0x18, 0x82, 0x42, 0x94, 0x4D, 0x24, 0x16, 0x01,
  35109. 0x02, 0x93, 0x4C, 0x00, 0x16, 0x06, 0xC1, 0xC0,
  35110. 0x0C, 0x8B, 0xC0, 0x41, 0x41, 0x06, 0x42, 0xA3,
  35111. 0xC6, 0x64, 0x1A, 0x85, 0x91, 0x41, 0x06, 0x49,
  35112. 0x04, 0xA7, 0x44, 0x82, 0x22, 0x6A, 0x50, 0x08,
  35113. 0x0E, 0x14, 0x18, 0x20, 0x4B, 0x88, 0x91, 0x01,
  35114. 0xA0, 0x49, 0x1A, 0x85, 0x4D, 0x94, 0x18, 0x10,
  35115. 0x0A, 0x05, 0x44, 0x94, 0x38, 0x05, 0x93, 0x40,
  35116. 0x68, 0x23, 0x07, 0x85, 0xE2, 0x12, 0x22, 0x9B,
  35117. 0xB8, 0x08, 0xD2, 0x10, 0x2A, 0x08, 0xA8, 0x10,
  35118. 0x92, 0x40, 0x2D, 0xD8, 0x44, 0x4C, 0xCC, 0x94,
  35119. 0x05, 0x24, 0x43, 0x4C, 0xD3, 0xC2, 0x48, 0x10,
  35120. 0x21, 0x2D, 0xC9, 0xB6, 0x08, 0xC9, 0x06, 0x4D,
  35121. 0xE1, 0x90, 0x20, 0x14, 0x24, 0x70, 0x5C, 0x84,
  35122. 0x28, 0xC0, 0xC2, 0x81, 0x22, 0x13, 0x50, 0x44,
  35123. 0x84, 0x91, 0xCA, 0xA2, 0x48, 0x12, 0x91, 0x05,
  35124. 0x5B, 0x92, 0x8D, 0x92, 0x92, 0x24, 0x82, 0x42,
  35125. 0x48, 0x03, 0x37, 0x46, 0xD8, 0x44, 0x86, 0x44,
  35126. 0x20, 0x89, 0xE4, 0xC2, 0x84, 0xC2, 0x04, 0x65,
  35127. 0x49, 0xA8, 0x4D, 0xA4, 0x38, 0x28, 0xDB, 0xA4,
  35128. 0x64, 0x24, 0x00, 0x51, 0xC8, 0x12, 0x6D, 0x19,
  35129. 0x82, 0x24, 0xCB, 0x00, 0x44, 0x4B, 0x20, 0x20,
  35130. 0x9B, 0x82, 0x4C, 0x5C, 0xA8, 0x08, 0xD2, 0xB6,
  35131. 0x8C, 0x08, 0x35, 0x20, 0xC0, 0x92, 0x45, 0xE3,
  35132. 0xB4, 0x2C, 0x50, 0x32, 0x0E, 0xD1, 0x82, 0x11,
  35133. 0x4A, 0x96, 0x08, 0x1C, 0x86, 0x29, 0x02, 0x19,
  35134. 0x71, 0x12, 0x03, 0x6E, 0x94, 0x08, 0x50, 0x12,
  35135. 0x27, 0x20, 0x0B, 0x10, 0x12, 0xA1, 0x18, 0x06,
  35136. 0x5A, 0x36, 0x4C, 0x93, 0xB4, 0x68, 0x21, 0xA7,
  35137. 0x28, 0x09, 0x34, 0x91, 0x18, 0x93, 0x49, 0x4A,
  35138. 0x32, 0x60, 0x00, 0x29, 0x2D, 0x94, 0x48, 0x44,
  35139. 0x09, 0x94, 0x2C, 0x21, 0x07, 0x6C, 0x41, 0x38,
  35140. 0x60, 0x8C, 0x10, 0x46, 0x11, 0x19, 0x65, 0x01,
  35141. 0x46, 0x60, 0x1A, 0x29, 0x42, 0x23, 0x30, 0x29,
  35142. 0x40, 0x96, 0x85, 0x81, 0xC6, 0x6C, 0x09, 0xA2,
  35143. 0x31, 0x23, 0xC9, 0x84, 0x18, 0x27, 0x61, 0x02,
  35144. 0xA6, 0x05, 0x1B, 0x11, 0x32, 0xD1, 0x80, 0x24,
  35145. 0x59, 0x22, 0x52, 0x21, 0x34, 0x64, 0x0A, 0x21,
  35146. 0x52, 0x10, 0xC2, 0x80, 0x5C, 0x98, 0x0D, 0x81,
  35147. 0xA0, 0x84, 0x14, 0x97, 0x04, 0xCC, 0xC2, 0x04,
  35148. 0x1A, 0x81, 0x45, 0x23, 0x44, 0x6C, 0x13, 0xC0,
  35149. 0x44, 0x59, 0xC2, 0x68, 0x64, 0x08, 0x52, 0x51,
  35150. 0x30, 0x71, 0x12, 0x49, 0x70, 0x12, 0x94, 0x84,
  35151. 0x80, 0x12, 0x12, 0x1B, 0x00, 0x50, 0x84, 0x10,
  35152. 0x45, 0x4A, 0x30, 0x10, 0x22, 0x95, 0x49, 0xC9,
  35153. 0x82, 0x24, 0x03, 0x35, 0x21, 0x18, 0x16, 0x72,
  35154. 0x09, 0x89, 0x65, 0x88, 0xB2, 0x89, 0x41, 0xB4,
  35155. 0x90, 0x92, 0x38, 0x8C, 0x08, 0x23, 0x26, 0x0B,
  35156. 0x80, 0x61, 0x84, 0x28, 0x6A, 0x4C, 0x98, 0x44,
  35157. 0x10, 0xB9, 0x30, 0x93, 0x02, 0x49, 0x22, 0x13,
  35158. 0x80, 0x1C, 0xC3, 0x48, 0x50, 0xA8, 0x20, 0x1C,
  35159. 0x05, 0x00, 0x5B, 0x02, 0x41, 0xD2, 0x84, 0x61,
  35160. 0x4B, 0x40, 0x46, 0x20, 0x21, 0x44, 0xD9, 0xC4,
  35161. 0x21, 0xD3, 0xA4, 0x4D, 0xC0, 0xC0, 0x09, 0x5B,
  35162. 0x28, 0x91, 0x18, 0x15, 0x41, 0x18, 0xC5, 0x4C,
  35163. 0x14, 0xB7, 0x61, 0xDB, 0x34, 0x25, 0x02, 0x06,
  35164. 0x41, 0x14, 0xA9, 0x65, 0x0B, 0x10, 0x04, 0x23,
  35165. 0xC7, 0x49, 0x13, 0x47, 0x0A, 0xD0, 0x30, 0x80,
  35166. 0x99, 0x32, 0x68, 0x50, 0x18, 0x06, 0xA2, 0x28,
  35167. 0x65, 0x13, 0x35, 0x82, 0xD3, 0x06, 0x81, 0x22,
  35168. 0x49, 0x4D, 0x48, 0x44, 0x30, 0xCA, 0x96, 0x2C,
  35169. 0x12, 0xC8, 0x08, 0xA1, 0x24, 0x2C, 0x52, 0xA8,
  35170. 0x28, 0x23, 0x14, 0x0A, 0xD4, 0x20, 0x4D, 0x18,
  35171. 0x12, 0x72, 0xD4, 0x80, 0x44, 0xDC, 0x26, 0x2C,
  35172. 0x88, 0x10, 0x0A, 0x04, 0x14, 0x51, 0xC1, 0x96,
  35173. 0x00, 0xA3, 0x40, 0x30, 0x99, 0x48, 0x92, 0x9B,
  35174. 0x08, 0x86, 0x81, 0x04, 0x20, 0x4C, 0xB2, 0x29,
  35175. 0x18, 0x31, 0x08, 0x09, 0x23, 0x8C, 0x4C, 0x02,
  35176. 0x6A, 0xCA, 0x00, 0x62, 0x09, 0x22, 0x2D, 0x21,
  35177. 0x00, 0x02, 0x0A, 0x39, 0x41, 0x04, 0xA3, 0x50,
  35178. 0x90, 0x80, 0x2D, 0x59, 0xB4, 0x71, 0x13, 0x16,
  35179. 0x31, 0x11, 0x90, 0x4C, 0xC3, 0x14, 0x20, 0x60,
  35180. 0xB2, 0x30, 0x0A, 0xB6, 0x24, 0x21, 0xA9, 0x10,
  35181. 0x89, 0x80, 0x88, 0x44, 0x06, 0x8A, 0x91, 0x22,
  35182. 0x8E, 0xD9, 0x36, 0x86, 0x10, 0x46, 0x0A, 0xE1,
  35183. 0x16, 0x85, 0x42, 0x40, 0x6C, 0x09, 0x49, 0x11,
  35184. 0xE0, 0x88, 0x68, 0x12, 0x08, 0x68, 0x5C, 0x26,
  35185. 0x24, 0x04, 0xA8, 0x70, 0xC8, 0x08, 0x05, 0x13,
  35186. 0x87, 0x41, 0x23, 0x29, 0x72, 0xC9, 0xB8, 0x88,
  35187. 0x1B, 0x22, 0x66, 0x11, 0xA5, 0x2D, 0x11, 0x29,
  35188. 0x12, 0x50, 0x12, 0x70, 0x03, 0x09, 0x6A, 0x4B,
  35189. 0x88, 0x4C, 0xD2, 0xC8, 0x31, 0x40, 0x26, 0x40,
  35190. 0x4C, 0x04, 0x50, 0x58, 0x16, 0x71, 0x90, 0xC2,
  35191. 0x00, 0x0A, 0x30, 0x8A, 0xDC, 0x24, 0x85, 0x19,
  35192. 0xB0, 0x65, 0x1A, 0xA3, 0x64, 0x13, 0xA3, 0x45,
  35193. 0xC8, 0x48, 0x91, 0x91, 0x12, 0x20, 0xDC, 0x42,
  35194. 0x40, 0x24, 0xC0, 0x4D, 0xA3, 0x98, 0x10, 0x40,
  35195. 0x26, 0x25, 0xDC, 0xB4, 0x68, 0x4B, 0xC2, 0x45,
  35196. 0x13, 0x06, 0x91, 0xC8, 0x92, 0x24, 0x82, 0xA8,
  35197. 0x20, 0x4C, 0x30, 0x48, 0x52, 0x06, 0x01, 0x0B,
  35198. 0x24, 0x51, 0x41, 0x36, 0x40, 0x93, 0xC4, 0x70,
  35199. 0x44, 0x40, 0x2C, 0x24, 0x28, 0x22, 0x81, 0xA4,
  35200. 0x4C, 0x43, 0x84, 0x60, 0x20, 0x23, 0x90, 0x01,
  35201. 0x94, 0x6C, 0xDB, 0x28, 0x21, 0x93, 0x30, 0x80,
  35202. 0x93, 0xC0, 0x25, 0xC8, 0xA6, 0x50, 0xCA, 0x24,
  35203. 0x26, 0xD1, 0x40, 0x31, 0x04, 0xC4, 0x8D, 0xE2,
  35204. 0xC0, 0x04, 0x08, 0x33, 0x8C, 0x18, 0x87, 0x91,
  35205. 0xC8, 0xC8, 0x71, 0x40, 0x46, 0x06, 0x00, 0x44,
  35206. 0x20, 0x22, 0x49, 0x70, 0x11, 0x45, 0x90, 0x02,
  35207. 0xC3, 0x61, 0x60, 0xB4, 0x25, 0x80, 0x16, 0x21,
  35208. 0x11, 0x09, 0x04, 0x88, 0x04, 0x05, 0xCC, 0x36,
  35209. 0x20, 0x01, 0xB1, 0x2C, 0x64, 0xB6, 0x50, 0x54,
  35210. 0x32, 0x42, 0x0B, 0x08, 0x8D, 0x12, 0x39, 0x0D,
  35211. 0x10, 0x29, 0x52, 0x88, 0xB0, 0x04, 0x11, 0x38,
  35212. 0x44, 0xD2, 0xA6, 0x71, 0x0B, 0x45, 0x48, 0x9C,
  35213. 0x34, 0x72, 0xA0, 0x28, 0x49, 0x82, 0x16, 0x86,
  35214. 0x12, 0x18, 0x61, 0x04, 0x41, 0x0D, 0x8A, 0xA6,
  35215. 0x41, 0x80, 0xA8, 0x61, 0xDA, 0x30, 0x65, 0x82,
  35216. 0x84, 0x30, 0x08, 0xA3, 0x29, 0x04, 0x33, 0x8E,
  35217. 0x02, 0x24, 0x0D, 0x9C, 0x44, 0x10, 0xC9, 0x02,
  35218. 0x81, 0x53, 0x06, 0x66, 0x8B, 0x06, 0x90, 0x03,
  35219. 0x87, 0x69, 0x21, 0xC9, 0x69, 0x83, 0x46, 0x4E,
  35220. 0x14, 0x24, 0x89, 0x8C, 0xA0, 0x6C, 0x99, 0xA2,
  35221. 0x2C, 0x11, 0x37, 0x66, 0x0C, 0xA6, 0x4D, 0xD3,
  35222. 0xC8, 0x70, 0x03, 0x02, 0x61, 0xC3, 0xB6, 0x65,
  35223. 0x23, 0xC1, 0x6C, 0x10, 0x34, 0x8D, 0x1A, 0xC1,
  35224. 0x31, 0x43, 0x40, 0x44, 0xD4, 0x08, 0x02, 0x0A,
  35225. 0x36, 0x20, 0xE3, 0x26, 0x42, 0x0A, 0x48, 0x26,
  35226. 0x1A, 0x13, 0x44, 0x0C, 0x18, 0x61, 0x91, 0x96,
  35227. 0x84, 0x02, 0x17, 0x46, 0x9C, 0x20, 0x40, 0x41,
  35228. 0xC6, 0x2D, 0x1B, 0x16, 0x0C, 0x98, 0xB2, 0x90,
  35229. 0x1A, 0x20, 0x84, 0xE2, 0x34, 0x2D, 0xCB, 0x14,
  35230. 0x44, 0x93, 0xC6, 0x8D, 0x58, 0xB2, 0x69, 0x22,
  35231. 0xB2, 0x88, 0xC0, 0xB8, 0x2D, 0xA2, 0xC2, 0x31,
  35232. 0x20, 0xA3, 0x24, 0x11, 0x46, 0x48, 0x4A, 0xA6,
  35233. 0x50, 0x24, 0x09, 0x21, 0x1A, 0x01, 0x0D, 0x20,
  35234. 0x36, 0x01, 0xC4, 0x34, 0x70, 0xDA, 0x16, 0x68,
  35235. 0x84, 0x22, 0x4C, 0x11, 0x14, 0x09, 0x13, 0xC4,
  35236. 0x68, 0x11, 0x41, 0x2D, 0x1C, 0x10, 0x31, 0xDC,
  35237. 0xB2, 0x64, 0x42, 0x36, 0x08, 0x5C, 0x10, 0x88,
  35238. 0x04, 0x91, 0x25, 0xE1, 0xA0, 0x20, 0x14, 0x18,
  35239. 0x12, 0x14, 0x94, 0x91, 0x4C, 0xC2, 0x24, 0xD4,
  35240. 0x06, 0x71, 0x21, 0x02, 0x8D, 0xD4, 0x88, 0x30,
  35241. 0xC9, 0x36, 0x0E, 0xE4, 0x82, 0x81, 0xC0, 0x04,
  35242. 0x6D, 0x24, 0x23, 0x09, 0x21, 0x45, 0x45, 0x20,
  35243. 0x06, 0x65, 0xC2, 0x30, 0x2A, 0x18, 0x30, 0x8E,
  35244. 0x24, 0x83, 0x89, 0x93, 0x32, 0x66, 0xC1, 0x48,
  35245. 0x45, 0x62, 0x48, 0x0A, 0x52, 0xB8, 0x80, 0x11,
  35246. 0x86, 0x21, 0x04, 0x34, 0x11, 0x24, 0xB5, 0x6C,
  35247. 0x50, 0x36, 0x0A, 0x19, 0xA7, 0x8C, 0x14, 0x90,
  35248. 0x0D, 0x1A, 0xA5, 0x68, 0x0B, 0xB1, 0x11, 0x50,
  35249. 0x40, 0x08, 0x48, 0xB6, 0x31, 0x14, 0x28, 0x8D,
  35250. 0xE3, 0x47, 0xB4, 0xA1, 0x44, 0x94, 0xCC, 0x9F,
  35251. 0x0B, 0x94, 0x9F, 0x25, 0x49, 0xD9, 0xB3, 0x8F,
  35252. 0x71, 0xF4, 0x17, 0xA4, 0xA6, 0xAC, 0x24, 0x58,
  35253. 0x14, 0x25, 0x03, 0xC8, 0x63, 0x3E, 0x10, 0xA8,
  35254. 0xD4, 0x10, 0xD7, 0x90, 0x4A, 0x28, 0x37, 0x90,
  35255. 0x70, 0x27, 0xE3, 0x56, 0x5F, 0x04, 0x67, 0x76,
  35256. 0xC3, 0x67, 0x3F, 0xF5, 0xA5, 0x11, 0xA2, 0x2C,
  35257. 0x11, 0x01, 0x5D, 0x63, 0x71, 0x1A, 0xE6, 0x70,
  35258. 0x86, 0x46, 0xAB, 0xCE, 0x03, 0xB6, 0x82, 0xAF,
  35259. 0x51, 0xBA, 0x81, 0x94, 0x9C, 0x82, 0x36, 0xA9,
  35260. 0x49, 0xA5, 0xA3, 0x11, 0x08, 0x8C, 0x4B, 0x13,
  35261. 0x41, 0xF0, 0x08, 0xFD, 0xB2, 0x99, 0xED, 0xA8,
  35262. 0x07, 0x61, 0x3C, 0x2E, 0xBC, 0x49, 0x7B, 0x1C,
  35263. 0xBC, 0x87, 0xBC, 0xAE, 0x5F, 0x5E, 0x8F, 0x5D,
  35264. 0xE7, 0xB9, 0x0C, 0x70, 0x36, 0x25, 0x61, 0xFD,
  35265. 0x95, 0x9F, 0xAE, 0x0F, 0x8D, 0xF3, 0xA2, 0x45,
  35266. 0x24, 0xA7, 0xDE, 0x60, 0xD1, 0x4E, 0x6D, 0xAC,
  35267. 0xC7, 0x6A, 0x32, 0x42, 0xC0, 0x73, 0xEB, 0x78,
  35268. 0x50, 0xF4, 0x49, 0x52, 0x5E, 0x6F, 0x81, 0x42,
  35269. 0x54, 0xF8, 0x82, 0x05, 0xC9, 0x64, 0x74, 0x6A,
  35270. 0x60, 0x5E, 0x36, 0x59, 0x40, 0x50, 0xA3, 0xFE,
  35271. 0xDA, 0xE2, 0x6D, 0x8D, 0x6E, 0xE4, 0x5A, 0x27,
  35272. 0x73, 0x89, 0xDB, 0x0C, 0x5B, 0x14, 0xD9, 0xED,
  35273. 0xB2, 0xC7, 0x1D, 0x71, 0x93, 0x91, 0x0A, 0x72,
  35274. 0x32, 0xBE, 0xA3, 0xD8, 0x95, 0x8C, 0x94, 0x7E,
  35275. 0x63, 0xEB, 0xCE, 0x8B, 0xFC, 0xB0, 0x3F, 0x77,
  35276. 0x5C, 0x43, 0x48, 0x18, 0x83, 0xFE, 0xC8, 0xDA,
  35277. 0x89, 0xF2, 0x3B, 0x54, 0x82, 0x44, 0xC6, 0x9C,
  35278. 0xCC, 0x77, 0x0A, 0xC1, 0x6F, 0xB9, 0x98, 0x10,
  35279. 0xD5, 0xF2, 0x60, 0xFF, 0x38, 0xD2, 0x0D, 0xD6,
  35280. 0x8C, 0x38, 0x54, 0x5B, 0xD8, 0x38, 0x84, 0x50,
  35281. 0x36, 0xF4, 0x02, 0xC1, 0x06, 0x0F, 0x15, 0x1B,
  35282. 0xC8, 0x90, 0x9B, 0x6E, 0x36, 0xC8, 0x3F, 0xE9,
  35283. 0x8B, 0x62, 0x15, 0x6F, 0xF0, 0xC2, 0x86, 0x7F,
  35284. 0xD1, 0xB5, 0x97, 0x53, 0xAE, 0x41, 0xAE, 0x21,
  35285. 0x84, 0xAC, 0x57, 0xA5, 0x1F, 0xA7, 0xC7, 0x24,
  35286. 0xDF, 0xDE, 0x2F, 0x3C, 0xCD, 0xA2, 0x7E, 0x1D,
  35287. 0x97, 0xE1, 0x96, 0xC5, 0xB4, 0x7D, 0xF9, 0x5F,
  35288. 0x7E, 0xEF, 0x09, 0xC4, 0xF3, 0x57, 0xF0, 0x51,
  35289. 0x73, 0xAB, 0x0E, 0x6A, 0xCA, 0x64, 0xE4, 0x99,
  35290. 0x0F, 0xD2, 0x20, 0xAC, 0x72, 0xF1, 0xA8, 0x23,
  35291. 0x8F, 0x94, 0x63, 0xDC, 0xB3, 0xBB, 0x62, 0x2C,
  35292. 0xEA, 0xA6, 0x27, 0x5A, 0x93, 0xC6, 0xCD, 0xCE,
  35293. 0x1E, 0x09, 0xAF, 0x89, 0xEC, 0x22, 0xE4, 0x30,
  35294. 0x2D, 0xB9, 0xCD, 0x08, 0x2E, 0x12, 0x76, 0x79,
  35295. 0x99, 0xBC, 0xA0, 0x34, 0x0B, 0xDA, 0x89, 0x08,
  35296. 0x14, 0x60, 0x7B, 0x98, 0xE6, 0xAF, 0xD2, 0xE1,
  35297. 0x87, 0xC8, 0xDA, 0x50, 0xF7, 0x10, 0x2C, 0x72,
  35298. 0x74, 0x50, 0xD0, 0x3C, 0x98, 0x06, 0xFE, 0xEB,
  35299. 0xC6, 0xC5, 0x69, 0x31, 0x06, 0xE2, 0x2E, 0x7E,
  35300. 0x7D, 0x3D, 0x2B, 0x1F, 0x48, 0x43, 0xC5, 0x95,
  35301. 0xDA, 0x84, 0x08, 0x1E, 0x2B, 0x50, 0x6D, 0x91,
  35302. 0xA6, 0x2B, 0xCD, 0x08, 0x43, 0x7B, 0xA2, 0xD8,
  35303. 0x60, 0x6E, 0xF7, 0x80, 0x08, 0xC3, 0x3F, 0x35,
  35304. 0xF3, 0x70, 0xA5, 0xC7, 0x56, 0xFC, 0xBD, 0x34,
  35305. 0x46, 0x7B, 0xBF, 0x63, 0x19, 0xAC, 0xB6, 0xC3,
  35306. 0x1B, 0x81, 0x84, 0x9F, 0xBB, 0x54, 0x05, 0x99,
  35307. 0xAE, 0x43, 0xE2, 0xA5, 0x20, 0xFD, 0x5C, 0xC7,
  35308. 0x25, 0x47, 0xB1, 0xFD, 0x80, 0xB5, 0x78, 0xC2,
  35309. 0x00, 0x98, 0x02, 0xB9, 0x61, 0x2A, 0xBA, 0x39,
  35310. 0xC7, 0x20, 0xB8, 0x7D, 0x7A, 0x03, 0x68, 0xE5,
  35311. 0x37, 0x71, 0x1F, 0x72, 0xAA, 0x41, 0x61, 0xB4,
  35312. 0xC0, 0xC2, 0xD3, 0x7A, 0xCD, 0xD2, 0xED, 0xC2,
  35313. 0xC5, 0x99, 0x8C, 0x62, 0xA3, 0x7D, 0xC8, 0x9C,
  35314. 0xD2, 0x50, 0x02, 0x0D, 0xCB, 0x68, 0x15, 0xB0,
  35315. 0xD6, 0x19, 0x03, 0xC8, 0x01, 0x12, 0x72, 0xA1,
  35316. 0x3A, 0xC2, 0xA6, 0x63, 0x51, 0x26, 0x03, 0x5D,
  35317. 0x3F, 0x1D, 0x3B, 0x0E, 0x30, 0x6B, 0xB7, 0xEC,
  35318. 0xB6, 0x8E, 0x2D, 0x76, 0xC8, 0xD7, 0xAE, 0x59,
  35319. 0x81, 0xFC, 0x5F, 0x57, 0x5E, 0xAD, 0xA0, 0x20,
  35320. 0xC8, 0xB4, 0x91, 0x2D, 0xEC, 0x03, 0xC4, 0xC6,
  35321. 0x55, 0x05, 0x87, 0xA4, 0xA2, 0x21, 0x09, 0x25,
  35322. 0x97, 0x21, 0xA4, 0x46, 0x45, 0x46, 0x40, 0x3B,
  35323. 0xDC, 0x6F, 0xCD, 0xFB, 0xFB, 0xD9, 0xF4, 0x2C,
  35324. 0xEC, 0xF1, 0xC4, 0x73, 0x41, 0x30, 0x60, 0x63,
  35325. 0x9A, 0xF2, 0xA5, 0x26, 0x78, 0x9A, 0x5E, 0x70,
  35326. 0x98, 0xDE, 0x35, 0x10, 0xA0, 0x5D, 0x45, 0xD5,
  35327. 0x95, 0xF7, 0x11, 0xBC, 0x99, 0xD3, 0x00, 0x67,
  35328. 0x9A, 0x30, 0x85, 0x36, 0x50, 0xDB, 0x18, 0xEA,
  35329. 0x6D, 0xB2, 0xF3, 0x14, 0xDA, 0x23, 0xE2, 0x8A,
  35330. 0x44, 0x21, 0x25, 0xD4, 0xA3, 0x28, 0x43, 0xA0,
  35331. 0xC6, 0x5C, 0x99, 0xB0, 0x72, 0x6B, 0xC2, 0x1A,
  35332. 0x30, 0xBE, 0x6B, 0x7B, 0xE0, 0x31, 0x54, 0x8C,
  35333. 0x29, 0xE5, 0xC6, 0x69, 0x53, 0xDE, 0x05, 0x1E,
  35334. 0x43, 0xCC, 0x7E, 0x9A, 0x82, 0x4A, 0xC4, 0x0A,
  35335. 0x50, 0x65, 0xDC, 0xD8, 0xF9, 0x01, 0x32, 0x65,
  35336. 0x1E, 0xF9, 0xA4, 0xCC, 0x07, 0xB9, 0x55, 0x97,
  35337. 0x45, 0xA9, 0x61, 0xF8, 0xBE, 0x99, 0x00, 0x12,
  35338. 0xD8, 0x17, 0x62, 0xFB, 0x89, 0xE7, 0x05, 0x5E,
  35339. 0x1B, 0xCD, 0x2B, 0x09, 0x6C, 0x5A, 0x5C, 0xA3,
  35340. 0x66, 0x4D, 0x02, 0x78, 0x0C, 0xC3, 0x63, 0x30,
  35341. 0xD0, 0xFA, 0x7B, 0x11, 0x00, 0x40, 0xDD, 0xF0,
  35342. 0x8C, 0x7C, 0xBA, 0x4C, 0x63, 0x78, 0xDA, 0xBB,
  35343. 0xDF, 0xF9, 0xC9, 0xA4, 0x40, 0x25, 0x86, 0xD1,
  35344. 0xBA, 0x22, 0xD7, 0x69, 0x98, 0x4E, 0x9D, 0x15,
  35345. 0x21, 0xA8, 0x56, 0xC0, 0xFF, 0x52, 0xE4, 0xB4,
  35346. 0x0F, 0xB2, 0x53, 0xE7, 0xA1, 0x34, 0x18, 0xEA,
  35347. 0x5B, 0x25, 0x42, 0x13, 0xE3, 0x13, 0xE7, 0xDF,
  35348. 0x54, 0x2B, 0x8D, 0x70, 0x51, 0xC7, 0x60, 0xB1,
  35349. 0x1E, 0x4D, 0x3A, 0x46, 0x04, 0xA1, 0x11, 0x43,
  35350. 0xAD, 0x24, 0x29, 0x90, 0xC9, 0x04, 0x15, 0xC5,
  35351. 0x07, 0xE5, 0x46, 0xB8, 0x50, 0x16, 0x6B, 0x66,
  35352. 0xFE, 0x1C, 0x8B, 0xFC, 0x20, 0x9C, 0xC4, 0x88,
  35353. 0x10, 0x36, 0x5E, 0x56, 0xE8, 0x45, 0x75, 0x89,
  35354. 0xFB, 0xD6, 0xD0, 0x8D, 0x9D, 0x53, 0xAE, 0x89,
  35355. 0x19, 0x54, 0xCF, 0xE1, 0xFF, 0x12, 0x13, 0xF2,
  35356. 0xC7, 0xBE, 0x4C, 0x1E, 0xB0, 0x70, 0x6E, 0xDC,
  35357. 0x0A, 0x64, 0x3B, 0x60, 0x3A, 0xEA, 0x0D, 0x41,
  35358. 0xDD, 0x8E, 0x09, 0xB9, 0x96, 0x8F, 0x6A, 0x49,
  35359. 0x50, 0xEF, 0xDF, 0xD7, 0x73, 0x8D, 0x16, 0x32,
  35360. 0xA8, 0x5C, 0x0A, 0x90, 0x18, 0xA1, 0xEB, 0x19,
  35361. 0xCC, 0x50, 0xD5, 0x59, 0xD7, 0x35, 0x3F, 0xBA,
  35362. 0x38, 0x1B, 0x5F, 0x71, 0x56, 0x70, 0xB3, 0x20,
  35363. 0x4D, 0x9E, 0x16, 0xA8, 0xF7, 0x35, 0x19, 0xD2,
  35364. 0x09, 0x0A, 0x22, 0x28, 0x81, 0x61, 0x26, 0x5B,
  35365. 0x9C, 0xEC, 0x9D, 0x4A, 0x61, 0xCF, 0x0D, 0x3C,
  35366. 0x88, 0xEA, 0x0B, 0x7A, 0xA7, 0xC6, 0xAE, 0x31,
  35367. 0xBE, 0xC2, 0xBA, 0x48, 0xBB, 0x9D, 0x06, 0xE1,
  35368. 0x32, 0x6D, 0x80, 0xCE, 0x27, 0x5C, 0x6F, 0x13,
  35369. 0x79, 0x35, 0x9F, 0x9C, 0x11, 0xEA, 0xDB, 0xF5,
  35370. 0x49, 0x15, 0xB6, 0x51, 0x86, 0xFC, 0x62, 0x34,
  35371. 0x3D, 0x58, 0x6B, 0x0E, 0xF8, 0x3B, 0xBB, 0x42,
  35372. 0xF6, 0x2D, 0x5C, 0xE2, 0xF3, 0xAA, 0x9F, 0x03,
  35373. 0x43, 0xE9, 0x9E, 0x90, 0xB9, 0xFF, 0x55, 0x93,
  35374. 0x60, 0xF8, 0x10, 0x2F, 0xFC, 0xBD, 0x40, 0x23,
  35375. 0xB8, 0x4F, 0x4C, 0x7A, 0x74, 0x9F, 0xDC, 0x55,
  35376. 0xDF, 0x5E, 0xCD, 0x23, 0xEB, 0xAC, 0x47, 0x4E,
  35377. 0x0D, 0x0F, 0xBE, 0xDE, 0x02, 0x64, 0x61, 0x7E,
  35378. 0x73, 0x78, 0x8E, 0x25, 0xE9, 0x7D, 0x66, 0xE5,
  35379. 0x82, 0xBF, 0x98, 0x5B, 0x36, 0xCE, 0x17, 0x72,
  35380. 0x56, 0x9C, 0xDA, 0x63, 0x77, 0x55, 0x8B, 0xA9,
  35381. 0x75, 0xF5, 0x28, 0xC3, 0x78, 0x6D, 0x8F, 0xC2,
  35382. 0x75, 0x5F, 0x28, 0x9E, 0x3F, 0xFB, 0xF1, 0xFD,
  35383. 0xB7, 0xDE, 0x05, 0x3C, 0xD3, 0xE8, 0xD7, 0x7A,
  35384. 0x7D, 0xC9, 0xF7, 0x9D, 0x58, 0xB4, 0xA6, 0x21,
  35385. 0x25, 0xFC, 0x52, 0x84, 0x21, 0xF6, 0x0B, 0x6D,
  35386. 0xA6, 0x62, 0x51, 0x97, 0xCD, 0xA9, 0xA1, 0x0C,
  35387. 0x88, 0x21, 0x67, 0xA5, 0xFB, 0x8C, 0x8A, 0x50,
  35388. 0xC5, 0x21, 0x91, 0x3A, 0xAB, 0x95, 0x96, 0xF3,
  35389. 0x30, 0x6D, 0x08, 0x42, 0x07, 0x4B, 0x78, 0x1F,
  35390. 0xC1, 0xD3, 0x41, 0x15, 0x68, 0xED, 0x93, 0x09,
  35391. 0xC7, 0x8B, 0xF9, 0x77, 0x25, 0xD3, 0xCE, 0x2B,
  35392. 0xA2, 0x0D, 0xB4, 0xC6, 0x84, 0x7F, 0x8E, 0xE5,
  35393. 0x24, 0x46, 0x59, 0x8D, 0x6F, 0x0F, 0x0C, 0xA8,
  35394. 0xFC, 0x04, 0x9B, 0x4D, 0x2B, 0xA7, 0x70, 0x1F,
  35395. 0x46, 0x7E, 0x76, 0x03, 0xC6, 0x7E, 0xA5, 0x3D,
  35396. 0x79, 0xE2, 0xF1, 0xAC, 0xBC, 0xDD, 0xF6, 0x91,
  35397. 0x69, 0x4C, 0x44, 0x1F, 0xC3, 0xBF, 0x9F, 0xFC,
  35398. 0x4E, 0xB0, 0x79, 0x30, 0x68, 0x89, 0xAC, 0xF2,
  35399. 0xD7, 0xC6, 0xE1, 0x6C, 0x37, 0xFB, 0xB3, 0x38,
  35400. 0x44, 0x2C, 0x97, 0xAB, 0xDA, 0x2C, 0x88, 0xC7,
  35401. 0xF2, 0x80, 0x08, 0x00, 0x4E, 0x44, 0xED, 0xBE,
  35402. 0xA4, 0x28, 0x3D, 0xC1, 0xCF, 0x9E, 0x83, 0xE7,
  35403. 0x2E, 0x7F, 0xF5, 0x08, 0x47, 0x26, 0xE0, 0xBD,
  35404. 0x1A, 0x17, 0xDB, 0x2F, 0xED, 0x19, 0x2E, 0x65,
  35405. 0x1B, 0x62, 0x5F, 0x08, 0x82, 0x10, 0x61, 0xCB,
  35406. 0xAA, 0xA7, 0xF8, 0x59, 0x4B, 0x46, 0xCB, 0xA2,
  35407. 0xCB, 0x41, 0x34, 0x30, 0x51, 0x58, 0x2A, 0xEE,
  35408. 0xE1, 0x5E, 0xAC, 0xCA, 0xBF, 0x37, 0x45, 0x98,
  35409. 0xBD, 0x93, 0x1B, 0x5A, 0x5E, 0x92, 0x14, 0x05,
  35410. 0x75, 0x2D, 0xFB, 0x8F, 0xBD, 0x24, 0x9B, 0x81,
  35411. 0xCD, 0xDD, 0xF5, 0xBE, 0x05, 0x0D, 0xBD, 0x4B,
  35412. 0x2B, 0x8C, 0x0A, 0xF0, 0x3A, 0x85, 0xD6, 0x74,
  35413. 0x65, 0x7F, 0x98, 0xF8, 0x57, 0xA2, 0x36, 0xA2,
  35414. 0xFE, 0xE4, 0xB4, 0xA4, 0x0D, 0xEA, 0x9A, 0xBE,
  35415. 0x41, 0x79, 0x68, 0x63, 0x70, 0x3F, 0x3E, 0x38,
  35416. 0x60, 0xC3, 0x40, 0x81, 0x72, 0xDD, 0x25, 0x34,
  35417. 0xB4, 0xFE, 0xAC, 0x41, 0x6E, 0x4A, 0xE7, 0xBF,
  35418. 0xE3, 0x87, 0xFA, 0x20, 0x8B, 0xBD, 0x68, 0x9E,
  35419. 0x06, 0xA9, 0x15, 0x23, 0x07, 0x04, 0x4B, 0xFA,
  35420. 0x45, 0x45, 0xB7, 0x75, 0xD3, 0x3E, 0x16, 0x70,
  35421. 0xF6, 0x26, 0xF2, 0x3A, 0x9D, 0xFB, 0xEA, 0xEB,
  35422. 0x47, 0xCE, 0x99, 0x6B, 0x0E, 0xB2, 0xE8, 0x2B,
  35423. 0x18, 0x15, 0x14, 0x2E, 0xF2, 0x14, 0x0D, 0x44,
  35424. 0x47, 0x1E, 0x63, 0x84, 0x5B, 0x3F, 0xA8, 0xEF,
  35425. 0x5F, 0xEB, 0xA0, 0x41, 0x77, 0xC1, 0xF4, 0x4F,
  35426. 0x8E, 0x2E, 0x29, 0xCD, 0xDB, 0xF2, 0x75, 0x24,
  35427. 0x24, 0x46, 0x73, 0xC3, 0x46, 0xB5, 0xCA, 0x13,
  35428. 0x35, 0x12, 0x0A, 0x8D, 0x88, 0x89, 0x17, 0x99,
  35429. 0x13, 0xCA, 0x66, 0x07, 0x67, 0x6B, 0x7B, 0x3B,
  35430. 0x20, 0xD3, 0x5F, 0x78, 0x1C, 0xC0, 0x99, 0x59,
  35431. 0x0A, 0xBA, 0x8F, 0xA0, 0xDB, 0xDF, 0xCC, 0x03,
  35432. 0xC4, 0xA6, 0xC7, 0x08, 0xB9, 0xFD, 0x95, 0xC2,
  35433. 0x45, 0xF9, 0xF3, 0x11, 0x62, 0xF7, 0x14, 0xB9,
  35434. 0xEB, 0x09, 0xB3, 0x7C, 0xF8, 0xF6, 0x67, 0xCC,
  35435. 0x03, 0xB3, 0x06, 0x6F, 0x60, 0xAC, 0x72, 0xF2,
  35436. 0xD3, 0x71, 0x6C, 0x4D, 0xAD, 0x3A, 0x99, 0x75,
  35437. 0x5C, 0x52, 0x2D, 0x87, 0x69, 0x3E, 0xD6, 0x7E,
  35438. 0x12, 0x96, 0xD3, 0x88, 0x8D, 0x11, 0x85, 0xAA,
  35439. 0x0A, 0xA5, 0x32, 0x90, 0x51, 0xC5, 0x65, 0x64,
  35440. 0xE0, 0xA9, 0x73, 0xA4, 0xF3, 0x8A, 0x32, 0x83,
  35441. 0xE5, 0x08, 0x09, 0x39, 0x6A, 0x90, 0x2C, 0xC3,
  35442. 0xFC, 0x92, 0x29, 0x7A, 0x45, 0xBE, 0x02, 0x79,
  35443. 0x15, 0x1B, 0xBB, 0x60, 0xBB, 0xD9, 0x42, 0xF1,
  35444. 0xE5, 0x14, 0xB4, 0xA5, 0xFF, 0x12, 0x42, 0x30,
  35445. 0xB0, 0xCB, 0xD0, 0x1D, 0xB4, 0x62, 0x49, 0xC5,
  35446. 0xB7, 0xDA, 0x37, 0x47, 0x2C, 0x8B, 0x16, 0xCA,
  35447. 0xD2, 0x2C, 0xA1, 0x24, 0xE6, 0x57, 0xFA, 0xEB,
  35448. 0x2C, 0x62, 0x2E, 0x12, 0x74, 0x37, 0x2B, 0x3F,
  35449. 0x56, 0x23, 0x9C, 0xED, 0x90, 0xDE, 0x0D, 0x6E,
  35450. 0x9E, 0x11, 0x78, 0xA4, 0x9C, 0xB3, 0xA1, 0x37,
  35451. 0xF7, 0x4B, 0x09, 0x61, 0xD8, 0x33, 0x1D, 0x80,
  35452. 0x68, 0x5C, 0xDD, 0xBD, 0x3E, 0xAE, 0x9D, 0xB8,
  35453. 0xBA, 0x42, 0x41, 0xDC, 0xC9, 0x93, 0xF1, 0x92,
  35454. 0x2F, 0x7A, 0xF9, 0xFE, 0x67, 0x13, 0x87, 0xBD,
  35455. 0x7D, 0x04, 0x17, 0x91, 0xB6, 0x03, 0x5E, 0xA0,
  35456. 0x5B, 0x23, 0xEA, 0x0C, 0xFA, 0x45, 0xCB, 0x1A,
  35457. 0xC5, 0x7F, 0x63, 0xD6, 0x3D, 0x3C, 0x66, 0x4A,
  35458. 0x83, 0x4E, 0x4E, 0x90, 0xA6, 0x63, 0xB0, 0x8A,
  35459. 0xD7, 0x0D, 0xB4, 0xB7, 0xA9, 0x0F, 0xC6, 0xC7,
  35460. 0x3B, 0xAD, 0x07, 0xA6, 0x94, 0x47, 0xDB, 0x63,
  35461. 0x26, 0x00, 0x18, 0x5E, 0x27, 0xB5, 0xE2, 0xE3,
  35462. 0xED, 0x8D, 0x97, 0x95, 0x38, 0x20, 0x24, 0x9F,
  35463. 0x40, 0x84, 0x44, 0x7E, 0x8C, 0x05, 0xAB, 0xB1,
  35464. 0x89, 0x26, 0x7D, 0x46, 0x2C, 0x9F, 0xE5, 0xC1,
  35465. 0x27, 0xCE, 0x1D, 0x5A, 0x9F, 0xF1, 0xF8, 0x57,
  35466. 0x8F, 0xCF, 0xB7, 0x4E, 0x07, 0xF3, 0xBA, 0x56,
  35467. 0xCF, 0xE9, 0x87, 0x21, 0x61, 0xD6, 0x97, 0x7B,
  35468. 0x26, 0x97, 0x07, 0xB4, 0x87, 0xFE, 0x25, 0x9C,
  35469. 0xA9, 0x8E, 0x06, 0x90, 0x17, 0x2C, 0x98, 0x26,
  35470. 0x23, 0xEE, 0xBB, 0x91, 0x8A, 0x15, 0x38, 0xA1,
  35471. 0x38, 0xCB, 0x8B, 0xA0, 0xF3, 0x4A, 0xF2, 0x12,
  35472. 0xA7, 0xB7, 0x05, 0xB6, 0x09, 0xD0, 0xEC, 0xDD,
  35473. 0x21, 0xB6, 0xFA, 0x29, 0x95, 0xB4, 0x08, 0xD5,
  35474. 0x95, 0xB7, 0xB8, 0x2E, 0x23, 0xAA, 0x89, 0x81,
  35475. 0xE2, 0xD0, 0xFD, 0x9C, 0x8D, 0xF0, 0xCA, 0x61,
  35476. 0xE3, 0x1E, 0x73, 0x9E, 0xD1, 0x72, 0x5C, 0x63,
  35477. 0xB8, 0x74, 0x0E, 0x2C, 0x27, 0x3A, 0x71, 0xF9,
  35478. 0xFE, 0x66, 0x33, 0xE9, 0x41, 0x27, 0x61, 0xA3,
  35479. 0xFA, 0xD8, 0x66, 0x2A, 0x52, 0x6D, 0xAB, 0xBF,
  35480. 0x32, 0xC2, 0x8E, 0x8F, 0xB0, 0x60, 0x52, 0xE1,
  35481. 0x96, 0xC8, 0x1E, 0x9A, 0x3E, 0x07, 0xFA, 0x34,
  35482. 0xFA, 0x9C, 0x4C, 0x0D, 0x29, 0x0F, 0x68, 0xA6,
  35483. 0x59, 0x28, 0x22, 0xB1, 0x99, 0x56, 0x2C, 0x01,
  35484. 0x04, 0x2F, 0x34, 0x65, 0xFD, 0xD4, 0xD0, 0xD5,
  35485. 0x17, 0x7C, 0x14, 0x92, 0x73, 0x6C, 0x31, 0xCE,
  35486. 0xD4, 0xB3, 0x59, 0x83, 0x6B, 0x34, 0x7C, 0x76,
  35487. 0x8C, 0xED, 0xD5, 0xE2, 0x4F, 0x39, 0x44, 0xBF,
  35488. 0x90, 0x53, 0x9A, 0xC7, 0xD4, 0x6A, 0x86, 0xA3,
  35489. 0xE2, 0x15, 0x59, 0xD0, 0x0F, 0x32, 0x92, 0xC2,
  35490. 0x9B, 0x9E, 0xE3, 0xF6, 0x94, 0x96, 0xFD, 0x0B,
  35491. 0xB6, 0x06, 0x8F, 0x0D, 0x1F, 0x38, 0xFC, 0x6F,
  35492. 0xA2, 0x78, 0xAC, 0xC5, 0xB5, 0x6A, 0x6B, 0xEC,
  35493. 0x78, 0x8A, 0x6F, 0xD8, 0x21, 0xB7, 0xCF, 0x66,
  35494. 0x73, 0x03, 0xCA, 0x2E, 0x3C, 0x7F, 0x2F, 0x29,
  35495. 0x41, 0xC9, 0x88, 0xFD, 0x0E, 0xA0, 0x43, 0xD6,
  35496. 0x9E, 0xB1, 0xE7, 0x13, 0x9C, 0xF0, 0x9C, 0xCF,
  35497. 0x33, 0x22, 0x57, 0xEF, 0xE5, 0xCE, 0xD9, 0xAC,
  35498. 0x7D, 0x34, 0x75, 0xBD, 0xAE, 0x84, 0xEE, 0xE8,
  35499. 0x5D, 0x8C, 0x55, 0x86, 0xBA, 0x19, 0xE5, 0x9D,
  35500. 0x35, 0x6D, 0xD8, 0x70, 0xC5, 0xE0, 0xEA, 0x77,
  35501. 0x3A, 0xE5, 0xB5, 0x2C, 0xD2, 0x28, 0xB5, 0xE8,
  35502. 0xAF, 0xB1, 0xD2, 0xC4, 0xE5, 0x59, 0x06, 0xB8,
  35503. 0x2E, 0xA6, 0x8F, 0xC4, 0x9B, 0x30, 0xF9, 0x37,
  35504. 0xDB, 0x29, 0xA1, 0x44, 0x0B, 0xB7, 0xB5, 0xB4,
  35505. 0x12, 0xD3, 0x4E, 0xB3, 0xB7, 0xD8, 0x2F, 0x19,
  35506. 0xDE, 0x3B, 0xC3, 0x53, 0xCE, 0x1C, 0x34, 0x4C,
  35507. 0xA4, 0x6A, 0xE2, 0xD0, 0x04, 0xDF, 0x3C, 0x53,
  35508. 0x8B, 0x06, 0x8F, 0x36, 0xE5, 0x77, 0xB2, 0x7A,
  35509. 0x1A, 0xC0, 0x0C, 0xBD, 0xA3, 0xA0, 0xEE, 0xB6,
  35510. 0x40, 0xAD, 0x5C, 0x04, 0xAE, 0xCF, 0x64, 0x2B,
  35511. 0x8A, 0x18, 0x58, 0x86, 0xDE, 0xC9, 0x3D, 0x7D,
  35512. 0x15, 0xBC, 0xEE, 0x4C, 0x22, 0xF4, 0x98, 0xD9,
  35513. 0x37, 0xEE, 0xE2, 0x40, 0x43, 0xFF, 0xB2, 0x6F,
  35514. 0x05, 0xC0, 0x0E, 0x30, 0xDE, 0xD8, 0x0C, 0x0B,
  35515. 0xAD, 0xED, 0xCC, 0xBC, 0x29, 0x95, 0x07, 0x40,
  35516. 0x10, 0x99, 0xA0, 0xD1, 0x08, 0xF7, 0xD5, 0xF1,
  35517. 0xAD, 0xC9, 0xDD, 0xC8, 0x6A, 0x1E, 0x9E, 0x06,
  35518. 0xDF, 0x12, 0xFF, 0x66, 0x33, 0x5E, 0x21, 0x47,
  35519. 0xC3, 0xDE, 0x36, 0x98, 0x5B, 0xBF, 0x42, 0x9E,
  35520. 0x30, 0xA0, 0x81, 0x5C, 0x28, 0x34, 0x1B, 0x3A,
  35521. 0x32, 0xBC, 0xDE, 0x52, 0x53, 0x25, 0x1E, 0xF6,
  35522. 0xE2, 0x99, 0x12, 0x92, 0x07, 0x1D, 0xEB, 0x08,
  35523. 0x36, 0xA7, 0xD5, 0x18, 0x1F, 0xDB, 0x44, 0xA7,
  35524. 0xE1, 0x13, 0x06, 0xB0, 0xDF, 0x63, 0x82, 0x68,
  35525. 0xEF, 0xF5, 0x2B, 0x04, 0x0B, 0x93, 0xE8, 0xB0,
  35526. 0x92, 0x7B, 0xDE, 0x1F, 0xC9, 0x39, 0x8F, 0x42,
  35527. 0x9D, 0x06, 0x22, 0x13, 0xC9, 0x97, 0x2F, 0x43,
  35528. 0x8A, 0xBA, 0xAF, 0xF9, 0x71, 0xE3, 0x55, 0x5D,
  35529. 0x06, 0x77, 0x38, 0x39, 0xA3, 0xED, 0x41, 0x63,
  35530. 0xFE, 0x2A, 0xB3, 0x23, 0x43, 0x0C, 0xF3, 0x17,
  35531. 0x3B, 0x69, 0xED, 0x32, 0x0A, 0x54, 0xF3, 0x8D,
  35532. 0x76, 0xC6, 0x09, 0xDD, 0x88, 0x5B, 0x23, 0x57,
  35533. 0x72, 0xC4, 0x87, 0xB8, 0x9D, 0xF7, 0xCA, 0xFB,
  35534. 0x7C, 0x61, 0x67, 0x5C, 0x65, 0xF8, 0xD6, 0xD7,
  35535. 0x1E, 0x95, 0xB9, 0x73, 0x4D, 0x2E, 0x1F, 0x43,
  35536. 0x3E, 0x2B, 0x58, 0x92, 0x15, 0x2E, 0xAA, 0x51,
  35537. 0xF0, 0xD4, 0xF2, 0xA6, 0xCD, 0x12, 0x21, 0xD6,
  35538. 0xCA, 0x46, 0x2A, 0xFF, 0xCB, 0x1B, 0x6B, 0xB4,
  35539. 0x09, 0x17, 0x3B, 0xA2, 0x94, 0xDF, 0x1D, 0x68,
  35540. 0x8B, 0x75, 0xEA, 0x11, 0xD6, 0x99, 0x04, 0xD1,
  35541. 0x00, 0xDB, 0x61, 0xBC, 0xF2, 0x3B, 0x88, 0x4B,
  35542. 0x33, 0xDF, 0x0F, 0xD4, 0xFB, 0x14, 0x0C, 0x6A,
  35543. 0x53, 0x61, 0x1F, 0xBD, 0x28, 0xB2, 0x11, 0x19,
  35544. 0x38, 0x71, 0x17, 0x76, 0x4D, 0xEE, 0x01, 0xC4,
  35545. 0x77, 0x53, 0x2A, 0xAF, 0xD3, 0x78, 0xFF, 0x45,
  35546. 0x7F, 0x97, 0x9D, 0x26, 0x92, 0x0E, 0xD9, 0x4E,
  35547. 0x34, 0x1D, 0xE8, 0xDD, 0xBF, 0x5F, 0x87, 0xE6,
  35548. 0x35, 0x9A, 0x39, 0x71, 0x59, 0x20, 0x01, 0xFB,
  35549. 0x53, 0x2C, 0x61, 0x38, 0x0C, 0x8C, 0x02, 0xD3,
  35550. 0xA0, 0x53, 0x95, 0x02, 0xED, 0x5C, 0xFE, 0x9B,
  35551. 0xD3, 0x6A, 0xF3, 0x3F, 0x92, 0x6F, 0x33, 0x37,
  35552. 0x19, 0x97, 0x81, 0x3A, 0x50, 0xE1, 0xD9, 0x27,
  35553. 0x7E, 0x64, 0xF8, 0x01, 0x52, 0x26, 0x51, 0xD1,
  35554. 0x06, 0xAF, 0x20, 0xA0, 0x28, 0x0F, 0x3F, 0xCB,
  35555. 0x21, 0xB7, 0x55, 0x1A, 0x76, 0xB8, 0x9B, 0x4D,
  35556. 0xED, 0x2A, 0x05, 0x0E, 0x6E, 0xAF, 0xCC, 0xA1,
  35557. 0x08, 0x9C, 0xBE, 0x3F, 0x98, 0xE6, 0xB4, 0xB9,
  35558. 0x83, 0xC9, 0x08, 0x41, 0x96, 0xDD, 0xD9, 0x0D,
  35559. 0x52, 0x66, 0x94, 0xA4, 0xEA, 0xFC, 0xE5, 0x48,
  35560. 0x04, 0x73, 0x64, 0x79, 0x68, 0xC9, 0x4A, 0x81,
  35561. 0xA8, 0x07, 0xF8, 0xD9, 0x4E, 0x07, 0x1E, 0xC1,
  35562. 0x8F, 0x62, 0xAB, 0xA6, 0xD7, 0x68, 0xFC, 0x57,
  35563. 0x5E, 0x75, 0x1B, 0xBF, 0x3D, 0xA6, 0x91, 0xC5,
  35564. 0x08, 0x14, 0x5E, 0xF2, 0x4C, 0x22, 0x8B, 0x4E,
  35565. 0x29, 0x2D, 0xC0, 0x46, 0x3A, 0x9C, 0x9D, 0x86,
  35566. 0xCF, 0x51, 0x85, 0x9D, 0x93, 0x23, 0xA1, 0xA1,
  35567. 0xF3, 0x76, 0xB1, 0x56, 0xB0, 0xF4, 0x1F, 0x39,
  35568. 0xDA, 0xDB, 0x13, 0x70, 0x29, 0x89, 0x95, 0xD2,
  35569. 0xC5, 0xF3, 0x76, 0xFE, 0xEE, 0x99, 0xCF, 0xA0,
  35570. 0x84, 0xEC, 0x70, 0xF0, 0xD3, 0xFA, 0x42, 0xDB,
  35571. 0xFD, 0x99, 0x65, 0x2F, 0x84, 0x11, 0x99, 0xCD,
  35572. 0x38, 0xB3, 0x1B, 0xAB, 0x8C, 0x2D, 0x33, 0x04,
  35573. 0xCA, 0xE1, 0xB3, 0x05, 0x9A, 0x20, 0x80, 0xDB,
  35574. 0xED, 0x59, 0x42, 0x30, 0x48, 0x37, 0xB3, 0x85,
  35575. 0x5C, 0xEE, 0x54, 0x06, 0x92, 0x97, 0x4E, 0xFC,
  35576. 0xFA, 0xF7, 0x25, 0xE0, 0x4E, 0x57, 0xC4, 0x72,
  35577. 0x38, 0x59, 0xCA, 0x3C, 0x4A, 0x3F, 0x09, 0xD6,
  35578. 0x09, 0x15, 0x83, 0xEF, 0x24, 0x21, 0xDD, 0xFD,
  35579. 0x66, 0x9E, 0xBF, 0xEE, 0xCC, 0xBF, 0x86, 0x20,
  35580. 0x29, 0x40, 0x5E, 0x42, 0xD2, 0xC0, 0x24, 0x2D,
  35581. 0x76, 0xE6, 0x64, 0xF9, 0x5D, 0xC2, 0x85, 0xB6,
  35582. 0x09, 0x41, 0x04, 0x62, 0x17, 0xDC, 0xF8, 0xFA,
  35583. 0x2A, 0x4C, 0xD1, 0x82, 0x31, 0x57, 0xB7, 0x2B,
  35584. 0x49, 0xE8, 0x40, 0x13, 0x2A, 0xA1, 0x86, 0xD2,
  35585. 0x9A, 0xB8, 0xA9, 0xBE, 0x39, 0xBE, 0xE9, 0xA5,
  35586. 0x35, 0x12, 0x08, 0xF1, 0xA9, 0x9E, 0x57, 0x46,
  35587. 0x3A, 0x55, 0x16, 0xA7, 0x41, 0xD9, 0x25, 0xB8,
  35588. 0x2F, 0xAF, 0xA8, 0x81, 0x5F, 0x5F, 0x46, 0xA4,
  35589. 0x3B, 0xB3, 0xE9, 0x1B, 0x74, 0xEF, 0x5D, 0x57,
  35590. 0x48, 0x4A, 0x72, 0x08, 0xDA, 0xFE, 0x1D, 0x55,
  35591. 0x6B, 0xAB, 0x8B, 0x13, 0x18, 0xBF, 0xDD, 0xF4,
  35592. 0x4E, 0x01, 0x5F, 0x4B, 0xF6, 0x80, 0xD4, 0x16,
  35593. 0x4B, 0x2F, 0x03, 0x4B, 0xF8, 0x93, 0x20, 0x21,
  35594. 0x55, 0x52, 0x49, 0x4A, 0x6C, 0x1F, 0x7D, 0xAD,
  35595. 0x04, 0xEF, 0xB3, 0x74, 0xEE, 0xC5, 0xB6, 0xBC,
  35596. 0x33, 0x7A, 0xCF, 0x64, 0xB9, 0xF9, 0x41, 0x70,
  35597. 0xAF, 0xE9, 0xC7, 0xD6, 0x25, 0x18, 0x17, 0xAB,
  35598. 0xBA, 0xC9, 0x05, 0xEF, 0x40, 0x89, 0xD5, 0x69,
  35599. 0x76, 0xAA, 0xA0, 0x3E, 0x4D, 0x1C, 0xE7, 0x9D,
  35600. 0x9E, 0x74, 0xF4, 0xF2, 0x7B, 0x40, 0xF6, 0x57,
  35601. 0x78, 0x66, 0xFC, 0xDA, 0xE3, 0x6B, 0xD2, 0x6E,
  35602. 0xC7, 0x9D, 0x65, 0x84, 0xAF, 0x7A, 0x1F, 0xE4,
  35603. 0x34, 0xD4, 0x1A, 0x17, 0xA2, 0x72, 0xB0, 0xEE,
  35604. 0x5A, 0x0C, 0xF4, 0x02, 0xAC, 0x1D, 0x6F, 0x4A,
  35605. 0xD0, 0xB2, 0x02, 0x3A, 0x7D, 0x2C, 0xF1, 0x43,
  35606. 0x0E, 0x1E, 0x96, 0xEB, 0x42, 0xF8, 0x3A, 0xF5,
  35607. 0x0B, 0x5D, 0xA9, 0x23, 0x02, 0x28, 0xE5, 0x26,
  35608. 0x5E, 0x69, 0x38, 0x2F, 0x85, 0x34, 0x32, 0x5E,
  35609. 0x5E, 0x29, 0x33, 0x94, 0x05, 0xBD, 0x58, 0xF8,
  35610. 0xE8, 0x9C, 0xBF, 0xB1, 0x5A, 0x05, 0xC6, 0x23,
  35611. 0x9B, 0xBB, 0x57, 0x69, 0x8C, 0xE6, 0x41, 0x97,
  35612. 0x48, 0x01, 0x95, 0xAF, 0xE9, 0x62, 0x8C, 0x6F,
  35613. 0x09, 0x43, 0xF3, 0x64, 0x50, 0x90, 0x2F, 0x14,
  35614. 0xF7, 0x30, 0x07, 0xE0, 0x4B, 0xA8, 0x39, 0xAC,
  35615. 0x21, 0xC4, 0x07, 0x45, 0x5F, 0xD9, 0x87, 0xB1,
  35616. 0x57, 0x47, 0x07, 0x66, 0xFF, 0xC7, 0xAB, 0xEE,
  35617. 0x1F, 0x55, 0x71, 0x50, 0x63, 0xCF, 0x58, 0x3B,
  35618. 0xC8, 0x1B, 0xEA, 0xA5, 0xE2, 0xF1, 0x57, 0xB3,
  35619. 0x77, 0x65, 0xA9, 0xBD, 0x23, 0xC8, 0x30, 0x86,
  35620. 0xC3, 0x5F, 0xBF, 0x16, 0x3F, 0x42, 0x28, 0x0A,
  35621. 0xC6, 0x5A, 0x57, 0x15, 0x2F, 0xA1, 0x96, 0xA9,
  35622. 0x25, 0xC5, 0x8E, 0x32, 0x11, 0x62, 0xB3, 0x54,
  35623. 0x18, 0x00, 0xA4, 0xA6, 0xD4, 0x0F, 0x68, 0x27,
  35624. 0x8F, 0x21, 0x78, 0x02, 0x37, 0x98, 0xBD, 0xCE,
  35625. 0x3F, 0xBC, 0xF2, 0x9C, 0x66, 0x8E, 0x79, 0xA1,
  35626. 0x54, 0x12, 0x55, 0x2E, 0xC0, 0x59, 0xC7, 0x18,
  35627. 0x18, 0x22, 0x4D, 0x27, 0x8B, 0x8D, 0xF3, 0x08,
  35628. 0x99, 0xE6, 0x35, 0x14, 0xB1, 0xE3, 0xB8, 0x7A,
  35629. 0x40, 0x7B, 0x68, 0x7B, 0xFF, 0xDC, 0x54, 0x41,
  35630. 0x06, 0xCA, 0x91, 0xFE, 0xDB, 0x2B, 0xDA, 0x9E,
  35631. 0xC5, 0x20, 0xD8, 0xBF, 0x42, 0xBC, 0xE6, 0x39,
  35632. 0xC4, 0x26, 0x9E, 0xF3, 0x82, 0xD9, 0xF1, 0xA0,
  35633. 0x04, 0xAF, 0xFB, 0x77, 0x13, 0x36, 0xAF, 0xD7,
  35634. 0x91, 0x9B, 0x3A, 0x57, 0x98, 0xFE, 0xAD, 0xCD,
  35635. 0x46, 0xF8, 0xF8, 0xF1, 0x87, 0x53, 0xBD, 0x57,
  35636. 0x3F, 0x99, 0xBC, 0xA6, 0xBD, 0x9B, 0x6E, 0xF4,
  35637. 0x17, 0x7A, 0x78, 0x30, 0x70, 0xA3, 0x43, 0xFF,
  35638. 0x92, 0xCD, 0x99, 0x73, 0xAE, 0x65, 0x6A, 0x10,
  35639. 0xFF, 0x70, 0x47, 0x0F, 0x16, 0x4C, 0x4A, 0x90,
  35640. 0xF4, 0x52, 0x05, 0x79, 0x33, 0x63, 0xDE, 0x14,
  35641. 0x65, 0xAF, 0x8A, 0x5E, 0x67, 0x20, 0x03, 0x9F,
  35642. 0xE6, 0x70, 0x13, 0x6B, 0xE0, 0xF3, 0x6A, 0x4C,
  35643. 0x6B, 0x5B, 0xCB, 0xE1, 0x7C, 0x5D, 0x7D, 0xE3,
  35644. 0x23, 0xFD, 0xB8, 0x6A, 0xDA, 0x56, 0x1E, 0xA8,
  35645. 0x36, 0xC4, 0x29, 0x2D, 0x70, 0x41, 0x03, 0x18,
  35646. 0x31, 0x40, 0x79, 0x2E, 0xC8, 0x22, 0x98, 0x5E,
  35647. 0x11, 0xED, 0xA6, 0xDD, 0xB9, 0xAF, 0x8C, 0x27,
  35648. 0x5C, 0x1B, 0x2E, 0xEA, 0xB8, 0xC6, 0x2F, 0xA0,
  35649. 0x40, 0xB2, 0x64, 0x61, 0xFC, 0x0A, 0x3A, 0x10,
  35650. 0x88, 0xC2, 0x58, 0xEC, 0xA5, 0x8D, 0x14, 0xE9,
  35651. 0x9D, 0x21, 0xAF, 0x64, 0xD6, 0xC2, 0x5D, 0xAA,
  35652. 0x0B, 0x8A, 0x57, 0x0F, 0x84, 0x3E, 0x60, 0x8D,
  35653. 0xED, 0x05, 0x1D, 0x98, 0xED, 0xAE, 0x11, 0xD9,
  35654. 0x27, 0x03, 0x55, 0xED, 0xF5, 0x34, 0x92, 0x52,
  35655. 0xF2, 0x6F, 0x30, 0x3E, 0x69, 0xA5, 0x54, 0xA7,
  35656. 0x2E, 0x1B, 0x85, 0xAB, 0xA2, 0x3B, 0xEC, 0xC8,
  35657. 0x9D, 0xA9, 0xA3, 0xE4, 0xEF, 0x58, 0xB5, 0x33,
  35658. 0x88, 0x55, 0x16, 0x5E, 0x7D, 0x7E, 0x69, 0xFC,
  35659. 0xCA, 0xBD, 0x9C, 0x65, 0xFA, 0x0B, 0xBD, 0x7B,
  35660. 0x16, 0xC4, 0xE2, 0x9C, 0xB4, 0xF1, 0x6A, 0x25,
  35661. 0x70, 0x30, 0x32, 0xED, 0xEA, 0xD3, 0x1D, 0xDB,
  35662. 0x6F, 0x29, 0x2E, 0x42, 0x14, 0xBE, 0x03, 0x29,
  35663. 0x0A, 0x8A, 0x98, 0x9A, 0xD7, 0xB7, 0x0C, 0xF8,
  35664. 0xB9, 0xCF, 0x37, 0xC6, 0xAC, 0xAC, 0x6D, 0xCC,
  35665. 0x03, 0x23, 0x9F, 0x66, 0x85, 0x4B, 0x70, 0x45
  35666. };
  35667. #endif /* WOLFSSL_NO_ML_DSA_87 */
  35668. #endif
  35669. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  35670. ExpectNotNull(key);
  35671. if (key != NULL) {
  35672. XMEMSET(key, 0, sizeof(*key));
  35673. }
  35674. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  35675. #ifndef WOLFSSL_NO_ML_DSA_44
  35676. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  35677. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_44), 0);
  35678. ExpectIntEQ(XMEMCMP(key->p, pk_44, sizeof(pk_44)), 0);
  35679. ExpectIntEQ(XMEMCMP(key->k, sk_44, sizeof(sk_44)), 0);
  35680. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  35681. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44_DRAFT), 0);
  35682. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_44_draft), 0);
  35683. ExpectIntEQ(XMEMCMP(key->p, pk_44_draft, sizeof(pk_44_draft)), 0);
  35684. ExpectIntEQ(XMEMCMP(key->k, sk_44_draft, sizeof(sk_44_draft)), 0);
  35685. #endif
  35686. #endif
  35687. #ifndef WOLFSSL_NO_ML_DSA_65
  35688. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  35689. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_65), 0);
  35690. ExpectIntEQ(XMEMCMP(key->p, pk_65, sizeof(pk_65)), 0);
  35691. ExpectIntEQ(XMEMCMP(key->k, sk_65, sizeof(sk_65)), 0);
  35692. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  35693. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65_DRAFT), 0);
  35694. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_65_draft), 0);
  35695. ExpectIntEQ(XMEMCMP(key->p, pk_65_draft, sizeof(pk_65_draft)), 0);
  35696. ExpectIntEQ(XMEMCMP(key->k, sk_65_draft, sizeof(sk_65_draft)), 0);
  35697. #endif
  35698. #endif
  35699. #ifndef WOLFSSL_NO_ML_DSA_87
  35700. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  35701. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_87), 0);
  35702. ExpectIntEQ(XMEMCMP(key->p, pk_87, sizeof(pk_87)), 0);
  35703. ExpectIntEQ(XMEMCMP(key->k, sk_87, sizeof(sk_87)), 0);
  35704. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  35705. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87_DRAFT), 0);
  35706. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_87_draft), 0);
  35707. ExpectIntEQ(XMEMCMP(key->p, pk_87_draft, sizeof(pk_87_draft)), 0);
  35708. ExpectIntEQ(XMEMCMP(key->k, sk_87_draft, sizeof(sk_87_draft)), 0);
  35709. #endif
  35710. #endif
  35711. wc_dilithium_free(key);
  35712. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  35713. #endif
  35714. return EXPECT_RESULT();
  35715. }
  35716. static int test_wc_dilithium_sig_kats(void)
  35717. {
  35718. EXPECT_DECLS;
  35719. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  35720. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  35721. dilithium_key* key;
  35722. #ifndef WOLFSSL_NO_ML_DSA_44
  35723. static const byte sk_44[] = {
  35724. 0x5D, 0xFB, 0x07, 0xA2, 0x04, 0x4B, 0x93, 0x16,
  35725. 0x75, 0xC7, 0x89, 0x43, 0xEA, 0xC3, 0xC4, 0xC5,
  35726. 0x7B, 0x07, 0x77, 0x8A, 0xD9, 0xAF, 0x2E, 0x87,
  35727. 0xC4, 0x70, 0xB9, 0xCC, 0x2C, 0x8D, 0xA1, 0xE3,
  35728. 0x75, 0xBC, 0xB3, 0xBC, 0xD1, 0x9E, 0x7B, 0xB9,
  35729. 0x83, 0xC9, 0x63, 0x66, 0xCC, 0xEA, 0x14, 0x1E,
  35730. 0xAE, 0x22, 0x07, 0x75, 0x52, 0x24, 0xC8, 0xC6,
  35731. 0xC6, 0x1F, 0x90, 0x89, 0x89, 0xCF, 0xF2, 0xF6,
  35732. 0x27, 0x98, 0xA6, 0x86, 0x45, 0x77, 0x95, 0x15,
  35733. 0xD4, 0x74, 0xDD, 0xA6, 0x1F, 0x33, 0x41, 0x42,
  35734. 0x4E, 0xDA, 0x24, 0x79, 0x60, 0x27, 0x34, 0x4E,
  35735. 0x36, 0x94, 0x14, 0x74, 0x81, 0x9A, 0x58, 0x44,
  35736. 0x2B, 0x74, 0xBF, 0x50, 0x60, 0xB8, 0x40, 0x94,
  35737. 0x4A, 0xEF, 0xDE, 0xA7, 0xA4, 0xCF, 0xFC, 0xB3,
  35738. 0x9D, 0xE2, 0x07, 0xFD, 0x9E, 0x6A, 0xC6, 0x2E,
  35739. 0x6D, 0x0D, 0xB2, 0xB4, 0x51, 0x2E, 0x20, 0x26,
  35740. 0x00, 0xB5, 0x30, 0x01, 0xA9, 0x2D, 0xE2, 0x42,
  35741. 0x02, 0x42, 0x12, 0x71, 0x24, 0xB7, 0x28, 0x94,
  35742. 0x30, 0x86, 0xDA, 0x22, 0x30, 0x00, 0x87, 0x65,
  35743. 0xCC, 0x22, 0x91, 0x1B, 0x05, 0x82, 0x03, 0x46,
  35744. 0x8A, 0xA0, 0x32, 0x26, 0x40, 0xB4, 0x84, 0xC3,
  35745. 0x14, 0x2D, 0x88, 0x14, 0x8C, 0x94, 0x92, 0x49,
  35746. 0x23, 0x15, 0x0E, 0xCA, 0x88, 0x09, 0x18, 0x94,
  35747. 0x68, 0x82, 0x38, 0x00, 0x21, 0x41, 0x28, 0x8C,
  35748. 0xB8, 0x80, 0x02, 0x09, 0x49, 0x5A, 0xB4, 0x11,
  35749. 0x9B, 0x28, 0x05, 0xE4, 0x42, 0x30, 0xCA, 0x24,
  35750. 0x80, 0xA4, 0x06, 0x2A, 0xD3, 0x92, 0x05, 0x1C,
  35751. 0x03, 0x6A, 0x22, 0x36, 0x4A, 0x92, 0x44, 0x52,
  35752. 0xE2, 0x48, 0x28, 0x19, 0x83, 0x68, 0x88, 0xC6,
  35753. 0x31, 0x41, 0x90, 0x50, 0x00, 0x43, 0x8E, 0x23,
  35754. 0x87, 0x60, 0x19, 0x43, 0x81, 0x50, 0x32, 0x69,
  35755. 0x81, 0xC0, 0x51, 0x12, 0x06, 0x08, 0x02, 0x08,
  35756. 0x82, 0xC4, 0xA6, 0x81, 0x03, 0xA5, 0x90, 0x8C,
  35757. 0xB6, 0x00, 0x90, 0x14, 0x66, 0x01, 0xB1, 0x08,
  35758. 0x12, 0x25, 0x48, 0x1A, 0x88, 0x11, 0x43, 0x38,
  35759. 0x60, 0x23, 0x26, 0x2E, 0x14, 0x45, 0x0D, 0x9C,
  35760. 0x92, 0x8C, 0xA2, 0x46, 0x12, 0x94, 0xA6, 0x05,
  35761. 0x88, 0xB0, 0x11, 0x0A, 0xB0, 0x28, 0xA4, 0x42,
  35762. 0x09, 0x9C, 0x82, 0x80, 0x1A, 0x80, 0x61, 0x59,
  35763. 0xB0, 0x8D, 0x40, 0xA6, 0x6D, 0x12, 0xC9, 0x0C,
  35764. 0xD9, 0x18, 0x68, 0xA3, 0x84, 0x2C, 0x02, 0xB6,
  35765. 0x25, 0x01, 0x40, 0x2C, 0xD8, 0x20, 0x4D, 0x1B,
  35766. 0x35, 0x30, 0x11, 0x10, 0x49, 0x63, 0x44, 0x31,
  35767. 0x8A, 0xB2, 0x70, 0x4B, 0x24, 0x28, 0xA0, 0x46,
  35768. 0x08, 0xC9, 0x06, 0x81, 0x08, 0xC5, 0x04, 0x4A,
  35769. 0xB2, 0x30, 0x08, 0x15, 0x04, 0x24, 0xA2, 0x65,
  35770. 0x9B, 0x88, 0x41, 0x19, 0x36, 0x2E, 0xE2, 0xB8,
  35771. 0x29, 0xD9, 0x12, 0x64, 0x41, 0xA6, 0x30, 0x22,
  35772. 0xB7, 0x8C, 0x93, 0x38, 0x69, 0x93, 0x30, 0x0A,
  35773. 0xC8, 0xB6, 0x85, 0x23, 0xB1, 0x8D, 0x01, 0x38,
  35774. 0x0A, 0x59, 0xA0, 0x09, 0x64, 0x12, 0x6E, 0x88,
  35775. 0x08, 0x22, 0xDB, 0x00, 0x08, 0x0C, 0x08, 0x12,
  35776. 0x99, 0x42, 0x44, 0x1B, 0x00, 0x68, 0x08, 0x13,
  35777. 0x26, 0x53, 0xA2, 0x40, 0x5A, 0x34, 0x25, 0x98,
  35778. 0x90, 0x8C, 0x00, 0x34, 0x2D, 0x93, 0x94, 0x48,
  35779. 0xC8, 0x22, 0x4C, 0xE2, 0x44, 0x29, 0xE2, 0x00,
  35780. 0x28, 0x14, 0x22, 0x40, 0x48, 0x28, 0x24, 0x22,
  35781. 0x49, 0x06, 0xCA, 0xC8, 0x0C, 0x4C, 0x12, 0x80,
  35782. 0x1B, 0xA5, 0x41, 0x11, 0x06, 0x48, 0x1B, 0x27,
  35783. 0x72, 0x20, 0x07, 0x31, 0x24, 0x10, 0x8E, 0x9C,
  35784. 0x94, 0x91, 0x1B, 0x37, 0x82, 0x51, 0x28, 0x2E,
  35785. 0x11, 0x06, 0x42, 0x01, 0x34, 0x6E, 0x8C, 0x22,
  35786. 0x25, 0x24, 0x34, 0x6A, 0x19, 0x47, 0x21, 0x23,
  35787. 0xB6, 0x09, 0x51, 0xB2, 0x31, 0x18, 0x34, 0x45,
  35788. 0x8C, 0xB8, 0x20, 0x1C, 0x19, 0x0A, 0x19, 0xB7,
  35789. 0x6D, 0x18, 0x97, 0x48, 0x09, 0x82, 0x04, 0x9C,
  35790. 0x12, 0x8A, 0x41, 0x08, 0x46, 0x24, 0x13, 0x31,
  35791. 0xD0, 0x42, 0x46, 0xC3, 0x16, 0x80, 0x51, 0x10,
  35792. 0x2E, 0x51, 0x48, 0x04, 0x5C, 0xC2, 0x64, 0x1A,
  35793. 0x10, 0x8E, 0xD9, 0x86, 0x64, 0x90, 0x24, 0x68,
  35794. 0x93, 0xB4, 0x45, 0x94, 0x30, 0x4A, 0xE3, 0x12,
  35795. 0x0C, 0x54, 0x04, 0x90, 0x03, 0x31, 0x40, 0x62,
  35796. 0x92, 0x4D, 0x5C, 0xC8, 0x10, 0x8A, 0xB8, 0x61,
  35797. 0x5C, 0x04, 0x6A, 0xC8, 0xB0, 0x85, 0x93, 0x00,
  35798. 0x05, 0xC3, 0x06, 0x69, 0x1B, 0x34, 0x8E, 0x03,
  35799. 0x84, 0x0C, 0x50, 0x00, 0x2C, 0x8C, 0x96, 0x90,
  35800. 0x08, 0x32, 0x68, 0x0B, 0x90, 0x8C, 0x02, 0x86,
  35801. 0x2D, 0x18, 0x38, 0x09, 0x1C, 0xB2, 0x21, 0x1B,
  35802. 0x48, 0x04, 0x5C, 0x10, 0x86, 0xD8, 0x34, 0x51,
  35803. 0x43, 0x84, 0x88, 0x43, 0xB2, 0x65, 0x12, 0xB6,
  35804. 0x8D, 0x03, 0x01, 0x45, 0x19, 0xB8, 0x8D, 0x92,
  35805. 0x26, 0x4E, 0x12, 0x12, 0x88, 0x52, 0xB2, 0x64,
  35806. 0x21, 0x09, 0x26, 0x49, 0x38, 0x05, 0x24, 0x11,
  35807. 0x0A, 0x22, 0x38, 0x32, 0x23, 0x31, 0x20, 0x4A,
  35808. 0x24, 0x42, 0xC4, 0xA2, 0x44, 0x20, 0x10, 0x0D,
  35809. 0xA1, 0xA8, 0x51, 0x23, 0x86, 0x84, 0x81, 0x38,
  35810. 0x8E, 0x02, 0x00, 0x4A, 0x1C, 0xB7, 0x24, 0x4C,
  35811. 0x06, 0x0A, 0x1C, 0x26, 0x4E, 0xCC, 0x22, 0x48,
  35812. 0x4C, 0x92, 0x2D, 0xC0, 0x20, 0x2D, 0xA1, 0x16,
  35813. 0x89, 0xC3, 0x44, 0x82, 0x19, 0xA7, 0x6D, 0xC4,
  35814. 0x90, 0x10, 0x01, 0x82, 0x89, 0xD8, 0x44, 0x22,
  35815. 0xD9, 0x98, 0x20, 0xC0, 0x88, 0x45, 0x88, 0x22,
  35816. 0x0C, 0x90, 0x36, 0x90, 0x90, 0xA4, 0x05, 0xD3,
  35817. 0x82, 0x21, 0xD0, 0xA6, 0x28, 0x00, 0x33, 0x25,
  35818. 0xA2, 0xC2, 0x6C, 0xD8, 0x10, 0x71, 0xD1, 0x96,
  35819. 0x50, 0xC3, 0x34, 0x08, 0x8B, 0x94, 0x2D, 0x61,
  35820. 0x88, 0x04, 0x1B, 0xC8, 0x2D, 0xE2, 0x30, 0x64,
  35821. 0x20, 0x28, 0x24, 0x1A, 0x34, 0x50, 0x10, 0x25,
  35822. 0x6A, 0x64, 0x36, 0x81, 0x09, 0xC1, 0x45, 0xE3,
  35823. 0x30, 0x80, 0xC3, 0xA6, 0x8C, 0xE0, 0xB6, 0x10,
  35824. 0xC3, 0x34, 0x8D, 0xD1, 0x06, 0x11, 0x88, 0x20,
  35825. 0x0A, 0x0A, 0xC8, 0x21, 0x20, 0x81, 0x30, 0x9C,
  35826. 0x14, 0x61, 0x9B, 0xC2, 0x50, 0x22, 0x15, 0x8D,
  35827. 0x80, 0xA0, 0x41, 0x89, 0x24, 0x41, 0x20, 0x93,
  35828. 0x40, 0x01, 0xA6, 0x09, 0x08, 0x25, 0x2E, 0xC1,
  35829. 0xC6, 0x85, 0x00, 0x17, 0x62, 0x41, 0x30, 0x32,
  35830. 0xDC, 0x06, 0x6D, 0x48, 0x88, 0x08, 0x84, 0xC8,
  35831. 0x30, 0x5B, 0x96, 0x8D, 0x42, 0xB4, 0x4C, 0xD0,
  35832. 0x34, 0x88, 0xD0, 0x04, 0x02, 0x18, 0x15, 0x52,
  35833. 0x52, 0x26, 0x30, 0x8C, 0x46, 0x28, 0x20, 0x94,
  35834. 0x4C, 0x21, 0x18, 0x00, 0xD0, 0xB2, 0x48, 0x1B,
  35835. 0x17, 0x0A, 0x09, 0x30, 0x4C, 0x44, 0xC2, 0x04,
  35836. 0x47, 0x5E, 0xF2, 0x33, 0x31, 0xFF, 0x66, 0x73,
  35837. 0xE2, 0x6E, 0x6A, 0x32, 0xF2, 0x94, 0xBE, 0xFB,
  35838. 0xD5, 0x96, 0x4F, 0xED, 0x98, 0x7A, 0x42, 0xA2,
  35839. 0x35, 0xFC, 0x5B, 0x16, 0x08, 0x61, 0x45, 0xC0,
  35840. 0xB8, 0xA8, 0x23, 0xFB, 0xC1, 0x4F, 0x1C, 0x8C,
  35841. 0xD0, 0x3F, 0xD6, 0xEE, 0xC4, 0x95, 0x28, 0x3E,
  35842. 0x03, 0x5C, 0x0D, 0xCA, 0xE5, 0x2E, 0x68, 0xF3,
  35843. 0x29, 0xDE, 0x7A, 0xDF, 0xD6, 0x4F, 0xEE, 0x0B,
  35844. 0x11, 0x6D, 0x4A, 0x14, 0xE1, 0x53, 0x94, 0xB3,
  35845. 0x1D, 0xF8, 0x8B, 0xCA, 0x10, 0xD1, 0xC9, 0x06,
  35846. 0xAA, 0x82, 0x28, 0x7C, 0x11, 0x74, 0x99, 0xE9,
  35847. 0xD8, 0xC7, 0x7D, 0x17, 0xA9, 0x5C, 0xCC, 0x14,
  35848. 0xAF, 0xF9, 0xC2, 0x05, 0xD2, 0x64, 0x80, 0xA5,
  35849. 0x70, 0xB5, 0x77, 0x0B, 0x04, 0x81, 0x99, 0xCF,
  35850. 0x3F, 0x0E, 0x1B, 0x91, 0xAB, 0x39, 0x4B, 0x1F,
  35851. 0x65, 0xD4, 0x7F, 0x92, 0x98, 0xD0, 0x96, 0xCA,
  35852. 0x25, 0xC0, 0x99, 0xBC, 0x67, 0xF4, 0x33, 0x42,
  35853. 0x63, 0xE3, 0x6B, 0xD9, 0xE6, 0x6B, 0x99, 0x8A,
  35854. 0x07, 0xDC, 0x1E, 0x18, 0x1E, 0x05, 0x38, 0x6E,
  35855. 0x96, 0x8F, 0x1C, 0xB0, 0xAB, 0x1E, 0x9A, 0x67,
  35856. 0xD5, 0xD3, 0x30, 0x11, 0x20, 0x37, 0x82, 0x24,
  35857. 0x88, 0x1F, 0x65, 0x17, 0x59, 0xEC, 0x7D, 0xBF,
  35858. 0x45, 0x78, 0x1E, 0xF8, 0xA8, 0x4D, 0xAD, 0xAF,
  35859. 0xE6, 0x13, 0xD6, 0x01, 0x69, 0x66, 0xBD, 0x88,
  35860. 0x44, 0xB6, 0xA6, 0x17, 0xAC, 0xA1, 0xEE, 0xF6,
  35861. 0x73, 0xB7, 0x74, 0xCC, 0x80, 0x7B, 0x36, 0xDD,
  35862. 0x02, 0xDD, 0x45, 0x21, 0x66, 0x86, 0x03, 0x7F,
  35863. 0x9A, 0xC0, 0xB1, 0x2F, 0x57, 0x26, 0xF2, 0x51,
  35864. 0xC5, 0x72, 0x43, 0xE2, 0xC1, 0x88, 0xF5, 0xEC,
  35865. 0xC0, 0x97, 0xE0, 0xB9, 0x89, 0xB5, 0x8A, 0x5D,
  35866. 0x80, 0x4A, 0xBF, 0xD7, 0x20, 0x25, 0x55, 0x77,
  35867. 0x66, 0x8E, 0xE3, 0x04, 0xD0, 0x1C, 0x50, 0xFE,
  35868. 0x8B, 0x6D, 0x90, 0x68, 0x53, 0xCF, 0x7A, 0x49,
  35869. 0x4F, 0xB4, 0x79, 0x91, 0xF1, 0x81, 0xB7, 0x42,
  35870. 0x0E, 0x74, 0x19, 0x9C, 0x82, 0xE7, 0x1A, 0x82,
  35871. 0x4B, 0xF8, 0xC6, 0x13, 0x1D, 0xF4, 0xD1, 0x85,
  35872. 0x6F, 0x11, 0xE7, 0x04, 0x07, 0x70, 0x72, 0x4D,
  35873. 0xE7, 0x2C, 0x81, 0x5A, 0xC0, 0x44, 0x3F, 0x2E,
  35874. 0x77, 0xEC, 0x22, 0xA1, 0x28, 0xDB, 0x18, 0xE1,
  35875. 0x18, 0x3E, 0xE7, 0x96, 0x82, 0xC4, 0x30, 0x24,
  35876. 0xC9, 0x07, 0x46, 0x6C, 0x35, 0x4B, 0x1C, 0x7B,
  35877. 0x0E, 0x0E, 0xF0, 0x9F, 0x16, 0x48, 0x7B, 0xD8,
  35878. 0xA9, 0x9C, 0x3A, 0x0A, 0x9E, 0xDB, 0xF0, 0x0F,
  35879. 0x15, 0xA5, 0xEB, 0x1C, 0x50, 0xD4, 0x27, 0x36,
  35880. 0xDB, 0x07, 0x63, 0xBD, 0x56, 0xBD, 0xFA, 0x81,
  35881. 0x09, 0x9A, 0xDE, 0xCE, 0xE8, 0x4A, 0xEA, 0x06,
  35882. 0x9C, 0x06, 0x5B, 0x67, 0x03, 0x14, 0xB9, 0xE4,
  35883. 0x8C, 0x66, 0x75, 0xA3, 0xCC, 0x69, 0x39, 0x57,
  35884. 0xDA, 0x1D, 0x21, 0xBA, 0xCE, 0xD8, 0x70, 0x02,
  35885. 0xFF, 0xF5, 0x6F, 0x25, 0x3A, 0x3D, 0xFC, 0x79,
  35886. 0xA3, 0xF0, 0x3A, 0x3F, 0x2B, 0x10, 0x51, 0x9A,
  35887. 0xCB, 0xC9, 0x1A, 0xF5, 0xF1, 0x98, 0x5B, 0x5C,
  35888. 0x87, 0x96, 0x4E, 0xC8, 0x00, 0x8A, 0x3A, 0x6E,
  35889. 0x85, 0x02, 0xA5, 0xF1, 0x69, 0x32, 0x6E, 0xC1,
  35890. 0x95, 0x68, 0xCF, 0xA8, 0xE8, 0x85, 0x55, 0x4D,
  35891. 0x6A, 0x68, 0x1F, 0x00, 0xDD, 0x26, 0xB3, 0x24,
  35892. 0xF4, 0x9D, 0xD2, 0x4D, 0x81, 0x06, 0xDA, 0xE6,
  35893. 0x4D, 0x11, 0x73, 0xDF, 0xFE, 0x4F, 0xA6, 0x22,
  35894. 0x5E, 0x6C, 0x6D, 0x5E, 0xE3, 0x59, 0xCF, 0xF4,
  35895. 0x35, 0xA0, 0x80, 0x86, 0x89, 0x49, 0xB2, 0xED,
  35896. 0x0C, 0xC7, 0x3B, 0x42, 0x06, 0x68, 0x8D, 0x90,
  35897. 0x04, 0x1A, 0xBD, 0x51, 0xF6, 0xB9, 0x29, 0x2E,
  35898. 0xB6, 0xF0, 0x79, 0x40, 0x1E, 0x6E, 0x59, 0x94,
  35899. 0xFB, 0xF5, 0x6B, 0x72, 0x82, 0x4C, 0xB6, 0xC7,
  35900. 0x2B, 0x12, 0x71, 0x77, 0xDD, 0x89, 0xCC, 0x2F,
  35901. 0x98, 0xB0, 0x93, 0x1C, 0x98, 0xCE, 0x5E, 0x89,
  35902. 0x0D, 0x95, 0x7B, 0x98, 0xE1, 0xEA, 0xDC, 0xB7,
  35903. 0xFF, 0x22, 0xC5, 0x31, 0x40, 0x9E, 0x1C, 0x80,
  35904. 0x59, 0x47, 0x01, 0x49, 0xEC, 0x81, 0xEF, 0x16,
  35905. 0x32, 0x6B, 0xB0, 0x4E, 0xE2, 0x3B, 0xA3, 0xC1,
  35906. 0x03, 0x12, 0x0D, 0xA6, 0x65, 0xDE, 0x8D, 0xB0,
  35907. 0xA0, 0xBB, 0x75, 0xEF, 0x5C, 0xDA, 0xF4, 0xEE,
  35908. 0x47, 0x6E, 0x55, 0x02, 0x38, 0xCD, 0xC1, 0xAC,
  35909. 0xDD, 0x71, 0xA6, 0x34, 0xAB, 0xCE, 0xA5, 0x5C,
  35910. 0x90, 0xFF, 0xF8, 0xE0, 0xA7, 0x87, 0xBD, 0x21,
  35911. 0x36, 0x91, 0x4F, 0x23, 0xD8, 0x75, 0x58, 0xC5,
  35912. 0xF6, 0xBA, 0xAC, 0x54, 0x6C, 0x24, 0xB1, 0x41,
  35913. 0x02, 0x02, 0xB9, 0x44, 0x31, 0x0E, 0xC4, 0xC9,
  35914. 0xC6, 0x87, 0x85, 0x36, 0x05, 0xC8, 0xAE, 0xC9,
  35915. 0xF1, 0xEF, 0x6B, 0x67, 0x52, 0xD3, 0x9A, 0x15,
  35916. 0xBF, 0xA2, 0x47, 0xEF, 0x89, 0xFC, 0x06, 0x99,
  35917. 0xA1, 0x1A, 0xE4, 0x5A, 0x75, 0xE5, 0x09, 0xD4,
  35918. 0x54, 0xE9, 0x89, 0xF2, 0x60, 0x6E, 0xAB, 0x10,
  35919. 0xF8, 0x42, 0xE4, 0xAD, 0x57, 0xC6, 0xE3, 0x65,
  35920. 0x48, 0x94, 0x14, 0x05, 0x4F, 0x62, 0x20, 0x0F,
  35921. 0x3A, 0x1E, 0xC7, 0x62, 0xDC, 0x5C, 0x8E, 0xFA,
  35922. 0x19, 0x88, 0x47, 0x5D, 0xE8, 0xC3, 0xD5, 0x8C,
  35923. 0x2B, 0x71, 0xBA, 0x11, 0x98, 0x7C, 0x0A, 0xC6,
  35924. 0x42, 0x08, 0x3B, 0xAC, 0x76, 0xFB, 0x50, 0x78,
  35925. 0x8C, 0x26, 0x8F, 0xEE, 0x7B, 0xE2, 0x59, 0x9B,
  35926. 0x34, 0x58, 0x09, 0x2A, 0x8B, 0xCB, 0x1F, 0x31,
  35927. 0x94, 0x8F, 0xE4, 0x82, 0xDF, 0x9A, 0x54, 0x5B,
  35928. 0x63, 0x85, 0x94, 0xD6, 0x7A, 0x44, 0x06, 0x91,
  35929. 0x5C, 0xCD, 0xC7, 0x55, 0x57, 0x47, 0xC0, 0x4E,
  35930. 0x72, 0xA5, 0x48, 0xAB, 0x8F, 0xEE, 0x87, 0x6B,
  35931. 0x25, 0x82, 0x61, 0x3C, 0xCA, 0xBD, 0xA9, 0x6C,
  35932. 0xF1, 0x4A, 0xAA, 0xF6, 0x71, 0x6B, 0x79, 0x0B,
  35933. 0xFE, 0x4D, 0x92, 0x32, 0xD9, 0x03, 0x70, 0xD6,
  35934. 0x0B, 0xBC, 0x18, 0x4B, 0xA3, 0x3B, 0xCF, 0x77,
  35935. 0x83, 0x16, 0xE3, 0x4B, 0x11, 0x83, 0x8D, 0x8F,
  35936. 0x71, 0xFE, 0xEA, 0xC0, 0x42, 0xF0, 0x35, 0xB0,
  35937. 0x76, 0xEA, 0xC1, 0xC2, 0x62, 0xFA, 0x9C, 0x32,
  35938. 0xBC, 0x8D, 0x69, 0xB1, 0x38, 0xB3, 0x51, 0x31,
  35939. 0x8E, 0xD1, 0xF3, 0x44, 0x95, 0x95, 0x11, 0x52,
  35940. 0x36, 0xF4, 0xCA, 0x7C, 0xBA, 0x2B, 0xA9, 0xE1,
  35941. 0x03, 0xF0, 0xF5, 0x09, 0xAB, 0x91, 0x6E, 0x48,
  35942. 0xB8, 0xAF, 0x03, 0x9B, 0xDC, 0xD5, 0x1C, 0xAB,
  35943. 0xFA, 0xCA, 0xDC, 0xEE, 0x8E, 0x49, 0x84, 0xF5,
  35944. 0x61, 0xF9, 0x7D, 0x17, 0xCB, 0xF1, 0xDE, 0x9A,
  35945. 0x7A, 0x7B, 0xDA, 0xF3, 0x26, 0xE6, 0xD8, 0xAD,
  35946. 0x90, 0xE9, 0x5B, 0xAF, 0x15, 0x45, 0xD3, 0xE2,
  35947. 0x46, 0x69, 0xD1, 0xC5, 0xF4, 0x28, 0xE0, 0x7E,
  35948. 0x2C, 0x71, 0x10, 0xFF, 0x43, 0x59, 0x80, 0x93,
  35949. 0xE6, 0xF9, 0x28, 0xA0, 0x34, 0xC6, 0x86, 0xBA,
  35950. 0xE7, 0x5A, 0x56, 0x7A, 0xE4, 0xF5, 0x20, 0xB4,
  35951. 0x4D, 0xAC, 0xB4, 0x95, 0xE5, 0xB2, 0xC6, 0x43,
  35952. 0x9E, 0x2E, 0x67, 0x8E, 0x7C, 0x05, 0x4F, 0xF7,
  35953. 0x60, 0x14, 0x88, 0xC6, 0xAE, 0x4A, 0x05, 0x36,
  35954. 0x99, 0x73, 0x55, 0x10, 0xF9, 0xDB, 0xC3, 0x4C,
  35955. 0xD7, 0x6A, 0x19, 0x94, 0xC0, 0xFE, 0x74, 0x12,
  35956. 0xC0, 0xCE, 0x95, 0x15, 0xBF, 0x60, 0x3A, 0x8E,
  35957. 0xB5, 0xFC, 0x8A, 0xBC, 0xAC, 0x9F, 0x15, 0x10,
  35958. 0x44, 0x73, 0x58, 0x60, 0x5D, 0xA1, 0x33, 0xFD,
  35959. 0xDE, 0xBD, 0xF2, 0x22, 0x69, 0xEE, 0x1D, 0x46,
  35960. 0x8E, 0x2E, 0xE8, 0x21, 0x62, 0x1D, 0x27, 0x84,
  35961. 0xC4, 0x6D, 0xA8, 0x30, 0x02, 0xA6, 0x26, 0x94,
  35962. 0xFA, 0xB1, 0xEF, 0xEC, 0x3B, 0x8D, 0x6F, 0x1B,
  35963. 0x2C, 0xCE, 0x2A, 0x4E, 0xC4, 0x28, 0x35, 0x4E,
  35964. 0x39, 0xA4, 0xF4, 0x5C, 0x96, 0x65, 0xC1, 0xB8,
  35965. 0x55, 0xA5, 0x09, 0x15, 0xBC, 0x4D, 0x3B, 0xD0,
  35966. 0x1F, 0x7F, 0xBA, 0x90, 0x20, 0xCD, 0xBD, 0xC2,
  35967. 0xC8, 0xE5, 0xC6, 0xB0, 0x6F, 0x14, 0x4E, 0x6B,
  35968. 0xEA, 0x8A, 0x24, 0x44, 0xE1, 0x0A, 0xCD, 0xB2,
  35969. 0x05, 0xF3, 0x15, 0x71, 0x7C, 0x86, 0xFC, 0xF1,
  35970. 0xFD, 0x6B, 0xA6, 0xE3, 0xFC, 0x86, 0xE3, 0xBA,
  35971. 0x56, 0x6B, 0x8F, 0xBE, 0x02, 0x9A, 0x03, 0x0C,
  35972. 0x8C, 0x69, 0xE5, 0x7C, 0x15, 0xAE, 0x13, 0x12,
  35973. 0x25, 0x2B, 0x36, 0xFB, 0x51, 0xA1, 0x61, 0x5E,
  35974. 0x37, 0x46, 0x92, 0x0C, 0x0B, 0x71, 0x5C, 0x1D,
  35975. 0xA4, 0xDB, 0x04, 0xC1, 0x08, 0xED, 0x5C, 0x44,
  35976. 0x80, 0x70, 0xC1, 0x0E, 0x63, 0x6D, 0x92, 0xC2,
  35977. 0x1E, 0x18, 0x8E, 0x71, 0x0E, 0x7C, 0x10, 0x21,
  35978. 0x1E, 0xC2, 0xCF, 0xD6, 0x38, 0x7A, 0x9B, 0x5C,
  35979. 0x9E, 0xE8, 0x82, 0x3D, 0xDD, 0x40, 0x0C, 0x96,
  35980. 0x17, 0xEF, 0xB1, 0x25, 0xBA, 0x84, 0x45, 0x4F,
  35981. 0x64, 0xA6, 0x8E, 0x2B, 0xBA, 0xF1, 0xED, 0xB3,
  35982. 0x4F, 0x92, 0x5F, 0x1A, 0x73, 0x2A, 0x2A, 0x22,
  35983. 0x68, 0x19, 0x4C, 0x8A, 0x87, 0x51, 0x75, 0x78,
  35984. 0xCF, 0x3C, 0xC5, 0x97, 0xFD, 0x77, 0x43, 0xCB,
  35985. 0xAE, 0x3D, 0x9C, 0xB6, 0x45, 0x54, 0x45, 0xF4,
  35986. 0x1B, 0x92, 0xEE, 0xF4, 0x9D, 0xC4, 0x32, 0x10,
  35987. 0x6A, 0x48, 0xAB, 0xE9, 0x47, 0xBF, 0x2B, 0x92,
  35988. 0x49, 0x84, 0x23, 0x52, 0x05, 0xA1, 0x92, 0x3B,
  35989. 0xD7, 0x78, 0x2D, 0x9A, 0x15, 0xB4, 0xD9, 0xD3,
  35990. 0x45, 0xD0, 0x69, 0xF1, 0x38, 0x4D, 0x39, 0xEA,
  35991. 0x49, 0x7E, 0xC0, 0xE7, 0x7A, 0x07, 0x88, 0x1D,
  35992. 0x1F, 0xA3, 0xAC, 0xE9, 0xC3, 0xFD, 0x6B, 0x5D,
  35993. 0xF6, 0xB2, 0xB9, 0xAA, 0x9A, 0xBE, 0xF4, 0x06,
  35994. 0xD9, 0x5E, 0x81, 0xE5, 0x68, 0xDF, 0xEA, 0x20,
  35995. 0x4C, 0xEE, 0xED, 0x42, 0xA4, 0xD3, 0x7B, 0xA8,
  35996. 0x82, 0x98, 0x0D, 0xB4, 0xC8, 0xC3, 0x43, 0x28,
  35997. 0x13, 0xE9, 0x6B, 0x11, 0x0E, 0x54, 0xE6, 0xCD,
  35998. 0x11, 0x0A, 0x01, 0x36, 0x41, 0x78, 0xC5, 0x7D,
  35999. 0x00, 0xC6, 0x8D, 0xE7, 0x7B, 0x4C, 0xE6, 0x35,
  36000. 0x57, 0x8F, 0x56, 0xA9, 0x73, 0x5A, 0xEF, 0x93,
  36001. 0xF0, 0xD8, 0x16, 0xE3, 0x44, 0x8A, 0xA0, 0xA9,
  36002. 0xF1, 0x9C, 0x2E, 0x02, 0xD1, 0x3C, 0x66, 0xDD,
  36003. 0xE5, 0x35, 0xFE, 0x81, 0x77, 0x8D, 0xC2, 0x46,
  36004. 0x64, 0x03, 0x23, 0xCC, 0x37, 0x22, 0x60, 0x68,
  36005. 0xCC, 0x7F, 0x79, 0xE8, 0x6B, 0xD0, 0xEE, 0x1C,
  36006. 0x6A, 0xC3, 0x3C, 0xEB, 0x51, 0x95, 0xFA, 0xE4,
  36007. 0x28, 0x17, 0x94, 0x49, 0x22, 0x69, 0x64, 0x98,
  36008. 0x82, 0x8B, 0x68, 0x9F, 0x69, 0x35, 0xF9, 0xBF,
  36009. 0x33, 0x22, 0xA4, 0x32, 0x0F, 0x4C, 0x26, 0xE4,
  36010. 0x8D, 0xDF, 0xAE, 0xBD, 0xF4, 0x4D, 0x01, 0xAF,
  36011. 0xA1, 0xFA, 0x3E, 0xCE, 0xD3, 0xB0, 0x5D, 0x02,
  36012. 0xDB, 0x3B, 0xB4, 0x23, 0xB8, 0x55, 0x97, 0xB5,
  36013. 0x1F, 0x25, 0x64, 0xA7, 0x5D, 0x4A, 0x8C, 0x90,
  36014. 0xD4, 0xB6, 0x85, 0x20, 0x32, 0x09, 0x37, 0x26,
  36015. 0x00, 0xD5, 0x4D, 0x98, 0x5A, 0xCF, 0x29, 0x3B,
  36016. 0x0E, 0xAF, 0x69, 0x88, 0x78, 0x18, 0xAD, 0xD1,
  36017. 0xE1, 0xB7, 0xC5, 0xD7, 0xB7, 0x5F, 0xFE, 0xB5,
  36018. 0x64, 0xE0, 0x68, 0x0B, 0x4F, 0x46, 0x7B, 0xDE,
  36019. 0x0B, 0x11, 0x7A, 0x42, 0x10, 0x86, 0x09, 0x60,
  36020. 0xB5, 0xE0, 0x22, 0x17, 0x28, 0x68, 0x7A, 0xE9,
  36021. 0xEB, 0xBC, 0x6B, 0xD5, 0x95, 0x4C, 0xE0, 0xAE,
  36022. 0x57, 0xB1, 0x45, 0xFF, 0xC2, 0x7E, 0xB6, 0xA0,
  36023. 0xD3, 0x8E, 0x46, 0x16, 0xCE, 0xBE, 0x76, 0xCE,
  36024. 0x59, 0x5B, 0xA4, 0x96, 0x1E, 0x9F, 0x80, 0xF0,
  36025. 0x06, 0x7E, 0xCD, 0x6E, 0x27, 0xB8, 0x7D, 0x26,
  36026. 0xB6, 0x60, 0xA3, 0xAB, 0x52, 0xC1, 0x37, 0x9A,
  36027. 0xDD, 0x46, 0xF5, 0xB9, 0x39, 0x75, 0xAA, 0x19,
  36028. 0xF3, 0xE4, 0xA8, 0x95, 0x4B, 0x25, 0x3F, 0x0B,
  36029. 0x44, 0x13, 0xF5, 0x82, 0x10, 0x68, 0x03, 0xD5,
  36030. 0x0F, 0x99, 0xB5, 0xB2, 0x8B, 0x85, 0x77, 0x2E,
  36031. 0x78, 0x3E, 0xEE, 0x21, 0x6E, 0xAD, 0x2D, 0xCF,
  36032. 0x95, 0x62, 0x94, 0x1C, 0x50, 0xAB, 0xC5, 0xFA,
  36033. 0x8E, 0x24, 0xB6, 0x14, 0x86, 0x46, 0x8A, 0xAA,
  36034. 0x20, 0xDF, 0x15, 0xD1, 0x72, 0xF6, 0xAC, 0x03,
  36035. 0xAF, 0xDF, 0xCD, 0x53, 0x81, 0xBA, 0xDB, 0x07,
  36036. 0x8B, 0x8E, 0xBB, 0x70, 0x91, 0x57, 0x04, 0xB9,
  36037. 0x88, 0xE5, 0x8F, 0x45, 0xD3, 0xD6, 0x31, 0x12,
  36038. 0xA5, 0xC1, 0x28, 0xC6, 0x49, 0x90, 0x0F, 0x1D,
  36039. 0x69, 0x66, 0xE3, 0x98, 0x56, 0x7D, 0xE3, 0x48,
  36040. 0xAC, 0xC0, 0xDE, 0xE4, 0x2B, 0x88, 0x01, 0x19,
  36041. 0x4E, 0x99, 0xBB, 0x1A, 0xAF, 0x02, 0x5A, 0x91,
  36042. 0xE3, 0x2C, 0xE6, 0x56, 0x4D, 0x05, 0x10, 0xB9,
  36043. 0x10, 0xF2, 0x2A, 0x27, 0xDE, 0xCF, 0x9D, 0x2E
  36044. };
  36045. static const byte msg_44[] = {
  36046. 0xB1, 0x34, 0x49, 0x15, 0xCC, 0xD6, 0x93, 0x41,
  36047. 0x6B, 0x37, 0xFE, 0xBD, 0x8D, 0xC7, 0xC7, 0xDB,
  36048. 0x9F, 0x25, 0x3E, 0x9D, 0xF5, 0x3C, 0xEC, 0x51,
  36049. 0x49, 0x23, 0xAA, 0xA2, 0x67, 0x6F, 0xBF, 0xA4,
  36050. 0xCC, 0x04, 0xFC, 0x68, 0xF9, 0xE3, 0x2F, 0x9E,
  36051. 0x86, 0x4C, 0x68, 0x95, 0xDB, 0x37, 0xE9, 0xFF,
  36052. 0xEB, 0x80, 0xF0, 0xF6, 0xB8, 0x6C, 0xB6, 0xAD,
  36053. 0x9C, 0x42, 0xF8, 0xFC, 0x75, 0x19, 0x8D, 0xD3,
  36054. 0xCC, 0xDA, 0xF5, 0x77, 0xC7, 0xB3, 0x5B, 0x8F,
  36055. 0x1B, 0xF6, 0x0A, 0xAB, 0xEA, 0x89, 0x94, 0x42,
  36056. 0x20, 0x1F, 0xBB, 0xF4, 0x42, 0x8C, 0x7E, 0xC1,
  36057. 0x7B, 0xC3, 0x1B, 0x54, 0x72, 0x4B, 0x95, 0x90,
  36058. 0xF7, 0x53, 0x1E, 0x6F, 0x79, 0x0A, 0x1F, 0xA7,
  36059. 0x74, 0x32, 0x83, 0x37, 0x2D, 0x31, 0x71, 0xB8,
  36060. 0x96, 0x6B, 0x47, 0x0A, 0xAA, 0x85, 0x26, 0xEB,
  36061. 0x4A, 0x6E, 0x81, 0xE6, 0x5A, 0xD0, 0xC2, 0x9F,
  36062. 0x2D, 0x37, 0xDD, 0x5B, 0x41, 0x2B, 0xAE, 0x68,
  36063. 0x2A, 0x66, 0x79, 0x68, 0x77, 0xC8, 0x2F, 0xFD,
  36064. 0xA9, 0x76, 0x24, 0x34, 0xEA, 0xC2, 0xC7, 0xD4,
  36065. 0xAF, 0x60, 0x9B, 0x27, 0x72, 0x49, 0x0D, 0xEE,
  36066. 0x9B, 0xFB, 0x00, 0x5D, 0x2F, 0x1A, 0x2E, 0xBB,
  36067. 0xA0, 0x32, 0xCD, 0x71, 0x59, 0xD5, 0x4B, 0xE5,
  36068. 0x96, 0xF3, 0x30, 0x68, 0xBE, 0x5D, 0x9A, 0x2D,
  36069. 0x94, 0x0C, 0x76, 0x70, 0xE6, 0x4E, 0x9A, 0xF7,
  36070. 0xD7, 0xD3, 0x3E, 0xC3, 0xAE, 0xC6, 0xF1, 0xD9,
  36071. 0xDE, 0xE3, 0x92, 0x84, 0xF0, 0x5C, 0xE0, 0x25,
  36072. 0xD1, 0x81, 0x76, 0x0D, 0x40, 0xE5, 0xC2, 0xD9,
  36073. 0xBE, 0xAE, 0x24, 0x20, 0xF4, 0x0D, 0x9F, 0x32,
  36074. 0xB7, 0xBD, 0xCD, 0x3A, 0xFB, 0x1C, 0x66, 0x0D,
  36075. 0x01, 0x71, 0x4D, 0x81, 0x37, 0x58, 0xDB, 0xB8,
  36076. 0x2C, 0x6B, 0x7E, 0x85, 0x80, 0x52, 0xB5, 0xA5,
  36077. 0x0E, 0x39, 0xE0, 0x15, 0xD3, 0xF2, 0x4A, 0x2C,
  36078. 0x64, 0xC9, 0xDD, 0xCC, 0x15, 0x0D, 0x90, 0x4F,
  36079. 0x07, 0xF6, 0x5F, 0xF6, 0x8A, 0xD0, 0x12, 0x9E,
  36080. 0xC3, 0xF8, 0x12, 0x3F, 0x3A, 0x03, 0xFC, 0x95,
  36081. 0x8A, 0xE2, 0x47, 0x8C, 0x6C, 0x6E, 0x03, 0x61,
  36082. 0x67, 0xD8, 0x51, 0x49, 0xF7, 0x9F, 0xB0, 0x3F,
  36083. 0xAA, 0xB9, 0x89, 0x7C, 0xE7, 0x3F, 0x88, 0x55,
  36084. 0xC5, 0x4C, 0x83, 0xD7, 0x53, 0xB1, 0x04, 0xB5,
  36085. 0x13, 0xD5, 0x6B, 0xC6, 0x4C, 0x3B, 0x08, 0x91,
  36086. 0x73, 0x47, 0x35, 0x13, 0x26, 0xD8, 0xEB, 0x47,
  36087. 0xCF, 0x66, 0xF1, 0x3F, 0xB9, 0x0F, 0x6A, 0xF5,
  36088. 0xA8, 0x94, 0xC7, 0x75, 0x00, 0x77, 0xA8, 0x9C,
  36089. 0xEB, 0x77, 0x22, 0xE2, 0xE6, 0x80, 0xA5, 0x9B,
  36090. 0xF8, 0x43, 0x8C, 0x52, 0x35, 0x31, 0xEA, 0x8C,
  36091. 0xC2, 0x83, 0x4F, 0xFC, 0x4E, 0xF0, 0x2D, 0x35,
  36092. 0xB8, 0x51, 0x46, 0xF2, 0xD6, 0x01, 0xD5, 0x00,
  36093. 0x99, 0x6A, 0x44, 0x10, 0x64, 0xAD, 0xCA, 0x1F,
  36094. 0x62, 0x3F, 0x2F, 0xE7, 0x45, 0x22, 0x47, 0xEF,
  36095. 0x86, 0x9D, 0x76, 0xD5, 0x78, 0x42, 0x07, 0x30,
  36096. 0x88, 0x86, 0x90, 0xB1, 0xA0, 0x08, 0xDA, 0x28,
  36097. 0x2A, 0xD1, 0x75, 0x7D, 0x21, 0x71, 0x29, 0x38,
  36098. 0x59, 0xC7, 0x3F, 0x55, 0x20, 0xB5, 0xBB, 0x48,
  36099. 0x03, 0xE7, 0xFA, 0xB0, 0x29, 0x00, 0xD2, 0x0F,
  36100. 0xE7, 0x65, 0x81, 0x8E, 0xE6, 0x24, 0xE7, 0xA1,
  36101. 0x94, 0x50, 0x9D, 0x01, 0x6B, 0x4B, 0xD7, 0x81,
  36102. 0x4E, 0xA0, 0xD5, 0x4A, 0x51, 0xEE, 0x95, 0x0A,
  36103. 0x14, 0x76, 0xD5, 0x87, 0xAA, 0x6F, 0x78, 0xC8,
  36104. 0xD2, 0xE0, 0xC8, 0xF8, 0xF2, 0x78, 0xD8, 0x2E,
  36105. 0x11, 0x90, 0x44, 0xB6, 0xBF, 0xD0, 0xBE, 0xD8,
  36106. 0x6F, 0xA4, 0x20, 0xA2, 0xC8, 0xA4, 0xEF, 0xB0,
  36107. 0x5D, 0x73, 0x06, 0xBE, 0x52, 0xF9, 0x32, 0xD8,
  36108. 0x06, 0x5D, 0xD1, 0x29, 0x23, 0x46, 0x25, 0x6E,
  36109. 0x42, 0x9D, 0xEE, 0x41, 0x9E, 0xF3, 0x7D, 0x1B,
  36110. 0x35, 0x28, 0x81, 0xDC, 0x47, 0x7F, 0x25, 0xA4,
  36111. 0x0A, 0xEB, 0x3E, 0x17, 0xE6, 0x1B, 0xCC, 0x00,
  36112. 0xD2, 0xE2, 0xA9, 0x3D, 0xEC, 0xF3, 0x00, 0xF0,
  36113. 0x81, 0x68, 0x21, 0xED, 0x49, 0xF9, 0x9B, 0x9B,
  36114. 0x8B, 0xED, 0xD9, 0x1E, 0xFA, 0x04, 0xBB, 0xB0,
  36115. 0x9A, 0xBD, 0x1D, 0x24, 0x36, 0xA7, 0xD6, 0x64,
  36116. 0x8A, 0x38, 0x3A, 0x3A, 0x8F, 0x09, 0x08, 0x0E,
  36117. 0x46, 0x7B, 0xE1, 0x03, 0x30, 0xBF, 0x62, 0x27,
  36118. 0x10, 0x74, 0xBE, 0xBD, 0x7F, 0x56, 0x39, 0x0D,
  36119. 0x1D, 0x39, 0x47, 0xF4, 0x02, 0x47, 0x6B, 0x62,
  36120. 0x6B, 0x52, 0xAC, 0xAB, 0x21, 0xAC, 0x10, 0x4A,
  36121. 0xAB, 0x59, 0x75, 0x33, 0x11, 0xD9, 0xE9, 0xE2,
  36122. 0xB2, 0x20, 0x6B, 0xA1, 0x09, 0x42, 0xB6, 0x37,
  36123. 0xE4, 0x5C, 0xE6, 0x9F, 0x54, 0xB4, 0x67, 0xBC,
  36124. 0xAE, 0xF3, 0xDC, 0x1A, 0xA2, 0x15, 0x47, 0x7B,
  36125. 0x15, 0xC8, 0x00, 0x35, 0x8E, 0x1D, 0x69, 0x04,
  36126. 0xD8, 0x9C, 0xA9, 0x6A, 0x03, 0x1A, 0x55, 0x48,
  36127. 0x6C, 0x4F, 0xC1, 0x68, 0x27, 0x26, 0x13, 0xAB,
  36128. 0x8E, 0x03, 0x50, 0x7B, 0xDD, 0xC2, 0x7E, 0x5C,
  36129. 0x8A, 0x6F, 0xBB, 0x5F, 0x8B, 0x22, 0x86, 0xA5,
  36130. 0xC5, 0x0E, 0xC5, 0x68, 0x60, 0xF6, 0xBF, 0xFF,
  36131. 0x6E, 0xBA, 0xDC, 0x21, 0x71, 0xD2, 0xEB, 0xD1,
  36132. 0x27, 0x8C, 0x58, 0x14, 0xC3, 0x2E, 0x13, 0x9E,
  36133. 0x04, 0x09, 0x61, 0xC3, 0x19, 0xC3, 0x03, 0x48,
  36134. 0x70, 0x33, 0x3B, 0x12, 0xF7, 0x3B, 0x38, 0xE7,
  36135. 0x18, 0x14, 0xA9, 0xF1, 0x60, 0x83, 0x65, 0xEB,
  36136. 0x32, 0xD5, 0x23, 0x8F, 0x6B, 0xF7, 0xD8, 0x00,
  36137. 0x21, 0xBD, 0xA3, 0x98, 0xDE, 0xD7, 0x13, 0x17,
  36138. 0xAB, 0x3C, 0xA4, 0xD7, 0xBE, 0x1D, 0xA7, 0x4A,
  36139. 0x1B, 0xC4, 0x0C, 0x9B, 0x2E, 0x34, 0x5B, 0xA7,
  36140. 0xA2, 0x3F, 0x9B, 0x2D, 0xDB, 0xAF, 0x85, 0x14,
  36141. 0x0A, 0xF9, 0x30, 0x9E, 0x86, 0x53, 0xAC, 0x24,
  36142. 0xAF, 0xD8, 0x25, 0xBC, 0x2A, 0x07, 0x2B, 0xCD,
  36143. 0x02, 0xFE, 0x3E, 0xF0, 0x0B, 0xE3, 0xF9, 0x51,
  36144. 0x5C, 0x29, 0xEB, 0x8A, 0xFB, 0xC3, 0xEF, 0xD1,
  36145. 0xF9, 0xCF, 0xDF, 0xE9, 0xEB, 0xA9, 0x49, 0x59,
  36146. 0xB5, 0x17, 0x7E, 0x28, 0x86, 0xB8, 0xD1, 0x8D,
  36147. 0xCA, 0x97, 0xF0, 0xCB, 0x80, 0x7E, 0xE3, 0xEA,
  36148. 0xE3, 0x1B, 0x48, 0xCF, 0xAC, 0x61, 0x3C, 0x2E,
  36149. 0x00, 0xAB, 0x74, 0xFB, 0x95, 0xF6, 0x64, 0xF3,
  36150. 0xCA, 0xBF, 0x6E, 0xEF, 0xCD, 0xDD, 0x6D, 0xA5,
  36151. 0xF8, 0x98, 0xEC, 0x38, 0xF2, 0xF0, 0x7D, 0x6D,
  36152. 0xCB, 0x75, 0xE0, 0x50, 0x9D, 0x13, 0x19, 0x24,
  36153. 0x07, 0x4C, 0x05, 0xF4, 0x5D, 0xCA, 0x25, 0xB7,
  36154. 0xCF, 0xE2, 0xBC, 0xFE, 0xEC, 0xAF, 0x5F, 0xC3,
  36155. 0x6C, 0xE6, 0xE3, 0xC5, 0x85, 0x43, 0x7B, 0x06,
  36156. 0x9F, 0xD2, 0xC6, 0xBB, 0xAD, 0x33, 0xD6, 0x86,
  36157. 0xBD, 0x5B, 0x9E, 0x2C, 0xA0, 0xD9, 0x8B, 0xDC,
  36158. 0x5E, 0x71, 0x7B, 0x6D, 0xF7, 0x1D, 0x40, 0x91,
  36159. 0x30, 0x8E, 0x84, 0x73, 0x9A, 0xD6, 0x7F, 0xA6,
  36160. 0x79, 0xA6, 0xCE, 0xE9, 0xA6, 0x83, 0x28, 0x4B,
  36161. 0x4F, 0xB3, 0x1B, 0x2C, 0x40, 0x8F, 0x52, 0xF0,
  36162. 0x59, 0x7D, 0x9C, 0x04, 0xEA, 0xF4, 0xAC, 0x6D,
  36163. 0xBB, 0x6C, 0x3F, 0xD6, 0x7F, 0x25, 0x39, 0xD8,
  36164. 0x87, 0xDF, 0xBC, 0xF3, 0xCA, 0xE4, 0x59, 0xFA,
  36165. 0x76, 0x66, 0x61, 0xA4, 0x8B, 0xFC, 0xFD, 0x6F,
  36166. 0x64, 0x03, 0x99, 0xD3, 0xAF, 0x07, 0x86, 0x35,
  36167. 0x99, 0x98, 0xCE, 0xFF, 0x7E, 0x9E, 0xB1, 0xB0,
  36168. 0x57, 0xA6, 0x29, 0x3D, 0xFF, 0xB7, 0xF3, 0xF2,
  36169. 0x51, 0x4B, 0x0B, 0x70, 0x29, 0x46, 0x06, 0x8A,
  36170. 0x6B, 0xBD, 0x75, 0x30, 0xD6, 0x91, 0x7F, 0xB1,
  36171. 0x1D, 0xBB, 0xAA, 0xBE, 0xD7, 0xAA, 0x46, 0x81,
  36172. 0xD7, 0x8A, 0xEA, 0x91, 0x86, 0x69, 0x2D, 0xDA,
  36173. 0x34, 0x70, 0x65, 0x2E, 0xB8, 0xA3, 0xF1, 0x44,
  36174. 0x56, 0xA5, 0xAA, 0xC4, 0x20, 0x88, 0x3B, 0x42,
  36175. 0x37, 0xB0, 0xA7, 0x2D, 0x91, 0x27, 0x63, 0xB6,
  36176. 0x7A, 0xC4, 0x13, 0x1A, 0x8A, 0x5D, 0x2F, 0x16,
  36177. 0x82, 0x96, 0xB9, 0x12, 0xD3, 0xB6, 0x61, 0xC4,
  36178. 0xE8, 0x3C, 0xE6, 0x3A, 0x61, 0xC0, 0x45, 0xEB,
  36179. 0xA5, 0x75, 0xEE, 0xB6, 0x7F, 0xB0, 0x70, 0xED,
  36180. 0x82, 0x39, 0xE5, 0x1A, 0x67, 0xD9, 0x80, 0x3C,
  36181. 0xE0, 0x0B, 0x85, 0x66, 0x74, 0xE0, 0xB7, 0x26,
  36182. 0x66, 0x26, 0xDD, 0x02, 0x15, 0xE5, 0xEF, 0x5F,
  36183. 0xDE, 0x7B, 0xF4, 0x0B, 0x99, 0x10, 0x21, 0x08,
  36184. 0xFC, 0x2D, 0xF2, 0x8B, 0xDC, 0xC8, 0xEA, 0xC6,
  36185. 0x3E, 0xFB, 0x20, 0x50, 0x1F, 0x24, 0x66, 0x99,
  36186. 0x80, 0x88, 0xC7, 0xA0, 0xB9, 0x6D, 0x1B, 0x75,
  36187. 0xC4, 0xC2, 0xE2, 0x52, 0xA0, 0xBF, 0x38, 0x01,
  36188. 0x5C, 0xA5, 0x8A, 0xDA, 0x79, 0x38, 0xAE, 0x2E,
  36189. 0xC7, 0x96, 0x6F, 0x30, 0x5B, 0xB4, 0x21, 0xC0,
  36190. 0xCD, 0x95, 0xCA, 0xD2, 0x12, 0x7D, 0xAD, 0x87,
  36191. 0x08, 0x6C, 0xC3, 0x8B, 0xF6, 0xB1, 0x5D, 0xAD,
  36192. 0x2C, 0x7C, 0x04, 0x41, 0xE5, 0x34, 0x2E, 0x4B,
  36193. 0x5A, 0xD9, 0x1E, 0x66, 0xF4, 0x23, 0xE2, 0x88,
  36194. 0x4D, 0xD9, 0x03, 0xFE, 0x6C, 0x64, 0x7D, 0x61,
  36195. 0xE6, 0x70, 0x0E, 0xA8, 0x83, 0x08, 0x07, 0xE6,
  36196. 0xFD, 0x64, 0x54, 0x3E, 0x3C, 0x6E, 0x9A, 0xD1,
  36197. 0x93, 0x37, 0x36, 0x90, 0xDE, 0x94, 0xF7, 0x16,
  36198. 0x15, 0x47, 0x94, 0xFE, 0x97, 0x5B, 0x11, 0x80,
  36199. 0xBA, 0x40, 0xAF, 0x7F, 0x05, 0xC1, 0x82, 0x91,
  36200. 0x69, 0xFD, 0xFB, 0xEC, 0x3A, 0xF7, 0xCF, 0xE1,
  36201. 0xD7, 0x9B, 0x59, 0x7E, 0xE4, 0x38, 0xA2, 0x96,
  36202. 0xEF, 0x14, 0x6A, 0x05, 0x99, 0x71, 0xE3, 0xF9,
  36203. 0x50, 0x8E, 0x35, 0x0B, 0x50, 0x71, 0x6D, 0xEC,
  36204. 0xB5, 0x1B, 0xC8, 0x80, 0x2A, 0xE6, 0x2A, 0x7F,
  36205. 0x4C, 0x2E, 0x6F, 0x7B, 0x54, 0x62, 0x0E, 0xF0,
  36206. 0x4C, 0x00, 0xF0, 0x72, 0xAE, 0x37, 0xAC, 0x32,
  36207. 0x7E, 0x26, 0xD3, 0x65, 0x76, 0x1C, 0x10, 0x46,
  36208. 0x17, 0xAE, 0xE0, 0xF3, 0x28, 0xEE, 0x97, 0xE0,
  36209. 0x86, 0x18, 0x3D, 0x46, 0xA3, 0x62, 0x1F, 0x23,
  36210. 0xF3, 0xAC, 0x27, 0x60, 0xB8, 0x85, 0x9A, 0x96,
  36211. 0x0E, 0xF1, 0x6F, 0xC1, 0xC6, 0xB1, 0x97, 0x8A,
  36212. 0x74, 0x12, 0xDD, 0x73, 0x85, 0x02, 0x9C, 0x73,
  36213. 0x61, 0xA8, 0xF7, 0x49, 0xCE, 0xBA, 0x23, 0xED,
  36214. 0xE7, 0x9A, 0x17, 0x0E, 0xA6, 0x84, 0x59, 0xF5,
  36215. 0x21, 0x66, 0xF5, 0xC5, 0x61, 0xF8, 0x88, 0x7E,
  36216. 0x62, 0x0C, 0x00, 0xC6, 0x4F, 0x06, 0xBD, 0x0A,
  36217. 0xBB, 0xCD, 0xE5, 0x11, 0x7A, 0xBC, 0xFD, 0x03,
  36218. 0xB6, 0xD1, 0xBA, 0x4F, 0x30, 0xFA, 0x96, 0x75,
  36219. 0xD8, 0x2D, 0x7A, 0x43, 0x0D, 0x58, 0x41, 0x46,
  36220. 0xBA, 0x72, 0x06, 0xCB, 0xBD, 0xD9, 0xBE, 0xA1,
  36221. 0xEA, 0x47, 0x08, 0x3D, 0xF9, 0x32, 0x23, 0x9C,
  36222. 0xAA, 0x02, 0x1D, 0xA3, 0x3E, 0x43, 0xF1, 0x68,
  36223. 0xD8, 0xBE, 0x9F, 0x0E, 0xA8, 0xA8, 0x52, 0xC4,
  36224. 0x0A, 0xDE, 0x43, 0x9D, 0x58, 0xA8, 0x05, 0xD4,
  36225. 0x74, 0xF8, 0x93, 0x21, 0x62, 0x6E, 0x33, 0x78,
  36226. 0x3C, 0x23, 0xEB, 0x60, 0x1C, 0x4C, 0x25, 0xFE,
  36227. 0x0F, 0x5E, 0x73, 0xC3, 0xAD, 0x33, 0x9A, 0x7D,
  36228. 0x69, 0x6B, 0xAB, 0x2C, 0xAA, 0x5F, 0xBF, 0x96,
  36229. 0x62, 0x3A, 0xF0, 0x63, 0x41, 0x00, 0xC7, 0x4C,
  36230. 0x81, 0x4D, 0x42, 0x43, 0x25, 0xBC, 0x30, 0xB6,
  36231. 0x0B, 0xEE, 0xFC, 0x18, 0x3E, 0x68, 0x0E, 0x64,
  36232. 0x5C, 0xD4, 0x22, 0x2A, 0xBA, 0xB5, 0xC6, 0x7E,
  36233. 0x67, 0x11, 0x1C, 0x4C, 0x03, 0x30, 0xEC, 0x0C,
  36234. 0x77, 0xB2, 0x2B, 0xBC, 0x98, 0xF7, 0x52, 0x8C,
  36235. 0x95, 0x66, 0xE1, 0x71, 0xDD, 0x26, 0xA7, 0x7F,
  36236. 0x87, 0xF3, 0x94, 0x2E, 0x0D, 0x3E, 0xFE, 0xAD,
  36237. 0x0A, 0xDA, 0x3B, 0x77, 0x49, 0xC5, 0x1D, 0xED,
  36238. 0x5F, 0xDA, 0x3F, 0xE6, 0xE7, 0x96, 0x58, 0xF1,
  36239. 0x02, 0x30, 0x68, 0xB9, 0x62, 0xD0, 0x58, 0xA2,
  36240. 0x89, 0x65, 0x12, 0x20, 0x1E, 0x4C, 0xE7, 0xB6,
  36241. 0x98, 0x12, 0x52, 0xF0, 0xE8, 0x55, 0xBC, 0xFE,
  36242. 0x1F, 0x44, 0x42, 0x36, 0xC9, 0x30, 0xE4, 0x9A,
  36243. 0x13, 0xB3, 0x7A, 0xF4, 0xF5, 0x97, 0xC0, 0x5D,
  36244. 0xCA, 0x23, 0xCC, 0x05, 0xC4, 0x3C, 0x32, 0xA2,
  36245. 0x11, 0x08, 0x17, 0xCB, 0x30, 0x6B, 0xA4, 0x7D,
  36246. 0x24, 0x5E, 0x50, 0x22, 0x2E, 0x23, 0xC6, 0x55,
  36247. 0x6B, 0xD7, 0x5D, 0x50, 0xEE, 0xF8, 0xBE, 0xB0,
  36248. 0xDE, 0x83, 0x5C, 0x8D, 0xD2, 0xE1, 0x5C, 0x70,
  36249. 0x66, 0x70, 0x59, 0x8F, 0x86, 0x50, 0x71, 0x71,
  36250. 0x04, 0x69, 0xEC, 0xB3, 0x47, 0x9E, 0xE0, 0x26,
  36251. 0xB1, 0x9F, 0xE6, 0x21, 0xAC, 0x99, 0x12, 0x6B,
  36252. 0x97, 0x9E, 0x1B, 0xA1, 0xDD, 0xA8, 0xE6, 0x11,
  36253. 0x12, 0x97, 0xC1, 0x0E, 0x4A, 0x77, 0xF5, 0x52,
  36254. 0xF8, 0x09, 0xE9, 0x01, 0x63, 0x56, 0x4E, 0xFA,
  36255. 0x24, 0x39, 0x36, 0xB9, 0xF2, 0x6E, 0x07, 0x28,
  36256. 0x7F, 0xA4, 0x07, 0x7C, 0xA2, 0x69, 0x7B, 0xED,
  36257. 0x6A, 0x4F, 0x0A, 0x95, 0x99, 0x05, 0x60, 0xE7,
  36258. 0x58, 0xD9, 0x90, 0xB4, 0xC1, 0x92, 0x0F, 0x9E,
  36259. 0x1A, 0xBE, 0x0B, 0x58, 0x96, 0x50, 0x61, 0x1C,
  36260. 0x2D, 0x5A, 0x13, 0xAA, 0x5F, 0x4E, 0x2B, 0x88,
  36261. 0xBE, 0xAB, 0x93, 0x72, 0xF4, 0x68, 0xB8, 0x30,
  36262. 0x91, 0xCD, 0x0A, 0x53, 0x8A, 0x35, 0x82, 0x93,
  36263. 0x4F, 0x66, 0xCA, 0xCD, 0xF2, 0x39, 0x98, 0xFE,
  36264. 0xC2, 0xFE, 0xFE, 0x51, 0x35, 0xF1, 0xB5, 0x62,
  36265. 0x2D, 0x1A, 0xE9, 0x43, 0x25, 0x5E, 0x05, 0xE4,
  36266. 0x8B, 0xFE, 0x91, 0x2F, 0x4F, 0x24, 0x1B, 0x2B,
  36267. 0xAC, 0x49, 0x9C, 0x14, 0xB0, 0x58, 0xA3, 0xA8,
  36268. 0xEE, 0xB9, 0xD1, 0xFA, 0x4D, 0x44, 0x2E, 0x23,
  36269. 0xFC, 0x59, 0x77, 0xA5, 0x60, 0x2E, 0xDC, 0xEB,
  36270. 0x7B, 0x7B, 0x26, 0x95, 0xE1, 0x87, 0xB7, 0x94,
  36271. 0xF8, 0x4B, 0x96, 0x63, 0x15, 0xB1, 0xBB, 0xA5,
  36272. 0xC0, 0x4A, 0x72, 0x02, 0x4A, 0x80, 0x5F, 0xB1,
  36273. 0x94, 0x73, 0xB7, 0x06, 0xB8, 0x13, 0x76, 0x42,
  36274. 0xAD, 0xB1, 0xC6, 0x6C, 0xFD, 0x64, 0xF2, 0x60,
  36275. 0xBB, 0x1B, 0x7A, 0xAD, 0xF6, 0xC2, 0x96, 0xB3,
  36276. 0x5F, 0x30, 0xB9, 0xD7, 0x70, 0x8A, 0x9D, 0x41,
  36277. 0xE7, 0x23, 0xFA, 0xD4, 0xE8, 0x72, 0xAF, 0x73,
  36278. 0xF8, 0x8C, 0x26, 0xAB, 0x65, 0x1B, 0xD5, 0x7A,
  36279. 0x21, 0xE2, 0x8C, 0xE8, 0xC2, 0x47, 0xD5, 0x8E,
  36280. 0x47, 0x9F, 0x79, 0x68, 0x87, 0x6F, 0xCE, 0xD3,
  36281. 0x5D, 0x2B, 0x87, 0xD2, 0xDF, 0x14, 0x43, 0x47,
  36282. 0x03, 0x3D, 0xF4, 0xCB, 0x50, 0xDE, 0x52, 0xD8,
  36283. 0x98, 0x41, 0x46, 0x3F, 0x5D, 0xFB, 0x6D, 0x6F,
  36284. 0xF6, 0xD9, 0xE8, 0x2B, 0xBA, 0xB3, 0xB1, 0xEC,
  36285. 0x58, 0x77, 0x8A, 0xB8, 0xF3, 0x6D, 0xBC, 0x68,
  36286. 0x22, 0xEA, 0xE3, 0x2F, 0xB6, 0xCB, 0x67, 0x30,
  36287. 0xCB, 0x33, 0x1C, 0x39, 0x5C, 0x27, 0x4A, 0xE7,
  36288. 0xE3, 0x7B, 0x40, 0x9B, 0x7C, 0x66, 0x32, 0xE7,
  36289. 0x6D, 0xAA, 0x97, 0xB8, 0x0F, 0x1E, 0x0C, 0xB4,
  36290. 0x7A, 0xA3, 0x66, 0xA8, 0xE3, 0x50, 0xEA, 0x36,
  36291. 0x74, 0x65, 0x92, 0xEC, 0x9B, 0x1E, 0x97, 0xF0,
  36292. 0x2F, 0x99, 0xD6, 0x00, 0x21, 0x37, 0x0B, 0x89,
  36293. 0x93, 0xC6, 0x80, 0xA1, 0x02, 0xDC, 0x96, 0x5D,
  36294. 0x20, 0xB7, 0x57, 0xF4, 0x17, 0x7A, 0x81, 0xBA,
  36295. 0x7B, 0x61, 0xD2, 0x88, 0xEF, 0xC5, 0xAD, 0xED,
  36296. 0x4C, 0x9A, 0x94, 0xA5, 0x7B, 0x2C, 0x6B, 0xD2,
  36297. 0x97, 0x7E, 0x23, 0x64, 0x0A, 0x66, 0x98, 0x47,
  36298. 0xEE, 0x81, 0xB1, 0x49, 0x0B, 0xE3, 0x8A, 0xC4,
  36299. 0x3E, 0x52, 0x2C, 0x8D, 0x09, 0xA2, 0x07, 0xB6,
  36300. 0x2A, 0x8B, 0x07, 0x9A, 0x24, 0x84, 0xDE, 0xD1,
  36301. 0x00, 0x63, 0xD7, 0xA1, 0x3F, 0xBF, 0x0C, 0xA8,
  36302. 0xEE, 0xDC, 0x2B, 0xF6, 0x7B, 0xD8, 0x78, 0x53,
  36303. 0x35, 0xB8, 0x29, 0x5A, 0xFE, 0x6B, 0x35, 0x6E,
  36304. 0x20, 0x62, 0x24, 0x17, 0x0E, 0x87, 0x23, 0x1A,
  36305. 0x77, 0x2D, 0x21, 0x84, 0x37, 0xBF, 0x7D, 0x68,
  36306. 0xAC, 0x2A, 0xF9, 0x3F, 0x11, 0x27, 0x18, 0x4F,
  36307. 0xA2, 0x15, 0x21, 0x47, 0x9E, 0x56, 0xFF, 0x22,
  36308. 0xE8, 0x0F, 0x61, 0xBC, 0x28, 0xB8, 0xD2, 0xE7,
  36309. 0x1B, 0x3D, 0x1D, 0x94, 0x28, 0x1B, 0x69, 0x56,
  36310. 0x00, 0xC8, 0xB0, 0xFD, 0x8E, 0x1D, 0x7E, 0x81,
  36311. 0x1F, 0x4C, 0xCF, 0xE1, 0x6E, 0x3F, 0x57, 0x95,
  36312. 0xC2, 0x4A, 0xA0, 0xA0, 0x16, 0x7E, 0x30, 0x5C,
  36313. 0x28, 0x87, 0x5C, 0x8F, 0xA9, 0x38, 0x9B, 0x72,
  36314. 0xF7, 0x90, 0x86, 0xF6, 0xEC, 0xC1, 0x6C, 0x88,
  36315. 0xB0, 0x78, 0x3A, 0x58, 0x15, 0xFB, 0x6F, 0x77,
  36316. 0xCD, 0xC7, 0xCC, 0xC3, 0x8D, 0x60, 0xE7, 0x87,
  36317. 0xBE, 0x9C, 0xBF, 0xFA, 0xA6, 0x2E, 0xF9, 0x59,
  36318. 0xA5, 0xE5, 0xDC, 0xDE, 0xB6, 0x25, 0x5C, 0x8E,
  36319. 0x0D, 0x2E, 0x01, 0xFE, 0x05, 0xEF, 0xF9, 0xE7,
  36320. 0x81, 0x02, 0xBE, 0xA2, 0x91, 0x40, 0x57, 0xD3,
  36321. 0x6E, 0x3D, 0x1B, 0x48, 0x50, 0x7A, 0xB6, 0xB1,
  36322. 0x76, 0x40, 0x47, 0x0F, 0xE3, 0xF1, 0x7A, 0x8B,
  36323. 0x6A, 0x5E, 0x04, 0xE5, 0x34, 0x56, 0xC5, 0xD9,
  36324. 0xE5, 0x0F, 0x74, 0x5D, 0xE0, 0x6F, 0x9A, 0xED,
  36325. 0xF4, 0xBF, 0xCF, 0x31, 0xB0, 0xC6, 0xED, 0x12,
  36326. 0x13, 0x36, 0x54, 0xCB, 0xC8, 0xDE, 0xF7, 0xF6,
  36327. 0x60, 0x9E, 0x12, 0x2C, 0x2E, 0x4C, 0x93, 0x3E,
  36328. 0x6F, 0xCB, 0x0F, 0x3D, 0x8C, 0xCA, 0xE8, 0xCA,
  36329. 0x0B, 0x10, 0xED, 0xDA, 0xE8, 0xDB, 0x29, 0x7C,
  36330. 0x8B, 0x32, 0x31, 0xC8, 0x94, 0x34, 0xA5, 0xF5,
  36331. 0x4D, 0x01, 0x28, 0xC8, 0x3A, 0xA6, 0xFD, 0xE2,
  36332. 0x9A, 0xB7, 0x0C, 0xDA, 0x43, 0x78, 0x45, 0x45,
  36333. 0xFE, 0xE9, 0xFF, 0x6E, 0xD4, 0x44, 0xF8, 0x88,
  36334. 0x66, 0x4D, 0xD2, 0x2B, 0x2E, 0x2D, 0xF5, 0x7C,
  36335. 0xA6, 0x53, 0xB6, 0xD2, 0x10, 0xE6, 0xB4, 0x0B,
  36336. 0x7F, 0xC2, 0x1F, 0xE0, 0x63, 0x90, 0xCA, 0x5D,
  36337. 0x5E, 0x60, 0xF5, 0x8A, 0xB1, 0x4C, 0x49, 0x03,
  36338. 0xD4, 0x38, 0xAE, 0xEF, 0xB1, 0x7C, 0xA4, 0xB9,
  36339. 0x98, 0x70, 0x6A, 0x0E, 0xD6, 0xA4, 0xA6, 0xF4,
  36340. 0x74, 0xB1, 0xBA, 0x1D, 0x48, 0xCC, 0xC1, 0x14,
  36341. 0x3C, 0x84, 0xA8, 0xD2, 0xE7, 0x8D, 0xEC, 0x11,
  36342. 0x61, 0x8C, 0x76, 0xB6, 0xDA, 0x28, 0xBC, 0x39,
  36343. 0xDF, 0x68, 0xAD, 0x24, 0xA4, 0x07, 0xE1, 0x07,
  36344. 0x33, 0xDD, 0x18, 0x9D, 0x5D, 0xAA, 0x90, 0x4B,
  36345. 0xEF, 0x88, 0x18, 0x6E, 0xB6, 0x83, 0x21, 0x45,
  36346. 0x94, 0x0F, 0x15, 0xB8, 0xAC, 0xD9, 0xD1, 0x8D,
  36347. 0x4F, 0x17, 0xC8, 0xD9, 0x17, 0xB0, 0x9D, 0x54,
  36348. 0xF2, 0x5F, 0x56, 0x09, 0xD3, 0x80, 0x20, 0x77,
  36349. 0x44, 0x23, 0x90, 0xAB, 0xB6, 0x0B, 0x51, 0xA7,
  36350. 0x41, 0xC5, 0xD4, 0x42, 0x5B, 0xD4, 0x67, 0x89,
  36351. 0xE6, 0xEC, 0x1E, 0x7D, 0x22, 0xD5, 0x6E, 0x7F,
  36352. 0x34, 0xCE, 0x7A, 0x07, 0x2B, 0x63, 0x0A, 0x69,
  36353. 0x51, 0x71, 0x8C, 0x13, 0x63, 0xB8, 0x79, 0x6D,
  36354. 0x94, 0xEA, 0xAF, 0x86, 0x30, 0xD2, 0x22, 0x6C,
  36355. 0x67, 0x82, 0x6C, 0xDE, 0xEA, 0x71, 0xE8, 0xD1,
  36356. 0x36, 0xF3, 0x64, 0x2F, 0x79, 0xE6, 0x92, 0xF0,
  36357. 0x4B, 0x05, 0x14, 0x7E, 0x40, 0xCE, 0x0C, 0x53,
  36358. 0xCA, 0x08, 0xEF, 0x0A, 0xA6, 0xA5, 0x73, 0x99,
  36359. 0xFD, 0xF3, 0xED, 0xBD, 0x54, 0x56, 0x6E, 0x66,
  36360. 0xEF, 0xCC, 0xE1, 0x6F, 0x0C, 0x44, 0x76, 0x84,
  36361. 0xF5, 0x55, 0x2B, 0xA3, 0x6B, 0x20, 0x60, 0x54,
  36362. 0x3F, 0xC1, 0x35, 0x58, 0xD8, 0xD8, 0x9E, 0x18,
  36363. 0x63, 0x70, 0x73, 0xEF, 0x6A, 0x87, 0x46, 0x77,
  36364. 0xA9, 0x7F, 0x9F, 0xA0, 0x23, 0x4B, 0x14, 0x00,
  36365. 0x61, 0xC7, 0xE3, 0x44, 0xBE, 0xD6, 0x09, 0x71,
  36366. 0xE3, 0x58, 0x44, 0x9A, 0xCD, 0x17, 0xE5, 0x8E,
  36367. 0x6D, 0x05, 0xBB, 0x21, 0x44, 0xD7, 0x4B, 0xD8,
  36368. 0x9A, 0xE9, 0x7A, 0x75, 0x91, 0x43, 0xAD, 0x84,
  36369. 0x5B, 0x02, 0x70, 0xBE, 0x67, 0x0B, 0x1E, 0x1E,
  36370. 0x92, 0xB8, 0xC7, 0xB6, 0x5F, 0xE1, 0x60, 0x23,
  36371. 0xF5, 0x30, 0xE4, 0xD0, 0xCF, 0x70, 0x03, 0xD1,
  36372. 0x85, 0x4A, 0x50, 0xDC, 0xF4, 0x9C, 0x29, 0xAB,
  36373. 0x0E, 0xA4, 0x7B, 0x2E, 0x3B, 0xDB, 0xBF, 0x52,
  36374. 0xD5, 0x8A, 0x91, 0x47, 0xA9, 0xD1, 0x23, 0xEB,
  36375. 0xC5, 0x6F, 0x11, 0xBB, 0xEE, 0xBB, 0x29, 0xD7,
  36376. 0x31, 0xAB, 0x99, 0x27, 0x5E, 0xF3, 0xA9, 0x23,
  36377. 0xFF, 0x70, 0x87, 0x83, 0xCC, 0x26, 0x92, 0x06,
  36378. 0xEC, 0xD3, 0x8C, 0xF9, 0x47, 0x34, 0x7D, 0x1E,
  36379. 0x71, 0xAF, 0xCF, 0x9D, 0xBF, 0x29, 0x1B, 0x95,
  36380. 0x27, 0x48, 0x55, 0xCE, 0xE2, 0xAC, 0x25, 0x61,
  36381. 0x83, 0xD9, 0x7B, 0x26, 0xEF, 0x94, 0x9A, 0x95,
  36382. 0x0C, 0xD1, 0xE4, 0x0A, 0x51, 0x50, 0x1F, 0x86,
  36383. 0x7A, 0x7B, 0xD3, 0x83, 0x55, 0x2D, 0xFC, 0x7B,
  36384. 0x97, 0x77, 0x17, 0x67, 0xBB, 0x9F, 0xD7, 0xD1,
  36385. 0xDD, 0xDD, 0x49, 0x67, 0xBB, 0xF7, 0x9A, 0x45,
  36386. 0x33, 0x24, 0xCA, 0xBC, 0xA5, 0xB2, 0x0D, 0x3F,
  36387. 0xB0, 0x10, 0x6D, 0xB9, 0x7D, 0x03, 0x3F, 0xCD,
  36388. 0x40, 0x37, 0x1E, 0x8A, 0xDA, 0xCD, 0xBA, 0xD7,
  36389. 0x8D, 0x89, 0xBD, 0x5E, 0x90, 0xCF, 0x97, 0xE8,
  36390. 0x35, 0x51, 0x87, 0x94, 0xFA, 0x3D, 0xB2, 0xB5,
  36391. 0x01, 0xF2, 0x35, 0x75, 0x77, 0x65, 0x5B, 0x9A,
  36392. 0x3C, 0xDA, 0x36, 0x52, 0xDF, 0xCF, 0x96, 0xBA,
  36393. 0xB9, 0xC5, 0xF9, 0x57, 0x67, 0x0E, 0x32, 0xE5,
  36394. 0x86, 0xE5, 0x1F, 0xD8, 0x9D, 0x7B, 0xA8, 0x76,
  36395. 0x89, 0xFD, 0x59, 0x70, 0x88, 0x73, 0x9D, 0x87,
  36396. 0xE1, 0x24, 0x6D, 0xC2, 0xB5, 0x1E, 0xCD, 0x54,
  36397. 0x29, 0x25, 0x10, 0xA3, 0xB4, 0x3C, 0xB2, 0x5A,
  36398. 0x62, 0xBD, 0xE9, 0x14, 0xEC, 0x3C, 0xBF, 0xA9,
  36399. 0x9D, 0xEC, 0x70, 0xAC, 0x23, 0xC0, 0xDF, 0xC9,
  36400. 0x69, 0xAD, 0x94, 0x1A, 0x69, 0x94, 0xA3, 0x70,
  36401. 0xF9, 0x0B, 0x15, 0x5D, 0x25, 0x45, 0x63, 0xFA,
  36402. 0xAA, 0x7D, 0x30, 0x67, 0x3C, 0x06, 0x34, 0x75,
  36403. 0x3F, 0xD6, 0x57, 0x58, 0x8E, 0xC6, 0x60, 0x3F,
  36404. 0x82, 0x35, 0xE9, 0x17, 0x36, 0x5D, 0xD8, 0x93,
  36405. 0x25, 0x25, 0x1B, 0x21, 0xB2, 0xFF, 0x80, 0xF5,
  36406. 0x44, 0xFE, 0x73, 0x84, 0xFF, 0x62, 0xFE, 0x52,
  36407. 0xC4, 0xCA, 0x77, 0x41, 0x28, 0xC8, 0x95, 0x15,
  36408. 0x2C, 0xC7, 0x5C, 0xA6, 0x3B, 0xA8, 0xF8, 0x1E,
  36409. 0x01, 0x30, 0xC9, 0x3B, 0x59, 0xF9, 0x40, 0xB7,
  36410. 0x18, 0x80, 0x21, 0x24, 0xDB, 0x8D, 0x07, 0xDF,
  36411. 0xDC, 0x24, 0xBF, 0x2F, 0x7B, 0xD9, 0xC4, 0xEF,
  36412. 0x61, 0x74, 0x1A, 0xF2, 0xB6, 0x98, 0x75, 0x66,
  36413. 0x22, 0x4F, 0x11, 0x06, 0x41, 0xDB, 0x77, 0x83,
  36414. 0xFA, 0xF3, 0x1B, 0xEC, 0xB8, 0xF7, 0x89, 0x47,
  36415. 0xBA, 0x12, 0x3F, 0xB0, 0x0E, 0x1B, 0x6D, 0x13,
  36416. 0x36, 0x0B, 0x16, 0xD0, 0x7C, 0x3A, 0xAA, 0x33,
  36417. 0x6D, 0xDA, 0x1B, 0x65, 0xD4, 0xC2, 0xF2, 0x1B,
  36418. 0xD5, 0xCD, 0x4B, 0xE9, 0xED, 0xFA, 0xFA, 0x78,
  36419. 0x45, 0x97, 0x2D, 0x60, 0xCC, 0xE3, 0x40, 0x3E,
  36420. 0xB5, 0xE5, 0xC8, 0x33, 0xF6, 0x4C, 0x51, 0x45,
  36421. 0xDC, 0x08, 0xE7, 0xB3, 0x6F, 0xCF, 0xDE, 0xE8,
  36422. 0x73, 0x0B, 0x94, 0x4F, 0x5A, 0x23, 0xF9, 0xFF,
  36423. 0x3F, 0x0D, 0x1D, 0xCE, 0x80, 0x86, 0x3B, 0x55,
  36424. 0x8D, 0x8A, 0x35, 0xB2, 0xAA, 0x65, 0x27, 0x69,
  36425. 0x1D, 0xA5, 0x0C, 0xE6, 0xFA, 0x39, 0x85, 0x62,
  36426. 0x65, 0xAD, 0xE6, 0x08, 0x38, 0xCE, 0xC9, 0xEA,
  36427. 0x98, 0x73, 0x99, 0x1D, 0xB5, 0x6F, 0xEA, 0xE8,
  36428. 0xEE, 0xE2, 0xEC, 0xF4, 0x32, 0x44, 0x96, 0x5A,
  36429. 0x13, 0xCC, 0x1D, 0x23, 0x0E, 0x91, 0x72, 0xD8,
  36430. 0x2A, 0xD2, 0x3D, 0x6A, 0x6E, 0x2A, 0x37, 0x7A,
  36431. 0x7F, 0x67, 0xF6, 0x40, 0xBF, 0x3A, 0x36, 0x3B,
  36432. 0xC8, 0x1A, 0x78, 0x6D, 0x12, 0xB0, 0x35, 0xA3,
  36433. 0x18, 0x55, 0x33, 0x70, 0x48, 0x48, 0x52, 0x8F,
  36434. 0xB4, 0x59, 0x58, 0xEB, 0xAA, 0xB3, 0x03, 0x67,
  36435. 0x4F, 0xFF, 0xA5, 0x68, 0xE7, 0xAE, 0xAF, 0x46,
  36436. 0x3D, 0x66, 0x6B, 0x60, 0x21, 0x26, 0x31, 0x83,
  36437. 0xBE, 0xE8, 0x1E, 0x72, 0x92, 0x87, 0x79, 0x24,
  36438. 0xCF, 0xDE, 0xEF, 0x6F, 0x81, 0x73, 0xA1, 0x34,
  36439. 0x7B, 0x99, 0x94, 0x43, 0x33, 0xF4, 0x8B, 0x36,
  36440. 0xC8, 0xC5, 0xF8, 0xC1, 0x6D, 0x22, 0x6D, 0xA3,
  36441. 0xC9, 0xDA, 0x5F, 0x4C, 0xE7, 0x7F, 0x00, 0xE4,
  36442. 0x42, 0xD8, 0x5C, 0x73, 0xE5, 0x78, 0x0C, 0x36,
  36443. 0x28, 0xD9, 0x83, 0x8F, 0xCA, 0xFA, 0x5D, 0x1D,
  36444. 0x34, 0x05, 0xF1, 0x93, 0x6C, 0xBC, 0xFD, 0x2C,
  36445. 0x52, 0xD4, 0xE8, 0x8D, 0xA9, 0xC9, 0x0D, 0xFF,
  36446. 0x28, 0x5E, 0x3E, 0x91, 0x12, 0xC0, 0x3C, 0xBA,
  36447. 0x58, 0x64, 0x7E, 0x6B, 0x4E, 0xC0, 0x77, 0xB1,
  36448. 0x67, 0x08, 0x16, 0xF5, 0x7E, 0x29, 0x42, 0x81,
  36449. 0x6A, 0x6F, 0x34, 0x21, 0x32, 0x64, 0x9A, 0xA6,
  36450. 0x44, 0xD1, 0x4F, 0x41, 0xAB, 0xC5, 0x26, 0x4A,
  36451. 0xFA, 0x70, 0xBC, 0xAE, 0x3D, 0x67, 0x9B, 0x86,
  36452. 0xF5, 0x1A, 0xF2, 0x44, 0x70, 0x52, 0xD0, 0x78,
  36453. 0xA0, 0xEA, 0x56, 0x39, 0x0B, 0x37, 0x2A, 0x15,
  36454. 0x13, 0xBC, 0xD2, 0xEA, 0x46, 0x6D, 0xCB, 0x5A,
  36455. 0x4D, 0x86, 0x47, 0x4F, 0xA1, 0xE2, 0x6B, 0xC0,
  36456. 0xA8, 0x3F, 0x58, 0x5C, 0x79, 0xAD, 0x62, 0x17,
  36457. 0xBC, 0x96, 0xAF, 0x77, 0x1F, 0x74, 0xD1, 0x42,
  36458. 0xBF, 0x5E, 0x91, 0xA9, 0x28, 0x44, 0xC5, 0x4E,
  36459. 0x76, 0x6B, 0xF2, 0xD3, 0x69, 0x8C, 0x0E, 0x4F,
  36460. 0x61, 0x76, 0xAD, 0xDC, 0x79, 0xE9, 0x74, 0xA4,
  36461. 0x66, 0xFB, 0x2E, 0x0C, 0xBB, 0x42, 0xC5, 0x3F,
  36462. 0x59, 0xB0, 0xDC, 0xB0, 0x32, 0xCD, 0x37, 0x56,
  36463. 0x1B, 0xD2, 0x46, 0xED, 0x52, 0xC8, 0x12, 0xEA,
  36464. 0xA3, 0x6B, 0xB9, 0xE5, 0xB3, 0x2A, 0xF3, 0x9B,
  36465. 0x0F, 0xC3, 0x77, 0x5F, 0x9A, 0xE1, 0x20, 0xBC,
  36466. 0x59, 0x44, 0x9B, 0x7B, 0x77, 0xB1, 0xBA, 0x1A,
  36467. 0x5B, 0x60, 0x06, 0x6C, 0x85, 0x83, 0x68, 0xDD,
  36468. 0x5A, 0xC8, 0xEE, 0xDC, 0xFE, 0x1F, 0x83, 0xF5,
  36469. 0x2C, 0x53, 0x62, 0xED, 0xE8, 0x93, 0xB7, 0x22,
  36470. 0x3E, 0xCB, 0x70, 0xBA, 0xA6, 0x6D, 0xB2, 0x91,
  36471. 0x47, 0xB8, 0x04, 0x37, 0x20, 0x1F, 0xEF, 0x71,
  36472. 0xB0, 0x5F, 0xF2, 0x51, 0x03, 0x5F, 0x88, 0xCA,
  36473. 0xFF, 0x42, 0xE8, 0x2A, 0x43, 0x02, 0xD3, 0x60,
  36474. 0x98, 0x26, 0x8B, 0x74, 0xF4, 0x18, 0x3D, 0x4D,
  36475. 0x19, 0xF1, 0x3B, 0x87, 0xE9, 0x83, 0x37, 0x15,
  36476. 0x7D, 0xA5, 0xEF, 0xBB, 0xF3, 0x4F, 0x48, 0xCA,
  36477. 0x40, 0x65, 0xD3, 0xE3, 0xBA, 0xCC, 0x83, 0x83,
  36478. 0x3F, 0xEE, 0xBA, 0x57, 0x34, 0x6D, 0x16, 0x9F,
  36479. 0x1B, 0xE6, 0xA0, 0x4C, 0x29, 0xC8, 0x2F, 0xD2,
  36480. 0x25, 0xA3, 0xF7, 0xC6, 0x85, 0x12, 0x4F, 0x53,
  36481. 0x7E, 0xC0, 0xE1, 0x0A, 0xB8, 0x58, 0x34, 0xBA,
  36482. 0x3E, 0x65, 0x4F, 0x19, 0x55, 0x5C, 0xB9, 0x74,
  36483. 0x6B, 0x74, 0xCE, 0x43, 0xA2, 0xC7, 0x8B, 0x21,
  36484. 0x70, 0x8C, 0x3B, 0xEF, 0x87, 0xC1, 0xE8, 0x8F,
  36485. 0x08, 0x10, 0xB4, 0xED, 0xE1, 0x81, 0x14, 0xE9,
  36486. 0x2A, 0x43, 0x13, 0xB4, 0xEA, 0xA0, 0x5F, 0x60,
  36487. 0x93, 0x7E, 0x87, 0x6D, 0xA2, 0x57, 0x63, 0x32,
  36488. 0xAE, 0xC3, 0x8C, 0xCD, 0x42, 0x5E, 0xFD, 0x51,
  36489. 0x1A, 0x39, 0xB9, 0xB4, 0xBD, 0x4C, 0xF3, 0xF2,
  36490. 0xE2, 0x70, 0x9A, 0x05, 0xF9, 0x39, 0xE5, 0xFC,
  36491. 0x59, 0x7D, 0x4E, 0x85, 0x12, 0x02, 0xC9, 0xC2,
  36492. 0xC5, 0x71, 0x3A, 0xD5, 0x73, 0xF7, 0x5A, 0xC5,
  36493. 0x49, 0x0D, 0xEE, 0xCF, 0x9D, 0xB8, 0xDE, 0xE2,
  36494. 0x03, 0x99, 0x70, 0x6B, 0x19, 0x29, 0xA4, 0xE8,
  36495. 0x99, 0x00, 0xC4, 0x9C, 0x24, 0x46, 0x5E, 0x08,
  36496. 0x09, 0x56, 0x6D, 0x9C, 0x2E, 0xF7, 0x8C, 0x52,
  36497. 0xDB, 0xB4, 0x2F, 0x9E, 0x22, 0x7E, 0xFD, 0x1E,
  36498. 0x1A, 0x72, 0xCB, 0x71, 0x0B, 0xD2, 0x19, 0x33,
  36499. 0x0E, 0x69, 0xCC, 0x00, 0x49, 0x36, 0x79, 0x78,
  36500. 0xAB, 0x11, 0x4D, 0x9A, 0xD7, 0xF9, 0x55, 0xCF,
  36501. 0x0B, 0x7B, 0x3D, 0x32, 0x5C, 0xB3, 0x51, 0x65,
  36502. 0x00, 0x0E, 0xD2, 0x9D, 0xBE, 0x0A, 0x19, 0x56,
  36503. 0xF1, 0x45, 0x95, 0x83, 0xC6, 0x97, 0xCD, 0x19,
  36504. 0xE7, 0x8B, 0x51, 0x74, 0xE4, 0xFD, 0x2C, 0xEC,
  36505. 0x10, 0x8A, 0x7C, 0x24, 0x28, 0x0A, 0x78, 0xA3,
  36506. 0xEC, 0x93, 0x97, 0x16, 0x4F, 0x60, 0x03, 0xFD,
  36507. 0x85, 0x31, 0x98, 0x04, 0xE5, 0x65, 0x5A, 0x87,
  36508. 0x9F, 0x66, 0x3D, 0xD4, 0x56, 0x3E, 0xF9, 0x98,
  36509. 0x25, 0x21, 0xFE, 0xC2, 0x07, 0x9E, 0x88, 0x89,
  36510. 0x49, 0x7B, 0xE9, 0x20, 0x1F, 0x6D, 0x7F, 0x24,
  36511. 0x60, 0xA8, 0xB2, 0xDD, 0x96, 0x51, 0x0E, 0x0E,
  36512. 0x4C, 0x83, 0xC3, 0xB1, 0x93, 0xC1, 0x1F, 0xD6,
  36513. 0xB4, 0xB6, 0x84, 0xCE, 0x85, 0x63, 0xA5, 0x38,
  36514. 0x0F, 0x2E, 0x55, 0xF4, 0x74, 0xA6, 0x0B, 0x63,
  36515. 0x17, 0xD0, 0x96, 0x76, 0x15, 0xAD, 0x4F, 0xA9,
  36516. 0xF0, 0x83, 0x25, 0xAD, 0xD7, 0x97, 0xB7, 0x9E,
  36517. 0x6F, 0x5D, 0xC7, 0x2A, 0xD1, 0x97, 0xF5, 0xF6,
  36518. 0x1E, 0xC8, 0x8B, 0xE5, 0xFB, 0xFF, 0x92, 0x72,
  36519. 0x31, 0x9A, 0x49, 0x4B, 0x60, 0x8F, 0x34, 0x7C,
  36520. 0xE1, 0x55, 0x66, 0x7A, 0x59, 0xC3, 0x00, 0x9A,
  36521. 0x14, 0x50, 0xF3, 0x06, 0x19, 0x3C, 0xFE, 0x61,
  36522. 0x1C, 0xF7, 0x05, 0x49, 0x2A, 0x30, 0xFF, 0x56,
  36523. 0xFE, 0x7F, 0x71, 0xD7, 0x32, 0xCC, 0xEF, 0x63,
  36524. 0x64, 0xE1, 0x66, 0xCF, 0xF8, 0x12, 0xED, 0x23,
  36525. 0x11, 0xB5, 0x16, 0xFA, 0x56, 0x90, 0xF2, 0xA2,
  36526. 0x72, 0x7B, 0x18, 0x50, 0xF2, 0x98, 0x5D, 0x48,
  36527. 0x25, 0x5E, 0x8C, 0x47, 0xE7, 0x11, 0x50, 0x2A,
  36528. 0x4B, 0x4A, 0x97, 0x0B, 0xDF, 0x70, 0xDC, 0x34,
  36529. 0x47, 0xF8, 0xE2, 0x88, 0x78, 0x24, 0xB5, 0x8A,
  36530. 0xC7, 0x58, 0xE8, 0x83, 0xF7, 0x3B, 0xAD, 0xFC,
  36531. 0xED, 0x46, 0x40, 0xD5, 0x46, 0x35, 0x1B, 0xF3,
  36532. 0x3E, 0x8F, 0x1E, 0x0B, 0x1B, 0xB9, 0xFB, 0x5A,
  36533. 0xFF, 0x0F, 0x8B, 0xA0, 0x95, 0x4A, 0x8E, 0x65,
  36534. 0x33, 0xD3, 0x7C, 0x03, 0x04, 0x8E, 0xBA, 0x6A,
  36535. 0x55, 0xB3, 0xC5, 0xDA, 0xCB, 0xDC, 0x44, 0xD3,
  36536. 0x98, 0x77, 0xD3, 0x07, 0x8A, 0xE9, 0x5E, 0x44,
  36537. 0x5B, 0xED, 0x12, 0xB1, 0xA5, 0x03, 0xAF, 0xB2,
  36538. 0x20, 0x0C, 0xB1, 0x8B, 0x08, 0xB4, 0x6A, 0x11,
  36539. 0x96, 0xA9, 0xF5, 0x7A, 0xFD, 0x56, 0x48, 0x11,
  36540. 0xC0, 0x30, 0xA4, 0x45, 0xFC, 0xAE, 0x72, 0xE5,
  36541. 0x5E, 0x85, 0xB7, 0x6F, 0xA0, 0x50, 0x13, 0x4B,
  36542. 0x2E, 0xC2, 0x31, 0x13, 0xED, 0x04, 0x04, 0x3D,
  36543. 0xBC, 0xD0, 0xB6, 0xFC, 0xCE, 0xBD, 0xC9, 0x13,
  36544. 0x5C, 0xB2, 0x02, 0xB8, 0x4F, 0xDD, 0x74, 0x51,
  36545. 0x1F, 0x9E, 0x8F, 0x0C, 0xF2, 0x26, 0xE1, 0x4C,
  36546. 0xA5, 0xC4, 0x38, 0xC7, 0x6A, 0xA5, 0xC3, 0xC2,
  36547. 0xE9, 0xF3, 0x22, 0x71, 0x00, 0x91, 0x83, 0xEE,
  36548. 0x92, 0xA9, 0x95, 0x81, 0x9D, 0xB9, 0x0F, 0x66,
  36549. 0x89, 0x9B, 0xB9, 0xB0, 0xC7, 0xED, 0x31, 0xDF,
  36550. 0x41, 0xB6, 0x8E, 0x52, 0xAC, 0x5B, 0xBD, 0xF2,
  36551. 0x33, 0x9F, 0x71, 0x5E, 0x43, 0xFE, 0xED, 0xD9,
  36552. 0x4F, 0x57, 0xF9, 0x23, 0x05, 0x23, 0x03, 0x34,
  36553. 0x17, 0xE4, 0x22, 0x27, 0x97, 0xF7, 0x62, 0x5B,
  36554. 0x52, 0x66, 0x70, 0xEE, 0x6B, 0xD3, 0x46, 0x8C,
  36555. 0xCD, 0x9B, 0xA4, 0xA1, 0xED, 0x26, 0x4A, 0xAC,
  36556. 0xC2, 0x50, 0xA8, 0x2A, 0x48, 0x83, 0x46, 0xB2,
  36557. 0xA5, 0xF9, 0x26, 0xF2, 0xE7, 0x8A, 0x8E, 0xD8,
  36558. 0x40, 0x5F, 0x85, 0x8E, 0xAB, 0xB0, 0x29, 0xF7,
  36559. 0x81, 0x42, 0xA7, 0x4B, 0xD5, 0xA8, 0x2D, 0x3D,
  36560. 0xD7, 0x0A, 0xB1, 0x26, 0xCF, 0xA3, 0xBA, 0xD7,
  36561. 0xF5, 0x1B, 0x9E, 0x95, 0xCB, 0xC8, 0xCE, 0x75,
  36562. 0xE7, 0x7A, 0x4A, 0x1B, 0x63, 0x21, 0xB7, 0x74,
  36563. 0x77, 0x78, 0xCD, 0x03, 0x5B, 0x3B, 0xCD, 0x44,
  36564. 0x8E, 0xF1, 0xBB, 0xB6, 0xFF, 0x75, 0x52, 0x8A,
  36565. 0x7A, 0xE9, 0xAF, 0x62, 0x24, 0xA1, 0x6F, 0x4F,
  36566. 0x45, 0x03, 0x87, 0xA3, 0xED, 0xBC, 0x2E, 0x92,
  36567. 0xC0, 0xB1, 0x9C, 0x22, 0x2E, 0x35, 0xC1, 0xA5,
  36568. 0x7E, 0xC3, 0x36, 0x3B, 0x18, 0x14, 0x78, 0x6E,
  36569. 0x1D, 0x37, 0xD7, 0x92, 0xB3, 0x78, 0x26, 0x13,
  36570. 0x9A, 0xFB, 0x38, 0x1D, 0xE0, 0x4C, 0x07, 0xC4,
  36571. 0x2C, 0xD3, 0xCA, 0x78, 0xE4, 0x70, 0xC2, 0x52,
  36572. 0x7C, 0x63, 0xDB, 0x4B, 0xB4, 0x0A, 0x4B, 0x7D,
  36573. 0x20, 0x67, 0xF0, 0xF4, 0x80, 0x5B, 0x65, 0x8B,
  36574. 0x29, 0x80, 0x92, 0xF0, 0x87, 0x3D, 0x09, 0x5A,
  36575. 0x0E, 0xEA, 0x45, 0x63, 0x92, 0x99, 0xD6, 0x0D,
  36576. 0x2B, 0x58, 0xEE, 0x19, 0x03, 0x4F, 0x94, 0x2D,
  36577. 0xEC, 0xBF, 0x5A, 0xE9, 0xA6, 0x16, 0xAF, 0x72,
  36578. 0x37, 0x5C, 0x12, 0xBB, 0x7D, 0xED, 0xAA, 0x6A,
  36579. 0x7D, 0xDF, 0x9A, 0x48, 0x37, 0x37, 0x3D, 0x7B,
  36580. 0x51, 0x96, 0x0B, 0x30, 0xCE, 0x9C, 0xE7, 0x3B,
  36581. 0x3C, 0x10, 0xDE, 0x32, 0xA7, 0x86, 0x39, 0xA9,
  36582. 0x33, 0x7D, 0x9B, 0xCF, 0x15, 0x27, 0xA4, 0x36,
  36583. 0x88, 0xBD, 0xB6, 0xEB, 0x8B, 0xD0, 0x3D, 0xCA,
  36584. 0xF1, 0x02, 0x70, 0xDF, 0xC0, 0xE2, 0xF0, 0xD2,
  36585. 0x2C, 0x27, 0xE3, 0x22, 0x24, 0x33, 0x27, 0x34,
  36586. 0xCA, 0x26, 0x19, 0x74, 0x02, 0x2F, 0x7E, 0xC1,
  36587. 0x76, 0xCB, 0x12, 0xBE, 0x6F, 0x13, 0x62, 0x1F,
  36588. 0x32, 0x03, 0x65, 0xCF, 0xBB, 0x03, 0xD0, 0x4C,
  36589. 0xF2, 0x9E, 0xFE, 0x93, 0xE9, 0x1B, 0x02, 0x9B,
  36590. 0x7B, 0x26, 0xFF, 0xEE, 0xF0, 0x6F, 0xCE, 0x57,
  36591. 0xD1, 0x2B, 0xE3, 0x90, 0x2E, 0xE2, 0x71, 0x2A,
  36592. 0xBA, 0xCC, 0x3D, 0x27, 0xCE, 0xA3, 0x5A, 0xCA,
  36593. 0x15, 0x09, 0xE4, 0xD0, 0x86, 0x4F, 0xEC, 0x5A,
  36594. 0x5B, 0x41, 0xA0, 0xE0, 0x3E, 0x1D, 0xEC, 0x6F,
  36595. 0x2A, 0x33, 0x72, 0x15, 0xCD, 0xE5, 0x55, 0xD6,
  36596. 0x6F, 0x84, 0xE3, 0xD6, 0x75, 0x5D, 0xDC, 0x1C,
  36597. 0x07, 0x3D, 0x0C, 0xDC, 0xDE, 0xF8, 0x8A, 0x44,
  36598. 0x40, 0xB1, 0x76, 0x84, 0xB8, 0xE0, 0xAF, 0x9D,
  36599. 0xA2, 0xB2, 0x84, 0xAA, 0xBF, 0x61, 0x08, 0x21,
  36600. 0xE5, 0xC2, 0xC9, 0x11, 0x94, 0x2D, 0x0B, 0xD1,
  36601. 0xC6, 0x59, 0xC1, 0xEE, 0xBA, 0x8E, 0x21, 0xAF,
  36602. 0xDE, 0x32, 0x77, 0xD5, 0x07, 0x3B, 0x98, 0x39,
  36603. 0x95, 0x77, 0x03, 0x80, 0x2F, 0xA2, 0x76, 0xC8,
  36604. 0x2C, 0xC6, 0x6A, 0x00, 0xA8, 0x69, 0x77, 0xB8,
  36605. 0x87, 0x7D, 0xC0, 0x51, 0x19, 0x45, 0x14, 0xA6,
  36606. 0x33, 0xB3, 0x4D, 0x36, 0x29, 0x34, 0xE8, 0x50,
  36607. 0xC2, 0x71, 0x7A, 0x0B, 0xE5, 0x92, 0x4E, 0x86,
  36608. 0xAA, 0xDA, 0x33, 0xCF, 0x34, 0x54, 0x63, 0x2C,
  36609. 0x68, 0xA1, 0x0A, 0xEF, 0x8B, 0x5B, 0xAA, 0x10,
  36610. 0x83, 0xE9, 0x13, 0x7D, 0x29, 0x20, 0xA2, 0x5F,
  36611. 0x96, 0x9F, 0x54, 0x0B, 0x95, 0xDF, 0x59, 0x91,
  36612. 0x6C, 0x4C, 0xAC, 0xC4, 0x55, 0x98, 0x8F, 0x46,
  36613. 0x31, 0x77, 0x56, 0xCC, 0x93, 0x7E, 0xF0, 0x17,
  36614. 0x7C, 0x0F, 0xEB, 0x3F, 0x23, 0xBB, 0xD3, 0x56,
  36615. 0x9E, 0x89, 0x67, 0xC4, 0x9B, 0x95, 0xA3, 0xBF,
  36616. 0x6D, 0x9D, 0x6D, 0x7C, 0x72, 0x27, 0x20, 0x6E,
  36617. 0x28, 0x37, 0x39, 0xFC, 0x77, 0x41, 0xE9, 0xFE,
  36618. 0x64, 0xEF, 0xA0, 0x38, 0x9F, 0xC7, 0x2F, 0xDA,
  36619. 0xC8, 0x1F, 0xEB, 0x75, 0x07, 0xB8, 0x7E, 0x6B,
  36620. 0x73, 0xCE, 0x0E, 0x7C, 0x7C, 0x54, 0x06, 0x1D,
  36621. 0x48, 0x8A, 0x06, 0x53, 0x95, 0x9B, 0x75, 0x8A,
  36622. 0xFF, 0x6F, 0x7D, 0x19, 0x00, 0x17, 0x8D, 0x7C,
  36623. 0x1A, 0xEA, 0xD0, 0x79, 0x45, 0x68, 0xF9, 0x2F,
  36624. 0x8A, 0xCE, 0x98, 0xED, 0xCC, 0xE8, 0x6D, 0xE1,
  36625. 0x08, 0xA0, 0x50, 0x2C, 0x43, 0x49, 0xC4, 0x99,
  36626. 0x98, 0x31, 0xDE, 0x00, 0xE8, 0x08, 0x39, 0x0B,
  36627. 0xBB, 0xDB, 0x65, 0xEA, 0x36, 0x0F, 0xBE, 0x98,
  36628. 0xB7, 0x4A, 0x9C, 0x59, 0x34, 0x0E, 0xBB, 0xDD,
  36629. 0x6F, 0x65, 0x21, 0x39, 0x23, 0x48, 0x57, 0x7F,
  36630. 0xD4, 0x07, 0x89, 0x03, 0x01, 0xB0, 0x79, 0x27,
  36631. 0x28, 0xCC, 0xFB, 0x88, 0xC5, 0xDD, 0x47, 0x2A,
  36632. 0xDA, 0x73, 0x75, 0x9B, 0xC9, 0x99, 0xA0, 0x21,
  36633. 0x34, 0xDF, 0xB1, 0x62, 0x2F, 0x61, 0xD8, 0xB7,
  36634. 0x63, 0x2A, 0xC7, 0x7E, 0x3A, 0x98, 0x0B, 0x2C,
  36635. 0xE5, 0x66, 0xF3, 0xD5, 0x30, 0xF0, 0xBC, 0x21,
  36636. 0xC7, 0x51, 0x9B, 0xFB, 0x00, 0xBB, 0xAA, 0x9C,
  36637. 0x85, 0xC3, 0x9B, 0x0C, 0xDC, 0x5F, 0x8D, 0x1B,
  36638. 0xA1, 0x2B, 0x78, 0x82, 0xFE, 0x0F, 0x7C, 0x75,
  36639. 0x6E, 0x75, 0x56, 0x74, 0x35, 0x25, 0xE5, 0xD0,
  36640. 0xEC, 0x8E, 0xC1, 0xBD, 0x7D, 0x7A, 0xE3, 0xDC,
  36641. 0xAD, 0xC6, 0x8D, 0xB6, 0x0D, 0x7A, 0xA1, 0x3C,
  36642. 0xDB, 0x29, 0xFA, 0x15, 0xC0, 0xA9, 0xAF, 0x89,
  36643. 0x0F, 0x18, 0x75, 0xE3, 0x97, 0x58, 0x62, 0x12,
  36644. 0x79, 0xA9, 0x87, 0x7D, 0x9C, 0x69, 0x44, 0x9C,
  36645. 0x41, 0x39, 0x2C, 0xAD, 0x98, 0x8B, 0x8D, 0xE4,
  36646. 0x58, 0xEE, 0xCD, 0x98, 0x38, 0x5F, 0x79, 0x73,
  36647. 0x0B, 0x5E, 0x26, 0xC1, 0x16, 0x24, 0x15, 0xD9,
  36648. 0x73, 0x26, 0x41, 0x9B, 0x5F, 0xF9, 0x2A, 0xA8,
  36649. 0xC1, 0x33, 0x74, 0x39, 0x1D, 0xBB, 0xE7, 0x36,
  36650. 0xD9, 0x8C, 0x07, 0xAD, 0x32, 0xD6, 0x38, 0xBB,
  36651. 0x44, 0xE6, 0x77, 0xC7, 0x11, 0x05, 0xCF, 0xB5,
  36652. 0x72, 0x49, 0x68, 0x80, 0xC1, 0x67, 0x71, 0x5F,
  36653. 0x9B, 0xFF, 0x6E, 0x71, 0x1A, 0xBE, 0x5A, 0x83,
  36654. 0x25, 0x38, 0xC7, 0xE6, 0xDA, 0x88, 0x22, 0xDC,
  36655. 0xA6, 0x03, 0x02, 0xD1, 0x59, 0xC6, 0xA8, 0x2F,
  36656. 0xA4, 0x8F, 0xF8, 0x77, 0x3E, 0x0C, 0x6F, 0xA1,
  36657. 0x73, 0xE1, 0x35, 0x55, 0xB2, 0xDF, 0xBF, 0x47,
  36658. 0xB7, 0xD0, 0x8D, 0xBA, 0x35, 0x74, 0x44, 0x6B,
  36659. 0xC0, 0xA7, 0x8D, 0x30, 0x08, 0xE4, 0x41, 0xD1,
  36660. 0x55, 0x21, 0x50, 0xD9, 0x06, 0x12, 0x54, 0xB2,
  36661. 0xF3, 0xFC, 0x5A, 0x1E, 0xF3, 0xE3, 0x84, 0x33,
  36662. 0x34, 0x0B, 0xB5, 0x9A, 0x97, 0xFD, 0x51, 0xF4,
  36663. 0x68, 0xFE, 0x8A, 0x92, 0xBF, 0x62, 0x9D, 0xCD,
  36664. 0x00, 0x29, 0x39, 0x37, 0x12, 0xF3, 0x53, 0x6D,
  36665. 0x6B, 0x24, 0xB8, 0x86, 0x68, 0xAD, 0x6A, 0x4B,
  36666. 0x3A, 0x4C, 0x93, 0xA6, 0xB1, 0x41, 0xFA, 0x8E,
  36667. 0x58, 0x63, 0xCD, 0x59, 0x80, 0xBF, 0xD7, 0xAB,
  36668. 0x83, 0xC3, 0xCC, 0x5D, 0x2F, 0xBE, 0x80, 0xC7,
  36669. 0xB1, 0x67, 0xDC, 0x92, 0x8C, 0xA9, 0x57, 0x36,
  36670. 0x58, 0x0A, 0x52, 0x96, 0x0E, 0x20, 0x90, 0xCD,
  36671. 0x87, 0x68, 0xF5, 0x93, 0xBB, 0x04, 0xD4, 0x48,
  36672. 0xB6, 0x45, 0x30, 0xC0, 0xE3, 0xC2, 0x56, 0x8C,
  36673. 0xE3, 0xA2, 0xC6, 0x42, 0x0F, 0x81, 0xF7, 0x4D,
  36674. 0xF6, 0x88, 0x5D, 0x55, 0x07, 0x8E, 0xF1, 0xB3,
  36675. 0x83, 0xB0, 0x20, 0x85, 0x4A, 0x63, 0x6A, 0x78,
  36676. 0xA9, 0xEC, 0x13, 0x84, 0xF7, 0x4E, 0xBE, 0xB6,
  36677. 0x5F, 0x5A, 0x25, 0xFF, 0xD4, 0x14, 0x7D, 0xA7,
  36678. 0xEE, 0x40, 0xF6, 0x25, 0x7C, 0x7E, 0x34, 0xCA,
  36679. 0xC9, 0x27, 0x0E, 0xA2, 0x78, 0xB6, 0xE6, 0x08,
  36680. 0xA1, 0x9B, 0x56, 0x8D, 0x29, 0xE5, 0x8D, 0xEC,
  36681. 0xAD, 0xDA, 0xD3, 0x3C, 0x59, 0xBA, 0xDB, 0x92,
  36682. 0x52, 0x99, 0x3B, 0x31, 0x6B, 0x0B, 0x13, 0x00,
  36683. 0x79, 0x3D, 0x69, 0x85, 0x3A, 0x6B, 0x90, 0x33,
  36684. 0x96
  36685. };
  36686. static const byte rnd_44[] = {
  36687. 0x08, 0x34, 0x57, 0xD4, 0x0E, 0x25, 0x04, 0x88,
  36688. 0xA6, 0x0E, 0x76, 0x34, 0xA0, 0x1D, 0x43, 0x0A,
  36689. 0x60, 0xE8, 0x57, 0x2B, 0xA8, 0x8A, 0xED, 0xC5,
  36690. 0x54, 0x49, 0x18, 0x81, 0x37, 0x13, 0xA0, 0xB1
  36691. };
  36692. static const byte sig_44[] = {
  36693. 0x63, 0xA8, 0x23, 0x20, 0xD4, 0xCE, 0x09, 0xC4,
  36694. 0x7A, 0xD1, 0x27, 0xC5, 0xBB, 0x7F, 0x6C, 0x2D,
  36695. 0xFF, 0x15, 0x29, 0xCD, 0xAF, 0x9F, 0x74, 0x56,
  36696. 0xFF, 0xC2, 0xC6, 0xED, 0x90, 0x51, 0x17, 0xDC,
  36697. 0xAD, 0x8C, 0x08, 0x7A, 0xC0, 0xD8, 0x9E, 0x0C,
  36698. 0xE9, 0x61, 0xC0, 0x94, 0xFA, 0x9C, 0x2E, 0xDE,
  36699. 0x27, 0x9C, 0x65, 0xE6, 0x99, 0xD1, 0xD1, 0x7E,
  36700. 0xA6, 0x95, 0x98, 0x8F, 0xA1, 0xC4, 0x98, 0x3F,
  36701. 0x7E, 0x1F, 0x18, 0x86, 0x2A, 0xFE, 0xB2, 0xEC,
  36702. 0x9D, 0x0F, 0x5B, 0x0C, 0x11, 0xB2, 0xAA, 0x0B,
  36703. 0xDE, 0x95, 0x7C, 0x40, 0xA1, 0x5B, 0xFF, 0x97,
  36704. 0xD7, 0xCB, 0xCF, 0x4E, 0x59, 0xDA, 0xE9, 0xD5,
  36705. 0xA3, 0xC9, 0xF8, 0x7D, 0xDD, 0xA5, 0xB9, 0x06,
  36706. 0x9D, 0x82, 0xCC, 0x18, 0x10, 0x20, 0x80, 0x92,
  36707. 0xBC, 0xBA, 0x1C, 0x43, 0x73, 0xF2, 0xA8, 0x3E,
  36708. 0x19, 0x15, 0x80, 0x9E, 0x81, 0xD8, 0xD2, 0x06,
  36709. 0xEA, 0x78, 0x10, 0x3F, 0x68, 0x66, 0x3D, 0xBE,
  36710. 0xB1, 0x79, 0xB0, 0x28, 0x83, 0xCD, 0xD3, 0x33,
  36711. 0xEE, 0xFE, 0x6D, 0x02, 0x39, 0x17, 0xC6, 0xF2,
  36712. 0xA4, 0x6E, 0x5A, 0x5C, 0x45, 0x14, 0xF5, 0x7D,
  36713. 0xCA, 0x7B, 0x62, 0x4A, 0xF4, 0xE7, 0x71, 0x7B,
  36714. 0xD7, 0x1B, 0x51, 0x26, 0xE6, 0xDE, 0x2D, 0xC9,
  36715. 0x65, 0x24, 0x30, 0x2C, 0x08, 0x04, 0xD7, 0xBE,
  36716. 0x3A, 0xDA, 0x64, 0xAF, 0x11, 0x6F, 0xC6, 0xE7,
  36717. 0x38, 0xEF, 0xA6, 0xE6, 0x5E, 0x87, 0x90, 0xB4,
  36718. 0x0E, 0xB1, 0xB4, 0x83, 0x64, 0xD2, 0x15, 0xEF,
  36719. 0xD6, 0x1F, 0x7A, 0x44, 0x75, 0x3A, 0x95, 0x50,
  36720. 0x6E, 0x52, 0xC9, 0x9C, 0xE9, 0xB4, 0x56, 0xDC,
  36721. 0x93, 0x85, 0x92, 0xF1, 0x35, 0xEC, 0x50, 0x1B,
  36722. 0x3B, 0xCF, 0x82, 0xDA, 0x69, 0xA1, 0xDD, 0x44,
  36723. 0xE8, 0xB3, 0xC1, 0xCB, 0x8D, 0xD5, 0x13, 0xD0,
  36724. 0xF3, 0x14, 0x2C, 0x80, 0x82, 0x2C, 0x31, 0xBF,
  36725. 0x75, 0x20, 0x14, 0x39, 0x9F, 0x81, 0x79, 0x76,
  36726. 0x0F, 0xB6, 0x7D, 0xB6, 0x58, 0x1C, 0xF3, 0xE6,
  36727. 0x93, 0x5A, 0x9B, 0xE1, 0x8B, 0x92, 0xC2, 0xDB,
  36728. 0xF1, 0x89, 0xAA, 0x46, 0x67, 0xFA, 0x80, 0x45,
  36729. 0x72, 0xAA, 0xB4, 0xE2, 0x5E, 0xE9, 0xD1, 0xA7,
  36730. 0xA0, 0xD7, 0x05, 0x5C, 0xC6, 0xC7, 0x6D, 0x1D,
  36731. 0x66, 0x3D, 0x35, 0x0C, 0xB7, 0x1A, 0xFA, 0xB1,
  36732. 0xDB, 0xD0, 0xCB, 0x3A, 0x8B, 0xB7, 0x1B, 0x03,
  36733. 0x60, 0xA0, 0xA4, 0xDA, 0xD0, 0xE2, 0x3A, 0x1E,
  36734. 0xB5, 0xE4, 0x59, 0x68, 0x6A, 0x02, 0x94, 0x66,
  36735. 0x05, 0x60, 0x08, 0x64, 0xB4, 0xEE, 0x0F, 0x3A,
  36736. 0xCE, 0xFD, 0x40, 0x7B, 0x6F, 0xF5, 0x8D, 0x1E,
  36737. 0xFF, 0x0C, 0x75, 0xAF, 0xC1, 0x41, 0xC6, 0x24,
  36738. 0x1D, 0xF3, 0x76, 0x02, 0x48, 0x6B, 0xBA, 0x58,
  36739. 0xBC, 0xBB, 0xFE, 0xD3, 0x51, 0xC2, 0x68, 0x21,
  36740. 0x4B, 0x20, 0x4E, 0xAF, 0x8A, 0x0C, 0x74, 0x7F,
  36741. 0x5F, 0xB7, 0xAA, 0x43, 0xFC, 0x5A, 0x77, 0xA1,
  36742. 0x81, 0xCD, 0xBA, 0xE1, 0x31, 0x87, 0x1F, 0xA8,
  36743. 0x1F, 0x76, 0x30, 0x6C, 0xE0, 0x84, 0xCD, 0x14,
  36744. 0x4A, 0xDB, 0x67, 0xFD, 0x65, 0x8C, 0x35, 0xC0,
  36745. 0x91, 0x6C, 0x2B, 0xCF, 0x5B, 0x89, 0x29, 0x58,
  36746. 0x42, 0x9B, 0x65, 0xDB, 0x34, 0x7D, 0xD8, 0x31,
  36747. 0xC9, 0xB8, 0x0D, 0x07, 0xD1, 0x94, 0x60, 0x63,
  36748. 0x65, 0xDC, 0xB3, 0x70, 0x48, 0x46, 0x37, 0x18,
  36749. 0x4D, 0x5D, 0xE0, 0xAC, 0x77, 0xD0, 0x9E, 0xE1,
  36750. 0xD9, 0xB2, 0x2D, 0x09, 0xD6, 0xF8, 0x94, 0x96,
  36751. 0x7B, 0x43, 0xD9, 0x76, 0x36, 0xE6, 0x24, 0xA4,
  36752. 0x4A, 0xFF, 0x12, 0xFE, 0x30, 0x95, 0xD7, 0xCB,
  36753. 0xA9, 0xA0, 0x3A, 0xCA, 0xFC, 0x52, 0x57, 0xB8,
  36754. 0x20, 0x80, 0xF2, 0xD8, 0xAE, 0x3E, 0x18, 0xFC,
  36755. 0x0D, 0xE0, 0x9D, 0x01, 0x7B, 0x03, 0xAD, 0x6B,
  36756. 0xEE, 0xA4, 0xEC, 0x38, 0x40, 0xAC, 0x85, 0x42,
  36757. 0xF8, 0xCF, 0x93, 0x10, 0x8F, 0x8C, 0xFE, 0xF8,
  36758. 0x22, 0x64, 0xFC, 0xDD, 0x2C, 0xDD, 0x86, 0x97,
  36759. 0x5B, 0x3F, 0x8F, 0xDF, 0x1F, 0x58, 0x22, 0x08,
  36760. 0x26, 0x8A, 0x76, 0xE6, 0xC9, 0xFE, 0xDF, 0x42,
  36761. 0x90, 0x8D, 0x52, 0x78, 0xA2, 0xBF, 0xBD, 0x3F,
  36762. 0xD5, 0xD5, 0xDB, 0xAF, 0xDD, 0x5E, 0x2C, 0x2B,
  36763. 0x9F, 0x2E, 0xDC, 0xC1, 0xC4, 0x52, 0x96, 0x38,
  36764. 0x49, 0xCB, 0x34, 0xEC, 0x51, 0x00, 0x8D, 0x1B,
  36765. 0xF6, 0xDA, 0x50, 0xA0, 0xD1, 0x9D, 0x82, 0x34,
  36766. 0x5B, 0x78, 0x8C, 0x05, 0x40, 0xE1, 0x7B, 0x25,
  36767. 0xFF, 0xDC, 0xE8, 0xD4, 0x45, 0x3B, 0xBE, 0x75,
  36768. 0x1E, 0xDA, 0x96, 0xA4, 0x4C, 0x75, 0xFD, 0xD9,
  36769. 0x00, 0x81, 0x85, 0x7D, 0xC0, 0xF8, 0x26, 0x2A,
  36770. 0x30, 0x7B, 0x34, 0xCB, 0xEC, 0xD1, 0x56, 0x58,
  36771. 0x69, 0xA3, 0x14, 0xD6, 0x4C, 0x09, 0xDC, 0x9D,
  36772. 0x4A, 0x80, 0x26, 0x52, 0x2F, 0xDF, 0xE4, 0xCB,
  36773. 0x5B, 0x8B, 0x11, 0x05, 0xDA, 0xE0, 0xDB, 0x66,
  36774. 0xC8, 0x5B, 0xB4, 0x32, 0x1D, 0xBE, 0x76, 0x84,
  36775. 0xEB, 0x6B, 0x6F, 0x85, 0x87, 0xD8, 0x32, 0x0C,
  36776. 0x6D, 0xB3, 0x8D, 0xED, 0xD6, 0x18, 0x96, 0xED,
  36777. 0x51, 0xAB, 0x0C, 0x7F, 0x42, 0x8F, 0x19, 0xD2,
  36778. 0x55, 0xC6, 0xB0, 0xFD, 0xF5, 0x89, 0x51, 0xE5,
  36779. 0xCD, 0xB1, 0x96, 0x9C, 0xD9, 0xA7, 0x93, 0x4E,
  36780. 0xFD, 0xB9, 0xC8, 0x2E, 0x1E, 0x8D, 0x2A, 0x59,
  36781. 0xC9, 0xF7, 0x9D, 0xF1, 0xAA, 0x93, 0xE5, 0x07,
  36782. 0x1E, 0x3F, 0xAC, 0x73, 0x19, 0xFF, 0x68, 0x87,
  36783. 0x8C, 0xF2, 0x49, 0xDC, 0xBD, 0xCD, 0x10, 0x46,
  36784. 0x16, 0xCC, 0xC1, 0xC1, 0xFB, 0xD7, 0x85, 0x56,
  36785. 0x9F, 0x55, 0x87, 0x10, 0x44, 0x1B, 0x31, 0xCA,
  36786. 0xE3, 0x16, 0x7A, 0x4C, 0xD7, 0xDD, 0xD1, 0x86,
  36787. 0x26, 0xC5, 0x43, 0x62, 0x96, 0x20, 0x32, 0xE6,
  36788. 0xB7, 0xA2, 0x76, 0x05, 0x61, 0x96, 0xFC, 0x22,
  36789. 0x96, 0x7E, 0x90, 0x7C, 0x32, 0x0A, 0x7A, 0xF5,
  36790. 0x8C, 0xE3, 0xF5, 0x01, 0xC4, 0xCD, 0x31, 0x8A,
  36791. 0x70, 0x75, 0x04, 0xF1, 0xC2, 0x59, 0xE5, 0x07,
  36792. 0xA0, 0xD4, 0x7D, 0x25, 0x8E, 0x2F, 0x38, 0xE2,
  36793. 0x6A, 0x53, 0x41, 0x34, 0x7A, 0x06, 0xB5, 0x8B,
  36794. 0xB0, 0xBF, 0x21, 0xDE, 0xE6, 0x5F, 0x55, 0x6A,
  36795. 0xD4, 0x88, 0xA7, 0x36, 0xD4, 0xC6, 0x5C, 0x82,
  36796. 0xC6, 0x73, 0xC0, 0x60, 0xD7, 0xA6, 0xA0, 0x77,
  36797. 0x5C, 0xF8, 0xC3, 0x9A, 0xA1, 0x31, 0xFD, 0x64,
  36798. 0xDB, 0xB1, 0x7B, 0x72, 0x70, 0x4B, 0x7D, 0x1D,
  36799. 0x24, 0xBC, 0x5F, 0x84, 0x08, 0x3B, 0xF8, 0xA6,
  36800. 0x47, 0xEB, 0xED, 0xCF, 0xDD, 0xA0, 0x91, 0x14,
  36801. 0x26, 0x7D, 0x77, 0xCF, 0xBF, 0x39, 0x9B, 0xD9,
  36802. 0x2F, 0x3B, 0x2A, 0xA7, 0x2B, 0xBC, 0xF7, 0xDE,
  36803. 0x9D, 0x69, 0xBF, 0x90, 0xA4, 0xDE, 0x2C, 0xF8,
  36804. 0x24, 0x92, 0x7D, 0xE2, 0xB8, 0xBD, 0xF4, 0x6B,
  36805. 0x10, 0x9E, 0xD6, 0x08, 0x51, 0xC5, 0x9C, 0x44,
  36806. 0x8E, 0xCB, 0x44, 0x3F, 0x00, 0x26, 0x3C, 0x9C,
  36807. 0x25, 0xF4, 0x62, 0x74, 0xD1, 0x7C, 0x29, 0x4C,
  36808. 0xEB, 0xF2, 0x53, 0x7D, 0x8F, 0xEA, 0xBD, 0x78,
  36809. 0xEE, 0xBC, 0xBA, 0x72, 0x64, 0xA5, 0xB9, 0x45,
  36810. 0x08, 0xE0, 0xBF, 0x62, 0xEF, 0xC2, 0x1E, 0x06,
  36811. 0xE1, 0xE2, 0xFB, 0x14, 0x44, 0xC5, 0xAB, 0x6F,
  36812. 0x84, 0x7F, 0x52, 0x2F, 0x8A, 0xBE, 0xED, 0x04,
  36813. 0x6D, 0x6D, 0xDC, 0xFF, 0xBC, 0xB8, 0xC8, 0x1F,
  36814. 0xD0, 0x5D, 0x4D, 0x7F, 0x2E, 0x1B, 0xC9, 0x9B,
  36815. 0xEA, 0xF8, 0xC1, 0xAF, 0xE3, 0xE0, 0x5B, 0x36,
  36816. 0x90, 0xFE, 0xE4, 0xAA, 0x37, 0x5A, 0x3D, 0xCB,
  36817. 0x77, 0x57, 0x7C, 0xCC, 0x6E, 0x3E, 0xBE, 0x8A,
  36818. 0x98, 0x7C, 0x6D, 0x7E, 0x89, 0x60, 0x73, 0xC0,
  36819. 0xCC, 0x0C, 0x48, 0x25, 0x46, 0xB5, 0x39, 0xB4,
  36820. 0xFD, 0xF0, 0x4E, 0xED, 0x8E, 0x87, 0xF8, 0x5B,
  36821. 0x00, 0xBE, 0x43, 0xA6, 0x0B, 0x21, 0x7E, 0x96,
  36822. 0x88, 0x3B, 0x91, 0xD7, 0x88, 0x1A, 0xA0, 0xDD,
  36823. 0x3E, 0xBF, 0x5B, 0x0D, 0x08, 0xD0, 0x85, 0x4E,
  36824. 0xD4, 0x27, 0x8F, 0xC9, 0x02, 0xE0, 0x60, 0xEA,
  36825. 0x16, 0xFB, 0xC2, 0x54, 0xA5, 0x08, 0xC8, 0x6F,
  36826. 0x7A, 0xE7, 0x54, 0x93, 0xB8, 0xDD, 0xA0, 0x86,
  36827. 0xE9, 0xC1, 0xB2, 0x17, 0xF5, 0xC9, 0x11, 0x97,
  36828. 0x83, 0x66, 0x88, 0xCD, 0x2D, 0x0B, 0xB8, 0xE5,
  36829. 0x52, 0xD1, 0x13, 0x7A, 0xA7, 0xEB, 0xD5, 0xD5,
  36830. 0x60, 0x53, 0x8E, 0x9B, 0xB6, 0xB4, 0x1D, 0x06,
  36831. 0x90, 0xB0, 0x6C, 0x66, 0xD1, 0x57, 0x5B, 0x86,
  36832. 0x1C, 0x8A, 0x7D, 0x3A, 0x88, 0x4C, 0xC9, 0x88,
  36833. 0x1A, 0xC3, 0x00, 0x1F, 0x30, 0x0D, 0xF3, 0x47,
  36834. 0x62, 0x79, 0x85, 0x89, 0xF9, 0xEE, 0x5C, 0x92,
  36835. 0x43, 0x61, 0x53, 0xD8, 0xC7, 0x32, 0x55, 0x9B,
  36836. 0x33, 0x3D, 0x69, 0x8F, 0x3E, 0xC5, 0x82, 0x0E,
  36837. 0x8A, 0xA5, 0xF2, 0xE5, 0xA7, 0x69, 0xC2, 0xB4,
  36838. 0x7A, 0xFA, 0x27, 0x5F, 0xE4, 0x74, 0xAF, 0x81,
  36839. 0x37, 0xC7, 0x01, 0x9A, 0xF2, 0xE6, 0x0C, 0xA7,
  36840. 0x5E, 0xDB, 0xE4, 0x8F, 0x81, 0xA6, 0x51, 0xCE,
  36841. 0x6B, 0xAB, 0xD3, 0x37, 0x4C, 0x07, 0x72, 0xA8,
  36842. 0xAC, 0x36, 0x77, 0xB1, 0x0F, 0x54, 0x77, 0x17,
  36843. 0xC9, 0x67, 0x50, 0xDA, 0x44, 0x8B, 0xD9, 0xC7,
  36844. 0x93, 0x8C, 0x66, 0xCD, 0x6F, 0xB7, 0x5D, 0x73,
  36845. 0x2D, 0xAC, 0x83, 0x1A, 0xDC, 0xE9, 0x17, 0x6D,
  36846. 0x94, 0x85, 0x6E, 0x1B, 0xF6, 0x08, 0x38, 0xD0,
  36847. 0x9E, 0x63, 0x23, 0xA2, 0x7B, 0x16, 0x09, 0xF9,
  36848. 0xC1, 0x21, 0xF4, 0x98, 0xD2, 0xBB, 0x68, 0x58,
  36849. 0x18, 0xA0, 0x0D, 0xE7, 0xBA, 0x6B, 0x28, 0x47,
  36850. 0xC5, 0x16, 0x14, 0x9F, 0x35, 0x6E, 0xCE, 0xF0,
  36851. 0x4F, 0x34, 0xEA, 0x48, 0x35, 0x46, 0xFE, 0xEB,
  36852. 0x12, 0xEA, 0x40, 0x77, 0x62, 0x04, 0x30, 0xC3,
  36853. 0x9D, 0xBF, 0x47, 0xC0, 0x5E, 0xED, 0x5E, 0xD5,
  36854. 0x87, 0xFF, 0xF5, 0x92, 0x21, 0x7C, 0xA9, 0x5A,
  36855. 0x2C, 0x3D, 0x1E, 0x6F, 0x6F, 0xF9, 0xFF, 0x20,
  36856. 0x9F, 0x8B, 0x30, 0xA9, 0x9D, 0x56, 0xA3, 0x97,
  36857. 0x7A, 0x33, 0x17, 0x49, 0x0B, 0x2B, 0x00, 0x1F,
  36858. 0x43, 0xCD, 0x8D, 0xDD, 0x1D, 0x8F, 0xC1, 0x6A,
  36859. 0x3F, 0xA9, 0xB4, 0x31, 0x54, 0x62, 0x84, 0x5B,
  36860. 0x99, 0x5D, 0x2A, 0xB7, 0x6E, 0xA5, 0x39, 0xC7,
  36861. 0xF0, 0x4C, 0x31, 0x6C, 0x71, 0xD6, 0x00, 0xE1,
  36862. 0xAC, 0x4F, 0xD5, 0xC8, 0xC6, 0x34, 0x3B, 0xC8,
  36863. 0x05, 0x5F, 0x17, 0x00, 0xB4, 0x0E, 0xA2, 0xF1,
  36864. 0xAB, 0xE9, 0x4B, 0xE0, 0x06, 0x01, 0x3A, 0xA2,
  36865. 0x61, 0xF0, 0x72, 0x0A, 0xB7, 0x99, 0xD0, 0xFC,
  36866. 0x6D, 0xB5, 0xE9, 0xA4, 0xC3, 0xC5, 0xA7, 0xF8,
  36867. 0x2D, 0x70, 0xD2, 0x8E, 0x41, 0x0D, 0xD1, 0x64,
  36868. 0xE3, 0xE4, 0x61, 0xA4, 0x6E, 0x81, 0xFB, 0xDC,
  36869. 0xB8, 0x10, 0x84, 0x8B, 0xCE, 0xE0, 0x6F, 0x88,
  36870. 0x33, 0x25, 0x64, 0x6E, 0x1E, 0x2A, 0x69, 0x3F,
  36871. 0xA5, 0xDA, 0x7C, 0x25, 0xEB, 0x21, 0xC4, 0xEA,
  36872. 0xB8, 0x7D, 0xC7, 0x87, 0xA2, 0x67, 0x7C, 0xEB,
  36873. 0x6A, 0x26, 0xE1, 0x06, 0xFE, 0x78, 0xE1, 0x18,
  36874. 0xFF, 0x54, 0x71, 0x3E, 0x00, 0x59, 0x7B, 0xFA,
  36875. 0x52, 0x8C, 0x2A, 0xED, 0x06, 0x9A, 0x12, 0x6D,
  36876. 0xE3, 0x74, 0x6F, 0x06, 0x65, 0xE1, 0x75, 0x80,
  36877. 0x63, 0x0F, 0x70, 0x2F, 0xAB, 0xC0, 0xF1, 0xCD,
  36878. 0x7F, 0x57, 0xAA, 0x71, 0xF6, 0x38, 0xD8, 0xAF,
  36879. 0x37, 0xD3, 0xD9, 0xE0, 0xA7, 0xE9, 0x05, 0x5D,
  36880. 0xA3, 0xDF, 0x86, 0x48, 0x3F, 0x25, 0xDE, 0xBA,
  36881. 0x18, 0xCE, 0xF6, 0x99, 0xEB, 0x87, 0x70, 0xC7,
  36882. 0x85, 0x84, 0x79, 0x8A, 0xD8, 0x02, 0x8B, 0xAD,
  36883. 0xC5, 0x9D, 0x2A, 0xF9, 0xAE, 0xAE, 0x37, 0xEC,
  36884. 0x93, 0x91, 0x16, 0x10, 0x5F, 0x9F, 0x64, 0xEF,
  36885. 0x82, 0x78, 0xC6, 0x4D, 0xED, 0x3F, 0xD4, 0x33,
  36886. 0xA7, 0xB8, 0x82, 0x09, 0x16, 0xBE, 0xDC, 0x6B,
  36887. 0x7A, 0x75, 0x69, 0x8A, 0xDE, 0xD3, 0xFD, 0xE8,
  36888. 0x86, 0x75, 0x42, 0x83, 0x03, 0x57, 0x30, 0x70,
  36889. 0xA5, 0xA3, 0x85, 0x1F, 0x9F, 0x21, 0xEA, 0xC7,
  36890. 0x80, 0xFA, 0x8A, 0xA4, 0x02, 0x3E, 0x39, 0x11,
  36891. 0x48, 0x7D, 0x85, 0x2A, 0x53, 0x77, 0x43, 0x5A,
  36892. 0x5F, 0xFF, 0x9C, 0x60, 0x4B, 0x5D, 0x95, 0xB0,
  36893. 0x96, 0x8A, 0xE0, 0xEC, 0xF4, 0x43, 0x1B, 0x10,
  36894. 0x3F, 0xA6, 0xBA, 0x71, 0xC4, 0xDC, 0x81, 0x73,
  36895. 0xA2, 0xDE, 0x1F, 0x79, 0xDD, 0xB6, 0x0D, 0x2D,
  36896. 0x0C, 0x8E, 0x56, 0x55, 0xD0, 0x94, 0x44, 0x29,
  36897. 0x16, 0x92, 0x99, 0x2D, 0x99, 0xFC, 0x48, 0xF2,
  36898. 0x16, 0x0E, 0xC0, 0xAC, 0xE4, 0xC4, 0x92, 0x07,
  36899. 0xBB, 0xB7, 0x6D, 0x7F, 0x2A, 0x85, 0xE1, 0x81,
  36900. 0x02, 0xB9, 0x5A, 0x51, 0x45, 0x88, 0xF5, 0x9F,
  36901. 0x16, 0x2D, 0x33, 0xCE, 0xD6, 0x18, 0x07, 0x03,
  36902. 0xED, 0xC3, 0x6C, 0x8B, 0x33, 0x94, 0x88, 0x81,
  36903. 0x0D, 0x2E, 0xAE, 0x96, 0x25, 0xCE, 0xE3, 0x83,
  36904. 0x27, 0x1C, 0x71, 0x72, 0xEE, 0xD6, 0xB5, 0x48,
  36905. 0x69, 0x60, 0xE8, 0x99, 0x18, 0x74, 0xB0, 0x13,
  36906. 0x53, 0x59, 0x3D, 0x70, 0x70, 0xBD, 0xEB, 0x7A,
  36907. 0x9F, 0x92, 0x29, 0xAB, 0x77, 0x0E, 0xEB, 0x46,
  36908. 0x37, 0x8D, 0x57, 0xD9, 0x56, 0xDF, 0x7A, 0x86,
  36909. 0x40, 0x04, 0x02, 0x98, 0xF7, 0x00, 0xF4, 0x41,
  36910. 0x5B, 0xDD, 0x3A, 0x96, 0x15, 0xA4, 0x65, 0xDB,
  36911. 0x01, 0x28, 0x22, 0x12, 0xCF, 0x1A, 0xEC, 0x4B,
  36912. 0x0B, 0x8C, 0xB3, 0xB1, 0x7E, 0x5E, 0xFA, 0x28,
  36913. 0x6C, 0x6C, 0x04, 0x5B, 0x43, 0x9C, 0x74, 0x9F,
  36914. 0xE1, 0xD4, 0x50, 0x75, 0xD8, 0xE7, 0xA0, 0x0F,
  36915. 0xBE, 0x84, 0x48, 0xFC, 0xAC, 0xAA, 0x15, 0x3D,
  36916. 0x69, 0x70, 0x9D, 0x9F, 0xF2, 0xB9, 0x7C, 0xDB,
  36917. 0x26, 0xC0, 0xC3, 0x79, 0x28, 0x7C, 0xE6, 0x48,
  36918. 0x61, 0xAD, 0xD7, 0x89, 0xD0, 0xC8, 0x93, 0x9A,
  36919. 0x14, 0x21, 0xB0, 0x85, 0xD6, 0x23, 0x4C, 0xE1,
  36920. 0xA7, 0x49, 0xDE, 0x3D, 0xCB, 0xE8, 0xE0, 0x61,
  36921. 0x5C, 0xB3, 0xBC, 0xDC, 0x6A, 0x81, 0xA5, 0xC4,
  36922. 0x9D, 0x92, 0x85, 0x74, 0x5F, 0x1C, 0xA8, 0xA0,
  36923. 0x64, 0x1E, 0x32, 0x68, 0x83, 0x41, 0x93, 0x34,
  36924. 0x82, 0x18, 0x3E, 0x24, 0x5C, 0x1F, 0x9C, 0xD2,
  36925. 0x80, 0x28, 0xC3, 0x8A, 0x23, 0x18, 0x1A, 0x44,
  36926. 0x5A, 0xA6, 0xEA, 0xCC, 0xE2, 0x06, 0x06, 0xE6,
  36927. 0xF7, 0xF1, 0xDF, 0x70, 0x68, 0x83, 0xCD, 0xA5,
  36928. 0x2F, 0x3F, 0x2B, 0x68, 0xDE, 0x26, 0xDD, 0x37,
  36929. 0x71, 0xE9, 0x50, 0x03, 0x2C, 0xC7, 0x20, 0x0C,
  36930. 0x20, 0x23, 0xC8, 0x24, 0x96, 0x50, 0x82, 0x82,
  36931. 0xCD, 0x3B, 0xC4, 0x7F, 0xEC, 0xE5, 0xD9, 0x7C,
  36932. 0xA1, 0xCE, 0x35, 0x74, 0x4D, 0x03, 0xD7, 0xA4,
  36933. 0x28, 0xB7, 0xAF, 0x12, 0xB0, 0xCB, 0x8E, 0x65,
  36934. 0x7C, 0x01, 0x30, 0xF8, 0xA3, 0xA2, 0x54, 0x97,
  36935. 0x6E, 0xC8, 0xF7, 0xDC, 0xCF, 0x3A, 0xBF, 0x31,
  36936. 0xF4, 0xB0, 0xB3, 0xF7, 0x12, 0x6F, 0xFC, 0x48,
  36937. 0x77, 0xF3, 0xD1, 0xA0, 0x66, 0xD2, 0x6A, 0x23,
  36938. 0x2F, 0xA9, 0x99, 0x21, 0x61, 0x22, 0x54, 0x11,
  36939. 0xED, 0x7D, 0xDB, 0x93, 0xC3, 0x5C, 0x6A, 0x37,
  36940. 0x7F, 0x30, 0xCF, 0x22, 0xAA, 0x39, 0x2D, 0x5C,
  36941. 0x4F, 0xEE, 0x4F, 0x73, 0xC9, 0xEF, 0x6E, 0xD3,
  36942. 0xA0, 0x27, 0x97, 0x14, 0x52, 0x3B, 0x19, 0x18,
  36943. 0x65, 0x1E, 0x9B, 0x0F, 0xFA, 0x55, 0x0F, 0x16,
  36944. 0x10, 0x53, 0xEE, 0x78, 0x01, 0x39, 0x7B, 0x4C,
  36945. 0x18, 0x49, 0x98, 0x7C, 0x17, 0x9E, 0x76, 0x3E,
  36946. 0xCC, 0x60, 0xA4, 0xE4, 0xC5, 0x36, 0xB7, 0xE2,
  36947. 0x66, 0x3E, 0x4C, 0x72, 0x67, 0x14, 0xB0, 0x2E,
  36948. 0xC3, 0x16, 0x9E, 0x84, 0x07, 0xBA, 0x59, 0x2B,
  36949. 0x0E, 0xB8, 0x46, 0xF3, 0x69, 0x2D, 0xD4, 0x46,
  36950. 0x51, 0xEE, 0x08, 0x47, 0x21, 0xCA, 0xC0, 0xFE,
  36951. 0x1C, 0xCC, 0x30, 0x27, 0x07, 0xEF, 0xE2, 0x46,
  36952. 0x64, 0xE0, 0x5B, 0xDC, 0x69, 0xC8, 0x39, 0x04,
  36953. 0xAC, 0xB8, 0xCF, 0x97, 0x12, 0x1C, 0x7E, 0x5C,
  36954. 0x6D, 0xB2, 0x7E, 0xA2, 0x8E, 0x77, 0xBC, 0xDA,
  36955. 0x55, 0xD2, 0xBC, 0xC1, 0xC5, 0xFC, 0xC5, 0x52,
  36956. 0xAB, 0x83, 0xBC, 0xE4, 0x23, 0x8C, 0xA1, 0x80,
  36957. 0x62, 0xC2, 0xD2, 0x3A, 0x8B, 0x80, 0x0C, 0x82,
  36958. 0x09, 0xC3, 0xA4, 0xCD, 0xDA, 0xF1, 0x16, 0x16,
  36959. 0x57, 0x8A, 0x84, 0x55, 0x66, 0xFC, 0x28, 0x9A,
  36960. 0x8E, 0x3C, 0x88, 0xF5, 0x54, 0xC4, 0x92, 0x60,
  36961. 0x71, 0xDA, 0x89, 0x32, 0x6B, 0xEB, 0x25, 0x9A,
  36962. 0x0E, 0x1F, 0x6D, 0x84, 0x4E, 0xBF, 0x7B, 0x28,
  36963. 0x1F, 0x9F, 0xC3, 0x74, 0x3A, 0x65, 0x49, 0x9E,
  36964. 0x73, 0x94, 0x63, 0x48, 0x18, 0xE1, 0x33, 0xFA,
  36965. 0xC6, 0x64, 0xFA, 0x0C, 0x88, 0xF1, 0x01, 0xCE,
  36966. 0xC3, 0xFE, 0xD8, 0x79, 0x29, 0x50, 0xBF, 0x6E,
  36967. 0x49, 0x74, 0x84, 0x9E, 0x1E, 0xBD, 0x27, 0x69,
  36968. 0x1B, 0xF5, 0x51, 0x9B, 0x70, 0x2E, 0x1A, 0xA4,
  36969. 0xB3, 0xDB, 0xAD, 0xAB, 0x5D, 0xFA, 0x34, 0xFB,
  36970. 0x0E, 0xD9, 0xD4, 0xA9, 0xDF, 0x4B, 0x6B, 0x63,
  36971. 0xCA, 0x71, 0x65, 0xE2, 0xA9, 0x08, 0x27, 0x40,
  36972. 0x8C, 0x48, 0x2D, 0x9D, 0xBC, 0x97, 0x24, 0x68,
  36973. 0x58, 0x4F, 0x42, 0x37, 0x60, 0x04, 0xE7, 0x8B,
  36974. 0xE0, 0x67, 0x00, 0x9E, 0x43, 0x30, 0x4B, 0xED,
  36975. 0xC1, 0x07, 0xA4, 0xE2, 0xA8, 0x9C, 0xAF, 0x18,
  36976. 0x5C, 0x9B, 0xB7, 0xE9, 0xFD, 0x2C, 0xB9, 0x2A,
  36977. 0xEF, 0x36, 0x3B, 0xD7, 0x96, 0xF3, 0x60, 0x4E,
  36978. 0xDC, 0x08, 0xA7, 0xC5, 0x45, 0xB8, 0x37, 0x02,
  36979. 0xD3, 0xCF, 0x80, 0x88, 0x52, 0x10, 0x3E, 0x01,
  36980. 0x3B, 0xFE, 0xA1, 0x61, 0xAF, 0x25, 0x0B, 0xCC,
  36981. 0x72, 0x77, 0x1D, 0x0C, 0x48, 0x4D, 0xD5, 0x55,
  36982. 0x41, 0x72, 0x3A, 0x21, 0x0D, 0x68, 0x3B, 0x99,
  36983. 0x8C, 0xDB, 0xAF, 0x3D, 0x9A, 0x5E, 0x71, 0x78,
  36984. 0x6F, 0x1C, 0xF4, 0x7B, 0x86, 0x22, 0x51, 0xB5,
  36985. 0x16, 0x33, 0x60, 0x87, 0x9A, 0xC0, 0x20, 0x2D,
  36986. 0x33, 0x49, 0x51, 0x54, 0x5C, 0x5F, 0x71, 0x76,
  36987. 0x7C, 0x8F, 0x96, 0xA9, 0xD6, 0xE4, 0xF2, 0x1F,
  36988. 0x28, 0x43, 0x4D, 0x7E, 0x96, 0xBB, 0xC5, 0xE3,
  36989. 0xEF, 0xF3, 0xFD, 0x02, 0x0C, 0x17, 0x23, 0x3E,
  36990. 0x7F, 0x99, 0xB0, 0xE3, 0xE8, 0xF5, 0x00, 0x00,
  36991. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  36992. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  36993. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  36994. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  36995. 0x06, 0x17, 0x23, 0x2E
  36996. };
  36997. #endif
  36998. #ifndef WOLFSSL_NO_ML_DSA_65
  36999. static const byte sk_65[] = {
  37000. 0xF2, 0x6B, 0xFE, 0x12, 0x68, 0x86, 0xF4, 0x82,
  37001. 0x22, 0x94, 0x4D, 0x02, 0x18, 0xFA, 0xC1, 0x7C,
  37002. 0xD8, 0xA9, 0xCC, 0x6D, 0x67, 0xA0, 0x23, 0xFD,
  37003. 0xC0, 0x7A, 0xFF, 0xC2, 0xD0, 0x25, 0xF7, 0x70,
  37004. 0x63, 0x85, 0x0D, 0x88, 0x0E, 0x98, 0xFE, 0xE5,
  37005. 0x02, 0xE0, 0x17, 0x32, 0x70, 0x00, 0xCC, 0xAF,
  37006. 0x61, 0x45, 0x73, 0xB3, 0x5A, 0xDE, 0xFE, 0xBC,
  37007. 0xAC, 0xEE, 0xA4, 0xB2, 0xC4, 0xD0, 0x45, 0xE5,
  37008. 0xBB, 0xFD, 0x3E, 0x5A, 0x72, 0xE3, 0x71, 0xAD,
  37009. 0x83, 0xB9, 0x94, 0x98, 0x77, 0xD8, 0xE6, 0x56,
  37010. 0xD4, 0x6B, 0x47, 0x75, 0x0F, 0x73, 0x0F, 0x96,
  37011. 0xDB, 0x43, 0x0B, 0x18, 0x60, 0x88, 0x67, 0x5D,
  37012. 0x9A, 0x9B, 0xD7, 0x8E, 0x47, 0xB8, 0x9D, 0x04,
  37013. 0xA8, 0x51, 0x7E, 0xD2, 0x22, 0x06, 0x95, 0x33,
  37014. 0x9F, 0x99, 0xA9, 0x7F, 0x35, 0x3C, 0xE4, 0x20,
  37015. 0x47, 0x77, 0x20, 0x9F, 0x5F, 0x3C, 0x9E, 0x9A,
  37016. 0x36, 0x14, 0x54, 0x01, 0x57, 0x48, 0x60, 0x50,
  37017. 0x75, 0x28, 0x64, 0x61, 0x72, 0x60, 0x54, 0x20,
  37018. 0x75, 0x48, 0x60, 0x32, 0x73, 0x85, 0x34, 0x24,
  37019. 0x68, 0x63, 0x71, 0x73, 0x81, 0x26, 0x71, 0x68,
  37020. 0x32, 0x61, 0x24, 0x71, 0x14, 0x18, 0x26, 0x15,
  37021. 0x05, 0x77, 0x36, 0x27, 0x50, 0x35, 0x21, 0x82,
  37022. 0x50, 0x15, 0x31, 0x47, 0x48, 0x24, 0x43, 0x76,
  37023. 0x18, 0x85, 0x66, 0x18, 0x05, 0x64, 0x27, 0x01,
  37024. 0x06, 0x06, 0x01, 0x45, 0x42, 0x60, 0x80, 0x68,
  37025. 0x25, 0x08, 0x08, 0x36, 0x13, 0x05, 0x04, 0x32,
  37026. 0x34, 0x87, 0x00, 0x70, 0x71, 0x70, 0x02, 0x51,
  37027. 0x37, 0x15, 0x08, 0x28, 0x25, 0x72, 0x61, 0x67,
  37028. 0x08, 0x52, 0x63, 0x44, 0x07, 0x88, 0x60, 0x42,
  37029. 0x03, 0x17, 0x24, 0x64, 0x80, 0x08, 0x70, 0x23,
  37030. 0x56, 0x41, 0x46, 0x17, 0x46, 0x01, 0x57, 0x74,
  37031. 0x02, 0x76, 0x31, 0x64, 0x73, 0x83, 0x50, 0x62,
  37032. 0x72, 0x61, 0x62, 0x75, 0x45, 0x73, 0x46, 0x33,
  37033. 0x65, 0x14, 0x36, 0x46, 0x12, 0x26, 0x04, 0x34,
  37034. 0x02, 0x81, 0x20, 0x34, 0x41, 0x88, 0x26, 0x77,
  37035. 0x33, 0x40, 0x18, 0x58, 0x03, 0x41, 0x16, 0x58,
  37036. 0x88, 0x04, 0x88, 0x32, 0x71, 0x05, 0x85, 0x83,
  37037. 0x42, 0x55, 0x34, 0x20, 0x18, 0x46, 0x12, 0x54,
  37038. 0x28, 0x03, 0x67, 0x10, 0x84, 0x31, 0x76, 0x00,
  37039. 0x40, 0x85, 0x46, 0x71, 0x71, 0x56, 0x00, 0x50,
  37040. 0x15, 0x33, 0x43, 0x13, 0x37, 0x57, 0x13, 0x86,
  37041. 0x43, 0x77, 0x85, 0x57, 0x54, 0x81, 0x75, 0x60,
  37042. 0x37, 0x31, 0x28, 0x52, 0x20, 0x78, 0x65, 0x53,
  37043. 0x76, 0x10, 0x84, 0x87, 0x57, 0x13, 0x66, 0x03,
  37044. 0x56, 0x81, 0x36, 0x66, 0x68, 0x41, 0x55, 0x64,
  37045. 0x63, 0x70, 0x26, 0x21, 0x02, 0x30, 0x28, 0x35,
  37046. 0x02, 0x45, 0x88, 0x80, 0x02, 0x06, 0x44, 0x58,
  37047. 0x24, 0x13, 0x88, 0x83, 0x22, 0x34, 0x22, 0x50,
  37048. 0x47, 0x11, 0x01, 0x86, 0x45, 0x60, 0x67, 0x36,
  37049. 0x82, 0x22, 0x18, 0x74, 0x11, 0x60, 0x58, 0x60,
  37050. 0x87, 0x26, 0x31, 0x85, 0x12, 0x70, 0x84, 0x83,
  37051. 0x88, 0x68, 0x88, 0x51, 0x00, 0x55, 0x02, 0x57,
  37052. 0x77, 0x42, 0x13, 0x23, 0x14, 0x04, 0x76, 0x80,
  37053. 0x72, 0x25, 0x51, 0x56, 0x10, 0x63, 0x12, 0x21,
  37054. 0x03, 0x86, 0x27, 0x30, 0x28, 0x12, 0x01, 0x37,
  37055. 0x48, 0x32, 0x53, 0x86, 0x15, 0x46, 0x50, 0x05,
  37056. 0x34, 0x87, 0x61, 0x04, 0x88, 0x18, 0x35, 0x85,
  37057. 0x44, 0x46, 0x24, 0x67, 0x43, 0x83, 0x02, 0x26,
  37058. 0x56, 0x41, 0x41, 0x77, 0x86, 0x56, 0x41, 0x75,
  37059. 0x25, 0x61, 0x36, 0x05, 0x47, 0x65, 0x00, 0x14,
  37060. 0x32, 0x38, 0x16, 0x81, 0x06, 0x30, 0x61, 0x25,
  37061. 0x16, 0x30, 0x50, 0x44, 0x13, 0x08, 0x75, 0x00,
  37062. 0x50, 0x20, 0x68, 0x21, 0x55, 0x74, 0x61, 0x18,
  37063. 0x62, 0x05, 0x15, 0x51, 0x08, 0x24, 0x01, 0x13,
  37064. 0x81, 0x33, 0x64, 0x83, 0x23, 0x00, 0x55, 0x73,
  37065. 0x62, 0x40, 0x61, 0x75, 0x15, 0x78, 0x21, 0x14,
  37066. 0x13, 0x64, 0x21, 0x47, 0x07, 0x76, 0x80, 0x76,
  37067. 0x76, 0x17, 0x75, 0x50, 0x61, 0x14, 0x40, 0x82,
  37068. 0x87, 0x83, 0x50, 0x87, 0x30, 0x86, 0x35, 0x30,
  37069. 0x28, 0x20, 0x10, 0x01, 0x48, 0x18, 0x34, 0x65,
  37070. 0x23, 0x10, 0x25, 0x42, 0x40, 0x22, 0x54, 0x34,
  37071. 0x35, 0x33, 0x71, 0x70, 0x20, 0x61, 0x55, 0x74,
  37072. 0x33, 0x01, 0x02, 0x60, 0x58, 0x24, 0x80, 0x12,
  37073. 0x46, 0x41, 0x38, 0x10, 0x76, 0x67, 0x34, 0x63,
  37074. 0x48, 0x85, 0x06, 0x48, 0x04, 0x23, 0x22, 0x66,
  37075. 0x57, 0x71, 0x68, 0x18, 0x04, 0x32, 0x01, 0x31,
  37076. 0x01, 0x55, 0x22, 0x27, 0x55, 0x72, 0x10, 0x00,
  37077. 0x43, 0x88, 0x76, 0x62, 0x84, 0x77, 0x07, 0x77,
  37078. 0x14, 0x07, 0x20, 0x53, 0x74, 0x17, 0x51, 0x17,
  37079. 0x66, 0x84, 0x47, 0x83, 0x61, 0x03, 0x52, 0x10,
  37080. 0x05, 0x40, 0x46, 0x55, 0x61, 0x47, 0x26, 0x70,
  37081. 0x40, 0x22, 0x10, 0x34, 0x41, 0x01, 0x03, 0x48,
  37082. 0x33, 0x05, 0x72, 0x32, 0x75, 0x82, 0x45, 0x85,
  37083. 0x20, 0x70, 0x80, 0x82, 0x20, 0x23, 0x62, 0x81,
  37084. 0x15, 0x47, 0x80, 0x23, 0x67, 0x23, 0x73, 0x34,
  37085. 0x44, 0x33, 0x85, 0x10, 0x05, 0x50, 0x30, 0x03,
  37086. 0x48, 0x13, 0x01, 0x36, 0x45, 0x11, 0x06, 0x33,
  37087. 0x82, 0x22, 0x78, 0x75, 0x42, 0x02, 0x40, 0x45,
  37088. 0x04, 0x47, 0x43, 0x05, 0x30, 0x44, 0x42, 0x02,
  37089. 0x28, 0x26, 0x64, 0x24, 0x74, 0x75, 0x86, 0x11,
  37090. 0x85, 0x43, 0x25, 0x46, 0x10, 0x62, 0x82, 0x71,
  37091. 0x08, 0x27, 0x45, 0x13, 0x73, 0x18, 0x84, 0x73,
  37092. 0x51, 0x51, 0x67, 0x14, 0x70, 0x11, 0x07, 0x08,
  37093. 0x62, 0x16, 0x25, 0x27, 0x36, 0x68, 0x44, 0x01,
  37094. 0x18, 0x63, 0x74, 0x50, 0x31, 0x13, 0x43, 0x65,
  37095. 0x80, 0x11, 0x16, 0x52, 0x86, 0x42, 0x51, 0x81,
  37096. 0x51, 0x17, 0x05, 0x68, 0x05, 0x73, 0x60, 0x37,
  37097. 0x63, 0x85, 0x86, 0x11, 0x23, 0x23, 0x38, 0x13,
  37098. 0x87, 0x48, 0x82, 0x74, 0x71, 0x81, 0x87, 0x65,
  37099. 0x58, 0x26, 0x60, 0x34, 0x76, 0x16, 0x15, 0x24,
  37100. 0x06, 0x78, 0x16, 0x40, 0x03, 0x45, 0x72, 0x31,
  37101. 0x63, 0x73, 0x31, 0x85, 0x02, 0x66, 0x44, 0x36,
  37102. 0x24, 0x82, 0x56, 0x38, 0x86, 0x10, 0x40, 0x54,
  37103. 0x72, 0x70, 0x24, 0x22, 0x72, 0x78, 0x47, 0x07,
  37104. 0x86, 0x30, 0x48, 0x72, 0x84, 0x57, 0x06, 0x34,
  37105. 0x78, 0x37, 0x63, 0x25, 0x56, 0x64, 0x81, 0x30,
  37106. 0x62, 0x77, 0x22, 0x84, 0x20, 0x10, 0x74, 0x25,
  37107. 0x04, 0x21, 0x76, 0x47, 0x72, 0x35, 0x05, 0x06,
  37108. 0x22, 0x50, 0x34, 0x11, 0x26, 0x67, 0x03, 0x05,
  37109. 0x42, 0x04, 0x16, 0x01, 0x27, 0x17, 0x86, 0x67,
  37110. 0x70, 0x51, 0x53, 0x13, 0x12, 0x62, 0x03, 0x25,
  37111. 0x05, 0x38, 0x37, 0x44, 0x02, 0x66, 0x84, 0x74,
  37112. 0x14, 0x40, 0x35, 0x20, 0x40, 0x30, 0x44, 0x64,
  37113. 0x27, 0x50, 0x77, 0x47, 0x06, 0x15, 0x84, 0x48,
  37114. 0x13, 0x14, 0x32, 0x48, 0x11, 0x74, 0x80, 0x68,
  37115. 0x85, 0x81, 0x17, 0x67, 0x38, 0x22, 0x76, 0x16,
  37116. 0x18, 0x44, 0x55, 0x47, 0x85, 0x36, 0x44, 0x11,
  37117. 0x52, 0x01, 0x81, 0x50, 0x41, 0x00, 0x00, 0x25,
  37118. 0x83, 0x41, 0x62, 0x22, 0x12, 0x54, 0x88, 0x77,
  37119. 0x70, 0x48, 0x84, 0x25, 0x77, 0x75, 0x40, 0x16,
  37120. 0x46, 0x24, 0x88, 0x81, 0x65, 0x70, 0x02, 0x66,
  37121. 0x28, 0x64, 0x12, 0x40, 0x30, 0x60, 0x53, 0x06,
  37122. 0x44, 0x02, 0x48, 0x78, 0x75, 0x68, 0x21, 0x23,
  37123. 0x30, 0x05, 0x81, 0x17, 0x72, 0x66, 0x88, 0x71,
  37124. 0x50, 0x25, 0x03, 0x51, 0x42, 0x27, 0x20, 0x81,
  37125. 0x03, 0x52, 0x73, 0x53, 0x63, 0x57, 0x13, 0x60,
  37126. 0x41, 0x20, 0x47, 0x12, 0x55, 0x57, 0x58, 0x16,
  37127. 0x38, 0x63, 0x21, 0x34, 0x51, 0x76, 0x33, 0x26,
  37128. 0x70, 0x41, 0x18, 0x11, 0x07, 0x37, 0x16, 0x12,
  37129. 0x01, 0x14, 0x28, 0x56, 0x78, 0x10, 0x86, 0x24,
  37130. 0x24, 0x32, 0x01, 0x13, 0x57, 0x53, 0x46, 0x46,
  37131. 0x24, 0x05, 0x20, 0x16, 0x56, 0x83, 0x30, 0x30,
  37132. 0x61, 0x20, 0x75, 0x07, 0x05, 0x74, 0x14, 0x17,
  37133. 0x43, 0x72, 0x23, 0x04, 0x18, 0x61, 0x50, 0x13,
  37134. 0x67, 0x31, 0x75, 0x36, 0x71, 0x02, 0x38, 0x74,
  37135. 0x21, 0x80, 0x20, 0x48, 0x66, 0x23, 0x52, 0x54,
  37136. 0x77, 0x27, 0x45, 0x73, 0x23, 0x88, 0x60, 0x50,
  37137. 0x88, 0x82, 0x70, 0x23, 0x72, 0x08, 0x44, 0x66,
  37138. 0x44, 0x36, 0x12, 0x57, 0x66, 0x14, 0x25, 0x12,
  37139. 0x17, 0x34, 0x64, 0x82, 0x01, 0x54, 0x61, 0x57,
  37140. 0x50, 0x31, 0x65, 0x64, 0x75, 0x44, 0x76, 0x48,
  37141. 0x16, 0x44, 0x46, 0x55, 0x80, 0x64, 0x26, 0x53,
  37142. 0x27, 0x22, 0x10, 0x87, 0x84, 0x03, 0x15, 0x35,
  37143. 0x15, 0x20, 0x86, 0x14, 0x04, 0x03, 0x26, 0x43,
  37144. 0x31, 0x43, 0x31, 0x45, 0x46, 0x34, 0x36, 0x87,
  37145. 0x44, 0x41, 0x21, 0x77, 0x61, 0x20, 0x85, 0x06,
  37146. 0x28, 0x51, 0x15, 0x62, 0x77, 0x20, 0x38, 0x58,
  37147. 0x78, 0x27, 0x12, 0x22, 0x46, 0x71, 0x51, 0x38,
  37148. 0x11, 0x15, 0x40, 0x03, 0x78, 0x36, 0x15, 0x57,
  37149. 0x34, 0x28, 0x53, 0x21, 0x37, 0x35, 0x04, 0x76,
  37150. 0x00, 0x56, 0x72, 0x48, 0x46, 0x01, 0x56, 0x67,
  37151. 0x62, 0x36, 0x14, 0x51, 0x23, 0x54, 0x32, 0x35,
  37152. 0x82, 0x83, 0x21, 0x60, 0x38, 0x62, 0x21, 0x03,
  37153. 0x62, 0x76, 0x40, 0x34, 0x66, 0x88, 0x50, 0x73,
  37154. 0x00, 0x53, 0x87, 0x31, 0x37, 0x50, 0x11, 0x32,
  37155. 0x86, 0x52, 0x18, 0x64, 0x16, 0x63, 0x48, 0x71,
  37156. 0x70, 0x47, 0x24, 0x85, 0x31, 0x86, 0x60, 0x86,
  37157. 0x33, 0x52, 0x85, 0x82, 0x68, 0x17, 0x70, 0x88,
  37158. 0x84, 0x56, 0x52, 0x77, 0x04, 0x48, 0x22, 0x22,
  37159. 0x54, 0x57, 0x20, 0x31, 0x76, 0x47, 0x26, 0x25,
  37160. 0x04, 0x35, 0x38, 0x44, 0x55, 0x21, 0x14, 0x02,
  37161. 0x13, 0x64, 0x74, 0x87, 0x68, 0x68, 0x73, 0x05,
  37162. 0x22, 0x45, 0x54, 0x45, 0x83, 0x46, 0x64, 0x54,
  37163. 0x80, 0x07, 0x32, 0x87, 0x52, 0x43, 0x54, 0x54,
  37164. 0x14, 0x73, 0x24, 0x87, 0x36, 0x41, 0x74, 0x84,
  37165. 0x06, 0x35, 0x13, 0x40, 0x61, 0x54, 0x21, 0x31,
  37166. 0x48, 0x63, 0x05, 0x74, 0x24, 0x84, 0x74, 0x76,
  37167. 0x11, 0x10, 0x16, 0x63, 0x77, 0x12, 0x26, 0x61,
  37168. 0x31, 0x28, 0x70, 0x34, 0x25, 0x01, 0x30, 0x76,
  37169. 0x76, 0x06, 0x21, 0x58, 0x42, 0x87, 0x31, 0x72,
  37170. 0x76, 0x03, 0x76, 0x26, 0x78, 0x05, 0x88, 0x25,
  37171. 0x25, 0x86, 0x17, 0x02, 0x85, 0x88, 0x76, 0x20,
  37172. 0x36, 0x57, 0x30, 0x81, 0x83, 0x61, 0x05, 0x80,
  37173. 0x21, 0x45, 0x74, 0x01, 0x12, 0x74, 0x51, 0x28,
  37174. 0x77, 0x26, 0x30, 0x14, 0x54, 0x84, 0x13, 0x78,
  37175. 0x06, 0x00, 0x12, 0x64, 0x00, 0x37, 0x44, 0x68,
  37176. 0x40, 0x57, 0x05, 0x27, 0x07, 0x41, 0x56, 0x22,
  37177. 0x31, 0x40, 0x23, 0x26, 0x55, 0x42, 0x55, 0x16,
  37178. 0x02, 0x65, 0x32, 0x16, 0x33, 0x44, 0x46, 0x48,
  37179. 0x04, 0x52, 0x06, 0x53, 0x44, 0x40, 0x11, 0x28,
  37180. 0x46, 0x67, 0x56, 0x81, 0x72, 0x75, 0x51, 0x38,
  37181. 0x21, 0x86, 0x46, 0x03, 0x22, 0x87, 0x21, 0x70,
  37182. 0x68, 0x50, 0x75, 0x13, 0x11, 0x44, 0x35, 0x12,
  37183. 0x60, 0x02, 0x13, 0x47, 0x18, 0x38, 0x78, 0x86,
  37184. 0x38, 0x58, 0x45, 0x57, 0x23, 0x03, 0x88, 0x66,
  37185. 0x56, 0x82, 0x18, 0x31, 0x20, 0x08, 0x61, 0x47,
  37186. 0x78, 0x08, 0x68, 0x37, 0x21, 0x04, 0x65, 0x47,
  37187. 0x58, 0x70, 0x34, 0x58, 0x73, 0x24, 0x22, 0x30,
  37188. 0x66, 0x05, 0x01, 0x28, 0x87, 0x85, 0x77, 0x74,
  37189. 0x23, 0x86, 0x65, 0x84, 0x85, 0x57, 0x85, 0x63,
  37190. 0x06, 0x55, 0x61, 0x75, 0x46, 0x22, 0x87, 0x00,
  37191. 0x18, 0x53, 0x08, 0x03, 0x07, 0x50, 0x42, 0x70,
  37192. 0xFC, 0xB8, 0x7B, 0x22, 0x3D, 0x24, 0xAE, 0x5D,
  37193. 0xB1, 0x89, 0x04, 0x21, 0xC3, 0xFF, 0x1D, 0x59,
  37194. 0xB8, 0x4B, 0x19, 0xE2, 0x4D, 0x14, 0x36, 0x99,
  37195. 0x19, 0x1C, 0x7E, 0x9A, 0x46, 0x48, 0x42, 0x20,
  37196. 0x6B, 0xBA, 0x24, 0x7E, 0x8C, 0x6B, 0x27, 0xBA,
  37197. 0x26, 0xE6, 0x8A, 0xD5, 0xA7, 0x1D, 0x03, 0x61,
  37198. 0xCD, 0x5C, 0x74, 0xCE, 0x50, 0xC2, 0xCE, 0xF1,
  37199. 0x91, 0x31, 0xEF, 0x54, 0x66, 0x23, 0x7F, 0xFE,
  37200. 0xF7, 0xFE, 0x6B, 0x5F, 0xD1, 0x98, 0x23, 0x8E,
  37201. 0x1C, 0xA0, 0xB1, 0x01, 0x30, 0xC6, 0x29, 0xCC,
  37202. 0x91, 0x91, 0xF5, 0x78, 0x6F, 0x5C, 0xD6, 0x28,
  37203. 0xA4, 0x22, 0x56, 0xCB, 0x6F, 0xC7, 0xD7, 0x09,
  37204. 0x56, 0x88, 0xAF, 0x1B, 0xC8, 0x43, 0x51, 0xA4,
  37205. 0x7B, 0x4B, 0x38, 0x2E, 0xF6, 0x1F, 0xD6, 0x5C,
  37206. 0x9E, 0xC2, 0x26, 0xF4, 0x2B, 0x0A, 0x19, 0x7C,
  37207. 0x6A, 0xD8, 0xF0, 0xB0, 0x15, 0xD0, 0xB1, 0xC7,
  37208. 0xE0, 0x14, 0x28, 0x95, 0x6A, 0x9B, 0xB2, 0xDE,
  37209. 0x9A, 0x97, 0xE5, 0x75, 0x66, 0xF8, 0xF5, 0x66,
  37210. 0x86, 0xA1, 0xF4, 0x68, 0x0C, 0xEC, 0xEA, 0x87,
  37211. 0x3B, 0x69, 0x1C, 0xF8, 0xBD, 0x63, 0xAB, 0x73,
  37212. 0x73, 0xBA, 0xE8, 0x09, 0x5B, 0xA7, 0x76, 0x3E,
  37213. 0x50, 0xD6, 0x83, 0x9D, 0x00, 0x35, 0xBB, 0xFB,
  37214. 0x91, 0xBA, 0x60, 0x72, 0x17, 0x98, 0xFB, 0x2C,
  37215. 0x80, 0x2C, 0x60, 0x3A, 0x08, 0xA1, 0x24, 0x05,
  37216. 0xE0, 0xB5, 0x20, 0xEA, 0x41, 0x43, 0x8F, 0xEA,
  37217. 0xEF, 0xA5, 0x62, 0xDC, 0x78, 0x92, 0xF4, 0x58,
  37218. 0x9F, 0x8D, 0x2B, 0x96, 0x5E, 0xE5, 0x49, 0x73,
  37219. 0xA7, 0x2C, 0x8D, 0x33, 0x5C, 0x62, 0x61, 0x98,
  37220. 0x80, 0x64, 0x13, 0x31, 0x03, 0x10, 0xE3, 0x2E,
  37221. 0xFE, 0x6B, 0x39, 0xB5, 0xCF, 0xB1, 0xD1, 0x33,
  37222. 0xAD, 0xE0, 0x1B, 0xCE, 0x94, 0x21, 0x6C, 0xF4,
  37223. 0xCD, 0x8F, 0x86, 0x43, 0x03, 0x1D, 0xB8, 0xC2,
  37224. 0x47, 0xB5, 0x73, 0x21, 0xCA, 0x1E, 0xFB, 0xB8,
  37225. 0x53, 0x63, 0x7D, 0x0C, 0x57, 0x52, 0x14, 0xFC,
  37226. 0x77, 0xA5, 0xA6, 0x84, 0xD5, 0x0A, 0xBF, 0xE4,
  37227. 0xE9, 0x71, 0x99, 0x8E, 0x06, 0x6E, 0x50, 0x24,
  37228. 0xDA, 0x02, 0x76, 0x8A, 0xED, 0xE1, 0x3E, 0x83,
  37229. 0xF0, 0x51, 0x54, 0xA9, 0x99, 0x29, 0x48, 0x42,
  37230. 0x7A, 0xA9, 0x8C, 0x87, 0x42, 0x51, 0xAF, 0x56,
  37231. 0x94, 0x23, 0x53, 0x89, 0x44, 0xFA, 0xD8, 0x93,
  37232. 0xFC, 0x65, 0x6E, 0x9C, 0xED, 0x80, 0x6A, 0x85,
  37233. 0xD9, 0xC3, 0x36, 0x71, 0x02, 0x25, 0x29, 0x36,
  37234. 0x8E, 0x7E, 0xC7, 0x0C, 0x9E, 0xE9, 0x74, 0x30,
  37235. 0x1C, 0x08, 0xCB, 0xE6, 0xAC, 0x5E, 0x88, 0xE6,
  37236. 0x37, 0x79, 0x5C, 0xB2, 0xA2, 0x15, 0xFF, 0xAA,
  37237. 0x08, 0xED, 0xDE, 0x40, 0xAC, 0xFA, 0xEE, 0x2A,
  37238. 0x40, 0xD5, 0x05, 0xCF, 0x58, 0xA6, 0x69, 0x66,
  37239. 0x31, 0x5A, 0x68, 0x98, 0x24, 0x03, 0xD8, 0x1B,
  37240. 0xFA, 0x89, 0xE3, 0x7C, 0x9E, 0x42, 0x1D, 0xA5,
  37241. 0x88, 0xBA, 0x7E, 0x42, 0x2A, 0xC7, 0x44, 0x6A,
  37242. 0x1E, 0x61, 0xC8, 0x22, 0x29, 0x9D, 0xFC, 0x34,
  37243. 0xEC, 0xFA, 0xBE, 0x5C, 0xB6, 0x26, 0xB9, 0x6C,
  37244. 0x8E, 0xA6, 0xC9, 0x3B, 0xDB, 0xD2, 0xD5, 0xBD,
  37245. 0x70, 0xC5, 0xF8, 0x26, 0x7A, 0x84, 0xE0, 0x07,
  37246. 0xA7, 0x11, 0x5E, 0x5B, 0xE5, 0xF1, 0x20, 0x32,
  37247. 0xA3, 0x7C, 0xAB, 0x05, 0xD5, 0x41, 0xE3, 0xDE,
  37248. 0xA5, 0x1A, 0x83, 0x2E, 0xDE, 0x8D, 0x34, 0x9A,
  37249. 0xFD, 0xD5, 0xE6, 0xFC, 0xFC, 0x83, 0x46, 0xE3,
  37250. 0xD4, 0x7C, 0xF1, 0x7F, 0xEA, 0x87, 0x5E, 0x38,
  37251. 0x5D, 0xB9, 0x8A, 0xC2, 0xDB, 0xE8, 0xB4, 0xF8,
  37252. 0x05, 0x37, 0x31, 0x0D, 0xD9, 0x4C, 0xD0, 0xB6,
  37253. 0x25, 0xE9, 0x97, 0x85, 0xDB, 0x04, 0x9A, 0x01,
  37254. 0xF5, 0x4B, 0xA1, 0xF4, 0x2A, 0xDF, 0xEC, 0xAE,
  37255. 0x24, 0x11, 0xD3, 0x2B, 0x2F, 0x84, 0x6C, 0x88,
  37256. 0xA3, 0x0C, 0x76, 0xEA, 0x0A, 0x38, 0xB2, 0x71,
  37257. 0xB6, 0xAC, 0xA8, 0x23, 0x6E, 0x61, 0xEB, 0xB8,
  37258. 0x4A, 0x9D, 0xC4, 0x9E, 0x5C, 0x5B, 0xEE, 0x7E,
  37259. 0x7D, 0x8D, 0xA2, 0xC1, 0xA1, 0xA0, 0xA3, 0x14,
  37260. 0x50, 0xE0, 0x8F, 0xAB, 0xBB, 0x1B, 0x1F, 0x05,
  37261. 0xAA, 0xE3, 0x00, 0xD8, 0xCD, 0xE7, 0x35, 0xB4,
  37262. 0x7B, 0xBD, 0xB0, 0x5C, 0xCC, 0x0C, 0x05, 0x33,
  37263. 0x6B, 0xE4, 0x51, 0x73, 0x1B, 0x6B, 0x77, 0x7B,
  37264. 0xE5, 0xCB, 0xAF, 0x98, 0x53, 0x5F, 0x7E, 0x08,
  37265. 0xFF, 0xCD, 0x8A, 0x44, 0x9E, 0x1D, 0x43, 0x6A,
  37266. 0x4F, 0x05, 0x99, 0x01, 0xF5, 0x6F, 0x01, 0x30,
  37267. 0xBD, 0x15, 0xD7, 0x51, 0x16, 0x45, 0x40, 0x6B,
  37268. 0xF3, 0x13, 0xCA, 0x1F, 0x22, 0x02, 0xA4, 0xA8,
  37269. 0x6A, 0x1D, 0x04, 0x7F, 0xD5, 0x8A, 0x3E, 0x87,
  37270. 0x7F, 0x1D, 0x5A, 0x79, 0x75, 0xD1, 0x6D, 0x67,
  37271. 0xB3, 0x23, 0xC6, 0x28, 0x7B, 0x9C, 0xCE, 0xEE,
  37272. 0x98, 0x9E, 0xE8, 0x44, 0xA9, 0x3E, 0x7E, 0xFD,
  37273. 0x3B, 0xD9, 0xD8, 0x31, 0x6D, 0xA3, 0x77, 0xDF,
  37274. 0x0B, 0xB9, 0xE2, 0x61, 0xA2, 0x71, 0xD5, 0x0C,
  37275. 0xB7, 0x01, 0x67, 0xC3, 0x0D, 0x19, 0x2D, 0xAA,
  37276. 0xDE, 0x96, 0x0E, 0xEA, 0x33, 0x5E, 0xEC, 0x52,
  37277. 0xE5, 0x2D, 0x95, 0x39, 0xE1, 0xF9, 0x5D, 0x9E,
  37278. 0xB6, 0x5E, 0x54, 0x8F, 0x16, 0x60, 0x99, 0xED,
  37279. 0x88, 0x2C, 0x30, 0x72, 0x53, 0x6A, 0x6C, 0xAA,
  37280. 0x05, 0x21, 0xA5, 0xAA, 0x7C, 0x64, 0x72, 0xA0,
  37281. 0xC0, 0x4F, 0x80, 0xDA, 0x20, 0x5D, 0x52, 0x18,
  37282. 0x77, 0x07, 0xDF, 0x5C, 0x2F, 0x2E, 0xA2, 0x5F,
  37283. 0xEF, 0x00, 0xCA, 0x7B, 0xF0, 0xD3, 0xB7, 0xF8,
  37284. 0x1E, 0x31, 0x9E, 0x61, 0xCA, 0x2C, 0xC5, 0xA5,
  37285. 0x25, 0xA2, 0x7B, 0x56, 0xAA, 0xBA, 0xE4, 0xD5,
  37286. 0x35, 0xE5, 0xEC, 0x24, 0x2D, 0x81, 0x1A, 0x24,
  37287. 0xD7, 0x45, 0x76, 0xBF, 0x4B, 0x8A, 0x72, 0xFA,
  37288. 0x5F, 0xAE, 0xC1, 0xA2, 0x83, 0xB6, 0x1D, 0x60,
  37289. 0x28, 0x7E, 0x1E, 0x2E, 0xC8, 0xC6, 0xAB, 0x04,
  37290. 0x56, 0x5F, 0xD5, 0xCD, 0x64, 0x26, 0x34, 0x94,
  37291. 0xE8, 0x03, 0x41, 0x63, 0x35, 0x5B, 0x45, 0x84,
  37292. 0xCE, 0xFA, 0x0B, 0x66, 0x40, 0x85, 0x1A, 0xE1,
  37293. 0x23, 0xE9, 0x8F, 0xBD, 0xA9, 0x23, 0xFC, 0xA3,
  37294. 0x8E, 0x38, 0xB3, 0x84, 0xE2, 0xB9, 0x54, 0x41,
  37295. 0x4B, 0x36, 0x4F, 0xB8, 0xB0, 0x87, 0x56, 0x04,
  37296. 0x8B, 0x75, 0xC7, 0x85, 0x31, 0xD4, 0xA5, 0x12,
  37297. 0x99, 0xC4, 0x9D, 0xEA, 0x4B, 0x36, 0x8C, 0x19,
  37298. 0x82, 0xFE, 0xAD, 0x4A, 0xB1, 0xAA, 0x52, 0x35,
  37299. 0xA4, 0xA1, 0x7F, 0xB0, 0x64, 0x6F, 0x04, 0x04,
  37300. 0x7B, 0xF0, 0x80, 0x48, 0xA1, 0x1C, 0xF8, 0x95,
  37301. 0x8B, 0x68, 0x34, 0xB7, 0xFD, 0x00, 0x31, 0x30,
  37302. 0x6A, 0x39, 0xC8, 0xAE, 0x68, 0xC3, 0x53, 0x65,
  37303. 0x19, 0x7C, 0x1E, 0x57, 0x97, 0xFC, 0x47, 0x3E,
  37304. 0xB1, 0x94, 0x54, 0x48, 0x6F, 0xEB, 0xAA, 0xEC,
  37305. 0x5C, 0x2E, 0xE9, 0x2C, 0xCC, 0x3A, 0xF3, 0xC7,
  37306. 0x43, 0x08, 0x7D, 0x2D, 0x56, 0x4B, 0x7D, 0xE9,
  37307. 0xE5, 0x96, 0xF3, 0x12, 0x4B, 0xE9, 0x08, 0xF3,
  37308. 0x04, 0x5A, 0x75, 0x1A, 0x7D, 0x7E, 0x37, 0xE6,
  37309. 0xC8, 0xC1, 0xFE, 0xF3, 0x32, 0x63, 0x2D, 0x0B,
  37310. 0xBE, 0x05, 0x13, 0x6A, 0x44, 0x58, 0x7F, 0x54,
  37311. 0x5F, 0x5F, 0xF5, 0x2F, 0xB8, 0x0B, 0xF2, 0xBF,
  37312. 0x0B, 0xF4, 0x30, 0x2F, 0xCF, 0xEC, 0xFE, 0x08,
  37313. 0xEC, 0x51, 0xF2, 0x29, 0xD7, 0xAC, 0x28, 0xE1,
  37314. 0x75, 0x42, 0x61, 0xBC, 0xE7, 0xB1, 0x53, 0x4F,
  37315. 0x7D, 0x3B, 0xB0, 0x8D, 0x01, 0x15, 0x1E, 0xBE,
  37316. 0xEC, 0xD9, 0x54, 0xC2, 0x4E, 0x70, 0x3E, 0xEA,
  37317. 0x39, 0x14, 0x26, 0xB7, 0x01, 0x79, 0x5D, 0x06,
  37318. 0x93, 0x85, 0x99, 0xAA, 0x7D, 0xDC, 0xF9, 0x2E,
  37319. 0x44, 0x56, 0x9B, 0xFA, 0x9D, 0x91, 0x2A, 0x8E,
  37320. 0x89, 0x48, 0x51, 0xE3, 0xD0, 0x53, 0xB3, 0xAD,
  37321. 0x43, 0x29, 0xB7, 0x6A, 0x50, 0xC0, 0x78, 0x4D,
  37322. 0x42, 0xF3, 0x7C, 0x5F, 0x90, 0x06, 0xAC, 0x2A,
  37323. 0x9D, 0x5D, 0xE5, 0x18, 0x3F, 0xA3, 0xC6, 0x5E,
  37324. 0xCD, 0xB6, 0xCF, 0x31, 0x67, 0xA4, 0x7A, 0x8F,
  37325. 0x5C, 0x59, 0xBD, 0xD7, 0x9B, 0x7C, 0x24, 0x06,
  37326. 0x97, 0xE1, 0x59, 0x72, 0x85, 0x02, 0x74, 0xFE,
  37327. 0x41, 0xAD, 0x84, 0xD9, 0x0D, 0xCB, 0x34, 0x16,
  37328. 0x11, 0xE7, 0x66, 0xD2, 0x12, 0xDC, 0x76, 0x3C,
  37329. 0xF9, 0x4C, 0x8C, 0x41, 0x94, 0xCC, 0xA9, 0x1B,
  37330. 0x21, 0x03, 0x28, 0xE4, 0xA3, 0x37, 0x4E, 0x29,
  37331. 0xD2, 0x48, 0x11, 0x2B, 0xB6, 0x68, 0xA3, 0x92,
  37332. 0xC2, 0x0D, 0x87, 0x91, 0x03, 0x76, 0xB5, 0x00,
  37333. 0x1F, 0x3F, 0xFB, 0xBE, 0xC3, 0xE0, 0x08, 0xBF,
  37334. 0x2F, 0x46, 0xF7, 0x40, 0x73, 0x83, 0xA8, 0x0D,
  37335. 0xDA, 0x08, 0x2B, 0xDB, 0x8F, 0xE9, 0x25, 0xE4,
  37336. 0xF1, 0x2B, 0x37, 0x92, 0x27, 0x0E, 0x5A, 0x46,
  37337. 0xB8, 0xC5, 0x7B, 0x6E, 0x5A, 0x4B, 0x95, 0x58,
  37338. 0x4E, 0xF3, 0x80, 0xED, 0x49, 0x93, 0xEC, 0x52,
  37339. 0x9F, 0xF2, 0xAA, 0x39, 0xDD, 0x6D, 0xFE, 0x88,
  37340. 0xFD, 0xEB, 0x6E, 0xDA, 0x0E, 0x8D, 0xA7, 0x95,
  37341. 0x66, 0xB0, 0x7D, 0x37, 0xAE, 0xCC, 0x64, 0x37,
  37342. 0x25, 0x95, 0x18, 0xF9, 0x7E, 0x6C, 0x86, 0x12,
  37343. 0xB3, 0xC3, 0x57, 0x03, 0xBF, 0xF9, 0x92, 0x15,
  37344. 0x3E, 0x66, 0x0E, 0x2E, 0x20, 0x77, 0xA0, 0x5F,
  37345. 0x26, 0x5F, 0xB5, 0x12, 0x1D, 0xD7, 0x9F, 0x0A,
  37346. 0x33, 0xBC, 0x38, 0xEC, 0x83, 0x08, 0xE2, 0xA9,
  37347. 0x84, 0xCD, 0x3D, 0x8A, 0xC6, 0x09, 0x30, 0x6F,
  37348. 0x77, 0x93, 0xD7, 0xDE, 0x08, 0xD8, 0x45, 0xA4,
  37349. 0x21, 0x28, 0x26, 0x4E, 0x5C, 0x17, 0x77, 0x74,
  37350. 0xE3, 0x5D, 0x58, 0x7C, 0x96, 0xB2, 0x47, 0x05,
  37351. 0x42, 0x21, 0x78, 0x5D, 0xB3, 0x8D, 0xDC, 0x6F,
  37352. 0xDB, 0xF7, 0xBF, 0x6F, 0x66, 0x4B, 0xD6, 0x30,
  37353. 0x14, 0xC0, 0xBF, 0x94, 0x2A, 0x83, 0x91, 0x6C,
  37354. 0xBF, 0x2C, 0x42, 0x85, 0x41, 0xED, 0xA2, 0xBB,
  37355. 0xCB, 0xFC, 0xF9, 0x35, 0xDE, 0xFC, 0xB3, 0x63,
  37356. 0xE1, 0x64, 0xAA, 0x51, 0x2D, 0xD5, 0xFA, 0x79,
  37357. 0x53, 0x31, 0x40, 0x0B, 0x9B, 0xD0, 0x3C, 0xE3,
  37358. 0xD7, 0x2D, 0x91, 0x05, 0x62, 0xC3, 0x81, 0xFE,
  37359. 0x93, 0x1E, 0x8C, 0x37, 0x9E, 0x30, 0x23, 0x73,
  37360. 0x3A, 0xB9, 0x18, 0x6E, 0x5D, 0xEF, 0x31, 0xE9,
  37361. 0xF6, 0x25, 0x7F, 0xB8, 0x47, 0x74, 0xCE, 0x28,
  37362. 0x23, 0xD4, 0x4F, 0xC1, 0x42, 0xCB, 0xEB, 0x59,
  37363. 0x8A, 0x68, 0xFD, 0x39, 0x48, 0x37, 0x1A, 0x5D,
  37364. 0x0C, 0x09, 0x64, 0xC6, 0xE1, 0x21, 0x5D, 0x89,
  37365. 0xF6, 0x58, 0xE5, 0x50, 0x4A, 0xD0, 0x93, 0xBC,
  37366. 0x86, 0x02, 0xBA, 0xD2, 0x36, 0x24, 0x9D, 0x7E,
  37367. 0xAF, 0xB6, 0xA1, 0xA0, 0x7C, 0xA7, 0xC7, 0x4D,
  37368. 0xAC, 0x30, 0x7A, 0x70, 0x0F, 0x2F, 0x81, 0x40,
  37369. 0xC1, 0x08, 0x6B, 0x21, 0xF2, 0xE1, 0x51, 0x9C,
  37370. 0x1D, 0x46, 0x94, 0x93, 0x2A, 0x1C, 0x18, 0xCB,
  37371. 0xED, 0x0D, 0x0E, 0x29, 0xDE, 0xFC, 0x52, 0x52,
  37372. 0x97, 0x93, 0x70, 0x85, 0xE2, 0x63, 0x0D, 0xC6,
  37373. 0x2C, 0x0C, 0x05, 0x0C, 0x4F, 0xF2, 0x70, 0x87,
  37374. 0x2B, 0xE7, 0xBB, 0x52, 0x2D, 0xD6, 0x99, 0x1B,
  37375. 0x59, 0x6F, 0xC2, 0x92, 0x11, 0x72, 0x5D, 0x99,
  37376. 0x60, 0xB1, 0x6A, 0x52, 0xEA, 0x91, 0x78, 0x19,
  37377. 0x23, 0xC0, 0x3B, 0x71, 0x9D, 0x09, 0xD6, 0xE7,
  37378. 0x10, 0x6D, 0xC5, 0x70, 0x55, 0xC1, 0x9E, 0xF8,
  37379. 0x76, 0xE5, 0xEC, 0x23, 0x17, 0xE7, 0xE4, 0x23,
  37380. 0xC9, 0x71, 0x45, 0x40, 0x72, 0x01, 0x9E, 0x28,
  37381. 0xE6, 0x5C, 0x81, 0xED, 0x52, 0x7A, 0xF1, 0x89,
  37382. 0xBD, 0xFC, 0xF5, 0x21, 0xC9, 0x23, 0x40, 0x75,
  37383. 0x54, 0xAC, 0xBF, 0x69, 0x45, 0xD1, 0x85, 0x44,
  37384. 0x3D, 0xAC, 0x1A, 0x1A, 0x08, 0x8A, 0x68, 0xB5,
  37385. 0x17, 0xD5, 0xD9, 0x90, 0xE1, 0x10, 0x30, 0xDE,
  37386. 0x4F, 0x75, 0x09, 0xE8, 0x7A, 0x77, 0xB3, 0x7C,
  37387. 0xF2, 0x0A, 0x78, 0xE2, 0xCD, 0x48, 0x94, 0x17,
  37388. 0x3C, 0x32, 0xA3, 0x27, 0x35, 0x51, 0x16, 0xB7,
  37389. 0x18, 0x51, 0x44, 0x42, 0x65, 0x60, 0x6A, 0x0A,
  37390. 0x9A, 0x6D, 0x94, 0x61, 0xCC, 0x5D, 0xD8, 0x3B,
  37391. 0x52, 0x7E, 0x4D, 0xBD, 0x6A, 0xEE, 0x03, 0x3D,
  37392. 0x66, 0x1C, 0x3D, 0xE8, 0xC1, 0x82, 0x97, 0xE5,
  37393. 0xD1, 0x31, 0xDB, 0xC8, 0xF6, 0x96, 0xE9, 0x47,
  37394. 0xC9, 0x5C, 0x71, 0x77, 0x2B, 0x62, 0x44, 0x74,
  37395. 0x4D, 0x06, 0x1E, 0x14, 0x45, 0x3B, 0x9F, 0xB1,
  37396. 0x17, 0x34, 0x80, 0x2D, 0xBA, 0x6F, 0x81, 0x79,
  37397. 0xB8, 0x0D, 0xAC, 0xFE, 0xB6, 0xBA, 0xDF, 0xD1,
  37398. 0x4E, 0x05, 0x76, 0x73, 0x6F, 0x80, 0x10, 0xC5,
  37399. 0x32, 0x87, 0xA3, 0xD3, 0x93, 0x18, 0x79, 0xEF,
  37400. 0x27, 0x3B, 0xBF, 0xCD, 0xB5, 0xDE, 0x5B, 0x88,
  37401. 0xAF, 0x51, 0xFD, 0x8A, 0x8C, 0x8F, 0x0A, 0x58,
  37402. 0x94, 0xE2, 0x25, 0xDF, 0xE8, 0x73, 0xFC, 0xC0,
  37403. 0x3C, 0xB1, 0xC9, 0xB5, 0x78, 0x25, 0xF1, 0x11,
  37404. 0x75, 0xC8, 0x7D, 0x08, 0x78, 0xB9, 0xE6, 0x15,
  37405. 0x6B, 0x40, 0x1B, 0x2F, 0xBE, 0x30, 0x03, 0x6B,
  37406. 0xFC, 0x7D, 0xB1, 0x00, 0x02, 0x71, 0xB7, 0xFF,
  37407. 0x5D, 0x63, 0xA8, 0x09, 0x50, 0x75, 0xEF, 0xBD,
  37408. 0x34, 0xEE, 0x73, 0xDE, 0x60, 0x14, 0x95, 0x2D,
  37409. 0x15, 0xBC, 0x30, 0x23, 0x07, 0x02, 0xD8, 0x7C,
  37410. 0x9A, 0x96, 0xD5, 0xE9, 0xF1, 0xF0, 0xF9, 0x26,
  37411. 0x25, 0x96, 0xAA, 0x58, 0xB7, 0xE4, 0x1A, 0xD9,
  37412. 0xA0, 0x9E, 0xAD, 0xB9, 0x44, 0xB6, 0x3F, 0xD9,
  37413. 0x8B, 0x34, 0x7D, 0x11, 0xBD, 0x52, 0x97, 0xC3,
  37414. 0xBE, 0x28, 0x23, 0x85, 0x9F, 0x2F, 0x35, 0xA4,
  37415. 0xE5, 0x4E, 0x13, 0x68, 0x89, 0x09, 0xC3, 0x1A,
  37416. 0x83, 0xE7, 0xDE, 0xCE, 0x4B, 0xDF, 0x31, 0x03,
  37417. 0x9C, 0x72, 0xBA, 0x54, 0xA1, 0x20, 0x2D, 0x17,
  37418. 0x2A, 0x6B, 0x8A, 0x2C, 0xE9, 0x6D, 0xED, 0xCA,
  37419. 0x5B, 0x24, 0xF7, 0xB9, 0x42, 0xC1, 0x4E, 0x13,
  37420. 0x3D, 0xAA, 0x8A, 0xB8, 0xCB, 0xD2, 0x4C, 0x1F,
  37421. 0x0B, 0xBE, 0xB1, 0x27, 0x97, 0x67, 0x26, 0x72,
  37422. 0xE2, 0x2C, 0xE6, 0xC2, 0x12, 0x37, 0xB2, 0x79,
  37423. 0x7D, 0x8E, 0x54, 0xCC, 0x8F, 0xC7, 0x6C, 0x43,
  37424. 0xB4, 0x75, 0x29, 0x66, 0xA3, 0xA4, 0x09, 0x44,
  37425. 0xE7, 0x2D, 0x37, 0x3F, 0x0D, 0x3E, 0x84, 0xF9,
  37426. 0xA3, 0x30, 0x1E, 0xAE, 0x9E, 0xDA, 0x35, 0x44,
  37427. 0x4B, 0x1E, 0x49, 0xE6, 0x61, 0x18, 0x20, 0x6A,
  37428. 0x56, 0xEB, 0x46, 0xD4, 0x8D, 0x20, 0x95, 0x4A,
  37429. 0x77, 0x9A, 0x1E, 0x74, 0xE3, 0xE3, 0xB2, 0xBD,
  37430. 0x40, 0x3D, 0x46, 0xB3, 0x35, 0x10, 0x11, 0xCB,
  37431. 0x6F, 0x8A, 0x86, 0x72, 0xB2, 0xF3, 0xD9, 0x90,
  37432. 0x31, 0x47, 0x55, 0x77, 0x6C, 0xE3, 0x23, 0x7F,
  37433. 0x0A, 0x50, 0xE7, 0x71, 0x20, 0x53, 0x09, 0xC0,
  37434. 0x5D, 0x9A, 0x78, 0xD3, 0x68, 0x88, 0xA8, 0x3B,
  37435. 0xAD, 0x78, 0xE8, 0x6E, 0xDF, 0x36, 0xA8, 0x8D,
  37436. 0xC7, 0x1C, 0x5F, 0x11, 0x56, 0x83, 0x90, 0xD0,
  37437. 0xB5, 0x92, 0x02, 0xE2, 0x9E, 0xE1, 0x1E, 0xCB,
  37438. 0x9F, 0x56, 0x89, 0x63, 0xE8, 0x17, 0x70, 0x83,
  37439. 0x9F, 0xF2, 0x39, 0xAD, 0x03, 0x15, 0x6C, 0xC0,
  37440. 0x71, 0xE8, 0xB7, 0x40, 0x15, 0x95, 0xEC, 0xEE,
  37441. 0x62, 0x34, 0xAC, 0x34, 0xB7, 0x11, 0x70, 0x3D,
  37442. 0x68, 0xC6, 0x7A, 0x28, 0x83, 0xBE, 0x9C, 0x18,
  37443. 0xAB, 0x7F, 0x1A, 0x1B, 0x2E, 0x5C, 0x90, 0xA2,
  37444. 0x32, 0x3C, 0xDF, 0x1E, 0xD4, 0x98, 0x50, 0xB8,
  37445. 0x39, 0x38, 0x19, 0x2F, 0x62, 0x8C, 0x9E, 0xF6,
  37446. 0x5B, 0x77, 0x93, 0x95, 0xEE, 0x37, 0x34, 0xC7,
  37447. 0xA9, 0x01, 0xF7, 0x47, 0x38, 0x86, 0xD7, 0x12,
  37448. 0xD2, 0x15, 0x41, 0x68, 0x16, 0xC3, 0x01, 0x6C,
  37449. 0xC2, 0x83, 0x83, 0xD4, 0x78, 0x7B, 0x46, 0xF6,
  37450. 0x89, 0xDC, 0xE1, 0x11, 0xDA, 0x4D, 0xB8, 0xAC,
  37451. 0x10, 0xE8, 0x4F, 0x66, 0xA5, 0xC2, 0xBD, 0xA1,
  37452. 0xB3, 0xFC, 0x97, 0x7F, 0x6A, 0x0F, 0x73, 0x2E,
  37453. 0xDA, 0x4F, 0x69, 0xB9, 0x75, 0x51, 0xA4, 0xB8,
  37454. 0xB2, 0x61, 0xD6, 0x88, 0x71, 0x94, 0xD3, 0xAF,
  37455. 0xE7, 0xF4, 0xB8, 0x7F, 0xB3, 0xD4, 0x1A, 0xC6,
  37456. 0xDC, 0xDB, 0x8F, 0xD3, 0x9B, 0xE5, 0x0F, 0x2F,
  37457. 0x38, 0x2B, 0xAA, 0x4D, 0x19, 0xC7, 0x45, 0x0A,
  37458. 0xB3, 0xA1, 0xAC, 0x4C, 0x63, 0xCF, 0x93, 0x0A,
  37459. 0xAA, 0x51, 0x7A, 0x15, 0xD5, 0xC0, 0xD5, 0x49,
  37460. 0xFE, 0x03, 0x22, 0x00, 0x71, 0xD3, 0x69, 0x22,
  37461. 0x3E, 0x51, 0x29, 0x6E, 0xCB, 0xF8, 0x0D, 0xCD,
  37462. 0x79, 0xFB, 0xDF, 0xB8, 0xDF, 0x62, 0x90, 0x4D,
  37463. 0x5A, 0x36, 0x20, 0x0F, 0x29, 0xCC, 0x47, 0xE8,
  37464. 0x0C, 0x86, 0x15, 0xEF, 0x1B, 0x78, 0xDB, 0xB2,
  37465. 0x6A, 0x1A, 0xA7, 0xA6, 0x6E, 0x4D, 0x9A, 0x51,
  37466. 0xC9, 0x72, 0xAC, 0x9C, 0x94, 0xEA, 0xB9, 0x95,
  37467. 0x14, 0xB5, 0xAD, 0xAE, 0x62, 0x51, 0xE8, 0xAA,
  37468. 0x30, 0xA5, 0xE5, 0x87, 0x42, 0x4E, 0x3B, 0x7B,
  37469. 0xCC, 0x42, 0xEB, 0xE7, 0x33, 0x3D, 0x92, 0x10,
  37470. 0x97, 0x26, 0x53, 0xF8, 0x11, 0x8B, 0x83, 0xAB,
  37471. 0xE1, 0xBF, 0x7E, 0x9E, 0xE9, 0xCD, 0xAC, 0x28,
  37472. 0x99, 0x7D, 0x14, 0x4C, 0x34, 0xDE, 0xA6, 0x5B,
  37473. 0x59, 0x51, 0x2C, 0x73, 0x29, 0x27, 0xDB, 0xA8,
  37474. 0x20, 0x7D, 0x56, 0x91, 0x98, 0x47, 0x21, 0xB7,
  37475. 0x27, 0x9A, 0xFC, 0xDD, 0xE0, 0x6A, 0x6B, 0xD2,
  37476. 0x68, 0x0E, 0xBB, 0x9B, 0x2E, 0x3C, 0xFE, 0xE9,
  37477. 0xA6, 0x6D, 0x73, 0xD0, 0xC0, 0xDE, 0xD6, 0x53,
  37478. 0x70, 0x8B, 0x09, 0x0B, 0x82, 0x30, 0x65, 0xF9,
  37479. 0x70, 0x78, 0x49, 0xE3, 0xB3, 0x7D, 0x41, 0x25,
  37480. 0xCA, 0x69, 0x3E, 0x74, 0x2E, 0x02, 0x3F, 0x05,
  37481. 0x8A, 0xDC, 0x95, 0x07, 0x9B, 0xB0, 0x0C, 0x56,
  37482. 0xBE, 0x0D, 0x2F, 0x07, 0x81, 0x82, 0xEF, 0xAB,
  37483. 0x30, 0x72, 0xB0, 0xFD, 0x09, 0x76, 0x7B, 0x8A,
  37484. 0x13, 0xC2, 0x80, 0x5A, 0x75, 0x91, 0xB5, 0xB2,
  37485. 0xE1, 0x24, 0x75, 0xB5, 0xC8, 0x24, 0xDB, 0xEB,
  37486. 0x15, 0x79, 0x30, 0xAB, 0x38, 0x9F, 0x91, 0x5F,
  37487. 0xCC, 0xEC, 0x8F, 0x48, 0x64, 0x7E, 0xE4, 0xB6,
  37488. 0x6A, 0xB6, 0xB5, 0x36, 0xC2, 0x2D, 0xE3, 0xE5,
  37489. 0xEE, 0x4A, 0xBB, 0x42, 0xF8, 0xE0, 0x00, 0x9A,
  37490. 0xF0, 0x45, 0x54, 0xF1, 0x28, 0xAC, 0xA3, 0xCC,
  37491. 0xE4, 0x03, 0xBB, 0x01, 0xFD, 0xB7, 0xB5, 0xE2,
  37492. 0xA7, 0x2B, 0x82, 0x91, 0x1C, 0x1F, 0xD0, 0x65,
  37493. 0x23, 0xFF, 0x90, 0x19, 0x21, 0x41, 0xC6, 0x89,
  37494. 0xEC, 0xCB, 0x0B, 0xE6, 0x1B, 0x4C, 0x6D, 0x77,
  37495. 0x06, 0x29, 0x59, 0x02, 0x18, 0xA4, 0x01, 0x1A,
  37496. 0x68, 0xB8, 0x6F, 0xF5, 0x0D, 0x23, 0x03, 0x9C,
  37497. 0x9B, 0xCD, 0x43, 0x61, 0xF6, 0x98, 0x0A, 0x60,
  37498. 0xEF, 0x88, 0xD1, 0x44, 0x0D, 0x30, 0x4C, 0x5B,
  37499. 0x4B, 0x52, 0xD6, 0xED, 0xC2, 0x91, 0x12, 0xDC,
  37500. 0x3A, 0x8A, 0xF2, 0x85, 0x89, 0xE8, 0xF6, 0x29,
  37501. 0x48, 0xED, 0xB6, 0xBE, 0x76, 0x64, 0x6D, 0x59,
  37502. 0x66, 0x06, 0xB9, 0xE7, 0x05, 0xFE, 0xE3, 0xF1,
  37503. 0x44, 0xA0, 0x7B, 0xC9, 0xED, 0x1D, 0x40, 0x0C
  37504. };
  37505. static const byte msg_65[] = {
  37506. 0x88, 0x5A, 0x0B, 0xDD, 0x8D, 0xE7, 0x4B, 0xC7,
  37507. 0x11, 0x69, 0x0A, 0xA6, 0x14, 0xDD, 0xA5, 0x32,
  37508. 0xF4, 0xD8, 0xC7, 0xEA, 0x2C, 0x27, 0x85, 0x5A,
  37509. 0x57, 0x8E, 0x63, 0x61, 0xCA, 0xAE, 0x2C, 0x0B,
  37510. 0xF7, 0xE7, 0x73, 0xB4, 0x90, 0x0A, 0x32, 0x93,
  37511. 0x12, 0x1A, 0x6E, 0x0D, 0xD6, 0x10, 0x10, 0x7A,
  37512. 0x7A, 0x65, 0xBD, 0x6E, 0x11, 0xF6, 0x19, 0xFC,
  37513. 0x0E, 0x9C, 0xE7, 0xBF, 0x7B, 0x5D, 0xE1, 0x80,
  37514. 0x76, 0xE1, 0xB7, 0x25, 0x57, 0x20, 0x97, 0xB2,
  37515. 0x47, 0xD8, 0xE0, 0x46, 0x24, 0x94, 0xF6, 0x3F,
  37516. 0x4E, 0xDF, 0xBE, 0xAC, 0x2F, 0xA2, 0xEC, 0xAE,
  37517. 0x0C, 0xCA, 0xD4, 0x28, 0xBD, 0x79, 0x6C, 0xF2,
  37518. 0x60, 0x92, 0xA1, 0xCD, 0x50, 0x5F, 0x59, 0x39,
  37519. 0x11, 0xED, 0x10, 0xFD, 0xA4, 0x26, 0xC7, 0xE3,
  37520. 0xC5, 0xA4, 0x39, 0xE8, 0x50, 0x42, 0x13, 0x18,
  37521. 0xAE, 0x07, 0x85, 0xB0, 0x5A, 0xA9, 0x9F, 0x58,
  37522. 0xD6, 0x85, 0x6D, 0xEB, 0x78, 0xBB, 0xE4, 0x88,
  37523. 0xC7, 0x0E, 0xEE, 0x42, 0xBB, 0x9A, 0xB5, 0x92,
  37524. 0x7B, 0x2E, 0xD2, 0x5C, 0xD1, 0x43, 0x77, 0xCD,
  37525. 0x7E, 0x1A, 0x88, 0x34, 0xE8, 0x21, 0x48, 0x00,
  37526. 0x2F, 0xCB, 0x98, 0x5A, 0xB9, 0x43, 0x12, 0x97,
  37527. 0x01, 0x0B, 0x2B, 0xC7, 0x0F, 0x91, 0x32, 0x37,
  37528. 0x3C, 0x6D, 0xD2, 0xA2, 0xA9, 0xCF, 0x24, 0x6F,
  37529. 0xE0, 0x26, 0x2E, 0x8B, 0x53, 0xE6, 0x93, 0xF3,
  37530. 0xD6, 0xFE, 0xD3, 0xED, 0xD1, 0xF2, 0x00, 0x4E,
  37531. 0xD1, 0x7C, 0x2C, 0xF5, 0xB2, 0x57, 0xF4, 0xAD,
  37532. 0xA5, 0xDC, 0x1A, 0x7C, 0x15, 0x1F, 0xFE, 0x03,
  37533. 0xB9, 0x6A, 0x4D, 0xB9, 0x91, 0xE4, 0x13, 0x2D,
  37534. 0x01, 0xDE, 0x1F, 0x03, 0x3E, 0xD8, 0x13, 0x57,
  37535. 0xEA, 0xE7, 0xC1, 0xA8, 0xD2, 0xDD, 0xD9, 0x2D,
  37536. 0xDF, 0xC0, 0x6F, 0x67, 0x13, 0x94, 0xD2, 0xF6,
  37537. 0x02, 0x12, 0xC6, 0xE4, 0x49, 0xEA, 0x35, 0x93,
  37538. 0x24, 0xFE, 0xD3, 0x8C, 0x84, 0xD3, 0x6D, 0x15,
  37539. 0x43, 0x2E, 0x11, 0xE7, 0x15, 0x00, 0x15, 0x80,
  37540. 0x4F, 0x97, 0xA3, 0xC6, 0x77, 0x38, 0x2C, 0xD4,
  37541. 0x6A, 0xA4, 0xD7, 0xAC, 0xEE, 0x56, 0x86, 0xFB,
  37542. 0xCE, 0xD7, 0xA9, 0xE8, 0x5D, 0x29, 0xC4, 0x83,
  37543. 0x86, 0xE6, 0x9F, 0x40, 0x69, 0x3D, 0x9A, 0xDA,
  37544. 0xBE, 0xB4, 0x3B, 0xD0, 0xE5, 0x03, 0x6A, 0xCD,
  37545. 0xE6, 0x31, 0xB5, 0x49, 0x57, 0xF4, 0xFC, 0xE2,
  37546. 0x6F, 0x7A, 0x24, 0xB0, 0xDA, 0xD4, 0x34, 0x8A,
  37547. 0x67, 0x89, 0xCA, 0xE1, 0x06, 0x13, 0x06, 0x20,
  37548. 0xED, 0x2F, 0xA0, 0xEA, 0x38, 0xF5, 0x75, 0xF2,
  37549. 0x87, 0x83, 0xBC, 0x92, 0xB3, 0x2B, 0x0C, 0x51,
  37550. 0xC8, 0xA6, 0x54, 0x6F, 0x5D, 0x88, 0x09, 0x5F,
  37551. 0x9F, 0x73, 0xC6, 0x5B, 0xF6, 0xF2, 0x51, 0xA2,
  37552. 0xC4, 0x69, 0x74, 0x64, 0x45, 0xC5, 0x88, 0xC3,
  37553. 0xEA, 0x81, 0x39, 0xE4, 0x33, 0xD4, 0xFE, 0x2D,
  37554. 0xE4, 0xC0, 0xD3, 0x58, 0xB6, 0xCA, 0x8A, 0x62,
  37555. 0x94, 0xE6, 0xAF, 0xC1, 0xB9, 0x60, 0x74, 0xC0,
  37556. 0x68, 0xEF, 0x67, 0xB1, 0x58, 0xF1, 0x12, 0x9C,
  37557. 0xFE, 0x0A, 0x3A, 0xE7, 0xEB, 0x9D, 0x45, 0x4F,
  37558. 0x35, 0x7F, 0xBB, 0x6A, 0xB3, 0xB9, 0x92, 0x2B,
  37559. 0x1B, 0xCD, 0x55, 0x58, 0x61, 0x87, 0xCD, 0x24,
  37560. 0x69, 0x24, 0x82, 0x78, 0x23, 0x34, 0xAC, 0x9F,
  37561. 0x2B, 0x86, 0x12, 0x48, 0xF6, 0xA5, 0x30, 0xE9,
  37562. 0x3E, 0x11, 0x48, 0x87, 0x84, 0xDD, 0xE5, 0xEA,
  37563. 0x67, 0x8A, 0xE5, 0x05, 0x90, 0x3E, 0x23, 0x10,
  37564. 0x53, 0x30, 0x8C, 0x1B, 0x87, 0x84, 0x60, 0x7E,
  37565. 0x06, 0x3F, 0x48, 0x98, 0xA4, 0xFA, 0xB6, 0x01,
  37566. 0xD3, 0xE6, 0x96, 0x85, 0x97, 0x21, 0x55, 0xF6,
  37567. 0x3F, 0x09, 0xFD, 0x84, 0xB2, 0xB3, 0xDF, 0x74,
  37568. 0x1F, 0xB6, 0x42, 0xAC, 0xA6, 0x03, 0xD0, 0xD5,
  37569. 0x96, 0xE0, 0xA8, 0xDA, 0xD4, 0x24, 0xF4, 0x64,
  37570. 0x0F, 0x98, 0xB9, 0x6F, 0xB2, 0x42, 0xC6, 0x95,
  37571. 0xDC, 0x33, 0x1F, 0x57, 0x59, 0xF7, 0x5E, 0xAF,
  37572. 0x19, 0x1C, 0xBD, 0x98, 0x5E, 0xC5, 0x99, 0x8D,
  37573. 0x56, 0x48, 0xC8, 0x5E, 0xB6, 0x31, 0x29, 0x5F,
  37574. 0x61, 0x56, 0x7C, 0x11, 0x63, 0xF9, 0x90, 0xDC,
  37575. 0x4F, 0xA1, 0x71, 0x40, 0x91, 0x26, 0x1E, 0x5F,
  37576. 0x3E, 0x5F, 0x0B, 0xFE, 0x84, 0x55, 0xBB, 0x8B,
  37577. 0xAA, 0x1D, 0x69, 0x42, 0x1F, 0x15, 0x37, 0x4E,
  37578. 0x73, 0xB0, 0x7E, 0x78, 0x57, 0x9D, 0x0E, 0x25,
  37579. 0x1A, 0x41, 0xEE, 0x1A, 0x50, 0x43, 0xAA, 0xBF,
  37580. 0x8B, 0xE7, 0x73, 0xEE, 0x7F, 0x9D, 0x0F, 0xDF,
  37581. 0xCF, 0xD3, 0xAE, 0x71, 0x1F, 0xAB, 0x1D, 0x3D,
  37582. 0xBC, 0xC2, 0x84, 0x3B, 0xE5, 0xA9, 0x46, 0xB2,
  37583. 0x4D, 0x8B, 0x9B, 0x94, 0x35, 0x8B, 0x5F, 0x59,
  37584. 0x8E, 0x88, 0xED, 0x3D, 0x53, 0xF3, 0x10, 0xF8,
  37585. 0xEC, 0x63, 0x22, 0x9D, 0x4F, 0x5B, 0xB1, 0xB6,
  37586. 0xD5, 0x24, 0xA5, 0xAF, 0x9C, 0x39, 0x47, 0x79,
  37587. 0x25, 0xC7, 0xE2, 0x90, 0x95, 0xFC, 0x43, 0xF1,
  37588. 0x71, 0xFE, 0xCD, 0xD0, 0x61, 0xF3, 0x62, 0x62,
  37589. 0x71, 0x21, 0x75, 0x2C, 0x23, 0x6B, 0x79, 0x2F,
  37590. 0x1B, 0x31, 0x90, 0x79, 0x7C, 0xD0, 0x57, 0x5C,
  37591. 0x58, 0x4F, 0x30, 0xB5, 0x56, 0x81, 0x19, 0x61,
  37592. 0x90, 0x45, 0x09, 0xC9, 0x8B, 0xCD, 0xE8, 0x65,
  37593. 0x9D, 0x22, 0x80, 0xF4, 0x95, 0xA0, 0xC9, 0x55,
  37594. 0x7D, 0x38, 0x11, 0xAF, 0x5E, 0xD4, 0x37, 0x7B,
  37595. 0xC7, 0x59, 0x9E, 0x49, 0x59, 0xFF, 0x85, 0xF2,
  37596. 0x15, 0x0A, 0xCD, 0xEC, 0xC1, 0xF7, 0x67, 0x2D,
  37597. 0xE1, 0xEE, 0x4D, 0xB4, 0x4C, 0x1F, 0xB5, 0xF7,
  37598. 0x99, 0x8A, 0xB5, 0xDB, 0x74, 0x2F, 0x6C, 0x5D,
  37599. 0x32, 0xCB, 0xC0, 0xF2, 0xFB, 0xC9, 0x54, 0xEA,
  37600. 0xD6, 0xCC, 0x13, 0x4B, 0x97, 0x62, 0xDF, 0x33,
  37601. 0x13, 0x86, 0xDE, 0xCA, 0x31, 0x69, 0x47, 0x88,
  37602. 0x4B, 0x9A, 0x13, 0xAD, 0xEA, 0x5C, 0xBE, 0x29,
  37603. 0x56, 0x64, 0x4F, 0xA1, 0x2A, 0x7B, 0xB3, 0xBF,
  37604. 0xB9, 0x7E, 0x1D, 0x93, 0xA7, 0x01, 0x91, 0xAC,
  37605. 0x38, 0xA0, 0x37, 0x32, 0x58, 0xC2, 0xC2, 0x81,
  37606. 0x6D, 0xEA, 0x6E, 0xAF, 0x88, 0x0D, 0x69, 0xF4,
  37607. 0x5F, 0xBA, 0x4C, 0x29, 0x0F, 0x18, 0xD3, 0x4B,
  37608. 0xB8, 0x36, 0x8C, 0xF4, 0xEB, 0xB4, 0x72, 0xBA,
  37609. 0x49, 0x9C, 0xBB, 0x54, 0x50, 0x1E, 0xE3, 0xA2,
  37610. 0x8E, 0x5F, 0xB9, 0xFD, 0xC6, 0x6C, 0xF6, 0x45,
  37611. 0x72, 0x09, 0x47, 0x19, 0xBB, 0xDB, 0x48, 0xF3,
  37612. 0xF4, 0x88, 0x51, 0x3B, 0x65, 0x50, 0xE1, 0x27,
  37613. 0xE8, 0x34, 0x1C, 0x7E, 0x53, 0xDC, 0xFD, 0xA7,
  37614. 0xD4, 0x08, 0x05, 0x58, 0x0B, 0xC7, 0xD3, 0x0A,
  37615. 0x72, 0xF2, 0x44, 0xCC, 0xDB, 0x5A, 0xEF, 0x66,
  37616. 0x1B, 0x0F, 0x30, 0x4E, 0xC5, 0xB7, 0xAB, 0x93,
  37617. 0xB8, 0xC5, 0xC4, 0x9A, 0x77, 0x68, 0x38, 0xB7,
  37618. 0xD5, 0x23, 0x74, 0xAA, 0x41, 0x63, 0x02, 0x24,
  37619. 0xD6, 0x16, 0xF3, 0x10, 0xE4, 0x99, 0xEC, 0xAD,
  37620. 0xCE, 0x93, 0xE7, 0x8B, 0x94, 0xD3, 0xCA, 0x48,
  37621. 0xB3, 0x47, 0xBC, 0x0E, 0xEC, 0xAA, 0x20, 0x66,
  37622. 0x02, 0x29, 0x65, 0xC8, 0x07, 0xBE, 0xF9, 0x02,
  37623. 0x9B, 0xC5, 0x22, 0x8F, 0x00, 0x5E, 0xDB, 0x74,
  37624. 0xD4, 0xB1, 0x44, 0x98, 0xCE, 0x3A, 0xE1, 0x3B,
  37625. 0xEB, 0x7C, 0x69, 0x3B, 0x66, 0x9E, 0xE9, 0xF9,
  37626. 0xA6, 0xF4, 0x6F, 0xC0, 0x0E, 0xC0, 0x5E, 0x13,
  37627. 0x2B, 0xB6, 0xC6, 0x76, 0x0F, 0xB5, 0xC5, 0x1C,
  37628. 0x83, 0x23, 0xAC, 0xD6, 0xA3, 0xC7, 0x5A, 0x72,
  37629. 0xE9, 0x73, 0x89, 0x66, 0xD1, 0x25, 0xB9, 0x61,
  37630. 0x3B, 0x31, 0x45, 0xC6, 0x7B, 0x5E, 0x98, 0x81,
  37631. 0x87, 0xE8, 0x5F, 0x29, 0xAD, 0xCB, 0xAF, 0x74,
  37632. 0xE3, 0x3A, 0x61, 0x1F, 0xFF, 0x25, 0x2A, 0xEB,
  37633. 0xBA, 0xEB, 0x1E, 0xA6, 0x41, 0xE6, 0xFC, 0x8B,
  37634. 0xDF, 0x73, 0x41, 0xBE, 0x2A, 0xA8, 0x57, 0xE4,
  37635. 0x43, 0xAC, 0xFB, 0xCE, 0xB2, 0x15, 0x5D, 0x08,
  37636. 0x1A, 0xCB, 0x4C, 0xCD, 0xB0, 0x98, 0xD5, 0x7C,
  37637. 0xEF, 0x6F, 0x6F, 0xD3, 0x42, 0xDB, 0x2D, 0x83,
  37638. 0xB6, 0x12, 0x3E, 0x0A, 0xD3, 0xC9, 0x3F, 0x30,
  37639. 0x08, 0x11, 0xB8, 0xD5, 0xA1, 0x1A, 0x5A, 0x29,
  37640. 0xBE, 0x60, 0x81, 0x6F, 0x69, 0xB2, 0x9D, 0x1D,
  37641. 0x7E, 0x15, 0x88, 0x69, 0xD8, 0x60, 0xF6, 0xFB,
  37642. 0x82, 0x9D, 0xE8, 0x0D, 0x3E, 0x1B, 0x69, 0x9C,
  37643. 0x3A, 0xB6, 0x80, 0x4E, 0xB6, 0x54, 0x91, 0x78,
  37644. 0xD9, 0x47, 0x33, 0x38, 0xD6, 0xAF, 0x20, 0x9E,
  37645. 0x1F, 0x7D, 0x26, 0x3C, 0x66, 0x7A, 0xE6, 0x89,
  37646. 0x5F, 0x6E, 0x29, 0x33, 0x92, 0x34, 0x71, 0xF1,
  37647. 0x99, 0x58, 0x1F, 0x8A, 0x51, 0xBD, 0x9A, 0xA4,
  37648. 0x52, 0xEE, 0xE4, 0xBF, 0xE9, 0x56, 0x69, 0xAC,
  37649. 0xD0, 0x7B, 0x41, 0xB0, 0x0C, 0x03, 0xF5, 0x5A,
  37650. 0x40, 0xD1, 0x0B, 0x50, 0xF8, 0xE4, 0x67, 0xBD,
  37651. 0x07, 0x1C, 0x8F, 0x40, 0x5C, 0xF1, 0x19, 0x61,
  37652. 0x2D, 0x32, 0x40, 0x5B, 0xD5, 0x27, 0x5A, 0x6B,
  37653. 0xBF, 0x22, 0x17, 0xF9, 0xF1, 0x79, 0x0D, 0x29,
  37654. 0x99, 0x7B, 0x7B, 0x6B, 0x1E, 0xC8, 0xD7, 0x92,
  37655. 0x4A, 0xB9, 0xE6, 0x44, 0xC1, 0x29, 0xCE, 0xE8,
  37656. 0x74, 0x33, 0x29, 0x1A, 0x2C, 0x8E, 0xD6, 0xBC,
  37657. 0x3C, 0x2A, 0x19, 0xD0, 0x76, 0xB1, 0x77, 0xEE,
  37658. 0x60, 0x50, 0x69, 0x2A, 0xDA, 0x8E, 0x95, 0x57,
  37659. 0x4D, 0x6C, 0xE9, 0xAB, 0xE4, 0x97, 0x95, 0xD8,
  37660. 0xF2, 0x8E, 0xAB, 0x69, 0x67, 0x6E, 0x79, 0x03,
  37661. 0xA6, 0x56, 0xFA, 0xB3, 0x20, 0x25, 0xFE, 0x34,
  37662. 0x65, 0xCB, 0xDB, 0x57, 0x01, 0xC1, 0x77, 0x20,
  37663. 0x9D, 0x91, 0x89, 0xA5, 0x91, 0x7C, 0x13, 0x37,
  37664. 0xDE, 0x39, 0xF5, 0x75, 0xE5, 0xDD, 0xB9, 0x3C,
  37665. 0xA7, 0x6B, 0xEB, 0x52, 0xAF, 0x32, 0xE8, 0xD7,
  37666. 0x12, 0x7B, 0x28, 0xF7, 0xCE, 0x73, 0x12, 0xE8,
  37667. 0x03, 0x90, 0x47, 0x21, 0xAB, 0x21, 0x6E, 0x92,
  37668. 0xA8, 0xA9, 0xE6, 0x09, 0xFC, 0x10, 0xAF, 0x8D,
  37669. 0xC2, 0xAA, 0xCA, 0x14, 0xA9, 0x7B, 0xB0, 0xE4,
  37670. 0xB2, 0x34, 0xC7, 0x00, 0x0E, 0xBB, 0xE0, 0xC4,
  37671. 0x42, 0xF1, 0x85, 0x94, 0x6B, 0x7C, 0xE7, 0x72,
  37672. 0x80, 0x95, 0xCD, 0x60, 0x16, 0x9B, 0x0B, 0xD9,
  37673. 0x7B, 0x36, 0xB3, 0xAE, 0x38, 0x55, 0xD9, 0x89,
  37674. 0x25, 0xB2, 0x9D, 0x92, 0x94, 0xEF, 0x27, 0x75,
  37675. 0x09, 0xFC, 0xA4, 0x07, 0xEA, 0x2B, 0xC4, 0x76,
  37676. 0x59, 0x02, 0x6A, 0x82, 0x04, 0xD6, 0x96, 0x4F,
  37677. 0xC6, 0x5B, 0xEF, 0x35, 0x31, 0xE9, 0xC1, 0xE6,
  37678. 0xF9, 0x70, 0xBF, 0x2F, 0xF2, 0x40, 0x75, 0xEA,
  37679. 0x17, 0xD1, 0x36, 0xAD, 0xEA, 0xD2, 0x35, 0x6B,
  37680. 0x6C, 0xE4, 0x98, 0xF9, 0x3C, 0xD2, 0xF9, 0xE5,
  37681. 0xE1, 0x90, 0xD2, 0x09, 0xD9, 0x3E, 0x47, 0x3F,
  37682. 0xAA, 0x8E, 0xD9, 0x20, 0x96, 0x31, 0x5B, 0xF1,
  37683. 0xFC, 0xA6, 0x55, 0xFE, 0xBC, 0x78, 0xE0, 0x99,
  37684. 0x65, 0xC9, 0x74, 0x78, 0x29, 0x6B, 0x75, 0xD3,
  37685. 0x90, 0x56, 0x60, 0x4D, 0x32, 0x71, 0x91, 0x6D,
  37686. 0xCF, 0xF2, 0x25, 0xCB, 0x6B, 0x9A, 0x34, 0xE1,
  37687. 0x5D, 0xC1, 0x64, 0xB2, 0xA6, 0x8A, 0x3B, 0x42,
  37688. 0xDE, 0x05, 0x7A, 0x6B, 0xAC, 0x17, 0x32, 0xCF,
  37689. 0x59, 0x45, 0xBB, 0xCA, 0x12, 0xB8, 0xB3, 0x61,
  37690. 0x59, 0xFB, 0x89, 0xF7, 0xBB, 0xBE, 0x9F, 0xE0,
  37691. 0x34, 0x21, 0x8F, 0x5B, 0x3B, 0xCF, 0x18, 0x4C,
  37692. 0x20, 0x73, 0x06, 0xE6, 0xD2, 0xEA, 0x69, 0x59,
  37693. 0xEA, 0xE0, 0x89, 0x0A, 0x7B, 0x68, 0x02, 0xEC,
  37694. 0x1D, 0xA0, 0x82, 0xBE, 0xD6, 0x5B, 0xB6, 0xE4,
  37695. 0xEB, 0x4D, 0x56, 0x15, 0x70, 0x1C, 0xB0, 0xE3,
  37696. 0x50, 0x36, 0x33, 0x14, 0xA4, 0xD1, 0x01, 0xDB,
  37697. 0xBA, 0x60, 0x53, 0x71, 0xA3, 0x8B, 0x2D, 0x8A,
  37698. 0x37, 0xFF, 0x78, 0xEB, 0xB3, 0x69, 0x82, 0x53,
  37699. 0x88, 0xAA, 0xB7, 0xD3, 0xC6, 0x23, 0xB9, 0x3E,
  37700. 0x51, 0x2D, 0x96, 0xA9, 0xF3, 0x39, 0xEC, 0x96,
  37701. 0x8B, 0x35, 0x27, 0x59, 0xAF, 0x3E, 0x8F, 0xA3,
  37702. 0x21, 0x1C, 0x39, 0x29, 0x5B, 0x01, 0x10, 0xE6,
  37703. 0xDF, 0x26, 0x4E, 0x90, 0x67, 0x8C, 0x11, 0xE2,
  37704. 0xB9, 0x03, 0xAF, 0x32, 0x2E, 0x4F, 0xA7, 0x70,
  37705. 0x28, 0xD3, 0xEC, 0xC4, 0x4F, 0x62, 0x79, 0xD6,
  37706. 0x3B, 0x1E, 0x60, 0xD8, 0x06, 0x72, 0x41, 0x01,
  37707. 0x5F, 0xC4, 0xF8, 0x9B, 0xAA, 0x15, 0x6A, 0x78,
  37708. 0xFA, 0x77, 0xBB, 0x29, 0x14, 0xCA, 0xC2, 0x81,
  37709. 0xF4, 0x40, 0x9C, 0x9C, 0x03, 0x70, 0xAB, 0xD7,
  37710. 0xC1, 0xF8, 0xA5, 0xD1, 0x04, 0x0B, 0x59, 0x75,
  37711. 0x2C, 0xC4, 0xFD, 0xF0, 0xD1, 0x9C, 0xB0, 0xC5,
  37712. 0x6F, 0xEF, 0x34, 0xFA, 0x3A, 0x3B, 0xCE, 0xE1,
  37713. 0xF0, 0x64, 0xE3, 0x60, 0xE8, 0x6D, 0xC5, 0x5D,
  37714. 0xB5, 0xC9, 0x37, 0x5B, 0xDA, 0xDA, 0x67, 0x2E,
  37715. 0x72, 0xF6, 0x64, 0xE3, 0xAC, 0xB2, 0xE6, 0xD8,
  37716. 0xA0, 0x84, 0x09, 0xC8, 0xCD, 0x60, 0xA1, 0xF9,
  37717. 0x53, 0x80, 0xAB, 0x6C, 0x3A, 0xCB, 0x6B, 0x91,
  37718. 0xA8, 0xA9, 0xA3, 0xB7, 0x75, 0x50, 0x49, 0x79,
  37719. 0xB8, 0x02, 0x5A, 0xDB, 0x34, 0x22, 0x61, 0x9B,
  37720. 0xD1, 0x1E, 0x2B, 0x54, 0xFE, 0x6D, 0x07, 0x58,
  37721. 0x81, 0xAC, 0xAC, 0x24, 0x53, 0x20, 0x31, 0xCC,
  37722. 0xD2, 0x99, 0x06, 0x0E, 0x4E, 0xB7, 0xF7, 0xCB,
  37723. 0xD8, 0x08, 0x36, 0xD4, 0xB8, 0x23, 0xA5, 0xFF,
  37724. 0xA4, 0xFE, 0x8C, 0x6B, 0x98, 0x3D, 0x2A, 0xAE,
  37725. 0xB8, 0xF1, 0x6F, 0x6C, 0x1C, 0x22, 0x81, 0xEF,
  37726. 0xD7, 0x13, 0xFF, 0xDA, 0x22, 0x06, 0x9A, 0x5D,
  37727. 0x8A, 0xC4, 0x91, 0x29, 0x1C, 0xBF, 0x49, 0xF1,
  37728. 0x18, 0xC9, 0x46, 0xD5, 0x0F, 0x08, 0xE0, 0xD1,
  37729. 0x73, 0x28, 0x14, 0xE8, 0x15, 0x81, 0x90, 0x6A,
  37730. 0x31, 0x53, 0x94, 0x01, 0x14, 0xBE, 0xC8, 0xEB,
  37731. 0xD4, 0x9C, 0x73, 0x79, 0x0F, 0x9E, 0xD7, 0xCC,
  37732. 0xD9, 0x85, 0xED, 0xAD, 0x8D, 0xB3, 0x42, 0x6B,
  37733. 0x15, 0x13, 0x98, 0xEB, 0xF1, 0x6E, 0xFA, 0xFE,
  37734. 0x3D, 0xA0, 0xC7, 0xF3, 0x8B, 0x22, 0x76, 0x05,
  37735. 0x76, 0xD4, 0x88, 0x52, 0x73, 0xF5, 0xE4, 0x0B,
  37736. 0x14, 0x05, 0x57, 0x10, 0x7F, 0xCE, 0x0B, 0xF8,
  37737. 0x46, 0x1F, 0x24, 0x8B, 0xC4, 0x3F, 0xBF, 0x5C,
  37738. 0xEE, 0xE7, 0x6E, 0xF3, 0xA9, 0xEB, 0xD2, 0x30,
  37739. 0x95, 0x6C, 0x7B, 0x98, 0xAC, 0x89, 0x8A, 0x39,
  37740. 0x9E, 0x5C, 0x2A, 0xB0, 0xCB, 0xE9, 0xE5, 0xAB,
  37741. 0x94, 0x71, 0xDF, 0x5E, 0x53, 0x0C, 0x72, 0xF2,
  37742. 0x6C, 0x34, 0xDB, 0xFE, 0x2F, 0x83, 0x68, 0x3E,
  37743. 0xB6, 0x22, 0xF9, 0x64, 0x7A, 0xA0, 0x6A, 0x26,
  37744. 0x7D, 0x78, 0x97, 0x36, 0x31, 0x2C, 0x90, 0xC9,
  37745. 0xE5, 0x9D, 0x77, 0x12, 0x2A, 0x88, 0x53, 0x8F,
  37746. 0xD0, 0xF5, 0x39, 0x16, 0xAF, 0x08, 0xB2, 0x36,
  37747. 0x93, 0x5C, 0xDC, 0x5B, 0xB3, 0xCB, 0x49, 0x0C,
  37748. 0x83, 0x09, 0xE6, 0xA7, 0x9B, 0x43, 0xE7, 0xA5,
  37749. 0x4A, 0x8A, 0x07, 0xE1, 0xBA, 0xFB, 0x9B, 0x93,
  37750. 0x7E, 0xAC, 0x2F, 0xC3, 0xAC, 0xED, 0x30, 0x64,
  37751. 0x1F, 0x33, 0x79, 0x19, 0xD2, 0xDB, 0x54, 0xEC,
  37752. 0x7F, 0x32, 0x0E, 0xC5, 0x1C, 0xD1, 0x3C, 0x00,
  37753. 0xB9, 0xE6, 0x03, 0xDF, 0x6D, 0xD2, 0x69, 0x0C,
  37754. 0x75, 0xAF, 0x37, 0x07, 0xB7, 0xC9, 0x3E, 0x91,
  37755. 0xCF, 0x02, 0x78, 0xD7, 0x43, 0xA1, 0x8B, 0x4E,
  37756. 0x69, 0x74, 0xB4, 0x24, 0x08, 0x10, 0x42, 0xB5,
  37757. 0xB4, 0xE7, 0x8C, 0xEB, 0x7F, 0xFF, 0x67, 0x98,
  37758. 0x0B, 0xBC, 0xBA, 0x5E, 0x29, 0xBE, 0x61, 0x33,
  37759. 0x56, 0x16, 0xD6, 0x5E, 0x86, 0xF0, 0xE7, 0x46,
  37760. 0xD1, 0x83, 0xDF, 0xD4, 0x6B, 0x75, 0xC9, 0x30,
  37761. 0x0D, 0x60, 0xC5, 0x19, 0xFD, 0x95, 0xA8, 0xA6,
  37762. 0x61, 0xFF, 0xC8, 0x2A, 0xE7, 0x5D, 0xD1, 0x49,
  37763. 0x49, 0x1F, 0x99, 0xD1, 0x41, 0x4F, 0x15, 0x79,
  37764. 0x00, 0x8A, 0x80, 0x27, 0xA6, 0xC9, 0x98, 0xD3,
  37765. 0xE7, 0xA2, 0xBB, 0xFA, 0x07, 0xAB, 0x53, 0xEF,
  37766. 0xE8, 0x17, 0xAE, 0x9C, 0x6A, 0xE8, 0xD0, 0x52,
  37767. 0xAA, 0x85, 0x9D, 0x03, 0x48, 0xB0, 0xD2, 0xC8,
  37768. 0x5B, 0xCC, 0xC4, 0x50, 0x84, 0x90, 0xBE, 0x0F,
  37769. 0x9B, 0x32, 0x13, 0xB8, 0xAF, 0x7C, 0xCE, 0xE7,
  37770. 0x22, 0xE2, 0x82, 0x13, 0x18, 0x71, 0x46, 0xC5,
  37771. 0xDA, 0x05, 0xB7, 0x65, 0xD8, 0x33, 0x06, 0xFA,
  37772. 0x5A, 0x6B, 0x76, 0xD6, 0x92, 0x76, 0xD1, 0x6A,
  37773. 0x2B, 0xC6, 0x0D, 0xB1, 0xAD, 0xAB, 0x57, 0x62,
  37774. 0xEA, 0x76, 0x37, 0x4E, 0xAB, 0x2D, 0x34, 0xD2,
  37775. 0xA3, 0x57, 0xC7, 0x56, 0xFB, 0xEA, 0xD6, 0xA9,
  37776. 0xE3, 0xC1, 0x63, 0x07, 0xDE, 0xB9, 0x5E, 0x5A,
  37777. 0x30, 0x2E, 0x41, 0x4D, 0x43, 0xE9, 0x1C, 0xA1,
  37778. 0x5B, 0xB2, 0x4F, 0xAF, 0xDC, 0xE9, 0xBB, 0xBE,
  37779. 0x73, 0x55, 0x90, 0xF0, 0xD0, 0x02, 0x98, 0x6D,
  37780. 0x13, 0x50, 0x9A, 0xCA, 0x4C, 0xB3, 0x15, 0x3A,
  37781. 0x26, 0x14, 0x38, 0x67, 0xEB, 0xA7, 0x27, 0x33,
  37782. 0x48, 0x97, 0x58, 0x94, 0x57, 0xEA, 0xF9, 0x7E,
  37783. 0x8B, 0xB0, 0xBB, 0xF3, 0xF4, 0x84, 0x6E, 0x69,
  37784. 0x95, 0x2C, 0xF4, 0x6B, 0x1C, 0x65, 0x39, 0xB4,
  37785. 0x46, 0xA7, 0x99, 0xD6, 0x68, 0x47, 0x6E, 0x2E,
  37786. 0x49, 0x84, 0x75, 0x3E, 0x6C, 0x2E, 0x9A, 0x08,
  37787. 0xBC, 0xB7, 0x2F, 0x86, 0x68, 0x5C, 0xE1, 0xBF,
  37788. 0xEA, 0xA1, 0xAF, 0x59, 0xD6, 0x71, 0xB7, 0xBD,
  37789. 0xD6, 0xC5, 0xC2, 0xF2, 0xF3, 0xB5, 0x36, 0xBB,
  37790. 0x36, 0x23, 0x4F, 0xD6, 0x44, 0x59, 0x0A, 0x44,
  37791. 0x86, 0xCA, 0xDC, 0xD4, 0x22, 0x0F, 0x79, 0x09,
  37792. 0x99, 0x8C, 0x8C, 0x9E, 0x03, 0xA4, 0x51, 0x99,
  37793. 0x5A, 0xB9, 0x97, 0x76, 0x73, 0x20, 0xD3, 0x98,
  37794. 0x8C, 0x52, 0x96, 0xE1, 0x65, 0x7B, 0x4C, 0x77,
  37795. 0x40, 0xB2, 0xFE, 0x27, 0x0A, 0x11, 0x76, 0x6E,
  37796. 0x3B, 0x35, 0x12, 0xC6, 0x4E, 0xC2, 0x0E, 0xCC,
  37797. 0x04, 0xB5, 0x51, 0x91, 0xD0, 0x4A, 0xF7, 0x84,
  37798. 0xF2, 0xE7, 0xE5, 0x99, 0x7E, 0xB5, 0x3E, 0xAC,
  37799. 0x53, 0xDB, 0x61, 0x11, 0x71, 0x56, 0x4E, 0xAB,
  37800. 0x4A, 0x68, 0xC1, 0x6A, 0xA5, 0xC5, 0x7F, 0x72,
  37801. 0xEB, 0x14, 0x97, 0xA4, 0x27, 0xA0, 0x53, 0xA1,
  37802. 0xC4, 0x70, 0x7D, 0x58, 0xBD, 0xC1, 0xD7, 0xFD,
  37803. 0x9F, 0xB8, 0x8C, 0xCE, 0x34, 0xF9, 0xE1, 0x9C,
  37804. 0x59, 0x79, 0x31, 0x24, 0xEC, 0xBB, 0xF5, 0x6F,
  37805. 0x3F, 0xA3, 0x5A, 0x55, 0xB3, 0xDE, 0x64, 0xDF,
  37806. 0xA9, 0x95, 0x0B, 0x53, 0xF2, 0xA7, 0x25, 0x7B,
  37807. 0x8C, 0xAD, 0x25, 0x9A, 0x35, 0xBF, 0x15, 0x46,
  37808. 0x69, 0x4A, 0x83, 0x8C, 0x80, 0xFC, 0x37, 0xD0,
  37809. 0xC3, 0x6F, 0x00, 0xE2, 0x3C, 0x63, 0xAB, 0xC5,
  37810. 0x53, 0xC1, 0x8D, 0x4A, 0x40, 0x4B, 0xE6, 0xDC,
  37811. 0x05, 0xB1, 0x20, 0x23, 0x8B, 0xB8, 0xDF, 0x40,
  37812. 0x86, 0x97, 0xB9, 0x5E, 0xA4, 0xB7, 0xA1, 0x37,
  37813. 0xE0, 0x4B, 0x9E, 0xD9, 0x84, 0x2B, 0x2D, 0xAD,
  37814. 0xD1, 0xB1, 0x52, 0x15, 0x00, 0x9B, 0xDD, 0x23,
  37815. 0xA9, 0x27, 0x44, 0x21, 0x33, 0x17, 0x1C, 0x61,
  37816. 0x49, 0x84, 0x0D, 0x6A, 0x11, 0x7C, 0x77, 0xA5,
  37817. 0xD6, 0x8E, 0xE6, 0x1D, 0x6E, 0x90, 0x04, 0x4A,
  37818. 0xD3, 0x54, 0x3A, 0xA7, 0x1A, 0x28, 0xC5, 0x94,
  37819. 0x01, 0xCA, 0xDB, 0x1B, 0x5D, 0x78, 0xC5, 0xC6,
  37820. 0x69, 0x0D, 0x69, 0x88, 0x75, 0x00, 0x02, 0x0B,
  37821. 0x59, 0x6C, 0x3E, 0xC5, 0x30, 0xDF, 0xEE, 0x85,
  37822. 0x43, 0xA2, 0x9A, 0xF9, 0xDD, 0x85, 0x6E, 0xB3,
  37823. 0x0D, 0x83, 0x6A, 0x13, 0x88, 0xD0, 0x12, 0x15,
  37824. 0x53, 0x16, 0xFC, 0x5C, 0x15, 0x47, 0xEC, 0x6D,
  37825. 0x4D, 0x18, 0x2D, 0x88, 0xDB, 0xD2, 0x17, 0x6C,
  37826. 0xDE, 0x64, 0xEC, 0x70, 0x8D, 0x19, 0xDC, 0x66,
  37827. 0x69, 0x7F, 0xCF, 0x61, 0x6E, 0x4F, 0x23, 0x86,
  37828. 0xF5, 0x1A, 0x98, 0x47, 0x4B, 0xCC, 0xE9, 0x2F,
  37829. 0x12, 0x28, 0x12, 0xB9, 0xEB, 0xD8, 0x32, 0xDC,
  37830. 0xE4, 0xD8, 0x63, 0xAC, 0x56, 0x08, 0x2F, 0xEC,
  37831. 0x5E, 0x47, 0x29, 0xFF, 0x76, 0xFE, 0x95, 0x60,
  37832. 0xD2, 0x19, 0x61, 0x0E, 0xAF, 0xFC, 0x44, 0x42,
  37833. 0x11, 0x42, 0x79, 0xBC, 0x06, 0x3A, 0xAD, 0x93,
  37834. 0x7E, 0x46, 0x60, 0x03, 0xB0, 0xF5, 0x9F, 0x57,
  37835. 0x28, 0x48, 0x44, 0x8F, 0x0E, 0xFA, 0x72, 0x8C,
  37836. 0xE4, 0x18, 0xF4, 0x99, 0x6B, 0xB1, 0x23, 0x45,
  37837. 0xDC, 0x13, 0xA2, 0xF6, 0x5F, 0x57, 0x35, 0xA2,
  37838. 0xD7, 0x38, 0xF9, 0xE9, 0x8A, 0x7A, 0x79, 0xC6,
  37839. 0xB2, 0xCD, 0xBF, 0xD3, 0x41, 0x21, 0x56, 0xB3,
  37840. 0x39, 0xD9, 0x14, 0x3B, 0xDD, 0x85, 0xCB, 0x78,
  37841. 0x2F, 0xEB, 0x7E, 0x29, 0xBC, 0x52, 0x24, 0xE7,
  37842. 0x1B, 0x85, 0xB1, 0x65, 0xAE, 0xAB, 0x65, 0xF9,
  37843. 0x54, 0xD2, 0x1F, 0x37, 0x29, 0x52, 0x30, 0x5B,
  37844. 0x3D, 0x5F, 0x48, 0x84, 0x3F, 0x51, 0x27, 0x88,
  37845. 0x9D, 0xA7, 0x94, 0xF0, 0x73, 0xCD, 0x98, 0xD2,
  37846. 0x05, 0xE8, 0x25, 0x71, 0x7C, 0x93, 0x13, 0x82,
  37847. 0x5D, 0x53, 0x8D, 0x05, 0x0E, 0x69, 0x20, 0xC4,
  37848. 0xDB, 0xF2, 0xF6, 0x55, 0x24, 0x29, 0xD0, 0x41,
  37849. 0xF6, 0x2D, 0xF8, 0xC1, 0x2E, 0xC2, 0x4D, 0xE1,
  37850. 0xD7, 0x2D, 0xA0, 0x49, 0x16, 0x0B, 0x4D, 0x34,
  37851. 0xB5, 0x6D, 0xAE, 0x10, 0x93, 0x1E, 0xB6, 0x95,
  37852. 0x69, 0xC2, 0xB3, 0xC0, 0xAF, 0x6F, 0xFF, 0xA5,
  37853. 0x32, 0x3C, 0x7D, 0xC9, 0xC7, 0xC8, 0xEF, 0x0C,
  37854. 0x64, 0x20, 0x23, 0xC4, 0xFE, 0x89, 0x87, 0x8E,
  37855. 0xB3, 0xA6, 0xC5, 0x24, 0xCF, 0x03, 0x7E, 0x74,
  37856. 0xF7, 0xBF, 0x89, 0x1E, 0xCF, 0xB1, 0x02, 0xFA,
  37857. 0xF2, 0x9F, 0xD3, 0x9D, 0x99, 0x00, 0xDA, 0x7A,
  37858. 0x92, 0x7D, 0x13, 0x11, 0x92, 0xAD, 0x55, 0xF2,
  37859. 0xE1, 0x82, 0x72, 0xB1, 0x6A, 0xF1, 0x45, 0x05,
  37860. 0xDA, 0x17, 0xC9, 0xA1, 0x42, 0x82, 0x89, 0x77,
  37861. 0x31, 0xB6, 0x72, 0x54, 0x7C, 0x68, 0x10, 0x25,
  37862. 0x57, 0x30, 0x16, 0x15, 0x08, 0x58, 0x8B, 0xC1,
  37863. 0x61, 0xCB, 0xA0, 0x58, 0x29, 0x33, 0xB1, 0x64,
  37864. 0xF4, 0x4F, 0x06, 0xAA, 0x25, 0x31, 0xAA, 0xA8,
  37865. 0x92, 0x1C, 0x69, 0x1E, 0x6E, 0xB6, 0xBE, 0x81,
  37866. 0xDA, 0x9B, 0xE5, 0x1C, 0x56, 0x39, 0x55, 0xE0,
  37867. 0xC1, 0xEF, 0xD3, 0xED, 0x2A, 0x1C, 0x94, 0x9B,
  37868. 0xD4, 0xE0, 0x0B, 0x3A, 0xE9, 0xEB, 0xC1, 0x3C,
  37869. 0x4C, 0x6C, 0x4E, 0x5E, 0x39, 0x4C, 0xB0, 0x34,
  37870. 0xB9, 0xCB, 0x75, 0xBE, 0xCE, 0x86, 0x44, 0xFF,
  37871. 0x89, 0xEF, 0x95, 0xE7, 0x6E, 0xF7, 0x15, 0xE1,
  37872. 0x7A, 0xA2, 0x6B, 0x1F, 0xEB, 0x77, 0x4C, 0x50,
  37873. 0x59, 0xB3, 0xA3, 0x9A, 0x38, 0xDF, 0xD0, 0x57,
  37874. 0xD6, 0x41, 0xE4, 0x3F, 0xFE, 0x0F, 0x3E, 0x40,
  37875. 0xFF, 0xF6, 0xB2, 0x36, 0x3C, 0x1B, 0xF0, 0xEF,
  37876. 0x07, 0x87, 0x3D, 0x09, 0xA4, 0x87, 0x76, 0x9D,
  37877. 0x0A, 0x73, 0xCD, 0x0C, 0xC6, 0x44, 0xF5, 0x3C,
  37878. 0x25, 0xD2, 0x02, 0x5E, 0xE7, 0x1C, 0x69, 0xB7,
  37879. 0xAC, 0x0F, 0xA6, 0x61, 0x15, 0x57, 0xC4, 0x27,
  37880. 0xC0, 0x69, 0xDF, 0x2E, 0x1B, 0xF6, 0x29, 0xD9,
  37881. 0xA0, 0xCB, 0x5C, 0x67, 0xC7, 0xEA, 0x4F, 0xA6,
  37882. 0x58, 0xC7, 0x8D, 0x00, 0x42, 0xB0, 0x59, 0xE6,
  37883. 0xB6, 0x58, 0xFF, 0xCE, 0x60, 0x16, 0x69, 0x67,
  37884. 0xDB, 0x94, 0xF7, 0x16, 0xEB, 0x4D, 0x04, 0xB3,
  37885. 0xD2, 0x45, 0x0F, 0x40, 0x03, 0x1F, 0x10, 0xAC,
  37886. 0xDD, 0x07, 0x77, 0x7F, 0xBE, 0x9F, 0xBB, 0xB7,
  37887. 0x7F, 0xCB, 0x7C, 0x1F, 0xA9, 0xFC, 0x1E, 0xAF,
  37888. 0x0C, 0x5F, 0x86, 0xD7, 0x96, 0x2D, 0xAE, 0xD0,
  37889. 0x47, 0x4B, 0xA0, 0xFE, 0x68, 0xD9, 0xB2, 0x32,
  37890. 0x77, 0xA9, 0xCA, 0x7F, 0xC6, 0x76, 0xC6, 0x61,
  37891. 0x6B, 0x8E, 0x43, 0x9A, 0x1D, 0x4B, 0xFF, 0x72,
  37892. 0x43, 0x78, 0x19, 0xB5, 0x51, 0x87, 0x56, 0xA7,
  37893. 0x87, 0x3E, 0xF5, 0x84, 0x01, 0x26, 0x46, 0xC3,
  37894. 0x65, 0x9A, 0x6B, 0xA8, 0x6E, 0x62, 0x27, 0x26,
  37895. 0x14, 0xD8, 0x5E, 0xEC, 0xD5, 0x35, 0x0E, 0x3C,
  37896. 0xD0, 0xA1, 0x25, 0xAE, 0x9C, 0x17, 0xCC, 0xE2,
  37897. 0x52, 0x39, 0xE1, 0xEE, 0x9C, 0xDB, 0x39, 0xCA,
  37898. 0x7B, 0x18, 0xCF, 0x2C, 0x88, 0xCF, 0x14, 0x68,
  37899. 0x26, 0xB6, 0xCC, 0x1E, 0x6A, 0xA8, 0xE1, 0x69,
  37900. 0x2C, 0x91, 0x5F, 0x3B, 0xF1, 0xC1, 0xDB, 0x34,
  37901. 0xC6, 0xF3, 0x78, 0x83, 0xCB, 0x4E, 0xDC, 0xE0,
  37902. 0xF7, 0xC9, 0x95, 0xB6, 0x9E, 0x3A, 0xCE, 0x30,
  37903. 0xDC, 0x16, 0x6F, 0x78, 0x4C, 0x93, 0xD6, 0xCB,
  37904. 0xBC, 0xAC, 0x3C, 0x79, 0xBC, 0x31, 0x93, 0x10,
  37905. 0xCE, 0x6E, 0x66, 0x57, 0x00, 0xF1, 0x7F, 0x96,
  37906. 0x2F, 0x18, 0xB2, 0x40, 0x73, 0x9D, 0x15, 0x69,
  37907. 0x0B, 0x1B, 0x6C, 0x85, 0xD1, 0xAA, 0xA3, 0x2D,
  37908. 0x4A, 0x79, 0x74, 0x4A, 0xE5, 0x0C, 0xF9, 0xA9,
  37909. 0x0A, 0x09, 0x54, 0xB4, 0xA4, 0xD9, 0x4C, 0x49,
  37910. 0x9B, 0x41, 0x23, 0xEF, 0xC0, 0x20, 0x44, 0x31,
  37911. 0xF7, 0x22, 0x85, 0xB5, 0xDA, 0x9E, 0x19, 0x22,
  37912. 0x23, 0x0A, 0x30, 0x4D, 0x3A, 0x1B, 0xD8, 0x52,
  37913. 0x08, 0x72, 0x61, 0xB7, 0xCF, 0x0D, 0x8B, 0x90,
  37914. 0xD1, 0x46, 0x23, 0xEB, 0xCD, 0xC6, 0x38, 0x7B,
  37915. 0xC6, 0xAF, 0x65, 0xBE, 0x5F, 0x01, 0x1B, 0x6B,
  37916. 0xC1, 0x23, 0xC1, 0x30, 0x6A, 0x1E, 0x8F, 0xBF,
  37917. 0x2D, 0xF0, 0xB6, 0xF8, 0x9B, 0x0A, 0xE0, 0x5D,
  37918. 0xE0, 0xE4, 0xB7, 0xF5, 0x0A, 0xDA, 0x46, 0xE5,
  37919. 0x3A, 0x9B, 0x6B, 0xCA, 0xDA, 0x06, 0x43, 0xBE,
  37920. 0x6B, 0xFD, 0xC2, 0xB0, 0x6A, 0x6C, 0x75, 0x88,
  37921. 0x3C, 0x2D, 0xC6, 0x13, 0xAC, 0x72, 0x16, 0x31,
  37922. 0x7A, 0x40, 0xC4, 0xA2, 0xC0, 0x86, 0x69, 0x83,
  37923. 0xD3, 0x2C, 0x9C, 0xE0, 0xA6, 0xCC, 0xED, 0xF4,
  37924. 0x03, 0x62, 0x6B, 0xB2, 0x3B, 0x5B, 0x9D, 0xA5,
  37925. 0x86, 0x77, 0x7C, 0x73, 0x5E, 0x19, 0x11, 0xD7,
  37926. 0x7B, 0x11, 0x96, 0xC8, 0xFA, 0x47, 0x21, 0xD6,
  37927. 0xB0, 0xFE, 0x0B, 0x08, 0x11, 0xFC, 0x00, 0xB9,
  37928. 0xA1, 0x24, 0x2C, 0xBD, 0x4A, 0x92, 0x43, 0x10,
  37929. 0x08, 0xBE, 0xE9, 0xE1, 0x5D, 0x19, 0x82, 0xDE,
  37930. 0x34, 0xAE, 0xDC, 0xA6, 0x85, 0x8F, 0x19, 0x30,
  37931. 0x20, 0xB6, 0x44, 0x7F, 0x6B, 0xA6, 0x63, 0x70,
  37932. 0x59, 0xDA, 0x8D, 0xE0, 0xF8, 0x46, 0x86, 0x57,
  37933. 0xB8, 0x1C, 0x57, 0x13, 0x78, 0x41, 0x8C, 0xF5,
  37934. 0x7D, 0x77, 0xAE, 0x75, 0x6C, 0x59, 0x93, 0x2E,
  37935. 0x05, 0x25, 0x03, 0xD1, 0xEA, 0xFB, 0x2D, 0x60,
  37936. 0xD2, 0x61, 0x23, 0xEA, 0x0E, 0xFF, 0x55, 0xE3,
  37937. 0x24, 0x49, 0x00, 0x19, 0xBD, 0x1E, 0x56, 0x24,
  37938. 0x87, 0x2F, 0x7B, 0x98, 0x07, 0x36, 0xD2, 0x7C,
  37939. 0xC5, 0x9B, 0xE0, 0x4E, 0x29, 0xAB, 0xA1, 0xB8,
  37940. 0x35, 0x15, 0x31, 0xCE, 0x65, 0x14, 0x24, 0xF8,
  37941. 0x10, 0xB5, 0xAB, 0x3E, 0xD5, 0x58, 0xCA, 0xE5,
  37942. 0x73, 0x2D, 0x7C, 0x8B, 0xB4, 0x62, 0x75, 0x03,
  37943. 0x30, 0x89, 0xFE, 0x32, 0xF8, 0x65, 0x99, 0xD0,
  37944. 0x88, 0xD5, 0x72, 0x88, 0x03, 0xC9, 0x51, 0x03,
  37945. 0xBA, 0x2F, 0xFB, 0x7C, 0x39, 0x02, 0x05, 0xC4,
  37946. 0xCE, 0xD8, 0xB3, 0xC2, 0x7B, 0x29, 0x8E, 0xA7,
  37947. 0x9D, 0x35, 0x97, 0xB7, 0x17, 0xDE, 0x28, 0x0B,
  37948. 0x32, 0xE5, 0x41, 0xDA, 0x1D, 0x98, 0xBD, 0x27,
  37949. 0xEF, 0xF7, 0xB4, 0x43, 0x09, 0x13, 0x39, 0xC7,
  37950. 0x40, 0x16, 0x11, 0x20, 0x71, 0xCB, 0xB6, 0xC9,
  37951. 0xB0, 0x8F, 0x20, 0xC1, 0xF0, 0x40, 0xFB, 0x6E,
  37952. 0x73, 0x04, 0x8F, 0x73, 0xCA, 0x45, 0xDB, 0xE0,
  37953. 0xF9, 0x25, 0x8D, 0x32, 0xF2, 0x3E, 0x36, 0xBE,
  37954. 0xF7, 0x88, 0xF8, 0x13, 0x4D, 0x9B, 0x10, 0xC2,
  37955. 0x58, 0x0B, 0x20, 0xF8, 0x78, 0xB6, 0x4C, 0x7D,
  37956. 0x2A, 0xA6, 0x81, 0x40, 0xD1, 0x30, 0x50, 0x38,
  37957. 0x2A, 0x5F, 0xBC, 0x81, 0x8E, 0x0F, 0xD4, 0xD0,
  37958. 0x87, 0x99, 0x78, 0x3D, 0xBE, 0x25, 0x15, 0xF4,
  37959. 0x45, 0x61, 0xA3, 0x1A, 0x7D, 0x05, 0x3F, 0xB5,
  37960. 0xA6, 0x1C, 0x41, 0xC6, 0x0E, 0xBE, 0x57, 0x6F,
  37961. 0xC5, 0xB6, 0x38, 0x63, 0x90, 0x55, 0x23, 0xFC,
  37962. 0x26, 0x9E, 0xFD, 0xB8, 0x6C, 0xF2, 0x99, 0x6B,
  37963. 0x6D, 0x90, 0xFE, 0x28, 0xA0, 0x16, 0xEE, 0x63,
  37964. 0xC2, 0x4C, 0xD6, 0xB2, 0x0C, 0xFA, 0x6E, 0x85,
  37965. 0x51, 0xE4, 0x2F, 0x57, 0x91, 0x82, 0x84, 0x43,
  37966. 0x8A, 0x44, 0x31, 0x6C, 0x68, 0x02, 0x01, 0x7C,
  37967. 0xCE, 0x4D, 0xC0, 0x7C, 0x43, 0xA9, 0x54, 0xF5,
  37968. 0x0E, 0xCA, 0xE6, 0x15, 0x98, 0xAE, 0x41, 0x57,
  37969. 0x0A, 0x66, 0xBA, 0x6D, 0x6E, 0x68, 0xB9, 0x2E,
  37970. 0x0D, 0x42, 0xD2, 0xF5, 0x0B, 0xFC, 0x2D, 0xA8,
  37971. 0x61, 0x6E, 0x60, 0x4E, 0x51, 0x78, 0xEB, 0x0C,
  37972. 0x52, 0x9E, 0xC0, 0x4A, 0xB0, 0x92, 0x85, 0x5C,
  37973. 0x3A, 0x3D, 0x69, 0x95, 0xAB, 0x62, 0xEB, 0x2F,
  37974. 0x9B, 0x12, 0xF5, 0x2E, 0xB5, 0xA6, 0x93, 0xCE,
  37975. 0x14, 0x97, 0xA7, 0x1E, 0x0A, 0x7B, 0x94, 0x74,
  37976. 0xFB, 0x65, 0xD0, 0x5A, 0x97, 0x55, 0x40, 0x02,
  37977. 0x71, 0x87, 0x9C, 0x9F, 0xCB, 0x41, 0x3F, 0x08,
  37978. 0x8D, 0x6A, 0xCA, 0xE6, 0xEC, 0xE6, 0x71, 0x22,
  37979. 0xF8, 0x58, 0x9F, 0xF1, 0x94, 0xF6, 0xE4, 0xD6,
  37980. 0xDC, 0x35, 0xD7, 0xEB, 0x6B, 0x78, 0x99, 0x66,
  37981. 0xF9, 0xE2, 0x15, 0x27, 0xC9, 0x8C, 0x27, 0xB4,
  37982. 0x89, 0x3C, 0x15, 0xEE, 0x52, 0x71, 0xA9, 0xD2,
  37983. 0x50, 0x3C, 0xD2, 0x31, 0xBB, 0x3A, 0xE5, 0x87,
  37984. 0xAF, 0x65, 0x2B, 0xF2, 0xF5, 0xC9, 0x44, 0xA2,
  37985. 0x59, 0x1C, 0x57, 0x96, 0xB9, 0xC2, 0x5E, 0xCB,
  37986. 0x8A, 0x5B, 0x2B, 0x7A, 0x7E, 0x93, 0x3C, 0x08,
  37987. 0x27, 0xCD, 0xB4, 0xB0, 0x1B, 0xF3, 0x82, 0x50,
  37988. 0x78, 0xCF, 0xEA, 0x28, 0x57, 0xB1, 0x0F, 0xB4,
  37989. 0xB6, 0x93, 0x82, 0x8E, 0x7A, 0xD1, 0x9F, 0x04,
  37990. 0xEC, 0xEE, 0x24, 0x3D, 0x8A, 0x5E, 0x56, 0x99,
  37991. 0x8D, 0x83, 0xA4, 0x05, 0x7D, 0xFB, 0x36, 0xDB,
  37992. 0xAB, 0xD1, 0x67, 0x59, 0xC7, 0x4A, 0xB9, 0xAF,
  37993. 0x99, 0xB6, 0xD8, 0xD4, 0x2C, 0xCA, 0x8C, 0xCC,
  37994. 0xD2, 0x32, 0xAB, 0x51, 0xCE, 0x2D, 0x22, 0xE0,
  37995. 0x29, 0xB1, 0x73, 0x10, 0x60, 0xA8, 0x6B, 0x8F,
  37996. 0x68, 0xAF, 0x58, 0x06, 0x9D, 0x72, 0x36, 0x98,
  37997. 0x3F, 0xF3, 0x6B, 0xAD, 0x3E, 0x7F, 0x4A, 0x00,
  37998. 0x94, 0x04, 0xAE, 0xE9, 0x8A, 0x9E, 0x8A, 0x03,
  37999. 0xD8, 0x04, 0xCC, 0xFE, 0xE3, 0xF8, 0xA2, 0x04,
  38000. 0x64, 0x17, 0x54, 0x77, 0xCA, 0x20, 0xD0, 0x80,
  38001. 0x1B, 0x36, 0xEF, 0x59, 0x31, 0xFA, 0xE4, 0xF5,
  38002. 0xAF, 0x56, 0x09, 0x02, 0xAD, 0xCF, 0xA6, 0xBC,
  38003. 0x26, 0x23, 0x27, 0x6D, 0xF3, 0x52, 0xCE, 0x2F,
  38004. 0x4C, 0x9C, 0xA8, 0x23, 0x75, 0xFA, 0x56, 0x9E,
  38005. 0x07, 0x5B, 0xB9, 0x30, 0x5A, 0xB1, 0x27, 0xFF,
  38006. 0x72, 0xBF, 0x50, 0xB1, 0x27, 0xEF, 0xA1, 0x0C,
  38007. 0x3A, 0xC9, 0x72, 0x21, 0xBE, 0xD8, 0xDC, 0xD5,
  38008. 0x66, 0x4A, 0x0A, 0x58, 0xFA, 0x57, 0xB4, 0x00,
  38009. 0x07, 0x31, 0xF2, 0x4E, 0xDC, 0xE0, 0x86, 0x99,
  38010. 0x45, 0xE5, 0x45, 0xCF, 0x27, 0x35, 0x79, 0x57,
  38011. 0xF5, 0xA2, 0x7A, 0x29, 0xFA, 0x5E, 0xCF, 0xF9,
  38012. 0xA9, 0x96, 0x11, 0xE1, 0x4A, 0x6C, 0xE5, 0xB8,
  38013. 0x8E, 0x78, 0xE6, 0xA1, 0x46, 0x97, 0xAE, 0xB4,
  38014. 0xF3, 0x6D, 0x7F, 0x8E, 0xD1, 0x86, 0x6B, 0x78,
  38015. 0x2B, 0x55, 0xC5, 0xDF, 0x0F, 0x43, 0x78, 0xED,
  38016. 0xD2, 0x38, 0xE5, 0x8B, 0x94, 0x7A, 0x06, 0xC5,
  38017. 0x73, 0x17, 0x55, 0x93, 0xAD, 0xA5, 0xAC, 0xBA,
  38018. 0x81, 0x8A, 0x6D, 0x73, 0x4B, 0xA1, 0x32, 0x8F,
  38019. 0x21, 0xA6, 0x5B, 0x51, 0x31, 0x58, 0xD0, 0xE4,
  38020. 0x0B, 0x93, 0x46, 0xF2, 0x51, 0x30, 0x3E, 0x60,
  38021. 0xE1, 0xCB, 0x30, 0x04, 0x15, 0x8D, 0x1E, 0x87,
  38022. 0xA6, 0xF6, 0x38, 0xE0, 0x27, 0x84, 0x81, 0x18,
  38023. 0x2B, 0x37, 0xBB, 0xD3, 0xDB, 0xE7, 0x91, 0xA3,
  38024. 0x1B, 0x6B, 0x20, 0xCB, 0x2C, 0x52, 0xB1, 0xB9,
  38025. 0x6A, 0x94, 0xF8, 0xCD, 0xBA, 0x5D, 0xC7, 0xDD,
  38026. 0x79, 0x36, 0x38, 0xC2, 0xFC, 0xEC, 0x4F, 0x2B,
  38027. 0x5F, 0x73, 0x44, 0x03, 0xE9, 0xA9, 0xF5, 0xD9,
  38028. 0x99, 0xEA, 0x61, 0xDC, 0x6A, 0x98, 0xBE, 0xDE,
  38029. 0xB9, 0x34, 0xCC, 0x76, 0xB0, 0xE1, 0x8C, 0x70,
  38030. 0x3A, 0xA5, 0x7C, 0xD1, 0xC0, 0x2A, 0x8E, 0x7D,
  38031. 0x47, 0x8A, 0x63, 0xEA, 0x30, 0x6B, 0xEE, 0x36,
  38032. 0x0B, 0xA8, 0xAE, 0x46, 0xCD, 0x01, 0x83, 0xF6,
  38033. 0x07, 0xF9, 0xED, 0x8B, 0x69, 0x97, 0xB6, 0xC3,
  38034. 0x5D, 0x75, 0x6E, 0xD8, 0xDF, 0x01, 0x82, 0x48,
  38035. 0x31, 0x2F, 0xDE, 0xED, 0x8E, 0xC5, 0xD8, 0xA6,
  38036. 0xC0, 0x36, 0x0E, 0x66, 0xA4, 0xE9, 0xE5, 0xA9,
  38037. 0x7D, 0x5C, 0xD2, 0x43, 0x72, 0xC0, 0xAD, 0x26,
  38038. 0x78, 0xF2, 0xB0, 0x08, 0x12, 0xAE, 0x6C, 0x1A,
  38039. 0x0F, 0x53, 0x30, 0xB3, 0xAB, 0x01, 0x53, 0xDA,
  38040. 0x3C, 0x5F, 0x4C, 0x17, 0xBD, 0x2F, 0xB6, 0x0E,
  38041. 0x7E, 0x80, 0x87, 0x4C, 0x1B, 0x92, 0x9B, 0x62,
  38042. 0xE3, 0x89, 0xEE, 0xE2, 0xA0, 0x14, 0x06, 0x0D,
  38043. 0x4D, 0xCC, 0x96, 0x5A, 0xF8, 0x64, 0x2A, 0x05,
  38044. 0xA9, 0xEE, 0xD5, 0x0D, 0x23, 0x90, 0xB0, 0x67,
  38045. 0xD5, 0x51, 0x1D, 0x18, 0xBC, 0xBA, 0xE6, 0xA5,
  38046. 0xAD, 0x29, 0x18, 0xD5, 0x06, 0xFC, 0xC9, 0x12,
  38047. 0x6D, 0x70, 0xA8, 0x6E, 0x96, 0x8B, 0x5F, 0x9C,
  38048. 0x99, 0x43, 0x07, 0x02, 0x37, 0x48, 0x8C, 0xFB,
  38049. 0x5F, 0xF5, 0xDE, 0x69, 0x26, 0x73, 0x7D, 0xF6,
  38050. 0x3A, 0x2C, 0xE5, 0x58, 0x01, 0xC3, 0x48, 0xB0,
  38051. 0xF0, 0x0D, 0x56, 0xAF, 0x8C, 0x0F, 0x5C, 0xB3,
  38052. 0xBA, 0x44, 0x8C, 0x39, 0xB0, 0x20, 0xD2, 0x93,
  38053. 0x81, 0x19, 0x99, 0x4E, 0xAC, 0xB9, 0x1F, 0xC3,
  38054. 0x1F, 0x34, 0x7D, 0xF3, 0x3E, 0x1A, 0xE1, 0x26,
  38055. 0x7C, 0xB7, 0x22, 0x0A, 0xDC, 0x0D, 0x14, 0xF8,
  38056. 0x43, 0x8A, 0x23, 0x46, 0x37, 0x9C, 0x2A, 0xB8,
  38057. 0x1F, 0x24, 0x72, 0xE2, 0xEA, 0xC4, 0x67, 0x13,
  38058. 0x17, 0x33, 0xBD, 0xA0, 0x07, 0xA0, 0x3E, 0xDE,
  38059. 0x8B, 0xC4, 0xD6, 0xDB, 0xD9, 0xF1, 0xB8, 0xF4,
  38060. 0xFB, 0x83, 0x13, 0x14, 0xCD, 0x36, 0xF6, 0xDC,
  38061. 0xD5, 0x85, 0x93, 0x7C, 0xF9, 0x6C, 0xEA, 0x52,
  38062. 0x92, 0xFB, 0xFC, 0x95, 0x02, 0x10, 0x7B, 0x57,
  38063. 0x9F, 0xF0, 0x7C, 0x2E, 0x79, 0x00, 0x3D, 0xB2,
  38064. 0xA1, 0x6C, 0x4E, 0xD4, 0x17, 0xFA, 0x0F, 0x13,
  38065. 0xC8, 0xBF, 0xB1, 0x82, 0xF7, 0xDD, 0xCF, 0x08,
  38066. 0xF2, 0x50, 0xDB, 0x16, 0xA4, 0x5A, 0x60, 0x4A,
  38067. 0x57, 0x2B, 0x0E, 0xDC, 0x4A, 0xBF, 0x9C, 0x86,
  38068. 0x08, 0x8A, 0x5A, 0xC8, 0x74, 0xDD, 0xA2, 0x6E,
  38069. 0x12, 0xA0, 0xEF, 0x63, 0x5A, 0xD2, 0x82, 0xAD,
  38070. 0xCD, 0xC7, 0xED, 0x16, 0x86, 0x45, 0x3D, 0xFB,
  38071. 0x35, 0xC3, 0xB1, 0xBA, 0x68, 0x21, 0xB4, 0xB7,
  38072. 0x22, 0x0B, 0x55, 0x79, 0x8B, 0x9C, 0xCF, 0xE0,
  38073. 0x66, 0x61, 0x5C, 0xE2, 0x55, 0x96, 0x0D, 0x09,
  38074. 0xE6, 0x77, 0xFE, 0xFE, 0x76, 0xBE, 0x91, 0x5E,
  38075. 0x04, 0xE5, 0x65, 0x44, 0xBD, 0x09, 0xD0, 0x6F,
  38076. 0x83, 0x44, 0xF9, 0x68, 0xDC, 0x68, 0x25, 0xCB,
  38077. 0xC6, 0x64, 0xD5, 0x18, 0xA4, 0x41, 0xE1, 0x9B,
  38078. 0x07, 0x6F, 0xC3, 0x38, 0x91, 0x37, 0xFC, 0x1B,
  38079. 0x73, 0x32, 0xE2, 0xB0, 0x68, 0x95, 0x44, 0x3B,
  38080. 0x7A, 0x00, 0x23, 0x36, 0x31, 0x15, 0x79, 0xA9,
  38081. 0xB0, 0x8F, 0x36, 0x73, 0xDA, 0x05, 0x90, 0xE6,
  38082. 0x96, 0xCE, 0xD9, 0x01, 0x44, 0x4A, 0x70, 0xA6,
  38083. 0x7B, 0x2A, 0x7D, 0x55, 0x12, 0xD6, 0x5B, 0xFC,
  38084. 0xD7, 0xAF, 0x1E, 0x34, 0x27, 0x77, 0x69, 0xE1,
  38085. 0x71, 0x08, 0x83, 0x01, 0xDE, 0x78, 0x46, 0xF0,
  38086. 0x88, 0xF4, 0x87, 0xC4, 0x92, 0x1B, 0xEB, 0x98,
  38087. 0x35, 0x4B, 0xAE, 0x9A, 0xF6, 0xEA, 0xB2, 0x34,
  38088. 0x91, 0x14, 0xEB, 0x21, 0xF6, 0x18, 0xDB, 0x1D,
  38089. 0x92, 0x6C, 0x1D, 0x2F, 0xE3, 0xA5, 0xF2, 0x29,
  38090. 0xC5, 0x73, 0x40, 0xC4, 0x0A, 0xEC, 0x11, 0xC2,
  38091. 0xD0, 0x14, 0x4D, 0x03, 0x94, 0xFC, 0x4D, 0x8E,
  38092. 0x38, 0x66, 0xA7, 0xD0, 0xA1, 0x0B, 0x64, 0xC8,
  38093. 0xB9, 0x92, 0xB0, 0xA4, 0xDD, 0xBC, 0xAD, 0x82,
  38094. 0x4E, 0x43, 0x97, 0x43, 0x78, 0xEA, 0x9A, 0x38,
  38095. 0xE5, 0x8C, 0x2C, 0x5A, 0xE1, 0x94, 0xAF, 0x43,
  38096. 0x10, 0xFB, 0xEC, 0x90, 0x28, 0x41, 0x6C, 0x5C,
  38097. 0xB7, 0xB8, 0xAF, 0xA5, 0x24, 0xF7, 0x4F, 0xFD,
  38098. 0x6F, 0x2E, 0x98, 0x44, 0x3F, 0x5E, 0x89, 0x24,
  38099. 0xF6, 0xCF, 0x11, 0x0E, 0x67, 0x1B, 0x81, 0x68,
  38100. 0x37, 0xD5, 0x9B, 0x2D, 0xB9, 0x1C, 0xB1, 0xE6,
  38101. 0x87, 0xD6, 0xA2, 0x02, 0x0F, 0x91, 0x08, 0xF6,
  38102. 0x9B, 0x94, 0x76, 0x62, 0xFD, 0xE7, 0x18, 0xAC,
  38103. 0x28, 0xA6, 0xAC, 0xDA, 0x27, 0xF4, 0x33, 0x59,
  38104. 0xBB, 0xBE, 0x36, 0x2C, 0xEE, 0xEA, 0x91, 0xE6,
  38105. 0x91, 0x95, 0x2C, 0x58, 0x0A, 0xB2, 0xCA, 0xA3,
  38106. 0xAA, 0x39, 0x03, 0x9A, 0x75, 0x3C, 0x27, 0x6E,
  38107. 0x02, 0x89, 0x17, 0x4B, 0x02, 0x42, 0x7C, 0xB4,
  38108. 0x2E, 0xAD, 0xB4, 0xD9, 0x35, 0xB2, 0x30, 0x9E,
  38109. 0x2F, 0xEC, 0x9F, 0x25, 0x56, 0x1A, 0x35, 0x40,
  38110. 0xF1, 0xAF, 0x1D, 0xA4, 0xA8, 0x62, 0x07, 0x70,
  38111. 0x98, 0x6C, 0xDE, 0x1E, 0x89, 0xC1, 0xD3, 0x30,
  38112. 0xBB, 0x82, 0x72, 0x40, 0xF2, 0xBC, 0x53, 0xC7,
  38113. 0xDE, 0xAB, 0xFC, 0x7D, 0xAD, 0xBF, 0xDA, 0xE0,
  38114. 0xA7, 0xA1, 0x0C, 0xD6, 0x73, 0x37, 0x36, 0xA1,
  38115. 0xEE, 0xA6, 0x96, 0x88, 0x79, 0x0E, 0x4A, 0x2C,
  38116. 0x69, 0x4C, 0xE5, 0x30, 0xFB, 0xDD, 0xE1, 0xFE,
  38117. 0x86, 0x90, 0xDC, 0xDF, 0x03, 0xF5, 0x17, 0x2F,
  38118. 0xF4, 0x58, 0x2D, 0xD3, 0xED, 0x3D, 0x7D, 0xA0,
  38119. 0xB3, 0x6E, 0x1E, 0xD3, 0xBB, 0xD9, 0x57, 0xBA,
  38120. 0x8B, 0x00, 0x72, 0xC4, 0xEE, 0xCF, 0x39, 0xD5,
  38121. 0x74, 0xFA, 0x13, 0xF0, 0xD7, 0xE9, 0x10, 0x0C,
  38122. 0x7A, 0x52, 0x62, 0xD0, 0xC9, 0xD5, 0x2D, 0xDC,
  38123. 0x11, 0xD4, 0xFF, 0x34, 0xB2, 0x55, 0xF9, 0x99,
  38124. 0x81, 0xB4, 0xC9, 0x14, 0x02, 0x91, 0x81, 0x56,
  38125. 0x29, 0xF6, 0xA9, 0x1A, 0x19, 0x8E, 0x74, 0xB3,
  38126. 0xA3, 0xD1, 0x28, 0xB5, 0x72, 0xD8, 0x6F, 0x54,
  38127. 0x15, 0x74, 0x55, 0x70, 0x26, 0x62, 0xCB, 0x1D,
  38128. 0x15, 0x2C, 0x7F, 0x4C, 0x9C, 0xB4, 0xDE, 0xA2,
  38129. 0x07, 0xD5, 0xA9, 0x38, 0x29, 0x42, 0x51, 0x67,
  38130. 0x44, 0x26, 0x97, 0x7E, 0x73, 0x0E, 0xC6, 0x01,
  38131. 0x00, 0x65, 0xC8, 0xE0, 0x34, 0x88, 0x2B, 0xD3,
  38132. 0x2F, 0xD3, 0x5C, 0x6A, 0xF6, 0xB8, 0xD9, 0x3A,
  38133. 0x50, 0x9C, 0xC3, 0x39, 0xD9, 0x6F, 0xB9, 0xDD,
  38134. 0x55, 0x8A, 0xF9, 0x52, 0x35, 0xFB, 0xF1, 0x71,
  38135. 0x97, 0x76, 0x04, 0x75, 0xEE, 0x2E, 0x3F, 0xCA,
  38136. 0x0E, 0x83, 0xA8, 0xE3, 0x1F, 0xA7, 0xF1, 0x3D,
  38137. 0x78, 0xCC, 0x79, 0x64, 0x80, 0x5E, 0x77, 0x05,
  38138. 0xDB, 0xB7, 0x0F, 0x73, 0x53, 0x3A, 0x56, 0xD8,
  38139. 0xB7, 0x7C, 0x12, 0xE8, 0xF6, 0x51, 0x07, 0xC9,
  38140. 0x01, 0x43, 0x97, 0x51, 0x75, 0x95, 0x94, 0x65,
  38141. 0xFD, 0x4D, 0x8C, 0x8C, 0xD3, 0xA8, 0xEE, 0xA9,
  38142. 0x5E, 0xFB, 0xC7, 0xF6, 0xF8, 0x40, 0x0E, 0xA5,
  38143. 0xD5, 0x1E, 0x79, 0xB4, 0x0C, 0xEF, 0x8B, 0x04,
  38144. 0x59, 0x4D, 0x0C, 0x6F, 0x08, 0xD5, 0x00, 0xA2,
  38145. 0xAD, 0x08, 0xB4, 0x62, 0xE0, 0x2C, 0xF6, 0x30,
  38146. 0x31, 0x1E, 0xD7, 0x81, 0x56, 0x61, 0x17, 0x0D,
  38147. 0xB3, 0x9F, 0x27, 0x75, 0x38, 0x42, 0x6E, 0xB2,
  38148. 0xB0, 0x6C, 0xB8, 0xC9, 0xD8, 0x20, 0xC8, 0x36,
  38149. 0x7D, 0x1D, 0x57, 0x10, 0x4E, 0xC1, 0x45, 0xFC,
  38150. 0x93, 0xB1, 0xF7, 0x7B, 0xA1, 0x3B, 0x71, 0x12,
  38151. 0x16, 0xE5, 0x8F, 0xD0, 0x0C, 0x7D, 0xC0, 0x05,
  38152. 0x18, 0x02, 0x24, 0x25, 0x28, 0x8A, 0xE1, 0x29,
  38153. 0x9A, 0x79, 0xBD, 0xC7, 0x73, 0x2D, 0xF3, 0x42,
  38154. 0x70, 0x33, 0xF3, 0xF8, 0x48, 0x87, 0xB4, 0xD4,
  38155. 0x91, 0xE1, 0x53, 0xBA, 0x4A, 0x63, 0xAF, 0x3A,
  38156. 0xE5, 0xCB, 0x3D, 0x41, 0x04, 0xB5, 0x30, 0x87,
  38157. 0xAA, 0x40, 0x03, 0x56, 0x10, 0x02, 0xF3, 0x6A,
  38158. 0x9F, 0xDA, 0x33, 0xBC, 0xB8, 0xA5, 0xD0, 0x56,
  38159. 0x43, 0x29, 0xDA, 0x58, 0x12, 0x8B, 0x6A, 0x9D,
  38160. 0xCF, 0xCD, 0xCA, 0x66, 0x98, 0x92, 0x1D, 0xA4,
  38161. 0xEF, 0xAC, 0x9E, 0x19, 0xDE, 0xF7, 0xFE, 0x6C,
  38162. 0x3A, 0x66, 0x46, 0xB4, 0x00, 0x7F, 0x08, 0xAF,
  38163. 0x31, 0xD6, 0xD3, 0x22, 0x59, 0x1F, 0x34, 0x48,
  38164. 0x5A, 0xE1, 0x4E, 0x0F, 0x6F, 0x2D, 0xD0, 0xE5,
  38165. 0x8E, 0x34, 0x3B, 0xC0, 0x55, 0x02, 0x2D, 0x17,
  38166. 0x4B, 0x34, 0x78, 0x46, 0xD4, 0xC4, 0x7F, 0x1D,
  38167. 0xDC, 0x39, 0x94, 0x69, 0x78, 0xAB, 0xD8, 0x2B,
  38168. 0x6D, 0xF3, 0x1C, 0x0B, 0x0F, 0x4A, 0xA0, 0xB2,
  38169. 0xAC, 0x1A, 0x79, 0x7F, 0x9D, 0xE5, 0xE8, 0xC6,
  38170. 0x40, 0x4B, 0xCE, 0x32, 0x4B, 0xA1, 0x3C, 0x77,
  38171. 0xED, 0x5D, 0x59, 0x0F, 0xE0, 0x7D, 0x00, 0x07,
  38172. 0xB4, 0xD8, 0xA6, 0x3E, 0xC9, 0x6D, 0x62, 0x19,
  38173. 0x66, 0xC3, 0xE7, 0x10, 0x3B, 0x6C, 0x7A, 0x36,
  38174. 0x49, 0x75, 0xE6, 0x78, 0xB3, 0x8D, 0x04, 0x13,
  38175. 0x31, 0xE6, 0x79, 0x72, 0x64, 0x07, 0x76, 0x94,
  38176. 0x2B, 0xB4, 0xEC, 0x18, 0x1C, 0x32, 0x3C, 0x26,
  38177. 0xC4, 0x81, 0xBF, 0x4F, 0xB5, 0x6E, 0x5D, 0x67,
  38178. 0xCF, 0xBE, 0x17, 0x57, 0x11, 0x2B, 0xBC, 0xA0,
  38179. 0xF0, 0xC2, 0x70, 0x06, 0x94, 0x26, 0x9B, 0x26,
  38180. 0x12, 0x9C, 0x7F, 0x99, 0xD4, 0x4A, 0xF5, 0x60,
  38181. 0xCD, 0xF7, 0xA4, 0x70, 0x2E, 0xF5, 0xD6, 0xA2,
  38182. 0xEC, 0x0E, 0x99, 0x00, 0x2E, 0x89, 0x30, 0xAA,
  38183. 0x4E, 0xC0, 0x62, 0x11, 0x93, 0x0A, 0x1E, 0x68,
  38184. 0xF2, 0xED, 0x44, 0x8B, 0x10, 0x4A, 0x75, 0x68,
  38185. 0xBF, 0x46, 0xE1, 0x41, 0xD6, 0x0B, 0x61, 0x53,
  38186. 0xD4, 0x03, 0x10, 0xB3, 0x8F, 0x8E, 0x14, 0x57,
  38187. 0x27, 0x8F, 0xE3, 0x49, 0xB2, 0xB4, 0xA7, 0xAE,
  38188. 0x39, 0x7A, 0x7B, 0x8F, 0x48, 0xAA, 0xA5, 0xFD,
  38189. 0xC1, 0x28, 0x8E, 0x43, 0xE0, 0x58, 0x39, 0x32,
  38190. 0x0A, 0x14, 0xC6, 0x3A, 0xB8, 0x58, 0xE2, 0x6E,
  38191. 0x7D, 0x8C, 0x35, 0xB6, 0x47, 0x37, 0x90, 0x4D,
  38192. 0x89, 0xC1, 0x9A, 0x10, 0x3D, 0x6B, 0x68, 0x9A,
  38193. 0x3D, 0xC9, 0x0C, 0x72, 0xFC, 0x92, 0xE3, 0x5D,
  38194. 0x45, 0x2B, 0x81, 0x43, 0x02, 0x30, 0x70, 0xD4,
  38195. 0x8B, 0xB9, 0xFB, 0xB0, 0x45, 0xE3, 0xC6, 0xCE,
  38196. 0x9A, 0x8B, 0xD5, 0xC4, 0xB6, 0x7F, 0x5D, 0x8B,
  38197. 0x58, 0xC9, 0x6A, 0x28, 0x2D, 0x6E, 0x27, 0x78,
  38198. 0x3D, 0x7B, 0x99, 0x0E, 0x05, 0x2B, 0xD9, 0x5E,
  38199. 0x86, 0x50, 0x8F, 0x9B, 0xF7, 0xC0, 0x64, 0xA8,
  38200. 0xF2, 0x39, 0xE0, 0x24, 0x0A, 0x20, 0xD8, 0xDF,
  38201. 0x3A, 0x87, 0x6E, 0xDC, 0x8F, 0xF6, 0x24, 0x1B,
  38202. 0x54, 0xF2, 0x70, 0xA9, 0x8C, 0xB8, 0x07, 0x7A,
  38203. 0xAF, 0xE0, 0xE5, 0x8E, 0x5E, 0x98, 0x13, 0xC6,
  38204. 0xA5, 0xF9, 0x1F, 0x52, 0x89, 0x7B, 0x6A, 0xAD,
  38205. 0x24, 0x26, 0xC6, 0x0D, 0xA5, 0x88, 0x3E, 0x6B,
  38206. 0xDF, 0xEE, 0x33, 0x0A, 0x86, 0x09, 0xA2, 0x11,
  38207. 0x8B, 0x69, 0x9F, 0x75, 0xCE, 0xFD, 0x05, 0x01,
  38208. 0x95, 0x14, 0x64, 0xCD, 0x62, 0x04, 0x09, 0x87,
  38209. 0xFC, 0xF6, 0xB2, 0x2E, 0xCA, 0x92, 0xE4, 0x4F,
  38210. 0x55, 0xB3, 0x8C, 0x64, 0x99, 0xA8, 0xDA, 0x0A,
  38211. 0xC7, 0x82, 0x56, 0x93, 0x03, 0x67, 0xA4, 0xD7,
  38212. 0x54, 0x91, 0xA0, 0x89, 0xD8, 0x94, 0x1F, 0x6C,
  38213. 0x53, 0xCC, 0xB2, 0x60, 0x13, 0x6A, 0x93, 0xE1,
  38214. 0xFC, 0xA3, 0xDD, 0x72, 0xD5, 0x5A, 0x92, 0x35,
  38215. 0x9E, 0x3D, 0x62, 0x82, 0x70, 0x5D, 0x54, 0xAF,
  38216. 0x57, 0xC6, 0x98, 0x5E, 0x74, 0xE0, 0xF2, 0x33,
  38217. 0x26, 0x61, 0xBF, 0x2B, 0xDD, 0x78, 0x47, 0x29,
  38218. 0x04, 0xC7, 0xF0, 0x58, 0x17, 0xFC, 0x9D, 0xED,
  38219. 0xEF, 0x15, 0x6A, 0xCA, 0xC7, 0x46, 0xCE, 0x12,
  38220. 0xF8, 0x90, 0xD8, 0x5A, 0x93, 0x98, 0xA9, 0xED,
  38221. 0xFB, 0xF4, 0x6E, 0x73, 0x48, 0x81, 0x4A, 0x08,
  38222. 0x07, 0x29, 0xC8, 0x3E, 0x70, 0x4C, 0x40, 0x30,
  38223. 0x20, 0x2C, 0xF6, 0x1E, 0xCD, 0xEE, 0x27, 0x95,
  38224. 0xD5, 0x07, 0xAC, 0x28, 0x81, 0x4F, 0x53, 0xCD,
  38225. 0x06, 0x60, 0xA5, 0x57, 0x2C, 0xBE, 0x1A, 0xE5,
  38226. 0x33, 0x38, 0xB8, 0xEF, 0xDC, 0xA3, 0x1A, 0xA5,
  38227. 0xB9, 0x5A, 0xA9, 0xE7, 0x65, 0xAF, 0x4D, 0xA0,
  38228. 0x4C, 0x9B, 0x31, 0x62, 0x67, 0x7E, 0x41, 0xC0,
  38229. 0x18, 0xA5, 0xE1, 0x8A, 0xF2, 0xF9, 0x8A, 0xCA,
  38230. 0x14, 0x5C, 0xCD, 0x1B, 0x8F, 0x74, 0x31, 0x07,
  38231. 0x6A, 0x14, 0xA7, 0xC2, 0x0F, 0x6C, 0x72, 0xE8,
  38232. 0xEB, 0x97, 0x51, 0xB7, 0x89, 0x2E, 0x41, 0x01,
  38233. 0x54, 0x47, 0x63, 0x0E, 0xAA, 0x84, 0xB9, 0x60,
  38234. 0x1C, 0xB9, 0x54, 0xD8, 0x97, 0x39, 0x38, 0x9D,
  38235. 0x52, 0xBB, 0x91, 0xA9, 0x7F, 0x96, 0x08, 0x7C,
  38236. 0xB3, 0x8B, 0x0E, 0xAB, 0x59, 0xA7, 0x84, 0x68,
  38237. 0x34, 0x65, 0x55, 0xC7, 0x12, 0x84, 0xC2, 0xFB,
  38238. 0xBD, 0x27, 0x58, 0x18, 0xE9, 0x26, 0x73, 0xFA,
  38239. 0x42, 0xAB, 0x5E, 0x0D, 0x97, 0x76, 0x67, 0xA9,
  38240. 0x0F, 0x75, 0x92, 0x6C, 0x80, 0x76, 0x87, 0x75,
  38241. 0xD2, 0x3D, 0xFE, 0x0B, 0x33, 0x7B, 0x48, 0xB0,
  38242. 0xC8, 0x28, 0x1F, 0xE6, 0x3F, 0x18, 0xF2, 0x45,
  38243. 0xF8, 0x8F, 0x21, 0xE1, 0x1C, 0x56, 0xA5, 0x33,
  38244. 0x71, 0x88, 0x42, 0x5A, 0x34, 0x8B, 0x24, 0xDD,
  38245. 0x0E, 0x98, 0x30, 0xDB, 0x6B, 0x6C, 0x89, 0x64,
  38246. 0x8C, 0x7A, 0x63, 0x3C, 0xA9, 0xD8, 0x32, 0x51,
  38247. 0xD0, 0xC6, 0xF7, 0xA4, 0x53, 0x95, 0x0D, 0x02,
  38248. 0x19, 0x6A, 0x77, 0xBC, 0xDF, 0xD5, 0x2B, 0x2C,
  38249. 0x65, 0xC9, 0xBF, 0x72, 0x69, 0xC3, 0x0C, 0xEF,
  38250. 0x34, 0x75, 0x76, 0x29, 0x59, 0xBE, 0x9D, 0xE9,
  38251. 0x44, 0x21, 0x2F, 0x5F, 0xB7, 0x89, 0xA6, 0xCD,
  38252. 0x0A, 0x9A, 0x9E, 0x77, 0x5B, 0xBD, 0xDA, 0x03,
  38253. 0xA4, 0xBC, 0xFB, 0x47, 0xC1, 0x77, 0x73, 0x00,
  38254. 0x26, 0xAE, 0x2E, 0xFA, 0x62, 0x18, 0x9D, 0xB8,
  38255. 0xE2, 0xD3, 0x7A, 0xB9, 0xD8, 0xCF, 0xE9, 0x61,
  38256. 0x11, 0x80, 0xE9, 0xDC, 0xC3, 0x32, 0x9E, 0x63,
  38257. 0x6F, 0xD9, 0x42, 0xF6, 0x76, 0x7F, 0xBC, 0xBF,
  38258. 0xDB, 0x08, 0x2F, 0xA0, 0xEB, 0xB8, 0x4D, 0xF3,
  38259. 0x76, 0x62, 0xAA, 0xFA, 0x20, 0x4A, 0xDD, 0xE6,
  38260. 0xB3, 0x72, 0xC7, 0x7D, 0x36, 0x4F, 0x08, 0x56,
  38261. 0x4F, 0x19, 0xB2, 0xB0, 0x0C, 0x13, 0x1A, 0x8C,
  38262. 0xCE, 0x9A, 0x04, 0xB5, 0xB6, 0x9C, 0xD3, 0xD8,
  38263. 0xFE, 0x1F, 0x2C, 0xCC, 0x89, 0xEE, 0x7D, 0x22,
  38264. 0x8A, 0x4E, 0x0A, 0x91, 0x0C, 0x8B, 0x5A, 0xE0,
  38265. 0xBD, 0xE5, 0x3D, 0xBE, 0x90, 0x4B, 0x13, 0xA3,
  38266. 0x2F, 0x33, 0xE9, 0x9D, 0x6C, 0x67, 0x35, 0xBD,
  38267. 0x03, 0xD4, 0x09, 0x90, 0x2F, 0xC6, 0x3C, 0x8D,
  38268. 0xD8, 0x43, 0xFC, 0x1F, 0xB7, 0x49, 0xC0, 0xB7,
  38269. 0x38, 0x70, 0x1D, 0xEB, 0x5A, 0xD7, 0xAC, 0x07,
  38270. 0xAF, 0x5B, 0x93, 0xC5, 0x7B, 0x55, 0x65, 0x86,
  38271. 0x6E, 0xC1, 0xDB, 0xCD, 0x42, 0x92, 0x50, 0xDB,
  38272. 0xD1, 0x97, 0x95, 0x3D, 0x53, 0xC3, 0xFE, 0xC2,
  38273. 0xF9, 0x65, 0xF3, 0xD2, 0xEE, 0xA4, 0x7E, 0xDE,
  38274. 0xA1, 0x4B, 0x23, 0x7F, 0xA1, 0x0D, 0x25, 0x6E,
  38275. 0x80, 0x4F, 0xE3, 0xB5, 0x0C, 0xBA, 0x1C, 0x2B,
  38276. 0x42, 0x0B, 0x8F, 0xD9, 0xB6, 0x4E, 0x52, 0xD2,
  38277. 0xDB, 0x35, 0xD2, 0xA1, 0xC4, 0xE6, 0xD6, 0x51,
  38278. 0x76, 0xE7, 0x87, 0x5E, 0xBE, 0x93, 0xE6, 0x61,
  38279. 0x71, 0x4C, 0x8B, 0xA6, 0x96, 0xDA, 0xF7, 0xCB,
  38280. 0x06, 0xB7, 0xB8, 0xC4, 0xF6, 0xF5, 0xC6, 0x29,
  38281. 0xAA, 0xE1, 0x13, 0x87, 0x6F, 0x96, 0xBA, 0x0C,
  38282. 0xF6, 0x79, 0x8F, 0x03, 0x86, 0x22, 0xE3, 0xFB,
  38283. 0xCF, 0x86, 0xCF, 0x7C, 0x77, 0xFD, 0xB4, 0xEE,
  38284. 0xBD, 0x42, 0x38, 0x7F, 0xF2, 0xCC, 0xCB, 0x06,
  38285. 0xEA, 0x0D, 0x81, 0xA1, 0x8E, 0xB5, 0xE7, 0x40,
  38286. 0xC8, 0x03, 0xA3, 0x4B, 0xC8, 0xB4, 0x0E, 0x3E,
  38287. 0x36, 0xAB, 0x90, 0xC1, 0xFC, 0xB0, 0x37, 0x2B,
  38288. 0x83, 0xA1, 0x3D, 0x56, 0xD6, 0x83, 0x0F, 0x99,
  38289. 0xC4, 0x58, 0xB8, 0x94, 0x61, 0x19, 0xA6, 0x60,
  38290. 0x47, 0xCB, 0x2D, 0xAF, 0x29, 0x38, 0x90, 0xFA,
  38291. 0x99, 0x0F, 0x02, 0x02, 0x65, 0x90, 0x5F, 0xA2,
  38292. 0xA2, 0xE3, 0xBB, 0x34, 0x15, 0x2F, 0x0B, 0xF5,
  38293. 0xB2, 0xCC, 0x83, 0x59, 0xAF, 0xA7, 0x4D, 0x38,
  38294. 0xAD, 0xF6, 0x52, 0x5C, 0x53, 0xD9, 0x0E, 0x3F,
  38295. 0xD6, 0x53, 0x86, 0xE2, 0x79, 0xC2, 0x65, 0x48,
  38296. 0xB2, 0x67, 0x3B, 0xAF, 0x52, 0x53, 0x57, 0x9A,
  38297. 0x27, 0x80, 0x88, 0x37, 0x77, 0x67, 0x4E, 0x1F,
  38298. 0xF1, 0x7B, 0xC5, 0xCB, 0xD8, 0x11, 0x0A, 0xDD,
  38299. 0x92, 0x0E, 0x88, 0x6C, 0xCA, 0x33, 0x76, 0x3B,
  38300. 0x04, 0xFA, 0xC0, 0xFD, 0xC6, 0x3F, 0xB4, 0x72,
  38301. 0xC2, 0x2B, 0x6D, 0x5E, 0xB6, 0xA1, 0x4E, 0x5F,
  38302. 0xC0, 0x50, 0x16, 0xEF, 0xFE, 0x6A, 0x42, 0x72,
  38303. 0x65, 0x02, 0xEE, 0x07, 0xC6, 0x19, 0xC6, 0x95,
  38304. 0xDE, 0x3F, 0xD9, 0xC5, 0xC6, 0x0E, 0x70, 0x07,
  38305. 0x6A, 0xC3, 0x36, 0x1B, 0x84, 0x6F, 0xDF, 0x80,
  38306. 0x16, 0x4E, 0x86, 0x90, 0xC8, 0x55, 0x7B, 0xDD,
  38307. 0xC0, 0x86, 0x0C, 0x37, 0x47, 0x1F, 0x35, 0xF8,
  38308. 0x47, 0xF2, 0xCD, 0x96, 0x21, 0x64, 0xAD, 0x46,
  38309. 0xE1, 0xDF, 0x44, 0x79, 0x48, 0x02, 0xF9, 0x71,
  38310. 0x39, 0x35, 0x26, 0xFC, 0x12, 0x0D, 0x88, 0xAC,
  38311. 0xD6, 0xFA, 0x29, 0x74, 0x55, 0x51, 0xE7, 0xAF,
  38312. 0x3D, 0x7E, 0x1E, 0x7E, 0xE0, 0x18, 0xB6, 0x3C,
  38313. 0x4B, 0x99, 0x9D, 0x51, 0x02, 0x51, 0xD8, 0xE9,
  38314. 0xFA, 0x61, 0x88, 0x2E, 0xCF, 0x73, 0x77, 0x65,
  38315. 0x71, 0xAE, 0xAE, 0xD7, 0xA1, 0xF9, 0xE0, 0x7F,
  38316. 0x30, 0x46, 0xCB, 0x20, 0xEC, 0xF4, 0xD2, 0xC1,
  38317. 0x63, 0xF5, 0x6F, 0x8A, 0x72, 0xF9, 0x5B, 0x85,
  38318. 0xD2, 0xCA, 0x6D, 0x35, 0xD1, 0x17, 0xF6, 0x08,
  38319. 0x9E, 0x0A, 0x73, 0xB3, 0xDA, 0x1A, 0x32, 0xBA,
  38320. 0x23, 0x10, 0x4A, 0x5D, 0xD7, 0xAA, 0xB4, 0x68,
  38321. 0x97, 0x59, 0x45, 0xC5, 0x7C, 0x16, 0x6F, 0xE4,
  38322. 0x62, 0x89, 0xF1, 0xD3, 0xB4, 0x03, 0x90, 0x7B,
  38323. 0xA4, 0xA2, 0xCA, 0xA0, 0x5D, 0x69, 0x1B, 0xA9,
  38324. 0xBB, 0xEB, 0xA0, 0xE2, 0xDE, 0xBE, 0x0E, 0xC4,
  38325. 0x9E, 0x21, 0x38, 0x61, 0x92, 0x9B, 0xAB, 0x69,
  38326. 0xAA, 0xD0, 0x1D, 0xF6, 0xC3, 0xEE, 0xA6, 0xC3,
  38327. 0xF3, 0x29, 0x1B, 0xE5, 0x6E, 0x52, 0x89, 0xD0,
  38328. 0xBA, 0xD8, 0x60, 0x27, 0x80, 0x1A, 0xB5, 0x7F,
  38329. 0x7F, 0xB5, 0xC2, 0x5A, 0xC6, 0x83, 0xA4, 0xC0,
  38330. 0x88, 0x39, 0xF3, 0xE7, 0x39, 0xD6, 0x81, 0x1C,
  38331. 0x13, 0x20, 0xFD, 0x93, 0x3D, 0x8E, 0x79, 0x60,
  38332. 0x7C, 0xFF, 0xE4, 0x37, 0x5B, 0x33, 0xA3, 0x9D,
  38333. 0xB7, 0x57, 0xCD, 0x45, 0x0A, 0xB9, 0xE4, 0xF1,
  38334. 0xBC, 0x59, 0x74, 0xE8, 0xB3, 0x06, 0xD0, 0x9F,
  38335. 0x0F, 0xBC, 0x5B, 0x23, 0xB8, 0x6C, 0xD6, 0x4D,
  38336. 0xFA, 0xCC, 0x14, 0xAB, 0x74, 0x61, 0x1A, 0xFC,
  38337. 0x22, 0xA6, 0xED, 0x09, 0x76, 0x91, 0xD8, 0x6E,
  38338. 0x44, 0xB6, 0x00, 0x14, 0xDC, 0x74, 0x2D, 0x90,
  38339. 0xAA, 0x59, 0x98, 0x76, 0x30, 0xC5, 0x44, 0xA4,
  38340. 0x61, 0x43, 0xD6, 0xE2, 0x28, 0x28, 0xA7, 0xBD,
  38341. 0x6E, 0x50, 0x5C, 0xE1, 0x96, 0x7A, 0xF8, 0xA8,
  38342. 0x32, 0x8C, 0xE9, 0xFD, 0x11, 0x37, 0x91, 0xD1,
  38343. 0xAF, 0x3C, 0xD3, 0x1C, 0x1E, 0x88, 0x4D, 0x7E,
  38344. 0x87, 0x84, 0x84, 0x6F, 0x39, 0x0B, 0xFB, 0x2D,
  38345. 0xB3, 0x12, 0x4C, 0x6D, 0x45, 0xDD, 0xCD, 0x7D,
  38346. 0x75, 0xB7, 0xFE, 0x7E, 0x44, 0xCC, 0x29, 0xE5,
  38347. 0xB3, 0x10, 0xEE, 0x23, 0x55, 0x5B, 0xCF, 0xBA,
  38348. 0xBD, 0xA1, 0xBE, 0x64, 0xF8, 0x6E, 0x60, 0x31,
  38349. 0x0A, 0x2D, 0xC9, 0x3B, 0x1D, 0x44, 0xE1, 0x9D,
  38350. 0x60, 0x28, 0x77, 0xEE
  38351. };
  38352. static const byte rnd_65[] = {
  38353. 0x4E, 0x7A, 0x01, 0x7C, 0x15, 0x03, 0x9D, 0xC2,
  38354. 0x00, 0x51, 0xD2, 0x96, 0x0E, 0x5E, 0x15, 0x59,
  38355. 0xCC, 0x27, 0xED, 0x46, 0x87, 0x7C, 0xB9, 0x81,
  38356. 0x16, 0x19, 0x9A, 0x0F, 0x41, 0x05, 0xFE, 0x32
  38357. };
  38358. static const byte sig_65[] = {
  38359. 0xB8, 0x65, 0xB0, 0x0B, 0x21, 0x18, 0xDB, 0xB0,
  38360. 0x0B, 0x70, 0x1C, 0x66, 0x45, 0x65, 0x5E, 0x8A,
  38361. 0xCF, 0xA8, 0x4E, 0xA7, 0x92, 0xB4, 0x48, 0x64,
  38362. 0x2E, 0x18, 0x32, 0xC3, 0x70, 0x7C, 0x87, 0xCF,
  38363. 0x09, 0xFB, 0xE7, 0x72, 0xF1, 0xD4, 0x38, 0x5B,
  38364. 0xFB, 0xE5, 0xE6, 0xCF, 0xBB, 0xE2, 0x6C, 0x10,
  38365. 0xED, 0x6E, 0xB8, 0x65, 0xC8, 0x87, 0xF8, 0x69,
  38366. 0x39, 0x43, 0x9A, 0x9B, 0xF7, 0x68, 0xBF, 0x03,
  38367. 0x9D, 0x73, 0xE3, 0xEA, 0x83, 0xBD, 0xF1, 0x85,
  38368. 0x03, 0xB5, 0xD1, 0xB3, 0x91, 0x79, 0xA8, 0x27,
  38369. 0xB0, 0xD7, 0x80, 0x5F, 0x98, 0x42, 0x8B, 0xD8,
  38370. 0x7C, 0xEA, 0x6B, 0x06, 0x96, 0x0C, 0x78, 0xB4,
  38371. 0xB5, 0x86, 0xFB, 0x0D, 0x5E, 0xDA, 0x9F, 0xAA,
  38372. 0xC0, 0x25, 0x6E, 0x38, 0x82, 0x35, 0x62, 0xA3,
  38373. 0x07, 0x96, 0x61, 0x17, 0x00, 0x5A, 0xA4, 0x2F,
  38374. 0x1B, 0x65, 0x54, 0xA0, 0x48, 0x75, 0xF8, 0x5C,
  38375. 0x2E, 0x3F, 0xAF, 0xA6, 0x52, 0x47, 0x1D, 0x4E,
  38376. 0x98, 0x06, 0x54, 0x82, 0xFC, 0x7D, 0xF4, 0x9B,
  38377. 0x2C, 0x40, 0xD0, 0xE7, 0xB9, 0x82, 0x38, 0xDF,
  38378. 0xBE, 0x85, 0x3D, 0x16, 0xBF, 0x99, 0x92, 0xBB,
  38379. 0x08, 0xC1, 0x92, 0x59, 0xF9, 0xB5, 0x75, 0xEA,
  38380. 0x7A, 0x4A, 0x80, 0x09, 0x3A, 0x64, 0xA9, 0x26,
  38381. 0x71, 0x85, 0x7A, 0x50, 0x89, 0x20, 0xD6, 0x0F,
  38382. 0xF6, 0xFB, 0xF3, 0x83, 0x41, 0xC5, 0x59, 0x01,
  38383. 0x05, 0x63, 0x3A, 0x42, 0x6D, 0x60, 0x2D, 0xAC,
  38384. 0x06, 0x4D, 0xD7, 0xA7, 0xF1, 0x1A, 0x60, 0x21,
  38385. 0x5C, 0x35, 0xB7, 0xB9, 0xC0, 0x0E, 0x9D, 0x84,
  38386. 0x63, 0x98, 0x8C, 0xF4, 0x72, 0xCD, 0x6A, 0xCF,
  38387. 0xB7, 0xF7, 0x22, 0xB8, 0xC4, 0xC6, 0x27, 0x02,
  38388. 0x60, 0x7A, 0x67, 0x48, 0x80, 0xAC, 0xB3, 0xD6,
  38389. 0xC6, 0x25, 0x3E, 0x71, 0x17, 0x5A, 0x05, 0xB3,
  38390. 0x92, 0xCA, 0xB4, 0xBB, 0x14, 0xCE, 0x86, 0xA5,
  38391. 0x98, 0xAB, 0xC7, 0x88, 0xD0, 0xFF, 0x4D, 0x82,
  38392. 0x77, 0x5E, 0x4E, 0xA0, 0xFC, 0x36, 0x36, 0x3C,
  38393. 0xD0, 0xE9, 0x7B, 0x78, 0xA6, 0xAE, 0x4D, 0xA8,
  38394. 0xE9, 0x8C, 0xA6, 0x12, 0x77, 0x2D, 0x56, 0xB5,
  38395. 0x82, 0xF8, 0x2C, 0x07, 0x09, 0xBE, 0xAE, 0x46,
  38396. 0x67, 0x3B, 0xDD, 0x80, 0x42, 0x86, 0x5C, 0xFA,
  38397. 0x95, 0xBF, 0x53, 0x38, 0xCF, 0xEA, 0x60, 0x6A,
  38398. 0x6E, 0xF3, 0x16, 0x38, 0x46, 0xAE, 0x83, 0xB2,
  38399. 0x5E, 0x5F, 0x5B, 0xD3, 0x1C, 0x83, 0xF1, 0x36,
  38400. 0x72, 0x9A, 0x8E, 0xA6, 0x27, 0x4F, 0x99, 0x4F,
  38401. 0xA9, 0x04, 0x5F, 0xA8, 0xA9, 0x0F, 0xF8, 0x54,
  38402. 0xB8, 0x71, 0xCF, 0x82, 0xE2, 0xB7, 0x01, 0xE8,
  38403. 0xF4, 0xAC, 0x04, 0xFE, 0x9E, 0x28, 0x49, 0x1B,
  38404. 0x9A, 0x25, 0xFF, 0x26, 0x3E, 0x2C, 0xF7, 0x54,
  38405. 0x99, 0xE0, 0x09, 0xFD, 0x02, 0x29, 0xFB, 0xF7,
  38406. 0xE5, 0xE4, 0x60, 0x44, 0x34, 0x4B, 0x07, 0xD7,
  38407. 0x22, 0x14, 0xA9, 0xAC, 0xB4, 0xFF, 0x61, 0x02,
  38408. 0xAB, 0xC1, 0x26, 0x2B, 0xC2, 0xE1, 0xCD, 0x24,
  38409. 0x91, 0x60, 0x7A, 0xE7, 0xAA, 0xEC, 0xF4, 0xC3,
  38410. 0x51, 0x75, 0xCF, 0xA4, 0x38, 0x3A, 0xA8, 0x6A,
  38411. 0xF1, 0xE6, 0x2E, 0xD0, 0x63, 0x87, 0xCC, 0x59,
  38412. 0x48, 0x36, 0x46, 0x7F, 0x41, 0xDF, 0xCA, 0x8F,
  38413. 0xA0, 0xCA, 0x71, 0x28, 0x0B, 0xFB, 0x1C, 0x25,
  38414. 0x60, 0xC8, 0x99, 0x55, 0x36, 0xF8, 0x42, 0x74,
  38415. 0x70, 0x45, 0x59, 0x14, 0x53, 0x74, 0x5F, 0x26,
  38416. 0x03, 0x82, 0xE3, 0xDA, 0x50, 0x79, 0x3F, 0xD7,
  38417. 0xCA, 0x76, 0x27, 0x18, 0x5D, 0xBD, 0xCE, 0xDD,
  38418. 0xF6, 0x9B, 0x2D, 0x3E, 0x15, 0x1C, 0x7F, 0x97,
  38419. 0x28, 0x8A, 0x38, 0x2A, 0x92, 0xB0, 0x50, 0xF7,
  38420. 0x91, 0xF9, 0x58, 0x7D, 0x77, 0xC6, 0x4D, 0x8B,
  38421. 0x5D, 0x40, 0xAA, 0x19, 0x9D, 0x49, 0x66, 0xBE,
  38422. 0x2D, 0x52, 0x4F, 0x96, 0x10, 0xF2, 0xFA, 0x02,
  38423. 0xED, 0x23, 0x17, 0x63, 0x69, 0xDB, 0x93, 0x93,
  38424. 0x50, 0xDA, 0x60, 0x1E, 0xA6, 0x67, 0x70, 0x95,
  38425. 0x2E, 0x0F, 0x23, 0xED, 0xA6, 0x8A, 0x73, 0x75,
  38426. 0x6E, 0xFF, 0x61, 0x0E, 0x8D, 0x6A, 0x9F, 0x49,
  38427. 0x34, 0x56, 0x58, 0x54, 0x42, 0x82, 0x45, 0x3B,
  38428. 0x5E, 0x73, 0xA3, 0x22, 0xA0, 0x32, 0x67, 0xC9,
  38429. 0x69, 0xB5, 0x07, 0x34, 0xF2, 0xEC, 0xD4, 0xEC,
  38430. 0x90, 0x55, 0x76, 0x0D, 0x92, 0x86, 0x10, 0xE9,
  38431. 0x4E, 0x0B, 0x16, 0x28, 0xD6, 0xAF, 0x1B, 0x27,
  38432. 0xAB, 0x13, 0x82, 0x9F, 0x7F, 0x8E, 0xF5, 0x0D,
  38433. 0x9E, 0x29, 0x96, 0xFC, 0x64, 0xB0, 0x6A, 0xC8,
  38434. 0x94, 0x61, 0x14, 0x76, 0x6D, 0xAD, 0x8D, 0xFF,
  38435. 0xE6, 0x34, 0xF4, 0x7E, 0x9D, 0x85, 0x69, 0x96,
  38436. 0x6C, 0x6F, 0x69, 0x68, 0x21, 0x8C, 0x5B, 0x86,
  38437. 0x33, 0x61, 0x1B, 0xF4, 0x2B, 0x4F, 0xC0, 0xE7,
  38438. 0x8D, 0x0C, 0x02, 0x9E, 0xAB, 0x85, 0xF2, 0x2F,
  38439. 0x16, 0x17, 0x19, 0x80, 0xCC, 0x65, 0xF2, 0x84,
  38440. 0x45, 0xA1, 0x1A, 0x08, 0x3A, 0xA0, 0x29, 0x77,
  38441. 0xC2, 0xE8, 0x88, 0x6E, 0xD2, 0x70, 0x67, 0x2E,
  38442. 0x51, 0x2A, 0xE8, 0x9C, 0x6A, 0x26, 0xFC, 0xAD,
  38443. 0x1E, 0xC7, 0x2B, 0x9E, 0xCF, 0xA5, 0xA5, 0xEF,
  38444. 0xC7, 0x0F, 0xF0, 0xBA, 0xB2, 0x8F, 0x11, 0x4F,
  38445. 0x4D, 0xA8, 0x17, 0x0F, 0xE8, 0xB6, 0x3C, 0x2E,
  38446. 0x11, 0xBE, 0x7A, 0x35, 0x46, 0x6E, 0x97, 0x9A,
  38447. 0x12, 0x7E, 0xC0, 0xD2, 0x03, 0x23, 0xD5, 0x02,
  38448. 0x73, 0x0A, 0xBC, 0xE6, 0x40, 0xA2, 0x44, 0x1C,
  38449. 0xDD, 0xAB, 0xA3, 0x26, 0xD6, 0x78, 0x3D, 0x01,
  38450. 0x92, 0xDB, 0xA9, 0xE9, 0x3F, 0xE5, 0x07, 0xC6,
  38451. 0xA7, 0x37, 0x67, 0xBE, 0x56, 0xE2, 0x77, 0x65,
  38452. 0x76, 0xEF, 0xEF, 0xF1, 0xCA, 0x17, 0x9D, 0x83,
  38453. 0x34, 0x3E, 0x38, 0xC6, 0xA9, 0xC2, 0xFE, 0x72,
  38454. 0x5D, 0xDE, 0x80, 0x7D, 0x21, 0x72, 0x5E, 0x73,
  38455. 0x08, 0x72, 0xE2, 0xAB, 0x3D, 0x90, 0x11, 0x61,
  38456. 0xF4, 0x55, 0xBC, 0xAD, 0x23, 0xA8, 0x43, 0x3A,
  38457. 0x41, 0x31, 0x51, 0xFD, 0x22, 0x17, 0x14, 0x31,
  38458. 0x0E, 0x4D, 0x0B, 0x6A, 0x1E, 0x1B, 0x2C, 0xAC,
  38459. 0xA4, 0x99, 0xEE, 0xE8, 0x05, 0xA1, 0x64, 0xF2,
  38460. 0x91, 0xD5, 0x07, 0x5E, 0x6B, 0x65, 0xA7, 0x9C,
  38461. 0x2B, 0xCA, 0xD9, 0x17, 0xB1, 0x22, 0xFE, 0x1A,
  38462. 0xC4, 0xFB, 0xB4, 0x10, 0x21, 0x1B, 0xA0, 0xA1,
  38463. 0x99, 0x7A, 0x31, 0x30, 0x7C, 0x01, 0xF0, 0xFE,
  38464. 0xD3, 0xB3, 0x14, 0x3D, 0x28, 0x34, 0x0F, 0xAC,
  38465. 0xF0, 0x93, 0x37, 0xC4, 0xEF, 0x04, 0x74, 0x80,
  38466. 0xA2, 0x90, 0xAE, 0x02, 0xB2, 0xF7, 0xD8, 0x7B,
  38467. 0x8C, 0x29, 0xA0, 0xAE, 0xAE, 0x2E, 0x92, 0xC9,
  38468. 0xC5, 0x44, 0x7D, 0x66, 0xC5, 0x5C, 0x1D, 0x1E,
  38469. 0x25, 0x88, 0x5D, 0x10, 0x37, 0xFB, 0x5F, 0xCC,
  38470. 0x80, 0x15, 0x4F, 0x1D, 0x23, 0xB4, 0xF2, 0x7B,
  38471. 0x5B, 0xAC, 0x89, 0xBE, 0x1C, 0x36, 0x3C, 0xFF,
  38472. 0x8E, 0xA7, 0x58, 0x73, 0xAC, 0x3F, 0x63, 0x33,
  38473. 0xE8, 0x6C, 0x53, 0xEC, 0xA5, 0x5D, 0xBE, 0xD5,
  38474. 0xE1, 0xF1, 0x12, 0x6B, 0x12, 0x78, 0xC7, 0x29,
  38475. 0xC9, 0xA8, 0x4C, 0x4A, 0x1B, 0x7F, 0x15, 0x11,
  38476. 0x93, 0x01, 0xC8, 0x0B, 0xE2, 0x2F, 0xE9, 0xBE,
  38477. 0xBA, 0x17, 0x59, 0x45, 0xB2, 0x61, 0x2B, 0x66,
  38478. 0xDD, 0xCE, 0xDF, 0x9A, 0x2A, 0x4D, 0x5F, 0x24,
  38479. 0xF9, 0x02, 0xBB, 0xA6, 0x8D, 0xA7, 0x5D, 0x95,
  38480. 0x97, 0x2E, 0x28, 0xD6, 0xCB, 0x70, 0x17, 0xCA,
  38481. 0x51, 0xED, 0x58, 0x73, 0xAB, 0x03, 0xDD, 0x2E,
  38482. 0x92, 0x6C, 0x15, 0x64, 0x2C, 0x9D, 0x6E, 0x64,
  38483. 0x27, 0xFC, 0xE8, 0x0F, 0xC3, 0x8B, 0x34, 0xFE,
  38484. 0xB3, 0xC1, 0x55, 0x13, 0xA6, 0x87, 0xC3, 0x5B,
  38485. 0x94, 0xEB, 0x83, 0xE4, 0xAB, 0x3E, 0x18, 0x76,
  38486. 0x67, 0x92, 0x70, 0xF5, 0xA9, 0x8F, 0x18, 0xA6,
  38487. 0x5F, 0x57, 0x41, 0x76, 0x55, 0xFD, 0xA9, 0x99,
  38488. 0x4E, 0x8F, 0xCC, 0x61, 0x6C, 0x6C, 0x60, 0x06,
  38489. 0x10, 0x40, 0x26, 0xD6, 0xCD, 0x7A, 0xA0, 0x56,
  38490. 0x3D, 0x51, 0x07, 0x25, 0x76, 0x00, 0x05, 0xF5,
  38491. 0xFD, 0x39, 0xE7, 0x59, 0x24, 0x90, 0x29, 0xF0,
  38492. 0x3D, 0x9F, 0x00, 0x67, 0x10, 0x3F, 0xA0, 0x45,
  38493. 0x21, 0x14, 0xDF, 0x24, 0x40, 0xE8, 0xC6, 0xDB,
  38494. 0x65, 0xE2, 0x39, 0x56, 0xEB, 0x1B, 0xEE, 0xB2,
  38495. 0xC3, 0x4E, 0x5B, 0x20, 0xAC, 0x31, 0x6A, 0x03,
  38496. 0xA9, 0x54, 0x36, 0x66, 0x62, 0x68, 0xC3, 0xD8,
  38497. 0x22, 0x8F, 0x62, 0xEB, 0x56, 0x67, 0xB3, 0xB6,
  38498. 0xBB, 0x85, 0x7D, 0xD0, 0x73, 0x7B, 0x69, 0x05,
  38499. 0x1E, 0x9F, 0x26, 0xEE, 0x02, 0x36, 0x71, 0xCE,
  38500. 0xAD, 0xFA, 0xCA, 0xF9, 0x49, 0x7F, 0x1A, 0xDE,
  38501. 0x58, 0x7A, 0x69, 0x3E, 0xEF, 0xFB, 0xFC, 0xD5,
  38502. 0x50, 0xEC, 0x20, 0x8C, 0x23, 0x56, 0x91, 0xE8,
  38503. 0xE3, 0x66, 0xD9, 0x65, 0xB6, 0x2B, 0xEC, 0x16,
  38504. 0xA6, 0x61, 0xCD, 0x5D, 0xE2, 0x87, 0x93, 0x22,
  38505. 0x0D, 0x66, 0xF2, 0x64, 0x55, 0x05, 0xB8, 0x52,
  38506. 0x41, 0x2F, 0xAE, 0x7B, 0x9D, 0x98, 0x29, 0xBF,
  38507. 0x61, 0x5F, 0x7C, 0xBD, 0x59, 0xA7, 0xBC, 0x1D,
  38508. 0x03, 0x4E, 0x6A, 0x25, 0x52, 0x9C, 0xFB, 0x48,
  38509. 0x6A, 0xF2, 0x01, 0xDE, 0xB7, 0xEA, 0x95, 0xBA,
  38510. 0x70, 0x8A, 0x31, 0x59, 0x17, 0x16, 0x74, 0x34,
  38511. 0x53, 0x09, 0xDB, 0x81, 0x50, 0xE6, 0x7E, 0xBB,
  38512. 0x30, 0xA7, 0xFF, 0x80, 0xCA, 0xC9, 0xAB, 0x13,
  38513. 0x92, 0x50, 0x0A, 0x83, 0xE6, 0x3B, 0xBF, 0x7C,
  38514. 0x42, 0xEB, 0x94, 0x53, 0xC2, 0xC9, 0xAC, 0xDA,
  38515. 0x02, 0xBE, 0x53, 0x82, 0x34, 0xAA, 0xA7, 0xDB,
  38516. 0x5A, 0x7F, 0x58, 0x8F, 0xC9, 0x1B, 0x90, 0xEE,
  38517. 0x24, 0x77, 0xF2, 0xB6, 0x1C, 0xD1, 0x06, 0x2A,
  38518. 0x7E, 0xF1, 0xE6, 0xE4, 0xDC, 0x54, 0xB3, 0x6D,
  38519. 0x0E, 0x19, 0x93, 0x3E, 0x98, 0x1C, 0xB7, 0x63,
  38520. 0xA9, 0xE1, 0x07, 0xE0, 0x1D, 0xA9, 0x42, 0x0F,
  38521. 0x82, 0xCA, 0x79, 0x35, 0x92, 0xA4, 0x7C, 0x4B,
  38522. 0x97, 0x7F, 0xF2, 0xC8, 0x84, 0x98, 0xDA, 0x95,
  38523. 0xC4, 0x3D, 0x23, 0x2F, 0x42, 0xAF, 0x99, 0x48,
  38524. 0x0B, 0xF0, 0xA4, 0xF8, 0xB7, 0xC4, 0x94, 0x9D,
  38525. 0x1A, 0xE1, 0xD4, 0xFA, 0x8E, 0x1D, 0x1A, 0x8C,
  38526. 0xD0, 0xF9, 0xED, 0x00, 0xDA, 0x59, 0x5E, 0xFD,
  38527. 0x2B, 0x76, 0x6F, 0x0B, 0x79, 0xD4, 0x49, 0x0D,
  38528. 0xB9, 0x28, 0xEC, 0x44, 0xB5, 0x03, 0x0A, 0x74,
  38529. 0xCA, 0x42, 0x81, 0x1A, 0x5B, 0x5A, 0xE5, 0x22,
  38530. 0xC7, 0x76, 0x4D, 0xDF, 0xD9, 0xFD, 0x92, 0xF0,
  38531. 0x06, 0xE9, 0x4B, 0x35, 0xA7, 0xEF, 0x01, 0x42,
  38532. 0xDA, 0x71, 0x78, 0xC2, 0xF5, 0x30, 0x74, 0xD0,
  38533. 0x74, 0x51, 0xB1, 0x55, 0x65, 0xA9, 0xE0, 0xC5,
  38534. 0x7E, 0xA1, 0xB9, 0x4C, 0x88, 0xEA, 0xE7, 0x41,
  38535. 0xB1, 0xF5, 0x01, 0xC4, 0xD3, 0x70, 0x72, 0x7D,
  38536. 0xAD, 0x27, 0x65, 0xF7, 0x95, 0xAD, 0x41, 0x46,
  38537. 0x35, 0x80, 0x0E, 0xC1, 0x94, 0x9D, 0x03, 0x71,
  38538. 0x39, 0xDE, 0x26, 0xAF, 0xCF, 0x93, 0x3D, 0x9A,
  38539. 0x09, 0xC1, 0x27, 0xFC, 0x6B, 0x36, 0xE5, 0x18,
  38540. 0xC6, 0xDE, 0x94, 0x92, 0xBA, 0x70, 0x82, 0x7B,
  38541. 0x68, 0x1C, 0x2D, 0x18, 0xA4, 0x01, 0x23, 0xB6,
  38542. 0xC5, 0xF6, 0x17, 0x37, 0xCB, 0x9D, 0xC6, 0xAA,
  38543. 0x9C, 0xE1, 0x7D, 0x16, 0x8E, 0xBB, 0xDD, 0xD6,
  38544. 0x3C, 0x07, 0x60, 0x19, 0x3C, 0x97, 0x49, 0x33,
  38545. 0xDB, 0x47, 0x4A, 0xA8, 0x9A, 0xF3, 0x0E, 0x16,
  38546. 0x29, 0x38, 0xF6, 0xDB, 0x78, 0x65, 0xDE, 0x23,
  38547. 0x1F, 0x86, 0x16, 0x9C, 0x9E, 0x2A, 0x30, 0x2F,
  38548. 0xC4, 0x1F, 0x1B, 0xE5, 0xF3, 0x6C, 0x55, 0x83,
  38549. 0xFC, 0xD9, 0x1E, 0x21, 0xCB, 0x8A, 0x67, 0x57,
  38550. 0xD3, 0x0A, 0x4B, 0xAC, 0xDB, 0x67, 0xE7, 0xA6,
  38551. 0x1B, 0x0C, 0x8E, 0x21, 0x7E, 0x0C, 0xCB, 0xF5,
  38552. 0x0E, 0xA6, 0x42, 0xCD, 0xE3, 0xFC, 0x74, 0xC7,
  38553. 0xF9, 0xFF, 0xBD, 0xA9, 0xA1, 0xE6, 0x84, 0xBB,
  38554. 0xC9, 0xA8, 0xF7, 0xCD, 0x3F, 0x1B, 0xD0, 0xDB,
  38555. 0x63, 0xDD, 0xDF, 0x4E, 0xA4, 0x79, 0xC2, 0x35,
  38556. 0x65, 0x2C, 0x5D, 0xCB, 0xCA, 0x7B, 0xDD, 0x4E,
  38557. 0x2F, 0x33, 0xE8, 0x71, 0x72, 0xC1, 0x8B, 0x5F,
  38558. 0xF3, 0x90, 0x99, 0x40, 0x8D, 0x27, 0x2F, 0xD0,
  38559. 0xFB, 0x0D, 0x6A, 0x23, 0xB1, 0x43, 0x00, 0xDF,
  38560. 0xC6, 0x4C, 0x02, 0x74, 0x3E, 0x52, 0x36, 0x08,
  38561. 0xE9, 0x73, 0x61, 0x3D, 0xCA, 0xAC, 0x9D, 0x1D,
  38562. 0x14, 0xB3, 0xA6, 0x24, 0x0E, 0xC2, 0xF2, 0x29,
  38563. 0x39, 0x91, 0xF6, 0x90, 0x6A, 0xE3, 0x6C, 0x04,
  38564. 0x69, 0xF3, 0x09, 0x11, 0x34, 0x8E, 0xC1, 0x2D,
  38565. 0xDB, 0xA6, 0xC3, 0xCA, 0x19, 0xBC, 0x69, 0x5F,
  38566. 0xCD, 0x16, 0xE5, 0xAE, 0xF2, 0xAD, 0x7C, 0x73,
  38567. 0x25, 0x15, 0x70, 0xB5, 0xD0, 0x49, 0xA6, 0xC3,
  38568. 0xA5, 0x2F, 0xA3, 0xFC, 0x9E, 0xD5, 0x4E, 0x54,
  38569. 0x97, 0x3A, 0xE7, 0x89, 0xB0, 0xBF, 0xD6, 0xF8,
  38570. 0xCC, 0x26, 0x44, 0xA9, 0xF8, 0x5A, 0xCE, 0x06,
  38571. 0x78, 0xD8, 0x9E, 0xFC, 0x12, 0xB6, 0x11, 0xC3,
  38572. 0xDF, 0xAE, 0x3F, 0x94, 0x50, 0x34, 0xB8, 0x99,
  38573. 0xBE, 0x99, 0xA7, 0x32, 0x88, 0x9F, 0x17, 0xD2,
  38574. 0x08, 0xDC, 0xD7, 0xEE, 0x95, 0x9D, 0x1A, 0xC7,
  38575. 0x61, 0xDB, 0xA4, 0x86, 0x4C, 0x14, 0xB0, 0xA3,
  38576. 0x5E, 0x4C, 0x7B, 0xBD, 0xA0, 0x96, 0xFB, 0x8A,
  38577. 0xB3, 0x22, 0x69, 0x26, 0xC8, 0x9E, 0x7C, 0xDA,
  38578. 0x92, 0x9E, 0xF1, 0x30, 0xC6, 0x92, 0xC9, 0x26,
  38579. 0x59, 0xE6, 0xF4, 0x65, 0x2B, 0xF2, 0x15, 0x63,
  38580. 0x61, 0xC7, 0x7D, 0xBE, 0xEF, 0x5A, 0x06, 0x23,
  38581. 0xA0, 0x67, 0x04, 0x99, 0x0E, 0x19, 0x8A, 0x13,
  38582. 0x67, 0x30, 0x54, 0x32, 0x4B, 0xBB, 0xAA, 0x64,
  38583. 0x36, 0x92, 0xF2, 0x43, 0xD6, 0x7C, 0x1B, 0x4F,
  38584. 0x95, 0xB9, 0x28, 0xAC, 0xF1, 0x68, 0x6F, 0x60,
  38585. 0xC1, 0x44, 0x87, 0xD6, 0xDD, 0x7F, 0x88, 0x01,
  38586. 0xEF, 0x20, 0x93, 0x9E, 0x03, 0xA1, 0xCA, 0x7D,
  38587. 0x74, 0x32, 0xDC, 0xF5, 0x95, 0xF1, 0xE9, 0xED,
  38588. 0xF2, 0xB2, 0x93, 0x57, 0xA1, 0xD4, 0xC7, 0xDA,
  38589. 0x33, 0x51, 0x2C, 0x45, 0x1A, 0x7C, 0x66, 0x04,
  38590. 0x38, 0x2D, 0x90, 0xC3, 0x30, 0x79, 0xD9, 0x57,
  38591. 0x38, 0xE4, 0x71, 0x89, 0xD8, 0x54, 0x9E, 0x43,
  38592. 0xD2, 0x94, 0xE7, 0x3D, 0x1C, 0xA7, 0x48, 0x7B,
  38593. 0x50, 0xD0, 0xED, 0x7C, 0xC6, 0xF9, 0x6B, 0xEE,
  38594. 0xA7, 0x6C, 0xCE, 0xB9, 0x6D, 0x37, 0x92, 0x00,
  38595. 0x4E, 0xB3, 0xE5, 0x49, 0x16, 0x35, 0xA6, 0x7F,
  38596. 0x6F, 0xFA, 0x1F, 0x1D, 0xF6, 0xA1, 0xF2, 0xFD,
  38597. 0xEE, 0x77, 0x84, 0x17, 0x80, 0xAE, 0x08, 0x09,
  38598. 0xD2, 0x92, 0xED, 0x7B, 0x00, 0xF4, 0x2D, 0x80,
  38599. 0x91, 0x19, 0x09, 0xB5, 0x1C, 0x9A, 0x3A, 0xE5,
  38600. 0x4B, 0x7A, 0x6D, 0x7D, 0x29, 0xD2, 0x00, 0x05,
  38601. 0x22, 0xD4, 0xF8, 0x76, 0xE2, 0x5C, 0x0D, 0x6A,
  38602. 0x15, 0x77, 0x22, 0x18, 0x85, 0xFD, 0x30, 0x74,
  38603. 0xF3, 0x3B, 0xDC, 0xD9, 0x6C, 0xDE, 0x80, 0x40,
  38604. 0x4A, 0x37, 0xE1, 0x60, 0x9F, 0x26, 0xCF, 0xBE,
  38605. 0x24, 0xA1, 0xFB, 0xF9, 0x76, 0x2A, 0x1A, 0x23,
  38606. 0x32, 0xE7, 0xA2, 0xD8, 0x2D, 0xF9, 0xD2, 0x0F,
  38607. 0x08, 0x3A, 0xDB, 0x35, 0x35, 0x33, 0x59, 0x0B,
  38608. 0xB1, 0xF9, 0x54, 0x33, 0x49, 0x36, 0x9E, 0x21,
  38609. 0xEC, 0xF5, 0x94, 0xE2, 0x78, 0x07, 0xA5, 0x63,
  38610. 0x50, 0xD6, 0x23, 0x84, 0xDE, 0xAD, 0xA7, 0x89,
  38611. 0xBE, 0x92, 0xF0, 0x12, 0xC1, 0xF8, 0xA7, 0x2D,
  38612. 0x8B, 0xE0, 0x79, 0xF8, 0xD7, 0xBD, 0x04, 0x0B,
  38613. 0xC5, 0xF2, 0x23, 0x36, 0x11, 0x6D, 0x6F, 0x37,
  38614. 0xDB, 0xFB, 0xD2, 0xC7, 0x44, 0xC3, 0xAE, 0x78,
  38615. 0xEC, 0xB4, 0xE0, 0x5A, 0x55, 0xB3, 0xFC, 0xC3,
  38616. 0x1B, 0x8C, 0xA6, 0xDB, 0xE8, 0x95, 0x72, 0x44,
  38617. 0x90, 0x8F, 0x4E, 0xD1, 0xD3, 0x46, 0x6C, 0x9E,
  38618. 0x00, 0xC6, 0xCC, 0xAE, 0xFC, 0x95, 0x4D, 0x85,
  38619. 0x7C, 0x65, 0x5F, 0x74, 0x71, 0xE3, 0x80, 0x88,
  38620. 0xCF, 0x1E, 0xB8, 0xBE, 0xED, 0x8D, 0xC4, 0xFB,
  38621. 0x3E, 0x36, 0xF3, 0xB8, 0x42, 0x1F, 0x37, 0x31,
  38622. 0x8D, 0xA2, 0x35, 0x36, 0x9E, 0x92, 0x3D, 0xD8,
  38623. 0xEA, 0xA7, 0xA2, 0x29, 0x0E, 0x14, 0xBF, 0x59,
  38624. 0x1E, 0x1D, 0x98, 0x27, 0x30, 0x3B, 0xF3, 0x57,
  38625. 0x69, 0x75, 0xCC, 0x3A, 0xB3, 0x49, 0x99, 0x70,
  38626. 0x19, 0x50, 0xAB, 0xF6, 0x7F, 0xF6, 0x55, 0x1A,
  38627. 0xCA, 0x2D, 0xA0, 0x73, 0x50, 0xE0, 0x9C, 0xEE,
  38628. 0x07, 0xEC, 0x37, 0x26, 0x6B, 0xAA, 0xA5, 0x34,
  38629. 0xFD, 0x7B, 0x1A, 0x92, 0x4E, 0xE7, 0x36, 0x1A,
  38630. 0xEB, 0x35, 0xCC, 0x5A, 0x5C, 0x06, 0x7F, 0x77,
  38631. 0xCE, 0x52, 0x33, 0x57, 0x73, 0x9D, 0xEC, 0x2D,
  38632. 0x28, 0x0C, 0xC9, 0xBF, 0x06, 0x9E, 0xA7, 0x7C,
  38633. 0x36, 0xF9, 0x0B, 0xC6, 0x7F, 0x0F, 0x66, 0x24,
  38634. 0x65, 0x2D, 0x30, 0x2B, 0xD7, 0x7F, 0x07, 0xD3,
  38635. 0x57, 0xC8, 0x4B, 0xC3, 0x0C, 0xA3, 0x5B, 0xAA,
  38636. 0xAF, 0xEA, 0xF3, 0xA3, 0x9E, 0x9E, 0xD4, 0x63,
  38637. 0xCD, 0x82, 0x8B, 0xBC, 0x5D, 0xEF, 0xE6, 0x2A,
  38638. 0x4D, 0x5B, 0x95, 0x13, 0x17, 0x98, 0xD3, 0x67,
  38639. 0x66, 0x04, 0x9E, 0x71, 0x71, 0xE6, 0xBD, 0x44,
  38640. 0x15, 0x6B, 0x29, 0x76, 0xE4, 0x62, 0x01, 0x99,
  38641. 0xEB, 0xF4, 0x2E, 0x14, 0x29, 0x0D, 0xBF, 0x8A,
  38642. 0x02, 0x30, 0x4A, 0xE7, 0x0D, 0x25, 0x42, 0x9E,
  38643. 0xD7, 0x0C, 0xAD, 0x30, 0xC6, 0xA3, 0x49, 0xF9,
  38644. 0x90, 0x0C, 0x46, 0x5B, 0x77, 0x67, 0x5F, 0x0B,
  38645. 0xE9, 0xA9, 0xFE, 0xFA, 0xC8, 0x5F, 0x19, 0xF7,
  38646. 0x35, 0x09, 0xF7, 0xB5, 0x6D, 0x51, 0x32, 0x17,
  38647. 0xBE, 0xE6, 0xC3, 0xBE, 0x4A, 0x9A, 0x33, 0xDA,
  38648. 0xC6, 0x90, 0xB7, 0xA7, 0x6F, 0x97, 0x9E, 0xD5,
  38649. 0x80, 0xE5, 0x02, 0x9E, 0x58, 0xD6, 0x45, 0x34,
  38650. 0x4D, 0x61, 0x71, 0x19, 0x07, 0x69, 0x1F, 0xAF,
  38651. 0xFF, 0x9F, 0xDE, 0x97, 0x13, 0xA1, 0xDF, 0x47,
  38652. 0x0E, 0x8B, 0xD6, 0xD0, 0x75, 0x40, 0x08, 0x59,
  38653. 0x7D, 0xFB, 0x74, 0x74, 0xF2, 0x48, 0xF4, 0x23,
  38654. 0x1B, 0x5E, 0x18, 0x4E, 0x2D, 0x2D, 0xC5, 0x40,
  38655. 0xD0, 0x90, 0x4F, 0x95, 0x69, 0xC4, 0xDA, 0xFB,
  38656. 0x39, 0x4B, 0x12, 0x7D, 0x22, 0x1E, 0x9A, 0x68,
  38657. 0x5B, 0x68, 0x2E, 0x47, 0x23, 0xB9, 0x6A, 0xBF,
  38658. 0xF7, 0xE2, 0x56, 0x79, 0xDD, 0x7A, 0x72, 0xF9,
  38659. 0x5F, 0x20, 0x6B, 0x29, 0x56, 0xEE, 0x04, 0x11,
  38660. 0x4C, 0x16, 0x34, 0x04, 0x14, 0x54, 0xB5, 0x21,
  38661. 0xAA, 0x6A, 0x46, 0x40, 0xE4, 0xF1, 0x78, 0x7C,
  38662. 0x50, 0xF3, 0x4D, 0xBC, 0x57, 0x34, 0x7C, 0x6A,
  38663. 0xBD, 0x9B, 0xEF, 0x03, 0x80, 0x7D, 0xAB, 0x20,
  38664. 0x0F, 0x77, 0x87, 0x6F, 0x93, 0xFB, 0x24, 0x20,
  38665. 0x82, 0xC7, 0x7E, 0xFB, 0x43, 0x2D, 0xC6, 0xD4,
  38666. 0xE9, 0x27, 0x8C, 0x66, 0xA8, 0x5A, 0x58, 0xC8,
  38667. 0xD8, 0x9A, 0xA8, 0x50, 0x5F, 0x3A, 0x3D, 0x0B,
  38668. 0xC3, 0x4F, 0xCE, 0x94, 0xE0, 0x0D, 0x16, 0xCB,
  38669. 0x20, 0xE0, 0xF5, 0x1A, 0x13, 0x6E, 0x28, 0xA6,
  38670. 0x42, 0xB2, 0xB1, 0x30, 0x1D, 0x56, 0x28, 0xCD,
  38671. 0xF3, 0x4E, 0xA7, 0x3E, 0x74, 0x04, 0x7D, 0xA5,
  38672. 0x86, 0xD9, 0x1A, 0xDF, 0x07, 0xBC, 0x2C, 0x59,
  38673. 0xB1, 0x91, 0x6D, 0x9B, 0xA2, 0xD0, 0x72, 0xE7,
  38674. 0xA5, 0x56, 0x4A, 0x27, 0x56, 0x1F, 0x65, 0xCD,
  38675. 0x90, 0x7B, 0xB7, 0x5A, 0x51, 0x25, 0x75, 0x1B,
  38676. 0xD9, 0xD4, 0xC7, 0x19, 0x8A, 0xB0, 0x3D, 0x38,
  38677. 0x22, 0x61, 0xCF, 0xD9, 0x66, 0xED, 0xF5, 0xB8,
  38678. 0xF5, 0x86, 0xFF, 0x98, 0x1A, 0xB7, 0xFB, 0x67,
  38679. 0xED, 0x25, 0x52, 0xD9, 0x2F, 0x84, 0xDC, 0x96,
  38680. 0x89, 0x2C, 0x52, 0xCF, 0x5F, 0xA0, 0xEA, 0xD0,
  38681. 0xB3, 0x38, 0x98, 0xFC, 0xD7, 0x50, 0x84, 0xCF,
  38682. 0xA5, 0xE9, 0x53, 0x8B, 0x44, 0x38, 0xB5, 0x7D,
  38683. 0xD8, 0xAD, 0x0A, 0xE5, 0x35, 0x78, 0x29, 0xBF,
  38684. 0x9F, 0x6B, 0x2C, 0xBB, 0x97, 0x9D, 0xD3, 0x64,
  38685. 0x23, 0x2B, 0xA8, 0xA4, 0x71, 0xE3, 0xF1, 0x2F,
  38686. 0x61, 0xC9, 0x68, 0xD2, 0x06, 0xD0, 0x4E, 0x87,
  38687. 0x03, 0x99, 0xCC, 0xB1, 0x83, 0xB6, 0x94, 0x61,
  38688. 0x3C, 0xE9, 0xE0, 0x7D, 0x13, 0xAF, 0xCF, 0xE4,
  38689. 0xA6, 0x42, 0x7F, 0x62, 0x8F, 0xFC, 0x10, 0xF1,
  38690. 0x08, 0x4D, 0x1D, 0xFC, 0x0F, 0x37, 0x11, 0xBE,
  38691. 0xD7, 0xF1, 0x80, 0x46, 0xAF, 0xFA, 0x13, 0x65,
  38692. 0x99, 0xAE, 0xF9, 0xD0, 0x13, 0xA7, 0xC7, 0x3A,
  38693. 0xD2, 0xC1, 0x9B, 0x5A, 0xB8, 0xC3, 0x08, 0x13,
  38694. 0x49, 0x40, 0x33, 0x0D, 0x1F, 0x93, 0x5D, 0x10,
  38695. 0x49, 0x3E, 0x4F, 0x90, 0x34, 0xC5, 0xEA, 0xF7,
  38696. 0x24, 0xFF, 0xF3, 0xC5, 0x95, 0xF7, 0x1F, 0x13,
  38697. 0x9A, 0xE0, 0x0C, 0xCD, 0x61, 0x93, 0x39, 0xE6,
  38698. 0xAF, 0xD5, 0x3E, 0xA9, 0xD8, 0xC4, 0x8F, 0x64,
  38699. 0x05, 0x09, 0x45, 0x2A, 0xEB, 0x12, 0xC5, 0x51,
  38700. 0x58, 0x1C, 0x55, 0x20, 0xE9, 0x29, 0x74, 0xC7,
  38701. 0x10, 0x01, 0xF3, 0xA4, 0x56, 0xB4, 0x14, 0xFE,
  38702. 0x9C, 0x10, 0x2F, 0xF8, 0xBF, 0xB5, 0x9C, 0x6E,
  38703. 0xBB, 0xE6, 0x52, 0xE7, 0xAC, 0xA7, 0xCE, 0x41,
  38704. 0x6E, 0x00, 0x66, 0x0A, 0x2F, 0x46, 0x71, 0xB8,
  38705. 0x8F, 0x45, 0x89, 0x26, 0x68, 0xCD, 0x49, 0xDF,
  38706. 0xCB, 0xCD, 0xD6, 0x66, 0xC6, 0xA7, 0x8E, 0xB3,
  38707. 0xE4, 0x72, 0xEF, 0xBA, 0xA6, 0x6D, 0x7A, 0xB7,
  38708. 0xE9, 0xD9, 0xB2, 0x60, 0xB5, 0x82, 0x77, 0x20,
  38709. 0x2A, 0xFA, 0xE3, 0xCB, 0xF5, 0x30, 0x50, 0x30,
  38710. 0xC6, 0x19, 0x67, 0xA8, 0xB8, 0xFA, 0xFE, 0xB6,
  38711. 0xDA, 0xB6, 0xB6, 0xBF, 0x07, 0x90, 0x40, 0xD8,
  38712. 0x5B, 0x15, 0x48, 0x39, 0xCD, 0x99, 0x0F, 0x3A,
  38713. 0x28, 0xD2, 0x2E, 0xBA, 0xAC, 0x6D, 0xA3, 0xF8,
  38714. 0x53, 0x88, 0xF0, 0x86, 0x87, 0x70, 0xF5, 0x07,
  38715. 0xD2, 0x99, 0xC4, 0xCA, 0xDD, 0xD8, 0x8C, 0xEB,
  38716. 0x00, 0x96, 0xB4, 0x62, 0xA3, 0x7B, 0x79, 0x31,
  38717. 0xB2, 0x85, 0xB0, 0x61, 0x39, 0xF2, 0xBC, 0x1D,
  38718. 0x31, 0xC3, 0x0C, 0x7F, 0x70, 0x9A, 0x63, 0x74,
  38719. 0xC6, 0xCB, 0xD3, 0x93, 0x0D, 0x43, 0x7F, 0x80,
  38720. 0x85, 0x87, 0x72, 0x98, 0xE1, 0x6E, 0x9A, 0x59,
  38721. 0x2E, 0x6C, 0xA8, 0x9E, 0xC2, 0xC0, 0x72, 0xFE,
  38722. 0x26, 0xE8, 0xAF, 0x89, 0x61, 0xCA, 0x0D, 0x15,
  38723. 0xCC, 0xB0, 0xBA, 0x10, 0xB8, 0x9D, 0x77, 0x2C,
  38724. 0x6C, 0x28, 0xCC, 0x70, 0x5B, 0x1F, 0x5D, 0x68,
  38725. 0xD4, 0xC8, 0x1F, 0x0F, 0x67, 0xF5, 0x3E, 0x5C,
  38726. 0x70, 0x50, 0x4B, 0x32, 0x12, 0xE6, 0x1A, 0xCE,
  38727. 0xB8, 0x32, 0x5F, 0x1D, 0xC5, 0xFB, 0x07, 0x77,
  38728. 0xAD, 0x85, 0x45, 0x95, 0x04, 0x0D, 0x94, 0x7A,
  38729. 0x1F, 0xDD, 0x05, 0x74, 0x14, 0xA5, 0x9A, 0x66,
  38730. 0xF4, 0x93, 0xBE, 0xF2, 0xA9, 0x5B, 0xCD, 0xAB,
  38731. 0xC7, 0x82, 0xF7, 0xE7, 0x4A, 0x1C, 0x90, 0x6B,
  38732. 0x9A, 0xBD, 0x93, 0xDD, 0x41, 0x56, 0xDA, 0xA5,
  38733. 0x0F, 0x5D, 0x57, 0x2C, 0xBA, 0x07, 0x07, 0x4B,
  38734. 0x91, 0x33, 0xE6, 0x1B, 0x0E, 0x25, 0x9E, 0x36,
  38735. 0xBF, 0xCA, 0x21, 0xCE, 0xC6, 0x82, 0x33, 0x4D,
  38736. 0x42, 0x4F, 0x2E, 0x71, 0xC2, 0xE7, 0x6F, 0x16,
  38737. 0xF6, 0xB7, 0x30, 0x1C, 0xA1, 0xA8, 0xE3, 0xE7,
  38738. 0xB1, 0x71, 0xDD, 0x9F, 0x90, 0x1F, 0x01, 0x1D,
  38739. 0x0A, 0xBD, 0x2C, 0x4A, 0x22, 0x84, 0x5C, 0xBF,
  38740. 0x61, 0x07, 0x24, 0xC4, 0x0D, 0x23, 0xDB, 0xC6,
  38741. 0x28, 0xB1, 0x27, 0xCB, 0x7E, 0x06, 0xF8, 0x3C,
  38742. 0x42, 0xF9, 0x51, 0x2F, 0x21, 0xC5, 0x80, 0x98,
  38743. 0x08, 0x2F, 0x56, 0x58, 0xD7, 0xE0, 0xDA, 0xC4,
  38744. 0x24, 0x0C, 0xE8, 0xFA, 0x94, 0x23, 0x57, 0xA6,
  38745. 0xD8, 0xE2, 0xC5, 0xCC, 0x16, 0x70, 0x55, 0x57,
  38746. 0xC4, 0x52, 0x2D, 0x94, 0xCE, 0x5B, 0x22, 0x8E,
  38747. 0x6C, 0x3D, 0x8E, 0x74, 0x9D, 0xFD, 0x47, 0xC7,
  38748. 0x42, 0x11, 0x41, 0x9F, 0x6A, 0x0A, 0xF6, 0x16,
  38749. 0x97, 0xB1, 0x24, 0xC4, 0x6C, 0x98, 0xF8, 0x62,
  38750. 0x51, 0xE9, 0x67, 0x6D, 0x39, 0x2B, 0x76, 0x19,
  38751. 0x5F, 0x41, 0xF4, 0x82, 0x51, 0x87, 0xFF, 0xAA,
  38752. 0x87, 0xE3, 0x46, 0x87, 0xC0, 0xC9, 0xBB, 0xB5,
  38753. 0xAC, 0xA0, 0xD1, 0x56, 0x54, 0xC2, 0x2C, 0x59,
  38754. 0x9E, 0x78, 0xF9, 0xA6, 0xBA, 0xCB, 0xE2, 0x45,
  38755. 0x8A, 0xC1, 0xE5, 0xDF, 0xC3, 0x81, 0x91, 0xDB,
  38756. 0xDB, 0x9E, 0xE2, 0x9C, 0xB9, 0x44, 0x5F, 0x5D,
  38757. 0x6D, 0x83, 0x8D, 0x2D, 0x3E, 0x72, 0x2F, 0x98,
  38758. 0xFC, 0xFA, 0x5F, 0xC0, 0xF0, 0x03, 0x4A, 0x42,
  38759. 0x19, 0x67, 0x48, 0x24, 0x70, 0x35, 0xAE, 0x37,
  38760. 0x34, 0x27, 0xAB, 0xD6, 0x92, 0xB8, 0xB4, 0x52,
  38761. 0xC9, 0xD1, 0xF0, 0x5C, 0xAC, 0xFA, 0xB9, 0x2D,
  38762. 0xCE, 0xF2, 0x24, 0xE3, 0x53, 0xF4, 0x2D, 0x65,
  38763. 0x8D, 0xBF, 0x27, 0x3F, 0xAF, 0x62, 0xE0, 0x27,
  38764. 0xBE, 0x12, 0xCB, 0x40, 0xA4, 0x99, 0xAF, 0x47,
  38765. 0x19, 0x5F, 0x68, 0x69, 0x7F, 0x8C, 0xD2, 0x1E,
  38766. 0x4A, 0xA1, 0xA4, 0x3D, 0x5A, 0x62, 0x6F, 0x78,
  38767. 0x87, 0x8E, 0xA0, 0xC0, 0xF3, 0x2C, 0x60, 0xC3,
  38768. 0xCE, 0xDD, 0xED, 0x7C, 0xAF, 0xE0, 0x0B, 0x72,
  38769. 0x9D, 0xBA, 0xC6, 0xEE, 0x00, 0x00, 0x00, 0x00,
  38770. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  38771. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
  38772. 0x0B, 0x15, 0x1B, 0x1E, 0x24
  38773. };
  38774. #endif
  38775. #ifndef WOLFSSL_NO_ML_DSA_87
  38776. static const byte sk_87[] = {
  38777. 0xF1, 0x79, 0x16, 0xD9, 0x5C, 0x51, 0x2F, 0xEC,
  38778. 0x0C, 0xEF, 0xA6, 0xA1, 0x5C, 0x9F, 0xB3, 0xBF,
  38779. 0x84, 0xFF, 0x8D, 0x7F, 0xA3, 0x55, 0x22, 0xEB,
  38780. 0x1C, 0x91, 0x5C, 0x4D, 0x25, 0x4E, 0x89, 0x35,
  38781. 0x24, 0x8E, 0x3C, 0x08, 0x58, 0x2B, 0x74, 0x5E,
  38782. 0xB2, 0xFD, 0x13, 0x15, 0x2B, 0x5D, 0xAE, 0xEA,
  38783. 0xB0, 0x72, 0x80, 0x42, 0xB0, 0x08, 0x85, 0xBB,
  38784. 0x92, 0xF8, 0x44, 0xA8, 0x6B, 0x42, 0x62, 0x03,
  38785. 0x5C, 0x9F, 0x44, 0x8A, 0x2B, 0x78, 0xEF, 0x5D,
  38786. 0xB3, 0x47, 0xE0, 0x25, 0x04, 0x15, 0xE1, 0x01,
  38787. 0x5F, 0xBB, 0x34, 0x31, 0x91, 0x24, 0x07, 0xC8,
  38788. 0x5A, 0x2F, 0x36, 0x2A, 0x85, 0xA9, 0xAE, 0x42,
  38789. 0x77, 0x23, 0xBF, 0x62, 0x69, 0x7B, 0x77, 0x99,
  38790. 0x1B, 0x3E, 0x93, 0xA3, 0x81, 0x13, 0x3F, 0x95,
  38791. 0x0D, 0x40, 0xE7, 0xC1, 0xAC, 0xBC, 0x17, 0xE4,
  38792. 0xF1, 0xD1, 0x0C, 0xD1, 0x27, 0x4C, 0x8D, 0x3C,
  38793. 0x84, 0x02, 0x02, 0x0A, 0xC5, 0x10, 0x1C, 0xC3,
  38794. 0x4D, 0xD0, 0x94, 0x70, 0x24, 0xC0, 0x89, 0x94,
  38795. 0x08, 0x4D, 0xC2, 0x30, 0x20, 0x63, 0xC0, 0x24,
  38796. 0xE1, 0x80, 0x40, 0xD0, 0x26, 0x68, 0x10, 0x97,
  38797. 0x01, 0x83, 0xC2, 0x91, 0x5A, 0x90, 0x2D, 0x44,
  38798. 0x94, 0x6D, 0x10, 0x09, 0x50, 0x11, 0xA7, 0x0D,
  38799. 0xE4, 0x04, 0x89, 0x9B, 0x80, 0x8D, 0x40, 0xB8,
  38800. 0x45, 0x4B, 0x86, 0x0D, 0xC8, 0xB6, 0x05, 0xC0,
  38801. 0xC0, 0x71, 0x02, 0x09, 0x06, 0xA2, 0x00, 0x2D,
  38802. 0x0B, 0x24, 0x86, 0xA0, 0x90, 0x11, 0x20, 0x16,
  38803. 0x82, 0x1B, 0x24, 0x42, 0xCB, 0xB6, 0x70, 0x43,
  38804. 0x36, 0x05, 0xDA, 0x16, 0x25, 0x9A, 0x34, 0x6C,
  38805. 0xCB, 0xB4, 0x08, 0xC4, 0x16, 0x90, 0x24, 0x29,
  38806. 0x6C, 0x42, 0x90, 0x04, 0x24, 0x06, 0x46, 0x84,
  38807. 0x12, 0x6D, 0xC2, 0x26, 0x00, 0x88, 0x40, 0x02,
  38808. 0x51, 0xC8, 0x40, 0x9C, 0x16, 0x24, 0x82, 0x18,
  38809. 0x26, 0x21, 0x06, 0x0C, 0x12, 0xC2, 0x71, 0x50,
  38810. 0x98, 0x91, 0x4A, 0x40, 0x28, 0x48, 0x48, 0x21,
  38811. 0x5A, 0x18, 0x49, 0x1B, 0xB7, 0x01, 0x5A, 0xC6,
  38812. 0x48, 0xA1, 0x90, 0x2C, 0x14, 0x18, 0x2D, 0xD2,
  38813. 0x20, 0x62, 0xDC, 0xB6, 0x49, 0x00, 0x09, 0x6D,
  38814. 0x40, 0xA8, 0x4D, 0x24, 0xC8, 0x24, 0x4C, 0x06,
  38815. 0x08, 0x80, 0x40, 0x4E, 0xD3, 0x18, 0x88, 0x12,
  38816. 0x09, 0x91, 0x8B, 0x12, 0x31, 0xC9, 0x16, 0x04,
  38817. 0x64, 0x10, 0x72, 0xDA, 0x84, 0x91, 0x92, 0xC6,
  38818. 0x65, 0x22, 0x10, 0x48, 0x18, 0xC9, 0x00, 0x14,
  38819. 0x44, 0x62, 0x24, 0xC1, 0x60, 0x40, 0xC6, 0x10,
  38820. 0x4A, 0x48, 0x28, 0x9B, 0x44, 0x66, 0x91, 0x10,
  38821. 0x52, 0xD3, 0x26, 0x52, 0xD8, 0xA6, 0x0C, 0x0A,
  38822. 0xA8, 0x44, 0xD8, 0x26, 0x0C, 0x64, 0x86, 0x45,
  38823. 0x44, 0x20, 0x00, 0xD2, 0x48, 0x85, 0xDC, 0x46,
  38824. 0x32, 0xC8, 0x22, 0x45, 0x5B, 0x00, 0x8D, 0x20,
  38825. 0xA5, 0x45, 0x01, 0xC1, 0x91, 0xA2, 0x12, 0x84,
  38826. 0x20, 0x47, 0x0E, 0x98, 0xA8, 0x25, 0xD9, 0xA0,
  38827. 0x4D, 0xA4, 0x06, 0x2D, 0x5B, 0xB0, 0x08, 0x21,
  38828. 0xB0, 0x80, 0x4C, 0x10, 0x2C, 0xC4, 0x98, 0x71,
  38829. 0x99, 0x24, 0x24, 0xA4, 0x36, 0x71, 0x4B, 0xB6,
  38830. 0x49, 0xE1, 0x92, 0x00, 0x09, 0x92, 0x4C, 0x89,
  38831. 0x12, 0x49, 0x1A, 0x39, 0x2A, 0xE0, 0x22, 0x69,
  38832. 0x61, 0xB2, 0x50, 0x40, 0x26, 0x8E, 0xC9, 0xA2,
  38833. 0x08, 0x0A, 0x90, 0x24, 0x13, 0x35, 0x06, 0x21,
  38834. 0x24, 0x62, 0x60, 0xB0, 0x01, 0xE3, 0xC6, 0x29,
  38835. 0x5B, 0x28, 0x89, 0x20, 0x90, 0x70, 0xC4, 0xA4,
  38836. 0x31, 0x08, 0x42, 0x11, 0x10, 0xC0, 0x71, 0x98,
  38837. 0x98, 0x20, 0xC4, 0xA8, 0x29, 0x1A, 0x15, 0x32,
  38838. 0xC4, 0x86, 0x6C, 0x18, 0x14, 0x6A, 0x02, 0x46,
  38839. 0x46, 0xDC, 0xC2, 0x4C, 0x81, 0x02, 0x6D, 0x49,
  38840. 0x16, 0x48, 0x10, 0x94, 0x6C, 0x0A, 0x85, 0x90,
  38841. 0x9C, 0x34, 0x84, 0x54, 0x24, 0x25, 0x49, 0xA8,
  38842. 0x21, 0x04, 0xA6, 0x2C, 0x61, 0x00, 0x01, 0x61,
  38843. 0x46, 0x92, 0xE0, 0xA6, 0x44, 0xE2, 0x00, 0x90,
  38844. 0xC8, 0x06, 0x06, 0x90, 0xB8, 0x2D, 0x0B, 0x85,
  38845. 0x85, 0x20, 0x23, 0x0D, 0x83, 0x94, 0x04, 0x54,
  38846. 0x26, 0x50, 0x41, 0x92, 0x29, 0x09, 0x16, 0x20,
  38847. 0x54, 0xC6, 0x2D, 0x81, 0xC8, 0x8C, 0x09, 0x44,
  38848. 0x44, 0xE2, 0x06, 0x30, 0x13, 0x92, 0x49, 0x0B,
  38849. 0x17, 0x48, 0x93, 0x28, 0x86, 0xD8, 0xA4, 0x50,
  38850. 0xD1, 0x32, 0x91, 0x08, 0xB8, 0x05, 0xA4, 0x02,
  38851. 0x62, 0x01, 0x15, 0x82, 0xE3, 0x18, 0x42, 0x83,
  38852. 0xC6, 0x44, 0x43, 0x02, 0x81, 0x53, 0x88, 0x04,
  38853. 0x04, 0x98, 0x31, 0x19, 0x18, 0x46, 0xDB, 0x02,
  38854. 0x89, 0x10, 0x23, 0x81, 0x03, 0x90, 0x71, 0x83,
  38855. 0x26, 0x89, 0x1A, 0x01, 0x05, 0xCA, 0xB0, 0x01,
  38856. 0x4C, 0x84, 0x09, 0x10, 0x11, 0x84, 0x13, 0xB1,
  38857. 0x20, 0x61, 0xB8, 0x41, 0x1B, 0x02, 0x8C, 0x09,
  38858. 0x98, 0x61, 0x83, 0x18, 0x61, 0x08, 0xC1, 0x6D,
  38859. 0x44, 0x86, 0x09, 0xCB, 0x88, 0x8D, 0x93, 0xB4,
  38860. 0x41, 0x58, 0x90, 0x81, 0x04, 0x31, 0x08, 0xD1,
  38861. 0xC4, 0x04, 0x19, 0xB4, 0x4C, 0x1C, 0x88, 0x20,
  38862. 0xCA, 0x30, 0x72, 0x1C, 0xB5, 0x85, 0x13, 0x27,
  38863. 0x32, 0x84, 0xB4, 0x44, 0x04, 0x42, 0x20, 0x61,
  38864. 0x18, 0x52, 0x50, 0x96, 0x44, 0x03, 0x38, 0x86,
  38865. 0xE3, 0x48, 0x31, 0x02, 0x82, 0x68, 0x98, 0x06,
  38866. 0x90, 0x23, 0x28, 0x04, 0x10, 0x18, 0x0D, 0x10,
  38867. 0x28, 0x45, 0x4C, 0x84, 0x6C, 0x09, 0x36, 0x71,
  38868. 0x82, 0x26, 0x64, 0x18, 0xC6, 0x21, 0x90, 0x18,
  38869. 0x22, 0x0A, 0x37, 0x08, 0xC4, 0x94, 0x28, 0xE2,
  38870. 0x30, 0x2C, 0x92, 0xB4, 0x24, 0x63, 0x46, 0x70,
  38871. 0x52, 0x96, 0x0C, 0x8B, 0xA4, 0x05, 0xD3, 0x02,
  38872. 0x85, 0x09, 0x32, 0x92, 0x49, 0x12, 0x21, 0x18,
  38873. 0x43, 0x28, 0x01, 0x32, 0x45, 0x0B, 0xA5, 0x50,
  38874. 0x14, 0x16, 0x65, 0x91, 0x80, 0x65, 0x0A, 0x44,
  38875. 0x66, 0x13, 0xB6, 0x4C, 0x01, 0x38, 0x71, 0x11,
  38876. 0x49, 0x28, 0x22, 0x43, 0x02, 0x0B, 0x34, 0x04,
  38877. 0x01, 0x16, 0x91, 0x80, 0x14, 0x0E, 0x12, 0x93,
  38878. 0x01, 0x00, 0x11, 0x80, 0xDC, 0x28, 0x51, 0x11,
  38879. 0x87, 0x85, 0xC1, 0x34, 0x28, 0x02, 0xA2, 0x11,
  38880. 0x02, 0x38, 0x44, 0x52, 0x14, 0x64, 0xC2, 0xA0,
  38881. 0x01, 0x1B, 0x42, 0x8C, 0xC2, 0xB2, 0x71, 0xCB,
  38882. 0x16, 0x00, 0xCC, 0x10, 0x21, 0x04, 0x12, 0x52,
  38883. 0x84, 0x24, 0x2A, 0xD3, 0x48, 0x12, 0x08, 0x44,
  38884. 0x08, 0x81, 0x88, 0x44, 0x01, 0x23, 0x50, 0xC0,
  38885. 0xA2, 0x09, 0x81, 0x94, 0x50, 0x02, 0x89, 0x61,
  38886. 0x01, 0x31, 0x88, 0x1B, 0xA2, 0x61, 0x90, 0x94,
  38887. 0x84, 0x91, 0x24, 0x09, 0x03, 0x18, 0x22, 0xA3,
  38888. 0x46, 0x60, 0x10, 0x16, 0x4D, 0x48, 0x84, 0x89,
  38889. 0x11, 0x00, 0x2E, 0xCC, 0xC0, 0x40, 0x8C, 0xC0,
  38890. 0x51, 0xE4, 0x42, 0x62, 0xDA, 0x24, 0x11, 0x13,
  38891. 0x19, 0x46, 0x93, 0x34, 0x4C, 0x42, 0x42, 0x24,
  38892. 0xC4, 0x48, 0x90, 0x00, 0x35, 0x80, 0x1B, 0x98,
  38893. 0x51, 0x0B, 0x41, 0x60, 0x0C, 0x25, 0x46, 0x9A,
  38894. 0xA8, 0x89, 0x12, 0x86, 0x4C, 0xE3, 0x16, 0x09,
  38895. 0x14, 0x27, 0x24, 0x51, 0x26, 0x4D, 0x1B, 0x02,
  38896. 0x10, 0x00, 0x17, 0x28, 0xD4, 0xA8, 0x45, 0x48,
  38897. 0x88, 0x48, 0x01, 0xC7, 0x0D, 0x93, 0xC8, 0x40,
  38898. 0x5B, 0x02, 0x49, 0x51, 0x02, 0x4A, 0x01, 0x42,
  38899. 0x10, 0xE1, 0x08, 0x90, 0x03, 0x85, 0x48, 0x11,
  38900. 0xA8, 0x68, 0x8B, 0x90, 0x08, 0x5A, 0x02, 0x0C,
  38901. 0x5A, 0x18, 0x50, 0x11, 0x87, 0x51, 0x9C, 0x38,
  38902. 0x92, 0xD0, 0x44, 0x82, 0x10, 0x33, 0x21, 0x88,
  38903. 0x44, 0x2D, 0x24, 0x28, 0x0D, 0x22, 0xA3, 0x30,
  38904. 0x49, 0x88, 0x25, 0xA1, 0xB2, 0x01, 0x5C, 0x40,
  38905. 0x20, 0x1C, 0x03, 0x72, 0xCC, 0x96, 0x8C, 0x51,
  38906. 0xA6, 0x88, 0xE3, 0x92, 0x08, 0x13, 0xB0, 0x08,
  38907. 0x5C, 0x38, 0x44, 0x03, 0x47, 0x8E, 0x93, 0x12,
  38908. 0x4A, 0x88, 0x20, 0x48, 0xE0, 0x42, 0x20, 0x81,
  38909. 0x90, 0x09, 0x4B, 0x06, 0x6D, 0xD2, 0x90, 0x10,
  38910. 0x01, 0x82, 0x49, 0x19, 0x28, 0x91, 0xDA, 0x20,
  38911. 0x2A, 0x20, 0x85, 0x40, 0x0A, 0x16, 0x8A, 0x1C,
  38912. 0x83, 0x60, 0xCA, 0x48, 0x4A, 0xA2, 0xC8, 0x50,
  38913. 0xE4, 0x02, 0x31, 0x88, 0x86, 0x88, 0x53, 0x00,
  38914. 0x89, 0x60, 0x08, 0x8A, 0xA2, 0x02, 0x0A, 0x0A,
  38915. 0x34, 0x45, 0x03, 0x04, 0x42, 0x1B, 0x40, 0x09,
  38916. 0x89, 0xA0, 0x69, 0x42, 0x18, 0x49, 0x4A, 0xA8,
  38917. 0x8C, 0x99, 0x90, 0x30, 0xCA, 0x38, 0x91, 0x09,
  38918. 0x31, 0x72, 0x8B, 0x44, 0x29, 0x52, 0xA2, 0x8D,
  38919. 0x08, 0x14, 0x6E, 0xA1, 0x84, 0x50, 0x1C, 0x31,
  38920. 0x46, 0x19, 0xB7, 0x01, 0xCC, 0x06, 0x29, 0x11,
  38921. 0x09, 0x20, 0x4B, 0x40, 0x66, 0x40, 0xC4, 0x49,
  38922. 0x00, 0x13, 0x24, 0xD0, 0xA2, 0x84, 0xCA, 0x16,
  38923. 0x29, 0xD0, 0xC0, 0x84, 0xC8, 0x88, 0x44, 0xE1,
  38924. 0x20, 0x29, 0x1A, 0x97, 0x05, 0x90, 0x42, 0x90,
  38925. 0x04, 0x40, 0x71, 0x9C, 0x32, 0x4E, 0x64, 0x26,
  38926. 0x22, 0x93, 0x36, 0x66, 0xD3, 0x06, 0x49, 0xA3,
  38927. 0x26, 0x51, 0x4C, 0xA6, 0x89, 0x84, 0x36, 0x84,
  38928. 0x93, 0x46, 0x6D, 0x14, 0x07, 0x8D, 0x18, 0x29,
  38929. 0x42, 0x52, 0x34, 0x72, 0x44, 0x10, 0x90, 0x12,
  38930. 0x37, 0x81, 0xD4, 0x10, 0x64, 0x04, 0xA5, 0x08,
  38931. 0x84, 0x24, 0x09, 0x1C, 0x08, 0x8D, 0x02, 0x99,
  38932. 0x6C, 0x1B, 0x30, 0x50, 0x09, 0x89, 0x81, 0x19,
  38933. 0x30, 0x48, 0x5B, 0x14, 0x4D, 0xD9, 0x20, 0x20,
  38934. 0x0C, 0x01, 0x2A, 0x00, 0x90, 0x4D, 0xA1, 0x02,
  38935. 0x64, 0x1C, 0x03, 0x01, 0xC2, 0x26, 0x8C, 0x14,
  38936. 0x08, 0x45, 0xE3, 0x12, 0x48, 0x09, 0x20, 0x09,
  38937. 0x41, 0x40, 0x61, 0x90, 0x44, 0x21, 0x49, 0x06,
  38938. 0x91, 0x4B, 0xC0, 0x84, 0x22, 0x95, 0x51, 0x23,
  38939. 0x38, 0x0E, 0x5C, 0x28, 0x70, 0xC2, 0x40, 0x2C,
  38940. 0x94, 0x18, 0x62, 0x9A, 0x30, 0x4A, 0xE2, 0x86,
  38941. 0x4C, 0x5C, 0x10, 0x8D, 0xC2, 0x12, 0x21, 0x9C,
  38942. 0xC4, 0x4D, 0xD9, 0x96, 0x88, 0x0C, 0x29, 0x45,
  38943. 0x1B, 0x45, 0x6A, 0x1A, 0x00, 0x60, 0x91, 0x30,
  38944. 0x0C, 0x12, 0x00, 0x69, 0xA2, 0xA0, 0x04, 0x81,
  38945. 0x00, 0x65, 0x5C, 0x38, 0x8A, 0x18, 0x05, 0x89,
  38946. 0x48, 0x32, 0x24, 0x81, 0xC6, 0x4D, 0x60, 0x90,
  38947. 0x31, 0x83, 0x22, 0x12, 0xE1, 0xC2, 0x6C, 0x89,
  38948. 0x00, 0x90, 0x14, 0xB4, 0x40, 0xD3, 0xB8, 0x45,
  38949. 0x89, 0x24, 0x70, 0x09, 0x26, 0x6C, 0xD9, 0x32,
  38950. 0x8A, 0x83, 0x44, 0x0E, 0x21, 0x44, 0x61, 0x99,
  38951. 0xA4, 0x20, 0x44, 0x16, 0x2E, 0x1A, 0xC2, 0x08,
  38952. 0x09, 0x98, 0x6C, 0x8C, 0x18, 0x8C, 0x0C, 0x30,
  38953. 0x62, 0x8B, 0x46, 0x45, 0x80, 0x10, 0x21, 0x20,
  38954. 0x33, 0x32, 0x5A, 0x38, 0x4C, 0x98, 0x06, 0x45,
  38955. 0x1A, 0x33, 0x09, 0x82, 0x34, 0x44, 0x02, 0x20,
  38956. 0x09, 0x59, 0x00, 0x41, 0x08, 0x13, 0x08, 0xDC,
  38957. 0x18, 0x68, 0x12, 0x47, 0x86, 0x43, 0xB8, 0x21,
  38958. 0x62, 0x02, 0x8D, 0x5C, 0x10, 0x0D, 0x60, 0x96,
  38959. 0x65, 0xA2, 0x22, 0x4C, 0x83, 0x18, 0x09, 0x41,
  38960. 0x08, 0x41, 0x63, 0xC2, 0x80, 0x13, 0x81, 0x65,
  38961. 0x22, 0x03, 0x92, 0x04, 0xA9, 0x4D, 0x1C, 0xB0,
  38962. 0x44, 0x80, 0xC6, 0x24, 0x00, 0x01, 0x44, 0x22,
  38963. 0x11, 0x80, 0x21, 0x95, 0x64, 0x09, 0x99, 0x8C,
  38964. 0xD3, 0x14, 0x4A, 0xD1, 0x98, 0x2D, 0x19, 0x31,
  38965. 0x4C, 0x0A, 0x92, 0x40, 0x13, 0x98, 0x48, 0x14,
  38966. 0x89, 0x20, 0x23, 0xB3, 0x0D, 0x14, 0x98, 0x6D,
  38967. 0x12, 0x98, 0x05, 0x9B, 0x14, 0x06, 0x5B, 0x26,
  38968. 0x91, 0x0A, 0x38, 0x09, 0x08, 0x98, 0x2C, 0x19,
  38969. 0xA0, 0x45, 0x44, 0x26, 0x00, 0x0A, 0x05, 0x21,
  38970. 0xDB, 0xA0, 0x69, 0x51, 0x42, 0x92, 0x0B, 0x43,
  38971. 0x00, 0xD1, 0x42, 0x0D, 0x81, 0x30, 0x28, 0x13,
  38972. 0xC2, 0x20, 0x03, 0x27, 0x60, 0x10, 0x83, 0x91,
  38973. 0x0A, 0x53, 0x7E, 0xA1, 0x4F, 0x11, 0x54, 0x5E,
  38974. 0x25, 0x4F, 0xCF, 0x28, 0x03, 0x95, 0x2A, 0x58,
  38975. 0x0A, 0x4B, 0x6C, 0x9B, 0x29, 0x10, 0x3D, 0x97,
  38976. 0x43, 0x6C, 0x00, 0x3E, 0x2E, 0xCE, 0xAE, 0x20,
  38977. 0x28, 0x01, 0x7F, 0xF1, 0xD5, 0x18, 0xB0, 0xB5,
  38978. 0xD5, 0xE6, 0x24, 0x26, 0x64, 0xED, 0x33, 0x7C,
  38979. 0xCA, 0x45, 0x26, 0xED, 0x5D, 0xB5, 0xEA, 0xD8,
  38980. 0xBB, 0x31, 0x16, 0x94, 0x1C, 0xD0, 0xC8, 0xF0,
  38981. 0xA7, 0xED, 0x5A, 0x1A, 0x5A, 0x00, 0xB9, 0x8C,
  38982. 0x33, 0x6A, 0x9B, 0xC8, 0xEB, 0x6B, 0x3A, 0x30,
  38983. 0x83, 0x16, 0xF1, 0x17, 0xEA, 0xA8, 0x0D, 0x4B,
  38984. 0x77, 0x56, 0xDD, 0x4A, 0x91, 0xDA, 0xA5, 0x8E,
  38985. 0x80, 0xD7, 0xB5, 0x77, 0x55, 0x83, 0x97, 0xAF,
  38986. 0x90, 0x5B, 0x67, 0xC5, 0x9F, 0x14, 0xE1, 0x2C,
  38987. 0x15, 0x8D, 0x29, 0x2C, 0xA6, 0xB6, 0x41, 0xED,
  38988. 0x0C, 0x75, 0xE3, 0x9A, 0x91, 0x4F, 0xFA, 0x1A,
  38989. 0x9F, 0x24, 0xCA, 0x28, 0xF2, 0x00, 0xC7, 0x48,
  38990. 0xDE, 0x70, 0x9D, 0x15, 0xD7, 0x22, 0xE7, 0xED,
  38991. 0x2C, 0x91, 0x8D, 0xEF, 0x08, 0xCF, 0xAF, 0x9B,
  38992. 0x7E, 0x24, 0xDE, 0xF2, 0xD5, 0x1A, 0x4D, 0x42,
  38993. 0x0E, 0x7E, 0x89, 0x06, 0xFA, 0xCD, 0x9A, 0x5A,
  38994. 0x98, 0xB0, 0xD1, 0xD5, 0x34, 0x5C, 0x8B, 0x9A,
  38995. 0xC0, 0xBB, 0xF4, 0xB1, 0x5E, 0xF0, 0xB4, 0x6A,
  38996. 0x8E, 0x3B, 0x6B, 0xAE, 0x0C, 0x6E, 0x9F, 0x09,
  38997. 0x2E, 0xB3, 0xEF, 0x1D, 0x49, 0x62, 0x0B, 0x65,
  38998. 0xE7, 0xDE, 0xDB, 0xEF, 0x68, 0x7E, 0xBD, 0x0E,
  38999. 0xA0, 0x95, 0x97, 0x2A, 0x56, 0xA0, 0xEA, 0xFB,
  39000. 0x2D, 0x75, 0xF4, 0x32, 0x1B, 0x80, 0xAC, 0xBC,
  39001. 0xA3, 0x2B, 0x1B, 0x11, 0xAA, 0x57, 0x6F, 0xE4,
  39002. 0xE0, 0xCC, 0xCC, 0x20, 0x52, 0x12, 0x65, 0x42,
  39003. 0x96, 0xF0, 0x60, 0x8F, 0xF3, 0x83, 0x69, 0xAF,
  39004. 0x19, 0x80, 0x75, 0x68, 0xDB, 0xE1, 0x71, 0xDB,
  39005. 0x79, 0xEB, 0x8C, 0x1C, 0xB7, 0x6A, 0x8E, 0xB9,
  39006. 0x5B, 0x28, 0x8C, 0x9D, 0xCC, 0x62, 0x0B, 0xEF,
  39007. 0xCE, 0x96, 0x06, 0x0F, 0x45, 0xA6, 0xA2, 0xDA,
  39008. 0xC2, 0x2F, 0x55, 0xE4, 0x7D, 0xC7, 0xBA, 0xB4,
  39009. 0xA7, 0x93, 0xD9, 0x65, 0x8F, 0xE2, 0x7C, 0x66,
  39010. 0x2C, 0xA6, 0x37, 0x00, 0x81, 0x30, 0xF1, 0x00,
  39011. 0xD9, 0x65, 0xB4, 0x78, 0x17, 0x7A, 0xC6, 0xDC,
  39012. 0x35, 0x93, 0x1A, 0x5E, 0xCC, 0x5F, 0x93, 0x31,
  39013. 0x22, 0x40, 0x2C, 0x17, 0x0E, 0xB8, 0xE0, 0xA4,
  39014. 0x1C, 0xB6, 0x3F, 0xE5, 0x60, 0x2F, 0x7B, 0x18,
  39015. 0xE1, 0xDB, 0xB6, 0xDB, 0x30, 0xA7, 0x61, 0x55,
  39016. 0xC6, 0xCF, 0x03, 0x0F, 0x73, 0x8D, 0xC0, 0x91,
  39017. 0x6D, 0xB1, 0x80, 0xF8, 0x3F, 0x02, 0x90, 0x93,
  39018. 0x11, 0xCB, 0x6B, 0x3B, 0x9E, 0x55, 0x3F, 0xAC,
  39019. 0xA0, 0x52, 0x23, 0xB3, 0x3C, 0x69, 0x60, 0x2D,
  39020. 0x0F, 0x05, 0xA0, 0x8B, 0xEB, 0x84, 0x80, 0x96,
  39021. 0x51, 0x99, 0x9A, 0x55, 0x26, 0xE7, 0x76, 0xF3,
  39022. 0xDE, 0x39, 0x30, 0x4A, 0x5F, 0xEF, 0x00, 0x95,
  39023. 0x0A, 0x9A, 0x81, 0x0D, 0x12, 0xE0, 0x1D, 0x15,
  39024. 0xD8, 0x86, 0xDB, 0x26, 0x75, 0xF6, 0x54, 0xCA,
  39025. 0x17, 0xFA, 0xAE, 0xEB, 0xD1, 0xF5, 0x61, 0xF9,
  39026. 0xD1, 0xA9, 0x5E, 0x0B, 0xAD, 0xF7, 0xC3, 0x31,
  39027. 0x5A, 0xFA, 0xBA, 0x8D, 0x4B, 0xEC, 0x1F, 0x05,
  39028. 0x42, 0xA8, 0xF1, 0x0A, 0xC6, 0x66, 0xFD, 0x8D,
  39029. 0x0C, 0x5A, 0xF1, 0xD6, 0x86, 0x7A, 0x9D, 0x82,
  39030. 0x6B, 0xFB, 0x6B, 0x03, 0x0B, 0x58, 0xEC, 0xEF,
  39031. 0x67, 0x78, 0xD2, 0xC5, 0x2B, 0xF6, 0x2C, 0xB3,
  39032. 0x4B, 0x81, 0xFF, 0x93, 0x6D, 0xA3, 0x3E, 0xDA,
  39033. 0xB3, 0x1D, 0xB3, 0x9A, 0xB7, 0x63, 0x66, 0xD0,
  39034. 0x94, 0x36, 0x2F, 0x04, 0x6D, 0x50, 0x78, 0xB4,
  39035. 0x22, 0x35, 0x04, 0xA1, 0x2B, 0xA0, 0xC7, 0xB8,
  39036. 0xE8, 0x83, 0x72, 0x77, 0x18, 0x50, 0x9B, 0xD4,
  39037. 0x7A, 0x69, 0x6E, 0xE9, 0x88, 0x0C, 0xAF, 0xF6,
  39038. 0x63, 0x61, 0x2B, 0x95, 0x86, 0x30, 0x3D, 0x6D,
  39039. 0xE0, 0xD2, 0x1F, 0x9A, 0x21, 0x96, 0x22, 0x78,
  39040. 0xEB, 0xCE, 0x60, 0xA6, 0xD4, 0x68, 0x44, 0x09,
  39041. 0x5C, 0x5F, 0x89, 0x2D, 0xAC, 0xA4, 0x8D, 0x78,
  39042. 0x28, 0x22, 0x45, 0x38, 0x34, 0xB4, 0xE4, 0x2C,
  39043. 0xD3, 0xA1, 0xFE, 0x39, 0x87, 0x35, 0x6E, 0xAB,
  39044. 0x11, 0xEF, 0xB8, 0xEE, 0xCD, 0x8E, 0x9C, 0xC8,
  39045. 0xF3, 0x9A, 0x0F, 0xF1, 0xFF, 0xB8, 0x06, 0x9A,
  39046. 0x44, 0x1F, 0x85, 0x1E, 0xB4, 0x38, 0xE9, 0xC0,
  39047. 0xB5, 0x7E, 0x88, 0x18, 0xA3, 0x22, 0x65, 0x1E,
  39048. 0x60, 0xF4, 0xB6, 0x78, 0x90, 0xE5, 0xED, 0x7A,
  39049. 0x0F, 0xBF, 0x75, 0x36, 0xC3, 0xFD, 0x50, 0xD0,
  39050. 0xB0, 0x65, 0x8D, 0x7C, 0xCF, 0x27, 0x5E, 0x8A,
  39051. 0x9E, 0x9F, 0xBB, 0x99, 0xBE, 0x2E, 0x5F, 0x5E,
  39052. 0x16, 0x7B, 0xE2, 0x90, 0xB7, 0xE9, 0x67, 0x32,
  39053. 0xF8, 0x9E, 0x40, 0xD7, 0x85, 0xAF, 0x25, 0xC1,
  39054. 0xBA, 0x61, 0xA7, 0x78, 0x6D, 0x3E, 0xF2, 0xD0,
  39055. 0xC1, 0x14, 0xD1, 0x04, 0x8E, 0x76, 0x46, 0xDF,
  39056. 0xA3, 0x03, 0x2B, 0xFB, 0x7A, 0x51, 0xA6, 0x36,
  39057. 0x05, 0xDC, 0xE3, 0xE1, 0xD8, 0x98, 0x95, 0x00,
  39058. 0xD6, 0xE5, 0x8E, 0x96, 0x05, 0x19, 0x93, 0x1D,
  39059. 0xAC, 0x9F, 0x14, 0xDD, 0xA4, 0x28, 0xF5, 0xA2,
  39060. 0xC9, 0xC7, 0x4D, 0x91, 0x6D, 0x90, 0x77, 0x07,
  39061. 0xB5, 0x3E, 0xB5, 0x2C, 0x44, 0xAD, 0x71, 0xD7,
  39062. 0x27, 0x82, 0x6E, 0xB2, 0xCA, 0x68, 0x07, 0x0A,
  39063. 0x6F, 0x0E, 0x47, 0xFA, 0x16, 0xE5, 0x2E, 0x96,
  39064. 0x29, 0xB7, 0xAA, 0x82, 0x41, 0xDA, 0xAB, 0xB1,
  39065. 0x94, 0x97, 0xA5, 0x82, 0x4E, 0x58, 0xD7, 0x26,
  39066. 0x75, 0xC3, 0xA6, 0x7E, 0x10, 0xA1, 0x19, 0xB2,
  39067. 0x74, 0xB8, 0x4D, 0x9B, 0xEE, 0x28, 0x71, 0x72,
  39068. 0x8E, 0xD2, 0xF9, 0x4F, 0x85, 0x59, 0xB9, 0x7F,
  39069. 0x97, 0x9A, 0xE8, 0x82, 0xEA, 0x54, 0x99, 0x28,
  39070. 0xD6, 0xB1, 0xA9, 0xA4, 0xE4, 0xA2, 0x29, 0xF6,
  39071. 0xEB, 0x3F, 0xB1, 0xA4, 0x34, 0xA0, 0xFA, 0xED,
  39072. 0xAD, 0x62, 0xB7, 0x03, 0x30, 0xCF, 0xCB, 0x24,
  39073. 0xCB, 0x34, 0x98, 0x80, 0x2A, 0x67, 0x9F, 0x8F,
  39074. 0x54, 0xBF, 0x83, 0xEF, 0x34, 0x47, 0x22, 0x96,
  39075. 0x91, 0x98, 0x31, 0xCA, 0xAD, 0x59, 0xEB, 0xE8,
  39076. 0x30, 0x82, 0xEA, 0xB6, 0x7D, 0x4A, 0xBD, 0x90,
  39077. 0x22, 0x9A, 0x5E, 0x93, 0xA0, 0xB5, 0x80, 0x97,
  39078. 0x7F, 0x08, 0x13, 0xCC, 0xB1, 0x5E, 0xCD, 0x74,
  39079. 0xFF, 0x71, 0x5F, 0xE8, 0xDB, 0x5B, 0x05, 0xCE,
  39080. 0xF3, 0x7D, 0x34, 0x93, 0xBE, 0xDA, 0x27, 0x05,
  39081. 0x84, 0x94, 0x4C, 0x02, 0x09, 0x86, 0x34, 0x51,
  39082. 0x4D, 0xAA, 0xCE, 0x70, 0x47, 0xE4, 0x74, 0x32,
  39083. 0xF9, 0x2A, 0xDC, 0xA4, 0x91, 0xA3, 0xE0, 0x96,
  39084. 0x1A, 0x5D, 0x9F, 0x01, 0x44, 0x85, 0x2E, 0x46,
  39085. 0x32, 0x63, 0x35, 0xE2, 0x15, 0x24, 0x3D, 0xAA,
  39086. 0xE8, 0x37, 0x92, 0x7F, 0xBF, 0xDC, 0xE6, 0x91,
  39087. 0xF4, 0x98, 0x59, 0x26, 0x6E, 0x90, 0x08, 0x16,
  39088. 0x8C, 0x6A, 0x5E, 0x2F, 0x60, 0x9C, 0x80, 0xC6,
  39089. 0x8E, 0x08, 0x20, 0xE7, 0x27, 0x19, 0xE9, 0xB5,
  39090. 0x87, 0x3F, 0xA1, 0x99, 0xE1, 0x97, 0xF9, 0xC4,
  39091. 0x94, 0xAA, 0x8A, 0x3A, 0x65, 0x26, 0x9E, 0x95,
  39092. 0xB7, 0x61, 0xB6, 0x7B, 0xEC, 0x61, 0x13, 0xC1,
  39093. 0x44, 0xA5, 0x69, 0x89, 0xC5, 0x75, 0x0D, 0x45,
  39094. 0x05, 0x42, 0xCC, 0xF8, 0x1B, 0x24, 0x62, 0x09,
  39095. 0x2F, 0x70, 0x71, 0x5D, 0x49, 0x14, 0xEB, 0x2C,
  39096. 0xAA, 0x31, 0x74, 0xBC, 0x9E, 0xEB, 0x20, 0xAA,
  39097. 0xB6, 0xC6, 0x40, 0xF8, 0xB5, 0xD9, 0xC6, 0xA0,
  39098. 0xDC, 0xC6, 0xF0, 0xAE, 0xC9, 0x7B, 0x3A, 0xF6,
  39099. 0x47, 0xEB, 0xF8, 0x00, 0x34, 0xA4, 0x3B, 0xF3,
  39100. 0x19, 0xBF, 0x40, 0xAD, 0xF7, 0x9A, 0xFE, 0xAB,
  39101. 0x58, 0x90, 0xD2, 0x02, 0x3B, 0xAE, 0x02, 0xC9,
  39102. 0xFD, 0x02, 0xC5, 0xBB, 0x65, 0x87, 0x9C, 0x1B,
  39103. 0x5E, 0xA4, 0x06, 0x02, 0x9A, 0xE7, 0x78, 0x45,
  39104. 0xCB, 0x99, 0x4D, 0xB8, 0xC3, 0x52, 0x11, 0xCA,
  39105. 0x1D, 0xC8, 0x81, 0xF7, 0xF2, 0x0A, 0x47, 0x06,
  39106. 0x50, 0x5F, 0x29, 0xD9, 0xCD, 0x19, 0x89, 0xAD,
  39107. 0x42, 0xB0, 0x7E, 0xF5, 0x2D, 0x96, 0x54, 0xE2,
  39108. 0x8E, 0x3D, 0xCB, 0x83, 0x00, 0x08, 0xA1, 0xBE,
  39109. 0x31, 0x99, 0x38, 0x7E, 0x06, 0x6B, 0x28, 0xB3,
  39110. 0x15, 0xCA, 0x19, 0x02, 0xF4, 0xBB, 0x0E, 0xE6,
  39111. 0x3F, 0xDC, 0x4C, 0x93, 0xE1, 0xAB, 0x88, 0x6F,
  39112. 0xD7, 0x42, 0x52, 0x61, 0xC3, 0x7A, 0xC5, 0x87,
  39113. 0x62, 0xD0, 0x3D, 0xB6, 0x07, 0x06, 0x88, 0x7E,
  39114. 0x72, 0xCF, 0x74, 0x5A, 0x44, 0x6D, 0xF6, 0xC6,
  39115. 0x66, 0x2F, 0x53, 0xDD, 0x61, 0x24, 0x71, 0xA4,
  39116. 0x34, 0xAC, 0x56, 0xC4, 0xBE, 0xDB, 0x3C, 0x9F,
  39117. 0x36, 0x47, 0xE6, 0x03, 0x2B, 0x3C, 0xC0, 0x99,
  39118. 0x0A, 0x3A, 0x2E, 0x87, 0x05, 0x2B, 0x36, 0xD4,
  39119. 0xA1, 0x62, 0x42, 0x4E, 0x2D, 0x39, 0x9E, 0x1B,
  39120. 0xC2, 0x37, 0x92, 0x8D, 0x0B, 0xD7, 0x71, 0x58,
  39121. 0x07, 0x9C, 0xCB, 0x20, 0x8B, 0x71, 0x95, 0x07,
  39122. 0x96, 0x55, 0xBD, 0xB7, 0x6C, 0xBA, 0xFF, 0x44,
  39123. 0x7C, 0x34, 0xC5, 0x82, 0x9F, 0xAC, 0x19, 0x9B,
  39124. 0xB0, 0x27, 0xA0, 0x80, 0x06, 0x50, 0x8D, 0x56,
  39125. 0xC8, 0x1D, 0x18, 0x70, 0x90, 0xE7, 0x10, 0x24,
  39126. 0xDB, 0x7F, 0xBF, 0x3A, 0x7D, 0x64, 0xD8, 0xFA,
  39127. 0x48, 0x74, 0xA8, 0xF4, 0x70, 0x37, 0x7B, 0x15,
  39128. 0x38, 0x00, 0x96, 0x82, 0x2F, 0xFE, 0x46, 0x55,
  39129. 0x71, 0xB5, 0x0C, 0x54, 0x05, 0x58, 0xBA, 0x50,
  39130. 0xE9, 0x0E, 0xB8, 0x14, 0x52, 0xF4, 0x12, 0x75,
  39131. 0xC2, 0x51, 0x5B, 0xAE, 0x05, 0x92, 0xD5, 0x3F,
  39132. 0x6A, 0x6A, 0x34, 0xD2, 0xA3, 0x4D, 0x8E, 0xAC,
  39133. 0x6E, 0x7A, 0x03, 0xFB, 0xDB, 0x52, 0x49, 0x4F,
  39134. 0x4B, 0x98, 0x1B, 0x56, 0xC0, 0x96, 0x26, 0x08,
  39135. 0x48, 0x50, 0xC7, 0xCF, 0x96, 0x2F, 0x93, 0x10,
  39136. 0x72, 0x25, 0x15, 0xA6, 0x2A, 0xC0, 0x85, 0xA6,
  39137. 0x18, 0x9A, 0xDD, 0xEA, 0x38, 0x12, 0x91, 0x13,
  39138. 0x57, 0x31, 0xB2, 0xEE, 0x83, 0xA4, 0xF1, 0xEB,
  39139. 0xFA, 0x09, 0xAF, 0x80, 0xA9, 0x12, 0x68, 0xA8,
  39140. 0x76, 0x23, 0xCB, 0x55, 0x7C, 0x9F, 0x66, 0xDE,
  39141. 0xB4, 0x54, 0xFB, 0x2F, 0x4F, 0xC2, 0x64, 0x8F,
  39142. 0x44, 0x41, 0x5A, 0x7B, 0xEF, 0x29, 0x96, 0x2D,
  39143. 0x5F, 0x7C, 0x16, 0xE7, 0x85, 0x79, 0xF5, 0x26,
  39144. 0xDD, 0x20, 0xE9, 0x20, 0x9B, 0x6C, 0xA6, 0xDF,
  39145. 0xD1, 0x30, 0xF9, 0x2E, 0xF7, 0x24, 0x64, 0x5B,
  39146. 0x5B, 0x84, 0xD8, 0x72, 0x4F, 0x3C, 0xF6, 0xF3,
  39147. 0xA3, 0xB2, 0xA9, 0xCF, 0x61, 0x24, 0x7A, 0x54,
  39148. 0xBA, 0x92, 0x8F, 0x53, 0xEA, 0xCB, 0xA7, 0xE6,
  39149. 0xD6, 0xB8, 0x12, 0xC4, 0xCE, 0x21, 0xA1, 0x8B,
  39150. 0xA8, 0xD1, 0x14, 0x50, 0xE7, 0x04, 0x89, 0xBA,
  39151. 0x57, 0x2E, 0x5E, 0xB9, 0xA7, 0x72, 0x2D, 0x9D,
  39152. 0xC6, 0xAA, 0xE4, 0xF9, 0x57, 0x93, 0x60, 0x09,
  39153. 0xE2, 0x6E, 0xB3, 0xE7, 0x4D, 0x9F, 0x99, 0x33,
  39154. 0xF3, 0xDB, 0x4D, 0xA0, 0xA1, 0xF5, 0x44, 0x93,
  39155. 0x99, 0xB5, 0xE1, 0x01, 0x03, 0x11, 0xF8, 0x7D,
  39156. 0x92, 0xC1, 0x87, 0xAD, 0x2E, 0xFA, 0xBB, 0x0A,
  39157. 0x2C, 0x86, 0xB7, 0xD7, 0xF9, 0xA0, 0x72, 0xAB,
  39158. 0xC0, 0xC6, 0x60, 0x6D, 0xBC, 0xD9, 0x20, 0x17,
  39159. 0x7A, 0x22, 0x57, 0x20, 0xA7, 0x05, 0x76, 0xB8,
  39160. 0xE8, 0x2D, 0x7D, 0x53, 0xC1, 0xDF, 0xA4, 0x8E,
  39161. 0xA7, 0x31, 0x81, 0xAF, 0x0A, 0xF0, 0x86, 0xB6,
  39162. 0xAA, 0xF8, 0x0A, 0xB2, 0x49, 0x81, 0xF2, 0x75,
  39163. 0xD6, 0x6D, 0x4F, 0xBD, 0xE2, 0xC5, 0x1A, 0xE8,
  39164. 0xE8, 0xD4, 0x58, 0x33, 0x72, 0x9F, 0x45, 0x03,
  39165. 0x01, 0x30, 0xBC, 0x85, 0xB2, 0xBD, 0x9A, 0x14,
  39166. 0xC8, 0x13, 0xA3, 0x7F, 0x1F, 0xA1, 0x47, 0xF8,
  39167. 0x15, 0x48, 0x8D, 0x7A, 0x17, 0xC0, 0xC0, 0x39,
  39168. 0xEA, 0xF8, 0x66, 0xCE, 0xA7, 0x5F, 0x5B, 0x2E,
  39169. 0xBE, 0x05, 0xEF, 0x31, 0x09, 0x47, 0x2B, 0xA5,
  39170. 0xF7, 0xCF, 0xCE, 0x4C, 0x35, 0x8B, 0x60, 0x80,
  39171. 0x40, 0x0C, 0x5C, 0xC0, 0x85, 0x15, 0x14, 0x92,
  39172. 0xD1, 0x3A, 0x5B, 0x00, 0x96, 0xA0, 0x63, 0x1F,
  39173. 0xAA, 0x30, 0xCB, 0x48, 0xF2, 0xDA, 0x87, 0x3B,
  39174. 0x85, 0x7D, 0xFD, 0xB3, 0x86, 0xD9, 0x33, 0x98,
  39175. 0x18, 0x07, 0x34, 0x92, 0x55, 0x9A, 0x0E, 0xC2,
  39176. 0xDA, 0xF3, 0x73, 0x8E, 0x15, 0x88, 0xB0, 0x98,
  39177. 0x75, 0x1F, 0xF0, 0xFA, 0x1C, 0x87, 0x1B, 0x22,
  39178. 0x23, 0x7E, 0x5C, 0xD1, 0x5B, 0x0E, 0x17, 0x28,
  39179. 0xEA, 0x26, 0x71, 0x66, 0xC3, 0x8A, 0x71, 0x97,
  39180. 0xB6, 0xCC, 0x7D, 0xAD, 0x39, 0x11, 0x6B, 0xE6,
  39181. 0x1D, 0xF4, 0x33, 0x3C, 0xD7, 0xC2, 0xA4, 0x13,
  39182. 0xDB, 0x30, 0x63, 0xD7, 0xF0, 0x22, 0x8C, 0x61,
  39183. 0xFA, 0xDA, 0xC3, 0xF8, 0xC3, 0x31, 0xF4, 0x45,
  39184. 0x09, 0xB4, 0xD6, 0x08, 0x53, 0x1F, 0x99, 0x5D,
  39185. 0x15, 0xFA, 0xB1, 0x19, 0xD8, 0x47, 0xE6, 0xD8,
  39186. 0x54, 0x95, 0x75, 0xB7, 0xD8, 0x50, 0xB2, 0x60,
  39187. 0x0E, 0x4D, 0x13, 0x64, 0x6C, 0xF9, 0x6B, 0x6B,
  39188. 0x9D, 0xA6, 0xC6, 0x2F, 0x2A, 0x80, 0xAE, 0x02,
  39189. 0x58, 0xA8, 0xCD, 0x6E, 0xF4, 0xC5, 0x5E, 0xEA,
  39190. 0x7E, 0x78, 0xD2, 0x0A, 0x46, 0x4A, 0x19, 0x4C,
  39191. 0xEC, 0xBB, 0x01, 0xE7, 0x3F, 0x32, 0x76, 0xD6,
  39192. 0x6E, 0x12, 0xAD, 0x37, 0x74, 0x51, 0xBB, 0xB9,
  39193. 0x4E, 0x5C, 0x94, 0x88, 0x32, 0x59, 0x5F, 0x6B,
  39194. 0x6E, 0x38, 0x2A, 0xD1, 0x42, 0xD9, 0xF1, 0xB8,
  39195. 0x68, 0x97, 0x95, 0xE9, 0xEB, 0xC3, 0x2A, 0x5A,
  39196. 0x10, 0x1E, 0x69, 0x6C, 0xA3, 0x4A, 0xBA, 0x00,
  39197. 0x5B, 0x4C, 0xED, 0xA2, 0x7D, 0x12, 0x00, 0xFE,
  39198. 0x48, 0xFD, 0x82, 0xC1, 0x72, 0x17, 0xE5, 0x08,
  39199. 0xA8, 0x48, 0x4F, 0x03, 0x88, 0x34, 0x5C, 0x9D,
  39200. 0xED, 0xE2, 0xA1, 0x39, 0x28, 0xFA, 0xC3, 0x29,
  39201. 0x21, 0x84, 0x2F, 0x6E, 0x6A, 0xA5, 0xCF, 0xBF,
  39202. 0x57, 0xFA, 0xA2, 0x8F, 0x43, 0xE0, 0x5E, 0x9A,
  39203. 0x45, 0x23, 0x12, 0x50, 0x29, 0x11, 0xEF, 0x9C,
  39204. 0x33, 0xC8, 0x11, 0xEB, 0xE7, 0xCA, 0xD7, 0x30,
  39205. 0x62, 0x3D, 0xB7, 0x04, 0x8E, 0xC2, 0x18, 0xC7,
  39206. 0xEA, 0x9D, 0xFC, 0x6E, 0x19, 0x65, 0xA9, 0x85,
  39207. 0x7E, 0x92, 0x94, 0xC4, 0xE4, 0x7F, 0x4D, 0x96,
  39208. 0x23, 0xCB, 0x74, 0xB6, 0x5F, 0x7B, 0xB5, 0x86,
  39209. 0x22, 0x83, 0x8D, 0xC4, 0x4E, 0x16, 0xD9, 0x15,
  39210. 0xD9, 0x59, 0x65, 0x55, 0xCA, 0x3D, 0x26, 0x1C,
  39211. 0x9C, 0x2A, 0xFC, 0xCB, 0xAF, 0x5A, 0xC0, 0x3D,
  39212. 0xE0, 0x91, 0xF0, 0xDB, 0xEA, 0xE1, 0xB4, 0xA7,
  39213. 0xE3, 0xDE, 0xC4, 0x39, 0x09, 0x89, 0x67, 0x65,
  39214. 0x77, 0xA0, 0x53, 0x68, 0x4F, 0x57, 0x86, 0x8D,
  39215. 0x91, 0xFE, 0x6A, 0x5B, 0x7D, 0x3D, 0x7C, 0x79,
  39216. 0x50, 0x78, 0x9E, 0x89, 0xD8, 0x38, 0x83, 0xBC,
  39217. 0x3D, 0xAE, 0x55, 0xCA, 0x30, 0x78, 0xB0, 0x8D,
  39218. 0x99, 0x18, 0x31, 0xBA, 0x91, 0x50, 0x2A, 0x5A,
  39219. 0x33, 0x54, 0xB8, 0x8E, 0x15, 0x9B, 0x0A, 0xFF,
  39220. 0xD2, 0x5B, 0x0D, 0xBB, 0x72, 0xBC, 0xD6, 0xF4,
  39221. 0x04, 0x65, 0xDD, 0xFC, 0x00, 0xFF, 0x8B, 0x63,
  39222. 0x39, 0xC0, 0x67, 0x09, 0x5D, 0x6C, 0x7C, 0xB0,
  39223. 0x6F, 0x3B, 0xE7, 0x59, 0xC5, 0x27, 0x40, 0x39,
  39224. 0x5D, 0xD1, 0x08, 0x29, 0x6F, 0x2B, 0xBC, 0x2E,
  39225. 0x7A, 0x5D, 0xDD, 0xE3, 0xD1, 0xC3, 0x5D, 0x18,
  39226. 0xBF, 0xBE, 0x39, 0x68, 0xEC, 0x59, 0xAB, 0xF8,
  39227. 0x5C, 0x1B, 0xD2, 0x92, 0x8A, 0xB2, 0xAA, 0x67,
  39228. 0x8A, 0x78, 0x91, 0x74, 0x6E, 0x88, 0xF4, 0x39,
  39229. 0xF8, 0xB4, 0x38, 0x40, 0x31, 0xC3, 0xED, 0xB7,
  39230. 0x31, 0x97, 0xE5, 0x2A, 0x4E, 0x77, 0x3D, 0x2D,
  39231. 0x8B, 0x7B, 0xAD, 0xDC, 0x5D, 0xD0, 0xA7, 0xE4,
  39232. 0x4C, 0x80, 0x8D, 0x73, 0xB8, 0x18, 0x1D, 0x19,
  39233. 0x1C, 0x3C, 0x89, 0xFE, 0x15, 0xEA, 0x90, 0xD7,
  39234. 0x56, 0x7E, 0x89, 0x16, 0xA3, 0x37, 0x83, 0x03,
  39235. 0x05, 0x04, 0x1B, 0x1E, 0x94, 0xB3, 0xB4, 0x06,
  39236. 0xDA, 0x4C, 0x36, 0xBE, 0xF0, 0x5D, 0x91, 0x00,
  39237. 0xAB, 0x99, 0x2A, 0x4D, 0x56, 0x25, 0x33, 0x73,
  39238. 0x0E, 0x0D, 0x8C, 0x05, 0x2B, 0x3A, 0x62, 0xD3,
  39239. 0xF6, 0x9A, 0x83, 0xA0, 0xC9, 0xB2, 0x12, 0x4F,
  39240. 0x12, 0xAE, 0x7D, 0xAC, 0xC9, 0x78, 0xC4, 0xA0,
  39241. 0xAD, 0xCC, 0x2E, 0xBA, 0x2D, 0x80, 0xF4, 0x94,
  39242. 0xAA, 0x16, 0xEC, 0x1E, 0x8E, 0x71, 0xC7, 0x9B,
  39243. 0x02, 0xF3, 0x26, 0x1B, 0x6F, 0x98, 0x68, 0xB8,
  39244. 0xD5, 0x7E, 0x9D, 0x16, 0xF4, 0x2B, 0x7C, 0xC6,
  39245. 0x64, 0x06, 0x54, 0x9A, 0x27, 0x6D, 0x37, 0x14,
  39246. 0x37, 0xDE, 0x88, 0xB7, 0xF3, 0x9E, 0x74, 0x08,
  39247. 0x7C, 0xBB, 0xC5, 0x61, 0x16, 0x80, 0x31, 0x2D,
  39248. 0xE8, 0xF0, 0xC3, 0x68, 0x14, 0xE1, 0x74, 0xF9,
  39249. 0x1E, 0xB6, 0x00, 0xCC, 0x96, 0xE3, 0xCF, 0x51,
  39250. 0xBB, 0x20, 0x25, 0x88, 0x77, 0xA2, 0xAA, 0xEB,
  39251. 0x82, 0x7F, 0x7F, 0x5A, 0xDA, 0x80, 0x78, 0x6B,
  39252. 0x50, 0x84, 0xC8, 0x02, 0xE6, 0x06, 0xDE, 0xF3,
  39253. 0x88, 0xA3, 0x9C, 0xE4, 0xF0, 0xD5, 0xBC, 0x19,
  39254. 0x39, 0x4C, 0xE8, 0x41, 0xE2, 0xD2, 0xAA, 0x74,
  39255. 0x25, 0x23, 0x05, 0x80, 0xFA, 0x66, 0x75, 0xC5,
  39256. 0x17, 0x41, 0xD1, 0x75, 0x87, 0x9B, 0x4D, 0x03,
  39257. 0xC3, 0x90, 0xF6, 0x52, 0xA5, 0x03, 0xA7, 0x51,
  39258. 0x6A, 0x1F, 0x07, 0x5E, 0x30, 0x82, 0xD5, 0x2C,
  39259. 0x60, 0xB8, 0x64, 0x2A, 0x82, 0x40, 0xEE, 0x94,
  39260. 0x4D, 0x5F, 0xB4, 0x27, 0x37, 0x6B, 0x40, 0xB0,
  39261. 0xB2, 0x82, 0xE1, 0x9A, 0xB9, 0x08, 0xCC, 0xF2,
  39262. 0x0C, 0xA9, 0x26, 0x11, 0x64, 0x90, 0xAF, 0xED,
  39263. 0x57, 0xEA, 0xD0, 0xDC, 0x0C, 0x8E, 0x29, 0x6C,
  39264. 0x79, 0xA4, 0x8D, 0x08, 0x8E, 0x83, 0x7A, 0xF0,
  39265. 0x67, 0xDC, 0x02, 0x9E, 0xC6, 0x31, 0xF9, 0x93,
  39266. 0x3E, 0xE4, 0xD2, 0x07, 0x46, 0xE6, 0x4E, 0x5F,
  39267. 0x21, 0x67, 0x55, 0xA1, 0x38, 0x97, 0x4D, 0x30,
  39268. 0x82, 0x93, 0x73, 0x6D, 0xC1, 0x86, 0x04, 0x27,
  39269. 0x6C, 0xC4, 0x18, 0xBA, 0x69, 0xF8, 0x72, 0xB5,
  39270. 0x8E, 0x7F, 0x6E, 0x3A, 0x8B, 0x84, 0x6E, 0xBA,
  39271. 0xAE, 0xB3, 0x83, 0xE7, 0xF8, 0x90, 0xF5, 0x4E,
  39272. 0x77, 0xF5, 0xD7, 0xF5, 0xD4, 0xA5, 0x8D, 0xB7,
  39273. 0x83, 0xEC, 0xA0, 0x49, 0xF1, 0x86, 0x17, 0x12,
  39274. 0x82, 0xBA, 0xC2, 0x60, 0x7D, 0x51, 0xB2, 0x98,
  39275. 0xB1, 0x49, 0x38, 0xEF, 0xB1, 0x92, 0x8F, 0xC8,
  39276. 0xD0, 0x78, 0x06, 0xE8, 0xC3, 0xE7, 0x3B, 0x46,
  39277. 0x46, 0xBC, 0xF1, 0x68, 0x90, 0xCC, 0x13, 0x80,
  39278. 0xE7, 0xB6, 0x33, 0x50, 0x2B, 0x3E, 0xAD, 0xA4,
  39279. 0x47, 0x75, 0x02, 0xE2, 0x46, 0x7C, 0xFD, 0xB9,
  39280. 0xAC, 0xBD, 0x1C, 0x72, 0xBC, 0x6A, 0xEB, 0x4F,
  39281. 0x41, 0xE1, 0xC2, 0x3C, 0x63, 0x68, 0x39, 0xE3,
  39282. 0x57, 0x13, 0x5F, 0x76, 0xBC, 0x39, 0xC4, 0xF9,
  39283. 0xAC, 0x1C, 0xE8, 0xF1, 0xBE, 0xEF, 0xEB, 0xFF,
  39284. 0x87, 0x59, 0xE8, 0xF7, 0x19, 0x65, 0xD4, 0x85,
  39285. 0x4B, 0xEA, 0xAD, 0x0A, 0xFE, 0xDC, 0xA9, 0xD4,
  39286. 0xD6, 0xBD, 0x1E, 0x63, 0xD3, 0x48, 0xA4, 0x2C,
  39287. 0xEE, 0xFF, 0xC1, 0x70, 0xD0, 0xEE, 0x9F, 0x13,
  39288. 0x6F, 0x5B, 0xE9, 0x90, 0x14, 0x66, 0x92, 0x61,
  39289. 0x22, 0xF9, 0x48, 0xBD, 0xDE, 0x2A, 0x91, 0x07,
  39290. 0xD2, 0xA9, 0x8B, 0xA2, 0xDE, 0xA6, 0xD6, 0xF2,
  39291. 0xDA, 0x17, 0x72, 0x47, 0x02, 0xEC, 0x51, 0x8C,
  39292. 0x03, 0x75, 0x3D, 0x51, 0xEA, 0x83, 0x1E, 0x95,
  39293. 0xCB, 0x87, 0x08, 0xD5, 0xDE, 0xC8, 0x22, 0xDB,
  39294. 0x73, 0x7E, 0x44, 0x14, 0x3C, 0x86, 0xF4, 0x71,
  39295. 0x77, 0xD8, 0x5C, 0xD0, 0x98, 0xC2, 0x1B, 0x9B,
  39296. 0xC8, 0x00, 0xDF, 0xA9, 0xDC, 0x26, 0xFD, 0xC2,
  39297. 0x61, 0xE9, 0x21, 0xDE, 0x00, 0x2D, 0x81, 0xC1,
  39298. 0x59, 0xF8, 0xEB, 0x1F, 0xEE, 0x67, 0x67, 0x9D,
  39299. 0x62, 0x1E, 0xCE, 0x6B, 0x36, 0xD0, 0x1C, 0x77,
  39300. 0x5A, 0x16, 0x45, 0xD5, 0x22, 0x92, 0xB4, 0xB2,
  39301. 0xB8, 0x22, 0x73, 0x18, 0x77, 0x2A, 0x80, 0x91,
  39302. 0xE9, 0xEC, 0x01, 0x70, 0x13, 0xB1, 0x95, 0xEB,
  39303. 0xF4, 0xEF, 0x20, 0x1F, 0x4E, 0x88, 0x1C, 0x49,
  39304. 0x36, 0x33, 0xC0, 0x7F, 0x27, 0xC9, 0x79, 0x0D,
  39305. 0xD8, 0xAE, 0xCC, 0x94, 0x49, 0xCF, 0x63, 0xBC,
  39306. 0xB1, 0x19, 0x46, 0x16, 0x9A, 0xCF, 0xF3, 0x95,
  39307. 0x42, 0x26, 0x6B, 0x0C, 0x66, 0x85, 0xBB, 0xB0,
  39308. 0x80, 0xB5, 0x9F, 0x11, 0x7E, 0xEB, 0x2A, 0x73,
  39309. 0x38, 0x2B, 0x3D, 0x18, 0x7C, 0x06, 0x80, 0xC5,
  39310. 0xAE, 0x70, 0x90, 0x70, 0xDF, 0x03, 0xA0, 0x08,
  39311. 0xA7, 0xAD, 0x13, 0x22, 0x6F, 0x3C, 0x37, 0x15,
  39312. 0x39, 0x20, 0x52, 0xF2, 0x44, 0x1B, 0x4A, 0x17,
  39313. 0x8D, 0x7C, 0xF7, 0x05, 0x18, 0x33, 0x9C, 0xFF,
  39314. 0xBB, 0x54, 0xA6, 0xD9, 0xB9, 0xCD, 0xE3, 0xB0,
  39315. 0xB5, 0x7D, 0xBC, 0x79, 0xF4, 0xE4, 0x7A, 0xD6,
  39316. 0x27, 0x4C, 0xE2, 0x18, 0x0C, 0x92, 0xAC, 0x64,
  39317. 0x10, 0xE5, 0x0D, 0x05, 0xF6, 0x66, 0x5A, 0x57,
  39318. 0xD4, 0xD4, 0x47, 0x6C, 0x2C, 0x0E, 0x6E, 0xE0,
  39319. 0x75, 0x7A, 0x3A, 0xFE, 0xA2, 0xB1, 0xBF, 0x86,
  39320. 0xA5, 0x51, 0xEF, 0x98, 0xAA, 0x1D, 0xFC, 0xBA,
  39321. 0x96, 0x31, 0x59, 0x59, 0x45, 0x2B, 0x2B, 0x3A,
  39322. 0x2F, 0xCB, 0xBB, 0x95, 0x5C, 0xB3, 0xFA, 0x1E,
  39323. 0xEB, 0xBB, 0x83, 0xBD, 0x17, 0x87, 0x67, 0xC0,
  39324. 0x2E, 0xFB, 0xBE, 0xFF, 0x6C, 0x7E, 0xEF, 0x94,
  39325. 0xB5, 0x5D, 0xF8, 0x83, 0x1D, 0xDF, 0xB7, 0xB2,
  39326. 0x02, 0xCE, 0x7D, 0xE0, 0x55, 0xEA, 0xF9, 0x92,
  39327. 0x8A, 0xDA, 0xF6, 0xED, 0x0E, 0x31, 0x59, 0xCA,
  39328. 0x56, 0xC4, 0x83, 0xFA, 0x3B, 0xA3, 0xD2, 0x47,
  39329. 0x8C, 0xA3, 0x94, 0x82, 0x4C, 0xEE, 0x6A, 0xBD,
  39330. 0x59, 0x67, 0x09, 0x53, 0xEE, 0x80, 0xD3, 0x83,
  39331. 0xAA, 0xA6, 0x08, 0xE1, 0x58, 0x51, 0x13, 0x5C,
  39332. 0x1C, 0xDE, 0xEE, 0xB5, 0xF6, 0xA8, 0x89, 0x7C,
  39333. 0x3C, 0x9E, 0x06, 0x6A, 0xB4, 0x73, 0x4F, 0xDD,
  39334. 0xFA, 0xBC, 0x3B, 0xC3, 0xBA, 0x12, 0x06, 0xBA,
  39335. 0x54, 0x34, 0xDC, 0xDE, 0xDB, 0x9D, 0x8B, 0x3A,
  39336. 0x81, 0xA2, 0xE6, 0x38, 0x14, 0x6D, 0x83, 0xF1,
  39337. 0x4F, 0x06, 0xE5, 0x60, 0x99, 0xC0, 0xC8, 0xA0,
  39338. 0xFC, 0xCD, 0xB9, 0xEC, 0xF0, 0xF3, 0xD8, 0x8D,
  39339. 0xE3, 0x79, 0x2F, 0x2D, 0x0B, 0x65, 0x1B, 0x61,
  39340. 0x9C, 0x57, 0x1B, 0x69, 0xF4, 0xBF, 0x8E, 0x7C,
  39341. 0xD1, 0x91, 0x0F, 0x26, 0x6A, 0x4D, 0xAD, 0xF8,
  39342. 0xC2, 0xAB, 0xB4, 0xAC, 0x05, 0xBD, 0x1F, 0xBA,
  39343. 0x05, 0x8C, 0x03, 0x94, 0xC0, 0x16, 0xDE, 0xE6,
  39344. 0x0C, 0x66, 0x40, 0x1A, 0x17, 0xD1, 0x34, 0x59,
  39345. 0x54, 0x79, 0x33, 0x38, 0x9A, 0x35, 0x65, 0x69,
  39346. 0xAD, 0xA5, 0x32, 0xC9, 0xF4, 0x87, 0x69, 0x88,
  39347. 0x55, 0xA4, 0xD7, 0xBC, 0xCD, 0x0E, 0xF6, 0x95,
  39348. 0x31, 0x09, 0x4D, 0xA4, 0x08, 0x6F, 0x52, 0xBF,
  39349. 0x98, 0xCD, 0xC9, 0xA4, 0xB0, 0xBC, 0x88, 0x8D,
  39350. 0xC3, 0x89, 0x1A, 0x76, 0x09, 0x6C, 0x7C, 0x48,
  39351. 0x34, 0x90, 0xE9, 0x52, 0x32, 0x6A, 0xE4, 0x02,
  39352. 0xD8, 0xDF, 0xD2, 0xF3, 0xDC, 0xCF, 0x1A, 0xA5,
  39353. 0xD7, 0xBD, 0x69, 0x8E, 0x2A, 0xA8, 0x8D, 0x29,
  39354. 0x48, 0x13, 0xA8, 0x8F, 0xD3, 0x18, 0x66, 0xBC,
  39355. 0xA1, 0x1B, 0x3B, 0x91, 0xC0, 0x09, 0xEE, 0xB6,
  39356. 0x67, 0x60, 0x1C, 0xEE, 0xAF, 0xAF, 0xE9, 0x7C,
  39357. 0x56, 0xFA, 0x33, 0xF9, 0x38, 0x1F, 0x3E, 0x43,
  39358. 0x29, 0x90, 0x1A, 0xC3, 0xB7, 0xEA, 0x70, 0x32,
  39359. 0xC0, 0x19, 0xE5, 0xC8, 0xA8, 0xEF, 0xD7, 0x04,
  39360. 0x4C, 0x97, 0x36, 0x44, 0xAF, 0x2B, 0xE4, 0x20,
  39361. 0xA0, 0x33, 0xC6, 0xC2, 0xC7, 0xCE, 0x0C, 0xEA,
  39362. 0x39, 0x34, 0xDC, 0x18, 0xB4, 0x2A, 0xDF, 0xD7,
  39363. 0xA8, 0x46, 0xF4, 0x2D, 0xD4, 0x06, 0x86, 0x6A,
  39364. 0x39, 0x09, 0x29, 0x02, 0x6A, 0xDE, 0x5C, 0x79,
  39365. 0x1B, 0x5F, 0x61, 0xF9, 0x42, 0xB1, 0x55, 0x07,
  39366. 0x7D, 0x82, 0xF2, 0xAF, 0xCC, 0xFF, 0xF8, 0x5B,
  39367. 0x04, 0x06, 0x64, 0x7A, 0x96, 0x27, 0xE3, 0x69,
  39368. 0x5D, 0x4B, 0xEA, 0x3D, 0x58, 0xA6, 0x3E, 0x17,
  39369. 0x18, 0xD1, 0x84, 0xE4, 0x6B, 0x5F, 0x4B, 0xC8,
  39370. 0x41, 0x03, 0x34, 0xA4, 0x09, 0x5D, 0x0F, 0xAF,
  39371. 0x30, 0x6F, 0xB9, 0xDC, 0x10, 0x94, 0x25, 0xC3,
  39372. 0x16, 0x52, 0xD0, 0x6F, 0xF0, 0x51, 0xA1, 0x62,
  39373. 0xEE, 0x2B, 0x7B, 0x1C, 0x54, 0xD6, 0xC7, 0xDE,
  39374. 0xD6, 0xE3, 0x95, 0xAA, 0xD1, 0xA8, 0x6D, 0x03,
  39375. 0xB1, 0xB6, 0xC8, 0x00, 0x76, 0x7E, 0xC1, 0x44,
  39376. 0x12, 0xEE, 0xCE, 0x13, 0x46, 0x20, 0xA6, 0x1D,
  39377. 0x36, 0x9A, 0xF4, 0x9E, 0x21, 0xB0, 0xD1, 0x4B,
  39378. 0xC4, 0x23, 0x06, 0x49, 0xCD, 0xD3, 0xE9, 0xFD,
  39379. 0x84, 0x7A, 0xE5, 0x0B, 0xE9, 0x62, 0xEF, 0xC8,
  39380. 0xCB, 0x0F, 0x33, 0x9F, 0x9E, 0x6D, 0x32, 0x47,
  39381. 0x53, 0x3B, 0xDE, 0xD8, 0x71, 0x1D, 0x46, 0x1D,
  39382. 0x4A, 0xF2, 0xAE, 0x3F, 0xDD, 0x1D, 0x7D, 0x2A,
  39383. 0x28, 0x9C, 0x78, 0xCB, 0x19, 0xF3, 0xCD, 0xC2,
  39384. 0x14, 0x2B, 0xF5, 0x2B, 0x23, 0xE6, 0xA2, 0x7B,
  39385. 0x39, 0xD6, 0x99, 0x54, 0x3C, 0x3D, 0x63, 0x9B,
  39386. 0x9C, 0x72, 0xCA, 0x80, 0xB3, 0x7E, 0xA2, 0x77,
  39387. 0x5B, 0x5E, 0x26, 0x81, 0xF0, 0xDD, 0x01, 0xDF,
  39388. 0xF0, 0xC0, 0x55, 0x13, 0x36, 0x90, 0x62, 0xFE
  39389. };
  39390. static const byte msg_87[] = {
  39391. 0x9E, 0xFF, 0x34, 0x15, 0x06, 0xD1, 0x8B, 0xCB,
  39392. 0x27, 0xA7, 0xFC, 0x4E, 0xAA, 0xBF, 0x5A, 0x7C,
  39393. 0x4A, 0x59, 0x37, 0x77, 0x19, 0x6F, 0x66, 0x4B,
  39394. 0xCE, 0x31, 0x6C, 0x95, 0x5B, 0x83, 0x5A, 0xD4,
  39395. 0xC9, 0xF5, 0xDE, 0x9A, 0x2B, 0xF8, 0x96, 0x15,
  39396. 0xDA, 0xCB, 0x9C, 0x1E, 0x61, 0x8C, 0x78, 0xE7,
  39397. 0x11, 0x44, 0xCD, 0x4B, 0x70, 0x46, 0xF4, 0x7D,
  39398. 0x9A, 0x60, 0x0E, 0x9C, 0xE6, 0x65, 0x96, 0xC4,
  39399. 0xC5, 0x5E, 0xDA, 0x23, 0xA6, 0x6C, 0xC1, 0x18,
  39400. 0xA4, 0xA7, 0xBD, 0x0D, 0xED, 0x00, 0xAB, 0xDD,
  39401. 0xCE, 0x53, 0xFB, 0xF2, 0x48, 0x20, 0x33, 0xA4,
  39402. 0x18, 0x85, 0x06, 0xEC, 0x11, 0x3B, 0xBD, 0x98,
  39403. 0xD9, 0x89, 0x1F, 0x0D, 0x69, 0x46, 0x3A, 0x0D,
  39404. 0x36, 0x15, 0x6B, 0xA3, 0xEA, 0x0D, 0x02, 0xA1,
  39405. 0x4C, 0x1F, 0xD7, 0xA3, 0xFE, 0x70, 0x4E, 0xE5,
  39406. 0x6B, 0x44, 0x6A, 0xE1, 0x79, 0xF7, 0x2E, 0x10,
  39407. 0x4A, 0xA8, 0x1A, 0xF0, 0xA2, 0xF8, 0xFC, 0xA6,
  39408. 0xF6, 0xF9, 0x62, 0x96, 0x05, 0x9E, 0xE8, 0x82,
  39409. 0x66, 0x80, 0xE4, 0x3F, 0x4B, 0x07, 0x40, 0xF4,
  39410. 0x7A, 0xC1, 0x05, 0x66, 0xED, 0x31, 0x07, 0x99,
  39411. 0xAC, 0x71, 0x41, 0xD3, 0x8F, 0x69, 0x21, 0x31,
  39412. 0x5F, 0x23, 0xAB, 0x3E, 0x64, 0xC8, 0xA7, 0x70,
  39413. 0xAA, 0x57, 0x12, 0x80, 0x90, 0xDB, 0x82, 0x8C,
  39414. 0x7B, 0xAA, 0x59, 0xC3, 0x29, 0x5C, 0xCA, 0xA2,
  39415. 0x38, 0xC7, 0x5F, 0xAC, 0x0F, 0x93, 0xDA, 0x79,
  39416. 0x00, 0x74, 0x1B, 0xCD, 0x94, 0xBB, 0x9F, 0xD3,
  39417. 0x85, 0x2E, 0xC2, 0xB7, 0xD3, 0x3F, 0x60, 0x0B,
  39418. 0x1D, 0x51, 0x66, 0x6A, 0xE2, 0x22, 0xA5, 0x7A,
  39419. 0xF1, 0x40, 0xFA, 0x04, 0x9C, 0x2C, 0x9F, 0x6D,
  39420. 0x0F, 0xE6, 0xC0, 0xF1, 0xE7, 0xA0, 0xDD, 0xE1,
  39421. 0x14, 0x3B, 0xE5, 0xCE, 0xD7, 0xBB, 0xE2, 0x32,
  39422. 0xCB, 0xFB, 0xD8, 0xAE, 0x00, 0xEA, 0x5F, 0xC1,
  39423. 0x65, 0x02, 0x6D, 0x72, 0x9D, 0xB3, 0x0F, 0x6A,
  39424. 0xFD, 0x99, 0x73, 0xB6, 0x72, 0x2C, 0x07, 0xF6,
  39425. 0x00, 0x66, 0x54, 0x41, 0xE3, 0x0B, 0x7C, 0x5F,
  39426. 0xB2, 0x97, 0xB8, 0xAB, 0x96, 0x9C, 0x06, 0x83,
  39427. 0x9D, 0x33, 0x1D, 0xEE, 0x96, 0xDE, 0x48, 0x68,
  39428. 0x7D, 0xC9, 0xDA, 0x53, 0x1A, 0x95, 0xCA, 0x83,
  39429. 0xA7, 0x6F, 0x4B, 0x07, 0x6D, 0xFC, 0xF4, 0x83,
  39430. 0xF0, 0x04, 0x50, 0xE5, 0x1C, 0x8D, 0x34, 0xD8,
  39431. 0xED, 0x8E, 0x4B, 0x3D, 0xAF, 0xAE, 0x66, 0x4B,
  39432. 0x6D, 0xC1, 0x3E, 0xD8, 0x8E, 0x6D, 0x63, 0x02,
  39433. 0x7D, 0xD4, 0x38, 0xCB, 0x74, 0xF4, 0x12, 0xE8,
  39434. 0x70, 0xCC, 0x9D, 0xFD, 0x29, 0xB5, 0x2A, 0xBC,
  39435. 0xA1, 0x69, 0xC1, 0x7E, 0x97, 0x47, 0x58, 0xE0,
  39436. 0x3A, 0xC0, 0xFB, 0x7F, 0xE5, 0x64, 0x50, 0x8E,
  39437. 0x01, 0x7A, 0x9B, 0x47, 0x49, 0xD6, 0x41, 0xAF,
  39438. 0x0D, 0xE3, 0x84, 0x08, 0x8F, 0xA0, 0x0C, 0x69,
  39439. 0x40, 0x23, 0x3D, 0xDE, 0xFB, 0x65, 0x7C, 0x18,
  39440. 0x1C, 0x82, 0xA1, 0xB6, 0xA3, 0x1F, 0xCC, 0xF4,
  39441. 0xD5, 0x2C, 0x9D, 0x35, 0x1E, 0x6B, 0xDF, 0xDF,
  39442. 0x48, 0xBC, 0xE4, 0x14, 0x60, 0x74, 0x62, 0xDB,
  39443. 0x76, 0x9F, 0x9E, 0xB1, 0x59, 0x25, 0xBA, 0x9F,
  39444. 0xAF, 0xBA, 0xB2, 0x29, 0xB5, 0x89, 0x6B, 0xF1,
  39445. 0xF8, 0xE4, 0x7D, 0xF1, 0x7C, 0x82, 0x08, 0xDF,
  39446. 0xD5, 0x96, 0x04, 0xB6, 0x05, 0x2C, 0xD2, 0xCE,
  39447. 0xAB, 0x56, 0x40, 0x0F, 0x11, 0xC4, 0xD9, 0x52,
  39448. 0x1E, 0x1A, 0xB8, 0x27, 0x4A, 0xB5, 0x76, 0x4C,
  39449. 0x73, 0xE9, 0x41, 0x32, 0x42, 0x0E, 0x32, 0xB6,
  39450. 0xAE, 0xB0, 0x76, 0x33, 0x78, 0xD9, 0xBA, 0x68,
  39451. 0xE1, 0xFC, 0xDE, 0x2B, 0xD6, 0xDE, 0xDA, 0x39,
  39452. 0x17, 0xC0, 0x00, 0xAF, 0x39, 0xB7, 0x8F, 0x4C,
  39453. 0xCA, 0x7C, 0x8F, 0xBF, 0x94, 0xB4, 0xCB, 0x8A,
  39454. 0x81, 0x16, 0xEE, 0xEC, 0xFE, 0xF0, 0x13, 0x1E,
  39455. 0xC9, 0xF2, 0xDE, 0xDA, 0x01, 0x40, 0xC9, 0x02,
  39456. 0xA8, 0xD6, 0xE6, 0x0E, 0x98, 0xB3, 0xCD, 0x9D,
  39457. 0x9C, 0x75, 0x24, 0x8B, 0xF8, 0x84, 0x5A, 0xC0,
  39458. 0xD7, 0xE0, 0x6B, 0xA0, 0xE1, 0x83, 0x10, 0xFE,
  39459. 0xCE, 0x98, 0x62, 0x07, 0x54, 0x2C, 0xC1, 0xEE,
  39460. 0x08, 0x88, 0x43, 0xEF, 0x74, 0xA2, 0x6A, 0xEC,
  39461. 0xB6, 0xD0, 0x6F, 0x0F, 0xEF, 0xE1, 0xB7, 0x2C,
  39462. 0xF9, 0x33, 0x06, 0xC3, 0x2E, 0xD2, 0x8A, 0xEC,
  39463. 0xC5, 0x5B, 0xB1, 0x03, 0xA0, 0x84, 0x6D, 0x0C,
  39464. 0x84, 0x13, 0x6D, 0xB0, 0xB0, 0x54, 0xF3, 0xDE,
  39465. 0xA3, 0x9A, 0x72, 0x6C, 0x6F, 0xD6, 0x59, 0x7F,
  39466. 0x9B, 0x03, 0x8C, 0xC2, 0x38, 0x46, 0x01, 0x76,
  39467. 0x38, 0xF4, 0x43, 0x68, 0x81, 0x0D, 0x86, 0x29,
  39468. 0x3D, 0xDF, 0xE5, 0x48, 0x61, 0x53, 0x2F, 0x85,
  39469. 0xF5, 0x3F, 0x09, 0x30, 0x48, 0xC3, 0xE0, 0x09,
  39470. 0xC4, 0x32, 0x11, 0x27, 0xAD, 0xAA, 0xEC, 0x6A,
  39471. 0x5C, 0xCE, 0x03, 0xE0, 0xD9, 0xE9, 0x1D, 0xAC,
  39472. 0xCA, 0xBB, 0x2F, 0x50, 0xE0, 0x1E, 0xB2, 0xAC,
  39473. 0x2B, 0x39, 0x6D, 0x24, 0xB0, 0x5D, 0x45, 0x3B,
  39474. 0xD5, 0x1D, 0x52, 0x9F, 0xBA, 0x51, 0xE4, 0x6D,
  39475. 0x30, 0xC5, 0x66, 0x13, 0x00, 0x5A, 0xBF, 0x62,
  39476. 0x63, 0xB9, 0x8D, 0x8D, 0xFE, 0xB5, 0x26, 0x16,
  39477. 0xD1, 0xCB, 0x78, 0x92, 0x18, 0x1C, 0x2F, 0xC2,
  39478. 0xE2, 0x04, 0x3B, 0x99, 0x4C, 0x81, 0x66, 0x58,
  39479. 0x48, 0x2E, 0x06, 0x06, 0x34, 0x83, 0x78, 0xA3,
  39480. 0xCC, 0x85, 0x40, 0xE0, 0x20, 0x27, 0x3F, 0x10,
  39481. 0xB6, 0x9E, 0x20, 0x21, 0xA9, 0x2D, 0x9C, 0x36,
  39482. 0xCC, 0x9B, 0x97, 0x79, 0xFE, 0x8C, 0xE7, 0xA4,
  39483. 0x99, 0xAE, 0xB5, 0x3E, 0xC6, 0xDD, 0xB4, 0xF2,
  39484. 0xEC, 0x22, 0xBF, 0xB4, 0x52, 0xFC, 0x5E, 0x79,
  39485. 0x7D, 0x3A, 0x25, 0x33, 0x26, 0x00, 0x06, 0xFE,
  39486. 0x6D, 0xCC, 0xE4, 0xE9, 0x76, 0x65, 0xC6, 0x8C,
  39487. 0x39, 0x93, 0xDC, 0x7E, 0xA0, 0xBD, 0x4B, 0xDC,
  39488. 0xD2, 0x47, 0x21, 0xB0, 0x2B, 0x09, 0x02, 0xB1,
  39489. 0x84, 0x0D, 0xDE, 0xC5, 0x18, 0x20, 0x38, 0x76,
  39490. 0x2D, 0x55, 0xFC, 0x11, 0xB9, 0x87, 0x3A, 0x0D,
  39491. 0xD2, 0xEB, 0xBD, 0x55, 0xAD, 0xE3, 0x86, 0x5C,
  39492. 0xFF, 0x3D, 0x54, 0x5F, 0x76, 0x33, 0x53, 0x69,
  39493. 0xDD, 0x9E, 0x70, 0xB0, 0x73, 0x99, 0x77, 0xF6,
  39494. 0xE9, 0x8A, 0x61, 0x27, 0x19, 0x4A, 0x19, 0x26,
  39495. 0xA6, 0x97, 0xE4, 0x7F, 0x73, 0xE0, 0x4F, 0xF5,
  39496. 0xBD, 0x52, 0x5E, 0x8F, 0x17, 0x22, 0x00, 0x8F,
  39497. 0x7C, 0x15, 0x5C, 0xD3, 0xAD, 0xE0, 0xA5, 0xB6,
  39498. 0x6A, 0x31, 0x36, 0xFD, 0xD8, 0x44, 0xAE, 0x5E,
  39499. 0xCD, 0x6C, 0x82, 0x77, 0xC3, 0xD0, 0x7F, 0x39,
  39500. 0x72, 0x1E, 0x91, 0x19, 0x50, 0xE1, 0x28, 0x20,
  39501. 0x88, 0x3A, 0x6B, 0xC8, 0xA9, 0xE7, 0x93, 0x28,
  39502. 0x0F, 0xA7, 0x4F, 0xF2, 0x1A, 0xC2, 0x13, 0x4E,
  39503. 0x6B, 0xAE, 0x71, 0x3F, 0x43, 0x89, 0xC9, 0xE7,
  39504. 0xDD, 0x05, 0xBB, 0x41, 0x09, 0xB5, 0x5E, 0xB9,
  39505. 0x23, 0x51, 0xC0, 0xEB, 0x92, 0x1A, 0x0C, 0x3F,
  39506. 0xAC, 0xC5, 0x00, 0x8C, 0xB8, 0x5C, 0x3F, 0x2D,
  39507. 0x5F, 0x9A, 0xCE, 0xAE, 0x9B, 0x4B, 0x71, 0x48,
  39508. 0x25, 0xFD, 0xE2, 0xB6, 0x26, 0x3F, 0xEE, 0x10,
  39509. 0x33, 0x07, 0x4F, 0x59, 0xF0, 0x73, 0xE9, 0x39,
  39510. 0x5C, 0x0D, 0x8B, 0xB5, 0xD1, 0xEF, 0xE5, 0xBF,
  39511. 0xBB, 0xE1, 0x80, 0xF7, 0xC5, 0x91, 0xC1, 0x72,
  39512. 0xAA, 0xB0, 0x5E, 0x7C, 0x53, 0x69, 0x4C, 0x37,
  39513. 0x7A, 0xD2, 0x7B, 0x9D, 0x1C, 0xFA, 0x0F, 0xE0,
  39514. 0x92, 0x93, 0x40, 0x5D, 0xBE, 0x1C, 0xF8, 0x84,
  39515. 0x7A, 0x35, 0x1F, 0x72, 0x77, 0x68, 0xE2, 0xAF,
  39516. 0xA5, 0x6B, 0x54, 0xFF, 0x53, 0x7C, 0xCD, 0x9D,
  39517. 0x6A, 0x49, 0xD1, 0xCA, 0x74, 0x5F, 0xF5, 0xDB,
  39518. 0x54, 0xF8, 0x60, 0xA7, 0x41, 0x66, 0xDE, 0xFF,
  39519. 0xB0, 0xB2, 0xF9, 0x21, 0x06, 0xB7, 0x81, 0x4C,
  39520. 0x9C, 0xEF, 0xFD, 0x11, 0xD5, 0x63, 0xD8, 0xF3,
  39521. 0x3A, 0x81, 0xC4, 0x9D, 0x1B, 0xA8, 0x37, 0x73,
  39522. 0x57, 0x26, 0x29, 0xF8, 0xB4, 0x7F, 0x9F, 0xA2,
  39523. 0x7D, 0x2A, 0x63, 0x2C, 0x70, 0x08, 0x1E, 0x2E,
  39524. 0xE7, 0xED, 0x73, 0xAB, 0xD2, 0x4C, 0x02, 0x7E,
  39525. 0xF1, 0x15, 0x26, 0xE1, 0x09, 0x5C, 0x29, 0x13,
  39526. 0xDF, 0x69, 0x29, 0x25, 0xE5, 0x68, 0x39, 0x10,
  39527. 0x9B, 0xD0, 0x5E, 0xD8, 0xE2, 0xC9, 0x08, 0x61,
  39528. 0x63, 0xCD, 0xF9, 0x45, 0xBC, 0x16, 0xDC, 0x80,
  39529. 0x4C, 0x0F, 0x61, 0xEE, 0x8F, 0x3B, 0x72, 0xDB,
  39530. 0x02, 0x45, 0xF6, 0x78, 0x69, 0x81, 0xFC, 0xE0,
  39531. 0x32, 0x2F, 0xC2, 0xAF, 0xCD, 0x4E, 0x8E, 0x52,
  39532. 0x03, 0xB5, 0x1C, 0x7C, 0x37, 0x2C, 0x58, 0xD5,
  39533. 0xE2, 0x92, 0xA7, 0xE2, 0x49, 0x6C, 0x3F, 0x5D,
  39534. 0x7F, 0x2B, 0x26, 0x70, 0x1C, 0x0C, 0x16, 0x7F,
  39535. 0x49, 0x30, 0x71, 0x14, 0xEB, 0xBE, 0x13, 0xF4,
  39536. 0xF1, 0xAA, 0x5A, 0xCF, 0x98, 0xF2, 0x07, 0x29,
  39537. 0xB5, 0x12, 0x84, 0x80, 0x01, 0x46, 0x11, 0xA4,
  39538. 0x44, 0xAE, 0x6D, 0xE0, 0x43, 0x7F, 0xFD, 0x5D,
  39539. 0x84, 0xB5, 0x6E, 0x3E, 0x55, 0x0D, 0xE8, 0x66,
  39540. 0x13, 0xA9, 0x28, 0x5A, 0x10, 0x84, 0x0B, 0xED,
  39541. 0x0B, 0x69, 0xF0, 0x19, 0x69, 0x9B, 0x34, 0xB8,
  39542. 0x6F, 0xC6, 0x22, 0xD3, 0x25, 0x26, 0x9D, 0x1A,
  39543. 0x04, 0x6B, 0x53, 0xA4, 0xDF, 0x12, 0x93, 0xA5,
  39544. 0x2C, 0xEE, 0x1C, 0x35, 0xFE, 0x81, 0x6B, 0x67,
  39545. 0x81, 0x92, 0x07, 0xE0, 0x9A, 0x02, 0xC9, 0xD8,
  39546. 0x59, 0x4D, 0x51, 0xE8, 0xB3, 0x14, 0x55, 0x2F,
  39547. 0xDE, 0x26, 0xDB, 0x7C, 0xEB, 0x8D, 0x80, 0x12,
  39548. 0x4A, 0x8A, 0x1C, 0x33, 0x74, 0x8E, 0x05, 0xC1,
  39549. 0xAF, 0xD6, 0xE8, 0x7B, 0x56, 0x7C, 0x41, 0xE0,
  39550. 0xE7, 0x3F, 0x32, 0x5F, 0x25, 0xDD, 0x2F, 0x48,
  39551. 0x21, 0x90, 0xC4, 0x04, 0x42, 0x1A, 0x3D, 0x6A,
  39552. 0x0E, 0x5D, 0x5C, 0xDB, 0xE2, 0xB0, 0x18, 0x8B,
  39553. 0xAC, 0x77, 0xC6, 0xE3, 0x5D, 0x77, 0xC0, 0xA3,
  39554. 0x2B, 0x1D, 0x96, 0x29, 0xF8, 0x8E, 0x70, 0xA7,
  39555. 0x65, 0xFE, 0xE3, 0x8C, 0x1A, 0xB2, 0x39, 0x75,
  39556. 0xB9, 0x45, 0xF2, 0x16, 0x1F, 0x6C, 0xFE, 0x7E,
  39557. 0x68, 0x2A, 0xED, 0x96, 0x84, 0x95, 0x47, 0x05,
  39558. 0x1D, 0xDE, 0xB7, 0x7B, 0x90, 0xF6, 0xAF, 0x00,
  39559. 0x74, 0x7C, 0x47, 0xE0, 0x2E, 0x80, 0xB6, 0x9A,
  39560. 0x0D, 0x4B, 0x78, 0xA4, 0x7D, 0xDD, 0x81, 0xE2,
  39561. 0x99, 0x27, 0x1F, 0xA7, 0x8F, 0xE4, 0x23, 0xAD,
  39562. 0xDF, 0x12, 0x0D, 0xD0, 0x4D, 0x46, 0xC1, 0x32,
  39563. 0xE9, 0x70, 0xF4, 0xA0, 0x4E, 0x97, 0xA5, 0x88,
  39564. 0xD2, 0x7C, 0x7B, 0xA8, 0x43, 0x26, 0x18, 0x2A,
  39565. 0xAE, 0x04, 0xC2, 0x51, 0x28, 0x99, 0x71, 0x69,
  39566. 0x1D, 0x96, 0x78, 0xD4, 0x09, 0x88, 0x16, 0x88,
  39567. 0xF3, 0xBC, 0xCB, 0x95, 0x08, 0x30, 0xE6, 0x5B,
  39568. 0x78, 0x48, 0x41, 0x00, 0x4E, 0x40, 0x44, 0x58,
  39569. 0xE6, 0x16, 0x59, 0x63, 0xCF, 0xB4, 0xEE, 0xB5,
  39570. 0x05, 0xFD, 0xD1, 0x35, 0xF3, 0x1E, 0xD0, 0x14,
  39571. 0x7C, 0xC9, 0xE9, 0x87, 0x7F, 0xFF, 0x41, 0x07,
  39572. 0x68, 0x91, 0x06, 0x17, 0x4E, 0x76, 0x66, 0xEE,
  39573. 0xCB, 0x6C, 0xF2, 0xDA, 0x9C, 0x93, 0x51, 0xDC,
  39574. 0x43, 0x4A, 0x94, 0x49, 0x38, 0x4E, 0xED, 0x7F,
  39575. 0x5F, 0x90, 0x77, 0xB4, 0x2F, 0x0F, 0xC5, 0xD9,
  39576. 0xF0, 0xF5, 0xF7, 0x21, 0x91, 0x32, 0xFF, 0x9A,
  39577. 0x47, 0x09, 0x83, 0xE1, 0x9D, 0x30, 0xA4, 0xF3,
  39578. 0x7D, 0x18, 0x97, 0x44, 0xD8, 0x32, 0xFD, 0x5F,
  39579. 0xB3, 0x97, 0x49, 0x4E, 0x11, 0xAD, 0xF7, 0x4F,
  39580. 0x4E, 0x90, 0x0A, 0x41, 0x87, 0xCF, 0xF5, 0xDA,
  39581. 0x8F, 0x6D, 0x7B, 0x35, 0xAE, 0xA0, 0x16, 0xA8,
  39582. 0xDE, 0x88, 0x62, 0x26, 0x5F, 0x13, 0x69, 0xFB,
  39583. 0x36, 0x7E, 0xF1, 0x86, 0x0C, 0x8E, 0x07, 0xC3,
  39584. 0x3F, 0x32, 0x82, 0xB4, 0xD9, 0x83, 0x7C, 0xDF,
  39585. 0x3E, 0xF6, 0x58, 0x42, 0x2D, 0x34, 0xDE, 0xA4,
  39586. 0x1E, 0x56, 0xDD, 0x18, 0x70, 0x36, 0x81, 0xD0,
  39587. 0x44, 0xE3, 0xC4, 0x03, 0xAF, 0x33, 0xD1, 0xE7,
  39588. 0xAF, 0xA9, 0x6A, 0x8C, 0x44, 0x35, 0xFE, 0xBB,
  39589. 0xA0, 0xD2, 0x5D, 0xE0, 0xE4, 0xAE, 0xDF, 0xFB,
  39590. 0x82, 0xA0, 0xBA, 0xDE, 0x76, 0xB6, 0x6C, 0xA9,
  39591. 0xBE, 0xC7, 0xE9, 0xD7, 0x3F, 0x1C, 0xB2, 0x9C,
  39592. 0xD7, 0x3C, 0xF0, 0x0C, 0x2F, 0x60, 0x44, 0xD8,
  39593. 0x34, 0x53, 0xCE, 0xDD, 0xE0, 0x3F, 0x97, 0x2E,
  39594. 0xBB, 0x03, 0x20, 0x62, 0xD0, 0xA8, 0x23, 0x9F,
  39595. 0xB6, 0x99, 0xEC, 0x89, 0x0D, 0x32, 0x0F, 0x6F,
  39596. 0xAF, 0x3D, 0x20, 0x7B, 0xDC, 0x9A, 0xFE, 0xA2,
  39597. 0x02, 0x8B, 0x86, 0x99, 0x56, 0x23, 0x43, 0xAA,
  39598. 0x50, 0xF7, 0x0A, 0x4E, 0x8C, 0x62, 0xDA, 0xF8,
  39599. 0xB8, 0xCC, 0xA7, 0x2D, 0x02, 0x47, 0x63, 0xBA,
  39600. 0xEC, 0x25, 0x00, 0x23, 0xEA, 0xE8, 0x25, 0xC6,
  39601. 0x51, 0xAC, 0xC4, 0xAA, 0xA0, 0xDB, 0x6C, 0x5E,
  39602. 0xC7, 0xEF, 0xD0, 0x71, 0xED, 0xFB, 0x95, 0xAF,
  39603. 0x61, 0x0B, 0x64, 0x01, 0x61, 0x4F, 0x4F, 0xC6,
  39604. 0x36, 0x27, 0x75, 0xC3, 0x81, 0x0A, 0x9A, 0x21,
  39605. 0x69, 0xF8, 0x4A, 0x21, 0x12, 0x3B, 0x03, 0x1C,
  39606. 0xCE, 0x08, 0x7D, 0x52, 0x0E, 0x99, 0xE2, 0x62,
  39607. 0xE8, 0x81, 0x2E, 0x84, 0x09, 0x8E, 0xBE, 0x9B,
  39608. 0xCE, 0xD6, 0xE6, 0xA4, 0xF7, 0x3B, 0x67, 0x45,
  39609. 0x41, 0xDE, 0x0B, 0xCF, 0x5E, 0x7E, 0x31, 0x8F,
  39610. 0x90, 0x6D, 0x90, 0x1F, 0xEB, 0x1D, 0x9D, 0x1C,
  39611. 0xCB, 0x6C, 0xFF, 0xE8, 0x50, 0xDB, 0xFF, 0x75,
  39612. 0xC8, 0xA8, 0x9F, 0x43, 0xCB, 0x94, 0x89, 0x5F,
  39613. 0x28, 0x69, 0x6F, 0xAB, 0xB6, 0xAD, 0xCE, 0xE7,
  39614. 0x69, 0x7E, 0x60, 0x09, 0x03, 0x87, 0x43, 0x6E,
  39615. 0x19, 0xB1, 0x38, 0x81, 0x9B, 0x90, 0xAE, 0xB1,
  39616. 0x8A, 0xC2, 0x7D, 0x2C, 0x65, 0x9B, 0x0D, 0xF1,
  39617. 0x77, 0x94, 0xA7, 0x2F, 0x8B, 0xB7, 0xCE, 0x03,
  39618. 0xEE, 0x9A, 0x78, 0xFE, 0x8C, 0x8A, 0x37, 0x45,
  39619. 0xD5, 0x05, 0xDE, 0xD8, 0x85, 0x00, 0xF4, 0xCF,
  39620. 0x98, 0xFB, 0x62, 0x85, 0xB0, 0xBD, 0x82, 0xE2,
  39621. 0x7D, 0xED, 0x93, 0x3B, 0xCC, 0x18, 0x73, 0xF8,
  39622. 0x8A, 0xBD, 0x82, 0x8F, 0x60, 0x47, 0xAC, 0xEC,
  39623. 0x47, 0x2D, 0xEA, 0xE8, 0x7D, 0x8A, 0xDE, 0x0A,
  39624. 0xD0, 0x73, 0x48, 0xFF, 0xAF, 0x59, 0xC1, 0x70,
  39625. 0x29, 0xD8, 0x45, 0x38, 0x77, 0x7F, 0x73, 0xBF,
  39626. 0xED, 0x5C, 0x63, 0x63, 0x0B, 0xC4, 0x43, 0xE0,
  39627. 0xFA, 0x12, 0xDE, 0x72, 0x2D, 0xAB, 0xBB, 0xC2,
  39628. 0x25, 0x0A, 0xBA, 0x3F, 0xD8, 0x61, 0x54, 0xEE,
  39629. 0x20, 0x8D, 0x53, 0xA3, 0x27, 0xA7, 0xFF, 0x26,
  39630. 0xA0, 0x17, 0x93, 0x39, 0x4D, 0x04, 0x15, 0x8B,
  39631. 0xB3, 0x20, 0x60, 0x04, 0x47, 0xE2, 0xFD, 0x7D,
  39632. 0x7C, 0x6D, 0xE0, 0x76, 0xA5, 0x13, 0xD6, 0x81,
  39633. 0x95, 0xB0, 0x67, 0x20, 0x4F, 0xF6, 0x00, 0x5B,
  39634. 0x16, 0x25, 0x54, 0x2B, 0x28, 0x37, 0x2F, 0x06,
  39635. 0x80, 0x60, 0x53, 0xAE, 0xE2, 0xEA, 0x9F, 0x88,
  39636. 0xAE, 0xA2, 0x9A, 0x27, 0x02, 0x15, 0x4B, 0xF4,
  39637. 0x43, 0xBC, 0x70, 0x7D, 0x0A, 0x96, 0xEB, 0x06,
  39638. 0xCE, 0x43, 0xEF, 0xE6, 0x6A, 0xAC, 0x1F, 0x16,
  39639. 0x95, 0xE2, 0x8C, 0xF1, 0x07, 0x19, 0x3D, 0x06,
  39640. 0x2E, 0x71, 0xB6, 0x3A, 0xFD, 0xCF, 0x9E, 0x05,
  39641. 0x0B, 0xBE, 0xD7, 0x48, 0x4E, 0xC5, 0xE8, 0x0C,
  39642. 0x51, 0x5A, 0xC8, 0x20, 0xF0, 0xCD, 0xF9, 0x65,
  39643. 0xDD, 0x97, 0xF7, 0xA1, 0x1B, 0x57, 0xB2, 0x1A,
  39644. 0x04, 0xBF, 0x42, 0xF2, 0xA3, 0x3D, 0x61, 0x97,
  39645. 0x64, 0xDF, 0xB3, 0x63, 0x11, 0xFD, 0xAD, 0x8C,
  39646. 0x83, 0xA7, 0x48, 0xBA, 0x34, 0x42, 0xC5, 0x70,
  39647. 0x64, 0x5A, 0x78, 0x5E, 0x67, 0x03, 0xE5, 0xBF,
  39648. 0x22, 0xE8, 0x46, 0xFC, 0x51, 0x6C, 0xB4, 0x99,
  39649. 0x15, 0xFD, 0x63, 0xB6, 0x3E, 0x5D, 0xBF, 0x56,
  39650. 0xF5, 0x5E, 0xA4, 0x01, 0x16, 0xD5, 0x03, 0x4B,
  39651. 0xBB, 0x94, 0x5F, 0x58, 0xD6, 0x76, 0x95, 0xC7,
  39652. 0x96, 0xF1, 0xC1, 0xD0, 0x53, 0xA3, 0xEB, 0x28,
  39653. 0xA9, 0x5E, 0x8F, 0x38, 0x8E, 0x80, 0x04, 0xC3,
  39654. 0xB2, 0x4F, 0xD5, 0xFC, 0xCA, 0x7B, 0xB1, 0xE3,
  39655. 0xB9, 0x9A, 0x9F, 0x3C, 0x94, 0x5E, 0xF8, 0xA5,
  39656. 0x35, 0xF1, 0x37, 0x43, 0x20, 0x71, 0xA5, 0xCA,
  39657. 0x5B, 0x6F, 0x7D, 0xC7, 0xB8, 0xBC, 0xE5, 0x5A,
  39658. 0xD0, 0xF3, 0xB6, 0xCF, 0x1B, 0xCB, 0xB9, 0xCD,
  39659. 0x35, 0xE2, 0x41, 0xF8, 0x6E, 0x46, 0x97, 0x27,
  39660. 0x26, 0x48, 0xF4, 0x73, 0xDB, 0xD5, 0xB7, 0x68,
  39661. 0x1E, 0xF0, 0xC7, 0x84, 0x49, 0xE6, 0xC5, 0xFA,
  39662. 0x93, 0x0D, 0x83, 0x2C, 0x85, 0x1E, 0xED, 0x2A,
  39663. 0x65, 0x12, 0x19, 0xD7, 0xD9, 0xC3, 0xBB, 0x23,
  39664. 0xF3, 0xC6, 0xAD, 0x7E, 0xB7, 0x78, 0x68, 0x54,
  39665. 0x1F, 0x3C, 0xEE, 0x09, 0xF5, 0x1E, 0xE0, 0x4E,
  39666. 0xBA, 0x1B, 0xBC, 0x29, 0x69, 0x8A, 0xED, 0xD3,
  39667. 0xC7, 0xAC, 0xEC, 0x44, 0x29, 0xD7, 0xA4, 0x0C,
  39668. 0xFA, 0xBD, 0xA2, 0x29, 0x34, 0x80, 0x16, 0x4F,
  39669. 0x37, 0xEC, 0xB6, 0x73, 0xF2, 0xB5, 0xD7, 0x51,
  39670. 0x57, 0x43, 0xAF, 0x7E, 0xD0, 0xB6, 0xE0, 0x96,
  39671. 0xF0, 0xE2, 0xFE, 0xCE, 0xC8, 0x9F, 0x40, 0xD6,
  39672. 0xAF, 0xE0, 0xBF, 0xCD, 0x70, 0x37, 0x91, 0x69,
  39673. 0x99, 0x8C, 0xDF, 0x4A, 0x20, 0xDE, 0xB6, 0xC6,
  39674. 0x7A, 0xB4, 0xE3, 0x6A, 0xAD, 0x53, 0xED, 0xB9,
  39675. 0x8A, 0x13, 0x61, 0xC5, 0xE9, 0xB0, 0xDC, 0x16,
  39676. 0x36, 0xD7, 0x51, 0xA8, 0x7B, 0x52, 0x05, 0x3B,
  39677. 0xAD, 0x5C, 0xD2, 0xBD, 0x6F, 0x6B, 0xA9, 0x51,
  39678. 0xA7, 0xE8, 0x7E, 0xA4, 0xB6, 0x77, 0xAE, 0x00,
  39679. 0x89, 0x3A, 0x1F, 0x76, 0x72, 0x3F, 0xC5, 0x6C,
  39680. 0x49, 0x4F, 0xB5, 0xCA, 0x2F, 0x5D, 0xAE, 0xF8,
  39681. 0x58, 0x9A, 0xE2, 0x5B, 0x54, 0x76, 0xF4, 0xAA,
  39682. 0x89, 0xD4, 0x04, 0xAF, 0x1C, 0x26, 0x65, 0xEC,
  39683. 0xA1, 0x81, 0x06, 0x2A, 0x4B, 0x5E, 0xD5, 0x90,
  39684. 0xB8, 0x26, 0x33, 0x64, 0x15, 0x33, 0x25, 0xAC,
  39685. 0x97, 0x9A, 0xCA, 0x1B, 0x64, 0x50, 0x82, 0x8F,
  39686. 0x65, 0x6A, 0xD4, 0x47, 0xCF, 0x7E, 0x93, 0x7D,
  39687. 0xB3, 0xCB, 0xFE, 0x55, 0x0A, 0x46, 0x93, 0x22,
  39688. 0xB5, 0x46, 0xAB, 0xD6, 0x05, 0x59, 0x14, 0x5E,
  39689. 0x1B, 0xD4, 0x2D, 0xAF, 0xA3, 0x18, 0xB7, 0xA0,
  39690. 0xD7, 0x11, 0x70, 0xDE, 0x81, 0x8B, 0xD6, 0x64,
  39691. 0xFD, 0x38, 0xBD, 0x29, 0x92, 0x41, 0x80, 0xC4,
  39692. 0x4A, 0x6D, 0x34, 0x1B, 0xF0, 0x59, 0xA0, 0xD6,
  39693. 0x48, 0x55, 0xD2, 0xA5, 0xE2, 0x91, 0xB6, 0x71,
  39694. 0xF4, 0x90, 0x97, 0x8B, 0x0A, 0xDD, 0x90, 0xEA,
  39695. 0x61, 0x9B, 0x30, 0xA6, 0x2F, 0x5D, 0xB4, 0xEE,
  39696. 0x7A, 0x10, 0x40, 0x59, 0x89, 0xAC, 0x30, 0x6E,
  39697. 0x9C, 0x7B, 0xBC, 0x11, 0x75, 0x38, 0x00, 0x2E,
  39698. 0xDF, 0xED, 0x87, 0x47, 0x30, 0xFB, 0xD4, 0x8A,
  39699. 0xC6, 0xBE, 0xC7, 0x20, 0xC8, 0x3D, 0x51, 0x05,
  39700. 0x67, 0x48, 0xDE, 0xE2, 0xBF, 0x95, 0x5E, 0x7B,
  39701. 0xD7, 0xC7, 0x86, 0xDF, 0x68, 0x57, 0xA9, 0x29,
  39702. 0xBC, 0xF8, 0xE3, 0x81, 0x62, 0x1B, 0x37, 0x58,
  39703. 0xF2, 0xFF, 0xEE, 0xE8, 0x28, 0x08, 0x36, 0x23,
  39704. 0x5B, 0x24, 0x68, 0x1E, 0x62, 0xBD, 0x27, 0xC2,
  39705. 0x6F, 0xE9, 0x63, 0x67, 0x53, 0xC7, 0x8A, 0xB5,
  39706. 0xA7, 0xEF, 0x29, 0xFE, 0x60, 0xAC, 0x29, 0xCF,
  39707. 0x67, 0x40, 0x9F, 0xE6, 0x57, 0xCE, 0x65, 0x3A,
  39708. 0x2F, 0xDA, 0xA7, 0xF2, 0x0C, 0x50, 0x19, 0xE6,
  39709. 0xF7, 0x43, 0x2E, 0x8C, 0xEB, 0x9E, 0x99, 0x92,
  39710. 0xE6, 0x46, 0xB7, 0x8D, 0x43, 0x65, 0xFD, 0x02,
  39711. 0x17, 0x74, 0x6F, 0x7B, 0xA3, 0x1E, 0x06, 0x9D,
  39712. 0x75, 0x4E, 0x05, 0xED, 0x5A, 0x71, 0xFC, 0x5E,
  39713. 0x7D, 0x6D, 0x64, 0x5E, 0xAF, 0x41, 0x44, 0xD6,
  39714. 0xBC, 0x43, 0x05, 0x5E, 0x6C, 0xDB, 0x89, 0x34,
  39715. 0xC7, 0x02, 0x64, 0x08, 0xAE, 0x96, 0x53, 0x5B,
  39716. 0xA2, 0xDE, 0xCD, 0x2F, 0x74, 0x56, 0xD6, 0xEC,
  39717. 0xA4, 0x23, 0x68, 0xCD, 0x9A, 0xC5, 0x05, 0x7B,
  39718. 0x7D, 0x1E, 0x12, 0xF7, 0x7A, 0xA8, 0x7C, 0x43,
  39719. 0x7E, 0x7A, 0x43, 0x31, 0x5D, 0xA0, 0x81, 0xE5,
  39720. 0x3A, 0xFE, 0x23, 0xB5, 0xBC, 0xC2, 0xF4, 0xCE,
  39721. 0x3A, 0x80, 0x06, 0xE8, 0x1E, 0x08, 0xAF, 0x0A,
  39722. 0x33, 0xC1, 0xA9, 0x30, 0x7C, 0x8D, 0x5A, 0xC5,
  39723. 0x93, 0x89, 0xF2, 0x69, 0x24, 0x11, 0x6C, 0xAB,
  39724. 0x0B, 0x87, 0xD5, 0x49, 0xD0, 0x38, 0x3C, 0x27,
  39725. 0x4E, 0x8E, 0x85, 0xD4, 0x6E, 0x0F, 0xCD, 0x70,
  39726. 0xE3, 0x68, 0x42, 0xCA, 0x4C, 0x8D, 0x6D, 0x0F,
  39727. 0x48, 0xF3, 0xED, 0xF9, 0xE9, 0x43, 0x5D, 0xBF,
  39728. 0x55, 0x75, 0xF8, 0xEB, 0x78, 0x93, 0x72, 0x75,
  39729. 0x8B, 0xF5, 0xBD, 0xE9, 0x9D, 0xA2, 0xB9, 0x81,
  39730. 0x83, 0xDB, 0xAC, 0x82, 0xD1, 0xC1, 0x20, 0x03,
  39731. 0x72, 0x4D, 0xDC, 0x42, 0xAE, 0xC8, 0x1C, 0x0C,
  39732. 0x78, 0x22, 0x77, 0x27, 0x91, 0x50, 0x4C, 0x90,
  39733. 0xEA, 0x13, 0x8B, 0x6C, 0x91, 0xDF, 0x5D, 0x25,
  39734. 0x36, 0x9C, 0xC2, 0x06, 0x4F, 0xD5, 0xE2, 0xCC,
  39735. 0x9D, 0x89, 0x3B, 0xC4, 0x23, 0x5D, 0x88, 0x17,
  39736. 0x62, 0x4E, 0xC9, 0xFA, 0xC8, 0xEF, 0x1D, 0x45,
  39737. 0xE1, 0xFB, 0x58, 0xB3, 0x8E, 0xBD, 0x8D, 0xAE,
  39738. 0x12, 0xFF, 0xA0, 0x37, 0xE0, 0x7F, 0x5B, 0x41,
  39739. 0x1D, 0x40, 0x17, 0xAF, 0x95, 0x2D, 0x8C, 0x42,
  39740. 0xC6, 0x1A, 0x2A, 0x1E, 0x8E, 0x70, 0x25, 0xD6,
  39741. 0xD3, 0xA2, 0x85, 0xAA, 0x17, 0xFF, 0x0D, 0xB4,
  39742. 0x39, 0xD0, 0xF2, 0xAF, 0xA0, 0x4F, 0x31, 0x8D,
  39743. 0x6D, 0x57, 0x6A, 0xED, 0xC6, 0xF1, 0xE7, 0x67,
  39744. 0xA6, 0x6F, 0xB3, 0x9B, 0x72, 0xC6, 0x7F, 0x05,
  39745. 0xAF, 0x40, 0x87, 0x12, 0x0D, 0xC8, 0x98, 0x88,
  39746. 0x2D, 0xDE, 0xA1, 0x7C, 0x95, 0x32, 0xB2, 0x7A,
  39747. 0xB5, 0x9D, 0xE4, 0x0D, 0x75, 0xD4, 0x17, 0x5B,
  39748. 0xB4, 0x92, 0x73, 0xAF, 0x87, 0x3A, 0x92, 0xDA,
  39749. 0x4D, 0x87, 0xE2, 0x53, 0xCA, 0xE7, 0x2A, 0x52,
  39750. 0x64, 0xE0, 0xC1, 0xDE, 0x4C, 0x9C, 0xF9, 0x1A,
  39751. 0x1F, 0x3A, 0xD6, 0x05, 0xA0, 0xCC, 0x8D, 0x91,
  39752. 0x93, 0x51, 0xF9, 0x37, 0x1A, 0xFC, 0x68, 0xEF,
  39753. 0xBC, 0xED, 0x19, 0x8E, 0x4C, 0xD1, 0xB5, 0x8C,
  39754. 0xA2, 0x85, 0xDA, 0x02, 0x65, 0xAB, 0xAC, 0xAE,
  39755. 0xCA, 0x8E, 0xAC, 0xF0, 0x2A, 0x4F, 0xC7, 0x67,
  39756. 0x16, 0x2E, 0x24, 0x7F, 0x73, 0xCD, 0xD7, 0x3E,
  39757. 0xE3, 0x27, 0x8A, 0xF9, 0x4A, 0xC4, 0xA8, 0xCB,
  39758. 0x2B, 0x01, 0x55, 0x68, 0x34, 0xA3, 0xC0, 0xB8,
  39759. 0xD0, 0x6D, 0x05, 0xF2, 0x3B, 0x4C, 0x17, 0x47,
  39760. 0xE7, 0x64, 0x53, 0xF4, 0x9D, 0xE0, 0x8D, 0xF8,
  39761. 0xEE, 0x0E, 0xA6, 0x25, 0x64, 0x7D, 0x1B, 0xD0,
  39762. 0x80, 0xE7, 0x3C, 0x41, 0x97, 0xAE, 0xCB, 0x6A,
  39763. 0x23, 0xC2, 0x5F, 0x00, 0xC6, 0xC5, 0x4C, 0x8A,
  39764. 0x4C, 0xEF, 0x76, 0x65, 0x95, 0x28, 0xB3, 0x67,
  39765. 0x42, 0xEC, 0x17, 0xFF, 0x0E, 0xE3, 0x7B, 0x30,
  39766. 0x6D, 0xCC, 0xB8, 0x87, 0xD6, 0x63, 0x36, 0x5D,
  39767. 0xC9, 0xE8, 0x1D, 0x51, 0x47, 0xCF, 0xE5, 0x05,
  39768. 0x0D, 0xB4, 0x09, 0xDF, 0xAD, 0x88, 0x9C, 0x38,
  39769. 0x6F, 0x12, 0xA5, 0xCD, 0x0C, 0x95, 0x53, 0x41,
  39770. 0x13, 0xA6, 0xD0, 0xAB, 0xCB, 0x5A, 0x3F, 0x56,
  39771. 0xCE, 0x23, 0xEE, 0x32, 0x61, 0x22, 0x79, 0xE8,
  39772. 0xBA, 0x23, 0x94, 0x61, 0x25, 0x8E, 0xD6, 0x3E,
  39773. 0x78, 0x83, 0xE1, 0x15, 0xBA, 0x05, 0x81, 0xB8,
  39774. 0x1A, 0x7F, 0x73, 0xC1, 0xB7, 0x9F, 0x29, 0xA1,
  39775. 0x16, 0x2E, 0x6E, 0x84, 0xC7, 0x15, 0xBC, 0x50,
  39776. 0x28, 0x5F, 0xD3, 0x8D, 0x4D, 0x6D, 0xC0, 0x87,
  39777. 0x68, 0x88, 0x4B, 0xF4, 0xFB, 0x55, 0x85, 0x3D,
  39778. 0xA7, 0xB5, 0x47, 0x1E, 0x73, 0xA1, 0x47, 0x8D,
  39779. 0xB1, 0xE1, 0xCF, 0xE6, 0x15, 0x3E, 0xC6, 0xC3,
  39780. 0x78, 0xDD, 0x6A, 0x3F, 0x42, 0x29, 0x6E, 0x61,
  39781. 0x9D, 0xE7, 0x63, 0xFF, 0x2D, 0xDB, 0x83, 0xE5,
  39782. 0x15, 0x84, 0xC2, 0x8D, 0xD8, 0x34, 0x2E, 0x92,
  39783. 0x9E, 0x15, 0xB7, 0xBB, 0xCF, 0x5D, 0x6E, 0xCB,
  39784. 0x87, 0x79, 0xCF, 0x7F, 0x3A, 0x9A, 0xC1, 0x6A,
  39785. 0x43, 0x1F, 0x52, 0xA2, 0x34, 0xE6, 0xA3, 0x69,
  39786. 0x9D, 0x9E, 0x44, 0x84, 0x0A, 0x4D, 0x3D, 0x48,
  39787. 0x5D, 0xA5, 0xD9, 0x03, 0x94, 0xB1, 0x81, 0xEF,
  39788. 0x89, 0x98, 0xE6, 0xD1, 0x44, 0x21, 0x83, 0x59,
  39789. 0x09, 0xCD, 0xDB, 0x16, 0x7C, 0x8C, 0x38, 0x78,
  39790. 0x19, 0x4B, 0x6D, 0x51, 0x4D, 0xF8, 0x63, 0x6D,
  39791. 0x4A, 0x14, 0xA1, 0xBE, 0xF3, 0xCA, 0x38, 0x1E,
  39792. 0x36, 0xCF, 0x2E, 0x6D, 0x5F, 0xBC, 0xB4, 0x0A,
  39793. 0xF0, 0x91, 0x7D, 0x6D, 0xBB, 0x87, 0x5C, 0xFF,
  39794. 0x64, 0xCD, 0xCE, 0xCC, 0xCF, 0xB8, 0xBF, 0xB8,
  39795. 0x05, 0x45, 0x8D, 0xF8, 0x2C, 0x74, 0xEB, 0x86,
  39796. 0x3A, 0x96, 0x9E, 0xD9, 0x8B, 0x9C, 0x46, 0xE7,
  39797. 0x17, 0x3C, 0x09, 0x0D, 0xB0, 0x68, 0xB2, 0xD8,
  39798. 0x0C, 0xCE, 0x32, 0xDE, 0x51, 0x72, 0xB5, 0xD4,
  39799. 0xA8, 0xB9, 0x09, 0xA5, 0xA4, 0xCC, 0x47, 0xFA,
  39800. 0x9F, 0x2E, 0xD6, 0x6E, 0x60, 0x69, 0xCD, 0x96,
  39801. 0xAB, 0x1F, 0x3E, 0x84, 0x8C, 0x68, 0x72, 0x0F,
  39802. 0xEA, 0x32, 0xC5, 0x73, 0x6E, 0x8A, 0xB5, 0x10,
  39803. 0x05, 0xFE, 0x42, 0x58, 0x33, 0xF2, 0x07, 0x56,
  39804. 0xC1, 0x96, 0x76, 0x23, 0x77, 0x9D, 0x0A, 0xD2,
  39805. 0x42, 0xA1, 0x69, 0x06, 0x83, 0xBA, 0xD2, 0xEB,
  39806. 0x12, 0x3D, 0x97, 0xAB, 0x23, 0x08, 0x90, 0x15,
  39807. 0x51, 0x4D, 0x0C, 0x6A, 0x3B, 0x0F, 0x37, 0x15,
  39808. 0x25, 0xC2, 0x3E, 0x5F, 0x53, 0x84, 0x4C, 0x81,
  39809. 0xDD, 0xE8, 0x7C, 0xFE, 0x9F, 0x06, 0x5E, 0x11,
  39810. 0x68, 0x7D, 0x68, 0x6B, 0x07, 0x2C, 0x19, 0x00,
  39811. 0xF5, 0xC9, 0xA7, 0xC3, 0x1F, 0xE8, 0xBA, 0xBE,
  39812. 0x9F, 0x09, 0x0C, 0xE2, 0xCB, 0x3B, 0x68, 0x7B,
  39813. 0xA8, 0x9E, 0xD8, 0x3C, 0x08, 0x85, 0xDF, 0xF9,
  39814. 0x11, 0x2B, 0x52, 0xF6, 0xCE, 0xD7, 0x1E, 0x32,
  39815. 0xA4, 0x0A, 0x9A, 0xBC, 0xFF, 0xF4, 0x20, 0xB6,
  39816. 0x24, 0x85, 0x84, 0x7F, 0xFF, 0x70, 0x3C, 0xBB,
  39817. 0x74, 0x36, 0x42, 0x25, 0x5F, 0xBD, 0x0A, 0x90,
  39818. 0x86, 0xA7, 0xB8, 0x3F, 0x9E, 0xDF, 0x43, 0x24,
  39819. 0x88, 0x0C, 0x52, 0x08, 0xF7, 0xDC, 0xB1, 0xEA,
  39820. 0xC3, 0x38, 0xF9, 0x13, 0x16, 0x65, 0xA0, 0xCA,
  39821. 0x6B, 0xF0, 0xD6, 0x12, 0xFB, 0xA6, 0x3F, 0xF7,
  39822. 0x13, 0x91, 0x99, 0xB1, 0xDE, 0xE4, 0xEE, 0x1E,
  39823. 0x98, 0x9B, 0xE4, 0xA0, 0x3A, 0xA8, 0xAC, 0x4A,
  39824. 0x48, 0x3E, 0xCB, 0x9E, 0xB4, 0x1D, 0x22, 0x1F,
  39825. 0x59, 0x97, 0x24, 0x8C, 0xFE, 0xDC, 0xBF, 0x6C,
  39826. 0xAD, 0x8D, 0xB0, 0xA3, 0x27, 0xFA, 0x28, 0x8F,
  39827. 0xD6, 0xAE, 0x31, 0x39, 0x84, 0xFA, 0x61, 0x8F,
  39828. 0x7D, 0xD4, 0xEE, 0xBB, 0x13, 0xED, 0x85, 0xC4,
  39829. 0x35, 0xC0, 0xAB, 0x07, 0x73, 0xC5, 0xCD, 0xCA,
  39830. 0xD4, 0x69, 0x9B, 0x9C, 0x38, 0x2A, 0x1F, 0x37,
  39831. 0xF9, 0xDF, 0x8C, 0x3A, 0xE1, 0x57, 0xDF, 0x05,
  39832. 0x9F, 0x97, 0x51, 0xCC, 0xA6, 0x93, 0xD5, 0x49,
  39833. 0x2A, 0xE9, 0xCD, 0x46, 0x31, 0x22, 0x6E, 0x62,
  39834. 0xE8, 0x13, 0x90, 0x64, 0xFF, 0x00, 0x27, 0xCF,
  39835. 0xA1, 0x95, 0x4E, 0xE9, 0x36, 0xAF, 0xAD, 0x02,
  39836. 0x06, 0xDD, 0x2A, 0xE2, 0x28, 0xB6, 0xDD, 0x65,
  39837. 0xCD, 0x9A, 0x9D, 0x5F, 0xF9, 0xC0, 0xCC, 0x48,
  39838. 0xC8, 0xC2, 0xE9, 0x8F, 0x5A, 0xE6, 0xE2, 0xC9,
  39839. 0x79, 0x7A, 0x83, 0x84, 0xF8, 0xA3, 0xE3, 0xC7,
  39840. 0x48, 0xC7, 0x06, 0xFE, 0x6A, 0x36, 0x25, 0xD2,
  39841. 0xA2, 0xEB, 0x4A, 0xE2, 0xCA, 0xA0, 0x49, 0x24,
  39842. 0x1A, 0x47, 0x8C, 0x1A, 0x77, 0xF5, 0xC9, 0x0D,
  39843. 0xDC, 0x94, 0x18, 0x4D, 0x89, 0x80, 0x50, 0x18,
  39844. 0x7D, 0x67, 0x00, 0x43, 0xE4, 0xE7, 0x8F, 0x54,
  39845. 0xDC, 0x60, 0x84, 0x24, 0xF3, 0xBF, 0x5E, 0x92,
  39846. 0xC7, 0x0C, 0x05, 0x49, 0xBB, 0x61, 0x2F, 0x48,
  39847. 0x0A, 0xEB, 0xE5, 0xFA, 0x8B, 0x01, 0x33, 0x27,
  39848. 0x10, 0x3E, 0xA1, 0x28, 0x33, 0x11, 0x30, 0x1F,
  39849. 0x91, 0x47, 0x7B, 0xA6, 0x3E, 0xD4, 0xF9, 0xC2,
  39850. 0x8F, 0xA3, 0x4E, 0xBC, 0xA7, 0x61, 0x56, 0x1F,
  39851. 0x90, 0x33, 0x54, 0x15, 0x06, 0x21, 0x9C, 0x57,
  39852. 0x07, 0xC2, 0xF8, 0xED, 0x81, 0xED, 0x36, 0x15,
  39853. 0xC8, 0xAC, 0xAB, 0x12, 0x80, 0xBF, 0x7C, 0x5E,
  39854. 0x00, 0xEC, 0x1B, 0x27, 0x58, 0x3A, 0xE9, 0x09,
  39855. 0x2B, 0x23, 0x16, 0x69, 0x26, 0xF9, 0xCC, 0x3C,
  39856. 0x5A, 0xFB, 0x66, 0xBA, 0x32, 0xF9, 0xAF, 0xAB,
  39857. 0xCB, 0xA7, 0xF7, 0x91, 0x6A, 0x82, 0x42, 0xA7,
  39858. 0x9D, 0x7B, 0x0E, 0xD3, 0x5D, 0xF6, 0x52, 0x6D,
  39859. 0x7D, 0x2B, 0xE6, 0x30, 0x99, 0x01, 0xBD, 0xC0,
  39860. 0x3D, 0x15, 0x95, 0xC2, 0x67, 0x19, 0xD9, 0x0F,
  39861. 0xC0, 0x79, 0x1E, 0xAB, 0xA7, 0x67, 0x35, 0x12,
  39862. 0x53, 0xB0, 0x6A, 0xE4, 0xB9, 0x0A, 0x52, 0xEF,
  39863. 0xBD, 0xCD, 0xD4, 0x0C, 0x09, 0x6F, 0x24, 0xE9,
  39864. 0x52, 0x9F, 0xF8, 0x9F, 0x95, 0x95, 0x57, 0x07,
  39865. 0x5F, 0xC8, 0xDD, 0xAF, 0xE6, 0x10, 0x3A, 0x51,
  39866. 0x38, 0xF0, 0x9F, 0xBD, 0xEB, 0x0F, 0x5F, 0x36,
  39867. 0xB5, 0x2A, 0x57, 0xBE, 0x21, 0x39, 0xD8, 0x9D,
  39868. 0x29, 0x04, 0xBC, 0xE2, 0xB8, 0x6D, 0x03, 0xF2,
  39869. 0x6D, 0x56, 0xF4, 0x18, 0x40, 0x07, 0x1A, 0x15,
  39870. 0x8B, 0xF5, 0x46, 0xE1, 0x0C, 0x4D, 0xED, 0x0E,
  39871. 0x81, 0xB0, 0x0D, 0x98, 0x88, 0xC5, 0x5D, 0x53,
  39872. 0xE1, 0x1D, 0xB7, 0x00, 0x26, 0xC6, 0x46, 0x7E,
  39873. 0xD2, 0xAB, 0x0B, 0xD9, 0x1E, 0xE0, 0xE7, 0xC3,
  39874. 0xC3, 0xE0, 0x83, 0x7F, 0x8C, 0xB9, 0xBA, 0xE0,
  39875. 0x04, 0xE2, 0xA8, 0xFF, 0xEC, 0xD5, 0x9E, 0x79,
  39876. 0x2F, 0x13, 0xF9, 0x27, 0xCA, 0xDD, 0xF5, 0x0F,
  39877. 0x74, 0xD2, 0x9B, 0xC6, 0x2E, 0xF2, 0xF0, 0x2A,
  39878. 0xB0, 0xF9, 0x6E, 0x27, 0x3E, 0x8D, 0x66, 0xDB,
  39879. 0x44, 0x82, 0xDD, 0x1B, 0xD5, 0xBB, 0x51, 0x6E,
  39880. 0x72, 0x3A, 0xCB, 0x0F, 0x0B, 0x97, 0xBC, 0x32,
  39881. 0x07, 0xC1, 0x0C, 0xF3, 0x94, 0xFF, 0x62, 0xE2,
  39882. 0xFD, 0x7D, 0xBB, 0x3D, 0x43, 0x11, 0xB3, 0xFA,
  39883. 0x22, 0x05, 0xBF, 0x87, 0x0F, 0xFD, 0xD1, 0x81,
  39884. 0xC6, 0x30, 0xC6, 0x91, 0xD4, 0xEE, 0xA8, 0x6B,
  39885. 0x37, 0xB2, 0x38, 0xF1, 0x87, 0x89, 0xE0, 0x04,
  39886. 0x09, 0xED, 0x18, 0xA6, 0x3C, 0x18, 0x9E, 0x38,
  39887. 0xCB, 0x9F, 0xFE, 0xB3, 0x03, 0xF4, 0xE4, 0x3F,
  39888. 0xB3, 0x94, 0x7C, 0x74, 0x03, 0x6C, 0xCF, 0x16,
  39889. 0x24, 0xF8, 0x56, 0xE2, 0x4A, 0x7E, 0x9A, 0x21,
  39890. 0xB8, 0xC2, 0x7C, 0xF4, 0x3D, 0x85, 0x15, 0x43,
  39891. 0xA5, 0xCA, 0xFD, 0xA3, 0x05, 0xCC, 0x63, 0x8D,
  39892. 0x94, 0x82, 0x70
  39893. };
  39894. static const byte rnd_87[] = {
  39895. 0x16, 0xB8, 0x2B, 0x9B, 0x0A, 0x90, 0x5B, 0xB3,
  39896. 0xD8, 0x7B, 0x4A, 0x1E, 0x40, 0xAE, 0xAD, 0x3C,
  39897. 0xDE, 0x63, 0xB2, 0x2C, 0xB7, 0x16, 0xBD, 0x46,
  39898. 0x7A, 0x7B, 0xE8, 0x4A, 0xF1, 0x9B, 0x7C, 0xFE
  39899. };
  39900. static const byte sig_87[] = {
  39901. 0xE5, 0x5D, 0x62, 0x56, 0x92, 0x73, 0x72, 0x13,
  39902. 0xDD, 0x3D, 0x7F, 0x51, 0x42, 0xF3, 0xAA, 0x33,
  39903. 0x87, 0x12, 0x2F, 0x20, 0xC9, 0x50, 0x93, 0x0A,
  39904. 0x7E, 0x7C, 0xCC, 0x0C, 0x6D, 0x21, 0xB9, 0x5D,
  39905. 0x62, 0x47, 0xD5, 0xFB, 0x3A, 0xCC, 0xBC, 0xB8,
  39906. 0xA1, 0x5A, 0xDF, 0x97, 0x58, 0xBA, 0x7E, 0x40,
  39907. 0x9A, 0x76, 0xD0, 0x1C, 0xBF, 0x0F, 0x14, 0xC3,
  39908. 0x23, 0x3B, 0x21, 0xB0, 0x5D, 0x11, 0x3B, 0x1F,
  39909. 0x70, 0xCB, 0x21, 0x78, 0x51, 0x68, 0xE2, 0x3A,
  39910. 0x29, 0x4A, 0x0D, 0xD0, 0x32, 0x50, 0xDC, 0xBB,
  39911. 0xD1, 0xCF, 0x80, 0x19, 0x7A, 0xC7, 0xFC, 0x37,
  39912. 0x2D, 0x5A, 0x5A, 0xDF, 0x3E, 0x7E, 0x89, 0x2D,
  39913. 0xC6, 0x0E, 0x75, 0x9A, 0xBB, 0xDF, 0x69, 0x82,
  39914. 0x28, 0xB6, 0xD0, 0xF3, 0xF4, 0xCB, 0x4F, 0xD5,
  39915. 0xDC, 0x5D, 0xFE, 0x8D, 0x01, 0xB4, 0x93, 0x9F,
  39916. 0x89, 0x53, 0x18, 0x74, 0x29, 0x20, 0x36, 0xBF,
  39917. 0x34, 0xCA, 0x71, 0x2B, 0x01, 0x14, 0xFB, 0x66,
  39918. 0x94, 0x28, 0x81, 0xF1, 0xF1, 0x7E, 0x80, 0xB6,
  39919. 0x4E, 0x0E, 0x9E, 0x9E, 0x60, 0xD7, 0x6A, 0xFB,
  39920. 0x59, 0xC7, 0x96, 0x9F, 0xB4, 0x9C, 0x98, 0x72,
  39921. 0x06, 0xC1, 0x6C, 0xAA, 0x8E, 0xC7, 0x48, 0xE6,
  39922. 0xC3, 0xAD, 0x8B, 0x4E, 0xF7, 0x81, 0x92, 0x74,
  39923. 0xC0, 0x5A, 0x2B, 0x54, 0x8D, 0x47, 0x15, 0xAC,
  39924. 0xED, 0x45, 0x69, 0xD0, 0x7C, 0x28, 0x80, 0x18,
  39925. 0xA3, 0x9F, 0xB7, 0x14, 0xC6, 0x51, 0xF9, 0x02,
  39926. 0x70, 0x98, 0xD9, 0xC1, 0x09, 0xC0, 0xD7, 0xCE,
  39927. 0x8B, 0x81, 0x7B, 0x30, 0x99, 0x4C, 0x85, 0x1C,
  39928. 0xFA, 0xAE, 0xBF, 0x05, 0x95, 0xBB, 0x6E, 0x01,
  39929. 0xE4, 0xFC, 0xE7, 0x11, 0x16, 0x90, 0x28, 0xC3,
  39930. 0xC4, 0x36, 0x9F, 0x11, 0xCD, 0xEB, 0xEB, 0x71,
  39931. 0x15, 0x08, 0x1D, 0x43, 0x2B, 0x12, 0xA6, 0x4E,
  39932. 0xB6, 0xF9, 0x35, 0xE4, 0x37, 0x0D, 0xF7, 0x49,
  39933. 0xDF, 0x73, 0x4D, 0xE3, 0x57, 0x33, 0x96, 0x7B,
  39934. 0x72, 0x45, 0x2F, 0x92, 0x70, 0xBB, 0x6F, 0xCD,
  39935. 0x90, 0x82, 0x67, 0xBB, 0x31, 0x9D, 0x9E, 0x38,
  39936. 0x75, 0xCD, 0x5B, 0x55, 0x10, 0x6B, 0xFC, 0x00,
  39937. 0x15, 0xC8, 0xCB, 0xFC, 0xE1, 0x18, 0x41, 0xE8,
  39938. 0x6E, 0x92, 0xEC, 0x1A, 0x26, 0x88, 0x6C, 0xF6,
  39939. 0x2A, 0x5C, 0x05, 0x94, 0xD7, 0xB8, 0xD0, 0x78,
  39940. 0x52, 0x68, 0x8D, 0xC5, 0xBD, 0xD6, 0x29, 0xF8,
  39941. 0x21, 0xDF, 0xB3, 0x28, 0x43, 0x74, 0xC7, 0x0E,
  39942. 0x99, 0xD3, 0x0C, 0xDE, 0xE9, 0x06, 0x44, 0xCD,
  39943. 0x77, 0x13, 0x34, 0x82, 0xBA, 0x36, 0x20, 0x71,
  39944. 0x02, 0xB1, 0x6E, 0xBA, 0xCF, 0x9F, 0x15, 0x36,
  39945. 0xC8, 0xF1, 0x4E, 0x36, 0x30, 0x34, 0x2D, 0x23,
  39946. 0x6C, 0x77, 0xEC, 0xCA, 0xBA, 0x7C, 0x17, 0x4F,
  39947. 0x3F, 0x22, 0x4A, 0x34, 0xA1, 0x5C, 0xB3, 0x8F,
  39948. 0xD8, 0x48, 0xD5, 0x8A, 0x2C, 0x8B, 0x1B, 0xFB,
  39949. 0x87, 0xDA, 0xBC, 0xB6, 0xD9, 0x59, 0xD6, 0x9B,
  39950. 0xF0, 0x6E, 0x8D, 0xB1, 0x52, 0xE1, 0x8A, 0x36,
  39951. 0x31, 0xA7, 0x83, 0xCE, 0xDF, 0x36, 0xEB, 0xBE,
  39952. 0xEA, 0xC3, 0xC6, 0xA6, 0x52, 0x2D, 0x89, 0x0B,
  39953. 0xF9, 0x5B, 0x1D, 0x14, 0xA9, 0xBF, 0x37, 0x31,
  39954. 0xE0, 0x1C, 0xF5, 0x29, 0x95, 0xF0, 0xC0, 0x08,
  39955. 0xE8, 0x97, 0xEE, 0x53, 0x27, 0x85, 0x81, 0x7D,
  39956. 0x47, 0xE5, 0xAC, 0xC5, 0x1B, 0x48, 0xA5, 0x36,
  39957. 0x1E, 0x8A, 0xD7, 0xF5, 0xC9, 0x93, 0x74, 0xCE,
  39958. 0x06, 0xEA, 0xC3, 0x26, 0x45, 0xFF, 0xED, 0x39,
  39959. 0xC1, 0x0B, 0x7A, 0x59, 0x3C, 0x0F, 0xEE, 0x89,
  39960. 0xEF, 0xA4, 0xEC, 0xD0, 0x72, 0x34, 0x95, 0xC9,
  39961. 0xC4, 0x78, 0x47, 0xB6, 0xB7, 0xCE, 0xA4, 0xD9,
  39962. 0xA1, 0xB6, 0x37, 0xC1, 0xF1, 0xFB, 0x4E, 0x4C,
  39963. 0x38, 0xB0, 0x4A, 0xE5, 0x13, 0x63, 0xDC, 0x44,
  39964. 0xC4, 0x7E, 0x86, 0x9C, 0xAD, 0x69, 0x29, 0xFD,
  39965. 0xA1, 0xFE, 0xAD, 0x3B, 0x59, 0x24, 0x2F, 0x70,
  39966. 0xAE, 0x5F, 0x2C, 0x00, 0xFE, 0x01, 0x09, 0xA3,
  39967. 0x10, 0x87, 0xF0, 0xAD, 0xFA, 0x9B, 0x83, 0x8F,
  39968. 0x48, 0x96, 0x8B, 0x9A, 0x35, 0xE7, 0x4D, 0xAA,
  39969. 0xEC, 0xA4, 0xCD, 0x26, 0x7C, 0x3E, 0xAC, 0x93,
  39970. 0x26, 0x9D, 0x6B, 0x83, 0x34, 0xC4, 0x71, 0xE1,
  39971. 0xC8, 0x93, 0x88, 0x09, 0xAF, 0x00, 0xB5, 0x7F,
  39972. 0xD9, 0x5A, 0x8E, 0x36, 0xC1, 0x2E, 0x7E, 0xF1,
  39973. 0x0C, 0xC5, 0x2A, 0xB3, 0xE4, 0x48, 0xDF, 0xFB,
  39974. 0xFF, 0x99, 0xC9, 0x66, 0xD2, 0x28, 0x46, 0x7C,
  39975. 0x43, 0x39, 0x96, 0x69, 0x95, 0x42, 0xAC, 0xE0,
  39976. 0xC2, 0x0C, 0x65, 0x99, 0xC8, 0xB0, 0xAE, 0x76,
  39977. 0xE8, 0x18, 0x3E, 0xA9, 0x1D, 0x44, 0x81, 0x14,
  39978. 0x65, 0xF7, 0xDF, 0xD1, 0xD1, 0x7B, 0x7C, 0x28,
  39979. 0xE0, 0x77, 0x9D, 0x79, 0x9C, 0xE4, 0x1A, 0xF1,
  39980. 0xD0, 0xFF, 0x8E, 0xEA, 0x58, 0x84, 0xB3, 0x47,
  39981. 0xBC, 0xA1, 0x47, 0x48, 0xB7, 0xC3, 0xD5, 0xD1,
  39982. 0xF3, 0xDD, 0xA6, 0x3B, 0x15, 0x4C, 0xB3, 0xB5,
  39983. 0xFD, 0x52, 0x9D, 0x7E, 0xF0, 0xC7, 0x40, 0x2C,
  39984. 0x34, 0xBC, 0xCF, 0x1C, 0x67, 0x30, 0xC0, 0x4D,
  39985. 0xA1, 0xC7, 0x5E, 0xAD, 0xAF, 0xCD, 0xFA, 0x21,
  39986. 0xE4, 0xB5, 0x33, 0x8B, 0x37, 0x2D, 0xCF, 0x4D,
  39987. 0x07, 0x48, 0x61, 0xB0, 0xB6, 0x8B, 0x27, 0x05,
  39988. 0xA0, 0x8C, 0x71, 0x95, 0x84, 0x02, 0xB2, 0x1E,
  39989. 0x59, 0xBC, 0xB6, 0xE2, 0x2C, 0x3C, 0x20, 0x4C,
  39990. 0xDE, 0x1E, 0x35, 0x24, 0xC1, 0x5B, 0x3C, 0xB4,
  39991. 0x2A, 0x8C, 0xA7, 0x2D, 0xE3, 0xDC, 0x45, 0x26,
  39992. 0x6E, 0x29, 0x52, 0x5D, 0x24, 0x8A, 0xC2, 0x16,
  39993. 0x73, 0xDB, 0x80, 0xF2, 0x91, 0xEC, 0x05, 0x3E,
  39994. 0x2E, 0x9E, 0x39, 0x12, 0x5E, 0x11, 0x80, 0x24,
  39995. 0xF5, 0xFC, 0x86, 0x4C, 0xD9, 0xF9, 0x70, 0x59,
  39996. 0xC8, 0xC8, 0x57, 0x5D, 0x0F, 0x68, 0x75, 0x3C,
  39997. 0x7A, 0x3D, 0x1B, 0xF7, 0xD0, 0xDF, 0xE2, 0xF9,
  39998. 0xBD, 0x44, 0xFD, 0x21, 0x75, 0x86, 0x77, 0x25,
  39999. 0xAF, 0xD3, 0x28, 0x55, 0x2A, 0x60, 0x7D, 0x79,
  40000. 0x9C, 0x72, 0x2F, 0x6E, 0xAB, 0x2F, 0x26, 0x44,
  40001. 0x0C, 0xFF, 0x52, 0xBD, 0xA1, 0xA9, 0x07, 0xBD,
  40002. 0x9D, 0x2A, 0x64, 0x2E, 0x0B, 0xA1, 0xB8, 0x78,
  40003. 0xD3, 0xC4, 0x84, 0x9A, 0xE1, 0xDB, 0xB4, 0x4A,
  40004. 0x4C, 0x45, 0x7A, 0x8E, 0xD5, 0xA3, 0x6B, 0x09,
  40005. 0x8D, 0x72, 0x8E, 0x6D, 0x17, 0x34, 0xFF, 0xD6,
  40006. 0xED, 0x24, 0x19, 0x7D, 0xC6, 0x2D, 0x5B, 0x82,
  40007. 0x68, 0xAE, 0x25, 0x33, 0xBB, 0xCB, 0x7D, 0xFD,
  40008. 0x00, 0x15, 0x83, 0xEA, 0xBB, 0xE7, 0x40, 0x3D,
  40009. 0x80, 0xD5, 0x9E, 0x6C, 0xE0, 0x3C, 0x7E, 0x3E,
  40010. 0x12, 0xC7, 0x36, 0x7E, 0x41, 0x84, 0xE8, 0xB4,
  40011. 0x16, 0xCA, 0x4A, 0xB7, 0xEB, 0x16, 0xEC, 0xAB,
  40012. 0x5A, 0x69, 0x24, 0x7F, 0x5E, 0x81, 0x86, 0x7D,
  40013. 0x30, 0x61, 0x4E, 0x0F, 0x75, 0x39, 0xEE, 0xF2,
  40014. 0xF4, 0xDC, 0x5E, 0x23, 0x40, 0xE8, 0x3C, 0xC0,
  40015. 0x10, 0xAD, 0x5E, 0xE6, 0x06, 0x8E, 0x5F, 0x55,
  40016. 0xC5, 0x69, 0x65, 0x5F, 0xA3, 0x6E, 0x73, 0x86,
  40017. 0x82, 0x32, 0x5F, 0x36, 0xA7, 0x6B, 0x2C, 0x26,
  40018. 0xCD, 0x64, 0xC8, 0x57, 0x1F, 0x06, 0x7A, 0xAB,
  40019. 0x8B, 0xA7, 0xDB, 0x53, 0x48, 0x1A, 0x06, 0x8D,
  40020. 0x36, 0xF1, 0x77, 0x74, 0xE6, 0xF5, 0x18, 0x62,
  40021. 0x8E, 0x8A, 0xBF, 0xB7, 0x7F, 0x72, 0x44, 0xAC,
  40022. 0xC8, 0x9A, 0x0E, 0x60, 0x4B, 0xAB, 0xB2, 0x9E,
  40023. 0x95, 0xDF, 0x95, 0x28, 0x98, 0x78, 0xBB, 0xA9,
  40024. 0x5D, 0x8E, 0xEE, 0xB4, 0x84, 0xF5, 0x81, 0x7E,
  40025. 0xA1, 0x53, 0x3E, 0xBB, 0x43, 0xF6, 0xD4, 0xB7,
  40026. 0x60, 0xFD, 0xF4, 0xF8, 0x68, 0xB6, 0x1D, 0x9A,
  40027. 0xF7, 0xDA, 0x77, 0xFA, 0xBB, 0x74, 0x44, 0xDE,
  40028. 0x7C, 0x32, 0x2D, 0x5C, 0x24, 0xD8, 0x4D, 0xBF,
  40029. 0xE0, 0x5C, 0x70, 0x12, 0x3C, 0x43, 0xCC, 0x5F,
  40030. 0x00, 0xD5, 0x1F, 0xEA, 0x5D, 0xC9, 0x3A, 0x5C,
  40031. 0x32, 0xED, 0xE0, 0xF1, 0x59, 0xA0, 0xB7, 0x71,
  40032. 0xDC, 0x65, 0xD2, 0x88, 0x20, 0x20, 0xD8, 0x59,
  40033. 0x53, 0x2D, 0x30, 0x2D, 0xFC, 0xA9, 0xEA, 0x45,
  40034. 0xB0, 0xF3, 0x1E, 0x66, 0x9F, 0xF6, 0xF1, 0x5E,
  40035. 0x9B, 0x67, 0x1D, 0xBF, 0x5E, 0x19, 0xB3, 0x2A,
  40036. 0xE8, 0xCE, 0xE5, 0x90, 0xFE, 0x82, 0x5C, 0x19,
  40037. 0x7B, 0x84, 0x3E, 0x45, 0xFF, 0x5D, 0xC2, 0x2E,
  40038. 0x49, 0x6A, 0xB1, 0x2D, 0x50, 0x2D, 0x21, 0xF7,
  40039. 0x2A, 0xA2, 0x39, 0x47, 0x8D, 0xB5, 0x17, 0x64,
  40040. 0x3E, 0x96, 0x13, 0x90, 0x53, 0xEA, 0x57, 0x4C,
  40041. 0xDB, 0x3D, 0x43, 0xC3, 0xE7, 0xD6, 0x5C, 0x54,
  40042. 0x89, 0xDF, 0x6E, 0xF9, 0xE4, 0xC6, 0x64, 0xF0,
  40043. 0x88, 0x1C, 0xD0, 0xF6, 0x9D, 0x9E, 0xD7, 0xCD,
  40044. 0x2C, 0xFB, 0xCC, 0x54, 0x0E, 0x96, 0xD7, 0x4E,
  40045. 0x05, 0xD2, 0xB3, 0x88, 0x85, 0xD8, 0x60, 0xA4,
  40046. 0xF2, 0xE4, 0xD7, 0xFF, 0xAF, 0x12, 0x2E, 0xBA,
  40047. 0xC4, 0x5A, 0x3A, 0x3E, 0xC5, 0xD7, 0xF3, 0x60,
  40048. 0x4F, 0x27, 0xEF, 0xE0, 0x35, 0xAC, 0x4A, 0x8B,
  40049. 0x14, 0x7D, 0xC4, 0xEF, 0x61, 0x9A, 0x69, 0x2E,
  40050. 0x49, 0x80, 0x04, 0x0C, 0x18, 0xB9, 0x42, 0xC6,
  40051. 0x8C, 0x8A, 0x99, 0x43, 0xA6, 0x5A, 0xCD, 0x72,
  40052. 0x20, 0xAD, 0xFD, 0x9C, 0xC4, 0xAA, 0xDF, 0x6C,
  40053. 0x6C, 0x03, 0xEF, 0x48, 0x3E, 0xFB, 0x4A, 0xBC,
  40054. 0xAA, 0x44, 0xEE, 0xC4, 0x25, 0x8F, 0xF9, 0x8A,
  40055. 0xC2, 0x24, 0x73, 0x15, 0xFA, 0x0E, 0xCB, 0x00,
  40056. 0xEE, 0x9B, 0x39, 0x3F, 0x60, 0x1F, 0x00, 0x95,
  40057. 0xCA, 0xFE, 0xC2, 0x2C, 0x35, 0x5F, 0xD9, 0xD1,
  40058. 0x29, 0xB5, 0x4D, 0xC1, 0x66, 0x51, 0x8F, 0x17,
  40059. 0x3B, 0xF4, 0xF1, 0x49, 0x42, 0x36, 0x0C, 0x5B,
  40060. 0x58, 0xF2, 0x9B, 0x59, 0x01, 0xFB, 0x15, 0x7F,
  40061. 0x21, 0x90, 0x1F, 0x56, 0x69, 0x8B, 0xE2, 0xA5,
  40062. 0x44, 0xCB, 0x84, 0x98, 0x4B, 0x75, 0xA8, 0xCB,
  40063. 0x83, 0x0D, 0xE8, 0x1C, 0x91, 0x7F, 0xE4, 0x57,
  40064. 0x81, 0x16, 0x34, 0x2F, 0xCE, 0x01, 0xAA, 0x62,
  40065. 0x54, 0x44, 0xB7, 0xD6, 0xC7, 0xF1, 0x68, 0x9A,
  40066. 0x00, 0x3B, 0x71, 0x16, 0xF9, 0x96, 0x6A, 0x90,
  40067. 0x6C, 0x2C, 0x4E, 0x58, 0xBC, 0xDD, 0xE9, 0x3B,
  40068. 0x60, 0xB7, 0xA0, 0x97, 0xEE, 0xD6, 0x34, 0xDD,
  40069. 0x49, 0x4A, 0xD9, 0x85, 0xD1, 0xB7, 0x95, 0x14,
  40070. 0xEC, 0x6A, 0x40, 0xE8, 0x31, 0x80, 0xF1, 0xD8,
  40071. 0x5F, 0x75, 0xF6, 0x92, 0x3A, 0x4F, 0xCD, 0x0A,
  40072. 0x6E, 0xBF, 0xA1, 0x27, 0x48, 0x79, 0x27, 0x04,
  40073. 0x76, 0x2C, 0xAB, 0x25, 0x06, 0xEB, 0x43, 0xDD,
  40074. 0x1B, 0x4B, 0x24, 0xFC, 0x93, 0x51, 0x1C, 0x45,
  40075. 0xF6, 0xAE, 0x77, 0xCF, 0xC9, 0xE6, 0x20, 0xE4,
  40076. 0xA5, 0x2B, 0x3D, 0x7D, 0xF0, 0xEB, 0x51, 0x7C,
  40077. 0xCA, 0xFE, 0x58, 0xBA, 0xC4, 0x07, 0x95, 0x75,
  40078. 0x62, 0x0C, 0x50, 0x68, 0x88, 0x1A, 0x8A, 0x0D,
  40079. 0x1B, 0x5C, 0x53, 0x1A, 0x9C, 0xA8, 0x4E, 0xFE,
  40080. 0x63, 0x9B, 0xDB, 0x05, 0x70, 0x01, 0x75, 0xA1,
  40081. 0x3A, 0x08, 0xFA, 0x51, 0xD5, 0xF6, 0x81, 0xDE,
  40082. 0x69, 0xE5, 0x40, 0xB3, 0xF8, 0x7C, 0x46, 0x97,
  40083. 0xA6, 0x4E, 0xA8, 0x51, 0x47, 0x9C, 0xB9, 0x25,
  40084. 0xCD, 0x4E, 0xED, 0xFC, 0xEE, 0x03, 0x6A, 0xCD,
  40085. 0x93, 0x65, 0xB3, 0x68, 0x09, 0x6F, 0xE8, 0x00,
  40086. 0x6A, 0x3F, 0xBF, 0xE8, 0x6F, 0x09, 0xE9, 0xF2,
  40087. 0x6F, 0x44, 0x2E, 0xB1, 0x81, 0x76, 0x04, 0xDD,
  40088. 0x6E, 0xF4, 0x93, 0x61, 0xE5, 0x78, 0xD4, 0xDA,
  40089. 0xBF, 0x05, 0xA1, 0xF4, 0x9D, 0xFD, 0x57, 0x06,
  40090. 0x9C, 0x13, 0x45, 0x97, 0xF2, 0x48, 0xE6, 0x1A,
  40091. 0xB5, 0xAD, 0x09, 0x11, 0x04, 0xBB, 0xA0, 0xA8,
  40092. 0xA3, 0xA3, 0x33, 0xCD, 0x42, 0x2C, 0x66, 0xC2,
  40093. 0x94, 0x80, 0x15, 0x9D, 0x56, 0x74, 0x02, 0xEE,
  40094. 0xA7, 0xE4, 0x90, 0xDD, 0xFB, 0x0B, 0x3B, 0xF0,
  40095. 0x7A, 0x02, 0x44, 0xE8, 0x11, 0xC4, 0x3A, 0xFE,
  40096. 0x73, 0x2A, 0x4C, 0x92, 0x3C, 0x23, 0x37, 0x8B,
  40097. 0x4F, 0x28, 0x8E, 0x1C, 0x4E, 0x7D, 0x0D, 0x6B,
  40098. 0xFD, 0x20, 0xB5, 0x93, 0xB3, 0x75, 0x30, 0x28,
  40099. 0xC7, 0x7E, 0x67, 0xC4, 0xDE, 0xDA, 0x27, 0xA9,
  40100. 0xE3, 0xF2, 0xF5, 0x25, 0x98, 0x5F, 0x6B, 0xBE,
  40101. 0x11, 0x80, 0x23, 0x49, 0x30, 0xC8, 0x8A, 0x63,
  40102. 0xF9, 0xC4, 0x14, 0x77, 0x2A, 0xE2, 0x21, 0x42,
  40103. 0x28, 0x1C, 0xEB, 0x9F, 0x7B, 0x70, 0xA8, 0x2B,
  40104. 0xFB, 0x25, 0x36, 0xA6, 0xAC, 0xFE, 0x8E, 0xFF,
  40105. 0xB6, 0x86, 0x09, 0x15, 0x7E, 0xD9, 0x26, 0x8F,
  40106. 0xDB, 0xF2, 0x2D, 0xC2, 0xFA, 0xAE, 0xDA, 0x50,
  40107. 0xF6, 0x24, 0x53, 0xDB, 0xBF, 0x92, 0x9D, 0x7E,
  40108. 0x48, 0xCC, 0x75, 0xAC, 0xD0, 0xD3, 0x45, 0x09,
  40109. 0x2F, 0x01, 0x60, 0xBB, 0xAE, 0xCB, 0xE6, 0xB3,
  40110. 0x30, 0xDA, 0xD9, 0xB6, 0x12, 0xCD, 0xF5, 0x11,
  40111. 0xCF, 0x2B, 0x2A, 0xC6, 0x61, 0x9A, 0x05, 0x59,
  40112. 0x08, 0x58, 0x64, 0xEC, 0xDB, 0x77, 0xCF, 0x64,
  40113. 0xE2, 0x4B, 0x6E, 0xF4, 0x07, 0x68, 0x5E, 0xE9,
  40114. 0x31, 0xB1, 0x38, 0x67, 0xF9, 0x29, 0x2E, 0x7A,
  40115. 0xD2, 0x03, 0xA6, 0x29, 0x3F, 0x22, 0x58, 0x66,
  40116. 0x6A, 0x07, 0xD8, 0xFD, 0xC5, 0x03, 0xEE, 0x66,
  40117. 0xD4, 0x66, 0x70, 0x6D, 0xA4, 0xC4, 0xA1, 0xEE,
  40118. 0xCD, 0x4D, 0xFA, 0x3C, 0x34, 0x36, 0xC2, 0xC5,
  40119. 0x1E, 0x86, 0xB8, 0x7B, 0x7C, 0xBC, 0x67, 0x16,
  40120. 0xF3, 0x6E, 0xF2, 0xB7, 0xEA, 0x96, 0x1B, 0x0D,
  40121. 0xA2, 0xC8, 0x42, 0xBF, 0x30, 0x09, 0x2A, 0x6D,
  40122. 0x9D, 0x35, 0xB3, 0x92, 0xBA, 0x3E, 0xE2, 0xE9,
  40123. 0xE2, 0xAA, 0x90, 0x70, 0xCE, 0x0F, 0x07, 0xFA,
  40124. 0x7C, 0x3B, 0xF7, 0x66, 0x7F, 0x5C, 0xFE, 0xD9,
  40125. 0x72, 0x1C, 0x4E, 0xFE, 0x7E, 0x86, 0x8E, 0x7F,
  40126. 0x62, 0x8D, 0x41, 0x46, 0x7B, 0x43, 0x17, 0xB9,
  40127. 0x44, 0xED, 0x39, 0x1B, 0x3E, 0xF9, 0x2D, 0xC7,
  40128. 0x5C, 0x9D, 0xAC, 0x05, 0x00, 0xC6, 0x85, 0x4E,
  40129. 0xB8, 0xBC, 0x29, 0xDF, 0x6D, 0x6A, 0xCC, 0xEB,
  40130. 0xD6, 0x44, 0x86, 0xAA, 0xC9, 0x55, 0x49, 0xA1,
  40131. 0x3F, 0x59, 0x5E, 0xAF, 0xD5, 0xC9, 0x96, 0x19,
  40132. 0x84, 0xC0, 0x4D, 0x1B, 0xE5, 0x2C, 0x42, 0x8D,
  40133. 0x2C, 0xC8, 0x83, 0x00, 0x26, 0xBF, 0x46, 0x9F,
  40134. 0x20, 0x97, 0xEC, 0x2C, 0xA9, 0x2C, 0xF0, 0xA7,
  40135. 0x11, 0xED, 0xE2, 0xA2, 0x57, 0x83, 0x40, 0x92,
  40136. 0xF3, 0x58, 0xB7, 0x4E, 0xD6, 0x3A, 0x9D, 0xF0,
  40137. 0xDD, 0xD4, 0x5F, 0x82, 0x58, 0xD3, 0x72, 0x05,
  40138. 0x69, 0xFF, 0x1E, 0xBC, 0x74, 0x90, 0x87, 0xB5,
  40139. 0x7A, 0xEE, 0xF8, 0xCE, 0x3F, 0x59, 0xE1, 0xC0,
  40140. 0x46, 0x24, 0xF8, 0x9D, 0x93, 0x51, 0x4A, 0x44,
  40141. 0xFB, 0xEA, 0x58, 0xA6, 0xAC, 0x9A, 0x7C, 0xA3,
  40142. 0x11, 0xA3, 0x47, 0x44, 0x24, 0x11, 0xF5, 0x56,
  40143. 0x1A, 0x3B, 0xCF, 0xEC, 0xD9, 0x2B, 0x6C, 0xBA,
  40144. 0xA6, 0xA2, 0x67, 0xB9, 0xE0, 0xCB, 0x3F, 0x8D,
  40145. 0xA8, 0xC4, 0x8A, 0x45, 0xAB, 0xE2, 0x10, 0x19,
  40146. 0x10, 0xC9, 0xDB, 0x01, 0x64, 0xC0, 0x0B, 0x6F,
  40147. 0x3B, 0xA1, 0xE9, 0xEB, 0x74, 0x9A, 0x63, 0x93,
  40148. 0xE5, 0x74, 0x3F, 0xD3, 0x7B, 0xEA, 0x8C, 0xD6,
  40149. 0x7D, 0x66, 0xDD, 0x90, 0x6C, 0x69, 0x67, 0x05,
  40150. 0xAD, 0x70, 0xF1, 0xFA, 0x52, 0xBB, 0xD5, 0x3D,
  40151. 0x0E, 0x7E, 0x87, 0xE0, 0x98, 0xAF, 0xA6, 0xE6,
  40152. 0x0E, 0x25, 0x91, 0x70, 0xCA, 0x36, 0xE4, 0xF8,
  40153. 0xF7, 0x95, 0x1C, 0x48, 0xF6, 0x62, 0x9A, 0x4D,
  40154. 0xE4, 0xE7, 0x3A, 0x92, 0xC6, 0x2E, 0xAB, 0x8A,
  40155. 0x75, 0x7C, 0x45, 0xDA, 0x54, 0xB1, 0x6D, 0x2E,
  40156. 0xCC, 0x13, 0x46, 0x67, 0x8F, 0xFF, 0xDA, 0x18,
  40157. 0xE1, 0x4C, 0xE4, 0x6A, 0xB6, 0xAC, 0x65, 0x32,
  40158. 0x0C, 0x63, 0xD5, 0x43, 0xB5, 0x8B, 0xB1, 0x52,
  40159. 0xEE, 0x0C, 0xBB, 0x62, 0x34, 0x30, 0xDB, 0xF7,
  40160. 0x08, 0xC6, 0xE8, 0x5B, 0x07, 0x66, 0x6D, 0x4B,
  40161. 0x39, 0xC6, 0x94, 0x2B, 0x22, 0x9E, 0x3E, 0x45,
  40162. 0x62, 0x3D, 0x05, 0x03, 0x2B, 0x16, 0x71, 0xBB,
  40163. 0x85, 0x1B, 0x6E, 0x84, 0xD3, 0x48, 0x4D, 0x63,
  40164. 0x26, 0x60, 0x97, 0x45, 0xB8, 0xEA, 0x43, 0x96,
  40165. 0x00, 0xFE, 0x0B, 0x85, 0xBD, 0x22, 0x40, 0xA4,
  40166. 0xA7, 0x2F, 0xC1, 0xEB, 0xFD, 0xB5, 0x22, 0xD5,
  40167. 0x1F, 0xB3, 0xEA, 0x7C, 0x6D, 0x20, 0xFB, 0x98,
  40168. 0xA5, 0xF2, 0x84, 0x70, 0xF7, 0xB9, 0x2A, 0x12,
  40169. 0x63, 0x0C, 0x2D, 0x97, 0x6C, 0xC2, 0x76, 0xAC,
  40170. 0x32, 0xE2, 0xB1, 0x3A, 0xB3, 0xAB, 0x9E, 0xBB,
  40171. 0x61, 0xB4, 0x6A, 0x5F, 0x2D, 0x4D, 0xCE, 0x0D,
  40172. 0xFB, 0x97, 0x80, 0x89, 0x4A, 0x81, 0xFB, 0xB2,
  40173. 0x72, 0x37, 0x66, 0xB9, 0x08, 0xBF, 0xCD, 0x9F,
  40174. 0x63, 0xB2, 0xBA, 0x54, 0xF1, 0x9E, 0xEC, 0x11,
  40175. 0x67, 0x26, 0xC7, 0x98, 0xDD, 0xA3, 0xC5, 0x50,
  40176. 0x86, 0x17, 0xD5, 0xCF, 0x51, 0x97, 0x22, 0x65,
  40177. 0x2B, 0x71, 0xF7, 0x34, 0x84, 0x55, 0xC9, 0xD1,
  40178. 0xFE, 0x75, 0x42, 0x0A, 0x5A, 0x31, 0x59, 0xE8,
  40179. 0x8A, 0x0D, 0xE5, 0x77, 0x1C, 0xF5, 0xFD, 0x27,
  40180. 0x05, 0x05, 0xF7, 0x28, 0xDA, 0x54, 0xAB, 0xBD,
  40181. 0xDC, 0x50, 0xB8, 0xDB, 0x2E, 0xB4, 0x28, 0x41,
  40182. 0x30, 0x04, 0x40, 0xD5, 0xF0, 0x12, 0xD7, 0x16,
  40183. 0x3D, 0x8F, 0x41, 0xE7, 0x70, 0x76, 0x82, 0xB9,
  40184. 0xC4, 0xB2, 0x1F, 0x57, 0x10, 0xB6, 0xC4, 0x84,
  40185. 0x0D, 0xB1, 0xB8, 0x21, 0xB2, 0x77, 0x09, 0xF6,
  40186. 0xD5, 0x9C, 0xE4, 0xA2, 0xFA, 0x83, 0x13, 0x56,
  40187. 0x94, 0x3F, 0x37, 0x6D, 0x0D, 0x7C, 0x7E, 0xA0,
  40188. 0xE5, 0xC8, 0xD9, 0x42, 0x0F, 0x35, 0xB1, 0xDC,
  40189. 0xB9, 0x49, 0xD5, 0xED, 0xA8, 0x90, 0x09, 0x14,
  40190. 0xAE, 0x63, 0xB5, 0xEA, 0x62, 0x0D, 0x9E, 0x6D,
  40191. 0x93, 0xBD, 0x3A, 0xEA, 0x24, 0xB5, 0xAC, 0xC9,
  40192. 0xD1, 0x7B, 0xBC, 0xC6, 0xC4, 0xBA, 0x68, 0xB1,
  40193. 0x65, 0xFE, 0xAB, 0x30, 0xD4, 0x92, 0xD9, 0xC1,
  40194. 0x94, 0x84, 0xE1, 0x20, 0x4E, 0x28, 0x7C, 0x3A,
  40195. 0x3E, 0x8B, 0x44, 0x79, 0xC7, 0xB5, 0xA5, 0x95,
  40196. 0xC2, 0xC9, 0xA8, 0x3F, 0x92, 0x67, 0x06, 0x9A,
  40197. 0x12, 0xD3, 0xAE, 0x78, 0x87, 0x0E, 0x31, 0x54,
  40198. 0x26, 0xDF, 0x97, 0xEB, 0x6C, 0xF3, 0xC9, 0x53,
  40199. 0x39, 0xED, 0x50, 0x5A, 0xF9, 0x6A, 0x03, 0x27,
  40200. 0x8E, 0xC6, 0x79, 0x5B, 0xD4, 0xD3, 0x57, 0x97,
  40201. 0xFD, 0xF5, 0xCB, 0x14, 0xDB, 0xBE, 0x39, 0xB9,
  40202. 0x64, 0x8A, 0x75, 0xAA, 0xE3, 0x4A, 0x19, 0x59,
  40203. 0x69, 0x7D, 0xF8, 0x7D, 0x8C, 0xB8, 0x2F, 0x32,
  40204. 0x57, 0xBF, 0x84, 0x9E, 0x45, 0x4E, 0xC4, 0xA0,
  40205. 0x65, 0xA4, 0x0B, 0x73, 0x36, 0xC5, 0xD1, 0x07,
  40206. 0xF8, 0x1C, 0x91, 0x07, 0xB8, 0x0B, 0x4B, 0xE5,
  40207. 0x4F, 0xE6, 0xA1, 0xDF, 0x29, 0x03, 0xE7, 0x68,
  40208. 0xA4, 0x32, 0x8E, 0x21, 0x8F, 0x15, 0x51, 0x57,
  40209. 0x65, 0x16, 0xF0, 0x55, 0x71, 0x8C, 0x28, 0xD8,
  40210. 0x82, 0xDC, 0x8A, 0xC1, 0xE7, 0x5C, 0xF2, 0xD5,
  40211. 0xB8, 0x18, 0x16, 0x9F, 0x63, 0x89, 0x21, 0xF1,
  40212. 0xA6, 0xED, 0x21, 0xDA, 0xC8, 0x0A, 0x10, 0x21,
  40213. 0x18, 0x98, 0xD0, 0xF2, 0x9E, 0xDE, 0x5A, 0xA1,
  40214. 0x51, 0xC9, 0x18, 0x3B, 0x68, 0x79, 0x75, 0xE7,
  40215. 0xF4, 0xF9, 0xBF, 0x5F, 0xBE, 0x61, 0x35, 0xA9,
  40216. 0x02, 0x56, 0x2D, 0x99, 0xD8, 0x95, 0xFA, 0x78,
  40217. 0x8A, 0x67, 0x24, 0x1D, 0xDF, 0x13, 0x14, 0xD0,
  40218. 0xB4, 0xB6, 0x21, 0x11, 0xB7, 0xA4, 0x06, 0x8D,
  40219. 0x1D, 0xF6, 0xD5, 0x50, 0x2A, 0x0A, 0x42, 0x3C,
  40220. 0x7C, 0xF1, 0x1F, 0x15, 0x1C, 0x81, 0x69, 0xDA,
  40221. 0xCC, 0xAC, 0x8F, 0xB9, 0x08, 0x4E, 0xF8, 0x4E,
  40222. 0x3E, 0x77, 0x26, 0x4A, 0x1F, 0x72, 0x89, 0xCA,
  40223. 0x91, 0x77, 0x99, 0xBF, 0x28, 0xD2, 0x31, 0x65,
  40224. 0x30, 0x37, 0x84, 0x66, 0x8A, 0x1C, 0xC6, 0x59,
  40225. 0x7D, 0x48, 0x9B, 0x4D, 0xDC, 0x87, 0x4F, 0xD2,
  40226. 0x04, 0xA0, 0x8B, 0x8B, 0x37, 0x3B, 0x1A, 0xDB,
  40227. 0xCF, 0x63, 0x39, 0x07, 0xF3, 0x37, 0xCF, 0x0E,
  40228. 0x2F, 0xEB, 0xE6, 0x2A, 0xA1, 0x4C, 0xE0, 0x75,
  40229. 0x3F, 0xAB, 0xF7, 0xDE, 0x48, 0x83, 0x79, 0x89,
  40230. 0x30, 0xA7, 0x1B, 0xE8, 0x73, 0x8E, 0x9D, 0x1D,
  40231. 0xF6, 0x5C, 0x91, 0x4F, 0x44, 0x7C, 0x04, 0xA7,
  40232. 0x07, 0xC8, 0xCC, 0x4A, 0x5C, 0x81, 0xAD, 0x48,
  40233. 0x7C, 0xE5, 0x19, 0x5A, 0xC4, 0x29, 0x80, 0x14,
  40234. 0xFA, 0xC2, 0x26, 0x1C, 0x50, 0x28, 0xB9, 0xF6,
  40235. 0x7F, 0x8D, 0x51, 0x9A, 0xDA, 0xBB, 0x8E, 0x90,
  40236. 0xBA, 0x3B, 0xD9, 0x4D, 0x61, 0xBE, 0xFD, 0x33,
  40237. 0xC0, 0xCA, 0x7B, 0x09, 0xFF, 0x36, 0x84, 0x70,
  40238. 0x11, 0xB4, 0xBE, 0x81, 0xFE, 0x71, 0xEE, 0x81,
  40239. 0xD7, 0x61, 0xBB, 0x83, 0xA6, 0xA0, 0xDC, 0x20,
  40240. 0x04, 0x02, 0x4C, 0x1B, 0x4D, 0xED, 0x8A, 0xC1,
  40241. 0x38, 0x70, 0xC3, 0x69, 0xC9, 0x50, 0xC2, 0x17,
  40242. 0x64, 0xAD, 0x9D, 0x44, 0x63, 0x44, 0xE5, 0x32,
  40243. 0x7B, 0x90, 0xE3, 0xEF, 0x45, 0x28, 0xA6, 0x23,
  40244. 0x92, 0xCB, 0xA1, 0xFC, 0xA8, 0xB4, 0x39, 0xF1,
  40245. 0xB1, 0x00, 0x1F, 0x06, 0xD4, 0x91, 0x5D, 0xDB,
  40246. 0xAC, 0x7D, 0x87, 0xD4, 0xEE, 0xCD, 0x4A, 0x06,
  40247. 0x3E, 0xB4, 0x84, 0x65, 0xAA, 0x47, 0x05, 0x41,
  40248. 0x7C, 0x95, 0x47, 0x3A, 0x49, 0x80, 0xC5, 0xAC,
  40249. 0x32, 0x41, 0x6A, 0x3A, 0x2B, 0xB9, 0xD9, 0x21,
  40250. 0x80, 0xC7, 0xC1, 0xD0, 0xC9, 0x95, 0x4B, 0xC3,
  40251. 0xEA, 0x0D, 0x3F, 0x0E, 0xE4, 0x5A, 0xD8, 0xBD,
  40252. 0x11, 0xD0, 0x76, 0x6D, 0x3C, 0xA7, 0x64, 0xD8,
  40253. 0xCA, 0x4C, 0x8F, 0x58, 0x2C, 0xDD, 0x95, 0x1F,
  40254. 0xBB, 0x76, 0x8D, 0x10, 0xFD, 0xAD, 0x45, 0xCE,
  40255. 0x71, 0x6E, 0x27, 0x92, 0xC4, 0xA6, 0x17, 0x46,
  40256. 0x95, 0xDB, 0xD8, 0xEA, 0x9A, 0x5F, 0x0E, 0xE0,
  40257. 0x0A, 0xA2, 0xF5, 0x79, 0xC3, 0x74, 0xA7, 0x70,
  40258. 0x99, 0x3B, 0x23, 0xD7, 0x3E, 0xA4, 0x96, 0xB5,
  40259. 0x54, 0x77, 0x71, 0x8D, 0x78, 0x2E, 0xCC, 0x0A,
  40260. 0x4E, 0xF8, 0xA9, 0x96, 0xEE, 0xB4, 0x4B, 0x5B,
  40261. 0xDC, 0x52, 0x6D, 0xE1, 0x61, 0x36, 0xE1, 0x32,
  40262. 0xD6, 0xA2, 0x7B, 0x2E, 0xCC, 0x78, 0x92, 0xA1,
  40263. 0x81, 0x59, 0xB8, 0xC7, 0x04, 0x11, 0x3D, 0xF0,
  40264. 0xF9, 0xF9, 0x3E, 0x47, 0x3C, 0xEA, 0xD5, 0x30,
  40265. 0x2D, 0xAE, 0xC0, 0x47, 0xC8, 0x61, 0xCC, 0x9C,
  40266. 0x2E, 0xC0, 0x40, 0x16, 0x11, 0x73, 0x13, 0xF3,
  40267. 0x19, 0xAE, 0x72, 0x44, 0x72, 0xC5, 0x59, 0x51,
  40268. 0x2E, 0x9F, 0xE3, 0x07, 0xB0, 0xCA, 0x6B, 0xB0,
  40269. 0x15, 0x20, 0xB4, 0x25, 0x00, 0xED, 0xFD, 0xAC,
  40270. 0xD6, 0x34, 0x8B, 0xCA, 0xE8, 0xC6, 0x3B, 0xFD,
  40271. 0x02, 0x22, 0xE6, 0x91, 0x2B, 0x4B, 0x61, 0xDF,
  40272. 0x63, 0x5C, 0x2B, 0x5F, 0x82, 0x07, 0x23, 0x59,
  40273. 0x82, 0x5E, 0x0E, 0x21, 0xF7, 0x9C, 0x37, 0x1C,
  40274. 0x7E, 0x6F, 0xD4, 0xFA, 0x91, 0x40, 0x8B, 0x98,
  40275. 0x68, 0xBD, 0x60, 0x2F, 0x0A, 0xC8, 0xC8, 0x99,
  40276. 0xA1, 0xC6, 0x10, 0xF1, 0x27, 0x53, 0xD3, 0xFB,
  40277. 0x23, 0x02, 0xE7, 0x8E, 0x95, 0xB1, 0xF0, 0x21,
  40278. 0xCB, 0x90, 0xEE, 0x8D, 0xE0, 0x27, 0x57, 0xDE,
  40279. 0x40, 0xA3, 0xE7, 0x8F, 0x61, 0xC1, 0x8F, 0xC5,
  40280. 0x0C, 0x0F, 0xBA, 0x05, 0xA0, 0x58, 0x8E, 0x86,
  40281. 0x8A, 0xF5, 0x72, 0xE1, 0x34, 0xB4, 0xF6, 0x8E,
  40282. 0x6E, 0xA4, 0x21, 0x75, 0x43, 0x73, 0xE7, 0x32,
  40283. 0x72, 0x80, 0x9B, 0xE7, 0x1D, 0x78, 0x8F, 0x0D,
  40284. 0x06, 0x47, 0x9E, 0x4D, 0xB4, 0xAC, 0x3E, 0x0D,
  40285. 0xB8, 0x11, 0x23, 0xFF, 0xAD, 0xB9, 0x23, 0xE0,
  40286. 0xA4, 0x37, 0xA6, 0x3D, 0xC2, 0x15, 0xF4, 0x64,
  40287. 0x03, 0x1F, 0x0A, 0x68, 0xED, 0x37, 0x37, 0xE8,
  40288. 0x3E, 0x5B, 0x49, 0x78, 0xFC, 0xFC, 0x12, 0x06,
  40289. 0xE8, 0xC7, 0xCD, 0x3A, 0xAF, 0xD4, 0x54, 0xA7,
  40290. 0x04, 0x7B, 0xFC, 0x66, 0xA6, 0xA8, 0x1C, 0x38,
  40291. 0x0C, 0x26, 0x08, 0xE6, 0xEE, 0x47, 0x25, 0x80,
  40292. 0x59, 0xA5, 0x39, 0x81, 0x20, 0xEE, 0x5F, 0x49,
  40293. 0x9A, 0x01, 0x37, 0xE9, 0x96, 0x18, 0xD0, 0x05,
  40294. 0x2D, 0xE3, 0x73, 0xD5, 0x08, 0x3B, 0x18, 0x46,
  40295. 0xFE, 0x9E, 0x67, 0x5B, 0x9E, 0xF8, 0x53, 0x05,
  40296. 0x2F, 0x96, 0x18, 0x9C, 0x09, 0x0D, 0xA6, 0x05,
  40297. 0xB3, 0x9E, 0x2F, 0x0B, 0x5A, 0xF3, 0x93, 0xFF,
  40298. 0x29, 0xF3, 0x4F, 0x62, 0xD5, 0x9A, 0xCE, 0x74,
  40299. 0x64, 0xD0, 0xBC, 0xB3, 0x08, 0xF1, 0xD3, 0x22,
  40300. 0xA5, 0xBE, 0x64, 0x0A, 0xEB, 0xA5, 0xF5, 0x1B,
  40301. 0x7E, 0x0A, 0x44, 0x3B, 0x1D, 0xA9, 0x48, 0x9A,
  40302. 0x2F, 0xED, 0x05, 0x0F, 0x44, 0xB3, 0x6D, 0xAD,
  40303. 0x39, 0x2C, 0xBA, 0x8E, 0x2B, 0xDE, 0x17, 0x38,
  40304. 0xD1, 0x69, 0xEA, 0xAE, 0x4E, 0x97, 0xCD, 0x61,
  40305. 0xBA, 0x75, 0x39, 0xF2, 0x81, 0xBB, 0xA9, 0x0F,
  40306. 0x6F, 0x82, 0xD4, 0xCB, 0xE4, 0x93, 0x82, 0x11,
  40307. 0x72, 0x9A, 0xE9, 0x87, 0xEC, 0xCC, 0x6D, 0xA1,
  40308. 0x7D, 0x47, 0x60, 0x20, 0xB6, 0xEE, 0xC6, 0xAA,
  40309. 0xC0, 0x3C, 0x95, 0x08, 0xA0, 0x8B, 0xFA, 0x04,
  40310. 0xF6, 0x6F, 0x65, 0x48, 0xCA, 0xA7, 0xA3, 0xA8,
  40311. 0xBB, 0x3B, 0x80, 0x91, 0xB6, 0x6D, 0x2F, 0x9D,
  40312. 0x97, 0xBB, 0x52, 0xE6, 0xC4, 0x24, 0x99, 0x97,
  40313. 0x63, 0xAD, 0xD2, 0xFD, 0xB3, 0x94, 0x6D, 0xC1,
  40314. 0xFB, 0xFA, 0x89, 0x45, 0x78, 0x80, 0x3C, 0xAA,
  40315. 0x3F, 0xC0, 0x7E, 0x8D, 0x37, 0x00, 0xA7, 0x70,
  40316. 0xD6, 0x57, 0x2A, 0xD3, 0x17, 0xB1, 0x9E, 0xDF,
  40317. 0x96, 0x98, 0x40, 0xB8, 0x1C, 0xCC, 0xC6, 0xCD,
  40318. 0xCD, 0xB0, 0xF3, 0x23, 0x53, 0xB6, 0x45, 0x78,
  40319. 0xA6, 0xA0, 0x88, 0x61, 0x06, 0x04, 0x8E, 0x1B,
  40320. 0xCD, 0x12, 0x29, 0x50, 0x0F, 0xD2, 0x8C, 0x89,
  40321. 0x51, 0xD1, 0x74, 0x0B, 0xE3, 0xA7, 0x75, 0x8A,
  40322. 0x60, 0x95, 0xEF, 0x6A, 0x98, 0xC7, 0x35, 0xA5,
  40323. 0xC0, 0xFB, 0x4C, 0x88, 0xA1, 0xDA, 0xCE, 0x79,
  40324. 0x3D, 0x4E, 0x4F, 0x91, 0x75, 0x88, 0xE0, 0x5F,
  40325. 0x17, 0xF5, 0xEF, 0xF8, 0x49, 0xFE, 0xB1, 0xDB,
  40326. 0x0D, 0xE8, 0xB2, 0xF7, 0xD4, 0x90, 0xBD, 0xB0,
  40327. 0x6B, 0x3A, 0x1B, 0xB5, 0xC6, 0xFB, 0x93, 0xEF,
  40328. 0xF3, 0xDD, 0x60, 0xEA, 0x67, 0x11, 0xFE, 0x6A,
  40329. 0xCC, 0x2C, 0x64, 0x2A, 0x85, 0x2E, 0x24, 0x39,
  40330. 0x34, 0x6B, 0xBC, 0xF8, 0x89, 0xB3, 0x49, 0x82,
  40331. 0x9C, 0xC0, 0x04, 0x29, 0x6D, 0x25, 0xCB, 0x19,
  40332. 0xE1, 0x53, 0xC6, 0x10, 0x7D, 0x62, 0x07, 0xD2,
  40333. 0x83, 0x8B, 0x89, 0x04, 0x70, 0x06, 0x60, 0x4F,
  40334. 0xB6, 0x10, 0x2B, 0xA0, 0x92, 0xF4, 0x1A, 0x7A,
  40335. 0xD6, 0x4F, 0xDC, 0x6C, 0x6C, 0x27, 0xE5, 0xEC,
  40336. 0x68, 0x1B, 0x95, 0x7C, 0x1C, 0x95, 0x2C, 0xB7,
  40337. 0x0A, 0x8D, 0xC7, 0x57, 0x92, 0x00, 0x4D, 0xC0,
  40338. 0x5F, 0xD4, 0xF4, 0x88, 0x3F, 0x8D, 0x43, 0x12,
  40339. 0x05, 0xE2, 0x14, 0x0E, 0xDD, 0x2C, 0xEC, 0xD5,
  40340. 0x2F, 0x1A, 0xE6, 0x97, 0xDC, 0xFE, 0x96, 0x80,
  40341. 0x67, 0x3B, 0xD4, 0x63, 0x73, 0xFA, 0xC8, 0x4F,
  40342. 0x4C, 0x4F, 0x2D, 0x68, 0x76, 0x44, 0x8E, 0xC2,
  40343. 0x19, 0x99, 0x44, 0xEA, 0xF2, 0x33, 0x23, 0x83,
  40344. 0xC8, 0xB1, 0x7C, 0x27, 0x43, 0x9B, 0x67, 0xF9,
  40345. 0xDE, 0xE1, 0xAE, 0x03, 0xA5, 0xA5, 0x2B, 0x96,
  40346. 0xB2, 0xEC, 0x4A, 0x43, 0xA7, 0x6D, 0xF4, 0xDB,
  40347. 0x32, 0x5B, 0x54, 0xD6, 0x63, 0xEA, 0x65, 0xC2,
  40348. 0xA8, 0x4B, 0x80, 0xCC, 0x65, 0x2D, 0xCE, 0x6F,
  40349. 0x61, 0x2F, 0x58, 0xD1, 0xE5, 0x64, 0x8A, 0x42,
  40350. 0x8D, 0xBA, 0xFA, 0x35, 0x5C, 0x9E, 0xD5, 0x80,
  40351. 0x2D, 0x5C, 0xC3, 0x47, 0xFB, 0x0D, 0x43, 0x20,
  40352. 0x7A, 0xA4, 0x37, 0xB2, 0x2F, 0x0B, 0x43, 0xB9,
  40353. 0x94, 0xD3, 0xD9, 0xC2, 0xD7, 0x02, 0x5D, 0x6A,
  40354. 0x12, 0x99, 0xE7, 0x32, 0x6C, 0xF0, 0x0C, 0x73,
  40355. 0x51, 0x33, 0x84, 0xA9, 0x0C, 0x66, 0xC9, 0x19,
  40356. 0x88, 0x9A, 0xF1, 0xB6, 0xF8, 0x41, 0xB1, 0xDC,
  40357. 0x60, 0xA4, 0x80, 0x73, 0x0B, 0x21, 0xF9, 0xB8,
  40358. 0x01, 0x7E, 0x66, 0x0D, 0xB4, 0x2B, 0x53, 0x8D,
  40359. 0x7D, 0x0B, 0xE1, 0xA3, 0x0C, 0x27, 0xF6, 0x2F,
  40360. 0x27, 0x34, 0x53, 0x75, 0x54, 0xF7, 0x5E, 0x05,
  40361. 0x1C, 0x5A, 0x94, 0x08, 0x14, 0xDE, 0xAA, 0x98,
  40362. 0xD9, 0xA5, 0xA0, 0xBE, 0x80, 0xC1, 0xEB, 0x3C,
  40363. 0xCF, 0x78, 0x88, 0xA4, 0xA2, 0x03, 0xF8, 0x79,
  40364. 0x1F, 0x84, 0x84, 0xA7, 0x0E, 0x95, 0x1A, 0x85,
  40365. 0xEF, 0x4C, 0xBE, 0xA2, 0x99, 0xAB, 0x10, 0xDD,
  40366. 0x85, 0x3F, 0x10, 0x6A, 0x9C, 0xD5, 0xDD, 0x7A,
  40367. 0xFB, 0xF5, 0xD9, 0xD9, 0xAA, 0xDF, 0x03, 0x78,
  40368. 0xAF, 0x1D, 0xEC, 0x18, 0xEB, 0x00, 0xB6, 0x64,
  40369. 0xB5, 0x75, 0xA5, 0x00, 0xDC, 0x36, 0x45, 0xBD,
  40370. 0x0C, 0x66, 0xCE, 0xA9, 0xBB, 0xD1, 0xF7, 0xE4,
  40371. 0x6A, 0xDA, 0x0E, 0x81, 0x0F, 0x6A, 0x71, 0x60,
  40372. 0x5C, 0x41, 0xD2, 0x12, 0x45, 0x14, 0xEF, 0x6F,
  40373. 0xEC, 0x22, 0x73, 0x4C, 0xA7, 0x94, 0xDD, 0x1A,
  40374. 0x42, 0x22, 0x58, 0x14, 0x0C, 0x4E, 0x6D, 0x77,
  40375. 0x7F, 0xF5, 0xC9, 0x69, 0x81, 0xA3, 0xB8, 0x6D,
  40376. 0x1C, 0x39, 0x47, 0xA5, 0xC4, 0x61, 0x1C, 0x91,
  40377. 0x2F, 0x67, 0xC3, 0x5E, 0x87, 0x1A, 0x85, 0x81,
  40378. 0x7D, 0x76, 0xF2, 0xE0, 0xB9, 0xD0, 0x43, 0x33,
  40379. 0xF1, 0xC1, 0xBA, 0x48, 0x6F, 0x48, 0xD5, 0xAE,
  40380. 0xB6, 0xDC, 0xAA, 0xCA, 0xEB, 0x0B, 0x6B, 0xFE,
  40381. 0xF4, 0xF1, 0x6E, 0x5D, 0xE4, 0x90, 0x53, 0xCF,
  40382. 0x9E, 0x13, 0x80, 0xCE, 0xE5, 0xDD, 0xA4, 0x01,
  40383. 0xBC, 0x16, 0x50, 0xD0, 0x78, 0x96, 0x3F, 0x2B,
  40384. 0x7A, 0x71, 0x8E, 0x86, 0xFD, 0x14, 0x21, 0xDF,
  40385. 0x4D, 0xD7, 0xDD, 0x42, 0x59, 0xB3, 0xED, 0x81,
  40386. 0xE3, 0xAF, 0x71, 0x57, 0xE7, 0x04, 0xD2, 0x26,
  40387. 0xA8, 0x83, 0xFC, 0x03, 0x90, 0x8C, 0x88, 0xC4,
  40388. 0xBF, 0x74, 0x54, 0x59, 0xD8, 0x66, 0x9F, 0xE2,
  40389. 0x7A, 0xCE, 0x5B, 0x9C, 0xC4, 0x37, 0xFA, 0xDB,
  40390. 0x40, 0x9A, 0xDD, 0x73, 0x9C, 0x06, 0x5A, 0x21,
  40391. 0x43, 0xFB, 0xFA, 0x1B, 0x41, 0x31, 0x9F, 0xF4,
  40392. 0x24, 0x09, 0x05, 0xFE, 0x56, 0x17, 0x52, 0x9C,
  40393. 0xC7, 0xE2, 0xCA, 0xC9, 0x1F, 0xBE, 0xE2, 0xEB,
  40394. 0x92, 0xEE, 0xD4, 0x76, 0x44, 0x9A, 0xFA, 0xFB,
  40395. 0x07, 0x62, 0x98, 0xEC, 0xA0, 0xCF, 0xBF, 0xFA,
  40396. 0x5E, 0x1B, 0x8B, 0xCD, 0x33, 0xFB, 0x1A, 0x97,
  40397. 0xFE, 0x50, 0x65, 0x22, 0x08, 0x9E, 0xC3, 0x87,
  40398. 0x88, 0xCA, 0xDD, 0x11, 0x5E, 0xA7, 0xCF, 0xF3,
  40399. 0x07, 0x0A, 0x34, 0x0E, 0x30, 0x1B, 0xC5, 0xCE,
  40400. 0xF7, 0xA6, 0xA4, 0x31, 0xB5, 0x40, 0xB8, 0x81,
  40401. 0xAC, 0xAA, 0x07, 0xE0, 0x7D, 0x5E, 0x6A, 0x25,
  40402. 0x85, 0x8D, 0x1D, 0x82, 0x45, 0x82, 0x76, 0xB2,
  40403. 0x65, 0x69, 0x3E, 0x88, 0xFE, 0x21, 0xFE, 0x6A,
  40404. 0x6B, 0x97, 0xD6, 0x70, 0x70, 0x00, 0x83, 0x18,
  40405. 0x39, 0xA6, 0x91, 0x3F, 0xB1, 0xB7, 0xED, 0x11,
  40406. 0xD3, 0xF9, 0x74, 0x31, 0xEC, 0x21, 0xA2, 0xEE,
  40407. 0x69, 0x04, 0xC0, 0xEA, 0x4A, 0x17, 0x1A, 0xF8,
  40408. 0xDA, 0xF1, 0x52, 0xB2, 0x78, 0x69, 0x4F, 0xDF,
  40409. 0xE6, 0xB9, 0xF3, 0xE7, 0x48, 0x8B, 0x09, 0x5F,
  40410. 0x4A, 0x7A, 0x05, 0x8E, 0xA8, 0xF6, 0x69, 0x3D,
  40411. 0x91, 0x7A, 0x6F, 0x6C, 0xAD, 0x03, 0x16, 0xEA,
  40412. 0xE0, 0x04, 0xFE, 0x54, 0x71, 0x50, 0x6D, 0x31,
  40413. 0xE4, 0x37, 0x76, 0xD6, 0x1B, 0xA9, 0xEE, 0x56,
  40414. 0x7A, 0x39, 0x34, 0x24, 0x00, 0x58, 0xE3, 0x2F,
  40415. 0xD4, 0x97, 0x57, 0x6F, 0xD8, 0x0E, 0x8B, 0xD3,
  40416. 0x88, 0x7F, 0xE8, 0x74, 0x72, 0xF7, 0xBA, 0x26,
  40417. 0x25, 0xE4, 0xD5, 0x86, 0xCD, 0xA8, 0x1E, 0x8D,
  40418. 0x49, 0xCF, 0x04, 0x92, 0x5B, 0x50, 0xD0, 0x73,
  40419. 0x3C, 0xC9, 0x17, 0xC3, 0x0E, 0x67, 0x02, 0xC5,
  40420. 0xDE, 0x48, 0x88, 0x0D, 0x2C, 0x0D, 0x68, 0x04,
  40421. 0xD5, 0x51, 0xDF, 0x4F, 0x23, 0x89, 0x7A, 0x29,
  40422. 0x41, 0xB2, 0x7A, 0xCA, 0x86, 0xA5, 0xCC, 0xC4,
  40423. 0xF5, 0xD3, 0xE1, 0xEF, 0xB8, 0xCD, 0x84, 0xB5,
  40424. 0x6D, 0xB6, 0x51, 0x1B, 0x81, 0x26, 0x97, 0xAC,
  40425. 0x00, 0xFC, 0x76, 0x8D, 0x99, 0xD9, 0x35, 0x8E,
  40426. 0x4D, 0x3E, 0xC0, 0xC1, 0x0E, 0x8D, 0x9B, 0xE5,
  40427. 0x79, 0xF3, 0xC7, 0xA0, 0xA4, 0xA6, 0xA2, 0xE9,
  40428. 0x8B, 0xCD, 0x36, 0x79, 0x76, 0xF1, 0x6A, 0xEE,
  40429. 0xCF, 0x91, 0x8D, 0x91, 0xB1, 0xAF, 0xF2, 0xF5,
  40430. 0x43, 0xF6, 0xB2, 0x3A, 0x39, 0x9F, 0xBF, 0xDE,
  40431. 0x16, 0x03, 0x52, 0x18, 0x62, 0x93, 0xB5, 0x09,
  40432. 0xC4, 0xEE, 0x27, 0x9C, 0x56, 0x6F, 0x0C, 0x1C,
  40433. 0x12, 0x42, 0xF0, 0x34, 0xBD, 0x44, 0x52, 0x4C,
  40434. 0x32, 0x7E, 0x64, 0xDF, 0x78, 0x16, 0xD9, 0x9E,
  40435. 0xD7, 0x8A, 0x11, 0x33, 0x65, 0x42, 0xEC, 0x36,
  40436. 0x07, 0xEE, 0x3F, 0x19, 0x97, 0x9B, 0x92, 0x9D,
  40437. 0x3A, 0xE4, 0x98, 0x83, 0xDB, 0x0C, 0x85, 0x39,
  40438. 0xFA, 0x8D, 0x73, 0xF5, 0xBF, 0xE0, 0x75, 0x40,
  40439. 0x50, 0x9B, 0xF2, 0xE6, 0xB6, 0xA5, 0x33, 0xD0,
  40440. 0xC4, 0xD6, 0xAB, 0xFF, 0x16, 0xDE, 0x30, 0x9C,
  40441. 0x68, 0x90, 0xE0, 0x5E, 0xD3, 0xD5, 0xA9, 0xB0,
  40442. 0xD9, 0x6B, 0x0A, 0x43, 0x45, 0x9A, 0x3D, 0xE8,
  40443. 0xB6, 0x66, 0xE4, 0x57, 0x05, 0x8E, 0x5B, 0x72,
  40444. 0xFE, 0x50, 0x44, 0x8C, 0xE4, 0x68, 0x43, 0x51,
  40445. 0x0D, 0x9A, 0xD3, 0x36, 0xA9, 0xC7, 0xF6, 0xCF,
  40446. 0x6D, 0x2C, 0x95, 0x46, 0x98, 0x6D, 0x9E, 0x78,
  40447. 0x90, 0x87, 0x19, 0x64, 0xD5, 0xDE, 0x1D, 0x9B,
  40448. 0x37, 0x4E, 0x52, 0xF5, 0x14, 0xAA, 0xEE, 0x31,
  40449. 0x83, 0x55, 0x7C, 0x38, 0x0F, 0xB3, 0xF6, 0xF2,
  40450. 0x1C, 0x60, 0x71, 0x68, 0x1F, 0x06, 0xBD, 0x99,
  40451. 0xFD, 0x42, 0x12, 0x54, 0x3E, 0xBA, 0x4B, 0x60,
  40452. 0xFB, 0xFB, 0x51, 0x4D, 0x02, 0xCE, 0xE5, 0x9E,
  40453. 0x59, 0xB2, 0xE6, 0x98, 0x67, 0xBB, 0xAB, 0xC8,
  40454. 0x08, 0xE4, 0x08, 0x0D, 0xF5, 0x3B, 0x47, 0x78,
  40455. 0x39, 0x24, 0x56, 0x80, 0xF0, 0x6A, 0x1D, 0x33,
  40456. 0x05, 0x5F, 0xF2, 0xA2, 0x38, 0xAD, 0xDF, 0x5C,
  40457. 0xC5, 0xEA, 0x9C, 0xC7, 0x0A, 0x1B, 0x5B, 0x43,
  40458. 0xE9, 0x59, 0x3D, 0x68, 0x00, 0x23, 0x32, 0x5D,
  40459. 0x25, 0xFD, 0xA7, 0xCA, 0xDA, 0xA1, 0xFD, 0x22,
  40460. 0x4E, 0x34, 0x96, 0xE7, 0x0D, 0xFF, 0x89, 0x3B,
  40461. 0xA6, 0x56, 0x0D, 0x11, 0x13, 0xA6, 0x9D, 0x3B,
  40462. 0xBC, 0x12, 0x97, 0x9A, 0x2B, 0xAA, 0xE9, 0xE2,
  40463. 0xCF, 0xD2, 0xD3, 0xEF, 0x95, 0xFC, 0x40, 0x80,
  40464. 0x94, 0x48, 0x80, 0x5A, 0x3F, 0x4A, 0xD2, 0xB5,
  40465. 0x7D, 0x61, 0xA2, 0x26, 0x7B, 0xDC, 0x32, 0xCB,
  40466. 0x84, 0x2E, 0x9B, 0x29, 0x63, 0x45, 0x74, 0x0D,
  40467. 0x85, 0x54, 0xB2, 0x16, 0x77, 0x9B, 0x47, 0x51,
  40468. 0x63, 0x33, 0xE9, 0x1A, 0x52, 0x9D, 0xEB, 0x26,
  40469. 0x06, 0x7F, 0x97, 0xA0, 0xA1, 0xAA, 0x07, 0x0F,
  40470. 0x1E, 0x23, 0xAB, 0xCC, 0xD5, 0x0F, 0x3E, 0x88,
  40471. 0xAA, 0xC3, 0xED, 0x06, 0x25, 0x3A, 0x4A, 0x62,
  40472. 0x85, 0x9F, 0xA7, 0xD3, 0xF5, 0x1C, 0x9A, 0xCC,
  40473. 0x52, 0x87, 0x9F, 0xB8, 0xC7, 0xDD, 0xF1, 0x50,
  40474. 0x66, 0x70, 0xAC, 0xC6, 0x2C, 0x2E, 0x8C, 0xC9,
  40475. 0xD9, 0xF6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40476. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40477. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40478. 0x00, 0x00, 0x00, 0x06, 0x0D, 0x13, 0x1D, 0x20,
  40479. 0x27, 0x2C, 0x32
  40480. };
  40481. #endif
  40482. byte sig[DILITHIUM_MAX_SIG_SIZE];
  40483. word32 sigLen;
  40484. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  40485. ExpectNotNull(key);
  40486. if (key != NULL) {
  40487. XMEMSET(key, 0, sizeof(*key));
  40488. }
  40489. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  40490. #ifndef WOLFSSL_NO_ML_DSA_44
  40491. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  40492. ExpectIntEQ(wc_dilithium_import_private(sk_44, (word32)sizeof(sk_44), key),
  40493. 0);
  40494. sigLen = PARAMS_ML_DSA_44_SIG_SIZE;
  40495. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_44, (word32)sizeof(msg_44),
  40496. sig, &sigLen, key, rnd_44), 0);
  40497. ExpectIntEQ(sigLen, PARAMS_ML_DSA_44_SIG_SIZE);
  40498. ExpectIntEQ(XMEMCMP(sig, sig_44, sizeof(sig_44)), 0);
  40499. #endif
  40500. #ifndef WOLFSSL_NO_ML_DSA_65
  40501. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  40502. ExpectIntEQ(wc_dilithium_import_private(sk_65, (word32)sizeof(sk_65), key),
  40503. 0);
  40504. sigLen = PARAMS_ML_DSA_65_SIG_SIZE;
  40505. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_65, (word32)sizeof(msg_65),
  40506. sig, &sigLen, key, rnd_65), 0);
  40507. ExpectIntEQ(sigLen, PARAMS_ML_DSA_65_SIG_SIZE);
  40508. ExpectIntEQ(XMEMCMP(sig, sig_65, sizeof(sig_65)), 0);
  40509. #endif
  40510. #ifndef WOLFSSL_NO_ML_DSA_87
  40511. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  40512. ExpectIntEQ(wc_dilithium_import_private(sk_87, (word32)sizeof(sk_87), key),
  40513. 0);
  40514. sigLen = PARAMS_ML_DSA_87_SIG_SIZE;
  40515. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_87, (word32)sizeof(msg_87),
  40516. sig, &sigLen, key, rnd_87), 0);
  40517. ExpectIntEQ(sigLen, PARAMS_ML_DSA_87_SIG_SIZE);
  40518. ExpectIntEQ(XMEMCMP(sig, sig_87, sizeof(sig_87)), 0);
  40519. #endif
  40520. wc_dilithium_free(key);
  40521. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  40522. #endif
  40523. return EXPECT_RESULT();
  40524. }
  40525. static int test_wc_dilithium_verify_kats(void)
  40526. {
  40527. EXPECT_DECLS;
  40528. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  40529. !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  40530. dilithium_key* key;
  40531. int res;
  40532. #ifndef WOLFSSL_NO_ML_DSA_44
  40533. static const byte pk_44[] = {
  40534. 0x09, 0xB4, 0x88, 0x7D, 0x97, 0xBC, 0xF6, 0x37,
  40535. 0x9C, 0xC5, 0x9B, 0x61, 0x62, 0xC1, 0xE8, 0xBF,
  40536. 0x05, 0x60, 0xBF, 0x44, 0xD6, 0x18, 0x09, 0x17,
  40537. 0x0E, 0x6E, 0x28, 0xF7, 0x06, 0x69, 0xA3, 0xE9,
  40538. 0x49, 0x64, 0x38, 0xE8, 0x91, 0x57, 0x35, 0xAD,
  40539. 0xAE, 0xB4, 0x45, 0xCF, 0xDB, 0x7D, 0x89, 0xB3,
  40540. 0x8C, 0x04, 0x8F, 0x4C, 0x3E, 0x00, 0x58, 0x15,
  40541. 0x14, 0xC5, 0xFD, 0x19, 0x8B, 0x2D, 0x17, 0x39,
  40542. 0xE8, 0x83, 0xB8, 0x78, 0xD5, 0x6B, 0xB4, 0x12,
  40543. 0x64, 0xBE, 0x41, 0xD3, 0xD5, 0x15, 0x65, 0xE2,
  40544. 0xE9, 0xCA, 0xE3, 0x31, 0x84, 0xA8, 0x99, 0xF6,
  40545. 0x2D, 0xD5, 0x7D, 0x07, 0x40, 0x0E, 0x98, 0xE5,
  40546. 0x86, 0x87, 0xA9, 0xB2, 0x2F, 0xA3, 0x17, 0xEE,
  40547. 0xD1, 0x34, 0xCA, 0x72, 0x14, 0xBF, 0xF0, 0x21,
  40548. 0xDD, 0x21, 0x62, 0xB1, 0x83, 0x09, 0x1D, 0x15,
  40549. 0xF2, 0x63, 0xB7, 0x29, 0x82, 0x14, 0x42, 0x3C,
  40550. 0x6B, 0xB6, 0x96, 0xD7, 0x5C, 0x20, 0xD9, 0xEA,
  40551. 0xCD, 0x0A, 0x03, 0xE4, 0x26, 0x2C, 0x4B, 0x08,
  40552. 0xBE, 0x39, 0xFA, 0x21, 0x54, 0xBD, 0x6E, 0x50,
  40553. 0x25, 0xFF, 0x79, 0x1E, 0x88, 0x5F, 0x22, 0x26,
  40554. 0xE3, 0xCF, 0x48, 0xF7, 0xB5, 0xEB, 0x04, 0xFB,
  40555. 0xE9, 0xEC, 0xF7, 0x5B, 0x19, 0xE1, 0xD1, 0x5C,
  40556. 0x30, 0x5E, 0x92, 0x26, 0x0A, 0xB0, 0xD6, 0xAE,
  40557. 0x7D, 0xBA, 0x7B, 0xBE, 0x73, 0xB6, 0xBC, 0x18,
  40558. 0x1C, 0xF9, 0x33, 0x84, 0x0C, 0xC1, 0x0A, 0x00,
  40559. 0x05, 0x02, 0x28, 0xFA, 0x46, 0xA2, 0x63, 0x6D,
  40560. 0xD9, 0xA9, 0x09, 0x47, 0xE9, 0xF1, 0x3A, 0x93,
  40561. 0xEF, 0x4C, 0x62, 0xBE, 0x37, 0x4D, 0x76, 0xD1,
  40562. 0xFD, 0xBB, 0xC5, 0xD8, 0xB5, 0x5E, 0x72, 0x9F,
  40563. 0xA5, 0x86, 0x65, 0xAA, 0x07, 0xB9, 0x0C, 0x8C,
  40564. 0xDD, 0xD6, 0x1C, 0x56, 0x6B, 0x0D, 0x7E, 0xD6,
  40565. 0x57, 0x70, 0x49, 0x2E, 0xA0, 0x71, 0x3E, 0x1E,
  40566. 0xD4, 0x6A, 0xC7, 0xAD, 0x15, 0x03, 0xC5, 0x6D,
  40567. 0x90, 0x52, 0xD2, 0xC9, 0x4D, 0x49, 0xE4, 0x41,
  40568. 0x6A, 0xC9, 0x2B, 0x70, 0x39, 0x6F, 0x76, 0xF6,
  40569. 0xFB, 0x48, 0x10, 0x45, 0x68, 0x17, 0x25, 0xA6,
  40570. 0x8C, 0xB3, 0x56, 0x37, 0x7F, 0xB2, 0x31, 0xAB,
  40571. 0x8F, 0x3E, 0xB9, 0xA4, 0x98, 0x2F, 0xFF, 0x18,
  40572. 0x36, 0x47, 0x3B, 0xCB, 0xDA, 0xB6, 0x87, 0x2D,
  40573. 0x22, 0x94, 0x67, 0xEF, 0xB9, 0x36, 0x62, 0x61,
  40574. 0xFE, 0xB1, 0x48, 0xBA, 0x9B, 0x7D, 0xB9, 0xC4,
  40575. 0xFE, 0x0B, 0xB8, 0x86, 0x12, 0xAB, 0xB8, 0xFD,
  40576. 0x61, 0x09, 0x6F, 0x18, 0x19, 0x60, 0x4D, 0x55,
  40577. 0xDF, 0x60, 0x20, 0x46, 0x4D, 0x3F, 0x09, 0x2C,
  40578. 0xFC, 0xA5, 0x98, 0x12, 0x08, 0x22, 0x18, 0x56,
  40579. 0x68, 0x99, 0xA5, 0x6A, 0x3C, 0x63, 0x3C, 0xC8,
  40580. 0x1F, 0x88, 0xAD, 0xB2, 0xE1, 0x41, 0x4E, 0xF3,
  40581. 0x85, 0x0D, 0x10, 0xBF, 0x5A, 0x77, 0xAC, 0xE7,
  40582. 0x24, 0xD6, 0xC1, 0xF3, 0x88, 0x92, 0x87, 0x44,
  40583. 0xB3, 0xE5, 0x42, 0xAE, 0x49, 0x1C, 0xD5, 0x6A,
  40584. 0x64, 0x21, 0x3F, 0x1D, 0x3C, 0xC9, 0x0B, 0x29,
  40585. 0x10, 0x5F, 0x43, 0xD2, 0x37, 0xC8, 0x3D, 0x5F,
  40586. 0xB8, 0x29, 0x32, 0x5C, 0x83, 0xE6, 0x54, 0x57,
  40587. 0x77, 0x76, 0x39, 0x2F, 0x85, 0x36, 0xAA, 0x9D,
  40588. 0xAE, 0x87, 0x24, 0x07, 0xAB, 0xAA, 0xA9, 0xAC,
  40589. 0xC2, 0x2A, 0x68, 0x12, 0xCE, 0xA7, 0x4C, 0x0B,
  40590. 0xA6, 0x7E, 0xAF, 0x4A, 0x41, 0x01, 0x52, 0x97,
  40591. 0x5E, 0x9A, 0x83, 0xEE, 0x44, 0x69, 0x29, 0x53,
  40592. 0x17, 0xBE, 0xD1, 0x05, 0x51, 0xBA, 0x32, 0xE6,
  40593. 0x5A, 0xFC, 0x8C, 0x8E, 0x68, 0xDD, 0x55, 0x42,
  40594. 0x0C, 0x50, 0x2D, 0x93, 0x7D, 0xAD, 0xD2, 0xEF,
  40595. 0xA2, 0xCB, 0xFD, 0x1F, 0x73, 0x9F, 0xC0, 0xAB,
  40596. 0x2B, 0x26, 0x54, 0xFA, 0xE0, 0x8C, 0x0C, 0x7F,
  40597. 0x8E, 0xDD, 0x43, 0xCF, 0x9F, 0xF0, 0xB0, 0x1D,
  40598. 0x98, 0x4D, 0x49, 0x18, 0x52, 0xA3, 0x72, 0xE9,
  40599. 0xFE, 0xFD, 0xCC, 0x1B, 0xC1, 0x6C, 0xDB, 0x52,
  40600. 0x39, 0xAE, 0x10, 0x01, 0x15, 0x5F, 0x89, 0x56,
  40601. 0x30, 0x51, 0xCE, 0x47, 0x99, 0x6C, 0x5A, 0xEE,
  40602. 0xB2, 0x19, 0x0E, 0xA1, 0x8F, 0x7F, 0x73, 0x40,
  40603. 0x42, 0xDE, 0x68, 0xE9, 0x88, 0x36, 0x7D, 0x89,
  40604. 0x35, 0x5D, 0x9D, 0x83, 0x77, 0xBA, 0xF9, 0x64,
  40605. 0x79, 0x78, 0xEB, 0x2E, 0x49, 0x2A, 0xD0, 0x21,
  40606. 0xC5, 0x69, 0xAE, 0x8B, 0xA6, 0x9B, 0x15, 0xF1,
  40607. 0xFC, 0xF7, 0x03, 0x9A, 0x7E, 0x64, 0xAF, 0x10,
  40608. 0xAB, 0xF3, 0xEA, 0x45, 0xB7, 0x22, 0x2F, 0x96,
  40609. 0x59, 0xE3, 0x33, 0x73, 0x37, 0x2E, 0x1D, 0xB1,
  40610. 0x86, 0xD2, 0xC2, 0xA0, 0xD7, 0x54, 0x51, 0xC4,
  40611. 0x78, 0xAE, 0xF3, 0x3E, 0x59, 0x49, 0xF2, 0x40,
  40612. 0x04, 0x0C, 0x2A, 0xFC, 0x44, 0xB1, 0xD3, 0xA0,
  40613. 0x2A, 0x6D, 0x2F, 0x87, 0x90, 0x2A, 0x28, 0x0E,
  40614. 0x27, 0xA2, 0x0D, 0x4E, 0x57, 0xF8, 0x89, 0x66,
  40615. 0x27, 0x00, 0xDB, 0x8A, 0x9D, 0x24, 0x99, 0x57,
  40616. 0xA7, 0xDB, 0x43, 0x7C, 0xD4, 0x80, 0xDD, 0xC0,
  40617. 0x58, 0x84, 0xFB, 0x23, 0xF8, 0x68, 0x26, 0x8E,
  40618. 0xAC, 0xE3, 0x4E, 0xED, 0x27, 0x4A, 0x92, 0x7D,
  40619. 0x9D, 0x84, 0xF1, 0xEA, 0x57, 0xEA, 0xB1, 0xA8,
  40620. 0x13, 0xB5, 0xE6, 0xAA, 0xBE, 0x9E, 0xD2, 0x61,
  40621. 0x0B, 0xC6, 0xF7, 0x2E, 0x32, 0x0C, 0xDE, 0xC4,
  40622. 0xF9, 0x95, 0x23, 0xF9, 0x3F, 0xA4, 0x48, 0xDC,
  40623. 0x1F, 0xBB, 0xDD, 0x25, 0x9B, 0x10, 0x2F, 0x5D,
  40624. 0xC9, 0x95, 0x5A, 0xFA, 0x0C, 0x41, 0x60, 0x4D,
  40625. 0x83, 0xDD, 0x1C, 0x2D, 0x22, 0x95, 0xEF, 0x44,
  40626. 0x61, 0x45, 0x6B, 0xAE, 0x86, 0x90, 0x5C, 0x4C,
  40627. 0x30, 0xD8, 0xA9, 0xFA, 0x48, 0xC9, 0x0F, 0x37,
  40628. 0xA1, 0x9C, 0x41, 0xA2, 0xD5, 0x98, 0x8F, 0x13,
  40629. 0xD5, 0x13, 0x44, 0xEC, 0x30, 0xA4, 0xA4, 0x62,
  40630. 0x19, 0xFE, 0x84, 0x11, 0x37, 0xD5, 0xAA, 0x1F,
  40631. 0x51, 0xE6, 0xC4, 0x44, 0x16, 0x8A, 0xF3, 0x98,
  40632. 0x90, 0xB6, 0xFA, 0x40, 0x0D, 0x67, 0xF4, 0x80,
  40633. 0x6F, 0x5B, 0xBD, 0x44, 0x47, 0x03, 0x07, 0x4A,
  40634. 0x7A, 0x11, 0x39, 0xC7, 0x17, 0x46, 0xD7, 0xC4,
  40635. 0xCE, 0xB3, 0xC9, 0x11, 0xF5, 0x25, 0x7E, 0x3E,
  40636. 0x53, 0xEB, 0xFA, 0x5A, 0xA8, 0xF2, 0x27, 0x80,
  40637. 0x9D, 0x44, 0xEE, 0x7D, 0xE1, 0x3C, 0x02, 0x79,
  40638. 0x24, 0xDD, 0x60, 0x15, 0x3B, 0x30, 0xAA, 0x76,
  40639. 0xDD, 0x96, 0xA7, 0xC5, 0xAC, 0xC5, 0x9B, 0x62,
  40640. 0x79, 0x19, 0x50, 0x7B, 0xF1, 0x42, 0x57, 0xAE,
  40641. 0x7A, 0x26, 0x24, 0x3C, 0x16, 0x83, 0xB2, 0x8D,
  40642. 0x1B, 0x14, 0xB5, 0x01, 0xAD, 0x05, 0x9B, 0x4D,
  40643. 0x52, 0x2A, 0x57, 0x99, 0x1E, 0x55, 0x39, 0xCE,
  40644. 0xF1, 0x8C, 0xEB, 0x5C, 0x26, 0xD6, 0x60, 0xB8,
  40645. 0x82, 0x24, 0x54, 0xC9, 0xC4, 0x2A, 0x95, 0xE6,
  40646. 0xF7, 0x2B, 0x84, 0xF7, 0x8A, 0xB9, 0x9F, 0x51,
  40647. 0xEC, 0x49, 0x78, 0x9F, 0x9D, 0xB4, 0xC1, 0x28,
  40648. 0xB0, 0x31, 0x8F, 0xFF, 0xC8, 0x2D, 0x95, 0xCA,
  40649. 0xD2, 0x77, 0xF1, 0x1E, 0x14, 0xF1, 0xEF, 0x87,
  40650. 0x14, 0x14, 0x88, 0x11, 0x22, 0xA9, 0xB1, 0x1B,
  40651. 0xDF, 0xAE, 0x4A, 0x7A, 0xBC, 0x8E, 0x75, 0x75,
  40652. 0x5A, 0xB1, 0x37, 0x41, 0xDF, 0xAC, 0xD6, 0x64,
  40653. 0x29, 0x3D, 0x1A, 0x32, 0x6B, 0xF5, 0xED, 0x5A,
  40654. 0xBB, 0xB1, 0x53, 0xEB, 0xE6, 0x99, 0x6D, 0xD6,
  40655. 0x22, 0xF0, 0xA8, 0xCB, 0x47, 0x39, 0x69, 0xA5,
  40656. 0x03, 0x66, 0xBD, 0x0B, 0x01, 0xC5, 0xC7, 0x3A,
  40657. 0x89, 0x2B, 0x8E, 0x26, 0xCE, 0x08, 0xF7, 0x5F,
  40658. 0xF8, 0x01, 0xB6, 0xDE, 0xF0, 0x41, 0xE1, 0x71,
  40659. 0x3B, 0xE6, 0xDF, 0x0E, 0xFB, 0x51, 0x58, 0x7B,
  40660. 0xE5, 0xFB, 0xEA, 0x72, 0x7E, 0x00, 0xD7, 0x17,
  40661. 0x64, 0x7D, 0xD5, 0x39, 0x07, 0x9D, 0xE1, 0x8A,
  40662. 0xE7, 0xBE, 0xD1, 0x2B, 0x91, 0xAF, 0x8D, 0xBB,
  40663. 0x1B, 0x8B, 0x32, 0xD2, 0x86, 0x0B, 0xAF, 0x40,
  40664. 0xAF, 0x8A, 0x0B, 0xBF, 0xE0, 0x28, 0x87, 0xEB,
  40665. 0x5D, 0xBE, 0x7A, 0xB1, 0xAF, 0xC4, 0x1D, 0xA7,
  40666. 0x9B, 0x01, 0x6A, 0xA1, 0x6E, 0xDA, 0x28, 0x13,
  40667. 0x21, 0xCA, 0xA5, 0xDA, 0x64, 0x4F, 0xD8, 0x65,
  40668. 0x8A, 0x7B, 0x70, 0x21, 0x81, 0x00, 0x14, 0x31,
  40669. 0x56, 0x0D, 0xD6, 0x3C, 0xB2, 0x1E, 0x5F, 0xF7,
  40670. 0x5C, 0x3F, 0x72, 0x50, 0x45, 0x6B, 0xE0, 0x8C,
  40671. 0x0D, 0x5E, 0x34, 0xC3, 0xBD, 0xE2, 0xF6, 0x06,
  40672. 0xA2, 0xBF, 0x34, 0x17, 0x76, 0x8D, 0x24, 0xB2,
  40673. 0x37, 0x39, 0xEA, 0x86, 0xCB, 0xEF, 0xDD, 0xA3,
  40674. 0x43, 0x88, 0xBC, 0x1F, 0x91, 0x8F, 0x95, 0x1E,
  40675. 0x15, 0xE4, 0x3B, 0x13, 0x85, 0xA7, 0xBC, 0xC5,
  40676. 0x59, 0xF9, 0x49, 0x2C, 0x72, 0x13, 0xA1, 0x42,
  40677. 0x27, 0xE0, 0x93, 0xE9, 0x29, 0xF3, 0x2D, 0x1E,
  40678. 0xFB, 0xE7, 0xF1, 0xEE, 0x57, 0xC4, 0x9C, 0x90,
  40679. 0x55, 0x62, 0x3E, 0xA4, 0x2E, 0xC6, 0xC7, 0x9D,
  40680. 0x7F, 0xCE, 0x71, 0xFA, 0x74, 0x76, 0x07, 0x56,
  40681. 0x6D, 0xDA, 0x69, 0xF6, 0x9D, 0xAF, 0x68, 0x11,
  40682. 0x59, 0x19, 0xC6, 0x32, 0x2E, 0xBB, 0x42, 0xC8,
  40683. 0xC0, 0x89, 0x33, 0x8C, 0x9E, 0x0C, 0x53, 0x56,
  40684. 0x5B, 0xCB, 0xE7, 0x2F, 0xBE, 0x47, 0x26, 0x68,
  40685. 0x7B, 0x07, 0x87, 0x07, 0x18, 0x06, 0xC5, 0xA6,
  40686. 0xC1, 0x49, 0xC8, 0x2B, 0x66, 0x8A, 0xA6, 0x4A,
  40687. 0x7B, 0xA0, 0xCC, 0xC1, 0xCC, 0x49, 0xA1, 0xEE,
  40688. 0xE9, 0x45, 0x3D, 0x04, 0x33, 0x6E, 0x5D, 0xC8,
  40689. 0x11, 0xE0, 0x38, 0x92, 0xF7, 0xF4, 0x66, 0x88,
  40690. 0xEC, 0xEF, 0xD0, 0x4F, 0x18, 0x76, 0xF7, 0x11,
  40691. 0x17, 0x12, 0xB5, 0x95, 0xED, 0x62, 0xDA, 0x00,
  40692. 0x67, 0x8F, 0x9E, 0x37, 0x86, 0xB5, 0xC1, 0xA5,
  40693. 0x09, 0x5B, 0xE8, 0x71, 0x0D, 0xCF, 0xA4, 0x16,
  40694. 0x52, 0x56, 0x50, 0x9E, 0x00, 0x14, 0x3A, 0x6F,
  40695. 0x11, 0x72, 0xFA, 0xBE, 0x8B, 0xF2, 0x1E, 0x5F,
  40696. 0xCE, 0x7C, 0x79, 0xC1, 0xA4, 0x4B, 0x4B, 0x15,
  40697. 0x25, 0xA0, 0x76, 0xFF, 0xB8, 0xDD, 0x90, 0x66
  40698. };
  40699. static const byte msg_44[] = {
  40700. 0x3A, 0xFD, 0x7F, 0xF8, 0xCA, 0xD3, 0xAC, 0xBD,
  40701. 0xF9, 0x77, 0x31, 0x26, 0x1C, 0x7A, 0x1C, 0x96,
  40702. 0x9D, 0x50, 0x16, 0xF1, 0x7D, 0x3E, 0x7F, 0x83,
  40703. 0xD2, 0x44, 0x1A, 0xF9, 0x01, 0x4B, 0x63, 0x47,
  40704. 0x7B, 0x14, 0xA6, 0x41, 0x31, 0x50, 0xFA, 0xD7,
  40705. 0xC8, 0x44, 0x39, 0xBC, 0x88, 0x66, 0x2C, 0x5E,
  40706. 0x93, 0x1F, 0x06, 0xB9, 0x51, 0x41, 0x90, 0xE1,
  40707. 0x3F, 0xB0, 0x49, 0xC4, 0xAB, 0x74, 0x01, 0x32,
  40708. 0x33, 0xB9, 0x8D, 0x48, 0xD9, 0xAF, 0xB6, 0xA3,
  40709. 0x0A, 0x67, 0x33, 0x0E, 0x1F, 0xBE, 0x33, 0x1B,
  40710. 0x09, 0xC5, 0x6D, 0x03, 0x7E, 0x97, 0x01, 0x08,
  40711. 0x5D, 0x80, 0xF1, 0xE7, 0xF4, 0x04, 0x3E, 0xFB,
  40712. 0x53, 0x58, 0x7A, 0xBB, 0x82, 0x36, 0x24, 0x01,
  40713. 0x23, 0x84, 0x51, 0x52, 0x49, 0xEE, 0x61, 0x30,
  40714. 0x97, 0x3D, 0xC9, 0xEA, 0x6F, 0x55, 0x8B, 0xAE,
  40715. 0x75, 0x10, 0x7E, 0xFD, 0xB1, 0xD9, 0x28, 0x5B
  40716. };
  40717. static const byte sig_44[] = {
  40718. 0x4A, 0x2B, 0x16, 0xCD, 0xB5, 0x52, 0xF9, 0x29,
  40719. 0x7F, 0x8E, 0x39, 0x1A, 0xD8, 0xF5, 0xAD, 0xC8,
  40720. 0xCC, 0x5D, 0x2C, 0x56, 0xC4, 0x6B, 0x80, 0x0F,
  40721. 0x9B, 0x3E, 0xE4, 0xBB, 0xD2, 0xF2, 0xE8, 0xA8,
  40722. 0x9D, 0x59, 0x9D, 0x7B, 0x5C, 0xC2, 0xD8, 0x8C,
  40723. 0x80, 0xF2, 0x71, 0x85, 0x9B, 0xBC, 0x83, 0x04,
  40724. 0x3E, 0xC4, 0xE5, 0x48, 0x12, 0xF5, 0x93, 0x6B,
  40725. 0x44, 0x6C, 0x95, 0x13, 0xC8, 0x55, 0x28, 0x9C,
  40726. 0x94, 0xB1, 0x15, 0x51, 0xA0, 0xC7, 0x65, 0x3E,
  40727. 0x7B, 0xA7, 0x4F, 0xFB, 0x6F, 0x72, 0xD4, 0x65,
  40728. 0x2C, 0x91, 0xD3, 0x8D, 0xD1, 0xF9, 0x0D, 0xFE,
  40729. 0x44, 0x39, 0xBC, 0x21, 0xCA, 0x53, 0xE0, 0xCC,
  40730. 0x7A, 0x7A, 0xA5, 0xB8, 0x75, 0xA5, 0xB9, 0xBA,
  40731. 0x42, 0x36, 0x6E, 0xB8, 0xEC, 0xBA, 0x24, 0x36,
  40732. 0xDA, 0xF0, 0x8A, 0x91, 0x97, 0x8D, 0xD0, 0x93,
  40733. 0xF2, 0x0F, 0x1E, 0xFB, 0x6B, 0x0B, 0xCB, 0x90,
  40734. 0xDA, 0x99, 0xCC, 0xA0, 0x5E, 0x8F, 0x6F, 0x82,
  40735. 0xB8, 0x6D, 0x3C, 0x6E, 0xE2, 0x4B, 0xA5, 0xD5,
  40736. 0x0A, 0xEA, 0x10, 0xB2, 0x30, 0x7F, 0x57, 0xF8,
  40737. 0x9E, 0xD7, 0x8D, 0xB4, 0xA7, 0x4F, 0xBB, 0xF6,
  40738. 0xEB, 0x33, 0x2A, 0xFB, 0x08, 0xD0, 0x74, 0xAC,
  40739. 0xF0, 0xDE, 0x5C, 0xD7, 0xFE, 0xC1, 0x2F, 0x76,
  40740. 0xF3, 0xAB, 0x61, 0x9C, 0x81, 0x5B, 0x9E, 0xDD,
  40741. 0x28, 0x7E, 0xAD, 0x67, 0xF0, 0x4F, 0x14, 0x79,
  40742. 0x7F, 0x8D, 0xCF, 0x2C, 0xDE, 0x9A, 0x87, 0x53,
  40743. 0xB5, 0xAD, 0x0A, 0xFA, 0x12, 0x87, 0x41, 0x97,
  40744. 0xD1, 0x74, 0x40, 0x92, 0x87, 0x25, 0x21, 0xE8,
  40745. 0x68, 0xAF, 0x9E, 0x64, 0x45, 0x23, 0x73, 0xFE,
  40746. 0xB6, 0xFE, 0x25, 0xD5, 0x27, 0x3D, 0x63, 0xC0,
  40747. 0xEB, 0xD6, 0xD3, 0xB1, 0x02, 0x8C, 0x1C, 0xD0,
  40748. 0x6A, 0xF3, 0x2C, 0xEC, 0xA2, 0x62, 0x13, 0x10,
  40749. 0x83, 0x7C, 0x72, 0x78, 0x8C, 0x8A, 0xDA, 0xB5,
  40750. 0xA0, 0xF0, 0x38, 0x17, 0x12, 0x8E, 0xB7, 0xB7,
  40751. 0x66, 0xFA, 0x81, 0x2C, 0x69, 0x6C, 0xF8, 0x86,
  40752. 0xF0, 0x0A, 0x10, 0x44, 0xCD, 0xD0, 0x6B, 0xB2,
  40753. 0x8C, 0xB2, 0xE5, 0x78, 0x0C, 0x8D, 0x8C, 0xC7,
  40754. 0xE6, 0x0A, 0xB6, 0x99, 0xDD, 0x78, 0x66, 0x8B,
  40755. 0xE4, 0xFF, 0x9F, 0x46, 0x90, 0xC6, 0xFC, 0x98,
  40756. 0xAA, 0xC9, 0xC0, 0x2B, 0x66, 0xB9, 0xB9, 0x82,
  40757. 0x6A, 0x30, 0x61, 0xFD, 0x32, 0x22, 0xDA, 0x84,
  40758. 0x82, 0x66, 0x79, 0x60, 0xA3, 0x16, 0x52, 0xEE,
  40759. 0x88, 0xEB, 0x32, 0xB0, 0x46, 0x9A, 0xB7, 0x1C,
  40760. 0xAA, 0x25, 0x19, 0xF2, 0x3D, 0x1A, 0x24, 0x42,
  40761. 0xD5, 0xB1, 0x31, 0x62, 0x62, 0x13, 0x1D, 0xCE,
  40762. 0xC5, 0xF2, 0x87, 0xE3, 0x2F, 0xD3, 0x43, 0xFE,
  40763. 0xB4, 0x42, 0x9E, 0x54, 0x25, 0x8D, 0x69, 0x0D,
  40764. 0x9D, 0x20, 0xA1, 0x0A, 0xBD, 0x75, 0xA5, 0x36,
  40765. 0xDF, 0xF8, 0xCF, 0x1D, 0x6D, 0xDF, 0x19, 0x29,
  40766. 0x1E, 0x27, 0x49, 0xA7, 0xD1, 0x6E, 0xB9, 0x0A,
  40767. 0xB5, 0x09, 0x3B, 0xAD, 0x38, 0xE1, 0x16, 0xA8,
  40768. 0x6B, 0x73, 0x0E, 0x65, 0x57, 0x4C, 0x06, 0x8C,
  40769. 0x38, 0xBA, 0x94, 0x57, 0xC9, 0xD6, 0xD9, 0x13,
  40770. 0xEA, 0xFF, 0x57, 0xFE, 0x23, 0xBF, 0x3D, 0xD2,
  40771. 0x4D, 0x8C, 0xA5, 0x11, 0xEF, 0xA3, 0x76, 0xA5,
  40772. 0xDF, 0x08, 0x46, 0x70, 0x25, 0xFF, 0x51, 0xBE,
  40773. 0xAD, 0x3E, 0xDE, 0x0A, 0x84, 0xED, 0xC5, 0x32,
  40774. 0x16, 0x20, 0x99, 0x80, 0x61, 0xE8, 0xA1, 0xA7,
  40775. 0x3D, 0x67, 0xB7, 0x02, 0x1B, 0x81, 0x0C, 0x78,
  40776. 0x67, 0xFF, 0x39, 0x18, 0x7B, 0x59, 0xD4, 0x03,
  40777. 0xBF, 0x7C, 0x75, 0x06, 0x30, 0x0C, 0x73, 0x45,
  40778. 0xB1, 0xFE, 0x07, 0xC1, 0x12, 0x78, 0xB0, 0xAB,
  40779. 0xA6, 0x1D, 0xBB, 0x4F, 0x2B, 0x8C, 0x43, 0xE7,
  40780. 0x4F, 0xEF, 0xA5, 0x5E, 0xD5, 0x2C, 0x10, 0xA8,
  40781. 0xC4, 0x90, 0x88, 0x2B, 0xBF, 0xE3, 0xE3, 0xB3,
  40782. 0xCE, 0x57, 0x9E, 0x81, 0x16, 0xA9, 0xB6, 0x68,
  40783. 0x6C, 0x1A, 0x10, 0x0A, 0xA1, 0xF6, 0x59, 0x1F,
  40784. 0x19, 0x1F, 0x77, 0x2B, 0x5A, 0x5A, 0x50, 0xDD,
  40785. 0x6C, 0xC1, 0x55, 0xCB, 0x5A, 0x1B, 0xE5, 0xBA,
  40786. 0x12, 0x2E, 0x91, 0xF0, 0x44, 0x42, 0x01, 0x56,
  40787. 0xCD, 0x63, 0x08, 0x0F, 0x0A, 0x45, 0xD6, 0x62,
  40788. 0xE7, 0x6D, 0xD5, 0x7B, 0xD0, 0xF6, 0x89, 0xD0,
  40789. 0xB2, 0x99, 0x04, 0x2B, 0xFF, 0x48, 0x5E, 0x8A,
  40790. 0x38, 0x2D, 0x86, 0x5C, 0x26, 0xCD, 0x46, 0xB4,
  40791. 0xA5, 0x47, 0x28, 0xBD, 0x48, 0x45, 0x83, 0x62,
  40792. 0xD7, 0x9A, 0xC3, 0xEB, 0x75, 0x6F, 0xC6, 0xC5,
  40793. 0x18, 0xC9, 0xE2, 0xF0, 0xE7, 0xD5, 0xA3, 0x03,
  40794. 0xAF, 0x11, 0x59, 0xEE, 0x6D, 0xBE, 0x7D, 0xD5,
  40795. 0x6B, 0xA0, 0x71, 0x28, 0x57, 0xA6, 0x88, 0x36,
  40796. 0xC3, 0xC7, 0x8C, 0x6C, 0x9F, 0x74, 0x88, 0x57,
  40797. 0x28, 0x13, 0xC0, 0xF6, 0xA8, 0x14, 0x70, 0x9D,
  40798. 0x2B, 0xC1, 0x42, 0xFE, 0xF0, 0x25, 0x27, 0xCA,
  40799. 0xE7, 0x71, 0x23, 0x58, 0x37, 0x1C, 0x54, 0x26,
  40800. 0x52, 0x2C, 0xCC, 0x64, 0x30, 0x0C, 0x2C, 0xD9,
  40801. 0xFB, 0xE2, 0x0C, 0x65, 0x62, 0xE3, 0x48, 0x35,
  40802. 0x20, 0x5F, 0xCD, 0xD5, 0xA8, 0x98, 0x2C, 0x92,
  40803. 0x0B, 0xB4, 0x77, 0xFB, 0x88, 0x17, 0x02, 0x82,
  40804. 0x7B, 0x49, 0x11, 0x87, 0x13, 0x94, 0xC0, 0x6B,
  40805. 0x5F, 0xEC, 0xD0, 0xC7, 0x40, 0xAF, 0x7B, 0x27,
  40806. 0x63, 0x7B, 0xAC, 0x1A, 0x0C, 0xBC, 0xA5, 0x37,
  40807. 0xE4, 0x43, 0x3E, 0xA8, 0x47, 0x45, 0x4C, 0x69,
  40808. 0x38, 0x97, 0xA3, 0x2E, 0x4D, 0x18, 0x44, 0x19,
  40809. 0x54, 0x26, 0xA0, 0xC6, 0xAE, 0xD6, 0x74, 0x72,
  40810. 0xBD, 0x2C, 0x4E, 0xEE, 0x17, 0x9F, 0x3F, 0x60,
  40811. 0x84, 0xA3, 0x6A, 0x76, 0x89, 0xF4, 0xCB, 0x1F,
  40812. 0x8E, 0x5D, 0xB2, 0xDD, 0xE5, 0x4A, 0xCC, 0x06,
  40813. 0x66, 0xBA, 0x98, 0x41, 0x54, 0x31, 0xA4, 0xB2,
  40814. 0x02, 0xF4, 0x02, 0xFB, 0x1F, 0x1B, 0xCC, 0xDC,
  40815. 0x23, 0xBF, 0xF1, 0x31, 0x48, 0xC7, 0xB8, 0xF6,
  40816. 0x1F, 0xBF, 0x62, 0x43, 0xB2, 0x96, 0xA7, 0x8E,
  40817. 0xB6, 0x98, 0x18, 0x9D, 0xA9, 0x5B, 0xDA, 0x85,
  40818. 0xDB, 0xC1, 0x1D, 0x15, 0xFF, 0xDC, 0x6B, 0xF4,
  40819. 0x6C, 0x53, 0xF6, 0xE4, 0x72, 0xA8, 0x71, 0x40,
  40820. 0x1E, 0x9A, 0x9A, 0xB7, 0xF9, 0xFB, 0x46, 0x7E,
  40821. 0xB4, 0xEC, 0xB1, 0xF0, 0xDA, 0x7E, 0x63, 0xEE,
  40822. 0x86, 0x19, 0xCB, 0xC4, 0x86, 0xEB, 0xB0, 0xF2,
  40823. 0x12, 0x0A, 0x78, 0x11, 0xBF, 0xB0, 0x55, 0x7D,
  40824. 0x13, 0x93, 0x05, 0x74, 0x29, 0x7C, 0x94, 0x64,
  40825. 0xFC, 0x59, 0x5B, 0x27, 0x56, 0x9A, 0xDF, 0x5F,
  40826. 0x4A, 0x8D, 0xF6, 0x69, 0xC9, 0xEE, 0xA0, 0xA2,
  40827. 0x50, 0xF4, 0xD2, 0x2C, 0x2E, 0x8C, 0x64, 0x1B,
  40828. 0xA3, 0x90, 0x2B, 0xA8, 0x08, 0x00, 0x48, 0x99,
  40829. 0x65, 0xF1, 0x1A, 0xF1, 0xE1, 0xA8, 0x57, 0x17,
  40830. 0xC6, 0x24, 0xE7, 0x42, 0xF1, 0x61, 0x55, 0x08,
  40831. 0x19, 0xD1, 0xF0, 0x37, 0x2C, 0x5C, 0xAE, 0x8B,
  40832. 0xC6, 0x2B, 0x54, 0x9E, 0xFE, 0x87, 0x44, 0x61,
  40833. 0x08, 0x0D, 0x06, 0x34, 0x6E, 0x1F, 0xA6, 0xF0,
  40834. 0x15, 0x14, 0xFB, 0xEC, 0xCB, 0x06, 0xE3, 0x4E,
  40835. 0xE2, 0x71, 0xA0, 0xF0, 0x03, 0x17, 0x90, 0xBD,
  40836. 0xAB, 0xE0, 0xF0, 0x2B, 0xBA, 0x4A, 0xEA, 0x4B,
  40837. 0x73, 0x97, 0xFE, 0x33, 0x33, 0xEB, 0x81, 0x21,
  40838. 0x82, 0x07, 0x57, 0x28, 0x1F, 0x96, 0xA5, 0x83,
  40839. 0x1F, 0x9E, 0x49, 0x03, 0x66, 0x54, 0x9D, 0x16,
  40840. 0x76, 0x3F, 0xF1, 0x9F, 0xF7, 0x73, 0x58, 0x0E,
  40841. 0xD5, 0xE3, 0xE1, 0xE2, 0xAA, 0x3E, 0x38, 0xF8,
  40842. 0x84, 0x74, 0xDE, 0x6D, 0x9B, 0xA6, 0x99, 0x4F,
  40843. 0x8E, 0x62, 0x91, 0x60, 0x48, 0x8C, 0xB4, 0xCD,
  40844. 0x5B, 0x87, 0x8C, 0xDA, 0x37, 0xAA, 0xEC, 0x9B,
  40845. 0x56, 0x36, 0x9A, 0x7E, 0x73, 0xF7, 0x3B, 0x42,
  40846. 0x86, 0x39, 0xA0, 0x5C, 0x13, 0x78, 0x44, 0x8A,
  40847. 0xDB, 0x7F, 0x07, 0x4D, 0xC8, 0x15, 0x4D, 0x92,
  40848. 0xE1, 0x3C, 0x63, 0x56, 0xB5, 0xF4, 0x66, 0xD6,
  40849. 0x64, 0x77, 0x15, 0x9B, 0x2A, 0x94, 0x37, 0x99,
  40850. 0xAD, 0x61, 0x9A, 0x02, 0x9F, 0x30, 0x10, 0xD0,
  40851. 0x37, 0x67, 0x2D, 0xBB, 0x68, 0x20, 0xE5, 0x13,
  40852. 0x23, 0xAD, 0xA9, 0x88, 0x81, 0xC6, 0xDE, 0x85,
  40853. 0x9D, 0xF8, 0x75, 0xAB, 0xAF, 0x11, 0xDA, 0x5D,
  40854. 0xDC, 0xA5, 0xA7, 0x77, 0x62, 0x2B, 0xDA, 0xE8,
  40855. 0xFA, 0xCE, 0x2E, 0x0C, 0xED, 0x3B, 0x6A, 0x77,
  40856. 0xB8, 0x8A, 0x87, 0x29, 0xFB, 0x7C, 0x50, 0x93,
  40857. 0x3D, 0xA6, 0xC5, 0x2E, 0x3F, 0x4D, 0x94, 0x8F,
  40858. 0x9D, 0xC1, 0x53, 0xB5, 0xB1, 0x29, 0x9C, 0xD8,
  40859. 0x62, 0x1D, 0xDF, 0xBA, 0x48, 0xAF, 0x44, 0xE4,
  40860. 0xB6, 0xF6, 0x10, 0x6E, 0xE7, 0x77, 0x95, 0x01,
  40861. 0xDD, 0x5F, 0xB3, 0xC5, 0x78, 0xEA, 0x4D, 0x32,
  40862. 0xC5, 0xC2, 0xF0, 0x36, 0xA7, 0x35, 0x27, 0x03,
  40863. 0xAD, 0xD1, 0x35, 0xAB, 0x84, 0x46, 0x01, 0x62,
  40864. 0x41, 0x7E, 0x50, 0xBF, 0x91, 0xE6, 0x07, 0x97,
  40865. 0xD5, 0x9B, 0x9E, 0x18, 0xD3, 0x24, 0xDA, 0x97,
  40866. 0x1F, 0x4F, 0xF4, 0x28, 0xAE, 0xAF, 0x23, 0xAC,
  40867. 0x0B, 0xA4, 0xE2, 0xE2, 0xFC, 0x7A, 0xBA, 0xA6,
  40868. 0xC8, 0x98, 0x4F, 0xE9, 0xE2, 0xD8, 0x5B, 0x8A,
  40869. 0xDA, 0x40, 0x86, 0xB3, 0xC1, 0x3A, 0xBD, 0x43,
  40870. 0xCF, 0xD1, 0xC7, 0x11, 0xD8, 0x32, 0x6B, 0x18,
  40871. 0xAD, 0xC3, 0x4C, 0xC1, 0x4C, 0xF8, 0x95, 0x7E,
  40872. 0xC3, 0x95, 0x94, 0x98, 0xFC, 0x2A, 0x7B, 0xE0,
  40873. 0x6B, 0xD1, 0x84, 0x0D, 0xE1, 0x70, 0x36, 0x65,
  40874. 0x66, 0xE5, 0x07, 0x41, 0x95, 0x77, 0x63, 0xC2,
  40875. 0xDD, 0x27, 0xAC, 0xF8, 0xC3, 0xF1, 0x02, 0x6F,
  40876. 0xAE, 0xE1, 0xD2, 0x56, 0x2F, 0xA1, 0x05, 0x2E,
  40877. 0x69, 0xAF, 0xDD, 0x42, 0xF4, 0x46, 0xF0, 0x59,
  40878. 0x88, 0x66, 0xD5, 0xD3, 0x06, 0xBF, 0x1B, 0x77,
  40879. 0x50, 0x42, 0xB0, 0x35, 0x92, 0x73, 0x72, 0x82,
  40880. 0x7F, 0x43, 0x86, 0x31, 0x65, 0x34, 0xFA, 0x1B,
  40881. 0x7E, 0xE6, 0x33, 0xBA, 0x95, 0x8C, 0xED, 0x8F,
  40882. 0x0D, 0x24, 0x1D, 0x46, 0x88, 0xE3, 0xC7, 0x91,
  40883. 0x8E, 0x2A, 0x75, 0x62, 0x63, 0x77, 0xC3, 0x42,
  40884. 0xA5, 0x90, 0x69, 0x2B, 0xBF, 0xB8, 0x27, 0xBF,
  40885. 0x90, 0x51, 0x41, 0x82, 0xD4, 0x09, 0x0D, 0xF8,
  40886. 0xD7, 0x32, 0x35, 0x19, 0xA1, 0xAB, 0x6C, 0xD0,
  40887. 0x22, 0x73, 0x67, 0x41, 0x0D, 0xD1, 0x4D, 0x37,
  40888. 0x86, 0xA2, 0x6D, 0xDF, 0x91, 0x72, 0x4F, 0xC8,
  40889. 0x2D, 0x06, 0xA2, 0x5D, 0x5F, 0x56, 0x68, 0x39,
  40890. 0x53, 0xE8, 0xE0, 0xF2, 0x0E, 0x3C, 0x17, 0x71,
  40891. 0xDA, 0xF4, 0x2E, 0x52, 0x02, 0x4C, 0x11, 0x6E,
  40892. 0xD8, 0xA4, 0xC0, 0xA6, 0x11, 0x68, 0x0F, 0x5F,
  40893. 0xE0, 0x0E, 0xD9, 0xB1, 0x48, 0xD1, 0x5F, 0x12,
  40894. 0xAA, 0x95, 0xB9, 0xBD, 0x5A, 0x9F, 0xD8, 0x10,
  40895. 0x16, 0x42, 0xB3, 0x69, 0x11, 0xF3, 0x10, 0xB0,
  40896. 0xDE, 0x18, 0x17, 0x1D, 0x62, 0x37, 0xD9, 0xBE,
  40897. 0x17, 0x25, 0xDC, 0x29, 0x9A, 0x1A, 0x3A, 0xAA,
  40898. 0xE9, 0x85, 0x40, 0xCE, 0xED, 0x26, 0x95, 0x3D,
  40899. 0x10, 0xCE, 0x85, 0x47, 0xF1, 0xC3, 0xE4, 0x6A,
  40900. 0x86, 0x2B, 0xED, 0x42, 0x8D, 0x1E, 0x10, 0x60,
  40901. 0x1B, 0xF3, 0x28, 0xC7, 0x27, 0xFD, 0x95, 0x34,
  40902. 0x3E, 0x2D, 0xB4, 0xD9, 0xAC, 0xD5, 0xD1, 0xCB,
  40903. 0x47, 0x15, 0xF6, 0x00, 0x40, 0x96, 0xED, 0xA0,
  40904. 0x93, 0xD1, 0xB0, 0xA3, 0x3B, 0x1E, 0x56, 0xF1,
  40905. 0x6D, 0x73, 0xAD, 0xB8, 0x73, 0x2C, 0xB4, 0xA3,
  40906. 0x11, 0x60, 0xA4, 0x49, 0x1F, 0xAA, 0x0C, 0x86,
  40907. 0xE6, 0x80, 0xE3, 0xD7, 0xC0, 0x2C, 0xCE, 0xA8,
  40908. 0xFE, 0x92, 0xF1, 0xE0, 0x01, 0x01, 0x6D, 0x22,
  40909. 0x02, 0x21, 0xDD, 0x10, 0xED, 0x62, 0x60, 0x17,
  40910. 0x96, 0x6C, 0x34, 0x50, 0xAD, 0x12, 0x13, 0x65,
  40911. 0x91, 0x8C, 0x93, 0x09, 0x1F, 0x14, 0x71, 0x2B,
  40912. 0xA4, 0x77, 0xCF, 0x2E, 0x26, 0x32, 0x96, 0xC7,
  40913. 0x78, 0xA2, 0xBA, 0xEE, 0xF5, 0x84, 0x94, 0x55,
  40914. 0xFA, 0x35, 0xCB, 0x61, 0x72, 0x51, 0xE0, 0x2A,
  40915. 0x22, 0xDA, 0xF5, 0xC3, 0x3E, 0x5A, 0xAA, 0x9F,
  40916. 0x00, 0xE8, 0xAC, 0xDC, 0x50, 0xEC, 0xF4, 0x7C,
  40917. 0x52, 0x15, 0x03, 0xC5, 0x2F, 0x27, 0xD6, 0xB5,
  40918. 0x7C, 0x8F, 0x2B, 0x3D, 0x8F, 0x12, 0x22, 0x41,
  40919. 0x3E, 0x7F, 0xA4, 0xEC, 0x59, 0x29, 0x63, 0x38,
  40920. 0x09, 0x8C, 0x9A, 0xB5, 0xA1, 0xD8, 0xA5, 0x78,
  40921. 0x84, 0xBD, 0x86, 0x00, 0x41, 0x40, 0x6D, 0x96,
  40922. 0x55, 0xD1, 0x73, 0x82, 0x94, 0x9A, 0x03, 0xD5,
  40923. 0x0F, 0x11, 0x08, 0xD0, 0x5B, 0xDB, 0x31, 0xCA,
  40924. 0x08, 0xE6, 0x6F, 0x2D, 0x8D, 0xE4, 0x80, 0xC6,
  40925. 0x79, 0x35, 0x18, 0xD4, 0x9A, 0x60, 0xD4, 0x76,
  40926. 0x2A, 0x9E, 0xDD, 0xC0, 0x24, 0x9B, 0x42, 0x2E,
  40927. 0x84, 0x02, 0x0E, 0xD5, 0x39, 0xA1, 0x4E, 0x24,
  40928. 0x78, 0xF6, 0x8B, 0xAB, 0x1F, 0x2B, 0x00, 0xE2,
  40929. 0x2A, 0x5C, 0xBB, 0x62, 0x97, 0x9A, 0xC7, 0x44,
  40930. 0xE0, 0x8B, 0x57, 0xD5, 0xB5, 0x78, 0xC4, 0x01,
  40931. 0xA8, 0xD2, 0x6D, 0x9A, 0xDD, 0x15, 0x05, 0x23,
  40932. 0x60, 0x82, 0x86, 0x36, 0x72, 0xD9, 0x11, 0xCF,
  40933. 0x3A, 0x09, 0x66, 0xD3, 0x03, 0xF8, 0x91, 0x70,
  40934. 0x93, 0xBF, 0x97, 0xAF, 0x90, 0xA7, 0xE1, 0xF9,
  40935. 0xD5, 0x9B, 0x09, 0x20, 0x6B, 0x9C, 0xAC, 0x35,
  40936. 0x11, 0x0F, 0xA3, 0x8D, 0x58, 0x90, 0xED, 0x21,
  40937. 0x16, 0x83, 0x5C, 0xE3, 0x73, 0x84, 0xF5, 0x63,
  40938. 0x0F, 0x1C, 0x42, 0x8E, 0x21, 0x36, 0x05, 0x87,
  40939. 0x2E, 0xCF, 0x91, 0x1B, 0x01, 0x4B, 0x91, 0xC2,
  40940. 0xC6, 0x00, 0xE8, 0xA4, 0x07, 0x29, 0xD0, 0x7B,
  40941. 0xF9, 0x18, 0x79, 0x07, 0x42, 0xC9, 0x27, 0x9F,
  40942. 0x31, 0x14, 0xF6, 0x8C, 0xDF, 0x65, 0x94, 0xCD,
  40943. 0xA3, 0xCA, 0x66, 0x94, 0x22, 0x3A, 0x82, 0xF6,
  40944. 0x6C, 0x2B, 0x4B, 0xDF, 0x3E, 0x51, 0xC6, 0xFF,
  40945. 0xDC, 0x55, 0xE0, 0xFF, 0x51, 0xEF, 0xD6, 0xC9,
  40946. 0x34, 0x36, 0x2B, 0xE7, 0xD6, 0xFA, 0xBC, 0x11,
  40947. 0xB8, 0xB0, 0xDA, 0xDD, 0xD5, 0x21, 0x08, 0xFA,
  40948. 0x5F, 0xB5, 0xCA, 0x75, 0x8A, 0x64, 0x37, 0x7D,
  40949. 0x38, 0x6D, 0x45, 0xCE, 0x70, 0x60, 0x5B, 0x46,
  40950. 0x0E, 0x81, 0x57, 0x03, 0x7B, 0x5B, 0x1B, 0x2E,
  40951. 0x0A, 0xED, 0xD1, 0x2A, 0x63, 0x31, 0x15, 0xD6,
  40952. 0xC4, 0x3B, 0xC6, 0xC7, 0xC8, 0x36, 0xFF, 0xF3,
  40953. 0x3E, 0x7D, 0x03, 0x3F, 0x2E, 0x58, 0x00, 0x52,
  40954. 0x71, 0x64, 0xC0, 0xC4, 0x78, 0x1C, 0x37, 0xDF,
  40955. 0x50, 0xB6, 0x6B, 0xBA, 0x5C, 0x81, 0x94, 0x73,
  40956. 0xA1, 0xC5, 0x30, 0x20, 0x83, 0xA1, 0x6F, 0x01,
  40957. 0x43, 0x72, 0x79, 0xD2, 0xF2, 0xDF, 0x14, 0xC8,
  40958. 0x78, 0x26, 0x9A, 0x2F, 0x3F, 0xA4, 0x0C, 0x1C,
  40959. 0x76, 0x1E, 0xD6, 0x15, 0x01, 0xAC, 0x9E, 0xF1,
  40960. 0x41, 0x02, 0x90, 0x38, 0xC8, 0x19, 0x95, 0x40,
  40961. 0x89, 0xB7, 0x38, 0x09, 0x87, 0x08, 0x17, 0x43,
  40962. 0x93, 0xFE, 0xAE, 0xA7, 0xB0, 0x2A, 0xE5, 0xCE,
  40963. 0xF6, 0x7B, 0x3C, 0x8C, 0xE6, 0xA9, 0x70, 0x67,
  40964. 0x5C, 0xA1, 0xB8, 0xC8, 0x56, 0xDC, 0xF5, 0x97,
  40965. 0x25, 0x08, 0xC7, 0xC6, 0xB2, 0x5E, 0xE4, 0xD1,
  40966. 0x2D, 0x82, 0x12, 0xB9, 0x89, 0x40, 0xB4, 0x88,
  40967. 0xEC, 0x40, 0x2A, 0xC7, 0xAE, 0x3C, 0x70, 0xDF,
  40968. 0x93, 0x8D, 0x12, 0x88, 0xCD, 0xA7, 0xA3, 0x19,
  40969. 0xE0, 0x85, 0xBC, 0x73, 0xA4, 0x69, 0xB2, 0xD2,
  40970. 0xA3, 0x30, 0x3B, 0x11, 0xA6, 0x83, 0x10, 0x0A,
  40971. 0xF6, 0xDB, 0x86, 0x93, 0x7B, 0xA1, 0x18, 0x29,
  40972. 0x03, 0x61, 0x6E, 0x3F, 0x03, 0x47, 0xBD, 0x68,
  40973. 0x59, 0x1B, 0x47, 0xBA, 0x65, 0x15, 0x6B, 0x93,
  40974. 0xF2, 0x60, 0xDE, 0x59, 0xB3, 0xAE, 0xB2, 0x89,
  40975. 0xE2, 0xA7, 0x3A, 0x3B, 0xFF, 0x38, 0xC2, 0xF3,
  40976. 0xAD, 0xED, 0xA2, 0x9C, 0x7E, 0x90, 0x28, 0x3A,
  40977. 0xC7, 0xB8, 0x6D, 0x03, 0x6B, 0x47, 0xD5, 0xBA,
  40978. 0x1A, 0x03, 0xEC, 0x78, 0x3D, 0x25, 0x0B, 0xAC,
  40979. 0xAE, 0x58, 0x47, 0xE4, 0x1F, 0x82, 0x9C, 0xB3,
  40980. 0x3D, 0xE0, 0x8D, 0xF8, 0xF7, 0xD6, 0x9C, 0x9A,
  40981. 0xA4, 0xED, 0xE8, 0xD7, 0xAB, 0x96, 0x84, 0x07,
  40982. 0xEE, 0xD3, 0x1A, 0x05, 0x6B, 0xA0, 0xEF, 0x88,
  40983. 0x16, 0xE1, 0x27, 0xAA, 0x90, 0x06, 0x5A, 0x67,
  40984. 0x9E, 0x1C, 0xA9, 0x55, 0x0D, 0xEE, 0xF2, 0x5A,
  40985. 0xC5, 0xB7, 0xA3, 0x4F, 0x70, 0xDC, 0xF2, 0xB1,
  40986. 0x16, 0xCF, 0x35, 0x1F, 0x3B, 0xAD, 0xA9, 0x9F,
  40987. 0x83, 0x6C, 0x73, 0x0D, 0xCC, 0x1A, 0xE0, 0x3F,
  40988. 0x49, 0x6C, 0xF3, 0xF0, 0x38, 0x7A, 0x0C, 0x2C,
  40989. 0x70, 0x2E, 0x2C, 0x13, 0xBD, 0xD9, 0xCF, 0x45,
  40990. 0xA1, 0xCD, 0x53, 0xAB, 0x58, 0x73, 0x11, 0x88,
  40991. 0xB1, 0x8E, 0xA8, 0xBE, 0x48, 0xD5, 0x10, 0xC5,
  40992. 0x81, 0x2E, 0x90, 0xBC, 0xEC, 0xBC, 0x6E, 0x19,
  40993. 0x8E, 0x70, 0x8B, 0x1C, 0x08, 0xC8, 0xF8, 0x64,
  40994. 0xB1, 0x24, 0xBB, 0x4C, 0xC0, 0xBD, 0xBB, 0xDF,
  40995. 0x2C, 0x2F, 0x4E, 0x38, 0x8F, 0xC1, 0x96, 0x60,
  40996. 0xD6, 0x9C, 0xC2, 0xC0, 0xEB, 0xF9, 0x10, 0x08,
  40997. 0xC8, 0x24, 0x3D, 0xB4, 0x2D, 0xDA, 0xF5, 0x7C,
  40998. 0x02, 0x42, 0x51, 0xC4, 0x23, 0x1D, 0xF5, 0x37,
  40999. 0x90, 0xCE, 0x57, 0x56, 0x13, 0xEE, 0x8E, 0x1C,
  41000. 0x7A, 0x33, 0xC1, 0x56, 0x1F, 0x35, 0x04, 0xDE,
  41001. 0xAA, 0xED, 0x1E, 0x84, 0x08, 0x50, 0x06, 0x23,
  41002. 0xEC, 0xA5, 0xAE, 0x5A, 0x28, 0x45, 0x41, 0x17,
  41003. 0x49, 0x93, 0x0D, 0x8E, 0x42, 0x07, 0x8C, 0x03,
  41004. 0x23, 0x49, 0x95, 0x7F, 0xC3, 0x9A, 0x1D, 0xA0,
  41005. 0xEA, 0xF9, 0xE8, 0x7C, 0x31, 0xFF, 0xBF, 0x6A,
  41006. 0xC0, 0xC1, 0x81, 0x1E, 0xB2, 0x8A, 0x41, 0xB1,
  41007. 0xD8, 0x6B, 0xD7, 0xD4, 0x9A, 0xD1, 0xC4, 0x68,
  41008. 0xA4, 0x95, 0x94, 0x95, 0x65, 0x25, 0xA2, 0x0A,
  41009. 0x31, 0x70, 0x0F, 0x12, 0x2F, 0x4C, 0x4B, 0xB2,
  41010. 0x25, 0x2A, 0x2F, 0x3D, 0x5C, 0x5D, 0x68, 0x73,
  41011. 0x83, 0x8C, 0x90, 0x95, 0x97, 0xBB, 0xCA, 0xD8,
  41012. 0xE1, 0x33, 0x3D, 0x5D, 0x61, 0x7C, 0x87, 0xC8,
  41013. 0xEE, 0x0F, 0x1B, 0x22, 0x38, 0x3B, 0x42, 0x4B,
  41014. 0x4C, 0x5C, 0x62, 0x72, 0x98, 0xA3, 0xBE, 0xCC,
  41015. 0x1B, 0x32, 0x47, 0x5C, 0x9D, 0xB6, 0xB9, 0xBD,
  41016. 0xC6, 0xD6, 0xDC, 0xF5, 0x00, 0x00, 0x00, 0x00,
  41017. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41018. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41019. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41020. 0x11, 0x19, 0x28, 0x34
  41021. };
  41022. #endif
  41023. #ifndef WOLFSSL_NO_ML_DSA_65
  41024. static const byte pk_65[] = {
  41025. 0x6C, 0x9E, 0x7A, 0x1E, 0xE3, 0x66, 0x25, 0x76,
  41026. 0x0E, 0x5D, 0x2F, 0x33, 0xDF, 0x29, 0x29, 0xDA,
  41027. 0x56, 0x20, 0x32, 0x34, 0x06, 0x91, 0x60, 0xE5,
  41028. 0xF2, 0xBF, 0x03, 0x9C, 0x11, 0x06, 0x22, 0x73,
  41029. 0x07, 0x3C, 0x23, 0x75, 0x66, 0xCE, 0x05, 0x5D,
  41030. 0x87, 0x1F, 0x38, 0xAC, 0xD1, 0xA9, 0x85, 0x9A,
  41031. 0x82, 0x44, 0x67, 0xF1, 0x9B, 0xE6, 0x8E, 0x4F,
  41032. 0x00, 0x64, 0x5D, 0x22, 0x5C, 0x42, 0xC8, 0x5A,
  41033. 0x55, 0x7D, 0x2C, 0x5E, 0xCB, 0x44, 0x2B, 0x0F,
  41034. 0x02, 0x8A, 0x65, 0x28, 0x89, 0x8E, 0xE2, 0xB6,
  41035. 0x73, 0xD8, 0x63, 0xF3, 0x2E, 0xB9, 0xEC, 0x81,
  41036. 0x64, 0x12, 0x75, 0x41, 0xF3, 0x25, 0x19, 0xBB,
  41037. 0x88, 0xE0, 0x34, 0xA0, 0x3F, 0x46, 0xF7, 0xD1,
  41038. 0x93, 0xCD, 0x3D, 0xFB, 0xAD, 0xF6, 0x35, 0x57,
  41039. 0x92, 0x6C, 0x5C, 0x8F, 0x5B, 0x76, 0x6A, 0x7F,
  41040. 0xC5, 0xEC, 0x8B, 0x3F, 0x94, 0x8B, 0xF7, 0xA8,
  41041. 0x21, 0xB5, 0x4C, 0x94, 0x41, 0xAB, 0x0B, 0xD8,
  41042. 0x33, 0xFD, 0x63, 0x54, 0xCE, 0xC7, 0x06, 0xFA,
  41043. 0xA5, 0x00, 0xAB, 0xB5, 0x28, 0x9B, 0x90, 0xB1,
  41044. 0xBF, 0x91, 0x76, 0x77, 0xA2, 0x9D, 0x11, 0x5F,
  41045. 0x00, 0x94, 0xBD, 0xB4, 0x8D, 0xC7, 0x2E, 0x26,
  41046. 0x1D, 0xBA, 0x12, 0x0B, 0xA6, 0xFF, 0x5E, 0x52,
  41047. 0xA0, 0x1B, 0x17, 0x89, 0x81, 0xDD, 0x82, 0x96,
  41048. 0x44, 0x46, 0x56, 0xD9, 0x44, 0x2D, 0xF9, 0xCB,
  41049. 0xB6, 0xBF, 0xDA, 0xE5, 0x6A, 0x23, 0x0F, 0x6F,
  41050. 0x29, 0xF9, 0x4C, 0xDC, 0xC2, 0x65, 0x57, 0x6A,
  41051. 0xA8, 0x75, 0x2A, 0xCE, 0xD0, 0x7E, 0x99, 0x89,
  41052. 0x5C, 0xAE, 0xF0, 0x16, 0x8B, 0xF8, 0x3D, 0x23,
  41053. 0xFD, 0xAD, 0xFB, 0xB9, 0x28, 0xCB, 0xCD, 0xAB,
  41054. 0xA2, 0x5F, 0xE2, 0xCD, 0x26, 0xAD, 0xDF, 0xB0,
  41055. 0xDA, 0xCD, 0x74, 0x94, 0x0F, 0x35, 0x14, 0x26,
  41056. 0x94, 0x2F, 0x17, 0x6F, 0xFB, 0xC5, 0xF3, 0x45,
  41057. 0x6D, 0xB7, 0xC9, 0x12, 0xAA, 0x16, 0xB8, 0x6D,
  41058. 0x07, 0x45, 0xF8, 0x7C, 0x9F, 0x45, 0x37, 0x0A,
  41059. 0x84, 0x56, 0xA1, 0xAD, 0xB5, 0x1D, 0xB4, 0x05,
  41060. 0x2B, 0x5C, 0x9E, 0xAF, 0x60, 0xAD, 0x7B, 0x80,
  41061. 0xA4, 0x2E, 0xA4, 0xBF, 0x92, 0xC8, 0x41, 0x27,
  41062. 0x3A, 0xD7, 0x61, 0xDE, 0xDB, 0x0D, 0x34, 0xBF,
  41063. 0x57, 0x96, 0x00, 0xB1, 0x49, 0xFC, 0xCD, 0x42,
  41064. 0xAB, 0x15, 0x49, 0xBA, 0x0A, 0xBE, 0xDA, 0x57,
  41065. 0xEF, 0x71, 0xD1, 0xFC, 0xA5, 0x70, 0x2A, 0xAD,
  41066. 0x08, 0x32, 0x99, 0xBB, 0x98, 0x30, 0x01, 0x89,
  41067. 0xC2, 0x5F, 0x3B, 0x27, 0x0A, 0x87, 0x65, 0x8D,
  41068. 0x0B, 0x2E, 0xA5, 0x65, 0x24, 0x14, 0x7F, 0x73,
  41069. 0x9E, 0xB6, 0xC6, 0x76, 0xD7, 0xBE, 0x73, 0xDD,
  41070. 0x3B, 0x95, 0xB1, 0x0C, 0x55, 0xAB, 0x46, 0xFD,
  41071. 0x01, 0x54, 0x9C, 0x51, 0x68, 0xBF, 0x7D, 0xA1,
  41072. 0x3A, 0x49, 0x97, 0x85, 0xF3, 0x5A, 0x1E, 0x3B,
  41073. 0x56, 0xF4, 0xC5, 0x67, 0xF5, 0x4E, 0xA9, 0xAA,
  41074. 0x28, 0x17, 0xA3, 0x36, 0x38, 0x36, 0x43, 0xFA,
  41075. 0x2E, 0xA3, 0x1F, 0xB1, 0xB7, 0x3E, 0x10, 0x24,
  41076. 0x8D, 0xFC, 0xA0, 0x5C, 0x04, 0x13, 0x12, 0x66,
  41077. 0x49, 0x8E, 0x1C, 0x94, 0x91, 0x13, 0x5A, 0x50,
  41078. 0xE6, 0x3D, 0x02, 0xFA, 0xDF, 0x41, 0x65, 0xFC,
  41079. 0x9E, 0x15, 0xE3, 0xE1, 0xB3, 0x2F, 0xAB, 0x83,
  41080. 0x37, 0x68, 0x4C, 0x49, 0x19, 0x3E, 0x1B, 0xC4,
  41081. 0xED, 0xEA, 0xE3, 0x73, 0xA2, 0x67, 0xA7, 0x14,
  41082. 0xAC, 0x1F, 0x90, 0x9C, 0xC6, 0x57, 0xCD, 0x80,
  41083. 0x66, 0x64, 0x63, 0x27, 0xE0, 0xEE, 0xA0, 0x41,
  41084. 0xAC, 0x9F, 0x2A, 0xEF, 0xFC, 0x80, 0x69, 0x1B,
  41085. 0xF6, 0x0D, 0x3C, 0x94, 0xC6, 0x42, 0x55, 0x7E,
  41086. 0x42, 0x99, 0xD3, 0x95, 0x92, 0x22, 0x16, 0xC6,
  41087. 0x5E, 0x75, 0xB7, 0xE1, 0xA5, 0x02, 0x89, 0x60,
  41088. 0x38, 0x4B, 0xF8, 0x16, 0xC9, 0xF7, 0x05, 0x48,
  41089. 0x29, 0xE7, 0x98, 0x5B, 0x58, 0x41, 0xA7, 0x33,
  41090. 0xF3, 0x3F, 0xCE, 0x24, 0x55, 0xEF, 0xC8, 0x9B,
  41091. 0xAE, 0x84, 0xB4, 0x79, 0x90, 0xE8, 0xD0, 0xAF,
  41092. 0xC6, 0x19, 0x3E, 0x4A, 0xF9, 0xBC, 0x68, 0x0A,
  41093. 0xE2, 0x4F, 0xE5, 0x91, 0xE8, 0x8B, 0xA6, 0xA2,
  41094. 0xAE, 0x12, 0xDA, 0x38, 0x58, 0xD2, 0x1F, 0x49,
  41095. 0x2D, 0x24, 0xAB, 0xC4, 0xFE, 0x4F, 0xD5, 0x2D,
  41096. 0x5A, 0xBF, 0x24, 0xBD, 0x25, 0x46, 0x87, 0xB9,
  41097. 0x18, 0x79, 0x2F, 0x0A, 0x00, 0x3A, 0x52, 0x22,
  41098. 0xDF, 0x45, 0x03, 0x86, 0x85, 0xC7, 0x25, 0xCE,
  41099. 0x75, 0x79, 0xE0, 0x2C, 0xB1, 0x68, 0xBB, 0xC6,
  41100. 0x66, 0xAB, 0xF6, 0x69, 0x85, 0x6E, 0x10, 0x53,
  41101. 0x7C, 0x92, 0x91, 0x69, 0x2C, 0x0C, 0xB0, 0xCF,
  41102. 0xA9, 0x06, 0x27, 0x0A, 0xC2, 0xC7, 0xB7, 0xDC,
  41103. 0x31, 0xD4, 0xF9, 0x28, 0x3C, 0xB2, 0xDB, 0x8A,
  41104. 0x46, 0x2A, 0xEC, 0x0B, 0x98, 0x07, 0xBB, 0xF4,
  41105. 0xAB, 0x45, 0x76, 0xFE, 0xC6, 0x22, 0x6B, 0x41,
  41106. 0x79, 0x32, 0x2B, 0x67, 0xAE, 0xA5, 0x3B, 0xDD,
  41107. 0xF9, 0xC9, 0xBE, 0x5E, 0x0D, 0xBC, 0x43, 0xF7,
  41108. 0x87, 0x43, 0x06, 0x8A, 0xB5, 0xBE, 0x49, 0xF0,
  41109. 0xE6, 0x2F, 0x8E, 0x2E, 0xB1, 0xB6, 0xC6, 0x73,
  41110. 0x6C, 0x05, 0xC9, 0x41, 0x3D, 0x06, 0x5C, 0xE0,
  41111. 0xCC, 0xB7, 0x90, 0x54, 0x80, 0x41, 0xD7, 0xE8,
  41112. 0x32, 0x88, 0x1A, 0x83, 0x9B, 0x57, 0x29, 0xAF,
  41113. 0x94, 0xAB, 0x79, 0xFD, 0x8A, 0x16, 0xDF, 0xFF,
  41114. 0x78, 0xCA, 0xAA, 0x14, 0x1D, 0x97, 0xCC, 0x06,
  41115. 0x50, 0xF8, 0x62, 0x62, 0xF2, 0x61, 0x59, 0xBE,
  41116. 0x8B, 0x36, 0x1A, 0x4A, 0x04, 0x1E, 0x9A, 0x0B,
  41117. 0x65, 0x11, 0xBB, 0xE3, 0x35, 0x5A, 0x4B, 0xF5,
  41118. 0x7A, 0xC0, 0x98, 0x48, 0x84, 0x7E, 0xE0, 0x24,
  41119. 0x3C, 0x3B, 0xA7, 0x74, 0x77, 0x6F, 0x7E, 0x9A,
  41120. 0x22, 0x72, 0x75, 0xD7, 0x4E, 0x6E, 0x31, 0x01,
  41121. 0xD3, 0x82, 0x81, 0x87, 0x63, 0xED, 0x1E, 0x13,
  41122. 0x53, 0xAB, 0x9E, 0xEC, 0xCD, 0x92, 0x0C, 0xD2,
  41123. 0x89, 0x22, 0xD5, 0x59, 0xA4, 0x04, 0x8F, 0x40,
  41124. 0xF0, 0x62, 0x16, 0x4C, 0xB6, 0x61, 0xC4, 0xF4,
  41125. 0xAF, 0xA8, 0x1A, 0x3D, 0x55, 0x93, 0x3C, 0x47,
  41126. 0x91, 0xED, 0xDA, 0xA3, 0x93, 0x9E, 0x5A, 0xC3,
  41127. 0x42, 0xB0, 0xAD, 0x1F, 0x43, 0x8A, 0x53, 0x2C,
  41128. 0x6C, 0xE7, 0x86, 0x68, 0x1A, 0x87, 0x0D, 0x94,
  41129. 0xEC, 0x88, 0xA3, 0x34, 0xCC, 0xEF, 0xC6, 0xAC,
  41130. 0xE7, 0xD9, 0x88, 0xA1, 0xA8, 0x2B, 0xC0, 0xAC,
  41131. 0xCE, 0x78, 0x5F, 0x12, 0x3B, 0xE2, 0x3A, 0x7C,
  41132. 0x92, 0xAF, 0x10, 0x8E, 0x5E, 0xD4, 0xF0, 0x86,
  41133. 0x9E, 0x22, 0xDA, 0xE2, 0x73, 0x55, 0x6D, 0x1D,
  41134. 0xE3, 0x86, 0x62, 0x3A, 0x6C, 0x3F, 0x11, 0x5B,
  41135. 0xBD, 0x11, 0x92, 0x71, 0xD3, 0xFB, 0xA7, 0x96,
  41136. 0xF6, 0x18, 0xB5, 0x39, 0x59, 0xFB, 0x98, 0x01,
  41137. 0x2E, 0x7D, 0x5B, 0x9A, 0xC6, 0x88, 0x94, 0x0B,
  41138. 0x87, 0xE2, 0xC9, 0xC0, 0x65, 0x52, 0x4A, 0x00,
  41139. 0xD3, 0xA4, 0xF4, 0xDB, 0xF5, 0x2F, 0x4B, 0x1A,
  41140. 0x63, 0xEF, 0x5C, 0x46, 0x19, 0x3B, 0xAD, 0xF7,
  41141. 0xAD, 0x7F, 0x98, 0x8D, 0x44, 0x64, 0x34, 0x5B,
  41142. 0x2C, 0x3E, 0x54, 0x96, 0x84, 0xF2, 0xF9, 0x05,
  41143. 0xF6, 0xF8, 0x9D, 0xD6, 0x41, 0x47, 0x3E, 0xC0,
  41144. 0x51, 0x08, 0xA5, 0x2D, 0x8D, 0xBB, 0x91, 0x76,
  41145. 0x8C, 0x54, 0x1D, 0xE5, 0x20, 0xB1, 0x76, 0x66,
  41146. 0x97, 0x0A, 0xAE, 0xB5, 0x06, 0xE7, 0x5D, 0x8E,
  41147. 0xE9, 0xF4, 0xB4, 0x45, 0x5B, 0x71, 0xE0, 0x08,
  41148. 0x8A, 0xB2, 0x56, 0x55, 0x21, 0x3B, 0x75, 0x85,
  41149. 0x9D, 0x25, 0xF5, 0x59, 0xD3, 0xC3, 0x24, 0xD2,
  41150. 0x83, 0xD3, 0x97, 0xAB, 0xE6, 0xF0, 0xAA, 0xA3,
  41151. 0x86, 0x81, 0x57, 0x68, 0xD0, 0x33, 0x57, 0xD7,
  41152. 0x75, 0x96, 0x49, 0x02, 0x41, 0x31, 0x53, 0xE3,
  41153. 0x56, 0x0C, 0xCE, 0xF1, 0xFD, 0x44, 0xB6, 0x5F,
  41154. 0xF1, 0xB2, 0x87, 0xA9, 0x2A, 0x96, 0x93, 0xF0,
  41155. 0x34, 0xB7, 0xEE, 0x66, 0x89, 0x34, 0x70, 0x2D,
  41156. 0x75, 0x01, 0xCA, 0xF6, 0xDA, 0x4E, 0xE9, 0x8A,
  41157. 0xF4, 0xE8, 0xE6, 0x4B, 0x03, 0x40, 0xE0, 0xBB,
  41158. 0x8B, 0xDC, 0x53, 0x3B, 0x0E, 0xFE, 0xE1, 0x91,
  41159. 0x5A, 0x4B, 0x68, 0xB9, 0x3C, 0x5E, 0x95, 0x32,
  41160. 0x1E, 0xED, 0xC2, 0x34, 0xAE, 0xFE, 0x71, 0xAE,
  41161. 0x2E, 0x5D, 0xAC, 0xEC, 0x2F, 0x52, 0xF8, 0x37,
  41162. 0x23, 0xA2, 0x39, 0x2A, 0x7F, 0x8E, 0x13, 0xBC,
  41163. 0x03, 0x01, 0xCD, 0x10, 0x4D, 0x85, 0x2E, 0x62,
  41164. 0xA7, 0xF8, 0x28, 0xAD, 0x32, 0x9B, 0x3D, 0x95,
  41165. 0x96, 0xC5, 0x8E, 0x13, 0xFC, 0xC0, 0xED, 0x96,
  41166. 0xC1, 0xC4, 0x8D, 0x82, 0xA2, 0xC0, 0xF4, 0xD9,
  41167. 0xD2, 0x4D, 0xD8, 0x42, 0x1F, 0xDC, 0xCE, 0xFD,
  41168. 0x49, 0x7A, 0x9B, 0x05, 0xFF, 0xC5, 0x09, 0x04,
  41169. 0x77, 0x04, 0x01, 0x37, 0x3F, 0xEE, 0x7D, 0xC7,
  41170. 0x37, 0x73, 0x41, 0x8A, 0xEB, 0x4A, 0x1F, 0x59,
  41171. 0x9A, 0x4B, 0xB3, 0x8E, 0xDE, 0x8D, 0x10, 0xA3,
  41172. 0xCC, 0x83, 0xA1, 0xC7, 0x2D, 0xE9, 0x21, 0x96,
  41173. 0x9E, 0x3C, 0xE3, 0xE8, 0xEF, 0x2F, 0x7D, 0xA8,
  41174. 0x9D, 0x34, 0x4C, 0x80, 0xD6, 0x1C, 0xF9, 0xC5,
  41175. 0xA4, 0x23, 0xB1, 0xA4, 0xF3, 0x56, 0x7D, 0x96,
  41176. 0xDB, 0x2D, 0xA3, 0xDB, 0x9B, 0x5B, 0x5F, 0xA6,
  41177. 0x81, 0x56, 0xBE, 0x74, 0x52, 0xC8, 0xA0, 0x18,
  41178. 0x1B, 0xB9, 0xF0, 0xDC, 0x75, 0xCD, 0x97, 0x50,
  41179. 0x88, 0x3D, 0x0D, 0xDA, 0xE5, 0x3F, 0xC1, 0x56,
  41180. 0xD6, 0x7A, 0x74, 0x20, 0x08, 0x69, 0x04, 0x6B,
  41181. 0x41, 0xDF, 0x4B, 0xC4, 0x39, 0x69, 0x93, 0xC0,
  41182. 0x8A, 0xA4, 0x89, 0x7A, 0x0B, 0xDD, 0xEF, 0xB5,
  41183. 0x5F, 0x69, 0xCC, 0x1C, 0x4D, 0x7B, 0x5F, 0xB1,
  41184. 0x50, 0x40, 0x84, 0x27, 0xB4, 0x16, 0xF7, 0x31,
  41185. 0x83, 0xF2, 0xB3, 0xCC, 0x16, 0xE3, 0xB7, 0xDA,
  41186. 0x63, 0xCE, 0xE1, 0x14, 0x3A, 0xDA, 0x1A, 0x05,
  41187. 0x66, 0x26, 0xA0, 0x77, 0xB6, 0xD2, 0x1C, 0x3D,
  41188. 0xD9, 0x74, 0xED, 0x90, 0x7C, 0x5A, 0x09, 0x40,
  41189. 0x19, 0x22, 0x57, 0x37, 0xEF, 0xB9, 0x33, 0x19,
  41190. 0xAD, 0x3B, 0x40, 0xA4, 0xF4, 0x34, 0xAE, 0x49,
  41191. 0xD2, 0x83, 0x91, 0xC1, 0x7A, 0x99, 0x9C, 0x74,
  41192. 0x4A, 0x68, 0xC5, 0x5A, 0x91, 0xB8, 0x62, 0x72,
  41193. 0x95, 0x83, 0xD3, 0xDA, 0x46, 0xEE, 0x70, 0xC5,
  41194. 0xCC, 0x46, 0x16, 0x94, 0x16, 0x7D, 0x32, 0xD2,
  41195. 0x1D, 0xE7, 0x53, 0x27, 0x73, 0x2C, 0x63, 0xBB,
  41196. 0xFB, 0xD7, 0xB3, 0x0D, 0xBF, 0x20, 0x57, 0xA0,
  41197. 0xD6, 0x81, 0x51, 0x9F, 0x6E, 0x4A, 0xF6, 0x08,
  41198. 0xD4, 0xBC, 0xD0, 0xB4, 0x75, 0x07, 0x26, 0x77,
  41199. 0x0E, 0x15, 0x6A, 0xED, 0xE8, 0x54, 0x17, 0xBD,
  41200. 0x75, 0x9D, 0x5F, 0xFE, 0x40, 0x1C, 0xB2, 0x99,
  41201. 0x6F, 0x34, 0x43, 0x4D, 0xB4, 0x28, 0xD9, 0xA4,
  41202. 0x17, 0x03, 0x72, 0x01, 0xFC, 0xD2, 0x60, 0xFA,
  41203. 0xA9, 0x80, 0x84, 0x50, 0x2E, 0xED, 0x5C, 0x27,
  41204. 0xA8, 0x91, 0x6E, 0x44, 0xF5, 0x92, 0x98, 0x19,
  41205. 0xD2, 0x1A, 0x69, 0xCE, 0x16, 0xBC, 0xDC, 0x3C,
  41206. 0xC8, 0x14, 0x1E, 0x28, 0x5E, 0xF8, 0x97, 0xB1,
  41207. 0x40, 0x2C, 0x15, 0xC9, 0x52, 0x59, 0x01, 0x19,
  41208. 0x05, 0x1E, 0x36, 0x9A, 0x1B, 0x7B, 0xE4, 0x43,
  41209. 0xFE, 0xAE, 0x6E, 0x32, 0xBC, 0x8F, 0x3D, 0x64,
  41210. 0x7F, 0xC5, 0x31, 0x5A, 0x52, 0x00, 0xCD, 0x52,
  41211. 0x38, 0xDC, 0x66, 0x77, 0x46, 0x6E, 0xA8, 0x6E,
  41212. 0xF8, 0xD1, 0x8E, 0x5A, 0x79, 0xF2, 0x62, 0x48,
  41213. 0x3E, 0x89, 0x6B, 0x82, 0x77, 0xC7, 0x41, 0xF5,
  41214. 0x16, 0xFC, 0x04, 0x0C, 0x10, 0x90, 0xF2, 0x49,
  41215. 0x5B, 0xF1, 0x65, 0x0B, 0x02, 0xAF, 0x30, 0x45,
  41216. 0x67, 0x33, 0xA0, 0x71, 0xAF, 0x47, 0xD7, 0xA1,
  41217. 0x5B, 0xD8, 0xE3, 0x2A, 0x49, 0x80, 0x64, 0x55,
  41218. 0xD3, 0xBE, 0xA7, 0x4A, 0xEF, 0x5D, 0x00, 0x90,
  41219. 0x6A, 0xD2, 0xF0, 0xC0, 0x45, 0x35, 0x4E, 0xFD,
  41220. 0xE7, 0xC9, 0xA2, 0x76, 0xE7, 0x3D, 0x9E, 0xDD,
  41221. 0x11, 0xD1, 0xCA, 0x5C, 0x29, 0x7B, 0x9A, 0x68,
  41222. 0x51, 0xE7, 0xF6, 0x7E, 0x21, 0xEB, 0x06, 0x1B,
  41223. 0xB5, 0x5D, 0x9E, 0x67, 0x3C, 0x4A, 0x75, 0xFE,
  41224. 0xB8, 0x4D, 0x52, 0x62, 0x9E, 0xEC, 0xC5, 0x3C,
  41225. 0x24, 0xBE, 0xA9, 0x51, 0x53, 0x05, 0x1A, 0xC2,
  41226. 0x06, 0xC8, 0x7D, 0xF5, 0x54, 0x10, 0xCA, 0x1F,
  41227. 0xE6, 0xCF, 0xC3, 0xF4, 0x03, 0xA6, 0xD9, 0xD4,
  41228. 0x3E, 0xA8, 0x4C, 0x60, 0xC9, 0x45, 0xE6, 0x42,
  41229. 0xB2, 0x83, 0x63, 0x38, 0xB5, 0xAF, 0x9F, 0x69,
  41230. 0xE5, 0x27, 0x08, 0xB2, 0xE2, 0x25, 0x93, 0x3D,
  41231. 0xB3, 0x20, 0xBB, 0x3F, 0x79, 0x0D, 0x39, 0x7F,
  41232. 0x22, 0xD7, 0xB6, 0xF8, 0xA4, 0x33, 0xCD, 0xAC,
  41233. 0xE9, 0x81, 0x0A, 0xA0, 0xE2, 0x7C, 0x69, 0x95,
  41234. 0x55, 0x53, 0x0C, 0x56, 0x2D, 0xBF, 0x75, 0x17,
  41235. 0xA4, 0x16, 0x26, 0x28, 0xBF, 0x10, 0xD1, 0xB6,
  41236. 0xDB, 0xAC, 0xEF, 0x5C, 0x9E, 0xD5, 0x1E, 0x55,
  41237. 0xD9, 0xA8, 0x9D, 0x60, 0xE0, 0xFC, 0x37, 0x8C,
  41238. 0x47, 0xA2, 0x1D, 0x5E, 0x0F, 0x2D, 0xC3, 0xBC,
  41239. 0xEF, 0x5E, 0x05, 0xC6, 0xE0, 0x26, 0x15, 0x30,
  41240. 0xFB, 0x02, 0x7E, 0x50, 0x32, 0x55, 0x8C, 0xA2,
  41241. 0xB4, 0x70, 0x05, 0xBD, 0xDE, 0x99, 0x90, 0x99,
  41242. 0x30, 0x39, 0x1E, 0xAD, 0x7F, 0x3F, 0x0A, 0x96,
  41243. 0xB3, 0xDE, 0xDA, 0x54, 0xA1, 0x11, 0x45, 0xF5,
  41244. 0x30, 0xE5, 0x1D, 0xEF, 0x89, 0x2E, 0x5A, 0xB0,
  41245. 0x20, 0x4D, 0x61, 0x4E, 0x6E, 0x38, 0xAF, 0xE7,
  41246. 0x9C, 0xA9, 0x2C, 0x28, 0x15, 0x8D, 0x57, 0x01,
  41247. 0x20, 0x35, 0x3B, 0x7A, 0x4D, 0xE0, 0x88, 0x98,
  41248. 0x46, 0xD8, 0x35, 0x29, 0x49, 0x39, 0x55, 0x7E,
  41249. 0xD0, 0xAE, 0xDA, 0x27, 0x0D, 0x4D, 0x73, 0xED,
  41250. 0x84, 0xD3, 0xD4, 0x9F, 0x9F, 0x03, 0x2D, 0x43,
  41251. 0x45, 0x7B, 0xF5, 0x9B, 0xB7, 0xD6, 0x63, 0x59,
  41252. 0xDC, 0x53, 0xF9, 0xB4, 0x69, 0x63, 0xB2, 0x17,
  41253. 0x84, 0xB0, 0x6C, 0xBC, 0xF0, 0x4B, 0xEC, 0x1E,
  41254. 0x33, 0xA3, 0x33, 0x71, 0x53, 0x27, 0x16, 0xC9,
  41255. 0xED, 0xB3, 0xFB, 0xED, 0xB8, 0x19, 0x99, 0xB4,
  41256. 0x37, 0x2D, 0x09, 0x45, 0xC1, 0x0A, 0xE8, 0x26,
  41257. 0xC6, 0x0F, 0xFE, 0x93, 0x17, 0x0B, 0x6D, 0x29,
  41258. 0x4B, 0x38, 0x91, 0xB0, 0xD2, 0xA7, 0xB3, 0x5B,
  41259. 0x28, 0xA8, 0x97, 0x18, 0x45, 0xDC, 0x2F, 0xEC,
  41260. 0xE2, 0x37, 0xB8, 0x0F, 0x20, 0xB3, 0x79, 0xCC,
  41261. 0x4D, 0x13, 0x6D, 0xAB, 0x3F, 0xBB, 0x37, 0x92,
  41262. 0xC6, 0x3E, 0xC6, 0x1F, 0x5C, 0x75, 0x5B, 0xC9,
  41263. 0xDB, 0x35, 0x08, 0x6F, 0xBF, 0x46, 0xD2, 0xB7,
  41264. 0x97, 0x0D, 0xCA, 0x2A, 0x85, 0x23, 0xFD, 0xB4,
  41265. 0xC7, 0xA0, 0xB8, 0xE4, 0x2F, 0x8A, 0xF9, 0xAC,
  41266. 0xAD, 0x2A, 0x0E, 0xFC, 0x11, 0x36, 0x02, 0xA4,
  41267. 0xEA, 0x62, 0xE4, 0xEB, 0xB7, 0xD2, 0x69, 0xC3,
  41268. 0xA4, 0x0B, 0xA2, 0xC4, 0x4E, 0xDD, 0x29, 0x56
  41269. };
  41270. static const byte msg_65[] = {
  41271. 0xC4, 0xF5, 0x9F, 0xA2, 0xDE, 0x30, 0xC8, 0x42,
  41272. 0x0A, 0x7E, 0x7F, 0x09, 0x6B, 0xAF, 0x6A, 0xD6,
  41273. 0x9B, 0x1C, 0x15, 0xA5, 0xC6, 0xE6, 0x1C, 0x9D,
  41274. 0x82, 0xAF, 0xCF, 0xDB, 0x6E, 0xB8, 0xF2, 0x75,
  41275. 0xBF, 0x57, 0x87, 0x18, 0x6A, 0xAE, 0x78, 0x1F,
  41276. 0x48, 0x7F, 0x9F, 0x88, 0x75, 0x8C, 0x9C, 0x61,
  41277. 0xF3, 0x5D, 0x50, 0x83, 0xEE, 0x70, 0x42, 0x4B,
  41278. 0x0D, 0x0A, 0x51, 0x57, 0x50, 0x10, 0xC2, 0xA9,
  41279. 0x07, 0xF4, 0x96, 0x08, 0x11, 0x5D, 0x33, 0xEB,
  41280. 0xA0, 0x03, 0x15, 0x09, 0x32, 0x2A, 0xA7, 0xD3,
  41281. 0x06, 0x1F, 0xEC, 0x31, 0x62, 0xF9, 0x6A, 0x56,
  41282. 0x5F, 0x98, 0x76, 0x9E, 0x9A, 0x19, 0x23, 0x5D,
  41283. 0x89, 0xD1, 0xB2, 0x1D, 0x60, 0xA3, 0x81, 0xDF,
  41284. 0x8E, 0xB3, 0x7D, 0x58, 0xC6, 0xA2, 0xE4, 0x83,
  41285. 0xA8, 0xEB, 0x70, 0x73, 0x6E, 0x4B, 0x7B, 0xB9,
  41286. 0x11, 0xF7, 0xAB, 0x92, 0x3D, 0xC2, 0x9F, 0x1E
  41287. };
  41288. static const byte sig_65[] = {
  41289. 0xE8, 0x95, 0xDB, 0x64, 0xC5, 0x7B, 0xC3, 0xC2,
  41290. 0xA9, 0x7F, 0x0E, 0xC9, 0x33, 0x41, 0x0E, 0x98,
  41291. 0xF6, 0x21, 0x61, 0x03, 0xE3, 0x42, 0x3C, 0xAF,
  41292. 0x06, 0xA6, 0x71, 0x96, 0x4C, 0x51, 0x4A, 0x69,
  41293. 0x4E, 0xB6, 0xF6, 0x5C, 0xBD, 0x11, 0x37, 0xCC,
  41294. 0xCF, 0x88, 0x81, 0xFA, 0x40, 0x3C, 0x5F, 0xA0,
  41295. 0xE0, 0xB2, 0xF3, 0x6B, 0x9F, 0x40, 0x09, 0xC3,
  41296. 0x78, 0x21, 0x0D, 0x29, 0xE5, 0x4A, 0x7A, 0x5A,
  41297. 0x9B, 0x79, 0x31, 0x97, 0xCD, 0x6D, 0x2F, 0x38,
  41298. 0xD7, 0xE1, 0xF3, 0xAC, 0xA6, 0x9D, 0x48, 0x88,
  41299. 0x13, 0x89, 0x38, 0x1C, 0x89, 0xFA, 0x67, 0x6D,
  41300. 0xE4, 0x26, 0xD6, 0x34, 0xF9, 0xA1, 0x57, 0x05,
  41301. 0x5F, 0x17, 0x28, 0x3E, 0xCE, 0x82, 0x48, 0xCA,
  41302. 0xF1, 0x4D, 0xCF, 0x11, 0xE2, 0xD5, 0x63, 0x55,
  41303. 0xB0, 0x47, 0xDF, 0x63, 0x2A, 0x18, 0x48, 0x2E,
  41304. 0x79, 0xCB, 0x2D, 0x5A, 0x74, 0x39, 0x66, 0xBA,
  41305. 0xA8, 0xA7, 0x61, 0x21, 0xBB, 0x69, 0xC2, 0xE6,
  41306. 0x81, 0x55, 0xAC, 0xCB, 0x0A, 0x31, 0xDA, 0x6E,
  41307. 0xDC, 0x73, 0xCB, 0x09, 0xA9, 0xE6, 0x60, 0xFE,
  41308. 0xB2, 0x0F, 0x66, 0xC7, 0xBD, 0x96, 0x7A, 0xDE,
  41309. 0x32, 0x14, 0x9C, 0x55, 0x52, 0xEA, 0xEB, 0x2E,
  41310. 0xA1, 0x75, 0xB5, 0x62, 0x33, 0xF3, 0xB3, 0x70,
  41311. 0xED, 0xD8, 0x67, 0x92, 0x69, 0xCE, 0x0D, 0x2B,
  41312. 0x43, 0xF6, 0xB2, 0xF6, 0x5F, 0xE9, 0x57, 0xE7,
  41313. 0xAB, 0x37, 0xB9, 0x82, 0x04, 0x37, 0x54, 0xEA,
  41314. 0xC8, 0xA3, 0x0B, 0x36, 0xC1, 0x00, 0x04, 0xEF,
  41315. 0x13, 0xC6, 0x92, 0xE2, 0x19, 0xAA, 0x7A, 0xF0,
  41316. 0xA4, 0xC5, 0x28, 0x69, 0x10, 0xC7, 0x10, 0x0D,
  41317. 0xA4, 0x1E, 0x17, 0xBB, 0xEF, 0x2D, 0xA2, 0xAB,
  41318. 0x03, 0xAD, 0xF3, 0x07, 0x4B, 0xA1, 0xDA, 0x15,
  41319. 0xBC, 0xC8, 0x48, 0x05, 0xB8, 0x9B, 0x9D, 0xA8,
  41320. 0x8E, 0x9B, 0x40, 0x0A, 0xFB, 0x7E, 0x3B, 0xC8,
  41321. 0x33, 0x8D, 0x35, 0x4D, 0xA9, 0x53, 0xAC, 0x0B,
  41322. 0xAD, 0x82, 0x27, 0x56, 0xCA, 0x92, 0xE5, 0xDD,
  41323. 0x95, 0x07, 0xF4, 0x2B, 0xFE, 0xFC, 0xCB, 0x32,
  41324. 0xB4, 0xB9, 0x1A, 0x2B, 0xE5, 0xEF, 0x34, 0xC2,
  41325. 0xCF, 0x11, 0x77, 0xEA, 0xAF, 0xB2, 0x50, 0xAC,
  41326. 0x9A, 0xDE, 0xC4, 0xBE, 0x71, 0x80, 0x75, 0x89,
  41327. 0xF1, 0x00, 0x32, 0x27, 0xF9, 0xB7, 0x6B, 0x74,
  41328. 0xE0, 0x7B, 0xA6, 0x7A, 0xC6, 0x08, 0x19, 0xB2,
  41329. 0xAF, 0x76, 0x6A, 0x47, 0xFF, 0xFC, 0x7B, 0x76,
  41330. 0xD3, 0xA7, 0xC0, 0x77, 0xF5, 0xEC, 0x69, 0xAE,
  41331. 0xEA, 0x3E, 0x96, 0x38, 0x59, 0xB8, 0x2C, 0x2A,
  41332. 0xDE, 0x58, 0xBE, 0xC2, 0x15, 0x2E, 0xC8, 0x20,
  41333. 0x51, 0x10, 0x97, 0x5D, 0x37, 0xC6, 0x50, 0x5E,
  41334. 0x0D, 0xC7, 0x76, 0xFD, 0xE0, 0x71, 0x09, 0x7E,
  41335. 0x93, 0x01, 0x3D, 0x10, 0x04, 0xF4, 0xE1, 0xA2,
  41336. 0xFD, 0x79, 0xB8, 0x77, 0xED, 0x50, 0x25, 0xF5,
  41337. 0x27, 0xF3, 0xBF, 0xF1, 0x37, 0xF0, 0x41, 0xBB,
  41338. 0x9B, 0xD0, 0x01, 0xE9, 0x49, 0xF0, 0x8B, 0x4C,
  41339. 0xF8, 0x8D, 0xFD, 0x32, 0xFC, 0x7C, 0xDB, 0xCE,
  41340. 0xCC, 0xFD, 0xB0, 0xFA, 0x2D, 0xE7, 0x82, 0x3E,
  41341. 0x11, 0x0B, 0xCF, 0xF5, 0x8A, 0x41, 0x2C, 0xEA,
  41342. 0x27, 0x95, 0x75, 0x3E, 0x9C, 0x89, 0x67, 0x8C,
  41343. 0x3A, 0xE2, 0x42, 0x68, 0xF7, 0x48, 0x9F, 0x72,
  41344. 0x97, 0x4B, 0x69, 0x55, 0xED, 0xD0, 0x4E, 0x19,
  41345. 0x0D, 0x99, 0xBB, 0x0D, 0x7A, 0x25, 0x2F, 0xAD,
  41346. 0x5B, 0xBA, 0x60, 0x6C, 0x1A, 0x1F, 0x3A, 0xCA,
  41347. 0x73, 0x3B, 0xFA, 0xE3, 0x30, 0x9E, 0xA0, 0xA6,
  41348. 0xEB, 0x7D, 0x07, 0xE3, 0x6D, 0x8C, 0xA3, 0x36,
  41349. 0xD2, 0x64, 0x4F, 0xCE, 0x1A, 0x41, 0x89, 0x5D,
  41350. 0x01, 0x4D, 0x1A, 0x60, 0xCB, 0x10, 0x6F, 0x3F,
  41351. 0x80, 0x75, 0xF9, 0x37, 0x84, 0x61, 0x73, 0x8D,
  41352. 0x63, 0xD1, 0x15, 0xD0, 0x0B, 0x02, 0x4C, 0x67,
  41353. 0x78, 0x01, 0x05, 0x0A, 0x1B, 0x0B, 0x50, 0xDE,
  41354. 0x05, 0x7F, 0x85, 0xDB, 0x6A, 0xEB, 0x2C, 0x9D,
  41355. 0x6B, 0xB7, 0x40, 0x2A, 0x66, 0xE3, 0xAB, 0x4D,
  41356. 0xB0, 0x5C, 0x58, 0xBB, 0xDA, 0x12, 0xF6, 0x95,
  41357. 0x95, 0x8B, 0x8A, 0xC7, 0xB4, 0xE4, 0x5E, 0xC6,
  41358. 0xC9, 0x52, 0xF6, 0x79, 0xC1, 0xEE, 0xBD, 0xF8,
  41359. 0x60, 0xE3, 0x48, 0x98, 0x27, 0x79, 0xAA, 0x69,
  41360. 0x88, 0xEF, 0xC2, 0xAD, 0x1D, 0xC1, 0xEA, 0xE2,
  41361. 0x2A, 0x27, 0xA5, 0xB2, 0xC6, 0x1C, 0x97, 0xB3,
  41362. 0xB2, 0x49, 0x3C, 0xB6, 0xC1, 0x3C, 0x5F, 0x6E,
  41363. 0x20, 0xA6, 0x7B, 0x88, 0xD3, 0xC3, 0xAC, 0xCF,
  41364. 0xAF, 0x0A, 0x42, 0x57, 0x42, 0xDF, 0x24, 0x06,
  41365. 0x34, 0xD1, 0xEE, 0x59, 0x38, 0x28, 0xFE, 0x62,
  41366. 0x97, 0x44, 0x6C, 0x07, 0x6F, 0x97, 0x90, 0x55,
  41367. 0x98, 0x8A, 0xB8, 0x34, 0xB2, 0xBD, 0x82, 0xE1,
  41368. 0x4D, 0xC0, 0x86, 0x40, 0x0E, 0x1C, 0x95, 0x6C,
  41369. 0xC0, 0xC3, 0x0C, 0xE7, 0xBF, 0xD9, 0x62, 0x22,
  41370. 0x3D, 0x23, 0xFE, 0x94, 0x94, 0x96, 0x4A, 0x81,
  41371. 0x1B, 0x93, 0xE8, 0xD7, 0xB8, 0xF3, 0x4C, 0x89,
  41372. 0xAA, 0xD4, 0x5D, 0xD4, 0x11, 0x3F, 0x2A, 0xE7,
  41373. 0xBD, 0x94, 0xB5, 0x3F, 0xC8, 0x6E, 0x8B, 0x2A,
  41374. 0xE8, 0x2E, 0x51, 0xEC, 0x6F, 0x3E, 0xA4, 0xC3,
  41375. 0x0D, 0x60, 0xB8, 0x60, 0x72, 0x74, 0x86, 0x12,
  41376. 0xD1, 0x60, 0x70, 0x56, 0xB5, 0xFF, 0x6A, 0x45,
  41377. 0x00, 0xEE, 0xE7, 0x8A, 0x5A, 0x63, 0x9C, 0x7B,
  41378. 0x74, 0x16, 0x97, 0x77, 0x62, 0x68, 0x64, 0xDD,
  41379. 0x9E, 0xAE, 0xF0, 0xE3, 0xAD, 0x84, 0x93, 0xD8,
  41380. 0x31, 0xF7, 0x1D, 0xEA, 0x95, 0xBB, 0xFC, 0xF8,
  41381. 0x14, 0x23, 0xA2, 0x66, 0xDE, 0x56, 0xF3, 0xA8,
  41382. 0xFE, 0x8E, 0x6C, 0x3C, 0x0D, 0x61, 0x2F, 0xB6,
  41383. 0x2B, 0xD6, 0x42, 0x18, 0x8C, 0xA7, 0x1C, 0xB8,
  41384. 0x98, 0x34, 0xF3, 0x0B, 0xCC, 0x28, 0xBD, 0x17,
  41385. 0x88, 0x45, 0xF1, 0xF6, 0xF4, 0x6C, 0x03, 0xD3,
  41386. 0x06, 0xF7, 0xED, 0x4E, 0x68, 0x75, 0x94, 0x27,
  41387. 0xAE, 0xC2, 0x70, 0x11, 0x98, 0xC3, 0xC0, 0x5D,
  41388. 0x38, 0x5D, 0xFA, 0xFD, 0x52, 0x8C, 0xCE, 0x84,
  41389. 0x25, 0xBC, 0x55, 0x14, 0x69, 0xA0, 0xED, 0x68,
  41390. 0x1B, 0xEE, 0x4D, 0x12, 0xA8, 0x43, 0xE3, 0x33,
  41391. 0xB5, 0xA8, 0xE0, 0x51, 0x7F, 0xC6, 0x19, 0x06,
  41392. 0xF9, 0xC4, 0xE7, 0x80, 0x9B, 0xAE, 0xD4, 0xD3,
  41393. 0xD1, 0x6E, 0xB2, 0x2F, 0x1F, 0xA9, 0xAB, 0x40,
  41394. 0x2D, 0x98, 0x8E, 0xD5, 0x9F, 0x9F, 0xED, 0x04,
  41395. 0x55, 0xE9, 0x26, 0x0F, 0xD6, 0x27, 0xA2, 0x4A,
  41396. 0x17, 0xFE, 0x7C, 0xB6, 0x3E, 0x53, 0x0B, 0x48,
  41397. 0xF5, 0xFB, 0x66, 0x87, 0xA2, 0xE8, 0xC4, 0x9D,
  41398. 0xA7, 0x9F, 0xBD, 0x69, 0xA3, 0x40, 0x00, 0x56,
  41399. 0x66, 0x5D, 0xD1, 0x1D, 0x19, 0xA2, 0xBC, 0x4D,
  41400. 0xB1, 0xD3, 0x74, 0xAB, 0x6A, 0x6E, 0x42, 0x47,
  41401. 0x2A, 0x27, 0xAC, 0x6B, 0x98, 0xF6, 0x76, 0xE8,
  41402. 0xED, 0xAA, 0xDD, 0x51, 0x4F, 0x6D, 0x44, 0xDE,
  41403. 0xEC, 0xDA, 0xB5, 0xA6, 0xDF, 0xA0, 0xF8, 0x4F,
  41404. 0x13, 0x9A, 0x80, 0x3A, 0x25, 0x24, 0xBF, 0x33,
  41405. 0x5D, 0xC5, 0x2E, 0xA5, 0x8F, 0xA5, 0x0D, 0x98,
  41406. 0xFB, 0x5C, 0xD5, 0x5D, 0x5D, 0x50, 0xA6, 0x63,
  41407. 0xCF, 0x64, 0x7E, 0xEE, 0x56, 0xFE, 0x8E, 0x66,
  41408. 0x4B, 0x3B, 0xCA, 0xF9, 0xE3, 0x33, 0x97, 0x8A,
  41409. 0x79, 0x46, 0x97, 0x3F, 0xD1, 0x13, 0xE4, 0xFD,
  41410. 0x39, 0x24, 0xE6, 0xC0, 0x9E, 0x60, 0x38, 0x64,
  41411. 0x44, 0x21, 0x4D, 0xFA, 0x7A, 0x4D, 0x67, 0x1F,
  41412. 0xC2, 0x38, 0x90, 0x63, 0x7E, 0xB8, 0x59, 0x13,
  41413. 0x4D, 0x79, 0xE2, 0x65, 0xC5, 0x9C, 0xA3, 0xEC,
  41414. 0xCD, 0xDF, 0xA0, 0x18, 0x22, 0x3C, 0x9B, 0xAE,
  41415. 0x1C, 0xCA, 0x10, 0x39, 0x62, 0x07, 0x8B, 0xC5,
  41416. 0xF0, 0xDD, 0x02, 0x24, 0x6F, 0xA2, 0x83, 0x24,
  41417. 0xF7, 0xCB, 0x2F, 0xCF, 0xAD, 0x07, 0xC2, 0x5B,
  41418. 0x4B, 0xC2, 0xD8, 0x88, 0x06, 0x9B, 0x0C, 0xF5,
  41419. 0xF2, 0x3C, 0x76, 0x1C, 0x0E, 0x47, 0x10, 0x98,
  41420. 0x81, 0xCD, 0x31, 0x45, 0x6A, 0x64, 0xB9, 0x40,
  41421. 0xB4, 0xBB, 0x9B, 0x4C, 0x2C, 0x3B, 0x8E, 0x6B,
  41422. 0xA8, 0x34, 0xAA, 0xAE, 0x69, 0xFD, 0xFC, 0x47,
  41423. 0xD4, 0x4B, 0x3C, 0x96, 0x88, 0x7A, 0xBE, 0xD3,
  41424. 0x60, 0x15, 0xE7, 0xB6, 0x4E, 0x85, 0x42, 0x92,
  41425. 0x8F, 0x27, 0x7C, 0xBD, 0x2D, 0x3C, 0x51, 0x2C,
  41426. 0x24, 0xDE, 0xEF, 0xE5, 0x90, 0xE8, 0x1C, 0x68,
  41427. 0x4E, 0x06, 0x3E, 0x7A, 0xAD, 0xCF, 0x11, 0x7B,
  41428. 0x48, 0x94, 0x3D, 0xB7, 0x71, 0xFC, 0x22, 0x07,
  41429. 0xF5, 0x7A, 0x74, 0x53, 0x57, 0x55, 0x5D, 0x41,
  41430. 0x9C, 0x9C, 0xDC, 0xA3, 0x5C, 0xC1, 0xA7, 0x10,
  41431. 0x0A, 0x69, 0x13, 0xA3, 0xB6, 0xAA, 0xCF, 0x79,
  41432. 0x6F, 0xE3, 0xF9, 0x4D, 0xD2, 0xF8, 0x18, 0x98,
  41433. 0x27, 0x16, 0xCE, 0x03, 0x16, 0x54, 0x2A, 0x1B,
  41434. 0x95, 0x7E, 0x12, 0xDA, 0x43, 0xE2, 0x31, 0x54,
  41435. 0x2C, 0xC1, 0x4F, 0xCC, 0x66, 0xD7, 0x28, 0xA6,
  41436. 0x83, 0x26, 0xB2, 0xBC, 0x31, 0x12, 0x48, 0x33,
  41437. 0x0F, 0x3E, 0x98, 0xF8, 0x1E, 0xA3, 0x8C, 0xA9,
  41438. 0x24, 0xA8, 0xE4, 0xDA, 0x97, 0xCF, 0x67, 0x38,
  41439. 0x42, 0xC7, 0x59, 0xF9, 0x35, 0xBE, 0x88, 0x16,
  41440. 0x3C, 0xE9, 0x7F, 0xE4, 0xD9, 0x45, 0x71, 0x76,
  41441. 0xF5, 0xB8, 0x90, 0x8A, 0xF9, 0x48, 0xF7, 0x4D,
  41442. 0x5D, 0x1D, 0xDB, 0xC5, 0x21, 0x82, 0x5D, 0x93,
  41443. 0x1C, 0x63, 0xCA, 0x8A, 0x8E, 0x12, 0x24, 0x26,
  41444. 0x26, 0x30, 0x5A, 0xB6, 0xA2, 0xE0, 0x62, 0x45,
  41445. 0x64, 0xEE, 0x04, 0x19, 0x83, 0xC1, 0x8C, 0x29,
  41446. 0x52, 0xEC, 0x3D, 0x9D, 0x15, 0x9B, 0xDE, 0x39,
  41447. 0x85, 0xCF, 0x77, 0x89, 0x7E, 0xE2, 0xDC, 0x88,
  41448. 0x81, 0x12, 0x72, 0x1D, 0x48, 0x54, 0xE9, 0x14,
  41449. 0xA5, 0x39, 0x7E, 0x08, 0xB5, 0x4F, 0x4A, 0x54,
  41450. 0x32, 0x3F, 0xF8, 0x20, 0x82, 0x1B, 0xE0, 0x26,
  41451. 0xEA, 0x09, 0x1E, 0xCA, 0x6B, 0x7D, 0x80, 0xD9,
  41452. 0x1E, 0x3D, 0xCA, 0x2E, 0xF7, 0x84, 0x8B, 0x86,
  41453. 0xFC, 0xA6, 0xBB, 0x40, 0xCE, 0x48, 0x27, 0x1E,
  41454. 0x10, 0x08, 0x36, 0x8E, 0x3E, 0xBB, 0x5E, 0x39,
  41455. 0x5E, 0x1C, 0xCD, 0x0D, 0x17, 0x8F, 0x1A, 0x62,
  41456. 0x57, 0xD2, 0x6B, 0x6B, 0xA4, 0xB7, 0xCE, 0x53,
  41457. 0x2C, 0xAA, 0x1E, 0x76, 0xCE, 0x28, 0xFA, 0x4C,
  41458. 0xF9, 0xE0, 0x29, 0xE2, 0x48, 0x2B, 0x94, 0xD3,
  41459. 0xAC, 0xF9, 0x7A, 0x32, 0x6D, 0x23, 0x5D, 0x1B,
  41460. 0xDC, 0x89, 0xF7, 0x00, 0x02, 0x19, 0x84, 0x51,
  41461. 0xD9, 0xF1, 0xF1, 0x2C, 0xCD, 0x5B, 0xCA, 0xEC,
  41462. 0xDD, 0xE9, 0xE1, 0x4A, 0xC8, 0x07, 0x42, 0xEB,
  41463. 0x31, 0xE6, 0x46, 0x4C, 0x83, 0x21, 0x0A, 0x39,
  41464. 0xF3, 0x50, 0x98, 0xBE, 0x03, 0x78, 0xD0, 0x74,
  41465. 0xCE, 0x1C, 0xCD, 0x1E, 0xBC, 0x1C, 0x77, 0x70,
  41466. 0xF7, 0x78, 0xD6, 0x05, 0xF2, 0xBE, 0x59, 0xDB,
  41467. 0x7E, 0xA0, 0x7D, 0x80, 0xCC, 0xDF, 0x55, 0xF1,
  41468. 0x6E, 0x98, 0x5B, 0x14, 0x2F, 0xB7, 0xBD, 0xA0,
  41469. 0x7A, 0xA7, 0xDC, 0xA5, 0xB2, 0x01, 0xE1, 0x95,
  41470. 0x0C, 0xF9, 0xA7, 0x28, 0xF2, 0x1E, 0x9A, 0x9D,
  41471. 0x8A, 0xC4, 0xD1, 0x32, 0x7E, 0x3B, 0xC0, 0xFF,
  41472. 0x33, 0x9A, 0x25, 0x05, 0x22, 0xF6, 0x31, 0xDF,
  41473. 0x2E, 0x75, 0x95, 0x51, 0x54, 0x89, 0x3E, 0x4A,
  41474. 0x1A, 0xAF, 0x98, 0x66, 0xFE, 0xE1, 0x63, 0x7E,
  41475. 0xE1, 0xAA, 0x51, 0x06, 0xD2, 0x44, 0xE9, 0x9E,
  41476. 0x6F, 0x31, 0xFC, 0x56, 0x01, 0xBB, 0x7B, 0x79,
  41477. 0xBA, 0xD8, 0x28, 0x60, 0xB1, 0xD6, 0x05, 0x9D,
  41478. 0x9B, 0x13, 0x2E, 0x02, 0x64, 0x18, 0x02, 0x0D,
  41479. 0xB0, 0x6E, 0xB8, 0x39, 0x1F, 0xA1, 0x5B, 0x7A,
  41480. 0x0F, 0x29, 0xE3, 0x6D, 0x96, 0x6A, 0xBD, 0x3D,
  41481. 0x2A, 0x2F, 0xF3, 0xF2, 0xAA, 0xC3, 0x4C, 0x8B,
  41482. 0x45, 0xC7, 0xD2, 0x35, 0x5E, 0xDB, 0xB8, 0x0B,
  41483. 0x22, 0x4B, 0xC1, 0x06, 0xEB, 0xC6, 0x75, 0x0E,
  41484. 0x55, 0x07, 0x0F, 0x85, 0xA7, 0xCB, 0x60, 0x03,
  41485. 0x39, 0x4E, 0x51, 0x61, 0xAE, 0x26, 0xF5, 0xAB,
  41486. 0xF8, 0x3F, 0x0D, 0xCC, 0xCF, 0x69, 0xB8, 0x61,
  41487. 0x39, 0xAF, 0x86, 0x94, 0xFE, 0x1D, 0xC0, 0x07,
  41488. 0x81, 0xEA, 0xE0, 0x9C, 0xDB, 0x42, 0x18, 0x14,
  41489. 0x87, 0x80, 0x43, 0xDC, 0x9B, 0x05, 0x30, 0xE5,
  41490. 0x54, 0x5A, 0x16, 0x5E, 0x39, 0xA9, 0xB7, 0xDE,
  41491. 0x88, 0xB4, 0xAD, 0x2A, 0xEB, 0x90, 0xD3, 0xC3,
  41492. 0x29, 0x41, 0x2E, 0xD2, 0xFE, 0x1D, 0x97, 0xB7,
  41493. 0x32, 0xC8, 0x43, 0x9D, 0xF4, 0xF8, 0x3D, 0x22,
  41494. 0x88, 0x35, 0xB5, 0x38, 0xDC, 0x27, 0x8F, 0xF0,
  41495. 0xA2, 0xDC, 0x42, 0xF4, 0x1B, 0x00, 0xCE, 0x3A,
  41496. 0xCA, 0x06, 0xB0, 0x5C, 0x48, 0x39, 0xB8, 0x96,
  41497. 0x93, 0x15, 0x15, 0xD7, 0x8E, 0xA3, 0x67, 0x3A,
  41498. 0x37, 0x82, 0x79, 0xF4, 0xE8, 0x9C, 0xE0, 0x8E,
  41499. 0x34, 0x53, 0xFF, 0x2F, 0xB4, 0x53, 0xBE, 0x03,
  41500. 0x1C, 0x63, 0x18, 0x62, 0x8A, 0x73, 0x1D, 0x02,
  41501. 0x9F, 0xC7, 0xBE, 0xA2, 0xBA, 0x5E, 0xAC, 0x49,
  41502. 0x16, 0x27, 0x8B, 0x93, 0x8A, 0x6A, 0x6A, 0xCE,
  41503. 0xF5, 0xBF, 0xE2, 0x15, 0x8F, 0x2A, 0xF4, 0x3D,
  41504. 0x8E, 0x56, 0xA0, 0x64, 0x9D, 0xF2, 0x8A, 0x25,
  41505. 0x0D, 0x2F, 0x25, 0x36, 0xAB, 0xDE, 0x1E, 0x00,
  41506. 0x8E, 0xB6, 0x31, 0xF4, 0xBD, 0x0E, 0xB5, 0x55,
  41507. 0x73, 0xA4, 0x05, 0x39, 0xA6, 0x00, 0x41, 0x81,
  41508. 0xA9, 0xD2, 0xBF, 0x7A, 0x1E, 0x53, 0x50, 0x4F,
  41509. 0x11, 0xE0, 0x14, 0x84, 0x07, 0x33, 0x84, 0x41,
  41510. 0x31, 0xAC, 0x66, 0x89, 0x46, 0xE5, 0xB8, 0x27,
  41511. 0x28, 0x9A, 0xB6, 0xB2, 0x13, 0x66, 0xC5, 0xD0,
  41512. 0xE2, 0x64, 0x92, 0x19, 0xB9, 0x2C, 0x47, 0x60,
  41513. 0xDF, 0xB7, 0x05, 0xF7, 0xF6, 0x1A, 0x96, 0x56,
  41514. 0x4C, 0x9E, 0x84, 0x0D, 0x14, 0xB0, 0xBB, 0x0D,
  41515. 0xA8, 0x2D, 0xA5, 0x0F, 0x8B, 0x8E, 0x75, 0x2B,
  41516. 0xBF, 0xEA, 0x3B, 0x0A, 0x33, 0x7B, 0xE1, 0x24,
  41517. 0xF7, 0x2D, 0x8F, 0x82, 0x49, 0x19, 0x5B, 0xC1,
  41518. 0x9C, 0x3E, 0x0B, 0x62, 0xEA, 0xE4, 0x96, 0xD3,
  41519. 0x8C, 0xF7, 0x50, 0x0B, 0x4F, 0x10, 0x66, 0x5F,
  41520. 0xC2, 0xD2, 0x8B, 0x9E, 0xA9, 0x35, 0xF7, 0xE3,
  41521. 0x16, 0x47, 0x2F, 0x4F, 0xF4, 0x01, 0x26, 0x75,
  41522. 0x41, 0xBD, 0xB6, 0x23, 0x01, 0x55, 0x4B, 0x20,
  41523. 0x09, 0x92, 0x8C, 0x64, 0x45, 0xBB, 0xD0, 0xEF,
  41524. 0x21, 0xD0, 0x99, 0x72, 0xF3, 0x50, 0x81, 0xAB,
  41525. 0xA9, 0x09, 0x1A, 0x6C, 0x23, 0xFE, 0xD2, 0x9F,
  41526. 0x5C, 0xF9, 0xE0, 0x77, 0x9F, 0x7E, 0xFB, 0xAD,
  41527. 0x88, 0xE6, 0x2A, 0x45, 0x44, 0x42, 0xB3, 0x00,
  41528. 0x79, 0xBE, 0x0A, 0xC9, 0xC6, 0x48, 0x26, 0xB9,
  41529. 0x8C, 0x1E, 0x10, 0x01, 0xCB, 0x0F, 0xB0, 0xF0,
  41530. 0xA9, 0x5F, 0x79, 0x65, 0xFE, 0x93, 0x12, 0xBF,
  41531. 0xDA, 0xEC, 0x33, 0xF9, 0x50, 0x65, 0xC8, 0xE5,
  41532. 0x9D, 0x39, 0x50, 0xF8, 0x0A, 0xDC, 0x7F, 0xB3,
  41533. 0x34, 0xF2, 0x02, 0xD3, 0xE5, 0xF8, 0xDA, 0x48,
  41534. 0x1C, 0x9B, 0x54, 0xA7, 0x59, 0x83, 0x93, 0x0F,
  41535. 0xD1, 0xE5, 0xAC, 0xD1, 0x62, 0x84, 0xF0, 0x71,
  41536. 0x93, 0xFB, 0xCB, 0x50, 0xD0, 0xDC, 0x00, 0xEF,
  41537. 0xF8, 0x20, 0x31, 0x44, 0xC1, 0x1E, 0xC6, 0x14,
  41538. 0x20, 0xFC, 0x32, 0xD7, 0x98, 0x2C, 0xE8, 0x96,
  41539. 0x40, 0x6B, 0xE7, 0x69, 0xA7, 0x5D, 0xD8, 0xD3,
  41540. 0xCA, 0xC7, 0x53, 0xAB, 0xE5, 0xA2, 0x78, 0x65,
  41541. 0x5B, 0xF5, 0x4B, 0xE3, 0x3A, 0x1B, 0x83, 0x74,
  41542. 0xEB, 0xEE, 0xFF, 0x21, 0x2C, 0x39, 0xCE, 0x51,
  41543. 0x46, 0x68, 0xF1, 0xC4, 0x56, 0xEA, 0xA2, 0x53,
  41544. 0x28, 0x28, 0xC8, 0x42, 0x93, 0xF1, 0xA5, 0xBC,
  41545. 0x9E, 0xB5, 0xDE, 0xDF, 0x55, 0x8A, 0x9B, 0x4C,
  41546. 0x12, 0x39, 0xF7, 0x72, 0x72, 0xC6, 0x7E, 0x1A,
  41547. 0xB2, 0x8E, 0x1E, 0xFE, 0xC5, 0x89, 0x3E, 0x09,
  41548. 0xC1, 0x06, 0x62, 0xB5, 0x3C, 0x8B, 0x82, 0x55,
  41549. 0xB1, 0xC8, 0xDC, 0x8F, 0x8E, 0x51, 0x20, 0xA2,
  41550. 0x5C, 0x75, 0xEE, 0xFE, 0x79, 0xC4, 0x3F, 0x7A,
  41551. 0x8B, 0x37, 0xDF, 0x9D, 0x1E, 0x4F, 0x32, 0x48,
  41552. 0x69, 0x33, 0xDA, 0x1C, 0xB0, 0x66, 0x4C, 0x5D,
  41553. 0xB3, 0x9E, 0x21, 0xBC, 0x22, 0x7B, 0x0C, 0xDF,
  41554. 0xE7, 0xA5, 0x50, 0x7F, 0x07, 0xF2, 0x18, 0xA7,
  41555. 0xA4, 0x7D, 0xEB, 0xCD, 0x9D, 0xAD, 0x72, 0x47,
  41556. 0xB4, 0xD0, 0x45, 0xA1, 0x3A, 0xD4, 0xF7, 0x5E,
  41557. 0xAD, 0x2D, 0x45, 0xC3, 0x39, 0xD0, 0xDF, 0x04,
  41558. 0x57, 0x7F, 0x2E, 0x0F, 0xDC, 0x78, 0x03, 0x92,
  41559. 0x55, 0x30, 0x33, 0xC7, 0x38, 0x85, 0x2B, 0x1B,
  41560. 0xE4, 0xE6, 0x3E, 0xA3, 0x89, 0x7D, 0x6C, 0x9C,
  41561. 0x4B, 0x11, 0xAD, 0x6B, 0x58, 0xD3, 0xE2, 0xD3,
  41562. 0x42, 0xD3, 0x28, 0x40, 0xF6, 0x49, 0xDD, 0x83,
  41563. 0xE7, 0x59, 0x86, 0x6B, 0x73, 0x81, 0xA8, 0x4C,
  41564. 0x8A, 0xDD, 0xDF, 0x41, 0x3F, 0xAE, 0x18, 0xE6,
  41565. 0x43, 0x1B, 0x1E, 0xEA, 0x73, 0xA5, 0x6C, 0xD8,
  41566. 0x89, 0xB7, 0x6B, 0xC9, 0x78, 0x6B, 0xED, 0xED,
  41567. 0xCA, 0x25, 0x41, 0xE4, 0xC9, 0xB2, 0x4E, 0x28,
  41568. 0xF5, 0x8A, 0xD3, 0x74, 0xC1, 0xD9, 0x3D, 0xF2,
  41569. 0xD3, 0xF2, 0xC3, 0x7E, 0xC5, 0x94, 0xA0, 0x49,
  41570. 0x8C, 0x57, 0x45, 0x79, 0xA7, 0x33, 0x2F, 0x72,
  41571. 0xC0, 0xF9, 0x75, 0x08, 0x77, 0xFA, 0xD5, 0xB9,
  41572. 0x0B, 0x96, 0x8D, 0x88, 0xF1, 0x16, 0x82, 0xC4,
  41573. 0x07, 0x1E, 0x4E, 0xA3, 0x8B, 0x81, 0x6A, 0xEA,
  41574. 0xD6, 0xBE, 0x54, 0xD2, 0xF3, 0x71, 0x32, 0x4F,
  41575. 0x24, 0x75, 0xB8, 0x62, 0xC7, 0x54, 0x24, 0xEC,
  41576. 0xF9, 0x85, 0x8A, 0xA4, 0xE2, 0x00, 0xCF, 0xBA,
  41577. 0x41, 0x2D, 0x7E, 0x3E, 0x6C, 0x30, 0x8D, 0x8D,
  41578. 0xE1, 0x1D, 0xD1, 0x85, 0x33, 0x1A, 0xF9, 0xD4,
  41579. 0x1A, 0xFE, 0x88, 0x79, 0x96, 0x5D, 0x67, 0x46,
  41580. 0xEF, 0x21, 0xFD, 0x98, 0xD3, 0xED, 0x38, 0x06,
  41581. 0xFB, 0x5C, 0x46, 0x19, 0xC9, 0x8E, 0x34, 0x7D,
  41582. 0x76, 0xB8, 0xB8, 0x98, 0x49, 0x39, 0x55, 0x61,
  41583. 0xEE, 0x28, 0x6D, 0xFD, 0xFC, 0x6A, 0x04, 0xE1,
  41584. 0xD4, 0x7E, 0x9F, 0x5B, 0x5B, 0x49, 0x25, 0x77,
  41585. 0x84, 0xC3, 0x93, 0x64, 0xDF, 0xA8, 0x8A, 0xD6,
  41586. 0x30, 0xDF, 0xA5, 0x9C, 0xCA, 0x32, 0x37, 0xF4,
  41587. 0xA2, 0xB1, 0x41, 0xA8, 0x13, 0xD2, 0x2C, 0x6F,
  41588. 0xFE, 0x73, 0xC2, 0xD9, 0x9A, 0xDC, 0x82, 0x4D,
  41589. 0x93, 0xE0, 0x6A, 0x54, 0xB6, 0xDE, 0x62, 0xC3,
  41590. 0x12, 0x5D, 0x94, 0xB4, 0x9E, 0x95, 0x0D, 0xEC,
  41591. 0x36, 0x1F, 0x96, 0x1F, 0x56, 0xD3, 0x67, 0x1C,
  41592. 0x99, 0x25, 0x37, 0x7F, 0x6E, 0x67, 0x06, 0x65,
  41593. 0x32, 0x2B, 0x84, 0x89, 0xE8, 0x33, 0xD3, 0x83,
  41594. 0x0E, 0xCC, 0xDD, 0x0F, 0x53, 0xF4, 0xA4, 0xF9,
  41595. 0xD6, 0x8F, 0x14, 0x45, 0xF3, 0xAE, 0xD5, 0xC9,
  41596. 0xD7, 0x66, 0x40, 0x9B, 0x59, 0xBA, 0xE7, 0xA7,
  41597. 0x29, 0x12, 0xE9, 0x8B, 0x3B, 0xB5, 0x73, 0x42,
  41598. 0xD2, 0x9B, 0x6A, 0xCF, 0xD1, 0x43, 0x36, 0xB7,
  41599. 0xB8, 0xB6, 0xB7, 0x54, 0x9A, 0xF8, 0xCC, 0x88,
  41600. 0x45, 0xE1, 0x0C, 0x28, 0x11, 0x28, 0x72, 0x81,
  41601. 0x98, 0x5D, 0x5D, 0x47, 0x68, 0x5F, 0xC5, 0x89,
  41602. 0xF2, 0x67, 0x8E, 0xD8, 0x93, 0xF5, 0x7B, 0x85,
  41603. 0xAC, 0xED, 0x75, 0x63, 0x2E, 0x50, 0xDE, 0x5E,
  41604. 0x07, 0x4E, 0x6C, 0xED, 0xCF, 0x1A, 0xD4, 0x99,
  41605. 0xBC, 0xE6, 0x7A, 0x7F, 0x49, 0x85, 0x64, 0xDE,
  41606. 0xEC, 0x67, 0x7C, 0x70, 0x83, 0x88, 0xDE, 0x8F,
  41607. 0xD7, 0xB0, 0x99, 0xCF, 0xC1, 0x16, 0x09, 0x6C,
  41608. 0x45, 0xFE, 0x28, 0x89, 0x0B, 0x5E, 0xAF, 0x06,
  41609. 0x16, 0x99, 0x39, 0xFD, 0xA3, 0x5E, 0x12, 0x15,
  41610. 0xF2, 0x38, 0xE8, 0xCD, 0xED, 0xFE, 0x67, 0x00,
  41611. 0x65, 0xF5, 0xDE, 0x32, 0x72, 0xA2, 0x32, 0xFD,
  41612. 0x53, 0xC2, 0x50, 0xF5, 0xD7, 0x79, 0xB3, 0x16,
  41613. 0x94, 0xFB, 0xA9, 0x1B, 0x55, 0x48, 0x03, 0x67,
  41614. 0x6E, 0x4D, 0xEA, 0x28, 0x84, 0x63, 0xFE, 0x10,
  41615. 0x63, 0x00, 0x9E, 0x9C, 0xB7, 0x6C, 0x31, 0x7D,
  41616. 0xB4, 0x00, 0xAC, 0xF4, 0xD2, 0xD2, 0xB6, 0xD1,
  41617. 0x6E, 0xDE, 0xBA, 0x41, 0x08, 0x91, 0x3F, 0x60,
  41618. 0xAE, 0xB2, 0x52, 0xCD, 0xE4, 0x13, 0x69, 0x0C,
  41619. 0xEE, 0xFD, 0xCF, 0xA6, 0x38, 0x96, 0x3D, 0xBD,
  41620. 0x04, 0xF4, 0xCF, 0x21, 0xAD, 0x74, 0xDD, 0xE6,
  41621. 0x5F, 0x0F, 0x1E, 0x7C, 0xE7, 0x0A, 0xF1, 0x01,
  41622. 0xA6, 0xDE, 0x9A, 0x59, 0xDB, 0x21, 0xD3, 0x80,
  41623. 0x27, 0xDB, 0xBF, 0x76, 0x16, 0x78, 0x27, 0x95,
  41624. 0x0B, 0x69, 0x41, 0x82, 0x66, 0xAF, 0xA4, 0x44,
  41625. 0xC7, 0x28, 0xDE, 0x36, 0x24, 0xA1, 0xC8, 0x1E,
  41626. 0x5B, 0x16, 0x41, 0xDB, 0xE8, 0x79, 0xCD, 0x82,
  41627. 0x2F, 0xB2, 0x30, 0x3C, 0xC3, 0xA9, 0xFC, 0xEE,
  41628. 0xFE, 0x3D, 0xDF, 0x7D, 0xBD, 0x0B, 0x70, 0x57,
  41629. 0x24, 0x8A, 0x28, 0xD6, 0x06, 0x2D, 0x76, 0xEB,
  41630. 0x13, 0xB9, 0x2C, 0x9C, 0x9D, 0x00, 0x3B, 0x69,
  41631. 0xE1, 0x84, 0x2A, 0x54, 0xC0, 0x9C, 0xF6, 0xB4,
  41632. 0x84, 0x52, 0x08, 0x15, 0xE2, 0xBB, 0x23, 0x72,
  41633. 0x88, 0xC6, 0x4F, 0xC6, 0x96, 0xFD, 0x3B, 0xC4,
  41634. 0x5D, 0xB3, 0x0C, 0xB8, 0x64, 0x65, 0xDF, 0x11,
  41635. 0x88, 0xBF, 0x47, 0x95, 0x6E, 0x5B, 0x91, 0x6A,
  41636. 0x80, 0x09, 0x71, 0x5C, 0xC9, 0xA9, 0xA6, 0xDC,
  41637. 0xE4, 0x4C, 0x54, 0xF9, 0x28, 0x81, 0x6B, 0x41,
  41638. 0xD0, 0x18, 0xC5, 0xFE, 0x65, 0x2F, 0xFE, 0x4E,
  41639. 0x33, 0xF3, 0x52, 0xD3, 0x83, 0xA9, 0xC1, 0x36,
  41640. 0x5F, 0x02, 0xAB, 0xFD, 0x64, 0x7B, 0xD6, 0xB4,
  41641. 0x2A, 0xD1, 0x63, 0x73, 0x0F, 0x8B, 0xFD, 0xA1,
  41642. 0xE2, 0xBE, 0x5F, 0x61, 0x4D, 0x79, 0x59, 0x78,
  41643. 0x25, 0xBA, 0x09, 0xF4, 0x57, 0xD3, 0xCB, 0xE7,
  41644. 0x56, 0x1E, 0x7E, 0x89, 0xEA, 0xF0, 0x59, 0xE9,
  41645. 0x77, 0xD1, 0xEE, 0x88, 0x84, 0x8B, 0x78, 0x1F,
  41646. 0x21, 0xF7, 0x23, 0x89, 0x0F, 0xF1, 0xF9, 0x87,
  41647. 0x39, 0x28, 0x41, 0x2C, 0x8F, 0x11, 0xEE, 0xDD,
  41648. 0x2C, 0x0C, 0x39, 0xC9, 0x51, 0x27, 0x90, 0x98,
  41649. 0x6A, 0x19, 0xE1, 0x7B, 0x2B, 0x70, 0xA4, 0xD7,
  41650. 0xCF, 0x49, 0xD9, 0xD1, 0x8C, 0xAA, 0x0C, 0x20,
  41651. 0x23, 0x13, 0x4C, 0xAC, 0xD1, 0x69, 0x20, 0x0D,
  41652. 0x88, 0x17, 0xFA, 0x32, 0x1F, 0x04, 0xAC, 0xC9,
  41653. 0x10, 0x61, 0x3D, 0xFF, 0x25, 0x0E, 0xB3, 0x25,
  41654. 0xDB, 0xEF, 0x29, 0xEB, 0x56, 0x11, 0xB2, 0xAD,
  41655. 0x2A, 0x23, 0xED, 0xD5, 0x38, 0x04, 0x9B, 0x3F,
  41656. 0x43, 0xEF, 0xEB, 0x4D, 0x60, 0x98, 0x37, 0x92,
  41657. 0xB4, 0xBF, 0x05, 0x56, 0x79, 0x44, 0xAA, 0xDB,
  41658. 0x7A, 0xC4, 0xD3, 0xA5, 0xD8, 0x0A, 0x1B, 0x9D,
  41659. 0x84, 0x48, 0xB4, 0xC0, 0xC1, 0x15, 0xC3, 0xB5,
  41660. 0xAD, 0x38, 0x85, 0x35, 0x3F, 0x47, 0xD5, 0xFC,
  41661. 0xB9, 0xB7, 0xD6, 0x44, 0x6F, 0x1A, 0x72, 0x10,
  41662. 0xBB, 0xC6, 0x67, 0xFC, 0x41, 0x14, 0x15, 0xF2,
  41663. 0x3C, 0xD4, 0x0A, 0x2A, 0x3D, 0x64, 0x06, 0x1D,
  41664. 0x71, 0xC6, 0x71, 0x91, 0x57, 0x1A, 0x97, 0xD0,
  41665. 0x10, 0x88, 0xA2, 0x4B, 0x67, 0x11, 0x56, 0x7F,
  41666. 0xC8, 0x91, 0x06, 0x73, 0x2D, 0x88, 0x92, 0xFF,
  41667. 0x98, 0x5B, 0x8E, 0x6C, 0xF7, 0x01, 0x63, 0x82,
  41668. 0x9C, 0xC0, 0x85, 0xBE, 0x4E, 0x40, 0x83, 0x15,
  41669. 0x36, 0x1B, 0xB1, 0xB2, 0x00, 0x3D, 0x64, 0x13,
  41670. 0x22, 0x0B, 0x13, 0x45, 0x06, 0xD3, 0xC3, 0x04,
  41671. 0xC0, 0xBB, 0xBA, 0x9C, 0x9C, 0x45, 0xD3, 0x65,
  41672. 0x1E, 0x05, 0x71, 0xB6, 0xB1, 0x15, 0x17, 0x72,
  41673. 0x13, 0xD8, 0x59, 0x5E, 0x14, 0x3D, 0xB9, 0x0B,
  41674. 0xD7, 0x2F, 0x7E, 0xB9, 0x74, 0xD8, 0xD0, 0xA0,
  41675. 0x31, 0x74, 0x09, 0xD6, 0x4D, 0x58, 0x37, 0xEA,
  41676. 0xEC, 0x9B, 0x8D, 0x44, 0xDD, 0x7E, 0xCF, 0xF6,
  41677. 0xCD, 0xA9, 0xF7, 0x29, 0x38, 0x2A, 0x43, 0xB3,
  41678. 0x79, 0xCB, 0xDD, 0x43, 0xFF, 0xB1, 0x8A, 0xEA,
  41679. 0x35, 0xC1, 0xA9, 0x96, 0xCE, 0xF1, 0x48, 0x8D,
  41680. 0x3B, 0x7A, 0x81, 0xEE, 0x7C, 0xFC, 0x0B, 0x96,
  41681. 0x23, 0x41, 0x8A, 0xB3, 0x91, 0x9A, 0x6E, 0xDD,
  41682. 0xB9, 0x9F, 0x22, 0x2F, 0x0D, 0xDD, 0xB2, 0xF3,
  41683. 0x2A, 0x20, 0xC8, 0xF8, 0x4F, 0xBF, 0x4C, 0x49,
  41684. 0xB4, 0xCB, 0x3E, 0xB5, 0x0D, 0x9C, 0x4C, 0xD2,
  41685. 0x5A, 0x6F, 0x71, 0x75, 0x46, 0x70, 0x66, 0xD2,
  41686. 0x5E, 0x64, 0x37, 0xB6, 0x7F, 0x2D, 0xBC, 0x70,
  41687. 0xC2, 0xE6, 0xEB, 0x0B, 0xDE, 0x23, 0x86, 0xD0,
  41688. 0x30, 0x14, 0xA7, 0x89, 0xFB, 0x6D, 0xC0, 0x8E,
  41689. 0xE3, 0x3C, 0x0C, 0x67, 0x95, 0x1D, 0xA9, 0xD7,
  41690. 0x4B, 0x9C, 0x94, 0x84, 0x5D, 0x2A, 0x99, 0x03,
  41691. 0x7E, 0x09, 0x5F, 0xEF, 0x79, 0x19, 0x92, 0x0F,
  41692. 0xE5, 0x26, 0xEB, 0x5D, 0xD0, 0xBA, 0x1F, 0x97,
  41693. 0xDF, 0xBD, 0x2D, 0xDC, 0x31, 0x60, 0x9C, 0x1B,
  41694. 0x7B, 0x45, 0xEC, 0x3A, 0xDB, 0x58, 0x6F, 0xE3,
  41695. 0x03, 0x0A, 0x0C, 0x7A, 0x9D, 0xD0, 0x34, 0xA3,
  41696. 0xC2, 0xE6, 0xF9, 0x84, 0x90, 0x93, 0xCE, 0xE1,
  41697. 0x0A, 0x18, 0x19, 0x53, 0x54, 0x7F, 0x8B, 0xE3,
  41698. 0x28, 0x72, 0x0A, 0x4A, 0x5A, 0x82, 0x90, 0xB5,
  41699. 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41700. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41701. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
  41702. 0x0B, 0x10, 0x18, 0x1A, 0x21
  41703. };
  41704. #endif
  41705. #ifndef WOLFSSL_NO_ML_DSA_87
  41706. static const byte pk_87[] = {
  41707. 0x59, 0xB2, 0x37, 0x1F, 0xE7, 0xBA, 0xCC, 0x20,
  41708. 0x7F, 0xE1, 0xFE, 0xE8, 0x8A, 0x8B, 0x38, 0x05,
  41709. 0xA7, 0x05, 0x28, 0x65, 0x69, 0x17, 0x89, 0xBB,
  41710. 0x90, 0x54, 0x2F, 0xA4, 0x7F, 0x7E, 0xF2, 0xB7,
  41711. 0x5F, 0xCA, 0x13, 0xDB, 0xA5, 0x88, 0x8B, 0xEC,
  41712. 0x32, 0x05, 0x14, 0xDC, 0xB0, 0x5F, 0xD2, 0x6E,
  41713. 0xB5, 0x54, 0x1F, 0x6E, 0x57, 0x2E, 0xCE, 0xA6,
  41714. 0xC4, 0xF1, 0xD3, 0x8A, 0xA7, 0x02, 0x59, 0x09,
  41715. 0x4A, 0xA9, 0x45, 0xF1, 0x9F, 0xED, 0x0D, 0x98,
  41716. 0x0E, 0x65, 0xDB, 0xF6, 0x5D, 0xB8, 0x0F, 0x56,
  41717. 0x4F, 0xE2, 0x9D, 0x83, 0x6C, 0x54, 0x79, 0x28,
  41718. 0x8B, 0x55, 0xCF, 0x07, 0xF4, 0xE0, 0x01, 0x59,
  41719. 0xB6, 0x95, 0x5D, 0xAB, 0xDE, 0xCC, 0x8C, 0x4D,
  41720. 0x66, 0xAE, 0x68, 0x87, 0x28, 0xBA, 0x6D, 0x5C,
  41721. 0x04, 0x42, 0xF3, 0xC1, 0x23, 0x2C, 0x78, 0x2C,
  41722. 0x46, 0x5B, 0x9B, 0x7C, 0x50, 0x14, 0xB1, 0x46,
  41723. 0x40, 0x65, 0xCC, 0xD8, 0xA5, 0x6D, 0x6B, 0x1C,
  41724. 0x16, 0x51, 0x08, 0x69, 0xE0, 0x14, 0xE6, 0x93,
  41725. 0x39, 0x98, 0xEF, 0x72, 0x55, 0x20, 0xB4, 0x00,
  41726. 0x91, 0x3D, 0x93, 0xB0, 0xEC, 0x75, 0xE2, 0xFB,
  41727. 0x72, 0x5D, 0xC1, 0xAE, 0xC0, 0xC0, 0xCC, 0x73,
  41728. 0x43, 0xB9, 0xE5, 0x44, 0xBA, 0xA4, 0xD6, 0x79,
  41729. 0x86, 0x0E, 0x34, 0x7B, 0x2E, 0x94, 0x7D, 0x8D,
  41730. 0x24, 0x36, 0xF0, 0x92, 0x98, 0xA7, 0xBB, 0x83,
  41731. 0x36, 0xB9, 0xDE, 0x9C, 0xFD, 0x5C, 0xDB, 0xCD,
  41732. 0x91, 0xC7, 0x24, 0x92, 0x68, 0xCA, 0x03, 0xEF,
  41733. 0xAC, 0x27, 0x3A, 0xF5, 0x29, 0x68, 0xD5, 0x01,
  41734. 0x40, 0x6C, 0xD9, 0xC9, 0x61, 0x59, 0xD7, 0xC1,
  41735. 0x5A, 0xA2, 0x90, 0x03, 0x30, 0xC1, 0x18, 0x9C,
  41736. 0xFC, 0x2C, 0xD8, 0xB9, 0x12, 0xC4, 0x80, 0xE4,
  41737. 0x58, 0x29, 0x7E, 0xF1, 0x4D, 0xB6, 0x94, 0xA3,
  41738. 0xF1, 0xE7, 0x2C, 0x1D, 0xFA, 0x3A, 0x3D, 0x2A,
  41739. 0x8A, 0x69, 0xE0, 0x11, 0x60, 0x2B, 0x93, 0x02,
  41740. 0x0B, 0xAC, 0xD1, 0xC2, 0xF3, 0xAD, 0x06, 0xC9,
  41741. 0x5A, 0x7F, 0x36, 0xEB, 0xF5, 0x26, 0x1F, 0x6E,
  41742. 0xC1, 0x06, 0x81, 0x6B, 0xB3, 0x30, 0x3C, 0xC0,
  41743. 0x0B, 0xF4, 0xE8, 0x68, 0x8D, 0x2E, 0x85, 0x48,
  41744. 0xF1, 0x04, 0x90, 0xD9, 0xEB, 0x23, 0xC5, 0x67,
  41745. 0x93, 0xB3, 0x4B, 0x84, 0x06, 0xCB, 0xE4, 0x43,
  41746. 0xD8, 0x35, 0x6B, 0xCD, 0x0F, 0x4F, 0x61, 0xD0,
  41747. 0xD0, 0x17, 0xD5, 0x48, 0x31, 0xB9, 0xBA, 0x32,
  41748. 0x9F, 0x89, 0x48, 0xF2, 0x5C, 0x31, 0x22, 0xF9,
  41749. 0xDE, 0xDE, 0x8C, 0xEC, 0xBA, 0x51, 0x56, 0x9E,
  41750. 0xDF, 0xFF, 0x89, 0x5F, 0xA0, 0x20, 0x86, 0x2C,
  41751. 0x5D, 0xF7, 0x9F, 0x86, 0x40, 0x78, 0x48, 0x6B,
  41752. 0x5F, 0xB2, 0x28, 0xFD, 0x78, 0x9C, 0x35, 0xFD,
  41753. 0xE1, 0xC5, 0x4B, 0xFF, 0xBF, 0x4A, 0x02, 0x5A,
  41754. 0x7F, 0xE7, 0xD8, 0xC3, 0x49, 0x0A, 0x5D, 0x4E,
  41755. 0x62, 0xD0, 0x4F, 0x79, 0xF4, 0x18, 0x3C, 0xA6,
  41756. 0x83, 0x79, 0xF4, 0x64, 0x8B, 0xD5, 0xB2, 0x41,
  41757. 0x6D, 0xBE, 0x5B, 0x84, 0x5C, 0x9F, 0x4B, 0x7A,
  41758. 0x7E, 0x23, 0x39, 0xC0, 0x50, 0x6D, 0x58, 0x53,
  41759. 0x9E, 0xAE, 0xA9, 0x45, 0x1C, 0x9B, 0x2F, 0xE2,
  41760. 0xA1, 0x8C, 0x84, 0x9D, 0xCA, 0x7E, 0xED, 0x9D,
  41761. 0xAC, 0xC0, 0x58, 0xD0, 0x05, 0xFB, 0x73, 0x75,
  41762. 0xC4, 0xEF, 0x45, 0xB0, 0x01, 0x54, 0x3F, 0xC6,
  41763. 0x8E, 0x47, 0xDD, 0xB6, 0xD1, 0x4F, 0xF9, 0x37,
  41764. 0xD1, 0xAA, 0x0D, 0x4D, 0x74, 0x89, 0xDF, 0xFA,
  41765. 0x62, 0x10, 0x67, 0x9C, 0xCC, 0xEC, 0xF9, 0xB8,
  41766. 0x55, 0x1D, 0xCF, 0x68, 0x2D, 0x2A, 0xF1, 0xE5,
  41767. 0xBD, 0x86, 0x9F, 0x3E, 0x8D, 0x40, 0x0D, 0x5C,
  41768. 0x86, 0x1A, 0xE5, 0x1F, 0xE7, 0xEB, 0xBB, 0x54,
  41769. 0x57, 0xF2, 0xEA, 0xAF, 0xD0, 0x93, 0xA9, 0x59,
  41770. 0x8E, 0xC7, 0x21, 0xC6, 0x93, 0x27, 0xC5, 0x19,
  41771. 0x30, 0xF4, 0xB9, 0xFF, 0xB2, 0xAA, 0x7F, 0x1A,
  41772. 0x28, 0x43, 0x6B, 0x6D, 0x80, 0x8D, 0x75, 0x39,
  41773. 0x2B, 0xC4, 0x3C, 0x1B, 0x5B, 0x85, 0x9C, 0x66,
  41774. 0xC5, 0x4F, 0xA5, 0x15, 0xC7, 0xA6, 0x15, 0xA6,
  41775. 0x9E, 0x60, 0x92, 0x14, 0x34, 0xAA, 0x9C, 0xF9,
  41776. 0xF9, 0xE0, 0x3C, 0x3C, 0xA3, 0x5B, 0x5E, 0xBC,
  41777. 0x6A, 0x40, 0x9E, 0x82, 0x2F, 0xE7, 0x6E, 0x09,
  41778. 0x24, 0xC6, 0xC0, 0x62, 0xF1, 0x72, 0x4C, 0x38,
  41779. 0x2F, 0xF3, 0xC8, 0xAC, 0xB5, 0xC1, 0x66, 0x6C,
  41780. 0x2E, 0xC2, 0x6B, 0x76, 0x28, 0xE3, 0xD7, 0xC1,
  41781. 0x3D, 0xA8, 0xD7, 0x58, 0x89, 0x0E, 0x6C, 0xC0,
  41782. 0x17, 0xB7, 0x89, 0x25, 0x82, 0xE9, 0x5E, 0xDD,
  41783. 0x04, 0xBA, 0x93, 0x45, 0xDF, 0x70, 0xFA, 0xD5,
  41784. 0x6E, 0xA6, 0x8B, 0xF8, 0x87, 0x5B, 0x93, 0x2C,
  41785. 0x28, 0xB3, 0x28, 0x07, 0xC8, 0x63, 0x71, 0xE1,
  41786. 0x7D, 0xCC, 0x04, 0x72, 0x5C, 0xB5, 0x97, 0xB5,
  41787. 0x24, 0x46, 0x79, 0x63, 0xE1, 0xD4, 0xA6, 0x1B,
  41788. 0x5F, 0xBF, 0x9E, 0xC5, 0x04, 0xD5, 0xDD, 0xB6,
  41789. 0x17, 0x93, 0xDD, 0x4E, 0x34, 0xAE, 0x08, 0x2A,
  41790. 0x59, 0x90, 0xEF, 0xCE, 0x80, 0x1E, 0x93, 0x8C,
  41791. 0xCA, 0xE7, 0x38, 0xE0, 0x2E, 0x90, 0x59, 0x9D,
  41792. 0x97, 0x1C, 0x2D, 0x7C, 0x64, 0xE5, 0xB6, 0xF8,
  41793. 0x63, 0x9F, 0x75, 0x8E, 0xD6, 0x21, 0xC1, 0xF2,
  41794. 0x10, 0x73, 0xC0, 0x3E, 0xDB, 0x78, 0x2C, 0x7A,
  41795. 0x0F, 0x5D, 0x7C, 0x66, 0xF5, 0xCE, 0x16, 0x1D,
  41796. 0xED, 0x55, 0xB3, 0xE9, 0x2D, 0xC2, 0x71, 0x83,
  41797. 0xAB, 0x08, 0x3D, 0xBC, 0x1F, 0x39, 0x30, 0xAE,
  41798. 0x56, 0xED, 0xB8, 0xC5, 0x3E, 0x9A, 0x7E, 0x02,
  41799. 0x0F, 0xFF, 0x0C, 0x40, 0x42, 0xF5, 0x18, 0xB2,
  41800. 0x6F, 0x39, 0x0C, 0x96, 0xC8, 0x18, 0x3B, 0x79,
  41801. 0xB5, 0x3C, 0x7C, 0x7B, 0xC5, 0x15, 0x18, 0x7B,
  41802. 0x3D, 0xE8, 0xCA, 0xB0, 0x87, 0x69, 0xC5, 0xDD,
  41803. 0x6F, 0xF5, 0x49, 0x21, 0x12, 0xE8, 0xB0, 0xF2,
  41804. 0x8D, 0x09, 0xF4, 0x06, 0x7A, 0xDB, 0x04, 0x19,
  41805. 0x4F, 0x60, 0x25, 0x0E, 0x75, 0xAD, 0xE3, 0x31,
  41806. 0xA5, 0xC2, 0x55, 0x93, 0xBC, 0xD9, 0x2A, 0x6D,
  41807. 0x13, 0x50, 0x43, 0x95, 0x85, 0x86, 0x0B, 0xB6,
  41808. 0xFE, 0xED, 0xBD, 0x2F, 0x83, 0x9F, 0x31, 0x7A,
  41809. 0x01, 0x35, 0x88, 0x76, 0xC8, 0x8E, 0x89, 0x8A,
  41810. 0xC0, 0xC8, 0x53, 0x78, 0xF5, 0x72, 0xF2, 0x3C,
  41811. 0xDE, 0x93, 0x1D, 0x47, 0xDE, 0x71, 0xD3, 0x35,
  41812. 0x3D, 0xAB, 0x1F, 0x81, 0x0A, 0x61, 0xB1, 0x8D,
  41813. 0x24, 0xCD, 0x83, 0xDD, 0xAB, 0x8D, 0x53, 0xBA,
  41814. 0x9C, 0x7B, 0x82, 0x74, 0xB0, 0xFE, 0x82, 0xAF,
  41815. 0xF3, 0x0C, 0x57, 0x07, 0x2F, 0x64, 0x37, 0x87,
  41816. 0xCA, 0x1D, 0xF0, 0x3B, 0x99, 0xEB, 0x57, 0xDB,
  41817. 0xDA, 0x8C, 0x8E, 0xE8, 0xEB, 0x20, 0x1F, 0x28,
  41818. 0x47, 0xCB, 0xC9, 0xD3, 0x4F, 0xD8, 0x0C, 0xE6,
  41819. 0xBC, 0x5E, 0x1E, 0x32, 0x8E, 0xB6, 0xEF, 0xC8,
  41820. 0x3C, 0x4B, 0xD9, 0xD5, 0x2F, 0x32, 0x4E, 0x30,
  41821. 0xEE, 0x4B, 0x5E, 0x86, 0x35, 0x1E, 0x5C, 0x8C,
  41822. 0x4C, 0x54, 0x56, 0x83, 0x6D, 0x5A, 0x45, 0x22,
  41823. 0x03, 0xB3, 0xC3, 0x72, 0xC7, 0x87, 0xAE, 0x33,
  41824. 0x32, 0xC8, 0xA5, 0xE9, 0xDC, 0x21, 0x97, 0xD9,
  41825. 0xC3, 0x41, 0xB9, 0x75, 0x6B, 0xB1, 0xE6, 0x3C,
  41826. 0x75, 0xBB, 0xD5, 0xCF, 0x3E, 0x5C, 0xD4, 0xBF,
  41827. 0x47, 0xBD, 0x1F, 0xEB, 0xC3, 0xE3, 0x71, 0x09,
  41828. 0x12, 0xD6, 0x30, 0x32, 0xF6, 0xB9, 0x7D, 0xC1,
  41829. 0x9C, 0x4D, 0xE1, 0x96, 0xAC, 0xD9, 0x15, 0x77,
  41830. 0x15, 0xE2, 0xC1, 0x4E, 0x05, 0x4A, 0x93, 0x17,
  41831. 0xBF, 0x96, 0xA6, 0x84, 0xBB, 0x96, 0xCE, 0xFB,
  41832. 0x7D, 0x8F, 0xDC, 0xA8, 0xAA, 0x47, 0x7A, 0x2A,
  41833. 0xF6, 0xF7, 0x26, 0xD2, 0xCA, 0xC1, 0xA6, 0x03,
  41834. 0xCF, 0x13, 0x60, 0xEC, 0x11, 0xCA, 0x89, 0x7E,
  41835. 0x5B, 0xC7, 0x35, 0xAB, 0x69, 0xB8, 0x64, 0x7F,
  41836. 0x30, 0xCE, 0xD4, 0x94, 0x7B, 0xA9, 0xF6, 0x35,
  41837. 0xD9, 0xCB, 0x2D, 0x82, 0xA6, 0x62, 0xFF, 0x17,
  41838. 0xA0, 0xE1, 0x2D, 0x4D, 0x06, 0xD6, 0x41, 0xEE,
  41839. 0x76, 0xEB, 0x8B, 0x45, 0xC7, 0x1E, 0xDE, 0x38,
  41840. 0xC9, 0x05, 0xC5, 0x2B, 0xE7, 0x6C, 0x61, 0x09,
  41841. 0xF2, 0x61, 0x2F, 0xEE, 0x6C, 0x31, 0x94, 0x46,
  41842. 0x5C, 0x19, 0xBA, 0x5D, 0x3E, 0xBC, 0xF1, 0xF0,
  41843. 0xB5, 0xE5, 0x34, 0xE0, 0xF0, 0xF1, 0xD3, 0x1C,
  41844. 0xB1, 0xE7, 0xA3, 0x6C, 0x43, 0x03, 0xF2, 0x83,
  41845. 0xDB, 0xA8, 0x59, 0x1C, 0xC6, 0x09, 0x31, 0x1A,
  41846. 0x80, 0x9E, 0x44, 0x4E, 0x33, 0xA8, 0x93, 0x88,
  41847. 0x0C, 0xDB, 0xAE, 0x29, 0x11, 0x91, 0x46, 0xA3,
  41848. 0x68, 0xE4, 0xD2, 0xED, 0xD9, 0x1F, 0xE4, 0x71,
  41849. 0x64, 0x7F, 0xFE, 0x82, 0x1A, 0xA6, 0xD3, 0x1C,
  41850. 0x9F, 0xA4, 0x96, 0x95, 0xEB, 0x99, 0x41, 0xB0,
  41851. 0x8F, 0x7B, 0xE3, 0xF0, 0x6C, 0xDD, 0xF2, 0x73,
  41852. 0x9B, 0x8C, 0xAD, 0x2A, 0xB0, 0xDA, 0x4F, 0x5A,
  41853. 0x3C, 0x0A, 0x26, 0xDF, 0x6A, 0x17, 0xB1, 0x37,
  41854. 0xCA, 0xAB, 0x3B, 0x91, 0x9A, 0xB6, 0x36, 0xD6,
  41855. 0xC8, 0x9B, 0xED, 0xA3, 0x05, 0x88, 0x98, 0x62,
  41856. 0x87, 0x21, 0xF2, 0x77, 0x03, 0x15, 0xFE, 0xEE,
  41857. 0x88, 0x15, 0x95, 0xE2, 0x4C, 0xF4, 0x8B, 0x44,
  41858. 0x16, 0x60, 0xD0, 0xB2, 0xE9, 0xD5, 0xB9, 0x09,
  41859. 0x28, 0xC3, 0x81, 0xF2, 0xB0, 0xFA, 0x26, 0x34,
  41860. 0x2E, 0x4C, 0x9B, 0x88, 0xC0, 0x88, 0x7A, 0x46,
  41861. 0x87, 0x12, 0x4C, 0x01, 0x2D, 0x96, 0x9E, 0x1A,
  41862. 0xFD, 0x85, 0x32, 0x75, 0x4B, 0xA1, 0x21, 0x25,
  41863. 0xE9, 0x43, 0x3D, 0xCF, 0x6D, 0x7B, 0xC1, 0xA3,
  41864. 0x6A, 0x83, 0xE6, 0xA1, 0x0B, 0xA1, 0xCB, 0x76,
  41865. 0x52, 0xA8, 0x13, 0x50, 0x89, 0x9C, 0x2D, 0xFC,
  41866. 0x6E, 0x4F, 0xED, 0x38, 0xD0, 0x09, 0xE6, 0xD0,
  41867. 0xF1, 0xD4, 0x4C, 0xCC, 0xB9, 0x5E, 0x55, 0x1B,
  41868. 0x3A, 0xD5, 0x4B, 0x3A, 0xC8, 0x1E, 0x8B, 0xA4,
  41869. 0x66, 0x5E, 0xA4, 0x28, 0xB3, 0xC8, 0x61, 0xE8,
  41870. 0x67, 0x78, 0x90, 0xCF, 0x5F, 0x62, 0x5C, 0x19,
  41871. 0xA7, 0xC5, 0x94, 0x3A, 0x94, 0x01, 0xCB, 0x78,
  41872. 0xE7, 0x02, 0x6B, 0xAE, 0x92, 0xB6, 0x0A, 0x8B,
  41873. 0x68, 0x07, 0xC1, 0x77, 0x45, 0x41, 0x5C, 0xD8,
  41874. 0xE0, 0x30, 0xC6, 0x4C, 0x56, 0xE8, 0x22, 0x13,
  41875. 0x9A, 0x35, 0xDA, 0x42, 0x3F, 0x26, 0x43, 0x36,
  41876. 0xE0, 0xAF, 0xDF, 0x16, 0x74, 0x30, 0xDD, 0x36,
  41877. 0xE0, 0x06, 0x4B, 0x2F, 0x6E, 0x8D, 0x8B, 0xB6,
  41878. 0xBE, 0x99, 0xC5, 0xA9, 0xFB, 0x55, 0x1C, 0xC6,
  41879. 0x3E, 0x50, 0x8D, 0xB6, 0x36, 0x66, 0x7D, 0xDA,
  41880. 0x53, 0xF6, 0x11, 0xF0, 0x2F, 0xCD, 0x1F, 0x99,
  41881. 0x41, 0x0F, 0x1A, 0x7A, 0x82, 0x88, 0x2F, 0x96,
  41882. 0x23, 0xAD, 0xDC, 0x50, 0xEB, 0x01, 0xE1, 0xF3,
  41883. 0x99, 0x78, 0xBF, 0x68, 0x50, 0x6C, 0x71, 0xDB,
  41884. 0xBE, 0xE4, 0x2E, 0x4A, 0x80, 0x06, 0x9B, 0x0E,
  41885. 0x4C, 0x7F, 0xC4, 0xCC, 0x14, 0x71, 0xF4, 0xF1,
  41886. 0x02, 0x8D, 0xB2, 0x5C, 0x46, 0x87, 0xB6, 0x0D,
  41887. 0xF4, 0x25, 0x5D, 0xEC, 0x91, 0x48, 0x19, 0x7A,
  41888. 0x74, 0x79, 0x6E, 0xC7, 0x60, 0xA6, 0x6A, 0xFC,
  41889. 0x78, 0x84, 0x03, 0x86, 0x51, 0x92, 0x09, 0x73,
  41890. 0xA6, 0x9C, 0x20, 0x35, 0x16, 0x22, 0x26, 0x32,
  41891. 0xEC, 0x58, 0x75, 0xEA, 0x6D, 0x83, 0x80, 0x96,
  41892. 0xE7, 0xFE, 0x9B, 0x5B, 0x4F, 0xB6, 0x9C, 0x5E,
  41893. 0x94, 0x07, 0xE7, 0x0D, 0x27, 0xFA, 0x34, 0xB0,
  41894. 0xCD, 0xBD, 0x6E, 0x11, 0x9D, 0x87, 0xCE, 0x38,
  41895. 0x58, 0x1D, 0xF1, 0xD3, 0xE0, 0xDF, 0x3A, 0xE0,
  41896. 0x29, 0x04, 0x2A, 0x3B, 0x20, 0xE9, 0x23, 0xEB,
  41897. 0xCE, 0x19, 0xA4, 0x95, 0x87, 0x55, 0xEE, 0x2F,
  41898. 0x98, 0xFD, 0x23, 0x4C, 0x44, 0x13, 0xE2, 0xDB,
  41899. 0xC9, 0x35, 0x59, 0xA4, 0x28, 0xDC, 0x37, 0xF2,
  41900. 0xD1, 0x23, 0x5B, 0xD4, 0x41, 0x9B, 0x09, 0x9E,
  41901. 0x0F, 0x0D, 0xE5, 0x42, 0xC4, 0x69, 0x35, 0x99,
  41902. 0x1B, 0xE0, 0x69, 0x2A, 0x6D, 0x80, 0xB8, 0xFD,
  41903. 0x98, 0x86, 0xE0, 0xFA, 0x17, 0x69, 0xB4, 0x9E,
  41904. 0x8A, 0xE6, 0x30, 0x7C, 0xB0, 0xBC, 0x1B, 0x49,
  41905. 0x73, 0x2D, 0x26, 0xE2, 0x5C, 0xA1, 0xCD, 0x9D,
  41906. 0x40, 0x7E, 0x0D, 0x88, 0x64, 0x04, 0x09, 0x41,
  41907. 0x61, 0x1F, 0x93, 0x33, 0xB6, 0x36, 0x7E, 0x83,
  41908. 0x00, 0xFD, 0x64, 0x6A, 0xC5, 0xA7, 0x1A, 0xD9,
  41909. 0x13, 0xEE, 0xFD, 0x80, 0x8D, 0x5C, 0xAF, 0xBF,
  41910. 0x15, 0x21, 0xA3, 0x06, 0x2E, 0xC1, 0x84, 0xE5,
  41911. 0x21, 0x65, 0x50, 0x1E, 0x00, 0x55, 0x56, 0xDE,
  41912. 0x4D, 0xEE, 0x46, 0xF9, 0xE5, 0x3D, 0x7D, 0xEF,
  41913. 0x99, 0x09, 0xF3, 0xD5, 0xD9, 0x8C, 0xA8, 0x0D,
  41914. 0x87, 0x70, 0x7F, 0x7B, 0xC0, 0xFF, 0x8D, 0x87,
  41915. 0x9D, 0x65, 0xD4, 0xD7, 0x83, 0xD1, 0x96, 0xF2,
  41916. 0x46, 0x06, 0x93, 0x81, 0x1C, 0xDF, 0x33, 0x35,
  41917. 0x8E, 0x08, 0x2D, 0x81, 0xF4, 0xDB, 0x8F, 0x6C,
  41918. 0x20, 0x48, 0x61, 0x83, 0xA3, 0x6D, 0x4F, 0xBC,
  41919. 0xC8, 0xA1, 0xC6, 0xDA, 0x21, 0xAA, 0x4D, 0xD1,
  41920. 0x36, 0xE1, 0x9F, 0xEF, 0x2E, 0xA9, 0x93, 0x97,
  41921. 0x2B, 0xB9, 0x98, 0x9A, 0xC1, 0xC3, 0x8A, 0x79,
  41922. 0xF3, 0x18, 0x52, 0x17, 0x80, 0x04, 0x12, 0x3C,
  41923. 0x46, 0x27, 0x7D, 0x38, 0xA8, 0x8F, 0xC1, 0x58,
  41924. 0x9F, 0x25, 0x73, 0x32, 0x28, 0x4C, 0xD8, 0xA8,
  41925. 0x73, 0xC2, 0x5A, 0x1A, 0x6D, 0x40, 0x26, 0x5B,
  41926. 0x28, 0x5D, 0xF0, 0x93, 0x70, 0xE8, 0x8F, 0x72,
  41927. 0xFF, 0x70, 0xE4, 0x34, 0xE8, 0xF6, 0x60, 0x84,
  41928. 0xCC, 0xFE, 0xBD, 0xBB, 0xC4, 0xB9, 0x9E, 0xDF,
  41929. 0xBC, 0x75, 0x0C, 0xC5, 0xDE, 0xA6, 0x36, 0x17,
  41930. 0xF6, 0x47, 0xF5, 0xF0, 0x21, 0xD5, 0x7D, 0x64,
  41931. 0xD5, 0xEF, 0xF0, 0x48, 0x63, 0x4D, 0xB2, 0x20,
  41932. 0x9D, 0x7C, 0x8B, 0x82, 0xFB, 0x63, 0xB8, 0x82,
  41933. 0x3E, 0x4C, 0xA0, 0x57, 0x16, 0x8B, 0xAE, 0x88,
  41934. 0xD9, 0x71, 0x52, 0x91, 0x24, 0x0B, 0x37, 0x58,
  41935. 0xD7, 0x68, 0x45, 0x01, 0xF8, 0x61, 0x86, 0x7B,
  41936. 0x7A, 0x24, 0x1C, 0x06, 0x3B, 0x05, 0xD5, 0xE8,
  41937. 0xCA, 0x6B, 0x4C, 0x79, 0xCB, 0x24, 0x35, 0xD7,
  41938. 0xF9, 0x94, 0xCB, 0x76, 0x91, 0x5B, 0x4A, 0x54,
  41939. 0x87, 0x08, 0xB1, 0x1B, 0x29, 0x44, 0x96, 0x85,
  41940. 0x94, 0x1D, 0x43, 0xE6, 0x0A, 0x89, 0x76, 0xF9,
  41941. 0xA9, 0x60, 0x72, 0xF9, 0x10, 0x41, 0xF4, 0xC3,
  41942. 0xDF, 0x7C, 0x73, 0x96, 0x90, 0x12, 0xAE, 0x1B,
  41943. 0x30, 0xE4, 0xB9, 0xC4, 0xE1, 0x33, 0x55, 0x8D,
  41944. 0xAB, 0xC4, 0x6C, 0x10, 0x3C, 0x0C, 0xB1, 0xDF,
  41945. 0xB9, 0x9B, 0x58, 0x53, 0x74, 0xA5, 0x4F, 0x9B,
  41946. 0xA5, 0x6B, 0x72, 0x48, 0xB8, 0xC3, 0xF6, 0x6F,
  41947. 0x1D, 0x55, 0x76, 0x0D, 0x6A, 0xBB, 0x43, 0x03,
  41948. 0x75, 0x77, 0x4D, 0xFB, 0xA2, 0x05, 0x9C, 0x5D,
  41949. 0xDD, 0xB6, 0x59, 0xFD, 0x2E, 0x1D, 0xA9, 0xC3,
  41950. 0xF0, 0xB8, 0x08, 0x68, 0xC9, 0x2B, 0xCA, 0xC1,
  41951. 0x04, 0x03, 0xDC, 0xD1, 0x40, 0xD6, 0xA3, 0xD3,
  41952. 0xF3, 0x5F, 0x8E, 0xF1, 0xA2, 0xDD, 0x98, 0xDE,
  41953. 0x1A, 0x43, 0x34, 0x23, 0x85, 0x99, 0xED, 0xAD,
  41954. 0x92, 0x0D, 0xC0, 0xAA, 0x69, 0x8E, 0x9F, 0xE6,
  41955. 0x10, 0x6A, 0x07, 0x80, 0xC9, 0xC2, 0x45, 0xF2,
  41956. 0xC6, 0x5A, 0x0C, 0x3E, 0x5C, 0xD5, 0x36, 0x61,
  41957. 0x10, 0xB1, 0x76, 0x0F, 0xCD, 0x41, 0x4D, 0x45,
  41958. 0x0D, 0xB9, 0xD7, 0x6A, 0x22, 0xA9, 0xEA, 0xEA,
  41959. 0x0C, 0x9F, 0xB7, 0x2E, 0xD5, 0x43, 0xCE, 0x9F,
  41960. 0xA3, 0x31, 0x4B, 0xAB, 0x17, 0x68, 0x7E, 0x9D,
  41961. 0xE5, 0xAD, 0xAD, 0x75, 0x61, 0xF1, 0xA5, 0xBE,
  41962. 0xC1, 0x63, 0x39, 0x26, 0x9A, 0x87, 0xE0, 0x9A,
  41963. 0xCB, 0x29, 0xE4, 0xC4, 0x39, 0x60, 0x5E, 0x95,
  41964. 0x72, 0xAA, 0x9B, 0x7D, 0x0E, 0x83, 0x71, 0xA3,
  41965. 0x0E, 0x41, 0xA0, 0xA7, 0xBD, 0xC0, 0x2D, 0xA3,
  41966. 0xA6, 0x12, 0x1B, 0xF2, 0x61, 0xEA, 0xA0, 0x16,
  41967. 0xA2, 0x07, 0x4E, 0x44, 0x32, 0xCF, 0x63, 0xAF,
  41968. 0x96, 0xBE, 0x81, 0xCE, 0xB6, 0xE0, 0xC2, 0x67,
  41969. 0x6A, 0x85, 0x45, 0xC6, 0x6D, 0x2F, 0x30, 0xC9,
  41970. 0x8B, 0x54, 0x24, 0xF0, 0xFE, 0xF0, 0x4B, 0x3C,
  41971. 0x6C, 0x70, 0x64, 0xE2, 0xD2, 0xE1, 0x1C, 0xBE,
  41972. 0x60, 0xF8, 0x57, 0x23, 0xFF, 0xC0, 0xB7, 0x70,
  41973. 0xD6, 0x86, 0x6F, 0xFA, 0x58, 0x9E, 0x3F, 0x9B,
  41974. 0x2A, 0xBF, 0x75, 0x10, 0x40, 0x19, 0xAA, 0x69,
  41975. 0xCB, 0x58, 0x89, 0x5B, 0x47, 0x4A, 0x0A, 0xDE,
  41976. 0x2B, 0x60, 0xA4, 0xAB, 0x07, 0x7C, 0x3A, 0x6D,
  41977. 0xF6, 0x15, 0x33, 0x4E, 0xBB, 0xE7, 0x32, 0xE9,
  41978. 0x52, 0x20, 0x21, 0x39, 0x94, 0xD3, 0xBD, 0xC4,
  41979. 0x43, 0xC8, 0xEF, 0x94, 0xAD, 0x51, 0x5F, 0x45,
  41980. 0x41, 0x83, 0x55, 0x18, 0x33, 0x14, 0x48, 0x58,
  41981. 0x57, 0xAC, 0x12, 0xBA, 0x1D, 0x62, 0xCF, 0x4F,
  41982. 0xD4, 0xF4, 0xDE, 0x2A, 0x7F, 0xFF, 0x1E, 0xCF,
  41983. 0x0D, 0x29, 0x0C, 0x4C, 0xDF, 0xFA, 0x88, 0xD8,
  41984. 0xF4, 0x8C, 0x5B, 0x83, 0x7D, 0x3A, 0x94, 0xCD,
  41985. 0x17, 0xB3, 0xD1, 0x69, 0x96, 0x6E, 0xB0, 0x38,
  41986. 0xFE, 0x5A, 0x6E, 0x85, 0xDF, 0xC6, 0x0A, 0x00,
  41987. 0x23, 0x3F, 0x10, 0x73, 0x19, 0x73, 0xDC, 0x47,
  41988. 0x5D, 0x53, 0xBC, 0x7B, 0x9E, 0x60, 0x32, 0x0B,
  41989. 0xA7, 0x90, 0x5D, 0x88, 0x51, 0x9F, 0xA3, 0x25,
  41990. 0xDF, 0x5A, 0xB0, 0x2B, 0x40, 0xF2, 0xAB, 0xBD,
  41991. 0xB3, 0x7D, 0x22, 0x61, 0xCB, 0x81, 0x48, 0x27,
  41992. 0x7B, 0x87, 0xAE, 0x32, 0x97, 0x97, 0x6C, 0x80,
  41993. 0xC3, 0x51, 0x34, 0xE5, 0xF7, 0x86, 0x90, 0x45,
  41994. 0x64, 0xC1, 0x46, 0x99, 0x47, 0xF6, 0x20, 0xFE,
  41995. 0x09, 0xFD, 0xF3, 0x86, 0x2C, 0x40, 0x57, 0xA3,
  41996. 0xBC, 0xEF, 0x70, 0x75, 0x0C, 0xB7, 0x27, 0xF0,
  41997. 0x31, 0x28, 0x3A, 0x18, 0x26, 0xF1, 0x38, 0x1B,
  41998. 0x33, 0x48, 0xE3, 0xEA, 0x46, 0x88, 0x60, 0x9E,
  41999. 0xCB, 0x19, 0x3A, 0xFA, 0xAE, 0xE1, 0xCD, 0x97,
  42000. 0xE4, 0xDD, 0xAA, 0x02, 0xC0, 0xC3, 0x0E, 0x49,
  42001. 0xF1, 0x37, 0xD0, 0x82, 0x85, 0x94, 0x15, 0x28,
  42002. 0x10, 0x17, 0x59, 0xA7, 0x42, 0x2A, 0xA4, 0x99,
  42003. 0xC9, 0x00, 0xA3, 0x79, 0xDD, 0x73, 0xB3, 0x07,
  42004. 0x28, 0x4C, 0xCD, 0xDA, 0xF1, 0xFA, 0x1B, 0x0C,
  42005. 0x4B, 0x28, 0x0E, 0x3F, 0x9F, 0x1D, 0xB6, 0xD3,
  42006. 0x8E, 0xCF, 0x8A, 0x84, 0x1F, 0x9D, 0x4E, 0x40,
  42007. 0xEC, 0xA8, 0x62, 0x47, 0xD6, 0xCD, 0x9B, 0x31,
  42008. 0xEA, 0xCD, 0x6A, 0x46, 0xF0, 0xE3, 0x33, 0xB9,
  42009. 0xE8, 0x3D, 0x69, 0x0D, 0x7E, 0x13, 0x46, 0x76,
  42010. 0x19, 0xB4, 0x6A, 0xF9, 0xAF, 0xCF, 0xDC, 0x4A,
  42011. 0xA9, 0xA0, 0x49, 0xB1, 0x80, 0x26, 0x0D, 0x70,
  42012. 0xD9, 0xEE, 0xDB, 0x8A, 0x53, 0x30, 0x51, 0xAB,
  42013. 0x83, 0x51, 0x7A, 0xAD, 0xC2, 0xCD, 0x90, 0x0B,
  42014. 0x3E, 0xA5, 0x12, 0x60, 0xF4, 0x64, 0xAF, 0xC5,
  42015. 0xD2, 0xDC, 0x41, 0x10, 0x29, 0x77, 0x9B, 0x21,
  42016. 0xCE, 0x2C, 0xBD, 0x16, 0x02, 0x18, 0xDF, 0x41,
  42017. 0xF6, 0x61, 0xDA, 0x1A, 0xD9, 0x5A, 0xD4, 0x0B,
  42018. 0x8C, 0x35, 0x3C, 0x7F, 0x10, 0xFC, 0x23, 0xF8,
  42019. 0x30, 0xD1, 0x17, 0xBC, 0xAE, 0xF8, 0xCE, 0xCE,
  42020. 0xBC, 0xBF, 0xA4, 0x9D, 0x79, 0xD8, 0xD9, 0x39,
  42021. 0x1E, 0x8D, 0x08, 0x28, 0x1F, 0x00, 0x0A, 0x55,
  42022. 0xE9, 0x2D, 0xB3, 0x31, 0xBD, 0xEC, 0xD7, 0x31,
  42023. 0x83, 0xE0, 0x58, 0xFF, 0x3F, 0xE5, 0x83, 0x9A,
  42024. 0xF5, 0x0D, 0x8C, 0x55, 0xF2, 0x2F, 0x6A, 0xFF,
  42025. 0x5A, 0x33, 0xDA, 0x77, 0x4B, 0xA1, 0xB3, 0xE6,
  42026. 0x43, 0xF5, 0x87, 0x7C, 0xF5, 0x49, 0xC4, 0xF9,
  42027. 0x08, 0xEA, 0x64, 0xA3, 0x7D, 0xF3, 0xBF, 0xA4,
  42028. 0xCD, 0x5F, 0x70, 0xF8, 0xCD, 0x15, 0x44, 0x76,
  42029. 0xD3, 0x4B, 0xC8, 0x53, 0xC9, 0xE8, 0xF7, 0x97,
  42030. 0x9E, 0x5F, 0x4E, 0xBB, 0x88, 0x8A, 0xF7, 0x61
  42031. };
  42032. static const byte msg_87[] = {
  42033. 0x4A, 0xC4, 0x67, 0x5C, 0x96, 0xD9, 0x11, 0x7D,
  42034. 0x1E, 0xDE, 0xB8, 0x0D, 0x7C, 0xD2, 0x84, 0xA3,
  42035. 0xE1, 0xE1, 0xFE, 0x03, 0x8E, 0x30, 0x12, 0x05,
  42036. 0xB4, 0xC4, 0x08, 0xEB, 0x96, 0x52, 0x35, 0xAD,
  42037. 0x1C, 0x85, 0xF8, 0xBE, 0x3F, 0x77, 0xCA, 0x48,
  42038. 0x6F, 0xD2, 0x07, 0xF7, 0xC7, 0x5F, 0x41, 0x21,
  42039. 0xCD, 0x3C, 0xA2, 0xB2, 0x3D, 0x6B, 0xCE, 0x43,
  42040. 0x82, 0xA6, 0xD3, 0x61, 0x21, 0x81, 0x50, 0x25,
  42041. 0xD5, 0x80, 0x6C, 0xBE, 0xF4, 0x52, 0xE0, 0x83,
  42042. 0x93, 0x3C, 0x6E, 0x5C, 0x73, 0x94, 0xAC, 0x88,
  42043. 0x26, 0x2A, 0x6D, 0xE7, 0x77, 0x0B, 0x2D, 0x88,
  42044. 0x43, 0xEC, 0x10, 0x1F, 0xFB, 0x5E, 0x84, 0xDE,
  42045. 0x2F, 0x7A, 0x8B, 0x74, 0xE7, 0x67, 0x4B, 0x3B,
  42046. 0x23, 0x19, 0xBD, 0x6B, 0xF4, 0x11, 0x2F, 0x92,
  42047. 0xC5, 0xCF, 0xC0, 0xA5, 0x5F, 0x7F, 0xA0, 0x61,
  42048. 0xF4, 0x53, 0x25, 0x40, 0x8D, 0x03, 0x9D, 0x51
  42049. };
  42050. static const byte sig_87[] = {
  42051. 0x4B, 0x3F, 0x52, 0xF0, 0x81, 0xB3, 0xD9, 0x14,
  42052. 0xBC, 0x7C, 0x6C, 0x07, 0x3B, 0x18, 0x2B, 0x26,
  42053. 0x8A, 0xDF, 0x51, 0x89, 0xE2, 0x98, 0xA8, 0x69,
  42054. 0xBF, 0xB9, 0x91, 0xB1, 0x99, 0x99, 0x3C, 0x10,
  42055. 0x42, 0xDE, 0xF5, 0xB5, 0x92, 0x70, 0xB6, 0xCD,
  42056. 0x3F, 0xF8, 0xF9, 0x07, 0xA1, 0xCB, 0x0D, 0x3B,
  42057. 0x6F, 0xED, 0xCA, 0x14, 0x38, 0x38, 0xF8, 0xF8,
  42058. 0x1E, 0x0C, 0x37, 0x0F, 0xFE, 0xEE, 0x6B, 0x25,
  42059. 0xCD, 0x07, 0x03, 0x56, 0x41, 0xA0, 0x51, 0x94,
  42060. 0x4E, 0xAB, 0x51, 0x6C, 0xFB, 0xB8, 0x01, 0x53,
  42061. 0x6B, 0x4F, 0x26, 0x2B, 0x16, 0x19, 0x8E, 0x7D,
  42062. 0xDB, 0x1D, 0x61, 0xC3, 0x5A, 0x64, 0xD9, 0x0D,
  42063. 0x39, 0x48, 0xCE, 0xAA, 0xC8, 0xEE, 0x58, 0x0D,
  42064. 0xCE, 0xF5, 0x40, 0xED, 0x99, 0xD9, 0x12, 0xBB,
  42065. 0xA2, 0xBC, 0x4F, 0x51, 0x45, 0xBB, 0x94, 0x9C,
  42066. 0x73, 0xCC, 0xBD, 0x58, 0x26, 0x13, 0xB1, 0x0E,
  42067. 0xAA, 0xE8, 0x63, 0xAC, 0xA3, 0x46, 0x83, 0xEB,
  42068. 0x92, 0x2B, 0x3D, 0xAD, 0xFC, 0x74, 0xF7, 0x6F,
  42069. 0x47, 0xE4, 0x97, 0x86, 0x02, 0x59, 0x24, 0x02,
  42070. 0xD9, 0x15, 0x43, 0x94, 0xEB, 0x09, 0xFB, 0xC2,
  42071. 0xEB, 0xCC, 0xC5, 0x94, 0x73, 0x2F, 0x2D, 0x8B,
  42072. 0xC3, 0x83, 0x50, 0xE5, 0x53, 0x5A, 0x44, 0x12,
  42073. 0xA7, 0x7A, 0xDD, 0x79, 0x16, 0x60, 0x45, 0x76,
  42074. 0xFD, 0x6A, 0x36, 0x31, 0xE5, 0x15, 0xBA, 0xF2,
  42075. 0x6A, 0x6F, 0x9C, 0xA4, 0x06, 0x1E, 0xBB, 0xDD,
  42076. 0x3B, 0xEC, 0x71, 0x79, 0xAD, 0x58, 0x55, 0x2A,
  42077. 0x5B, 0x50, 0x8F, 0x31, 0x34, 0x8A, 0x56, 0xAD,
  42078. 0x1A, 0xDA, 0x7A, 0x05, 0x35, 0x2C, 0x72, 0xC0,
  42079. 0x04, 0xB9, 0x4C, 0x47, 0xE7, 0x04, 0x9A, 0x10,
  42080. 0xB3, 0xA5, 0x9B, 0xF2, 0x38, 0xA8, 0xDF, 0xC6,
  42081. 0xC7, 0x01, 0x9A, 0x17, 0xF0, 0x5D, 0x5B, 0xFC,
  42082. 0xB9, 0xD9, 0x3D, 0x9D, 0x1C, 0xCB, 0xCB, 0x47,
  42083. 0xF8, 0xC4, 0x38, 0x09, 0x8F, 0xDB, 0xDF, 0xE2,
  42084. 0x3F, 0x9F, 0x78, 0xBC, 0x28, 0x06, 0x99, 0x08,
  42085. 0xC6, 0xB9, 0x89, 0x8B, 0x43, 0x4C, 0xBF, 0x37,
  42086. 0x78, 0x7E, 0x1A, 0xF6, 0xA6, 0xB8, 0x27, 0xE8,
  42087. 0x30, 0xE9, 0xF7, 0x62, 0x9C, 0xD8, 0xF5, 0x10,
  42088. 0x70, 0xC4, 0xC8, 0xA8, 0xDE, 0xB2, 0x60, 0xD0,
  42089. 0x7C, 0x3E, 0x41, 0xD8, 0x49, 0x04, 0x84, 0x87,
  42090. 0x74, 0x91, 0xB3, 0x9A, 0xA6, 0xD9, 0xE1, 0x0D,
  42091. 0x91, 0x74, 0x8B, 0x64, 0xE3, 0x31, 0x60, 0x62,
  42092. 0x9D, 0x8A, 0xE4, 0x3E, 0xFD, 0x5F, 0x85, 0x78,
  42093. 0x1E, 0x69, 0xF7, 0x6B, 0x68, 0x95, 0xC1, 0x41,
  42094. 0xEB, 0xCD, 0xDF, 0xEE, 0xB4, 0x85, 0xA0, 0x0B,
  42095. 0xDB, 0xA4, 0xF7, 0xC9, 0x91, 0xF5, 0x3F, 0x2F,
  42096. 0x84, 0x93, 0x39, 0x26, 0xAF, 0x39, 0xE6, 0x96,
  42097. 0x4A, 0xBF, 0x2D, 0xFE, 0xBB, 0xC1, 0x9A, 0x7E,
  42098. 0x31, 0xC5, 0x07, 0x97, 0xB8, 0xDA, 0x29, 0x31,
  42099. 0xE1, 0x0F, 0x3D, 0xAC, 0x49, 0x3F, 0x19, 0x8D,
  42100. 0xFD, 0x78, 0x5D, 0x21, 0xAD, 0xB2, 0xC0, 0x62,
  42101. 0xB0, 0x97, 0xE8, 0x89, 0xA2, 0x07, 0x37, 0xF1,
  42102. 0x86, 0x00, 0x8F, 0x29, 0x28, 0xF6, 0xB8, 0x4D,
  42103. 0x6E, 0x09, 0xE9, 0x75, 0xA8, 0xF2, 0xAA, 0xAD,
  42104. 0xC7, 0x85, 0x23, 0x42, 0x34, 0xFD, 0xA0, 0x37,
  42105. 0x03, 0xA7, 0xC2, 0x1F, 0x81, 0x2D, 0x65, 0x0B,
  42106. 0xD2, 0x51, 0x0B, 0x30, 0xF0, 0x55, 0x00, 0x81,
  42107. 0x04, 0x7A, 0x15, 0x5C, 0x84, 0x85, 0x86, 0xA9,
  42108. 0x6F, 0x10, 0x0D, 0x77, 0x4F, 0x3E, 0x39, 0xE0,
  42109. 0x29, 0xB0, 0x77, 0x7C, 0xD3, 0x3E, 0x68, 0x31,
  42110. 0x8A, 0x11, 0xC1, 0x98, 0x02, 0x93, 0xFA, 0xD3,
  42111. 0xE7, 0x87, 0xD2, 0x0D, 0xFE, 0x7E, 0xEE, 0x70,
  42112. 0x53, 0xC0, 0x5E, 0xEB, 0x6A, 0x15, 0x9B, 0xAA,
  42113. 0xD4, 0x02, 0x0B, 0x9E, 0xC3, 0xF5, 0x37, 0xDA,
  42114. 0x4D, 0xAD, 0xAF, 0xB3, 0xB1, 0xBB, 0x1D, 0xBE,
  42115. 0xB2, 0xD5, 0xB8, 0xF9, 0xD0, 0x5A, 0x01, 0x97,
  42116. 0x98, 0xEA, 0xE0, 0xED, 0x09, 0x9D, 0xB0, 0x66,
  42117. 0xD7, 0x3E, 0xE8, 0xE9, 0xA5, 0x6D, 0xE3, 0x68,
  42118. 0xE8, 0x78, 0xA7, 0xFF, 0x39, 0x14, 0x0D, 0x80,
  42119. 0x21, 0xD5, 0x00, 0x85, 0xE6, 0x25, 0x29, 0x41,
  42120. 0xAB, 0x31, 0x53, 0x09, 0xCB, 0x53, 0xAA, 0xA4,
  42121. 0x9E, 0x86, 0x34, 0x7F, 0xBA, 0xD5, 0x4A, 0x1F,
  42122. 0x87, 0x3E, 0x0C, 0xB4, 0xB8, 0x6A, 0x8D, 0x5B,
  42123. 0x1B, 0x2A, 0x95, 0xD4, 0x85, 0xF3, 0x7A, 0x9F,
  42124. 0xB6, 0x10, 0x5D, 0xF8, 0x44, 0x0F, 0xDB, 0x85,
  42125. 0x78, 0xF2, 0x62, 0x4C, 0x07, 0x93, 0x29, 0x56,
  42126. 0x9A, 0x75, 0xF3, 0x6F, 0x2C, 0x55, 0xD8, 0xD0,
  42127. 0x30, 0xFB, 0xFE, 0xAA, 0x88, 0x89, 0xAD, 0x74,
  42128. 0x6C, 0x32, 0x3B, 0x1A, 0xC4, 0xEC, 0x8C, 0x40,
  42129. 0x3E, 0x77, 0x5A, 0x6F, 0xBE, 0x59, 0x6E, 0x7E,
  42130. 0x6A, 0x5A, 0x28, 0x63, 0x57, 0x66, 0x25, 0x14,
  42131. 0x99, 0x40, 0x97, 0x6F, 0x7C, 0xC9, 0x36, 0x17,
  42132. 0xB4, 0x3F, 0xB1, 0x34, 0x89, 0x07, 0x4E, 0xCA,
  42133. 0xC5, 0xBE, 0xB1, 0xA4, 0xDF, 0xE5, 0x8B, 0x9A,
  42134. 0xD2, 0xE0, 0xC6, 0xA1, 0x5B, 0x76, 0xA7, 0xC2,
  42135. 0xD2, 0x08, 0x72, 0x5A, 0x31, 0x23, 0xCA, 0x4E,
  42136. 0x6F, 0x2C, 0x58, 0x47, 0xEE, 0x5F, 0xA8, 0x38,
  42137. 0x49, 0x19, 0xEF, 0x89, 0x01, 0x1D, 0x21, 0x9B,
  42138. 0x25, 0x7B, 0x3E, 0x4D, 0xC4, 0xF2, 0x09, 0x51,
  42139. 0x60, 0x84, 0x4C, 0xAE, 0xEA, 0xFC, 0xF8, 0x57,
  42140. 0x26, 0x0F, 0x1C, 0x63, 0xD3, 0xB0, 0x5A, 0x67,
  42141. 0xD3, 0xD0, 0xF2, 0xB0, 0xEC, 0x9D, 0xCC, 0x27,
  42142. 0x23, 0xF1, 0x37, 0x55, 0x75, 0x0B, 0xAE, 0x62,
  42143. 0xFC, 0xC3, 0x61, 0xCF, 0xB5, 0x84, 0xF7, 0x74,
  42144. 0xC0, 0x9A, 0xDF, 0x9A, 0x04, 0x31, 0xB2, 0x3E,
  42145. 0x48, 0x8C, 0x35, 0x9C, 0x0A, 0xEF, 0x5B, 0x1C,
  42146. 0x97, 0x87, 0xBD, 0x8F, 0x52, 0xB0, 0x83, 0xBC,
  42147. 0x9D, 0xBC, 0xC9, 0xB3, 0x03, 0x9F, 0x77, 0x7C,
  42148. 0x7E, 0x8E, 0xAB, 0xC8, 0x00, 0x78, 0x05, 0x0C,
  42149. 0xE6, 0xD4, 0x9C, 0x3B, 0xB7, 0x01, 0x68, 0xFA,
  42150. 0x21, 0x77, 0x29, 0x8F, 0xB0, 0xA8, 0xF7, 0x2C,
  42151. 0x1C, 0xD2, 0x8D, 0x66, 0x2A, 0x07, 0xDA, 0xE6,
  42152. 0xC7, 0xAC, 0xB7, 0xFB, 0x8E, 0x7F, 0xDD, 0x01,
  42153. 0xDF, 0xB2, 0x7C, 0x62, 0xEE, 0x68, 0x3F, 0x4E,
  42154. 0x5F, 0x88, 0xC7, 0xC1, 0xDD, 0xDD, 0x5E, 0xEC,
  42155. 0xC1, 0xC3, 0xAF, 0x85, 0x3F, 0x1F, 0xF6, 0xB1,
  42156. 0xD9, 0xDE, 0x67, 0x2F, 0x1B, 0xF6, 0x47, 0x3A,
  42157. 0xF0, 0x02, 0x1D, 0x8A, 0x3D, 0x4D, 0xD0, 0x4A,
  42158. 0x2F, 0xCA, 0x23, 0x25, 0xC7, 0x21, 0xCF, 0x1C,
  42159. 0x82, 0x16, 0x76, 0xD0, 0xA0, 0xD5, 0x74, 0x18,
  42160. 0x66, 0x25, 0xDE, 0x83, 0x1C, 0x84, 0x11, 0xF6,
  42161. 0x41, 0x79, 0xF9, 0x16, 0x7F, 0x78, 0xBC, 0xB2,
  42162. 0x2F, 0xB4, 0x1C, 0x2C, 0xDB, 0x63, 0xC4, 0xDB,
  42163. 0x5E, 0x13, 0x87, 0x66, 0xD3, 0x80, 0x35, 0x89,
  42164. 0x59, 0x8F, 0x11, 0x4F, 0x41, 0xBA, 0x42, 0xCD,
  42165. 0xB1, 0x34, 0x10, 0x20, 0x44, 0x9B, 0xA9, 0x96,
  42166. 0x56, 0x11, 0x39, 0x90, 0xB4, 0xE0, 0x22, 0xD8,
  42167. 0xDA, 0x20, 0xD7, 0x44, 0x49, 0x1C, 0x6E, 0xEA,
  42168. 0xB6, 0x7B, 0x91, 0x8E, 0x80, 0xFF, 0xF3, 0x43,
  42169. 0xCC, 0x5B, 0x4C, 0x8E, 0x58, 0xC3, 0x48, 0x4B,
  42170. 0x01, 0x25, 0xA6, 0x0C, 0x36, 0xAE, 0xF7, 0x63,
  42171. 0x89, 0x4D, 0x35, 0x14, 0x8B, 0x57, 0x8F, 0x41,
  42172. 0x7C, 0x3A, 0x98, 0xA1, 0x43, 0xED, 0xFE, 0x9F,
  42173. 0x8C, 0x95, 0xBC, 0xC3, 0x46, 0xC6, 0xF5, 0xEA,
  42174. 0xF9, 0x7A, 0xAD, 0x11, 0xDA, 0xE0, 0x1C, 0x47,
  42175. 0x7C, 0x22, 0x7A, 0x88, 0xD1, 0x0E, 0xCF, 0xDC,
  42176. 0xF4, 0x50, 0xB3, 0x7F, 0x88, 0x19, 0x68, 0x02,
  42177. 0x78, 0x49, 0xD9, 0xB4, 0x3E, 0x2B, 0xFF, 0x90,
  42178. 0xC6, 0xA3, 0x4A, 0xE4, 0x1B, 0x8B, 0xBD, 0x74,
  42179. 0x30, 0x83, 0xD3, 0xC5, 0x87, 0x86, 0xB0, 0x36,
  42180. 0x67, 0x1C, 0xD6, 0xEE, 0xD9, 0x4D, 0xAE, 0x51,
  42181. 0xF7, 0x61, 0x32, 0x47, 0xEF, 0x86, 0x07, 0xAC,
  42182. 0xF7, 0x4A, 0x3C, 0xCE, 0x93, 0x2F, 0x1C, 0x38,
  42183. 0x69, 0xBD, 0xB3, 0x5C, 0xA1, 0x7F, 0xC6, 0xBA,
  42184. 0x9F, 0x9C, 0x95, 0x6F, 0xF1, 0xD4, 0xD8, 0x80,
  42185. 0x94, 0x32, 0x5C, 0xAB, 0xCE, 0x41, 0x23, 0x3F,
  42186. 0xB1, 0xD8, 0x08, 0xEF, 0x41, 0x01, 0x03, 0x96,
  42187. 0xDE, 0xB0, 0xEC, 0xF5, 0x07, 0x34, 0xD8, 0x18,
  42188. 0xDD, 0xAB, 0x70, 0x01, 0x5A, 0x0A, 0xBD, 0xD1,
  42189. 0x92, 0x6D, 0xFA, 0x49, 0x1F, 0x71, 0x1A, 0xA8,
  42190. 0x5D, 0xA2, 0xA8, 0xEC, 0x60, 0xE3, 0x25, 0x5C,
  42191. 0xCF, 0x97, 0x5C, 0x23, 0xCC, 0x4E, 0x8D, 0xAF,
  42192. 0xDD, 0xED, 0x9F, 0xEC, 0x60, 0xA6, 0x46, 0x7C,
  42193. 0x45, 0xB0, 0x3C, 0xA4, 0x76, 0x49, 0x9A, 0xA3,
  42194. 0x31, 0xB0, 0xE3, 0x99, 0x95, 0x76, 0xCE, 0xC3,
  42195. 0x19, 0x1A, 0x9A, 0x62, 0xBC, 0x1B, 0xEA, 0xC1,
  42196. 0xEA, 0xF2, 0x0E, 0x18, 0xCF, 0xC3, 0x21, 0x61,
  42197. 0x27, 0xDE, 0x4A, 0xAE, 0x2E, 0x75, 0x20, 0x1F,
  42198. 0x9E, 0x42, 0x7E, 0x39, 0xBF, 0x92, 0x11, 0x50,
  42199. 0xEA, 0xB9, 0x49, 0x55, 0x9C, 0x02, 0x2D, 0x87,
  42200. 0x6F, 0xA2, 0x42, 0xC2, 0xA8, 0x45, 0xBC, 0xA7,
  42201. 0x23, 0x5F, 0x72, 0x1B, 0x00, 0x56, 0x78, 0x8A,
  42202. 0x44, 0xEC, 0xC3, 0xEB, 0x98, 0xF0, 0xF5, 0x02,
  42203. 0xB8, 0x9F, 0x8E, 0x74, 0x10, 0xEA, 0x56, 0x79,
  42204. 0xAE, 0x7C, 0x04, 0x34, 0xF1, 0x3A, 0xD8, 0x16,
  42205. 0x42, 0x1D, 0x2F, 0xEE, 0x30, 0xCB, 0xCB, 0x2D,
  42206. 0xAA, 0x6B, 0x85, 0x1C, 0xD1, 0xB6, 0xE9, 0x96,
  42207. 0xDA, 0x7A, 0x75, 0x7E, 0x4C, 0x4D, 0x85, 0x72,
  42208. 0xC8, 0xB6, 0x00, 0xDE, 0x85, 0xDD, 0xB6, 0x53,
  42209. 0x20, 0xD1, 0xCB, 0x71, 0xD9, 0x37, 0x83, 0x49,
  42210. 0xC0, 0xC4, 0x01, 0xAD, 0x4F, 0x9E, 0x91, 0x27,
  42211. 0x21, 0x39, 0x22, 0x8A, 0x8D, 0xA2, 0xF4, 0xFD,
  42212. 0x2F, 0x48, 0x89, 0x1A, 0x4D, 0xCB, 0x06, 0x6D,
  42213. 0x50, 0x1D, 0x44, 0x74, 0x83, 0xB6, 0x11, 0xBB,
  42214. 0x3C, 0x80, 0x55, 0x0A, 0x90, 0xEA, 0x0B, 0x73,
  42215. 0x2D, 0x63, 0x9D, 0x8B, 0x39, 0x26, 0xB6, 0xE7,
  42216. 0xC3, 0x54, 0x53, 0xED, 0x3C, 0xC1, 0x10, 0xBA,
  42217. 0xF5, 0x56, 0xCF, 0x46, 0xD8, 0xFC, 0x21, 0x77,
  42218. 0xE7, 0x6F, 0xB2, 0x66, 0x3B, 0x8B, 0xDD, 0x17,
  42219. 0x1E, 0x94, 0xC0, 0xAC, 0xAF, 0x25, 0xB9, 0x15,
  42220. 0x3B, 0x22, 0xBC, 0xA7, 0x49, 0x91, 0x67, 0x56,
  42221. 0xFB, 0x3E, 0xD3, 0x01, 0x8E, 0x09, 0x44, 0xB6,
  42222. 0xC3, 0xB9, 0xB6, 0xBF, 0xA1, 0x5B, 0x9B, 0xE8,
  42223. 0x03, 0xAC, 0x79, 0x33, 0x3C, 0xD2, 0xC3, 0xA2,
  42224. 0x7A, 0x26, 0xBC, 0x17, 0xCD, 0xA2, 0x57, 0x79,
  42225. 0x8A, 0xE1, 0x6B, 0x28, 0xB4, 0x63, 0xB6, 0xDF,
  42226. 0x3F, 0xA8, 0x7C, 0x2D, 0x74, 0x2D, 0x0F, 0x68,
  42227. 0x85, 0xBE, 0xE0, 0xBE, 0xC6, 0xE2, 0x0D, 0x01,
  42228. 0xE5, 0xDA, 0xDC, 0x86, 0x82, 0x3E, 0x92, 0xD6,
  42229. 0x0F, 0xEC, 0x79, 0xB0, 0xD2, 0x40, 0x24, 0x87,
  42230. 0x53, 0xE4, 0x20, 0x48, 0x38, 0x4C, 0x80, 0x42,
  42231. 0x89, 0x60, 0x48, 0x21, 0xA5, 0x7F, 0x4F, 0x9F,
  42232. 0x50, 0xAE, 0x0C, 0x38, 0x52, 0x7F, 0xE5, 0xA3,
  42233. 0x49, 0x38, 0xDD, 0xBC, 0xDC, 0xD9, 0xA1, 0xD0,
  42234. 0x20, 0x83, 0x9B, 0xEB, 0xB6, 0x2F, 0x9F, 0x41,
  42235. 0xFB, 0xA0, 0x80, 0x52, 0xAB, 0xB8, 0x2F, 0xAD,
  42236. 0xA8, 0x84, 0xCB, 0xE5, 0x63, 0x79, 0x11, 0x03,
  42237. 0xAA, 0x58, 0x55, 0x46, 0xEB, 0xFE, 0xB1, 0x12,
  42238. 0x72, 0xCC, 0x2E, 0x87, 0xA3, 0xB7, 0x5B, 0x3C,
  42239. 0x6B, 0xB1, 0x85, 0x3A, 0xE7, 0xF9, 0xCF, 0x55,
  42240. 0x85, 0xB2, 0x65, 0x3C, 0xF5, 0xEE, 0xA2, 0x44,
  42241. 0xD2, 0x04, 0xEB, 0x26, 0x9C, 0x56, 0xA2, 0x09,
  42242. 0x85, 0x16, 0x06, 0x59, 0xCB, 0x07, 0x25, 0xEE,
  42243. 0x13, 0xCE, 0x35, 0xD5, 0x5E, 0xB0, 0x95, 0xA5,
  42244. 0x34, 0x14, 0xF2, 0x32, 0xDF, 0x81, 0x08, 0xB1,
  42245. 0x80, 0x24, 0xEB, 0x0D, 0xBF, 0x34, 0x5E, 0xB5,
  42246. 0xCD, 0xAD, 0x0B, 0xCE, 0x72, 0x63, 0x50, 0x9A,
  42247. 0x34, 0x1D, 0x54, 0xA7, 0xD5, 0x34, 0xE5, 0x53,
  42248. 0xEA, 0xEF, 0xFE, 0x4E, 0x24, 0x2E, 0xA2, 0x3B,
  42249. 0xCF, 0xE5, 0x9A, 0x58, 0xA6, 0x04, 0x25, 0x88,
  42250. 0x2C, 0xB7, 0xE3, 0xB0, 0xC9, 0xE4, 0xAF, 0xE8,
  42251. 0x69, 0x8E, 0x3D, 0xF5, 0x6A, 0xFD, 0x6D, 0x61,
  42252. 0x1E, 0x91, 0x68, 0x74, 0x7D, 0x87, 0x35, 0xCF,
  42253. 0x92, 0x46, 0xD9, 0x4F, 0x21, 0x26, 0xBE, 0x72,
  42254. 0x7F, 0xB4, 0x2B, 0x22, 0x41, 0xA8, 0x3B, 0x34,
  42255. 0xF0, 0xB9, 0xEB, 0x47, 0x93, 0x8D, 0x72, 0x65,
  42256. 0x02, 0xC5, 0x4E, 0x45, 0x72, 0x76, 0x63, 0x31,
  42257. 0x62, 0x8F, 0xA5, 0xCD, 0xA8, 0x93, 0xC3, 0x53,
  42258. 0x76, 0xAB, 0x45, 0x38, 0xFF, 0x87, 0x17, 0xC2,
  42259. 0x79, 0x5B, 0x0F, 0x51, 0xF0, 0x8E, 0x11, 0x37,
  42260. 0x61, 0x2B, 0x89, 0xB0, 0xC1, 0xE2, 0xCD, 0x1F,
  42261. 0x09, 0x9E, 0x88, 0x55, 0x69, 0x23, 0xAE, 0x57,
  42262. 0xA1, 0xDA, 0xD2, 0xAF, 0xB1, 0x23, 0x0B, 0x50,
  42263. 0x94, 0xA1, 0xB2, 0x1B, 0xAD, 0x7D, 0xBB, 0xC3,
  42264. 0x33, 0xA9, 0x7F, 0x17, 0x93, 0x04, 0x71, 0x8F,
  42265. 0x32, 0x89, 0xB6, 0xDE, 0x31, 0x31, 0x5B, 0x74,
  42266. 0xC1, 0xA7, 0x3A, 0xC7, 0x75, 0x6F, 0xAA, 0x4D,
  42267. 0x7E, 0xB5, 0x68, 0xBB, 0xC6, 0xF7, 0xE7, 0x88,
  42268. 0xCD, 0x08, 0x9B, 0x39, 0x55, 0x64, 0xD2, 0x17,
  42269. 0x6B, 0x00, 0x56, 0xDF, 0xFE, 0x95, 0x2C, 0x77,
  42270. 0x48, 0xB0, 0x48, 0x30, 0x67, 0x20, 0xF6, 0x02,
  42271. 0xB6, 0x7E, 0x8F, 0x6A, 0xDC, 0xC9, 0x1F, 0x8E,
  42272. 0x3A, 0xA4, 0xB8, 0xC4, 0xD7, 0xFA, 0xC2, 0x33,
  42273. 0xAA, 0xF9, 0x36, 0x53, 0xAD, 0x22, 0x09, 0xE2,
  42274. 0xFF, 0x92, 0xDA, 0x30, 0xC2, 0xD5, 0x3F, 0xDE,
  42275. 0xF6, 0xF4, 0xC9, 0x0E, 0xAA, 0x0D, 0xE6, 0x0D,
  42276. 0x59, 0x4A, 0xDA, 0x39, 0x15, 0xDB, 0x24, 0x27,
  42277. 0x9D, 0x86, 0x74, 0x76, 0xEA, 0xD7, 0x57, 0xB4,
  42278. 0xC0, 0x26, 0x4A, 0x1D, 0xB8, 0xA1, 0xF5, 0x7A,
  42279. 0x1B, 0x5D, 0x71, 0x73, 0xBB, 0x1A, 0x96, 0x0C,
  42280. 0xE0, 0x2F, 0xDE, 0xFE, 0xF1, 0x60, 0xD5, 0x12,
  42281. 0x66, 0x7D, 0x65, 0x52, 0x68, 0xFC, 0xC3, 0xA1,
  42282. 0x53, 0xA4, 0x31, 0x47, 0x82, 0xA0, 0xEB, 0xFF,
  42283. 0x84, 0xF6, 0x5F, 0x14, 0xA0, 0xE3, 0xE1, 0x2A,
  42284. 0x13, 0x25, 0x0C, 0x07, 0xD0, 0x8C, 0x22, 0x5B,
  42285. 0x11, 0xA6, 0x83, 0x1B, 0xC2, 0x5C, 0x40, 0x46,
  42286. 0x7B, 0x76, 0x80, 0x04, 0xDD, 0xE0, 0xE8, 0x74,
  42287. 0xA5, 0x11, 0x44, 0xC1, 0x89, 0x20, 0xBD, 0xF2,
  42288. 0x86, 0x09, 0x0B, 0x59, 0xF5, 0x15, 0x64, 0xEA,
  42289. 0x40, 0x70, 0xFB, 0xBF, 0x61, 0xE3, 0x69, 0x64,
  42290. 0x35, 0xF2, 0x8F, 0x63, 0x33, 0x2B, 0x64, 0x49,
  42291. 0x6D, 0xF3, 0xEC, 0x8B, 0x65, 0xD5, 0x4E, 0x1C,
  42292. 0xF4, 0x78, 0x9D, 0xDA, 0xB1, 0x22, 0xDA, 0x6B,
  42293. 0x26, 0x4D, 0x31, 0x2A, 0x71, 0x1C, 0x12, 0x9E,
  42294. 0x3B, 0x07, 0xF4, 0xC6, 0xDA, 0x25, 0xA5, 0x61,
  42295. 0x73, 0xAF, 0x58, 0xB9, 0x0A, 0x71, 0xB7, 0xAC,
  42296. 0xFA, 0x31, 0x61, 0xA8, 0x1F, 0x59, 0xD1, 0x79,
  42297. 0x14, 0xC9, 0x9B, 0xBA, 0xC4, 0xF9, 0xA3, 0x14,
  42298. 0x97, 0x7A, 0x89, 0xCE, 0xF7, 0x69, 0x69, 0x43,
  42299. 0x60, 0x9B, 0xB4, 0x82, 0x79, 0x64, 0xFB, 0x29,
  42300. 0x76, 0x40, 0x3B, 0xD4, 0x99, 0x6F, 0x1E, 0x84,
  42301. 0x2B, 0xF5, 0xAA, 0xAE, 0x1E, 0xCC, 0xA1, 0x12,
  42302. 0x55, 0xB9, 0xE6, 0x00, 0x1C, 0x20, 0xF7, 0x2F,
  42303. 0x1F, 0xD5, 0xE3, 0x2C, 0xDA, 0x32, 0xD8, 0xA7,
  42304. 0xAC, 0x5F, 0x62, 0xB0, 0x9A, 0x0E, 0x61, 0x58,
  42305. 0x47, 0xCA, 0x74, 0x6F, 0x48, 0x95, 0x15, 0xCF,
  42306. 0x8F, 0x18, 0x31, 0x62, 0x85, 0x9F, 0x53, 0xB9,
  42307. 0x7E, 0x9E, 0x5C, 0xA8, 0x00, 0xEE, 0x62, 0x4F,
  42308. 0x72, 0x98, 0x43, 0xA0, 0x00, 0x91, 0x64, 0xA4,
  42309. 0xA9, 0xFF, 0x76, 0xEB, 0x34, 0xE4, 0x70, 0x41,
  42310. 0x84, 0x84, 0x8A, 0x13, 0x9A, 0xD9, 0x7D, 0x90,
  42311. 0x9F, 0x7A, 0x7E, 0xD1, 0x14, 0xF0, 0x87, 0xA4,
  42312. 0xB2, 0xE1, 0xB4, 0xA3, 0x03, 0x23, 0x91, 0x16,
  42313. 0x0B, 0x6F, 0x3A, 0x36, 0x49, 0xFF, 0x15, 0xAE,
  42314. 0xA2, 0xB7, 0x10, 0x7A, 0xF8, 0xA3, 0xB5, 0xFC,
  42315. 0xAD, 0x61, 0xD4, 0x3D, 0x60, 0x2E, 0x62, 0x86,
  42316. 0xA9, 0x00, 0x87, 0x0C, 0xC8, 0xCE, 0x24, 0xE3,
  42317. 0x9E, 0x78, 0xF0, 0x39, 0x7A, 0x0D, 0x7E, 0x27,
  42318. 0xE8, 0xE2, 0xD4, 0x77, 0x6A, 0x44, 0xCB, 0xA2,
  42319. 0x18, 0xEB, 0xCD, 0x88, 0xB3, 0xC2, 0x8C, 0x18,
  42320. 0x2A, 0x7C, 0x9F, 0x4D, 0xBB, 0x2D, 0xBB, 0x5E,
  42321. 0x98, 0x15, 0x63, 0xD6, 0x6C, 0xEE, 0xB7, 0x7E,
  42322. 0x7F, 0x90, 0x34, 0xBD, 0x42, 0x9D, 0x27, 0x63,
  42323. 0x7C, 0xF7, 0x97, 0xDE, 0x82, 0xE0, 0x1F, 0xEB,
  42324. 0xBC, 0xE2, 0x17, 0x1E, 0xFD, 0x01, 0x6E, 0x40,
  42325. 0x2A, 0x42, 0xD7, 0x8E, 0xA1, 0xAC, 0xE2, 0xCB,
  42326. 0x37, 0x0E, 0x75, 0xC9, 0x0A, 0xDF, 0xA1, 0xA7,
  42327. 0x93, 0xB2, 0x16, 0x9C, 0xC2, 0x65, 0x22, 0xDB,
  42328. 0x2F, 0x54, 0x6A, 0xC1, 0xDE, 0x34, 0xC9, 0x08,
  42329. 0x71, 0x20, 0xC4, 0x2A, 0x9F, 0x10, 0xC0, 0x0D,
  42330. 0x49, 0x3C, 0x25, 0x73, 0x01, 0x66, 0xF9, 0xD2,
  42331. 0x19, 0xFB, 0xDA, 0xD2, 0x22, 0xC8, 0xB2, 0x81,
  42332. 0x15, 0x54, 0x33, 0x13, 0x21, 0x08, 0x48, 0xFB,
  42333. 0x2F, 0x04, 0xBF, 0xDC, 0xE1, 0x5D, 0x32, 0x0C,
  42334. 0x36, 0x34, 0xA8, 0xE4, 0xD6, 0x37, 0x55, 0x51,
  42335. 0x59, 0x00, 0xC7, 0x5B, 0xFD, 0x09, 0x0A, 0xD7,
  42336. 0x8D, 0xD5, 0x88, 0x65, 0x9F, 0xBF, 0x97, 0xC9,
  42337. 0x6E, 0x0D, 0x0A, 0xCC, 0x8E, 0x81, 0x5E, 0x60,
  42338. 0x8F, 0x9E, 0x86, 0x1D, 0x79, 0xAF, 0x30, 0x51,
  42339. 0xB9, 0x42, 0xB5, 0x25, 0x70, 0xB6, 0x29, 0x2B,
  42340. 0xF4, 0x8C, 0x2B, 0xFA, 0xA9, 0x07, 0x7D, 0xC7,
  42341. 0x6F, 0xE9, 0x02, 0x68, 0x32, 0x17, 0xB8, 0xBF,
  42342. 0x80, 0x9E, 0xD7, 0xA0, 0x05, 0x0A, 0xDD, 0xBB,
  42343. 0x65, 0xFD, 0xDF, 0xBD, 0x24, 0x01, 0x9C, 0x91,
  42344. 0x81, 0xB5, 0xAC, 0x81, 0x56, 0x61, 0x13, 0xD6,
  42345. 0x69, 0x4E, 0xA6, 0x29, 0x1D, 0x7F, 0x4A, 0x7F,
  42346. 0x56, 0xA4, 0x1E, 0xB9, 0x1F, 0x76, 0x36, 0x8D,
  42347. 0xF8, 0x2B, 0x16, 0x4B, 0x48, 0x59, 0x25, 0x9D,
  42348. 0x71, 0x89, 0x24, 0x0F, 0x1D, 0x88, 0x03, 0xF8,
  42349. 0x10, 0x72, 0x96, 0xD3, 0x78, 0xBA, 0xB4, 0xD2,
  42350. 0x4F, 0xE6, 0xD1, 0x0E, 0xF7, 0x88, 0x36, 0x7B,
  42351. 0xCE, 0x16, 0xC5, 0xAB, 0x77, 0xFB, 0xC1, 0x68,
  42352. 0xB8, 0x57, 0xF7, 0xBA, 0x5C, 0xDC, 0xBE, 0x50,
  42353. 0x67, 0xC8, 0x64, 0xF8, 0x79, 0x80, 0x9F, 0xE5,
  42354. 0x21, 0x7D, 0xEF, 0x02, 0x94, 0xBF, 0xAF, 0xDF,
  42355. 0x80, 0x9A, 0xBC, 0xE9, 0x53, 0x2D, 0xD9, 0xDA,
  42356. 0xB3, 0x44, 0x8F, 0x4D, 0xA6, 0x8E, 0xCA, 0x51,
  42357. 0x60, 0x94, 0x76, 0x27, 0x8E, 0xB8, 0xC4, 0xF6,
  42358. 0x9E, 0xA2, 0x96, 0x73, 0xF6, 0x94, 0x18, 0x04,
  42359. 0x1D, 0x26, 0x85, 0x7E, 0xBC, 0x24, 0xA4, 0x87,
  42360. 0xBB, 0x4B, 0x0B, 0xA6, 0x3A, 0xF8, 0x48, 0x54,
  42361. 0x5E, 0xE9, 0xBE, 0x89, 0xF1, 0x39, 0xD5, 0x02,
  42362. 0x09, 0x9B, 0x9D, 0x35, 0xDB, 0x38, 0x07, 0xB9,
  42363. 0x25, 0xCB, 0xA5, 0x76, 0xE2, 0x71, 0x70, 0xEA,
  42364. 0xEC, 0x48, 0xCC, 0x2C, 0xC1, 0x5B, 0x04, 0x36,
  42365. 0x77, 0x82, 0x5D, 0x0E, 0xE8, 0x1E, 0xB2, 0xCE,
  42366. 0xE3, 0xA8, 0xED, 0x14, 0xA7, 0x98, 0xB8, 0x79,
  42367. 0x53, 0x02, 0x20, 0xE5, 0x0C, 0xE8, 0xC0, 0x03,
  42368. 0xA3, 0x05, 0x38, 0x2A, 0x24, 0xD2, 0x3C, 0x27,
  42369. 0x7B, 0x99, 0xD1, 0xF4, 0xC5, 0x4F, 0x9A, 0x8D,
  42370. 0x33, 0xFA, 0x3D, 0x1E, 0x33, 0x7E, 0x18, 0xD7,
  42371. 0xCB, 0xBA, 0x5E, 0x5A, 0x47, 0xF2, 0xD5, 0xE0,
  42372. 0x96, 0xCF, 0x45, 0x51, 0xB2, 0x3B, 0x1B, 0x86,
  42373. 0x43, 0x6E, 0x81, 0xB4, 0xA0, 0x9D, 0x1E, 0x3D,
  42374. 0x38, 0x49, 0x2E, 0xC8, 0xB2, 0xA0, 0x09, 0x67,
  42375. 0x01, 0x6A, 0xB7, 0x6B, 0x9A, 0x9B, 0x18, 0x64,
  42376. 0x67, 0x14, 0x21, 0xDA, 0x56, 0xF5, 0x7D, 0x00,
  42377. 0x8D, 0x5C, 0xE1, 0xB8, 0x92, 0xA7, 0xE9, 0xC1,
  42378. 0xF6, 0x9F, 0x6C, 0x72, 0x2C, 0xF1, 0x09, 0xDB,
  42379. 0x50, 0x0E, 0x53, 0xF6, 0xBC, 0x07, 0x83, 0x7A,
  42380. 0xD1, 0xCD, 0x4C, 0xF4, 0xA6, 0x4D, 0xA7, 0x63,
  42381. 0xB4, 0xA9, 0xC4, 0x92, 0x9B, 0x0D, 0xCD, 0xDF,
  42382. 0x7C, 0x7E, 0x11, 0x86, 0xBE, 0x3F, 0xF0, 0xC3,
  42383. 0x21, 0x15, 0x84, 0x37, 0x82, 0x0C, 0x81, 0xE7,
  42384. 0x4F, 0xF3, 0x16, 0xAE, 0x32, 0x54, 0xE9, 0x72,
  42385. 0xFC, 0x19, 0x7A, 0x7F, 0x0E, 0x62, 0x02, 0x42,
  42386. 0xAC, 0x05, 0xA4, 0xE4, 0x3E, 0x98, 0x7C, 0x2A,
  42387. 0x83, 0x55, 0xB0, 0x35, 0x77, 0x45, 0xCA, 0x79,
  42388. 0xE6, 0xAE, 0x48, 0xAB, 0x29, 0xED, 0x4F, 0xA6,
  42389. 0x3D, 0x3A, 0x1F, 0x19, 0xB9, 0x99, 0xDE, 0x25,
  42390. 0x1F, 0xDE, 0x06, 0x40, 0xDD, 0x87, 0x87, 0x6D,
  42391. 0x55, 0x76, 0x28, 0x78, 0xAD, 0x1D, 0xB1, 0x2D,
  42392. 0x65, 0xBA, 0xFD, 0x14, 0xB6, 0xA9, 0xA7, 0x08,
  42393. 0x1B, 0xF2, 0x3F, 0x9F, 0x06, 0xD9, 0x0C, 0xE2,
  42394. 0x73, 0xC5, 0xA2, 0x6E, 0x01, 0x2C, 0xA9, 0x4D,
  42395. 0xD4, 0x81, 0xD3, 0x2E, 0x10, 0x93, 0x8C, 0x16,
  42396. 0x51, 0x63, 0xE8, 0x9B, 0xE8, 0xA9, 0x3A, 0x63,
  42397. 0x03, 0x4D, 0x34, 0x5B, 0x74, 0xE2, 0xA9, 0x4E,
  42398. 0xF6, 0x43, 0xD0, 0x6A, 0xF9, 0xE1, 0xF5, 0xC9,
  42399. 0xF1, 0x04, 0x93, 0x0D, 0xA0, 0x0E, 0x61, 0xE0,
  42400. 0x61, 0xEE, 0x8C, 0x3B, 0xB1, 0x7C, 0x11, 0xE0,
  42401. 0x5D, 0x45, 0xC1, 0x68, 0x2E, 0x4D, 0x59, 0x3C,
  42402. 0x91, 0x98, 0x23, 0x8D, 0x2B, 0xA2, 0x89, 0x77,
  42403. 0x9E, 0x7D, 0x0F, 0x22, 0x7B, 0xCB, 0x0B, 0x09,
  42404. 0x97, 0x2B, 0x19, 0x77, 0x0F, 0xF0, 0x11, 0xBF,
  42405. 0x6C, 0x60, 0xD9, 0xD1, 0x93, 0xCF, 0xAB, 0x32,
  42406. 0x74, 0x7A, 0x00, 0x95, 0xE1, 0xA4, 0xAD, 0x32,
  42407. 0x51, 0x4C, 0x78, 0x2E, 0xF3, 0xDE, 0x7A, 0x26,
  42408. 0xEA, 0x77, 0x1F, 0x55, 0x30, 0xD9, 0xDE, 0x97,
  42409. 0x36, 0xD0, 0xF6, 0xAE, 0x1A, 0xFB, 0x78, 0xEC,
  42410. 0x7C, 0xE4, 0x88, 0x4A, 0x1B, 0xB4, 0x36, 0xCF,
  42411. 0xCE, 0x45, 0x9C, 0xD9, 0x93, 0x58, 0x26, 0x09,
  42412. 0x06, 0xAA, 0xC9, 0x97, 0x16, 0xA5, 0x36, 0xCC,
  42413. 0x76, 0x87, 0xA0, 0x37, 0x5F, 0xDA, 0x11, 0x00,
  42414. 0x76, 0x18, 0xE5, 0x53, 0x53, 0x4E, 0x54, 0xD5,
  42415. 0xB2, 0x14, 0xF7, 0xAA, 0x6F, 0xC7, 0xDB, 0xE3,
  42416. 0x7C, 0x2B, 0xD2, 0xB6, 0x48, 0x50, 0xAE, 0x46,
  42417. 0x9A, 0x98, 0x58, 0x98, 0x7F, 0x3F, 0xA4, 0xB1,
  42418. 0xFD, 0x26, 0xD9, 0x54, 0xBF, 0xEC, 0x36, 0x5D,
  42419. 0xBE, 0x06, 0xDD, 0xCD, 0x61, 0x5E, 0x1F, 0xED,
  42420. 0x58, 0xA8, 0x86, 0x76, 0x40, 0x2D, 0x1D, 0x6B,
  42421. 0x58, 0x14, 0x85, 0x49, 0x8B, 0x5A, 0xDF, 0xFF,
  42422. 0xC4, 0x2D, 0x47, 0xD6, 0x1D, 0xF9, 0x93, 0x84,
  42423. 0xE2, 0x2C, 0x51, 0x57, 0xF0, 0x17, 0x8A, 0x6F,
  42424. 0xDA, 0xF8, 0xF4, 0xA9, 0x49, 0x1D, 0xAF, 0x29,
  42425. 0x8B, 0x2C, 0x3E, 0xC8, 0x80, 0x85, 0x02, 0x2C,
  42426. 0x0A, 0x7C, 0xF2, 0x45, 0xED, 0x0F, 0xB5, 0xA3,
  42427. 0x8C, 0xD1, 0x6F, 0x30, 0xD3, 0x7D, 0xA5, 0xC4,
  42428. 0x95, 0x9A, 0x55, 0x50, 0x1D, 0xAD, 0x50, 0xF1,
  42429. 0xB4, 0x8B, 0xBB, 0xDD, 0x86, 0xAB, 0x8B, 0xB5,
  42430. 0x22, 0xA9, 0x36, 0xDD, 0xF0, 0x00, 0x3B, 0x81,
  42431. 0xBE, 0x16, 0x23, 0x1A, 0x04, 0xE7, 0xA5, 0x89,
  42432. 0xC5, 0x6F, 0xFF, 0xB5, 0x1B, 0x07, 0x92, 0x7B,
  42433. 0x4A, 0xFA, 0x1D, 0xB7, 0xD4, 0x8B, 0xC6, 0xFB,
  42434. 0xC3, 0xF3, 0x67, 0x56, 0x37, 0x18, 0x4B, 0x7A,
  42435. 0xDB, 0x9B, 0xAD, 0xF4, 0xDE, 0x7C, 0x08, 0x5B,
  42436. 0xCA, 0x1D, 0x42, 0x8D, 0xC9, 0xFC, 0x82, 0x77,
  42437. 0xCB, 0xD8, 0x58, 0x84, 0xA5, 0x92, 0x1B, 0x52,
  42438. 0xBB, 0x05, 0xB7, 0x10, 0x61, 0x55, 0x08, 0x26,
  42439. 0x1B, 0xB4, 0x54, 0x6B, 0xD6, 0xE1, 0xFC, 0x73,
  42440. 0x0D, 0x16, 0xB0, 0x49, 0xEA, 0x12, 0x79, 0x8C,
  42441. 0xE2, 0xE6, 0xDF, 0x43, 0xF5, 0xB8, 0xF3, 0xEF,
  42442. 0x9A, 0xC8, 0xFB, 0xAE, 0x31, 0xB0, 0x11, 0xE1,
  42443. 0x0C, 0x4F, 0xC6, 0x2F, 0xFD, 0x7F, 0x39, 0xD1,
  42444. 0x6E, 0xC3, 0x2C, 0xA8, 0x21, 0x0E, 0xD1, 0x6E,
  42445. 0x04, 0x1D, 0xA4, 0x3D, 0x92, 0x74, 0x22, 0x95,
  42446. 0x14, 0x05, 0x4A, 0x0F, 0x82, 0xD4, 0x62, 0xFE,
  42447. 0x08, 0x0C, 0x6F, 0xFD, 0x7B, 0xBD, 0xBF, 0xBF,
  42448. 0x0B, 0xFF, 0xC6, 0xD5, 0xEC, 0xC4, 0x32, 0xA3,
  42449. 0x25, 0x6C, 0x0B, 0xE0, 0xDD, 0xFD, 0x5D, 0x90,
  42450. 0x80, 0xC6, 0x76, 0xC7, 0x95, 0x5D, 0x66, 0xE4,
  42451. 0x4D, 0x1C, 0xE5, 0x1F, 0xCC, 0x23, 0x82, 0xF8,
  42452. 0x68, 0xD7, 0x32, 0xE8, 0x58, 0x51, 0x72, 0x1B,
  42453. 0x48, 0xA0, 0x1D, 0x08, 0xC6, 0x39, 0x62, 0x6E,
  42454. 0xE0, 0x50, 0x9C, 0xB5, 0x81, 0xEF, 0xF5, 0x62,
  42455. 0x8F, 0xA6, 0xCC, 0xD1, 0x08, 0x9A, 0xC0, 0xE1,
  42456. 0x2D, 0xEB, 0xE0, 0x85, 0x17, 0x82, 0xE6, 0x4C,
  42457. 0x50, 0x49, 0xCB, 0xD6, 0x50, 0x10, 0x13, 0x96,
  42458. 0x5C, 0xC0, 0xCA, 0x25, 0xAC, 0xAB, 0x17, 0x6E,
  42459. 0xF7, 0xCA, 0xB9, 0x29, 0x40, 0x98, 0x5D, 0xDB,
  42460. 0x49, 0x02, 0x1D, 0xF6, 0xC6, 0x0D, 0x6C, 0x4A,
  42461. 0x48, 0x91, 0x16, 0x31, 0x1E, 0x86, 0xBA, 0x19,
  42462. 0xED, 0xF0, 0x0D, 0x74, 0x79, 0x73, 0x58, 0x20,
  42463. 0x7C, 0xDE, 0x50, 0x50, 0x6D, 0x00, 0x7F, 0xE0,
  42464. 0x3C, 0x88, 0x04, 0xC6, 0x64, 0x51, 0xF0, 0x2A,
  42465. 0x01, 0x82, 0xD3, 0x87, 0xB7, 0x59, 0x89, 0x40,
  42466. 0x96, 0xF6, 0x52, 0x32, 0x95, 0x2D, 0x18, 0x3D,
  42467. 0xBA, 0xAA, 0xBB, 0x6B, 0xC0, 0xE1, 0x91, 0xDC,
  42468. 0x2C, 0x3F, 0x75, 0xFC, 0x72, 0xBD, 0x61, 0xBA,
  42469. 0xB2, 0xEF, 0x19, 0xB6, 0x53, 0x2B, 0x23, 0x1C,
  42470. 0x4A, 0xFB, 0x1A, 0x9C, 0x2C, 0xB2, 0xF3, 0xD6,
  42471. 0xC4, 0x51, 0xE8, 0x44, 0x0D, 0x6A, 0x92, 0x3C,
  42472. 0xF7, 0x2A, 0x63, 0xE2, 0xED, 0x85, 0x54, 0x77,
  42473. 0x38, 0x87, 0x91, 0x0C, 0xA5, 0xC6, 0x71, 0xAD,
  42474. 0x4F, 0xD5, 0x92, 0x3C, 0xB9, 0x5E, 0xC7, 0x3F,
  42475. 0xFD, 0xFB, 0xDA, 0x4B, 0x66, 0x55, 0xF5, 0x5D,
  42476. 0xBF, 0xD1, 0x31, 0x7D, 0x02, 0x44, 0x22, 0x30,
  42477. 0x1E, 0xD6, 0x6A, 0x6E, 0x4C, 0x67, 0x20, 0x85,
  42478. 0xCE, 0xD1, 0xF4, 0xC7, 0xB0, 0x50, 0x30, 0xA1,
  42479. 0x00, 0xC4, 0x78, 0x8F, 0xEF, 0x4C, 0xD3, 0xE4,
  42480. 0x94, 0xA8, 0x53, 0xBD, 0xE6, 0x3E, 0x9D, 0x44,
  42481. 0x9A, 0xE3, 0xBB, 0x6B, 0xA1, 0x08, 0x32, 0x38,
  42482. 0xDA, 0x3F, 0x40, 0x90, 0x51, 0x5D, 0x14, 0x3C,
  42483. 0x67, 0xDB, 0xE5, 0x3D, 0x8D, 0x50, 0x7A, 0x52,
  42484. 0x29, 0xFF, 0xEB, 0x20, 0x72, 0xD0, 0xBD, 0x09,
  42485. 0x2F, 0xC9, 0xAE, 0x52, 0xDE, 0xAA, 0xAC, 0xD1,
  42486. 0xF0, 0xF1, 0x4B, 0x5A, 0xC8, 0x47, 0x52, 0xBF,
  42487. 0xD0, 0x02, 0x5E, 0x5F, 0x55, 0xB8, 0x69, 0x35,
  42488. 0x0F, 0x4B, 0x27, 0x19, 0xC5, 0xC0, 0x5A, 0xC1,
  42489. 0x66, 0x9B, 0xB0, 0xFD, 0x3C, 0x61, 0x4A, 0xCE,
  42490. 0x02, 0xA2, 0x70, 0x61, 0x3F, 0xD3, 0x30, 0x97,
  42491. 0x06, 0xDD, 0xCD, 0x5B, 0x1A, 0x6A, 0xD2, 0x6F,
  42492. 0x35, 0x9A, 0xDA, 0x80, 0xB3, 0x0E, 0x50, 0xA7,
  42493. 0xE5, 0x0B, 0xBD, 0x3A, 0xA4, 0x5D, 0x06, 0x54,
  42494. 0xDD, 0x7D, 0x05, 0x8B, 0x0B, 0xBF, 0x4D, 0x0D,
  42495. 0x92, 0x13, 0x51, 0x42, 0x21, 0x4E, 0xE7, 0x05,
  42496. 0x11, 0xF3, 0x67, 0x6A, 0xE6, 0x43, 0xB5, 0xF2,
  42497. 0x45, 0x06, 0x3B, 0x94, 0x19, 0xCF, 0x6B, 0x49,
  42498. 0xFD, 0x64, 0x7F, 0x27, 0xD7, 0xC4, 0x1C, 0x86,
  42499. 0x6E, 0x6C, 0xAD, 0x9D, 0x5E, 0x2E, 0x3E, 0x33,
  42500. 0x1B, 0xF6, 0xB9, 0xF7, 0x2A, 0xCA, 0x32, 0x9B,
  42501. 0xB6, 0x42, 0x59, 0xC3, 0xE7, 0x97, 0x83, 0xA2,
  42502. 0x66, 0x74, 0xB7, 0xD3, 0x8E, 0xBD, 0xE8, 0x31,
  42503. 0x84, 0x11, 0xF4, 0x76, 0x4E, 0xBD, 0xC4, 0xC7,
  42504. 0xE4, 0x1A, 0xCF, 0xF8, 0x5B, 0xBB, 0x30, 0x31,
  42505. 0x8D, 0x59, 0xC4, 0x2C, 0x92, 0x03, 0xAB, 0xD6,
  42506. 0x63, 0x6B, 0xA3, 0xF7, 0x72, 0xB6, 0x72, 0x51,
  42507. 0x21, 0xC0, 0x52, 0xDE, 0x99, 0x91, 0x0D, 0x55,
  42508. 0x15, 0x8C, 0x6F, 0x3E, 0xF8, 0xBB, 0x7F, 0xED,
  42509. 0xE2, 0xF8, 0x1E, 0x58, 0xA7, 0xAE, 0xB2, 0x5E,
  42510. 0x2E, 0x46, 0xFD, 0x72, 0x32, 0x30, 0x2F, 0xAF,
  42511. 0xA8, 0xFC, 0x37, 0xFC, 0x8B, 0x55, 0xD5, 0x94,
  42512. 0xB7, 0x6E, 0xC4, 0xA5, 0x3E, 0xB1, 0x1E, 0xB3,
  42513. 0xFD, 0x63, 0x44, 0x28, 0xAA, 0xA5, 0xD8, 0x6F,
  42514. 0x83, 0x9D, 0x08, 0x9A, 0xBE, 0x2F, 0xEF, 0xE2,
  42515. 0xAE, 0x52, 0x62, 0xFE, 0xFC, 0x73, 0x48, 0xD8,
  42516. 0x36, 0x69, 0x2E, 0xDB, 0x21, 0x5D, 0x6F, 0x8F,
  42517. 0x54, 0x8B, 0x88, 0x52, 0x90, 0xC2, 0x40, 0x3C,
  42518. 0x51, 0xC3, 0xE2, 0x69, 0xD4, 0x93, 0xFB, 0xD3,
  42519. 0x39, 0xB5, 0xDF, 0xB0, 0xA3, 0x8E, 0xED, 0xA7,
  42520. 0x75, 0x4D, 0xAF, 0xFA, 0x16, 0xE5, 0xBC, 0xA5,
  42521. 0xA9, 0xBB, 0xDE, 0x04, 0xB0, 0x14, 0xB7, 0xAE,
  42522. 0xA8, 0x98, 0x8F, 0x37, 0x49, 0xD5, 0x2D, 0x2F,
  42523. 0xC1, 0xC9, 0xF7, 0xC7, 0xB2, 0xC2, 0xD6, 0x92,
  42524. 0xE7, 0x89, 0x6E, 0x4C, 0x34, 0xF5, 0x7C, 0x55,
  42525. 0x8C, 0xFE, 0x83, 0x17, 0xA8, 0x37, 0x44, 0x09,
  42526. 0xD5, 0x66, 0x87, 0x9A, 0x08, 0x62, 0x8F, 0x64,
  42527. 0x4F, 0xB4, 0x5B, 0x81, 0x84, 0x55, 0xBC, 0xA6,
  42528. 0x04, 0x2B, 0x4E, 0x61, 0x87, 0xC1, 0xDD, 0x17,
  42529. 0x7E, 0x9E, 0x51, 0x46, 0x31, 0x99, 0x04, 0xB1,
  42530. 0x50, 0x5F, 0x3E, 0xE0, 0x0C, 0xD7, 0xFE, 0xAF,
  42531. 0x0E, 0x83, 0xC3, 0x02, 0x49, 0x56, 0xF7, 0x76,
  42532. 0x59, 0xAC, 0xC5, 0x6D, 0x8D, 0x91, 0x7A, 0x37,
  42533. 0xE8, 0xFF, 0x7E, 0xB8, 0x87, 0x13, 0xCC, 0xA3,
  42534. 0x34, 0xEA, 0x04, 0xB8, 0xE2, 0x58, 0xC9, 0x34,
  42535. 0x5D, 0xA9, 0xDE, 0x26, 0xA0, 0xA3, 0x66, 0x51,
  42536. 0x94, 0x51, 0xE1, 0x01, 0x2D, 0xE6, 0xAA, 0xBF,
  42537. 0x46, 0x97, 0xC9, 0xDE, 0x82, 0x1D, 0x70, 0x02,
  42538. 0x1C, 0x32, 0x50, 0xA1, 0x06, 0xCF, 0x4C, 0x23,
  42539. 0xA1, 0xB1, 0x78, 0x5F, 0x54, 0x9D, 0x3C, 0x8C,
  42540. 0xD7, 0x1B, 0x05, 0xFE, 0xA7, 0x53, 0xE0, 0x04,
  42541. 0x6A, 0x3A, 0xE0, 0xA9, 0xB1, 0xF4, 0x02, 0x77,
  42542. 0xCF, 0x45, 0x3A, 0x2B, 0xA1, 0x4C, 0xBA, 0x92,
  42543. 0x3C, 0xC6, 0x26, 0x97, 0x06, 0xDF, 0xFF, 0xD5,
  42544. 0x17, 0xC1, 0xE5, 0x93, 0x00, 0x79, 0x91, 0x2E,
  42545. 0x05, 0xA5, 0x57, 0x18, 0x97, 0xA0, 0x68, 0x65,
  42546. 0x51, 0x6C, 0x86, 0x69, 0x9F, 0x70, 0x7E, 0x00,
  42547. 0xCB, 0x38, 0xCE, 0x19, 0x34, 0x90, 0xAE, 0xE3,
  42548. 0x0B, 0xA4, 0x7D, 0xDD, 0xF3, 0xA5, 0xB4, 0xFB,
  42549. 0xCE, 0xBA, 0x73, 0xDC, 0x13, 0xD0, 0xA1, 0x60,
  42550. 0xEA, 0x64, 0x2D, 0x30, 0xD6, 0x3A, 0x02, 0x96,
  42551. 0x4E, 0xDF, 0xDB, 0x2F, 0x29, 0xDC, 0xD3, 0x2C,
  42552. 0xA9, 0x97, 0x4F, 0x89, 0xC3, 0x2D, 0x1F, 0xA9,
  42553. 0xA8, 0x3C, 0x94, 0xA2, 0x77, 0x0F, 0xCF, 0xCF,
  42554. 0x86, 0xE6, 0x46, 0x46, 0x88, 0x2B, 0xD5, 0x50,
  42555. 0xDD, 0xD6, 0x5B, 0x4E, 0x2D, 0x28, 0x7A, 0xF6,
  42556. 0xC1, 0x96, 0xF4, 0x2D, 0xBD, 0x39, 0xB0, 0x20,
  42557. 0xD7, 0xCD, 0xFB, 0xB6, 0xE6, 0xE7, 0x5F, 0xFA,
  42558. 0xAB, 0x26, 0x09, 0x9E, 0xC1, 0xD2, 0x5E, 0x32,
  42559. 0x34, 0xF7, 0x0D, 0xD9, 0x72, 0x28, 0x6A, 0xEA,
  42560. 0x0C, 0x34, 0x36, 0x59, 0x5F, 0xE4, 0x9F, 0xCA,
  42561. 0x89, 0x8B, 0xFA, 0x42, 0x16, 0x04, 0xC8, 0x2D,
  42562. 0x3E, 0x94, 0x85, 0x6D, 0x18, 0x69, 0x05, 0x07,
  42563. 0x6D, 0x18, 0x6C, 0x68, 0x41, 0x74, 0xBF, 0x42,
  42564. 0x90, 0xDF, 0x31, 0x76, 0x9E, 0xDC, 0x97, 0xA1,
  42565. 0xDF, 0x2D, 0xFE, 0xD0, 0x3C, 0xF4, 0x5C, 0xE6,
  42566. 0x78, 0xC8, 0xA1, 0x42, 0x9E, 0xB9, 0x78, 0xD0,
  42567. 0x2A, 0x79, 0xD4, 0xF8, 0xCF, 0x01, 0x68, 0xDA,
  42568. 0xAB, 0x48, 0x2C, 0x6C, 0x61, 0x2F, 0x04, 0xB1,
  42569. 0xC9, 0x36, 0x37, 0xFE, 0x77, 0xB3, 0x02, 0xCE,
  42570. 0xFA, 0x78, 0x8C, 0x11, 0x35, 0x6C, 0x52, 0xC5,
  42571. 0x4F, 0x37, 0xA9, 0xDC, 0xFD, 0xA5, 0x59, 0x27,
  42572. 0xA8, 0xEF, 0x0A, 0x0C, 0xEA, 0x7C, 0xC4, 0xAD,
  42573. 0xCE, 0xE4, 0x59, 0xEB, 0x64, 0xDF, 0x08, 0xED,
  42574. 0x0F, 0xC2, 0x9F, 0xDC, 0x3C, 0x7B, 0x76, 0x2B,
  42575. 0x39, 0x93, 0x32, 0x06, 0x33, 0x40, 0xD4, 0x73,
  42576. 0x96, 0x62, 0x19, 0xBF, 0xC8, 0x7B, 0x4A, 0x3C,
  42577. 0x91, 0xC8, 0x0F, 0x0E, 0x4B, 0xA8, 0x6A, 0xA1,
  42578. 0x87, 0x9C, 0x76, 0x62, 0x5C, 0x86, 0x80, 0xA2,
  42579. 0x27, 0xAB, 0x22, 0x78, 0x06, 0x59, 0xD4, 0xB5,
  42580. 0xD3, 0x0E, 0x0E, 0x9A, 0x0D, 0xCE, 0x09, 0x4D,
  42581. 0xAF, 0x53, 0x76, 0x79, 0x27, 0x3A, 0x9B, 0x27,
  42582. 0x7E, 0xD2, 0xA2, 0xE2, 0x50, 0xEE, 0xA0, 0x93,
  42583. 0x82, 0x04, 0xC9, 0xE9, 0x63, 0xD3, 0x38, 0x52,
  42584. 0x2A, 0x3D, 0x1A, 0x44, 0x40, 0xE2, 0xA1, 0x23,
  42585. 0x97, 0xA5, 0xB9, 0x7D, 0x35, 0x65, 0x73, 0x07,
  42586. 0xBE, 0xC9, 0x4C, 0xC0, 0xC7, 0x2C, 0x5C, 0x6B,
  42587. 0x09, 0xDA, 0xF2, 0xBA, 0xF0, 0x02, 0x0B, 0x7D,
  42588. 0x8C, 0xA5, 0x60, 0xBF, 0x65, 0x96, 0x92, 0x9A,
  42589. 0xC8, 0xD4, 0xE5, 0x46, 0x0F, 0x78, 0x37, 0xB4,
  42590. 0x1B, 0x4A, 0xE6, 0xFF, 0x12, 0x33, 0x9D, 0xB8,
  42591. 0xEB, 0xD7, 0x02, 0x8A, 0xAC, 0xFE, 0x0B, 0x42,
  42592. 0xE0, 0x2C, 0xDE, 0x90, 0x67, 0x83, 0xAB, 0xFF,
  42593. 0x69, 0x4E, 0x7C, 0xBE, 0x08, 0x97, 0xED, 0x6E,
  42594. 0xD4, 0x38, 0xAC, 0xDB, 0x00, 0xA4, 0x70, 0x9C,
  42595. 0xFE, 0xF7, 0x15, 0x0E, 0xBE, 0xB0, 0x8C, 0x8F,
  42596. 0xF6, 0xC1, 0x54, 0x38, 0x15, 0xF4, 0xB8, 0x95,
  42597. 0x1C, 0x3C, 0xAC, 0xE4, 0x99, 0x58, 0x64, 0x58,
  42598. 0xA7, 0x3C, 0x85, 0x72, 0x38, 0x9A, 0xFC, 0x97,
  42599. 0x03, 0xA7, 0xFE, 0xAF, 0x67, 0x34, 0x45, 0xFB,
  42600. 0x4B, 0x0C, 0xCA, 0xA5, 0x11, 0xD4, 0xA2, 0xCF,
  42601. 0x46, 0x3F, 0x57, 0xE3, 0xA6, 0xD7, 0x2D, 0xA0,
  42602. 0x4B, 0x25, 0x66, 0x99, 0xA3, 0x02, 0x12, 0xE7,
  42603. 0xC5, 0x76, 0x8E, 0xFC, 0x15, 0x1B, 0x71, 0x74,
  42604. 0x41, 0x56, 0x57, 0x5A, 0x2E, 0x94, 0x43, 0x31,
  42605. 0x92, 0x32, 0xD1, 0x59, 0xC6, 0xCC, 0x00, 0x6F,
  42606. 0xDB, 0x57, 0xC5, 0x81, 0x73, 0xAD, 0x8D, 0x2C,
  42607. 0x86, 0x6C, 0x88, 0x87, 0x43, 0x7C, 0x22, 0x38,
  42608. 0x88, 0xE2, 0x1E, 0xF6, 0x7E, 0x1A, 0x33, 0x2C,
  42609. 0x1F, 0xDF, 0xCC, 0x15, 0xEF, 0x17, 0x47, 0x6F,
  42610. 0xE0, 0xFB, 0x57, 0xD4, 0x22, 0x98, 0x94, 0x72,
  42611. 0x5E, 0x14, 0x74, 0xC1, 0xBA, 0x12, 0x16, 0x56,
  42612. 0x28, 0x17, 0xF1, 0x6C, 0x53, 0xEC, 0xE0, 0x1C,
  42613. 0x7F, 0x9E, 0x36, 0x64, 0xEE, 0xDB, 0xBA, 0x94,
  42614. 0x95, 0x29, 0x87, 0x43, 0x1A, 0xA2, 0xA5, 0x7D,
  42615. 0x33, 0x0E, 0xB1, 0x1B, 0x28, 0xE6, 0xBF, 0x77,
  42616. 0x0E, 0x34, 0x9E, 0xCE, 0x35, 0x0C, 0x83, 0xE9,
  42617. 0x0D, 0xA6, 0xFE, 0x0D, 0x0A, 0x4A, 0xB9, 0x71,
  42618. 0x5D, 0xB2, 0x8B, 0xDD, 0x39, 0x7F, 0xAF, 0xA1,
  42619. 0x42, 0x83, 0x02, 0x15, 0x1E, 0x1F, 0x22, 0x2B,
  42620. 0x44, 0x69, 0x87, 0x9E, 0xB5, 0xD0, 0xF0, 0x18,
  42621. 0x60, 0x6A, 0x75, 0x94, 0xBF, 0xC8, 0x2C, 0x39,
  42622. 0x4E, 0x91, 0xB9, 0x26, 0x44, 0x95, 0xC9, 0x06,
  42623. 0x3D, 0x50, 0x52, 0x62, 0x79, 0x9B, 0x9F, 0xCB,
  42624. 0xE6, 0x31, 0x6B, 0xBC, 0xC8, 0xD8, 0x09, 0x30,
  42625. 0x53, 0x63, 0x6A, 0x74, 0xD4, 0xFA, 0x00, 0x00,
  42626. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42627. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42628. 0x00, 0x00, 0x00, 0x02, 0x0F, 0x16, 0x1B, 0x1F,
  42629. 0x29, 0x2E, 0x36
  42630. };
  42631. #endif
  42632. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  42633. #ifndef WOLFSSL_NO_ML_DSA_44
  42634. static const byte pk_44_draft[] = {
  42635. 0x35, 0x07, 0x31, 0x3A, 0xE3, 0x7A, 0xF6, 0x96,
  42636. 0x6C, 0x11, 0xA9, 0xE4, 0x0B, 0xEB, 0xEC, 0xE9,
  42637. 0x2B, 0x67, 0x3F, 0xD2, 0x67, 0x3C, 0x1C, 0x4C,
  42638. 0x08, 0xF0, 0x45, 0xA9, 0xDD, 0x5A, 0xB8, 0x8C,
  42639. 0x0A, 0x51, 0xA9, 0xBA, 0x89, 0x0F, 0x4C, 0xCB,
  42640. 0x9D, 0x0A, 0x41, 0x3F, 0x9C, 0xF4, 0x13, 0x36,
  42641. 0x79, 0x49, 0x00, 0x90, 0xBB, 0x57, 0x3B, 0xBD,
  42642. 0x2E, 0x18, 0xB3, 0xD0, 0xA5, 0x0E, 0x6B, 0x67,
  42643. 0xFF, 0x98, 0x8C, 0xDD, 0x07, 0xE8, 0xA7, 0xA1,
  42644. 0x3F, 0xAE, 0xFB, 0xD6, 0xC0, 0xF8, 0xF3, 0x34,
  42645. 0xA5, 0x17, 0xC2, 0x34, 0x88, 0x92, 0x65, 0xA6,
  42646. 0xE8, 0x66, 0x57, 0xFE, 0x86, 0x08, 0xF7, 0xDF,
  42647. 0xA0, 0x5B, 0x70, 0x3E, 0x91, 0x6C, 0x63, 0xA0,
  42648. 0xA3, 0x75, 0x55, 0xF8, 0xB6, 0xAA, 0xD4, 0x1B,
  42649. 0x78, 0x5E, 0x42, 0x9F, 0x96, 0xE4, 0xA0, 0x50,
  42650. 0xB6, 0x94, 0x2D, 0xC3, 0xE3, 0x36, 0x2B, 0x9D,
  42651. 0x6B, 0x7A, 0xEF, 0xF5, 0x68, 0xF2, 0x11, 0xDF,
  42652. 0x87, 0xA0, 0x9A, 0xC4, 0x61, 0xFB, 0xA4, 0x1C,
  42653. 0x98, 0x3F, 0xC9, 0x52, 0x59, 0x3B, 0x47, 0x4D,
  42654. 0xF5, 0x24, 0xA3, 0xD8, 0x63, 0xE1, 0xED, 0xDC,
  42655. 0xFD, 0xEB, 0x96, 0xFB, 0xF3, 0xE7, 0x50, 0x9C,
  42656. 0x72, 0x61, 0xC7, 0x3C, 0xCE, 0xF2, 0xEB, 0x22,
  42657. 0x55, 0x6B, 0x9F, 0x25, 0xE4, 0x45, 0xE1, 0xFB,
  42658. 0x3E, 0x2E, 0x4E, 0x92, 0x4F, 0x8A, 0x85, 0xEB,
  42659. 0x63, 0x2C, 0x05, 0x0F, 0x9A, 0xEC, 0x0E, 0x9D,
  42660. 0x05, 0x81, 0x46, 0x82, 0xEA, 0x74, 0x91, 0xD5,
  42661. 0x2A, 0xBC, 0xCC, 0xBB, 0xD6, 0x7F, 0x5F, 0x9A,
  42662. 0xD3, 0xBD, 0xEB, 0x14, 0xBA, 0x84, 0x27, 0x13,
  42663. 0x32, 0xB5, 0xF3, 0x71, 0xAC, 0x47, 0x19, 0x6B,
  42664. 0x5E, 0x43, 0x50, 0xC2, 0xA8, 0x82, 0xF5, 0x97,
  42665. 0x9B, 0x27, 0x62, 0xFB, 0xB7, 0xFF, 0x6B, 0xC8,
  42666. 0x52, 0x1E, 0xFB, 0x97, 0x39, 0x1E, 0x7F, 0x01,
  42667. 0xF8, 0x34, 0x47, 0xAA, 0xB2, 0x64, 0xB5, 0x9E,
  42668. 0x28, 0x18, 0xCB, 0x4A, 0x94, 0xBE, 0x6A, 0x43,
  42669. 0x5B, 0xAE, 0x21, 0xA4, 0x63, 0x64, 0x46, 0x0C,
  42670. 0x6B, 0x36, 0x1C, 0x2A, 0x3B, 0x64, 0xFA, 0xA0,
  42671. 0xAB, 0xE3, 0x3B, 0x7D, 0xB0, 0x23, 0x99, 0x21,
  42672. 0x55, 0x59, 0xBF, 0xD6, 0xDB, 0xB8, 0xDB, 0x09,
  42673. 0x5E, 0xBC, 0x32, 0x3C, 0xAC, 0xAB, 0x1A, 0x63,
  42674. 0x32, 0x21, 0x10, 0xD5, 0x8D, 0x7A, 0x5F, 0xCE,
  42675. 0x72, 0x8D, 0x2A, 0xED, 0x1D, 0x30, 0x38, 0x5D,
  42676. 0x3E, 0x62, 0xC2, 0x8E, 0xC9, 0x9F, 0x8C, 0x50,
  42677. 0x3F, 0xC6, 0xCE, 0x86, 0x4D, 0x67, 0x3D, 0x09,
  42678. 0xB6, 0x27, 0x14, 0x57, 0x14, 0xED, 0xC9, 0x8F,
  42679. 0xAC, 0x9E, 0xAC, 0x6F, 0xB5, 0xB2, 0xE6, 0x8D,
  42680. 0x9D, 0x5E, 0xE6, 0x78, 0x77, 0x09, 0x94, 0x35,
  42681. 0x5E, 0x3B, 0x64, 0x04, 0x38, 0xD4, 0x5B, 0x04,
  42682. 0xB8, 0x6C, 0x33, 0x97, 0xE1, 0x58, 0x54, 0x32,
  42683. 0xB3, 0x0F, 0x37, 0x69, 0x39, 0xCE, 0x57, 0x31,
  42684. 0x5C, 0x75, 0xA8, 0x94, 0xD0, 0x39, 0x2D, 0xB4,
  42685. 0x73, 0xA7, 0xA4, 0x7C, 0xBE, 0x34, 0x03, 0x2D,
  42686. 0x99, 0x1D, 0xDF, 0x32, 0x26, 0xB7, 0x45, 0x1B,
  42687. 0x03, 0xCD, 0xEE, 0x9D, 0x58, 0xA8, 0xA7, 0x76,
  42688. 0x1B, 0x17, 0x42, 0xD9, 0x69, 0x0F, 0x26, 0x3A,
  42689. 0x9D, 0x70, 0x9B, 0x4E, 0x81, 0xEB, 0x96, 0x02,
  42690. 0xB5, 0xB3, 0x92, 0x31, 0xFE, 0xBC, 0x38, 0x11,
  42691. 0x5A, 0x47, 0xED, 0x0A, 0x2A, 0xE2, 0xB8, 0x47,
  42692. 0x13, 0x5E, 0x43, 0x97, 0xD5, 0xFA, 0x31, 0x02,
  42693. 0x58, 0xE9, 0x9E, 0xB5, 0x3F, 0x85, 0x92, 0x0E,
  42694. 0xB9, 0xDB, 0xE0, 0xEE, 0x56, 0x76, 0x64, 0x8F,
  42695. 0xF2, 0xE2, 0x47, 0x81, 0xD4, 0xA4, 0x82, 0x43,
  42696. 0x69, 0xAE, 0x8E, 0x48, 0x50, 0x84, 0x93, 0x3B,
  42697. 0x9C, 0x65, 0xD3, 0x6F, 0xCD, 0x90, 0xA0, 0xD8,
  42698. 0xA0, 0xE1, 0x79, 0xCC, 0xD5, 0x1F, 0x71, 0x73,
  42699. 0x93, 0xE7, 0xB2, 0xB0, 0x78, 0x17, 0xD7, 0x79,
  42700. 0xDE, 0xCC, 0x83, 0x7D, 0x5A, 0xF2, 0x0E, 0xA6,
  42701. 0xB1, 0x76, 0x61, 0x15, 0x88, 0x8E, 0xD7, 0xA6,
  42702. 0x51, 0xBF, 0x9C, 0xD1, 0x0A, 0xFC, 0xDA, 0x65,
  42703. 0xA5, 0x65, 0xFE, 0xB2, 0xED, 0x07, 0x74, 0x42,
  42704. 0x4C, 0xF5, 0x42, 0x3D, 0xAF, 0x5F, 0x4D, 0x72,
  42705. 0x51, 0xE6, 0x3F, 0x68, 0xCC, 0xC5, 0x2D, 0x89,
  42706. 0x01, 0xD8, 0x80, 0xB4, 0xFC, 0xEB, 0x3B, 0xBE,
  42707. 0x7C, 0xFA, 0x24, 0x27, 0xE1, 0x05, 0x94, 0x67,
  42708. 0xAD, 0xB3, 0x47, 0x7D, 0x28, 0x18, 0xC1, 0xC9,
  42709. 0xB8, 0xA1, 0x2A, 0x95, 0xBB, 0x5D, 0xC9, 0x42,
  42710. 0x4F, 0x64, 0x94, 0x07, 0x5F, 0x65, 0xD3, 0xA5,
  42711. 0x65, 0xEE, 0x67, 0x2C, 0x10, 0x65, 0x81, 0x4D,
  42712. 0x7F, 0xAF, 0x2E, 0x97, 0x9E, 0x11, 0xA3, 0xF5,
  42713. 0x3E, 0xDE, 0xB1, 0x1D, 0x44, 0x72, 0x90, 0x74,
  42714. 0xFD, 0x47, 0x82, 0xA6, 0x04, 0x3E, 0x28, 0x3C,
  42715. 0x15, 0xDF, 0xC4, 0x7A, 0x7C, 0xF5, 0x5A, 0xC6,
  42716. 0xFB, 0xE4, 0xC2, 0xE0, 0x6E, 0x4C, 0x09, 0x2E,
  42717. 0xE3, 0xE6, 0x3A, 0xEF, 0xF6, 0x54, 0xDC, 0x92,
  42718. 0xBE, 0x8F, 0x24, 0x8E, 0x70, 0x53, 0x90, 0x3D,
  42719. 0x06, 0xA5, 0x0A, 0x72, 0xA0, 0x7B, 0x22, 0x14,
  42720. 0x80, 0x43, 0xAD, 0xDC, 0x11, 0xFC, 0xFF, 0xCF,
  42721. 0x5E, 0xA4, 0x69, 0x1C, 0x09, 0x09, 0xC3, 0x3D,
  42722. 0xF5, 0xE7, 0x05, 0x6F, 0x16, 0x33, 0x75, 0xB4,
  42723. 0x9B, 0x7B, 0x26, 0xDB, 0xE7, 0x27, 0x56, 0xD3,
  42724. 0x91, 0x82, 0x9D, 0xEB, 0x96, 0x3E, 0xE8, 0x40,
  42725. 0xAB, 0x5D, 0x6C, 0xB7, 0xA6, 0x36, 0x07, 0xD4,
  42726. 0xE7, 0x7C, 0xD4, 0x5C, 0x36, 0xE4, 0xFC, 0x7C,
  42727. 0x8A, 0x36, 0x8D, 0x53, 0x43, 0xD4, 0xAC, 0x0B,
  42728. 0x1B, 0xBA, 0x32, 0x88, 0xFA, 0xCE, 0xC1, 0xB9,
  42729. 0x34, 0x3C, 0xAC, 0xA0, 0xF4, 0xF2, 0x83, 0xA8,
  42730. 0xBB, 0x6F, 0x12, 0xC6, 0xB5, 0x3C, 0xDE, 0xA8,
  42731. 0x49, 0x66, 0x97, 0xD7, 0x7E, 0x37, 0xF7, 0xCE,
  42732. 0x7C, 0xF8, 0xC8, 0xBB, 0x8C, 0xB5, 0x3B, 0x3F,
  42733. 0xB9, 0x51, 0x68, 0x00, 0xD7, 0x2E, 0x1C, 0x10,
  42734. 0xAF, 0x9F, 0x3C, 0xD2, 0xAC, 0xE5, 0xBE, 0x94,
  42735. 0xB9, 0x60, 0xF5, 0xB2, 0x70, 0x24, 0xE8, 0x8A,
  42736. 0x2C, 0xD8, 0x95, 0xAF, 0xAA, 0xA9, 0xA5, 0x2B,
  42737. 0xCA, 0xE0, 0x58, 0x44, 0x02, 0x3F, 0xF8, 0x21,
  42738. 0x0C, 0x29, 0xB7, 0xD5, 0x08, 0x9E, 0x69, 0x81,
  42739. 0xD4, 0x6C, 0xC5, 0x0B, 0xF6, 0xEF, 0xAB, 0x01,
  42740. 0xEA, 0xDF, 0x36, 0x2C, 0x5C, 0xFB, 0xEB, 0xC8,
  42741. 0x4F, 0x71, 0x80, 0xD7, 0x00, 0xC9, 0x32, 0x5D,
  42742. 0x02, 0x4F, 0x96, 0x94, 0x71, 0xCD, 0x98, 0xC4,
  42743. 0x25, 0x7A, 0x92, 0xF1, 0x9B, 0xA0, 0x34, 0x30,
  42744. 0x6C, 0x41, 0x59, 0xD5, 0x01, 0x5D, 0xD6, 0x56,
  42745. 0xEA, 0x05, 0xF2, 0xFC, 0xF8, 0x58, 0xFA, 0x12,
  42746. 0x9C, 0x5A, 0x5C, 0xD5, 0x3D, 0xC7, 0x5D, 0x1B,
  42747. 0x99, 0x2A, 0x6A, 0x4C, 0xF9, 0xEA, 0x9D, 0x70,
  42748. 0x53, 0xBC, 0xBE, 0xAD, 0x61, 0xC7, 0x2D, 0x77,
  42749. 0xEF, 0x61, 0xC7, 0xBE, 0x9C, 0x73, 0xC1, 0xD5,
  42750. 0xD4, 0x5C, 0x5F, 0x21, 0x6A, 0x5C, 0xEE, 0x78,
  42751. 0xAA, 0xC6, 0x6C, 0x56, 0xDB, 0x38, 0x5A, 0x94,
  42752. 0x12, 0xB8, 0x73, 0x7C, 0xDF, 0x9A, 0x27, 0xCD,
  42753. 0xC5, 0xD1, 0xD3, 0xCA, 0x0E, 0x37, 0x0A, 0xC1,
  42754. 0x6F, 0xAD, 0xE3, 0x32, 0x94, 0x6C, 0x20, 0xB5,
  42755. 0xED, 0xE6, 0x2D, 0x34, 0x39, 0x58, 0xD2, 0x1E,
  42756. 0x63, 0x8D, 0xFA, 0xFF, 0xB5, 0xE8, 0x40, 0xC8,
  42757. 0x42, 0x38, 0x7A, 0x01, 0x80, 0xFF, 0x52, 0x3F,
  42758. 0xE9, 0x89, 0x63, 0xAD, 0x91, 0x5F, 0xCE, 0x0A,
  42759. 0x47, 0x87, 0xF9, 0x6D, 0xD7, 0x79, 0xEF, 0xCE,
  42760. 0x10, 0x7B, 0x73, 0x43, 0xBE, 0x51, 0xA0, 0xDF,
  42761. 0xE5, 0xEC, 0xA9, 0x63, 0xF6, 0x5E, 0x72, 0x36,
  42762. 0x22, 0x86, 0xEE, 0x4E, 0x4A, 0x76, 0xFD, 0x86,
  42763. 0xBA, 0xE6, 0xD6, 0xC4, 0xD2, 0xE6, 0xFF, 0xB2,
  42764. 0x5B, 0x39, 0xF9, 0xC3, 0x29, 0xA8, 0x61, 0x3A,
  42765. 0x33, 0x34, 0x89, 0xC9, 0x83, 0xF9, 0xB2, 0x70,
  42766. 0x21, 0x54, 0x44, 0x94, 0x70, 0xAD, 0x70, 0x18,
  42767. 0x84, 0x38, 0x91, 0xFB, 0xDE, 0x5E, 0x3D, 0xE3,
  42768. 0xB2, 0xA7, 0x3C, 0x1D, 0x49, 0xA6, 0x66, 0x7C,
  42769. 0x4B, 0xEB, 0xB0, 0xA7, 0x7C, 0xC5, 0xAE, 0x45,
  42770. 0x1F, 0xBE, 0x0E, 0x2F, 0x11, 0xDC, 0x92, 0x08,
  42771. 0xAA, 0x18, 0x38, 0xFE, 0x61, 0xBE, 0x9D, 0xC3,
  42772. 0x3A, 0x1F, 0x2F, 0xB6, 0x6E, 0xB6, 0x54, 0x97,
  42773. 0x74, 0x06, 0xBC, 0x12, 0x2D, 0x64, 0x18, 0x14,
  42774. 0x25, 0x5A, 0xCB, 0x7B, 0xD7, 0x9D, 0xC3, 0x2C,
  42775. 0xC2, 0x0B, 0x19, 0x10, 0xD2, 0x57, 0xF0, 0xDF,
  42776. 0xA4, 0x95, 0xA4, 0x5A, 0xA0, 0x2D, 0x0F, 0xA0,
  42777. 0xBC, 0xF7, 0x60, 0x7F, 0x38, 0xE1, 0x17, 0x0D,
  42778. 0x36, 0x08, 0xF5, 0xF9, 0x75, 0x28, 0x75, 0xAC,
  42779. 0xA9, 0x2B, 0x75, 0xC4, 0x41, 0xE0, 0x0D, 0x5C,
  42780. 0xBC, 0x5F, 0x49, 0x16, 0x25, 0x38, 0x16, 0xE1,
  42781. 0x0C, 0x2C, 0x9C, 0x63, 0xA8, 0x5F, 0x70, 0xF4,
  42782. 0x64, 0xC7, 0x10, 0x19, 0x52, 0x19, 0x6E, 0x9B,
  42783. 0x5C, 0x09, 0x4F, 0xEE, 0xB6, 0x7C, 0x85, 0xC9,
  42784. 0x6E, 0xCB, 0x33, 0x32, 0x42, 0x9D, 0x57, 0x18,
  42785. 0xE6, 0x55, 0x94, 0x74, 0x02, 0xEE, 0xEB, 0xAA,
  42786. 0xF7, 0xD3, 0x45, 0x7A, 0x49, 0x6F, 0x83, 0x89,
  42787. 0x00, 0xE4, 0xAA, 0x20, 0x87, 0x10, 0xAD, 0xC0,
  42788. 0x0E, 0xF5, 0x93, 0x57, 0xE5, 0x45, 0x7A, 0xBD,
  42789. 0x82, 0x87, 0x50, 0x0F, 0xE1, 0x2C, 0x0C, 0x6D,
  42790. 0xEE, 0xC8, 0x94, 0xB8, 0x39, 0xF3, 0x3C, 0xFE,
  42791. 0x7E, 0xC1, 0x0F, 0xB4, 0x67, 0xA2, 0xDF, 0xC6,
  42792. 0x9D, 0xB5, 0x9D, 0xB8, 0x72, 0x50, 0xBD, 0xB3,
  42793. 0xDB, 0xF6, 0x87, 0x5E, 0x26, 0x93, 0xF0, 0xD4,
  42794. 0x0D, 0x68, 0xA4, 0x8B, 0xBD, 0x2C, 0x6E, 0xD8,
  42795. 0x4F, 0x81, 0x5D, 0x0D, 0xAC, 0x72, 0x65, 0xEC,
  42796. 0x4E, 0xF2, 0x4E, 0x5F, 0x67, 0x04, 0xF3, 0x08,
  42797. 0x29, 0x4D, 0xB2, 0xE2, 0xD5, 0x9F, 0xD4, 0xB9,
  42798. 0x13, 0xB4, 0x33, 0x80, 0x27, 0x84, 0x7E, 0xF4
  42799. };
  42800. static const byte msg_44_draft[] = {
  42801. 0x5C, 0x70, 0x7F, 0xBF, 0xF4, 0xFF, 0xE5, 0x9B,
  42802. 0x09, 0xAA, 0xF8, 0xDB, 0x21, 0xAD, 0xBE, 0xBA,
  42803. 0xC6, 0xB2, 0x65, 0x37, 0x9A, 0x9A, 0x43, 0x3A,
  42804. 0xA8, 0x23, 0x2B, 0x13, 0x9B, 0xBD, 0x46, 0x37,
  42805. 0x30, 0x60, 0xA7, 0x5B, 0xC4, 0x48, 0x63, 0x5F,
  42806. 0x41, 0x35, 0x38, 0x69, 0xF9, 0x6F, 0xB5, 0x65,
  42807. 0x26, 0xDB, 0xAE, 0xB7, 0x5C, 0xFE, 0x2C, 0x03,
  42808. 0xCB, 0x43, 0x08, 0x58, 0x5E, 0x27, 0xD1, 0x42,
  42809. 0x14, 0xF2, 0x4B, 0xD7, 0x13, 0xE4, 0x96, 0x74,
  42810. 0x6A, 0xC1, 0x36, 0xC7, 0x9D, 0x0F, 0x7D, 0xB0,
  42811. 0x7B, 0x8A, 0x3A, 0x6D, 0x00, 0x5B, 0x29, 0x7B,
  42812. 0x37, 0xBA, 0x3F, 0x5B, 0xBD, 0xCE, 0x21, 0x77,
  42813. 0xFD, 0xD6, 0x78, 0x77, 0x20, 0x31, 0xF0, 0x60,
  42814. 0x49, 0xAE, 0x12, 0x86, 0x7A, 0x64, 0xBD, 0x0B,
  42815. 0x9E, 0xC6, 0x26, 0x80, 0x9E, 0xCE, 0x19, 0x8D,
  42816. 0x6A, 0x6B, 0x09, 0x03, 0x45, 0xDF, 0x22, 0x7D
  42817. };
  42818. static const byte sig_44_draft[] = {
  42819. 0x08, 0xF0, 0x10, 0xFA, 0x63, 0x3F, 0x2B, 0xA1,
  42820. 0x46, 0x81, 0x34, 0xC4, 0xBC, 0xAB, 0x62, 0x17,
  42821. 0x0B, 0x64, 0xEA, 0x00, 0x2D, 0xD6, 0x8A, 0xE5,
  42822. 0xC2, 0x45, 0x29, 0xB9, 0xEC, 0x6F, 0x3B, 0xF2,
  42823. 0xDC, 0x2F, 0xC7, 0x34, 0x5A, 0x1E, 0xFE, 0x0C,
  42824. 0xCA, 0xB9, 0x6A, 0xD8, 0xDA, 0xBA, 0xAA, 0x80,
  42825. 0x90, 0xDC, 0x8C, 0x6C, 0x22, 0xFF, 0xC4, 0x90,
  42826. 0x9E, 0xE9, 0xA5, 0x45, 0xFC, 0xE8, 0x64, 0x53,
  42827. 0x9E, 0xC4, 0x17, 0xE1, 0xB2, 0x1A, 0x31, 0x40,
  42828. 0x26, 0x9D, 0x5E, 0x03, 0x6A, 0xC6, 0x09, 0x19,
  42829. 0xDD, 0xB3, 0x63, 0xE0, 0x35, 0xCD, 0xB4, 0x2E,
  42830. 0x25, 0x38, 0x6E, 0x6C, 0x76, 0xA9, 0x19, 0x75,
  42831. 0x68, 0x6E, 0xB7, 0xAB, 0xAD, 0x8F, 0x63, 0x64,
  42832. 0x97, 0x4E, 0x56, 0x82, 0x30, 0x45, 0x86, 0x22,
  42833. 0x64, 0xDA, 0xD2, 0xAE, 0x54, 0x70, 0x5C, 0xF1,
  42834. 0xEB, 0xD1, 0x84, 0x8D, 0xFF, 0x86, 0x15, 0xE6,
  42835. 0x20, 0xCE, 0x14, 0x89, 0xEF, 0xFA, 0x2E, 0xF8,
  42836. 0x60, 0xCA, 0x53, 0x52, 0xE4, 0xD5, 0xC8, 0x2E,
  42837. 0x50, 0xD5, 0x9D, 0x90, 0xA6, 0x12, 0xC7, 0xF1,
  42838. 0x70, 0x0D, 0xE2, 0x89, 0x5B, 0x31, 0x6A, 0x21,
  42839. 0x79, 0x9C, 0xBE, 0x77, 0x6E, 0xA6, 0xBF, 0x51,
  42840. 0x05, 0x2A, 0x83, 0x50, 0x7E, 0x86, 0x14, 0xD1,
  42841. 0x50, 0x53, 0x1F, 0x1C, 0x5E, 0x50, 0x24, 0x69,
  42842. 0x6C, 0x91, 0x55, 0x35, 0x19, 0x6F, 0xE0, 0xDC,
  42843. 0xB5, 0xD6, 0x48, 0x7E, 0x78, 0x61, 0x59, 0x2C,
  42844. 0xD0, 0x1B, 0x42, 0x58, 0xAF, 0x7A, 0x39, 0xCA,
  42845. 0x02, 0x1C, 0x50, 0xEF, 0xE9, 0xE1, 0xDE, 0x31,
  42846. 0x8D, 0x09, 0x51, 0xC9, 0xDB, 0x16, 0xF9, 0xB9,
  42847. 0x45, 0x54, 0x81, 0x16, 0xD7, 0x14, 0xD8, 0xBE,
  42848. 0x9C, 0xCA, 0x53, 0xFE, 0x8F, 0x24, 0x99, 0x0D,
  42849. 0xBA, 0x7F, 0x99, 0x42, 0x11, 0x9B, 0x32, 0xDD,
  42850. 0x93, 0x5C, 0xBA, 0x2D, 0xD3, 0xB3, 0xF2, 0x48,
  42851. 0x13, 0x9C, 0x80, 0xBB, 0x8D, 0xF4, 0xC7, 0xAA,
  42852. 0xEB, 0xC6, 0xFD, 0xB8, 0x35, 0x95, 0x87, 0x2B,
  42853. 0x9E, 0xCF, 0x48, 0xF3, 0x2D, 0xFF, 0x70, 0xF4,
  42854. 0xCE, 0x35, 0x68, 0x7E, 0x9D, 0xDF, 0xD5, 0x0C,
  42855. 0xCD, 0xE3, 0x51, 0xB0, 0x90, 0x86, 0xE5, 0xD1,
  42856. 0xF1, 0x3B, 0x72, 0x42, 0x73, 0x07, 0x03, 0xE2,
  42857. 0xFB, 0x40, 0x3F, 0xD4, 0xC8, 0x30, 0xB6, 0x86,
  42858. 0x49, 0x8A, 0x17, 0xDB, 0x8F, 0x46, 0x6C, 0x3A,
  42859. 0xC3, 0x49, 0xCD, 0x59, 0x68, 0x81, 0x66, 0x03,
  42860. 0xD7, 0x24, 0xAF, 0x1F, 0x77, 0xC7, 0xFB, 0xF7,
  42861. 0x83, 0xCD, 0xA2, 0x6D, 0x35, 0x0C, 0x8B, 0xBC,
  42862. 0x29, 0x3A, 0x7F, 0xAC, 0xB9, 0xF9, 0x78, 0x50,
  42863. 0x6A, 0x67, 0xFC, 0xDC, 0x6F, 0x01, 0x65, 0x06,
  42864. 0x82, 0x81, 0xB0, 0x7D, 0x25, 0x5D, 0x74, 0x0B,
  42865. 0x68, 0x5F, 0x51, 0x2C, 0x82, 0xF3, 0x1D, 0x92,
  42866. 0xF6, 0xA9, 0xA9, 0x6A, 0x77, 0x57, 0x58, 0xAA,
  42867. 0x7C, 0xBE, 0x35, 0xF4, 0x56, 0xDE, 0x42, 0x01,
  42868. 0x2D, 0xB8, 0x28, 0x83, 0x7B, 0xA0, 0xA9, 0x7D,
  42869. 0xC3, 0x30, 0x13, 0x52, 0xD0, 0xA1, 0xC8, 0xA1,
  42870. 0x2C, 0x51, 0x49, 0xAE, 0xA8, 0x04, 0xCB, 0xA8,
  42871. 0x66, 0x01, 0x26, 0xDF, 0x2D, 0x1C, 0x21, 0xA2,
  42872. 0x4E, 0xBD, 0xA5, 0x48, 0x2A, 0x2D, 0x56, 0x60,
  42873. 0x20, 0x98, 0x4D, 0x15, 0x7D, 0x02, 0xB6, 0x3A,
  42874. 0xE4, 0x11, 0xAE, 0xF7, 0x3E, 0x5D, 0x56, 0x4F,
  42875. 0x6A, 0xA3, 0x0A, 0xEA, 0xCC, 0x35, 0x8A, 0xB7,
  42876. 0xC4, 0x8F, 0x25, 0x3E, 0x42, 0x41, 0x2B, 0xA5,
  42877. 0x1F, 0xA7, 0x3B, 0x87, 0x22, 0x86, 0x79, 0xD5,
  42878. 0xE5, 0x2A, 0xA2, 0xCD, 0x68, 0xCE, 0xB8, 0x18,
  42879. 0x6D, 0xEF, 0x1C, 0x36, 0x7F, 0x75, 0x50, 0x36,
  42880. 0x1B, 0x58, 0xEB, 0x32, 0xA1, 0xC8, 0xAF, 0x47,
  42881. 0xE1, 0x26, 0x73, 0x1F, 0x5D, 0x73, 0x30, 0x13,
  42882. 0x2F, 0xC7, 0x8B, 0xA3, 0x03, 0xB4, 0xA8, 0x86,
  42883. 0x25, 0x29, 0xD1, 0x75, 0x10, 0xEE, 0x7F, 0x56,
  42884. 0xBC, 0x0D, 0x59, 0xB4, 0xAE, 0xC9, 0x44, 0x0A,
  42885. 0xF7, 0x0D, 0xBF, 0x17, 0x6A, 0x22, 0x9C, 0x75,
  42886. 0x2B, 0x3E, 0x22, 0xB8, 0x2F, 0x4B, 0x68, 0xF1,
  42887. 0x07, 0xE3, 0x47, 0x47, 0x21, 0x9C, 0xA3, 0x5B,
  42888. 0x31, 0x0A, 0x14, 0xD9, 0x7C, 0xA8, 0xC0, 0xC6,
  42889. 0x5C, 0xAD, 0x05, 0xD6, 0x15, 0xD3, 0xEC, 0xEC,
  42890. 0x32, 0xC2, 0xFF, 0xF4, 0x96, 0x9C, 0xC8, 0x65,
  42891. 0xA0, 0xB2, 0xD6, 0xF4, 0x98, 0xBB, 0xB1, 0x4E,
  42892. 0xA5, 0x11, 0x3B, 0x4E, 0xA8, 0xEB, 0x90, 0xAB,
  42893. 0xD8, 0x25, 0x10, 0xE3, 0x66, 0xB5, 0xA5, 0x11,
  42894. 0x60, 0xA0, 0xCB, 0xDF, 0x77, 0x8A, 0x80, 0x4C,
  42895. 0x07, 0x9B, 0x1B, 0x45, 0x95, 0x29, 0x1D, 0x88,
  42896. 0x85, 0xAC, 0x32, 0x94, 0x26, 0x87, 0x12, 0x0A,
  42897. 0x2F, 0x9E, 0xAE, 0x69, 0x79, 0x25, 0x5A, 0x50,
  42898. 0xF4, 0xDB, 0x15, 0x20, 0x9F, 0x7A, 0x7A, 0xF2,
  42899. 0xE5, 0x8A, 0x63, 0x6A, 0xDD, 0xBD, 0x06, 0xCB,
  42900. 0x42, 0xF0, 0x20, 0xA9, 0x3B, 0x52, 0xD8, 0x68,
  42901. 0x37, 0x71, 0x07, 0xB8, 0x5B, 0xFE, 0xA0, 0xEC,
  42902. 0xBD, 0x75, 0xFF, 0x9C, 0x89, 0xDF, 0x01, 0xE7,
  42903. 0x17, 0x7D, 0xA7, 0xE8, 0x27, 0x9E, 0xA2, 0x41,
  42904. 0x66, 0xE6, 0xDB, 0x8B, 0x5A, 0x3F, 0x6C, 0xC9,
  42905. 0xE3, 0x4F, 0x0D, 0xD0, 0x92, 0x1E, 0x27, 0x41,
  42906. 0xF2, 0xB3, 0x08, 0x32, 0x03, 0x6D, 0x2C, 0x4F,
  42907. 0x78, 0xEC, 0x99, 0xB3, 0x94, 0x6C, 0xC1, 0x89,
  42908. 0xD9, 0x34, 0x0F, 0xEF, 0x10, 0xF0, 0xDA, 0xCE,
  42909. 0x09, 0x69, 0x7A, 0x93, 0xC6, 0xFF, 0x19, 0x4F,
  42910. 0xBD, 0xDE, 0xA6, 0x54, 0x8A, 0xE5, 0x81, 0x3F,
  42911. 0x96, 0xD3, 0xA0, 0x77, 0x7C, 0xF2, 0x4B, 0xF1,
  42912. 0x68, 0xA2, 0x23, 0x3D, 0xD4, 0x16, 0xC1, 0x66,
  42913. 0xDA, 0x13, 0x53, 0xE1, 0x9F, 0x9A, 0x36, 0x09,
  42914. 0x4D, 0x72, 0x08, 0x09, 0xEB, 0x87, 0x74, 0x9A,
  42915. 0xB2, 0x8C, 0x60, 0x7F, 0xFB, 0x70, 0x17, 0x51,
  42916. 0xB1, 0xAC, 0x18, 0xDF, 0xCB, 0x43, 0x2A, 0xD3,
  42917. 0x89, 0xDA, 0x78, 0xAE, 0xDC, 0xEA, 0xB2, 0x22,
  42918. 0xCA, 0x2F, 0xF1, 0xE4, 0xA7, 0xCC, 0xAF, 0xB1,
  42919. 0x63, 0x1B, 0x5D, 0xDD, 0xD1, 0x49, 0xB8, 0x90,
  42920. 0x2E, 0xC9, 0xC0, 0x83, 0x0D, 0xAB, 0x88, 0x88,
  42921. 0x4C, 0x74, 0x72, 0x00, 0x7D, 0xFE, 0xF2, 0x46,
  42922. 0x73, 0xFD, 0x99, 0xEC, 0x89, 0x8B, 0x3B, 0x0F,
  42923. 0xCE, 0x35, 0x5A, 0xEA, 0x13, 0x4F, 0x67, 0x67,
  42924. 0xFD, 0x0D, 0x87, 0xFC, 0xB1, 0x36, 0x48, 0x07,
  42925. 0x33, 0x0B, 0xCA, 0xD4, 0xD7, 0xD0, 0xCC, 0xA1,
  42926. 0x8F, 0xF0, 0x3F, 0x01, 0x8B, 0x6B, 0x74, 0x44,
  42927. 0x2F, 0x1B, 0xE0, 0x65, 0x31, 0x1B, 0x4E, 0xDB,
  42928. 0x67, 0x65, 0xA9, 0x34, 0xE8, 0x4D, 0x0C, 0xF3,
  42929. 0x29, 0xED, 0x53, 0xAB, 0x8A, 0x98, 0x07, 0x2B,
  42930. 0xE0, 0xCD, 0xC0, 0x08, 0x82, 0x4A, 0x72, 0x28,
  42931. 0x72, 0xA2, 0xAC, 0xFE, 0xF7, 0xBF, 0x6E, 0x8E,
  42932. 0xF8, 0x3E, 0x04, 0x58, 0xA4, 0x36, 0x46, 0x33,
  42933. 0xAB, 0xDD, 0x0E, 0xBF, 0x01, 0xD2, 0xEF, 0x19,
  42934. 0x5B, 0x78, 0x2B, 0x30, 0x51, 0x25, 0x50, 0xD0,
  42935. 0xB5, 0x82, 0xC7, 0x20, 0x0D, 0xA1, 0x2C, 0x38,
  42936. 0xAF, 0x44, 0xFC, 0xBD, 0x49, 0xB8, 0x7F, 0x89,
  42937. 0xEF, 0xBE, 0x37, 0x5C, 0xCB, 0xA2, 0x11, 0x75,
  42938. 0x7D, 0xDA, 0xA8, 0x7B, 0x3A, 0x3C, 0x10, 0x11,
  42939. 0x4D, 0x9F, 0x99, 0xAB, 0x4B, 0xA2, 0x20, 0x7A,
  42940. 0x5F, 0x96, 0xEF, 0x1C, 0x00, 0xD7, 0x27, 0x17,
  42941. 0x77, 0x7C, 0x51, 0x58, 0x4B, 0x13, 0x97, 0x53,
  42942. 0x2A, 0xC6, 0x86, 0x4D, 0x3B, 0x8E, 0xBB, 0x4F,
  42943. 0xB8, 0xA0, 0x84, 0x87, 0xF6, 0xEF, 0x55, 0x12,
  42944. 0x2B, 0xCF, 0x9E, 0x5C, 0xD0, 0x0E, 0xBC, 0x1E,
  42945. 0x79, 0x53, 0xE7, 0x8C, 0x4D, 0x8B, 0xCB, 0x20,
  42946. 0xF6, 0xEA, 0x72, 0x0A, 0x63, 0x2F, 0x0C, 0xCF,
  42947. 0x57, 0x27, 0x26, 0xF4, 0x3A, 0x95, 0xCA, 0xBE,
  42948. 0xB5, 0x7C, 0x47, 0x60, 0x10, 0xCD, 0x28, 0x9E,
  42949. 0x02, 0x64, 0xC9, 0x8D, 0x82, 0x49, 0xD0, 0xD6,
  42950. 0x60, 0xF8, 0xDC, 0xC8, 0x4B, 0x7D, 0xB5, 0xEF,
  42951. 0x11, 0x17, 0xC7, 0x94, 0x5F, 0x0D, 0x99, 0xBE,
  42952. 0x75, 0x48, 0x49, 0xC6, 0x58, 0x43, 0x64, 0x99,
  42953. 0x1A, 0x5A, 0x41, 0xBA, 0xC2, 0x31, 0xB3, 0xE0,
  42954. 0x45, 0x1B, 0x81, 0xD2, 0x12, 0xBE, 0x90, 0xDB,
  42955. 0xFF, 0xBC, 0xCB, 0x99, 0xA3, 0xF0, 0x74, 0xE8,
  42956. 0x2C, 0x48, 0x58, 0xB3, 0x17, 0xA4, 0x9A, 0xD2,
  42957. 0x22, 0x46, 0xFB, 0xF5, 0x85, 0x8D, 0x07, 0xDF,
  42958. 0xDB, 0x78, 0x07, 0xF4, 0x99, 0xA8, 0x6C, 0xEE,
  42959. 0x6E, 0x96, 0x20, 0xB8, 0xC2, 0xA9, 0xFA, 0x8B,
  42960. 0x6E, 0xA6, 0x79, 0x6D, 0xF9, 0xC3, 0x0C, 0x77,
  42961. 0x74, 0xAE, 0xB0, 0x40, 0xA9, 0xE5, 0xA7, 0x0B,
  42962. 0x30, 0x40, 0x4B, 0x4F, 0xB1, 0x0A, 0x0B, 0x7B,
  42963. 0xEE, 0x1F, 0x69, 0xFA, 0xD0, 0xF0, 0x2D, 0x5D,
  42964. 0x00, 0xB5, 0x4D, 0xEB, 0x32, 0x84, 0xB2, 0xB7,
  42965. 0x60, 0xAA, 0x6C, 0xF9, 0x98, 0x18, 0xB3, 0xD9,
  42966. 0xC1, 0x54, 0x8D, 0xAC, 0x12, 0xB0, 0x3A, 0x26,
  42967. 0xB2, 0x23, 0x2D, 0x9B, 0xF8, 0x20, 0xEE, 0x90,
  42968. 0xE0, 0x6D, 0x31, 0xDE, 0xF5, 0xCA, 0xBA, 0x6A,
  42969. 0x53, 0x40, 0x29, 0x6C, 0x18, 0x62, 0xA5, 0x8A,
  42970. 0xB8, 0x17, 0xA0, 0xAB, 0xCB, 0xDC, 0xE1, 0x3B,
  42971. 0xD6, 0xC6, 0x29, 0xA3, 0x1C, 0x5F, 0x8D, 0x6E,
  42972. 0x73, 0xF6, 0x98, 0x10, 0x0F, 0x9F, 0x7E, 0xCA,
  42973. 0x4C, 0xD8, 0xEB, 0xE4, 0xB8, 0xDF, 0x72, 0x78,
  42974. 0x65, 0xAF, 0x4A, 0x20, 0xFE, 0x7C, 0xB4, 0xCA,
  42975. 0x07, 0x81, 0xFD, 0xC5, 0xC5, 0xFD, 0x33, 0x4D,
  42976. 0xB8, 0x37, 0x37, 0xC4, 0x21, 0x81, 0x66, 0x45,
  42977. 0xAE, 0x81, 0x34, 0x13, 0xA6, 0x40, 0x81, 0x39,
  42978. 0x55, 0x90, 0xE6, 0xF1, 0x42, 0x56, 0x74, 0xFF,
  42979. 0x06, 0x9B, 0x50, 0x1F, 0x0F, 0xDA, 0x6B, 0x31,
  42980. 0xC6, 0x4B, 0xC5, 0xC2, 0x14, 0xE7, 0x01, 0x5E,
  42981. 0xA9, 0xDA, 0x12, 0x2D, 0x6C, 0xE0, 0x8C, 0xEB,
  42982. 0x2D, 0xF6, 0x2C, 0x45, 0xBC, 0x01, 0x73, 0x34,
  42983. 0x6D, 0xAB, 0xBC, 0x15, 0x4C, 0x16, 0x03, 0x35,
  42984. 0x9D, 0xD4, 0xF0, 0xAC, 0x49, 0x84, 0x4A, 0xEE,
  42985. 0x46, 0x47, 0x64, 0x93, 0xF2, 0x49, 0x59, 0x86,
  42986. 0x26, 0xFB, 0x24, 0x6B, 0x99, 0xB3, 0x9A, 0xCB,
  42987. 0xB4, 0x2B, 0x28, 0x4E, 0x0C, 0x2D, 0x3F, 0x9E,
  42988. 0xCE, 0x32, 0x71, 0xC4, 0xD5, 0xE0, 0x6C, 0x48,
  42989. 0x25, 0xEA, 0x1A, 0x8F, 0x08, 0x57, 0x23, 0x85,
  42990. 0x89, 0xCD, 0xC5, 0x48, 0x37, 0x19, 0x8E, 0xD4,
  42991. 0x23, 0x4D, 0xD0, 0x31, 0x73, 0xA8, 0x8E, 0x43,
  42992. 0xEE, 0x95, 0x67, 0xF5, 0x7A, 0x93, 0x27, 0xD3,
  42993. 0x90, 0x36, 0x30, 0x4C, 0xA1, 0xCD, 0xB5, 0xF8,
  42994. 0x65, 0xC5, 0x89, 0x54, 0x57, 0x2C, 0xAE, 0xF8,
  42995. 0x75, 0xF1, 0x2E, 0x14, 0x14, 0x14, 0x0D, 0x97,
  42996. 0x5B, 0x24, 0x52, 0x46, 0x7A, 0x57, 0x6D, 0x9C,
  42997. 0x4C, 0x79, 0xDB, 0x0A, 0xE0, 0x23, 0x69, 0x52,
  42998. 0x9B, 0xF8, 0x1B, 0x54, 0x40, 0x18, 0xDF, 0xE0,
  42999. 0x1E, 0xF0, 0x61, 0xE4, 0x79, 0x81, 0xF9, 0x98,
  43000. 0x9A, 0x8C, 0x48, 0xFF, 0x86, 0x93, 0x0B, 0x68,
  43001. 0x96, 0x78, 0x2F, 0xF1, 0x2D, 0xDC, 0x60, 0x1F,
  43002. 0x8B, 0x1C, 0x04, 0x43, 0x4E, 0x60, 0x96, 0x5B,
  43003. 0x8A, 0xF6, 0x89, 0xCC, 0xC8, 0xB2, 0x9B, 0xBF,
  43004. 0x87, 0x16, 0x2E, 0xA8, 0x6F, 0x9B, 0x4B, 0xFD,
  43005. 0x74, 0x4E, 0x8F, 0x36, 0x33, 0x23, 0xDE, 0x94,
  43006. 0xD2, 0xA1, 0x72, 0x4F, 0xB2, 0xE6, 0x75, 0x3D,
  43007. 0x6E, 0x47, 0x9B, 0xDB, 0x58, 0xE5, 0x4A, 0x0C,
  43008. 0x09, 0x8F, 0x9C, 0x83, 0x63, 0x98, 0x8B, 0xA4,
  43009. 0xF7, 0x3D, 0x01, 0xA6, 0x8B, 0x93, 0x97, 0x48,
  43010. 0x84, 0x75, 0x32, 0xC7, 0xD7, 0x03, 0xDF, 0x7E,
  43011. 0x94, 0x8C, 0x8A, 0xA6, 0x78, 0x1A, 0xAE, 0xDE,
  43012. 0x36, 0x8A, 0xAD, 0x13, 0x7E, 0xF0, 0x16, 0xC2,
  43013. 0x3B, 0xAF, 0xF9, 0xD8, 0x66, 0x12, 0x30, 0x72,
  43014. 0x76, 0x6D, 0x21, 0x4C, 0xF3, 0xEF, 0x0D, 0x8C,
  43015. 0x11, 0xA4, 0x12, 0xBE, 0xF5, 0x7E, 0x8E, 0x6A,
  43016. 0x11, 0x13, 0x48, 0x8D, 0xC2, 0x62, 0xCF, 0x45,
  43017. 0x7C, 0xE3, 0x91, 0x88, 0x59, 0xFF, 0xB0, 0xF1,
  43018. 0xC3, 0xBC, 0x1D, 0x2A, 0x3E, 0x9B, 0x78, 0xF3,
  43019. 0xB1, 0x2E, 0xB0, 0x27, 0xD8, 0x16, 0xF8, 0x9B,
  43020. 0x2A, 0xAF, 0xF1, 0xAB, 0xB0, 0xF1, 0x8C, 0x7F,
  43021. 0x94, 0x31, 0x97, 0x85, 0xDA, 0xF0, 0xF4, 0x27,
  43022. 0x51, 0x3E, 0x5A, 0xE1, 0xDD, 0x6D, 0x9E, 0x98,
  43023. 0x39, 0xBB, 0xDF, 0xA2, 0xBA, 0x2C, 0x08, 0xAD,
  43024. 0x1D, 0x3F, 0x86, 0xF6, 0xC2, 0x1A, 0x8C, 0xAD,
  43025. 0xE0, 0xDC, 0xDD, 0x02, 0x47, 0x4C, 0x7E, 0x2D,
  43026. 0xDA, 0x1D, 0x70, 0x92, 0x39, 0xAA, 0x4E, 0xBA,
  43027. 0x14, 0xC7, 0xEC, 0x26, 0xBD, 0x9D, 0x1F, 0x6D,
  43028. 0x91, 0x58, 0x3C, 0xB5, 0xEF, 0x37, 0xB9, 0x66,
  43029. 0x4E, 0x04, 0x7C, 0x29, 0xCF, 0xD7, 0x8E, 0x47,
  43030. 0x84, 0xF3, 0xD2, 0x21, 0x84, 0xC5, 0xF8, 0xDC,
  43031. 0xC9, 0xF2, 0x52, 0xD5, 0x6A, 0xBF, 0xF1, 0xF1,
  43032. 0xDE, 0x9E, 0x7A, 0xF1, 0xD5, 0x5A, 0xF6, 0xEF,
  43033. 0x94, 0x66, 0xF9, 0x25, 0x44, 0x7F, 0x8D, 0x92,
  43034. 0xA2, 0x25, 0x1C, 0x72, 0x92, 0x30, 0x2A, 0xB7,
  43035. 0xEF, 0x18, 0xF3, 0x8C, 0xEF, 0x69, 0xA5, 0x5C,
  43036. 0x19, 0x3E, 0xC5, 0xBD, 0xEE, 0x2C, 0x2D, 0x71,
  43037. 0xDB, 0x89, 0xD4, 0x11, 0xA6, 0x27, 0x80, 0x8F,
  43038. 0x5A, 0x39, 0x9A, 0x04, 0x28, 0x4F, 0x9F, 0x00,
  43039. 0xBE, 0xF9, 0xF7, 0x9B, 0x46, 0x69, 0xD6, 0xAC,
  43040. 0x12, 0xE9, 0xA7, 0xC2, 0xD1, 0xC8, 0xAD, 0x5D,
  43041. 0xF7, 0xCB, 0x0C, 0x98, 0x78, 0x2D, 0x04, 0x4D,
  43042. 0x2D, 0x41, 0xAB, 0xC6, 0x3F, 0x81, 0x1D, 0xB9,
  43043. 0x2C, 0x1F, 0x3F, 0x59, 0x11, 0xF4, 0x80, 0x4F,
  43044. 0x0B, 0xCA, 0x9F, 0x81, 0x6E, 0x9C, 0xD1, 0xB4,
  43045. 0x74, 0x06, 0x48, 0x0A, 0x87, 0x2C, 0xFD, 0x4D,
  43046. 0x85, 0xD4, 0x21, 0x65, 0x7C, 0x96, 0x69, 0x53,
  43047. 0x51, 0xC0, 0xC4, 0xB0, 0xEB, 0x20, 0xDB, 0xE0,
  43048. 0x41, 0x09, 0xA7, 0x62, 0xB2, 0xF3, 0xC7, 0x6A,
  43049. 0x1D, 0x53, 0xA0, 0x39, 0xBA, 0xCF, 0x78, 0x9E,
  43050. 0xBF, 0x1D, 0xA5, 0x98, 0x09, 0x8E, 0xA7, 0x1A,
  43051. 0xE7, 0x95, 0xFF, 0x10, 0x38, 0xCC, 0x8F, 0x44,
  43052. 0xCB, 0xE7, 0xF6, 0xD6, 0x2C, 0xFF, 0xA8, 0x1C,
  43053. 0xFF, 0xA3, 0x65, 0xE8, 0x4E, 0xAE, 0xC7, 0xEF,
  43054. 0x61, 0xE1, 0x16, 0x4B, 0x8C, 0xA8, 0xC8, 0xFB,
  43055. 0xA5, 0x2C, 0xD1, 0x0A, 0x39, 0xAB, 0x4A, 0xF9,
  43056. 0xEE, 0x0B, 0x9B, 0xB4, 0x33, 0x5E, 0x25, 0x15,
  43057. 0xD0, 0xAA, 0x93, 0xC4, 0x53, 0x42, 0x91, 0xC5,
  43058. 0x98, 0x15, 0x34, 0x9A, 0x22, 0x1D, 0x9A, 0xE7,
  43059. 0x0E, 0x81, 0xF6, 0x99, 0x55, 0xB3, 0xD6, 0x49,
  43060. 0x1B, 0xB8, 0xA8, 0xBE, 0xDF, 0x54, 0xF0, 0x78,
  43061. 0xF7, 0x02, 0x97, 0x74, 0x84, 0x67, 0x6B, 0xAE,
  43062. 0x2F, 0xEC, 0x6E, 0x59, 0x20, 0x68, 0xD8, 0xE3,
  43063. 0x5A, 0x07, 0x48, 0xE1, 0x99, 0x90, 0xEE, 0xCD,
  43064. 0x17, 0x2B, 0xB6, 0xD6, 0xAA, 0x1A, 0xF8, 0x97,
  43065. 0x4E, 0xE0, 0x67, 0x9E, 0x4C, 0x35, 0xFE, 0x68,
  43066. 0x71, 0x54, 0x43, 0x5D, 0x43, 0x59, 0x19, 0xEB,
  43067. 0x58, 0x8E, 0x9A, 0xF6, 0xBD, 0x88, 0x71, 0xEE,
  43068. 0x89, 0xC6, 0xF2, 0x10, 0x04, 0x33, 0x13, 0x88,
  43069. 0xCD, 0x08, 0xB5, 0xE3, 0x5D, 0xA8, 0xBC, 0x43,
  43070. 0xB3, 0x84, 0x5F, 0x70, 0x94, 0xD9, 0xAC, 0xAE,
  43071. 0x74, 0x70, 0x13, 0x1E, 0x21, 0xFB, 0xD5, 0x7F,
  43072. 0xEC, 0x66, 0x2F, 0xA0, 0xB1, 0x1D, 0xE3, 0xF8,
  43073. 0xB9, 0x36, 0x48, 0x25, 0x3D, 0xBA, 0x7D, 0x44,
  43074. 0x08, 0xC5, 0x71, 0x74, 0xDA, 0xD3, 0x4F, 0x97,
  43075. 0x86, 0xF1, 0x16, 0x38, 0xD8, 0xC9, 0xE3, 0x3A,
  43076. 0xA7, 0x2E, 0x06, 0x4D, 0x9D, 0xE8, 0xFC, 0x38,
  43077. 0x58, 0x2A, 0x8D, 0x2D, 0x07, 0x99, 0xEA, 0xDF,
  43078. 0xF3, 0x00, 0x3B, 0xBC, 0x5F, 0x67, 0x1E, 0x4B,
  43079. 0x6C, 0xF1, 0x4A, 0x47, 0xB0, 0x71, 0x90, 0x5A,
  43080. 0x3B, 0x75, 0x93, 0x75, 0x56, 0x50, 0x4C, 0x70,
  43081. 0xF3, 0xC7, 0x95, 0xD5, 0xEA, 0xCB, 0x4C, 0x92,
  43082. 0x4F, 0x22, 0x4F, 0xD9, 0x34, 0x46, 0x76, 0xFB,
  43083. 0x79, 0xD6, 0xBD, 0x4E, 0x84, 0xEE, 0xE7, 0x78,
  43084. 0x7C, 0xB8, 0x92, 0x9F, 0xAD, 0xF2, 0x17, 0x5D,
  43085. 0x38, 0xB1, 0x88, 0x2E, 0xE9, 0x65, 0xAC, 0x4C,
  43086. 0x24, 0x27, 0x1D, 0x7B, 0xA3, 0x69, 0x96, 0x55,
  43087. 0x5C, 0x26, 0x40, 0xAF, 0x04, 0xB1, 0xCE, 0xA8,
  43088. 0x5D, 0x1E, 0x1F, 0xE5, 0x5A, 0xC3, 0xAE, 0xF9,
  43089. 0x14, 0x03, 0x58, 0x10, 0x1C, 0x8B, 0x1F, 0xDB,
  43090. 0x6C, 0x71, 0x68, 0x60, 0x13, 0x32, 0xF1, 0xA9,
  43091. 0x69, 0x45, 0x28, 0x69, 0x7C, 0xE3, 0xC9, 0x56,
  43092. 0xAF, 0xF3, 0xBD, 0x4B, 0x9E, 0x0A, 0x06, 0x6A,
  43093. 0x62, 0x20, 0x40, 0x65, 0xBD, 0xBC, 0xBF, 0xC7,
  43094. 0x0A, 0x2A, 0xCF, 0x56, 0x7C, 0x0E, 0x64, 0xBB,
  43095. 0x64, 0x71, 0x2D, 0x90, 0xBB, 0x32, 0x00, 0x0A,
  43096. 0x4A, 0x45, 0x44, 0x08, 0x75, 0x2C, 0x86, 0x13,
  43097. 0x86, 0x52, 0x8D, 0x3D, 0xFC, 0xF3, 0x5E, 0x5B,
  43098. 0x3F, 0x7A, 0xAA, 0x98, 0x84, 0xCF, 0x92, 0xF9,
  43099. 0x0B, 0x40, 0x8F, 0xC0, 0xA3, 0x71, 0x84, 0xAD,
  43100. 0xEE, 0xDF, 0xC4, 0x91, 0x7E, 0x87, 0x7D, 0x06,
  43101. 0xCA, 0x65, 0x8C, 0xE4, 0x8E, 0x03, 0xF0, 0x59,
  43102. 0x3E, 0xB4, 0x90, 0x4C, 0xEE, 0x88, 0x29, 0xE4,
  43103. 0x26, 0x7D, 0xA6, 0x54, 0x82, 0x49, 0xC1, 0x9D,
  43104. 0x80, 0xAB, 0x6B, 0xD7, 0xBE, 0x7D, 0x09, 0x80,
  43105. 0x5E, 0xB6, 0xD1, 0x1E, 0xD1, 0x1B, 0xE9, 0x8D,
  43106. 0xFC, 0x6E, 0x9C, 0x14, 0x0C, 0x15, 0x02, 0x87,
  43107. 0xF3, 0x9D, 0x21, 0xF8, 0xCB, 0xC8, 0xB9, 0xBD,
  43108. 0xE1, 0x70, 0xEA, 0xE4, 0x86, 0x4C, 0x97, 0xC1,
  43109. 0xEE, 0x4C, 0x18, 0x95, 0xEC, 0xD2, 0x4D, 0x35,
  43110. 0x9F, 0xC6, 0x56, 0x10, 0x3E, 0xC0, 0xB9, 0x7B,
  43111. 0x13, 0x1A, 0x37, 0x3D, 0x40, 0x4C, 0x88, 0x8B,
  43112. 0x9A, 0xA5, 0xB2, 0xB8, 0xB9, 0xC3, 0xEC, 0xF1,
  43113. 0x14, 0x33, 0x63, 0x67, 0x84, 0x98, 0xC8, 0xF4,
  43114. 0x06, 0x0C, 0x0E, 0x0F, 0x10, 0x12, 0x15, 0x16,
  43115. 0x45, 0x4E, 0x55, 0x5A, 0x5F, 0x8A, 0x94, 0x97,
  43116. 0xA8, 0xAF, 0xB2, 0xCC, 0xD4, 0xDC, 0xE7, 0xF1,
  43117. 0xFE, 0xFF, 0x11, 0x24, 0x53, 0x62, 0x94, 0xB7,
  43118. 0xB9, 0xD3, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00,
  43119. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43120. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43121. 0x10, 0x18, 0x32, 0x3B
  43122. };
  43123. #endif
  43124. #ifndef WOLFSSL_NO_ML_DSA_65
  43125. static const byte pk_65_draft[] = {
  43126. 0x6C, 0x84, 0x14, 0x38, 0x08, 0x56, 0xCB, 0x52,
  43127. 0xD7, 0x9C, 0x4B, 0x29, 0x13, 0x9F, 0xB1, 0x83,
  43128. 0x9B, 0x86, 0x06, 0xF5, 0x94, 0x8B, 0x9D, 0x72,
  43129. 0xA9, 0x56, 0xDC, 0xF1, 0x01, 0x16, 0xDA, 0x9E,
  43130. 0x2D, 0x79, 0x77, 0x01, 0x86, 0xFC, 0x74, 0xD9,
  43131. 0x42, 0xC0, 0xF4, 0xA3, 0xB5, 0x95, 0xFF, 0x6C,
  43132. 0x19, 0x80, 0x4B, 0x49, 0x90, 0x1C, 0x6A, 0xD5,
  43133. 0xFA, 0xF7, 0x16, 0x01, 0xC2, 0xB6, 0x00, 0x31,
  43134. 0x5E, 0x1F, 0x40, 0xC2, 0x05, 0x47, 0x67, 0xB0,
  43135. 0x09, 0x25, 0xDF, 0x3A, 0xA4, 0x90, 0xE8, 0xC7,
  43136. 0x6F, 0x05, 0xFB, 0xFB, 0x74, 0x91, 0x10, 0x75,
  43137. 0xE6, 0x51, 0x8C, 0x5F, 0x1D, 0x91, 0xB8, 0xA0,
  43138. 0xE5, 0xB5, 0x98, 0x30, 0xD3, 0xDF, 0x39, 0x94,
  43139. 0x76, 0x04, 0x11, 0xEB, 0xB9, 0x11, 0xED, 0x4C,
  43140. 0xC2, 0xC1, 0x60, 0xE3, 0x84, 0x9A, 0x93, 0x76,
  43141. 0x2D, 0xFC, 0xA7, 0xB9, 0x81, 0x2B, 0xC7, 0xAE,
  43142. 0xB2, 0xDD, 0xB2, 0x76, 0x7B, 0xEF, 0x36, 0x50,
  43143. 0x56, 0x05, 0xAE, 0x06, 0x92, 0x60, 0xBC, 0xC8,
  43144. 0xDC, 0x47, 0x87, 0xC4, 0x28, 0xCB, 0x3C, 0x07,
  43145. 0x6E, 0xF2, 0xA6, 0xB9, 0x35, 0x61, 0xD8, 0x94,
  43146. 0x3F, 0x45, 0xCA, 0xBE, 0x8F, 0x05, 0x53, 0xFF,
  43147. 0x2E, 0xA1, 0xAC, 0x95, 0xC1, 0xCE, 0x21, 0x59,
  43148. 0x3A, 0x17, 0x54, 0x59, 0xD7, 0xDF, 0x12, 0xC4,
  43149. 0x07, 0x0A, 0xDB, 0x0E, 0xEE, 0x55, 0xB4, 0xAB,
  43150. 0xAE, 0x59, 0xBE, 0x69, 0xC3, 0xFF, 0x0D, 0xE5,
  43151. 0xA9, 0xB0, 0x27, 0xFC, 0x7D, 0x8E, 0x6E, 0x05,
  43152. 0x7B, 0x71, 0x52, 0xEE, 0x6A, 0xB4, 0x80, 0xD1,
  43153. 0x05, 0xD3, 0x0B, 0x0F, 0x50, 0x51, 0xB6, 0x0C,
  43154. 0x79, 0x01, 0xC5, 0x25, 0xC4, 0x63, 0x5F, 0xE6,
  43155. 0x68, 0xCC, 0x00, 0xE9, 0xD3, 0x09, 0x7D, 0xB9,
  43156. 0x9D, 0x66, 0x32, 0x37, 0x15, 0xCE, 0x4F, 0x0B,
  43157. 0x79, 0xB4, 0x26, 0xB4, 0x54, 0x5E, 0x09, 0xF4,
  43158. 0xDE, 0x39, 0x32, 0x3D, 0xD1, 0x4C, 0xCB, 0x0D,
  43159. 0x17, 0x10, 0x8C, 0xD4, 0x6D, 0xEC, 0x61, 0x38,
  43160. 0xCD, 0xFA, 0x28, 0x72, 0xC1, 0xC4, 0xC8, 0xAE,
  43161. 0xAD, 0x5C, 0x8C, 0xE0, 0x41, 0x57, 0xE5, 0x53,
  43162. 0xA3, 0x75, 0x58, 0xC2, 0x34, 0x6A, 0x06, 0x19,
  43163. 0x4C, 0xB5, 0x0B, 0x49, 0x81, 0xBF, 0x4D, 0x09,
  43164. 0x0C, 0xE4, 0xE8, 0x60, 0x12, 0x6A, 0x82, 0x54,
  43165. 0xA4, 0xD4, 0xC0, 0x84, 0xC3, 0xE2, 0x02, 0x0B,
  43166. 0xC0, 0x75, 0x35, 0x21, 0x04, 0x9B, 0x0F, 0xD8,
  43167. 0x89, 0x97, 0xE0, 0x27, 0xAC, 0x51, 0xE7, 0x5C,
  43168. 0xF1, 0x35, 0x0C, 0x3F, 0x30, 0x3A, 0x0E, 0xCE,
  43169. 0x42, 0x64, 0x87, 0x15, 0x3D, 0xAF, 0x1F, 0xAA,
  43170. 0xD6, 0x80, 0x8B, 0x9D, 0x99, 0x07, 0xDA, 0x9F,
  43171. 0x35, 0x18, 0x5B, 0xD3, 0xBE, 0x8D, 0x9C, 0xEB,
  43172. 0xE9, 0x16, 0xCE, 0xD1, 0xFA, 0x29, 0x28, 0xD8,
  43173. 0x85, 0xA9, 0xCB, 0xA8, 0x81, 0x49, 0x70, 0x3F,
  43174. 0x5E, 0x47, 0x72, 0xE4, 0x85, 0x23, 0x12, 0x5D,
  43175. 0xDD, 0x02, 0x6E, 0x71, 0x4C, 0x49, 0xF4, 0xFB,
  43176. 0x4E, 0x54, 0x4B, 0xBF, 0x61, 0x7A, 0x40, 0xB0,
  43177. 0x0B, 0x68, 0xDF, 0x8F, 0x15, 0x5F, 0x58, 0x80,
  43178. 0xD4, 0x11, 0x87, 0x7E, 0x25, 0xB4, 0x2B, 0x24,
  43179. 0x48, 0xB3, 0x6B, 0xEC, 0x2F, 0x1F, 0x8F, 0x9A,
  43180. 0x77, 0x0C, 0x54, 0x51, 0x50, 0xA0, 0x27, 0x8E,
  43181. 0x9B, 0x72, 0x45, 0x00, 0xAE, 0xAA, 0xEA, 0x47,
  43182. 0x1C, 0x11, 0xCF, 0xF0, 0x4E, 0x30, 0xEA, 0xB2,
  43183. 0xF4, 0x73, 0xBC, 0x04, 0x8E, 0x32, 0xCD, 0x31,
  43184. 0xAE, 0xF2, 0x15, 0x79, 0xB6, 0x99, 0x22, 0x5B,
  43185. 0xF9, 0xE1, 0xB6, 0x70, 0x0C, 0x57, 0xE5, 0x09,
  43186. 0xFC, 0xA1, 0xF2, 0x36, 0x29, 0x4A, 0x59, 0x74,
  43187. 0xDA, 0xA1, 0x5F, 0xBC, 0xAD, 0x62, 0xD4, 0xBD,
  43188. 0xDC, 0x45, 0x32, 0xB2, 0x61, 0x41, 0x44, 0xDB,
  43189. 0xE2, 0x88, 0x07, 0x36, 0x8C, 0x28, 0x1A, 0x77,
  43190. 0x0E, 0xA2, 0x2B, 0x1E, 0x5A, 0x3F, 0xA5, 0xBA,
  43191. 0x14, 0x92, 0x6D, 0xC5, 0x5A, 0x54, 0xF8, 0x4A,
  43192. 0x2A, 0x77, 0xC5, 0xA7, 0x08, 0x41, 0xF0, 0x7B,
  43193. 0xC1, 0xDE, 0xEF, 0x74, 0x03, 0xB2, 0x47, 0xAB,
  43194. 0x42, 0xB8, 0x4A, 0xDF, 0x14, 0x1E, 0x03, 0x0C,
  43195. 0x98, 0x46, 0x84, 0x24, 0xDA, 0xAE, 0xB9, 0x9D,
  43196. 0x25, 0x77, 0xF9, 0x50, 0xC2, 0x37, 0x3C, 0xCA,
  43197. 0x1E, 0x2D, 0xC2, 0x76, 0x1B, 0x8E, 0xDD, 0x6D,
  43198. 0x08, 0xFF, 0x79, 0xE5, 0x28, 0x88, 0x0F, 0xFB,
  43199. 0x51, 0xC3, 0x6E, 0xD4, 0x20, 0xAC, 0x5D, 0x50,
  43200. 0xF2, 0x58, 0x2A, 0xA6, 0x64, 0xE5, 0x4E, 0xA5,
  43201. 0xF4, 0x18, 0x9E, 0xA0, 0x17, 0x6D, 0xAA, 0x61,
  43202. 0x22, 0xF6, 0x23, 0x5A, 0x70, 0xB1, 0x5C, 0xEB,
  43203. 0x4D, 0xDD, 0x65, 0xD3, 0xBE, 0x6E, 0xBF, 0x3D,
  43204. 0xC4, 0x31, 0x89, 0xEE, 0x0A, 0x2E, 0x31, 0x05,
  43205. 0x63, 0x8F, 0x23, 0x87, 0x36, 0x95, 0x28, 0x0F,
  43206. 0x1B, 0x74, 0x27, 0x43, 0x52, 0xD6, 0x0A, 0x48,
  43207. 0xE5, 0xD3, 0xDD, 0x02, 0xFB, 0x7A, 0x5E, 0xD8,
  43208. 0x3F, 0xE2, 0x7A, 0x69, 0x82, 0x51, 0x42, 0x1C,
  43209. 0x8E, 0x9C, 0x98, 0x80, 0x61, 0x02, 0x39, 0x6E,
  43210. 0x53, 0x73, 0x90, 0xAC, 0xFD, 0x8C, 0x1D, 0x0B,
  43211. 0x4F, 0x99, 0xB7, 0x02, 0xA9, 0xEA, 0x65, 0x98,
  43212. 0x78, 0x58, 0x3D, 0x92, 0x75, 0x89, 0x41, 0xB3,
  43213. 0x0E, 0xCE, 0x50, 0x7C, 0x10, 0x4B, 0x2C, 0xE4,
  43214. 0x87, 0x67, 0x9E, 0xCF, 0x68, 0xB4, 0xD8, 0xB9,
  43215. 0x80, 0x69, 0x8A, 0xCF, 0x6A, 0xA6, 0xA5, 0x7E,
  43216. 0x8E, 0xD6, 0xAF, 0x3F, 0xF1, 0x8D, 0x26, 0x68,
  43217. 0x95, 0x04, 0x28, 0xB5, 0x7D, 0x18, 0x2F, 0x73,
  43218. 0xBB, 0x49, 0xB9, 0xB0, 0x38, 0xCC, 0xC8, 0x2D,
  43219. 0x56, 0x12, 0x78, 0xA3, 0x86, 0xD5, 0x66, 0x45,
  43220. 0xEC, 0x3F, 0xAF, 0xFB, 0x41, 0x25, 0xE0, 0xE7,
  43221. 0xF3, 0x6B, 0x48, 0xB1, 0x4B, 0x45, 0x25, 0x47,
  43222. 0xA0, 0xB4, 0x81, 0xAA, 0x6B, 0x33, 0x42, 0x29,
  43223. 0x24, 0x91, 0x53, 0xE4, 0x2E, 0xDF, 0x7E, 0x49,
  43224. 0xDD, 0x6E, 0x76, 0x36, 0xBF, 0xC6, 0x15, 0xA2,
  43225. 0x3A, 0x40, 0x1E, 0xFD, 0x40, 0x34, 0xC8, 0x1B,
  43226. 0x4D, 0xCE, 0xF0, 0x27, 0xD3, 0x44, 0xDD, 0xCC,
  43227. 0xE0, 0xA7, 0x16, 0x18, 0xEB, 0x59, 0x10, 0xCE,
  43228. 0xC6, 0x22, 0x28, 0x81, 0x93, 0x85, 0x03, 0x3E,
  43229. 0x8D, 0x0A, 0xBD, 0x49, 0x3D, 0x98, 0x3E, 0x4F,
  43230. 0xC0, 0x87, 0xD7, 0x2B, 0x45, 0x5E, 0x4D, 0xB6,
  43231. 0x3A, 0x2F, 0x82, 0xCE, 0xFF, 0x65, 0xC1, 0xE6,
  43232. 0x28, 0xEA, 0xE6, 0x30, 0x59, 0x6D, 0xEC, 0x27,
  43233. 0xFB, 0x98, 0xB8, 0x4D, 0xBF, 0xDC, 0xDF, 0xAB,
  43234. 0x40, 0xE4, 0x72, 0x24, 0x49, 0x14, 0xAF, 0xF1,
  43235. 0x79, 0x32, 0x6D, 0x54, 0x2D, 0x40, 0x1A, 0x3C,
  43236. 0xBB, 0x86, 0xE5, 0xFF, 0x83, 0x51, 0xEF, 0xE5,
  43237. 0x3A, 0x73, 0xC5, 0x1A, 0xBB, 0x63, 0xFF, 0x55,
  43238. 0x3E, 0x7D, 0x79, 0x57, 0xEF, 0x89, 0x13, 0x5E,
  43239. 0x0F, 0x5B, 0xB1, 0xBD, 0x0C, 0x24, 0xF9, 0xE4,
  43240. 0x5E, 0x32, 0x36, 0x41, 0x3C, 0x60, 0xE1, 0x39,
  43241. 0x6A, 0x47, 0x56, 0x7C, 0x94, 0x39, 0x51, 0x0F,
  43242. 0x00, 0xD4, 0xA4, 0x3C, 0x14, 0x9A, 0x5C, 0xCC,
  43243. 0x04, 0xF3, 0xD4, 0x7E, 0x67, 0xA8, 0xE2, 0x94,
  43244. 0xA4, 0x61, 0xA5, 0xF6, 0x93, 0xDB, 0x0C, 0xAE,
  43245. 0x22, 0xCF, 0xAC, 0x61, 0xE8, 0x53, 0x47, 0x7D,
  43246. 0x33, 0x9A, 0x4E, 0x45, 0xF7, 0xB1, 0x7C, 0x3C,
  43247. 0x11, 0x6D, 0x56, 0xF3, 0xA0, 0x68, 0xFC, 0x5A,
  43248. 0xDF, 0xEF, 0x38, 0xFF, 0x85, 0x33, 0x2B, 0xD5,
  43249. 0x15, 0x3C, 0x4D, 0x8F, 0xB8, 0xF1, 0x48, 0xF1,
  43250. 0x17, 0x65, 0x9C, 0x2E, 0xA9, 0x4D, 0xB4, 0x2A,
  43251. 0xA0, 0xB0, 0xBE, 0xBB, 0x47, 0x5A, 0x11, 0x04,
  43252. 0x12, 0xF3, 0xCD, 0x33, 0x49, 0xFC, 0x1A, 0xD0,
  43253. 0x41, 0xB7, 0xD5, 0x30, 0x4A, 0x85, 0x93, 0x14,
  43254. 0x4E, 0xFA, 0x3A, 0x36, 0x1D, 0x1B, 0x0C, 0x76,
  43255. 0x13, 0xB8, 0x2C, 0x08, 0x6E, 0xA7, 0x12, 0x6E,
  43256. 0x43, 0xC6, 0x16, 0xCE, 0xE8, 0xF1, 0x44, 0x4E,
  43257. 0x99, 0x56, 0xE8, 0x7F, 0x5C, 0xAB, 0x95, 0xC7,
  43258. 0xC7, 0xFB, 0x17, 0x58, 0xEC, 0x7D, 0x97, 0x01,
  43259. 0x9E, 0x5B, 0xA9, 0x35, 0x43, 0xEF, 0x3B, 0xAC,
  43260. 0x1A, 0x17, 0x42, 0x99, 0xCA, 0x48, 0xBF, 0x78,
  43261. 0x59, 0xDB, 0xFB, 0xDF, 0xF2, 0x43, 0xB1, 0x14,
  43262. 0xF6, 0xBF, 0x42, 0x3C, 0xE9, 0x8B, 0x4D, 0x4D,
  43263. 0x09, 0x1D, 0xA4, 0x4F, 0x32, 0x74, 0xD5, 0x73,
  43264. 0xFD, 0xC9, 0x04, 0xBD, 0x88, 0x5E, 0x35, 0xC9,
  43265. 0x15, 0x2A, 0x65, 0x35, 0x48, 0x88, 0xF1, 0x1E,
  43266. 0xD4, 0xF3, 0xD6, 0x3F, 0x26, 0xA7, 0xBE, 0x2F,
  43267. 0x57, 0x26, 0xEA, 0xDA, 0xF4, 0x85, 0x86, 0x59,
  43268. 0x2B, 0xBD, 0xF6, 0xCE, 0xE2, 0x46, 0x76, 0x9E,
  43269. 0x0E, 0xDA, 0x2A, 0x80, 0x77, 0x1F, 0xED, 0x34,
  43270. 0x7D, 0x67, 0xAF, 0xEE, 0xC6, 0x8B, 0x89, 0x46,
  43271. 0x3F, 0xA0, 0x49, 0x6D, 0xBC, 0x15, 0xC8, 0x9E,
  43272. 0x8D, 0x56, 0x99, 0x83, 0xD1, 0xD6, 0x74, 0x73,
  43273. 0x3F, 0x2B, 0xF9, 0xDF, 0x4A, 0x98, 0x0E, 0xA8,
  43274. 0xC5, 0xE3, 0xAF, 0x15, 0x56, 0x0A, 0x0E, 0x28,
  43275. 0xD6, 0x72, 0xB5, 0x80, 0xAB, 0x65, 0x52, 0xED,
  43276. 0x76, 0xAA, 0xCB, 0x5F, 0x80, 0x26, 0x0B, 0x97,
  43277. 0x03, 0x76, 0x9D, 0x33, 0xF4, 0x13, 0x8A, 0xBC,
  43278. 0x10, 0xBF, 0x5B, 0x05, 0x82, 0xDC, 0xC6, 0x2D,
  43279. 0xBE, 0x58, 0xC8, 0x90, 0xF5, 0x1B, 0x41, 0x00,
  43280. 0x12, 0x77, 0x34, 0xFB, 0x7D, 0xB7, 0x44, 0x7A,
  43281. 0x72, 0x0A, 0xAE, 0x00, 0x9D, 0x00, 0xBE, 0x8C,
  43282. 0x61, 0x07, 0x92, 0xC6, 0x4F, 0x13, 0x1F, 0x2D,
  43283. 0x72, 0x11, 0x5C, 0x7E, 0x05, 0x8E, 0x48, 0xB9,
  43284. 0xDE, 0x64, 0xF5, 0x5B, 0x4D, 0x61, 0x0C, 0x36,
  43285. 0xD1, 0x12, 0x71, 0x6A, 0x31, 0xA3, 0xDF, 0xE2,
  43286. 0x66, 0x99, 0xE9, 0xC2, 0xAB, 0xA0, 0x56, 0x58,
  43287. 0xCE, 0xF1, 0xB2, 0xB0, 0x86, 0x7C, 0xF8, 0xD5,
  43288. 0x23, 0x3D, 0xB7, 0x4F, 0xA8, 0xDC, 0x3A, 0xD1,
  43289. 0x45, 0xF5, 0xD2, 0x85, 0x74, 0x36, 0x0A, 0x85,
  43290. 0xE3, 0xB0, 0xB1, 0x0A, 0xC0, 0xA6, 0x46, 0x7A,
  43291. 0x7B, 0x05, 0x98, 0x46, 0x28, 0xEC, 0xA1, 0x04,
  43292. 0x63, 0xF3, 0x48, 0xA3, 0x11, 0x1E, 0x00, 0x57,
  43293. 0x8D, 0x3C, 0xE5, 0x48, 0x0F, 0x53, 0x75, 0xA1,
  43294. 0xEE, 0x23, 0xEE, 0x82, 0x08, 0x7B, 0xAC, 0x41,
  43295. 0x23, 0x3A, 0x14, 0xAA, 0xA7, 0x24, 0x73, 0x4B,
  43296. 0x18, 0x74, 0xA4, 0xAC, 0xE1, 0x13, 0x37, 0x06,
  43297. 0x25, 0x8F, 0x5F, 0xEA, 0x3A, 0x0C, 0x16, 0x09,
  43298. 0xE3, 0x0C, 0x7F, 0xD2, 0x10, 0xDA, 0x0C, 0x4F,
  43299. 0xDE, 0x91, 0x62, 0xDF, 0x66, 0xFB, 0xAF, 0x79,
  43300. 0x2F, 0xA2, 0xAE, 0xAA, 0x51, 0x2F, 0x0F, 0xF7,
  43301. 0x83, 0x7B, 0x9C, 0xC0, 0x2E, 0xE9, 0xBD, 0x95,
  43302. 0x53, 0x9F, 0x00, 0x1B, 0xBD, 0x60, 0xDD, 0x8B,
  43303. 0x42, 0xD6, 0x16, 0xB2, 0xCA, 0x95, 0xF3, 0x83,
  43304. 0x5F, 0x5E, 0x47, 0xD4, 0x3B, 0x14, 0x34, 0xC4,
  43305. 0x56, 0x3F, 0xD8, 0x1C, 0x15, 0xBE, 0xFA, 0x20,
  43306. 0x2C, 0xF3, 0xD9, 0x54, 0x08, 0x73, 0xF6, 0x84,
  43307. 0xAF, 0xE1, 0x9A, 0xB5, 0xC0, 0x1F, 0xA9, 0x2E,
  43308. 0x95, 0xA8, 0xCD, 0x6F, 0x36, 0x07, 0x30, 0x85,
  43309. 0x6E, 0x59, 0xC9, 0xC6, 0xAB, 0x77, 0x0D, 0x65,
  43310. 0x75, 0x96, 0x2A, 0xF7, 0x58, 0x78, 0x57, 0x2A,
  43311. 0x2A, 0x26, 0x41, 0x3D, 0x01, 0xAB, 0x31, 0x8C,
  43312. 0x10, 0x0D, 0xFC, 0x34, 0xDC, 0x1D, 0xEF, 0xA5,
  43313. 0x92, 0x7C, 0x4B, 0x45, 0x99, 0x25, 0xD7, 0x3E,
  43314. 0x1E, 0xB9, 0x14, 0x70, 0xE3, 0x7A, 0x58, 0x45,
  43315. 0x5C, 0x22, 0xA9, 0x61, 0xFD, 0x53, 0xF7, 0xD9,
  43316. 0x90, 0x26, 0xFF, 0x88, 0x4B, 0xF4, 0xA2, 0x57,
  43317. 0x9F, 0x70, 0x63, 0x35, 0xEF, 0xB6, 0xFB, 0x22,
  43318. 0x50, 0xD5, 0x2A, 0xE5, 0x61, 0x89, 0x8B, 0xA1,
  43319. 0x60, 0x6E, 0x51, 0xE9, 0x6D, 0x37, 0xC9, 0xED,
  43320. 0x3E, 0xC6, 0xCF, 0xCB, 0x33, 0xBF, 0xBE, 0x9C,
  43321. 0x31, 0x43, 0xFD, 0x3B, 0x6B, 0x33, 0x4D, 0x5F,
  43322. 0x61, 0x92, 0x2B, 0x36, 0x9A, 0xFB, 0xB3, 0x1C,
  43323. 0x3E, 0x6E, 0x9B, 0x5F, 0x3A, 0xEB, 0xF9, 0x5C,
  43324. 0xB7, 0x08, 0x34, 0x6F, 0xEC, 0xF7, 0x15, 0x9C,
  43325. 0xAD, 0x94, 0xA9, 0x3D, 0x8C, 0xD4, 0xB8, 0xC4,
  43326. 0x89, 0x41, 0x92, 0xDF, 0xE5, 0x3E, 0xA4, 0x36,
  43327. 0xFB, 0xF3, 0xAF, 0x4E, 0x86, 0x4E, 0x8C, 0x39,
  43328. 0x91, 0xEA, 0x02, 0x0A, 0x81, 0x1F, 0x0A, 0xF5,
  43329. 0x0B, 0x42, 0x57, 0x43, 0x6A, 0x3F, 0xF5, 0x22,
  43330. 0xBE, 0x73, 0x67, 0x39, 0x1D, 0x0F, 0x95, 0x0B,
  43331. 0xA6, 0x45, 0x2F, 0xBF, 0xD8, 0xFD, 0x87, 0x28,
  43332. 0xF4, 0x0B, 0xD2, 0xFC, 0xB8, 0x94, 0x52, 0x99,
  43333. 0x85, 0xB4, 0x32, 0xDF, 0xEF, 0x62, 0x30, 0xEB,
  43334. 0x4D, 0xEE, 0x73, 0x7A, 0x8D, 0x10, 0xA3, 0xBC,
  43335. 0xDF, 0xB7, 0x63, 0xE0, 0x86, 0x9B, 0x22, 0x5C,
  43336. 0x1A, 0x8D, 0x0E, 0x1F, 0xBF, 0x2D, 0x16, 0x1C,
  43337. 0x2C, 0x65, 0xD6, 0xDF, 0xB9, 0x58, 0xE9, 0x82,
  43338. 0xD1, 0x17, 0x77, 0xAC, 0xBE, 0xAD, 0x8D, 0xFB,
  43339. 0x6B, 0x1F, 0x5E, 0xB2, 0x1E, 0xA9, 0x42, 0xF7,
  43340. 0xC4, 0x0D, 0xC2, 0x0D, 0x2E, 0x4E, 0xB3, 0xE7,
  43341. 0x29, 0xB4, 0xE2, 0x9F, 0x75, 0x01, 0xDA, 0x34,
  43342. 0x23, 0x45, 0x61, 0xF6, 0x28, 0x88, 0x12, 0xD6,
  43343. 0x12, 0xD4, 0x1D, 0xFA, 0x83, 0xC5, 0xB8, 0xD9,
  43344. 0x0F, 0xF3, 0x8B, 0xA5, 0x48, 0x20, 0x1B, 0x57,
  43345. 0x5B, 0x52, 0x93, 0xAD, 0x78, 0x12, 0x0D, 0x91,
  43346. 0xCE, 0xC0, 0x59, 0xCA, 0xE2, 0xE7, 0x6A, 0x9A,
  43347. 0xB4, 0x3E, 0xF1, 0x28, 0x1E, 0x2B, 0xEF, 0x3E,
  43348. 0x34, 0x8D, 0x28, 0xF2, 0x19, 0x47, 0xC8, 0x88,
  43349. 0x48, 0x96, 0x04, 0x59, 0x48, 0x97, 0x75, 0x17,
  43350. 0x6F, 0x8E, 0x40, 0xEE, 0x06, 0x42, 0x79, 0x53,
  43351. 0x68, 0x7F, 0xB6, 0x3E, 0x47, 0x0F, 0x7D, 0x59,
  43352. 0xFB, 0x60, 0xDF, 0x56, 0x9F, 0x8A, 0x11, 0xE2,
  43353. 0x8E, 0x09, 0x37, 0x16, 0x2C, 0x46, 0xAF, 0xC7,
  43354. 0xD2, 0x21, 0x0A, 0x88, 0x5F, 0xFA, 0x21, 0xB3,
  43355. 0xDB, 0xF5, 0x35, 0x4B, 0x29, 0x41, 0xF4, 0xED,
  43356. 0x5D, 0x50, 0x79, 0x08, 0x90, 0x84, 0x0C, 0xC3,
  43357. 0xB9, 0x73, 0xD2, 0xC3, 0xD0, 0x26, 0x02, 0xB2,
  43358. 0x9B, 0xAC, 0xCB, 0x6C, 0xE1, 0x7C, 0xED, 0xB9,
  43359. 0x7B, 0x08, 0x5A, 0x2A, 0xB3, 0x10, 0x57, 0x2B,
  43360. 0xA7, 0x37, 0x1D, 0x1F, 0x81, 0x20, 0xFF, 0xE3,
  43361. 0x7D, 0x0B, 0x0F, 0xCA, 0x35, 0xAF, 0xC5, 0xB5,
  43362. 0x62, 0xAA, 0x84, 0x99, 0x71, 0x5A, 0x29, 0x9C,
  43363. 0xE0, 0x59, 0xCC, 0xE3, 0xB0, 0xD1, 0x1C, 0xEF,
  43364. 0x0D, 0x92, 0x38, 0x96, 0x1A, 0xD4, 0xBE, 0x11,
  43365. 0xE9, 0xA6, 0xD1, 0xA4, 0x69, 0x21, 0x77, 0xC8,
  43366. 0xB0, 0xC5, 0x3F, 0x11, 0xA8, 0xED, 0x26, 0x50,
  43367. 0x21, 0x2E, 0x7A, 0x2F, 0x80, 0xEB, 0xFF, 0x6D,
  43368. 0xCF, 0xE4, 0x67, 0x21, 0x03, 0x65, 0x84, 0x34,
  43369. 0xD0, 0x32, 0x7A, 0xDD, 0xCD, 0x66, 0xBC, 0xB6
  43370. };
  43371. static const byte msg_65_draft[] = {
  43372. 0xDB, 0x84, 0x94, 0xBA, 0x19, 0xC4, 0x11, 0x8F,
  43373. 0xB1, 0x5D, 0x0A, 0xCF, 0x42, 0x54, 0xFD, 0x37,
  43374. 0x48, 0x3F, 0xCF, 0x47, 0x48, 0xFD, 0x18, 0x44,
  43375. 0xF7, 0x17, 0xCE, 0x6F, 0x69, 0x58, 0x9E, 0x61,
  43376. 0x77, 0x2C, 0xFE, 0xFA, 0x7F, 0x97, 0x58, 0x65,
  43377. 0x34, 0x09, 0xD4, 0xEE, 0x5A, 0x26, 0x4B, 0x83,
  43378. 0x4E, 0x60, 0xD6, 0xBB, 0x96, 0x49, 0x9E, 0xBE,
  43379. 0xB2, 0xB0, 0x6B, 0x0B, 0xA8, 0x74, 0xBF, 0x31,
  43380. 0xE6, 0x41, 0x39, 0x4C, 0xFA, 0xA6, 0xA2, 0xD3,
  43381. 0x0D, 0xDB, 0x8F, 0x04, 0x58, 0x76, 0x20, 0x8D,
  43382. 0x2F, 0x51, 0xDE, 0x15, 0xE2, 0x05, 0xE8, 0xC9,
  43383. 0x1B, 0x87, 0xEC, 0xEB, 0x05, 0xFF, 0x31, 0x83,
  43384. 0x27, 0x1B, 0x26, 0x49, 0x66, 0x5D, 0xD3, 0xCC,
  43385. 0x49, 0xBF, 0xDB, 0x99, 0x8D, 0x53, 0x9D, 0xA8,
  43386. 0x09, 0x30, 0x55, 0x16, 0xBB, 0xBE, 0x9C, 0x90,
  43387. 0x60, 0x21, 0x19, 0x1C, 0x52, 0x23, 0xE5, 0x25,
  43388. 0xA8, 0xFC, 0x36, 0x16, 0xA1, 0x76, 0x5E, 0xC3,
  43389. 0xF9, 0xC5, 0xDB, 0x53, 0xCC, 0x33, 0x7E, 0x03,
  43390. 0x9F, 0x18, 0x6A, 0xCF, 0xEA, 0x91, 0x14, 0x8E,
  43391. 0xE2, 0xA7, 0x9C, 0xCA, 0x36, 0x89, 0xED, 0xB6,
  43392. 0x2A, 0xAF, 0x28, 0xB5, 0xD7, 0x52, 0xFD, 0xE2,
  43393. 0x65, 0xEE, 0x52, 0x80, 0xB5, 0x19, 0x72, 0x6C,
  43394. 0x1C, 0xA9, 0x80, 0x32, 0x95, 0xC6, 0x74, 0xB7,
  43395. 0xEF, 0xAF, 0xA4, 0xD6, 0x1B, 0x30, 0x6A, 0x79,
  43396. 0xE3, 0xF6, 0xE7, 0xA8, 0x87, 0xC2, 0xFB, 0x53,
  43397. 0x5B, 0x3B, 0x0F, 0xB3, 0xD9, 0xEB, 0xC8, 0x76,
  43398. 0x03, 0xEA, 0xFE, 0xF1, 0x70, 0xC1, 0xF1, 0xD2,
  43399. 0x8E, 0x99, 0xBB
  43400. };
  43401. static const byte sig_65_draft[] = {
  43402. 0xF7, 0x78, 0x9A, 0x45, 0xA3, 0x58, 0x73, 0x30,
  43403. 0xE7, 0xFC, 0xF7, 0x06, 0x95, 0xF7, 0xF6, 0x96,
  43404. 0x88, 0xA2, 0xB8, 0xD0, 0xCE, 0x54, 0xF0, 0x90,
  43405. 0x21, 0x4F, 0x10, 0x9F, 0x56, 0x48, 0x4F, 0x98,
  43406. 0xC3, 0xAD, 0x1A, 0x53, 0xA5, 0x44, 0x1C, 0x2C,
  43407. 0xA7, 0x2A, 0x3B, 0x31, 0x91, 0xBC, 0x04, 0x6F,
  43408. 0x46, 0x37, 0x30, 0x45, 0xB9, 0xE5, 0x40, 0xC7,
  43409. 0x3D, 0xFE, 0x91, 0xB6, 0x1F, 0x05, 0x88, 0xD6,
  43410. 0x13, 0x59, 0x3F, 0xCE, 0x1B, 0x00, 0xEE, 0xF1,
  43411. 0xB2, 0x27, 0x03, 0x4C, 0x6F, 0xD3, 0xB1, 0x8B,
  43412. 0x3F, 0x22, 0x11, 0x10, 0xFB, 0x34, 0x5A, 0xA7,
  43413. 0x86, 0x31, 0xB8, 0xB5, 0x9F, 0xBD, 0xFD, 0xCC,
  43414. 0xDA, 0xE6, 0xA2, 0x4D, 0x25, 0x9D, 0x34, 0xAA,
  43415. 0xBA, 0xD2, 0x18, 0xB3, 0xAE, 0x4E, 0x77, 0x18,
  43416. 0x66, 0x53, 0xB8, 0x56, 0x3A, 0xA6, 0x12, 0x0A,
  43417. 0x0A, 0x53, 0x1A, 0x4E, 0x91, 0x37, 0x30, 0xDC,
  43418. 0x91, 0x4F, 0xE5, 0xE0, 0x08, 0xBE, 0xCE, 0x68,
  43419. 0x69, 0xB0, 0x2B, 0x07, 0xFD, 0xC1, 0x62, 0x14,
  43420. 0x54, 0x0D, 0x31, 0x6C, 0x43, 0xFA, 0x0C, 0x21,
  43421. 0x1B, 0x41, 0xAC, 0x7E, 0x52, 0x65, 0x67, 0x29,
  43422. 0xC7, 0x73, 0xE4, 0xC4, 0xB8, 0x8E, 0xD3, 0x11,
  43423. 0x88, 0x6D, 0xD4, 0xD2, 0x75, 0x41, 0x7D, 0x70,
  43424. 0x19, 0x66, 0x44, 0xEE, 0xD1, 0x5F, 0xA3, 0x15,
  43425. 0x06, 0x60, 0x03, 0xE3, 0x09, 0xF8, 0x32, 0xAF,
  43426. 0x91, 0x26, 0x2C, 0x94, 0x90, 0x11, 0xFC, 0xB0,
  43427. 0xAD, 0x2C, 0xCE, 0x65, 0xDD, 0x9E, 0xFF, 0x56,
  43428. 0x7E, 0xE2, 0x9C, 0xC4, 0x0A, 0x6F, 0xE0, 0x66,
  43429. 0x4E, 0x7D, 0x9F, 0x23, 0x65, 0x68, 0xFC, 0x94,
  43430. 0x29, 0x5D, 0xBB, 0x34, 0x28, 0x82, 0x33, 0xE8,
  43431. 0xC5, 0x11, 0xD2, 0x88, 0x15, 0xEC, 0x72, 0x10,
  43432. 0x32, 0x29, 0x6E, 0x1E, 0xDE, 0xCA, 0x7F, 0x72,
  43433. 0x6A, 0x6E, 0xB0, 0xF7, 0x6C, 0xC5, 0x82, 0x80,
  43434. 0x11, 0xC0, 0xE4, 0x01, 0x3C, 0xC7, 0xEE, 0x43,
  43435. 0x29, 0xB8, 0x1E, 0xCC, 0x0D, 0x52, 0xED, 0x1E,
  43436. 0x49, 0x1D, 0xD6, 0xD5, 0x5C, 0x52, 0x65, 0x66,
  43437. 0x5E, 0xD8, 0xAD, 0x21, 0x9B, 0x89, 0x4F, 0x31,
  43438. 0xC6, 0x8C, 0x61, 0x9A, 0xFC, 0xDB, 0x73, 0x58,
  43439. 0xE5, 0x55, 0x4C, 0x49, 0x5B, 0x8B, 0x6E, 0x33,
  43440. 0x25, 0x68, 0x8F, 0xB8, 0xC1, 0xA2, 0x53, 0x31,
  43441. 0xD5, 0x7B, 0xD3, 0x48, 0xA2, 0x7D, 0x39, 0x09,
  43442. 0x29, 0xBC, 0x46, 0xA1, 0x49, 0x6A, 0xB3, 0x5B,
  43443. 0x46, 0xBA, 0x61, 0xB6, 0xB9, 0xD2, 0x3C, 0xD0,
  43444. 0x63, 0x15, 0xFB, 0x72, 0xC2, 0x47, 0x76, 0x01,
  43445. 0x61, 0x30, 0xAD, 0xB1, 0xCF, 0x2D, 0xC7, 0x29,
  43446. 0x59, 0xEA, 0x9C, 0xAD, 0x96, 0xAF, 0x5D, 0xA9,
  43447. 0x96, 0x12, 0x6C, 0xDD, 0x85, 0xB1, 0x34, 0xCC,
  43448. 0x92, 0x7A, 0x51, 0xFD, 0x23, 0xF8, 0x47, 0x91,
  43449. 0xA3, 0xFC, 0xDA, 0x07, 0x7E, 0x15, 0x99, 0x17,
  43450. 0x48, 0xA0, 0x39, 0x4F, 0x33, 0x4E, 0xB8, 0xBC,
  43451. 0x48, 0xA9, 0x9A, 0xB9, 0xDF, 0xBB, 0x0F, 0x2A,
  43452. 0xAD, 0x6F, 0xBE, 0x48, 0x49, 0x61, 0xD3, 0xA4,
  43453. 0xE8, 0xF8, 0xB2, 0x1A, 0x6A, 0xC0, 0x92, 0xB2,
  43454. 0x26, 0xD6, 0xE1, 0x19, 0xFA, 0xD4, 0x4D, 0x8E,
  43455. 0x57, 0x6F, 0xE9, 0x6C, 0x6C, 0xDB, 0x68, 0x40,
  43456. 0xEA, 0x61, 0x4B, 0xAF, 0xC7, 0x07, 0x86, 0xC5,
  43457. 0x19, 0xE1, 0xD5, 0xDC, 0x0F, 0x98, 0x44, 0x43,
  43458. 0xC8, 0xB1, 0xE5, 0x4F, 0x8E, 0xE1, 0x76, 0xD9,
  43459. 0x8B, 0x2C, 0x70, 0x27, 0xF5, 0x7D, 0x7E, 0x3D,
  43460. 0xE9, 0xB2, 0xA0, 0xA3, 0x69, 0x11, 0xB8, 0xE4,
  43461. 0x71, 0x21, 0xDE, 0x0C, 0x07, 0xEB, 0xBA, 0x5D,
  43462. 0x7B, 0x59, 0x4E, 0xF2, 0x44, 0xC6, 0x83, 0x27,
  43463. 0xEC, 0x6C, 0x6D, 0x1D, 0xD5, 0x01, 0xF4, 0x83,
  43464. 0xFE, 0x9B, 0x95, 0x70, 0x59, 0x7E, 0x70, 0xDF,
  43465. 0x41, 0x3E, 0x7A, 0xF0, 0x38, 0x47, 0xF4, 0x09,
  43466. 0xED, 0x61, 0xE2, 0x84, 0x6E, 0x6C, 0x64, 0x1E,
  43467. 0x6A, 0x7F, 0xFA, 0x79, 0xDE, 0x6B, 0xFA, 0x37,
  43468. 0x3A, 0x06, 0x44, 0xB0, 0x0B, 0xF4, 0x1A, 0x03,
  43469. 0x49, 0x92, 0xA7, 0x94, 0xDA, 0x17, 0xC8, 0x88,
  43470. 0x85, 0x23, 0x90, 0x32, 0xC8, 0x51, 0x76, 0x4E,
  43471. 0x3E, 0x4D, 0xBD, 0xE7, 0xF1, 0x2A, 0x16, 0xC5,
  43472. 0xA2, 0x63, 0xE9, 0x64, 0xC1, 0xE7, 0xFD, 0xD3,
  43473. 0xCC, 0xE5, 0x76, 0xDD, 0x6D, 0x56, 0xB1, 0x81,
  43474. 0x82, 0x84, 0x8B, 0x75, 0x63, 0x64, 0x5D, 0x4E,
  43475. 0x42, 0xFF, 0x22, 0x74, 0x2A, 0x99, 0x67, 0x85,
  43476. 0x16, 0x9D, 0x7F, 0x50, 0x3B, 0x48, 0xA7, 0x15,
  43477. 0x8B, 0x3C, 0xBD, 0x29, 0x93, 0x5E, 0xD3, 0x20,
  43478. 0x49, 0xBE, 0xA1, 0xAD, 0x95, 0x3E, 0xF7, 0x07,
  43479. 0x32, 0x7B, 0x77, 0x8B, 0xFD, 0xDD, 0xFC, 0x60,
  43480. 0x51, 0x1D, 0xA1, 0x13, 0xA3, 0x4F, 0x65, 0x57,
  43481. 0x12, 0xE4, 0xE5, 0x9D, 0x6C, 0xCE, 0x40, 0x4E,
  43482. 0x94, 0xAB, 0xA6, 0x1E, 0x81, 0x35, 0x38, 0x8F,
  43483. 0xC2, 0x1C, 0x8E, 0x41, 0x34, 0x4F, 0x32, 0x4B,
  43484. 0x01, 0xAC, 0x8C, 0x06, 0x9F, 0x92, 0x57, 0x5D,
  43485. 0x34, 0xF8, 0x8B, 0xCA, 0x22, 0xCB, 0x30, 0x7E,
  43486. 0x37, 0x07, 0x00, 0x63, 0x32, 0x02, 0x56, 0xB8,
  43487. 0xBA, 0xD6, 0xEB, 0x7A, 0x81, 0xAF, 0xE9, 0xA2,
  43488. 0x54, 0x01, 0x6E, 0x1C, 0x8A, 0x12, 0x50, 0x89,
  43489. 0xAA, 0xA3, 0xED, 0xE8, 0x4E, 0x5B, 0x6C, 0x2E,
  43490. 0xCF, 0xAE, 0xFA, 0xA5, 0x2B, 0x9F, 0x57, 0x09,
  43491. 0x60, 0x2C, 0x06, 0xAE, 0xA4, 0xA0, 0x38, 0x4E,
  43492. 0x9B, 0x09, 0xE5, 0xB8, 0x81, 0x64, 0xB2, 0x74,
  43493. 0xEA, 0x32, 0x65, 0xFB, 0x51, 0x52, 0x39, 0x7D,
  43494. 0xFF, 0x5A, 0x3A, 0x08, 0x61, 0xE2, 0xBC, 0x12,
  43495. 0xD2, 0x10, 0x92, 0x89, 0x72, 0x97, 0x47, 0xE8,
  43496. 0x3F, 0xDF, 0x24, 0x3A, 0x1D, 0x17, 0xB9, 0x83,
  43497. 0x48, 0x37, 0x98, 0x45, 0xA9, 0xE9, 0x55, 0xE2,
  43498. 0xD6, 0xF9, 0x38, 0xDA, 0xA5, 0x91, 0x8E, 0x2A,
  43499. 0x14, 0xF9, 0x7B, 0xA2, 0xBE, 0x50, 0x1C, 0xCC,
  43500. 0xAF, 0xD6, 0x81, 0x91, 0x0F, 0x4A, 0x4F, 0x06,
  43501. 0x71, 0x5C, 0xE8, 0x40, 0x96, 0xF3, 0x7A, 0x91,
  43502. 0xDC, 0xCA, 0x2A, 0x8A, 0x4B, 0xE8, 0xDA, 0x79,
  43503. 0x21, 0xDB, 0xF8, 0xD3, 0xF4, 0xEF, 0xB9, 0x8C,
  43504. 0x6B, 0x4F, 0x94, 0x0E, 0xCE, 0xF8, 0x32, 0xB5,
  43505. 0x49, 0xD0, 0x68, 0x94, 0x7C, 0x3D, 0xFB, 0x58,
  43506. 0x09, 0xCB, 0x7B, 0x06, 0x0A, 0x3A, 0x0E, 0xF3,
  43507. 0xB2, 0x1C, 0x01, 0x64, 0x50, 0x1D, 0xDE, 0xA7,
  43508. 0xC9, 0xE5, 0xE7, 0x89, 0x7C, 0x6B, 0x1C, 0x46,
  43509. 0x34, 0x8B, 0x2C, 0x3E, 0x80, 0x5F, 0x6F, 0x22,
  43510. 0x87, 0xBA, 0x15, 0x8C, 0xF9, 0x25, 0xA7, 0xBA,
  43511. 0x7F, 0x08, 0x25, 0x49, 0x89, 0xC8, 0x7D, 0x24,
  43512. 0x97, 0x9A, 0xD9, 0x86, 0xAA, 0x97, 0xC5, 0x1B,
  43513. 0x01, 0xF4, 0x5D, 0x4A, 0x1F, 0x24, 0x75, 0x29,
  43514. 0x91, 0xF0, 0x42, 0x05, 0xEB, 0x55, 0x1F, 0xD0,
  43515. 0x2D, 0x41, 0x5F, 0x2D, 0xD1, 0xEF, 0xF1, 0x42,
  43516. 0xB0, 0xD7, 0x04, 0x16, 0xC6, 0xD8, 0x15, 0xEB,
  43517. 0x91, 0x73, 0x2B, 0x26, 0x8F, 0xB2, 0x0D, 0x08,
  43518. 0x67, 0x44, 0x2D, 0x71, 0xDE, 0xC0, 0x57, 0xB2,
  43519. 0x86, 0xCD, 0x93, 0x81, 0x1F, 0xF3, 0xF6, 0x46,
  43520. 0xEB, 0xD5, 0x65, 0xD5, 0x1D, 0x09, 0xA4, 0x2D,
  43521. 0x3A, 0xBA, 0xAC, 0x0F, 0x34, 0xCC, 0x81, 0x7B,
  43522. 0x18, 0x93, 0x8E, 0xCC, 0xBB, 0x1F, 0xEF, 0x05,
  43523. 0xBD, 0x3C, 0x2B, 0x49, 0x4F, 0xA5, 0x29, 0xED,
  43524. 0x4C, 0x63, 0x4C, 0x93, 0x25, 0xA4, 0x81, 0x73,
  43525. 0xF2, 0x0F, 0xFA, 0xC3, 0x2D, 0xC1, 0x01, 0xE6,
  43526. 0xEE, 0x03, 0xB2, 0xFC, 0xBE, 0xC2, 0x46, 0x8D,
  43527. 0xBC, 0x8F, 0x76, 0x75, 0x8C, 0x32, 0x15, 0x47,
  43528. 0x4F, 0x7E, 0xF2, 0x40, 0x65, 0xF7, 0x90, 0x60,
  43529. 0xAC, 0xA3, 0xC8, 0xD5, 0xD7, 0x4A, 0xF7, 0x0F,
  43530. 0x48, 0x30, 0x1D, 0xDB, 0x30, 0xC0, 0x5D, 0xB3,
  43531. 0xEF, 0xA7, 0x26, 0xCF, 0x88, 0x55, 0x59, 0x01,
  43532. 0x84, 0x12, 0x82, 0xAA, 0x08, 0xF6, 0x66, 0xA6,
  43533. 0x53, 0x51, 0xA6, 0xA2, 0x4E, 0xED, 0x6B, 0xE2,
  43534. 0x11, 0x77, 0x31, 0x07, 0xE1, 0x85, 0xE1, 0xB4,
  43535. 0x88, 0xA2, 0xE4, 0x91, 0xB6, 0xC1, 0x41, 0x52,
  43536. 0x84, 0x62, 0xA8, 0x64, 0x94, 0xB5, 0x4F, 0xDC,
  43537. 0xCE, 0xCC, 0xB6, 0xAA, 0x21, 0x25, 0x36, 0x86,
  43538. 0x69, 0x3A, 0xE7, 0x98, 0xC9, 0xCE, 0x9E, 0x0B,
  43539. 0xDD, 0xC6, 0xAE, 0x53, 0xD9, 0xB7, 0x06, 0xDC,
  43540. 0x4F, 0x4D, 0x81, 0xB9, 0xC7, 0x3C, 0x46, 0x1E,
  43541. 0xCD, 0x70, 0x35, 0xC5, 0x17, 0x2E, 0xFA, 0xE5,
  43542. 0x60, 0x2C, 0xAF, 0x88, 0xC6, 0x4E, 0x79, 0xE5,
  43543. 0x32, 0x40, 0x30, 0x55, 0x5D, 0xE2, 0x11, 0xF8,
  43544. 0x9F, 0xD4, 0x24, 0xC3, 0x38, 0xC3, 0x88, 0x3C,
  43545. 0x83, 0xCA, 0x94, 0x05, 0xC2, 0xB5, 0xD1, 0x44,
  43546. 0x5F, 0x7C, 0x98, 0xC4, 0x3E, 0xD3, 0xD2, 0xBE,
  43547. 0xCB, 0xE2, 0x5F, 0x5F, 0x3F, 0x54, 0x4C, 0xCC,
  43548. 0x5B, 0x5A, 0xEA, 0xE4, 0x7D, 0xDF, 0x3F, 0xB5,
  43549. 0x64, 0x9F, 0xF5, 0xD6, 0x1E, 0xAA, 0x02, 0xED,
  43550. 0xEB, 0xC7, 0x5C, 0xE4, 0x78, 0xBA, 0x00, 0x42,
  43551. 0x6C, 0xAF, 0x47, 0x4F, 0xA7, 0x9E, 0x5B, 0x08,
  43552. 0x9E, 0xB1, 0xA8, 0x82, 0xF1, 0x53, 0x54, 0x59,
  43553. 0x26, 0x95, 0x95, 0x2B, 0xA0, 0xA8, 0xEE, 0x91,
  43554. 0xE6, 0x49, 0xE3, 0xF2, 0xC3, 0x82, 0x26, 0x4D,
  43555. 0xAA, 0x30, 0xF6, 0xA6, 0xD2, 0x17, 0xF6, 0x12,
  43556. 0x9C, 0x19, 0x39, 0xB6, 0xDC, 0xAC, 0xCD, 0xA5,
  43557. 0xB6, 0x37, 0x32, 0x6E, 0x8A, 0x83, 0x61, 0xC3,
  43558. 0xB5, 0x6F, 0xCF, 0xFC, 0x48, 0x50, 0x36, 0x86,
  43559. 0x58, 0x22, 0xB9, 0xBB, 0x87, 0xB4, 0x35, 0x10,
  43560. 0xBC, 0xDD, 0x55, 0xBC, 0x35, 0x0D, 0xE7, 0xB2,
  43561. 0xAE, 0x90, 0xA2, 0x1E, 0x9E, 0x19, 0x97, 0x8E,
  43562. 0xDA, 0x10, 0xDF, 0x66, 0x76, 0x14, 0xA4, 0x4F,
  43563. 0xE2, 0xA8, 0x4D, 0x16, 0xBE, 0x04, 0x3E, 0xA8,
  43564. 0x77, 0x36, 0x33, 0xEA, 0x6B, 0xAD, 0xF6, 0x57,
  43565. 0x10, 0x05, 0x2F, 0x34, 0x1F, 0x65, 0xCB, 0xE9,
  43566. 0x28, 0xD3, 0x96, 0x2A, 0x5A, 0x2F, 0xE6, 0x4E,
  43567. 0x46, 0xD6, 0xBF, 0xB8, 0xFD, 0x0D, 0x99, 0x78,
  43568. 0xF0, 0x42, 0x3C, 0xBD, 0x19, 0x5F, 0x72, 0xF3,
  43569. 0xCB, 0x19, 0xD7, 0xEF, 0xD9, 0xEB, 0xE3, 0x3C,
  43570. 0xD2, 0xF5, 0x70, 0x9A, 0x57, 0x80, 0x7D, 0xF9,
  43571. 0x44, 0xEC, 0xE5, 0x68, 0xAA, 0xCA, 0x43, 0x36,
  43572. 0x42, 0x20, 0x83, 0xB0, 0x69, 0x7B, 0x6A, 0xA0,
  43573. 0x05, 0x86, 0xE4, 0xBF, 0x7D, 0xD6, 0x73, 0xA3,
  43574. 0xD5, 0x96, 0xB8, 0x61, 0x8A, 0xC3, 0xB4, 0x06,
  43575. 0x17, 0x50, 0xC6, 0xBE, 0x97, 0xCB, 0x53, 0x75,
  43576. 0x3D, 0x02, 0x39, 0x55, 0x56, 0x07, 0x5A, 0x26,
  43577. 0xF1, 0x40, 0xB9, 0x3F, 0x57, 0x7D, 0xAD, 0x50,
  43578. 0x5E, 0x1C, 0xF2, 0xB5, 0x51, 0xA0, 0x4C, 0x98,
  43579. 0xC7, 0xF0, 0x90, 0x18, 0x31, 0xB3, 0xCA, 0x61,
  43580. 0xD7, 0x5D, 0xA7, 0x93, 0xAC, 0x72, 0xA4, 0x4C,
  43581. 0x7A, 0x07, 0xF7, 0xDB, 0xBA, 0xD6, 0x0A, 0x55,
  43582. 0xF4, 0x9C, 0xBD, 0x79, 0xDE, 0xE4, 0x73, 0x9F,
  43583. 0xFD, 0x36, 0x77, 0x8E, 0xBD, 0x08, 0xEB, 0xDB,
  43584. 0x79, 0xEC, 0x07, 0xA1, 0x62, 0x39, 0xC5, 0xB9,
  43585. 0x21, 0x59, 0x9F, 0xEB, 0xFE, 0xA4, 0x6D, 0xDF,
  43586. 0x96, 0x6A, 0xA4, 0xA0, 0x15, 0x12, 0xE6, 0x10,
  43587. 0x94, 0x3F, 0x5D, 0xC5, 0x4B, 0x4C, 0x76, 0xB7,
  43588. 0x64, 0xB3, 0x80, 0xBF, 0x2F, 0x84, 0xED, 0xE3,
  43589. 0x21, 0x24, 0x91, 0x2F, 0x54, 0xF7, 0xB6, 0xE2,
  43590. 0x07, 0xB7, 0x38, 0x1F, 0x67, 0x0F, 0x7A, 0xA0,
  43591. 0xF3, 0xC3, 0xED, 0x10, 0x15, 0x74, 0x03, 0x84,
  43592. 0xDD, 0x61, 0xA9, 0x76, 0x5E, 0xE4, 0x69, 0x6E,
  43593. 0xAC, 0xF8, 0x2E, 0xA4, 0x10, 0x69, 0x18, 0x05,
  43594. 0xCB, 0x68, 0x89, 0x03, 0x53, 0x5D, 0x70, 0x46,
  43595. 0x10, 0x0D, 0xCC, 0x2B, 0xA7, 0xD8, 0x30, 0x2A,
  43596. 0xCB, 0x04, 0x30, 0xD5, 0x06, 0xCC, 0xC1, 0xC0,
  43597. 0xDD, 0xEA, 0x71, 0x11, 0xA7, 0x6F, 0x45, 0xB4,
  43598. 0x54, 0xE2, 0x5C, 0xDD, 0xFB, 0x63, 0x9B, 0x3D,
  43599. 0x66, 0x4C, 0x36, 0xD8, 0x84, 0x35, 0x13, 0xA3,
  43600. 0xFC, 0xAF, 0x9E, 0x60, 0x57, 0xE9, 0xBC, 0x06,
  43601. 0x82, 0x37, 0xFE, 0x24, 0x19, 0xA2, 0xD2, 0xD9,
  43602. 0x0B, 0x4A, 0x1F, 0xC2, 0xA7, 0x1A, 0x14, 0x6D,
  43603. 0x2B, 0xD0, 0x43, 0x64, 0xC7, 0x9B, 0x8E, 0xBA,
  43604. 0x8E, 0x3E, 0x88, 0xCE, 0x11, 0xE9, 0x16, 0xE4,
  43605. 0xA7, 0x52, 0x84, 0x21, 0x32, 0x8C, 0xF5, 0x4F,
  43606. 0xAA, 0xB2, 0xB1, 0x9F, 0x44, 0x46, 0x87, 0x81,
  43607. 0xF8, 0xAB, 0x84, 0xB7, 0xDD, 0x97, 0x2F, 0xF5,
  43608. 0x61, 0x50, 0x71, 0x43, 0x0A, 0x43, 0x74, 0xDA,
  43609. 0xFC, 0xAE, 0x1E, 0x60, 0x44, 0xAA, 0x98, 0xE9,
  43610. 0x85, 0x94, 0x1B, 0xA6, 0xB9, 0xDB, 0x8C, 0x02,
  43611. 0xF5, 0x89, 0x60, 0x3E, 0xEB, 0x8B, 0xE9, 0x0A,
  43612. 0x70, 0xEF, 0xC0, 0x88, 0xD7, 0x95, 0xE6, 0xDA,
  43613. 0x1F, 0x1F, 0x2E, 0x6E, 0xCE, 0xDD, 0x03, 0x1D,
  43614. 0x81, 0x99, 0xE6, 0x59, 0x12, 0xD4, 0x34, 0xD0,
  43615. 0x9B, 0xFB, 0xE5, 0x94, 0x40, 0x6D, 0xC1, 0x15,
  43616. 0x0E, 0x99, 0x35, 0x8C, 0xEA, 0x7F, 0xAD, 0x2E,
  43617. 0x7C, 0x44, 0xC3, 0x8B, 0x6E, 0x0C, 0xEE, 0xAB,
  43618. 0x9B, 0xDE, 0x0D, 0xB9, 0x7B, 0xCF, 0x5A, 0xC9,
  43619. 0x94, 0x10, 0xC9, 0x47, 0x0E, 0x26, 0x6B, 0x8B,
  43620. 0xE4, 0x5F, 0x66, 0x90, 0x83, 0x1F, 0x41, 0x45,
  43621. 0xE2, 0x63, 0x79, 0xDB, 0x80, 0x7C, 0x26, 0xDD,
  43622. 0xF9, 0x1E, 0x30, 0x9D, 0x4F, 0x4A, 0x3E, 0x7E,
  43623. 0xCA, 0xB7, 0x36, 0x2F, 0x15, 0xD2, 0x0E, 0xA4,
  43624. 0x33, 0xB7, 0xE7, 0x0A, 0x7D, 0xDE, 0x74, 0x16,
  43625. 0xCE, 0xA8, 0x71, 0x49, 0x8B, 0x2C, 0xE3, 0xF5,
  43626. 0x8D, 0x29, 0xD8, 0x62, 0x8C, 0x53, 0x18, 0x40,
  43627. 0xF0, 0x22, 0xDD, 0x3B, 0xD2, 0xF3, 0x80, 0x9B,
  43628. 0x11, 0x68, 0xD3, 0x8E, 0x63, 0xC7, 0xF6, 0x93,
  43629. 0x08, 0xA3, 0x1A, 0x2D, 0x4D, 0x5E, 0xEB, 0x97,
  43630. 0x42, 0x39, 0xB3, 0x4A, 0x62, 0xBC, 0x85, 0xE4,
  43631. 0xEC, 0xF9, 0x0C, 0x33, 0x6A, 0x0C, 0x37, 0xBD,
  43632. 0x9E, 0x0E, 0xF4, 0x26, 0x6B, 0x83, 0x5A, 0xC8,
  43633. 0x90, 0x6A, 0x83, 0xCF, 0x0B, 0x35, 0x13, 0x8A,
  43634. 0x65, 0xE5, 0xD9, 0xA6, 0x1F, 0xCC, 0x9B, 0x2D,
  43635. 0x5A, 0x33, 0x7B, 0x8A, 0xBE, 0xF8, 0x8A, 0x7F,
  43636. 0xB3, 0xC0, 0x94, 0x5D, 0x7C, 0xAF, 0x35, 0x61,
  43637. 0x1A, 0xE0, 0xE4, 0x46, 0x93, 0xA5, 0xBC, 0xE0,
  43638. 0xA6, 0xE2, 0xFE, 0xCA, 0xE9, 0xBD, 0xF4, 0xE3,
  43639. 0x56, 0xD6, 0x53, 0x6B, 0x58, 0x1A, 0x18, 0xF0,
  43640. 0x3A, 0x59, 0x16, 0x4E, 0xD5, 0x44, 0x7C, 0x7E,
  43641. 0xC8, 0xBD, 0x99, 0x7B, 0xE9, 0x53, 0xDE, 0xD9,
  43642. 0x32, 0x53, 0x5B, 0x5F, 0x43, 0x8A, 0x04, 0x31,
  43643. 0x9F, 0x5E, 0x0D, 0x8B, 0x0F, 0xEB, 0xC8, 0xDE,
  43644. 0x81, 0x46, 0x65, 0x8E, 0x52, 0xB9, 0x75, 0x9C,
  43645. 0x73, 0x93, 0x5B, 0x12, 0x0D, 0xC9, 0xB8, 0x54,
  43646. 0xF3, 0xC8, 0xF9, 0x4E, 0xC9, 0x33, 0x90, 0x57,
  43647. 0xD7, 0xD7, 0xCD, 0x91, 0xF7, 0xE0, 0xB9, 0x8D,
  43648. 0x84, 0xEC, 0x7B, 0x2F, 0x92, 0x32, 0x8D, 0x73,
  43649. 0x60, 0x18, 0xB0, 0x31, 0x65, 0xA8, 0x74, 0x5F,
  43650. 0x8E, 0x77, 0xEB, 0x80, 0x29, 0xF9, 0x78, 0x26,
  43651. 0x70, 0xCB, 0xD8, 0x6B, 0x43, 0x16, 0xC7, 0xBE,
  43652. 0x4A, 0x88, 0x03, 0x38, 0xBA, 0xCF, 0xB0, 0x15,
  43653. 0x69, 0x9B, 0xF3, 0x0D, 0x3A, 0x4B, 0x05, 0x32,
  43654. 0x54, 0x35, 0xBA, 0x5F, 0xA3, 0xB9, 0xD2, 0xB2,
  43655. 0xFE, 0x0B, 0x51, 0x9C, 0x2C, 0xB2, 0x46, 0xE5,
  43656. 0x3D, 0x1A, 0x34, 0x3D, 0x66, 0x1A, 0x66, 0x14,
  43657. 0x3C, 0x6F, 0x46, 0x8C, 0x55, 0x38, 0x64, 0x5C,
  43658. 0xC2, 0x6D, 0x4E, 0x2A, 0x87, 0x03, 0xEC, 0x9B,
  43659. 0x10, 0xFC, 0x89, 0xBE, 0x6F, 0x85, 0x99, 0x97,
  43660. 0x70, 0x8F, 0x31, 0x19, 0x4F, 0x0D, 0xFE, 0xE9,
  43661. 0x29, 0x98, 0xB2, 0x5E, 0x93, 0xB9, 0x70, 0x70,
  43662. 0xDE, 0x14, 0x40, 0x9D, 0x5B, 0xA4, 0x3D, 0xF8,
  43663. 0x8D, 0x15, 0xC2, 0xFB, 0xA9, 0x7B, 0xDD, 0xE6,
  43664. 0x18, 0xCC, 0x3F, 0xC0, 0x42, 0xF7, 0x74, 0x81,
  43665. 0x84, 0xBA, 0x9E, 0xC9, 0xCB, 0xA1, 0xB2, 0x00,
  43666. 0x68, 0x81, 0xD0, 0x51, 0x42, 0x64, 0x19, 0x8F,
  43667. 0xB6, 0x91, 0xC5, 0xC0, 0x38, 0xE0, 0x49, 0x50,
  43668. 0xCF, 0x69, 0x09, 0x93, 0x77, 0xFE, 0x66, 0xBA,
  43669. 0x64, 0xE2, 0x19, 0x52, 0xA4, 0x45, 0x81, 0x71,
  43670. 0x96, 0x64, 0xF5, 0xD9, 0x23, 0x97, 0xD2, 0x2A,
  43671. 0xA7, 0x03, 0x2B, 0xF5, 0x89, 0xAF, 0x8A, 0xCA,
  43672. 0x48, 0xDF, 0x6D, 0x14, 0xEB, 0x43, 0xCE, 0xF0,
  43673. 0xA9, 0xC8, 0xA8, 0xF9, 0xAD, 0x32, 0x95, 0x25,
  43674. 0xEF, 0x0A, 0xAA, 0x4F, 0x9E, 0x09, 0xC3, 0x51,
  43675. 0x3C, 0xF0, 0x29, 0xF3, 0xDE, 0xFC, 0xBB, 0x41,
  43676. 0x14, 0xFA, 0x0F, 0x66, 0x8D, 0xB4, 0x72, 0x2F,
  43677. 0xCC, 0xD9, 0xC2, 0x07, 0xB6, 0x6F, 0x10, 0x9E,
  43678. 0xD9, 0x5B, 0x45, 0x4B, 0xB6, 0x19, 0x5D, 0x59,
  43679. 0xC4, 0xA6, 0x78, 0xBA, 0x6F, 0x5A, 0x9B, 0x23,
  43680. 0x41, 0x21, 0xAD, 0x05, 0x16, 0xA1, 0xD4, 0x12,
  43681. 0x3D, 0x38, 0x26, 0xD9, 0x2A, 0x61, 0xB3, 0x5D,
  43682. 0xEB, 0x29, 0x5B, 0xAA, 0x2F, 0xE1, 0xB5, 0xEE,
  43683. 0x25, 0x02, 0x1D, 0xAE, 0xF8, 0x57, 0xB5, 0xDF,
  43684. 0x19, 0x2E, 0x17, 0x5E, 0x3A, 0x2A, 0x0D, 0x3F,
  43685. 0x08, 0x2F, 0x21, 0x1C, 0xB5, 0xBD, 0xC2, 0x36,
  43686. 0x27, 0x4F, 0x86, 0xC5, 0xDC, 0x74, 0xC3, 0x9B,
  43687. 0xE9, 0x7C, 0xCF, 0x5F, 0x57, 0x94, 0xEB, 0x64,
  43688. 0xEC, 0x64, 0x55, 0x45, 0x21, 0x0F, 0xC6, 0x67,
  43689. 0xD1, 0xE0, 0x74, 0x0E, 0x66, 0xCB, 0xED, 0xC2,
  43690. 0x06, 0x48, 0xCA, 0x1F, 0xA7, 0x34, 0x14, 0x59,
  43691. 0x6B, 0xA0, 0x89, 0x17, 0xA1, 0x9A, 0x46, 0x3A,
  43692. 0xD3, 0x02, 0x7C, 0x81, 0x83, 0x6B, 0x8F, 0x4F,
  43693. 0x02, 0xB9, 0x9F, 0xC5, 0x08, 0x3F, 0x06, 0xF3,
  43694. 0x4B, 0xD2, 0x30, 0x9C, 0x23, 0x42, 0xAD, 0x88,
  43695. 0xA8, 0x4F, 0xA9, 0x6E, 0x20, 0x7C, 0x01, 0x08,
  43696. 0xF6, 0x82, 0x54, 0x14, 0x94, 0x4F, 0x26, 0x4E,
  43697. 0xD6, 0xC4, 0x66, 0x7C, 0x78, 0x8D, 0x61, 0xA6,
  43698. 0xBC, 0x2C, 0x45, 0x6A, 0xF6, 0x6C, 0x2F, 0x76,
  43699. 0x9E, 0x16, 0x90, 0x17, 0x06, 0x91, 0x2C, 0xC9,
  43700. 0x0D, 0x4B, 0x6C, 0x90, 0xDC, 0xA1, 0x6C, 0xAC,
  43701. 0x8F, 0xFE, 0xD8, 0x39, 0x70, 0x20, 0xE2, 0x97,
  43702. 0x5E, 0x24, 0xFF, 0x4C, 0x80, 0x7C, 0x8A, 0xB7,
  43703. 0x31, 0xC8, 0x1D, 0x36, 0xCA, 0x84, 0xC9, 0x12,
  43704. 0x1A, 0x85, 0x13, 0xE0, 0xC9, 0xD0, 0xF4, 0x1B,
  43705. 0xC6, 0x8F, 0x88, 0xEA, 0xCA, 0xA3, 0x55, 0x99,
  43706. 0xFA, 0xE3, 0xBB, 0xA6, 0xFC, 0xC6, 0x52, 0x8D,
  43707. 0x47, 0xE4, 0x0C, 0x07, 0x64, 0xCF, 0x9C, 0x83,
  43708. 0x83, 0xB3, 0xA4, 0x45, 0x15, 0xE6, 0x1D, 0x92,
  43709. 0xCD, 0xAE, 0xC9, 0xCB, 0x90, 0x82, 0xB5, 0xA0,
  43710. 0xC0, 0x37, 0x94, 0x60, 0xD9, 0x17, 0x9A, 0x7D,
  43711. 0x9D, 0xF2, 0x9E, 0x0B, 0x4B, 0x6A, 0x41, 0x18,
  43712. 0x28, 0x52, 0x15, 0xE8, 0x7B, 0x6F, 0x11, 0x8E,
  43713. 0x97, 0x31, 0xE4, 0x66, 0xFB, 0x3F, 0xEB, 0xD1,
  43714. 0x95, 0xE1, 0x44, 0xFD, 0x20, 0x37, 0xD1, 0x16,
  43715. 0x62, 0x75, 0x79, 0xAC, 0x55, 0xFE, 0xD5, 0xE3,
  43716. 0x25, 0x85, 0xEC, 0x66, 0x38, 0xA0, 0xDF, 0xBE,
  43717. 0x6E, 0xD6, 0xC5, 0x87, 0x6C, 0xF8, 0x11, 0x4C,
  43718. 0x90, 0x2A, 0xEF, 0xA3, 0x63, 0xF4, 0xC9, 0xB7,
  43719. 0x2E, 0x7D, 0x5C, 0x85, 0x2D, 0xCC, 0x1A, 0xF2,
  43720. 0xB8, 0x85, 0x2A, 0x9D, 0x0F, 0x99, 0x59, 0x38,
  43721. 0x86, 0x50, 0x84, 0xCE, 0x52, 0x13, 0xB3, 0x08,
  43722. 0xA9, 0xCB, 0x37, 0xF6, 0x81, 0x96, 0x0D, 0x84,
  43723. 0xEF, 0xE1, 0xDF, 0x51, 0x34, 0xA5, 0x91, 0x5A,
  43724. 0xE5, 0x87, 0x8B, 0x10, 0xDA, 0x0F, 0xD4, 0xD9,
  43725. 0xAC, 0x2A, 0xEF, 0x0C, 0x7E, 0x01, 0xC2, 0xE9,
  43726. 0xE7, 0xC0, 0x17, 0xE7, 0xBA, 0x74, 0x0C, 0xEE,
  43727. 0x1A, 0x89, 0x94, 0x59, 0xBB, 0x75, 0x03, 0x3E,
  43728. 0xEA, 0xF3, 0x19, 0x0D, 0x67, 0x79, 0xED, 0x9E,
  43729. 0xDD, 0x84, 0x6A, 0x74, 0xE3, 0x21, 0x52, 0x8C,
  43730. 0x03, 0x08, 0x4A, 0x5D, 0x30, 0x87, 0x48, 0x39,
  43731. 0x71, 0x8A, 0x53, 0x54, 0x9B, 0x2E, 0xC6, 0xB2,
  43732. 0xB7, 0x30, 0xAA, 0x93, 0x5C, 0xA6, 0xE1, 0xC4,
  43733. 0xFD, 0x8B, 0xE0, 0x35, 0x7D, 0x93, 0xF6, 0x21,
  43734. 0x74, 0xEE, 0xED, 0xF8, 0xDA, 0xB7, 0x75, 0x5B,
  43735. 0x46, 0x65, 0x7E, 0x59, 0xD7, 0xAA, 0x00, 0xB9,
  43736. 0xF2, 0xF8, 0x5E, 0x4C, 0x0F, 0x77, 0xFA, 0x11,
  43737. 0xA5, 0xD6, 0x9A, 0x23, 0xB1, 0xEF, 0x3A, 0x09,
  43738. 0xF2, 0x19, 0xD8, 0x3B, 0x1F, 0x39, 0x1F, 0x84,
  43739. 0x13, 0x18, 0xEE, 0xF3, 0x5A, 0x32, 0x63, 0x67,
  43740. 0xBF, 0xA2, 0xB1, 0x5F, 0xD7, 0x14, 0x03, 0x20,
  43741. 0x92, 0xB9, 0xD0, 0x2B, 0xF6, 0x13, 0xAF, 0xF7,
  43742. 0x69, 0x6F, 0xAD, 0xF1, 0xDE, 0x2C, 0x81, 0x70,
  43743. 0x77, 0xCB, 0x7C, 0x99, 0x67, 0x76, 0xD6, 0x9E,
  43744. 0xC2, 0x41, 0xA2, 0x42, 0x54, 0xDA, 0x2D, 0x13,
  43745. 0x98, 0x76, 0x91, 0xEA, 0xC7, 0xEB, 0xA8, 0xCD,
  43746. 0x8D, 0xCF, 0xB3, 0x94, 0x7B, 0x1D, 0x99, 0xED,
  43747. 0xF9, 0x62, 0xD2, 0x15, 0xB3, 0x18, 0xBB, 0x5F,
  43748. 0x9A, 0xA0, 0x4D, 0x1C, 0x82, 0x62, 0x6A, 0x41,
  43749. 0x73, 0xD0, 0x2D, 0x41, 0x0C, 0x58, 0x6B, 0xCA,
  43750. 0x4E, 0x51, 0xCA, 0x4F, 0x3E, 0x15, 0x1B, 0x54,
  43751. 0xF1, 0x7A, 0x6B, 0xC9, 0x67, 0x76, 0x09, 0xBB,
  43752. 0xAF, 0x6C, 0x30, 0x38, 0xA6, 0x7C, 0xAD, 0xA6,
  43753. 0x6B, 0x4F, 0xDF, 0xB5, 0x10, 0x29, 0xE0, 0x78,
  43754. 0x07, 0xD7, 0x05, 0x96, 0x9D, 0x96, 0xC9, 0xAB,
  43755. 0xFB, 0x71, 0x62, 0xE4, 0x58, 0x10, 0xA1, 0xDC,
  43756. 0x4B, 0x56, 0xDA, 0x14, 0x77, 0xED, 0x90, 0x0A,
  43757. 0x89, 0xCC, 0xAC, 0x29, 0x8E, 0x17, 0x88, 0x42,
  43758. 0x69, 0xC3, 0x9E, 0x8D, 0x7A, 0xB9, 0x66, 0xF3,
  43759. 0x3D, 0xDA, 0xDB, 0xE5, 0x6A, 0x38, 0x4C, 0xA2,
  43760. 0x0A, 0x7B, 0x18, 0x99, 0xEC, 0x18, 0xE2, 0xAE,
  43761. 0x54, 0x70, 0x00, 0xB9, 0x04, 0xE3, 0x4E, 0x46,
  43762. 0x80, 0x1D, 0x85, 0x74, 0xDB, 0x00, 0x84, 0x17,
  43763. 0xBC, 0xFD, 0xD1, 0xA7, 0x4D, 0xC0, 0x18, 0xE5,
  43764. 0x07, 0xB7, 0x6B, 0x0F, 0xA0, 0x86, 0x26, 0x23,
  43765. 0x5B, 0x1C, 0xE2, 0x4B, 0xCF, 0xC3, 0x20, 0xFA,
  43766. 0xE3, 0x55, 0x1C, 0x1C, 0x92, 0x9B, 0x94, 0xC7,
  43767. 0xC4, 0x96, 0x53, 0x41, 0x82, 0x9D, 0x8A, 0x13,
  43768. 0x47, 0xD6, 0xA7, 0x38, 0x58, 0x03, 0xB0, 0x8B,
  43769. 0xCD, 0xA8, 0x4A, 0x27, 0xEA, 0x5E, 0x49, 0xCA,
  43770. 0x1E, 0x60, 0x06, 0xEA, 0x23, 0x2A, 0x53, 0xEE,
  43771. 0x41, 0x7E, 0xC8, 0x81, 0xD3, 0x32, 0x8A, 0x15,
  43772. 0x63, 0x82, 0xA6, 0xB2, 0x93, 0x89, 0x4D, 0xDF,
  43773. 0x9B, 0x36, 0x9C, 0xDE, 0x6B, 0x2F, 0xF5, 0x9C,
  43774. 0xB6, 0xA5, 0x64, 0xE2, 0x1C, 0x92, 0x79, 0xEC,
  43775. 0xA0, 0x31, 0x1F, 0x5D, 0x80, 0xCE, 0x39, 0xB9,
  43776. 0x8B, 0xF9, 0x0D, 0xB3, 0x27, 0xF7, 0x4D, 0x3F,
  43777. 0x76, 0x2D, 0x11, 0x7D, 0xF5, 0xF9, 0x13, 0x20,
  43778. 0x84, 0xFF, 0xB5, 0x55, 0xA5, 0xD1, 0x47, 0x22,
  43779. 0x1A, 0xF8, 0x63, 0xAB, 0xF7, 0x87, 0x15, 0xB7,
  43780. 0x21, 0x94, 0x52, 0x9A, 0x0E, 0x33, 0x4D, 0x4A,
  43781. 0x19, 0x1D, 0x42, 0xA9, 0x9B, 0xEA, 0x52, 0xAD,
  43782. 0xA2, 0xC7, 0xCC, 0x4A, 0x97, 0x74, 0xD5, 0xCB,
  43783. 0x28, 0xD4, 0xED, 0x82, 0xB6, 0x1F, 0x94, 0xE8,
  43784. 0x9F, 0x60, 0xF0, 0xC8, 0xEA, 0x52, 0xDC, 0x07,
  43785. 0x9D, 0x46, 0x58, 0xBF, 0x8C, 0x85, 0x6D, 0x61,
  43786. 0x52, 0xD9, 0x22, 0x51, 0x94, 0x8B, 0x3B, 0xA0,
  43787. 0x14, 0xD8, 0xBA, 0xF3, 0xDC, 0xD3, 0x6B, 0xC7,
  43788. 0x1F, 0x8E, 0x5B, 0x2C, 0xE6, 0xF5, 0x35, 0xB7,
  43789. 0xB9, 0xAE, 0x13, 0xDA, 0x4A, 0x1E, 0xAF, 0xFC,
  43790. 0x25, 0x3B, 0xE4, 0x3A, 0x9F, 0x60, 0x8E, 0xAC,
  43791. 0xE7, 0x33, 0xCF, 0xCE, 0x52, 0xEA, 0x5C, 0xDA,
  43792. 0x83, 0x59, 0xDB, 0x53, 0xFF, 0x3A, 0xF2, 0xCE,
  43793. 0xFE, 0x87, 0x79, 0xBC, 0xC5, 0x3C, 0x24, 0xA4,
  43794. 0xB1, 0x8D, 0x5E, 0x0D, 0x78, 0x1B, 0xEC, 0xF7,
  43795. 0x5B, 0x54, 0x77, 0x47, 0x3A, 0x20, 0x24, 0xAD,
  43796. 0x56, 0xC5, 0x4A, 0x7F, 0x99, 0x0E, 0xF6, 0xB1,
  43797. 0xDF, 0xAC, 0x50, 0x10, 0x88, 0x50, 0x9D, 0x3A,
  43798. 0x37, 0xF1, 0xC8, 0xD5, 0xC2, 0x64, 0x87, 0xE4,
  43799. 0x20, 0xB7, 0xF4, 0x35, 0x8E, 0x92, 0x69, 0x76,
  43800. 0x1F, 0xF1, 0xFA, 0x3A, 0xFC, 0xBE, 0xCA, 0xEB,
  43801. 0x68, 0xF5, 0xDD, 0xDE, 0x3A, 0xA8, 0xFD, 0x07,
  43802. 0x8C, 0xC4, 0x22, 0x4C, 0xEA, 0x67, 0x13, 0x2D,
  43803. 0x7E, 0xBF, 0x5D, 0x23, 0x2E, 0x43, 0xBA, 0xDD,
  43804. 0x21, 0x8C, 0x0B, 0x4D, 0xBE, 0x1E, 0x16, 0x52,
  43805. 0x98, 0x66, 0xB9, 0xAB, 0x93, 0x58, 0x85, 0xAC,
  43806. 0xB4, 0x15, 0xFB, 0xB1, 0xEE, 0xE6, 0x94, 0x08,
  43807. 0xA5, 0x21, 0xB4, 0x62, 0xEC, 0x59, 0xCD, 0x0D,
  43808. 0x3C, 0x54, 0x96, 0xD9, 0x85, 0xAE, 0xB0, 0xCE,
  43809. 0x37, 0x4F, 0x67, 0x72, 0xA4, 0xE6, 0x39, 0x3A,
  43810. 0x4E, 0xF0, 0x07, 0x43, 0x80, 0x90, 0xA8, 0xA9,
  43811. 0xE5, 0x2D, 0x2F, 0x55, 0x66, 0x6D, 0x70, 0xF0,
  43812. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43813. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43814. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
  43815. 0x08, 0x0E, 0x12, 0x19, 0x20
  43816. };
  43817. #endif
  43818. #ifndef WOLFSSL_NO_ML_DSA_87
  43819. static const byte pk_87_draft[] = {
  43820. 0x2D, 0x1E, 0x6B, 0xED, 0x84, 0x52, 0xEB, 0xF1,
  43821. 0x26, 0xED, 0xE7, 0x0C, 0xA0, 0xA2, 0xB5, 0x0D,
  43822. 0x03, 0x34, 0x2D, 0x5B, 0x13, 0xB2, 0xAE, 0x21,
  43823. 0x0F, 0x45, 0x62, 0xA3, 0xBF, 0x67, 0x0C, 0xB1,
  43824. 0x5C, 0xE9, 0x25, 0xFD, 0x22, 0xF2, 0x62, 0x42,
  43825. 0xBA, 0xE3, 0x10, 0xB3, 0xAA, 0x41, 0x3B, 0x6E,
  43826. 0x78, 0xD4, 0x42, 0xD9, 0x35, 0xD1, 0x72, 0x8A,
  43827. 0x32, 0x48, 0xCC, 0x20, 0x5C, 0xCD, 0x8D, 0x3F,
  43828. 0xD8, 0x34, 0x95, 0x55, 0x20, 0xCD, 0xFB, 0x2C,
  43829. 0x73, 0xE9, 0x0E, 0x60, 0x8B, 0x2C, 0x3F, 0xA8,
  43830. 0xB7, 0xD1, 0x79, 0xFD, 0xDC, 0xC8, 0x81, 0x11,
  43831. 0xC9, 0xE8, 0x41, 0x71, 0xE9, 0x70, 0x9B, 0x53,
  43832. 0x59, 0x33, 0xE4, 0x92, 0xB6, 0x81, 0x9C, 0x6A,
  43833. 0x92, 0xED, 0xA2, 0x5A, 0xC4, 0x07, 0x77, 0x1A,
  43834. 0x8F, 0xED, 0xB4, 0xE7, 0x11, 0xFB, 0x89, 0xEB,
  43835. 0x7B, 0xDF, 0xCC, 0xEA, 0xC5, 0x3B, 0x4E, 0xF4,
  43836. 0x6B, 0x6F, 0xBE, 0xE1, 0x32, 0xA9, 0xD7, 0xAD,
  43837. 0xB4, 0x36, 0xE7, 0x4A, 0x6D, 0x67, 0x11, 0x83,
  43838. 0xAF, 0x31, 0x1A, 0x7A, 0x31, 0x42, 0x9B, 0x01,
  43839. 0x21, 0x17, 0x52, 0x75, 0x85, 0xF7, 0x92, 0x0F,
  43840. 0x34, 0x8A, 0x69, 0x11, 0x88, 0x5A, 0x02, 0x08,
  43841. 0xB6, 0x6D, 0xE3, 0x07, 0x93, 0xB1, 0x3F, 0xE1,
  43842. 0xD5, 0x7B, 0xD9, 0x51, 0xF7, 0xAA, 0xC0, 0x34,
  43843. 0x9A, 0x78, 0x5D, 0x26, 0xDB, 0xF1, 0xF0, 0xA9,
  43844. 0x1E, 0x5C, 0x9F, 0x4F, 0xA7, 0x43, 0x5C, 0x44,
  43845. 0xA9, 0x43, 0xF1, 0x38, 0x11, 0x45, 0xED, 0xEB,
  43846. 0x1C, 0x8A, 0x05, 0xEE, 0xFF, 0xAB, 0x20, 0x2C,
  43847. 0xF6, 0x2C, 0xEE, 0x77, 0x42, 0x36, 0x3E, 0xE6,
  43848. 0x9D, 0x8E, 0x45, 0x0F, 0xF6, 0x7C, 0x39, 0x62,
  43849. 0xD6, 0xFF, 0x97, 0xBC, 0x3D, 0x02, 0xD6, 0xDF,
  43850. 0x4A, 0x35, 0xDA, 0x3F, 0x89, 0xA4, 0x88, 0x33,
  43851. 0xCD, 0xF2, 0x90, 0xF0, 0xE9, 0x37, 0x2F, 0x65,
  43852. 0xA5, 0x88, 0x65, 0xFD, 0x40, 0x44, 0xAD, 0x09,
  43853. 0x09, 0x92, 0xAA, 0x15, 0x9E, 0xEE, 0xF7, 0x2B,
  43854. 0x0D, 0xA7, 0xCB, 0x3A, 0x5E, 0x0A, 0xED, 0xD6,
  43855. 0x7D, 0x82, 0x8B, 0xBA, 0xCF, 0xE5, 0x9E, 0xE4,
  43856. 0x62, 0xAB, 0x69, 0x6B, 0xBA, 0xD0, 0xE5, 0xA9,
  43857. 0xBB, 0x1F, 0x5A, 0x51, 0xE0, 0xFA, 0x5D, 0xD4,
  43858. 0x4D, 0x8E, 0xC0, 0xDC, 0x43, 0x06, 0xDF, 0x23,
  43859. 0x67, 0xB2, 0x4A, 0xA2, 0xFB, 0x75, 0x2F, 0x82,
  43860. 0xD8, 0x44, 0xE4, 0xC0, 0xCE, 0x15, 0x9E, 0x3F,
  43861. 0xD6, 0xB4, 0x70, 0x5F, 0x3B, 0xD0, 0x56, 0x3E,
  43862. 0x0A, 0x7A, 0x4B, 0x94, 0xBF, 0xBA, 0x01, 0x2B,
  43863. 0x9C, 0x8B, 0x91, 0x35, 0xF2, 0xDB, 0x4C, 0x8C,
  43864. 0x8D, 0xD6, 0xEE, 0xC8, 0x65, 0x8D, 0xF3, 0x05,
  43865. 0x59, 0xBE, 0x3A, 0x17, 0xA7, 0x72, 0x10, 0x56,
  43866. 0x14, 0xEF, 0xB8, 0xC1, 0xBE, 0x18, 0x11, 0x0B,
  43867. 0xE6, 0x70, 0xF8, 0x39, 0xA5, 0x72, 0x7D, 0xF9,
  43868. 0x47, 0xFB, 0xAC, 0xFD, 0x1F, 0xC3, 0x71, 0x33,
  43869. 0x58, 0x44, 0x15, 0xD3, 0x7C, 0x93, 0x2E, 0x70,
  43870. 0x92, 0xFA, 0xBB, 0xF2, 0xD0, 0x9D, 0x25, 0xC4,
  43871. 0xCF, 0x4A, 0xB8, 0xEC, 0xBE, 0x5D, 0x8B, 0x7F,
  43872. 0xA4, 0x7C, 0xAB, 0xAD, 0xE7, 0x1E, 0x93, 0x83,
  43873. 0x92, 0x86, 0x1E, 0x8D, 0x15, 0xA4, 0x1C, 0x5B,
  43874. 0x42, 0x25, 0xDA, 0x3D, 0x16, 0xD3, 0x93, 0xF2,
  43875. 0x85, 0x50, 0x86, 0x0A, 0x86, 0x35, 0x6B, 0x14,
  43876. 0xAB, 0x5F, 0x22, 0xD0, 0xCF, 0x03, 0x7C, 0xEB,
  43877. 0xB4, 0x0E, 0xAC, 0x87, 0xA2, 0x41, 0x42, 0xA0,
  43878. 0x21, 0x93, 0x00, 0xB6, 0x47, 0x6F, 0x96, 0xD0,
  43879. 0x41, 0xD1, 0xC3, 0x0E, 0x3C, 0x52, 0xD2, 0x45,
  43880. 0xAB, 0x6A, 0xE7, 0xA1, 0xE5, 0xFD, 0x73, 0xC5,
  43881. 0x82, 0x9D, 0x60, 0x62, 0x8B, 0x6D, 0x87, 0xFC,
  43882. 0x88, 0x9C, 0x3E, 0xEF, 0xAE, 0xAA, 0xB6, 0x1C,
  43883. 0x18, 0xEE, 0xD7, 0x51, 0x1A, 0x96, 0xC4, 0x93,
  43884. 0x25, 0x05, 0xD3, 0x83, 0x3D, 0xD8, 0x33, 0x16,
  43885. 0x14, 0x44, 0x88, 0xE2, 0xAF, 0xC4, 0xEC, 0x59,
  43886. 0x18, 0x12, 0xB9, 0x99, 0xC1, 0xC9, 0x5F, 0x31,
  43887. 0x79, 0x00, 0x03, 0xF6, 0xC9, 0x55, 0x14, 0xAA,
  43888. 0x29, 0x08, 0x78, 0x24, 0xAF, 0x1D, 0x99, 0x12,
  43889. 0x36, 0xD9, 0x4A, 0xD9, 0x50, 0xEF, 0x66, 0xFC,
  43890. 0x7F, 0xF4, 0xBC, 0x3B, 0xA0, 0xF6, 0xFD, 0xF2,
  43891. 0x62, 0xCA, 0xA5, 0x9D, 0x2B, 0x55, 0xB8, 0x33,
  43892. 0xBC, 0xA6, 0x7A, 0xA5, 0x1E, 0xE1, 0x14, 0x5F,
  43893. 0x94, 0xE2, 0xDC, 0xF0, 0x5B, 0xBD, 0x43, 0x07,
  43894. 0xD8, 0xB1, 0xE0, 0x81, 0x3F, 0x84, 0x54, 0x90,
  43895. 0xBF, 0x23, 0x59, 0x92, 0x3C, 0xA5, 0x98, 0xAB,
  43896. 0x7D, 0x99, 0xD2, 0xF0, 0xED, 0x8E, 0x0B, 0xC9,
  43897. 0x9F, 0xAF, 0xB0, 0x13, 0xED, 0xC7, 0xDD, 0xB8,
  43898. 0x61, 0x72, 0x07, 0x3D, 0xCC, 0x35, 0x73, 0xA0,
  43899. 0xCF, 0x0C, 0xD9, 0x7E, 0x93, 0xDC, 0x63, 0xB8,
  43900. 0x82, 0xEC, 0xF4, 0x30, 0xCE, 0x43, 0x92, 0xEA,
  43901. 0x5E, 0xD8, 0xC8, 0xA1, 0xEC, 0x79, 0xDC, 0xAE,
  43902. 0x64, 0xD4, 0x33, 0xEB, 0x53, 0x8C, 0xFC, 0x49,
  43903. 0x79, 0xBF, 0x7A, 0x28, 0x65, 0x1E, 0x8C, 0xD5,
  43904. 0x21, 0xB0, 0x8E, 0xCA, 0xAD, 0xF8, 0x96, 0x9A,
  43905. 0x98, 0x10, 0x00, 0x35, 0x6D, 0x58, 0x9A, 0xEF,
  43906. 0x84, 0x84, 0x86, 0x72, 0xBA, 0xCD, 0x38, 0x66,
  43907. 0x96, 0x9B, 0xC2, 0x83, 0xB0, 0x65, 0xC1, 0xAB,
  43908. 0xCF, 0x63, 0x8C, 0x2D, 0xC3, 0x42, 0xB2, 0x7D,
  43909. 0xF6, 0xB8, 0xF0, 0x3D, 0x26, 0x21, 0x8F, 0xAE,
  43910. 0x4E, 0x96, 0xF2, 0x55, 0x66, 0xBC, 0x6F, 0xED,
  43911. 0xE7, 0x19, 0xD3, 0x8D, 0xC0, 0xCD, 0x55, 0x20,
  43912. 0x5F, 0x10, 0xCA, 0xDA, 0x09, 0xED, 0x91, 0x4A,
  43913. 0x43, 0x33, 0xD3, 0x82, 0x11, 0x5C, 0x2F, 0x5D,
  43914. 0xEC, 0xCD, 0x54, 0xF9, 0x6C, 0xE4, 0xE5, 0xF2,
  43915. 0x68, 0xBC, 0xE9, 0x27, 0xB2, 0x1D, 0xCA, 0xB5,
  43916. 0xCD, 0x04, 0x01, 0x1E, 0x92, 0xF5, 0xF6, 0x01,
  43917. 0x86, 0x2B, 0x20, 0x20, 0x9B, 0xB0, 0xF9, 0x56,
  43918. 0xD9, 0x33, 0xD5, 0x0A, 0xEC, 0x1B, 0xF4, 0xCE,
  43919. 0xD2, 0xB2, 0xC2, 0xD4, 0x3F, 0x9A, 0x25, 0x76,
  43920. 0x8E, 0x29, 0x87, 0x52, 0x64, 0x86, 0x4A, 0xA5,
  43921. 0x7B, 0x5A, 0x91, 0x72, 0x6E, 0xBE, 0x6D, 0x73,
  43922. 0x0A, 0x8D, 0x89, 0x53, 0x82, 0x33, 0x70, 0x44,
  43923. 0x20, 0xBE, 0xE0, 0xB0, 0x1B, 0x76, 0x30, 0x43,
  43924. 0xA5, 0x5B, 0x8F, 0xAB, 0x7E, 0xB8, 0x61, 0x5F,
  43925. 0x43, 0x70, 0x1B, 0x1A, 0x71, 0x61, 0x56, 0xF9,
  43926. 0x13, 0x31, 0x2A, 0x64, 0x33, 0x14, 0x00, 0x98,
  43927. 0x72, 0xEC, 0x32, 0x88, 0x09, 0xFB, 0x64, 0x46,
  43928. 0x3D, 0x56, 0x02, 0xD9, 0x76, 0xD3, 0xAA, 0x90,
  43929. 0x0F, 0xBD, 0xF0, 0xF9, 0x96, 0x43, 0x7B, 0x62,
  43930. 0x19, 0x26, 0x22, 0x6A, 0x93, 0x91, 0xEC, 0x07,
  43931. 0x34, 0xF5, 0x22, 0x32, 0xB3, 0x65, 0x66, 0xE0,
  43932. 0x6B, 0x11, 0x7F, 0x97, 0x9F, 0x1A, 0x89, 0x46,
  43933. 0xCE, 0x8F, 0xBD, 0xFD, 0x2F, 0xCC, 0x3D, 0xBF,
  43934. 0xF2, 0x83, 0xA4, 0x30, 0xE1, 0x02, 0x72, 0xF8,
  43935. 0x74, 0xE6, 0x21, 0x96, 0x77, 0xE1, 0x57, 0x8A,
  43936. 0xF7, 0x9E, 0xB3, 0x31, 0xAF, 0xD8, 0xC5, 0xD7,
  43937. 0x20, 0xDC, 0xFD, 0xCF, 0x79, 0x06, 0x0F, 0x1F,
  43938. 0xE5, 0x84, 0x3D, 0x0B, 0x9C, 0xB3, 0xC7, 0xAB,
  43939. 0xB8, 0xF1, 0xC0, 0xD0, 0xB5, 0xC7, 0x01, 0xE2,
  43940. 0x0E, 0x3B, 0xAF, 0x7E, 0xAC, 0x44, 0x5A, 0x75,
  43941. 0x50, 0x0A, 0x76, 0x1C, 0x13, 0xDB, 0x25, 0xD4,
  43942. 0x0D, 0x19, 0x75, 0x4C, 0x02, 0xD9, 0xF3, 0xDF,
  43943. 0x6D, 0xBB, 0xCF, 0x47, 0xA6, 0xAE, 0xF6, 0xD1,
  43944. 0xFB, 0xF4, 0xB4, 0x55, 0xD3, 0xA5, 0x87, 0xA1,
  43945. 0x55, 0xFB, 0xBF, 0xCD, 0xF6, 0xA1, 0x64, 0x57,
  43946. 0x12, 0x75, 0x9A, 0x11, 0xA3, 0xCE, 0x42, 0x70,
  43947. 0x84, 0x54, 0x93, 0x12, 0xE1, 0x3A, 0x0F, 0xFA,
  43948. 0xCA, 0xF2, 0x25, 0x91, 0xF1, 0x4D, 0x8F, 0x84,
  43949. 0xB1, 0xB5, 0x35, 0xAC, 0xE9, 0x81, 0x77, 0x34,
  43950. 0x4D, 0x6F, 0x5D, 0x14, 0x9D, 0xB9, 0xE1, 0xF0,
  43951. 0x3F, 0x3C, 0xE7, 0xAD, 0x48, 0xE6, 0x8C, 0x51,
  43952. 0x86, 0xF4, 0x4A, 0xB4, 0xD0, 0x98, 0xEC, 0x3A,
  43953. 0x4E, 0xAB, 0x58, 0x2F, 0x08, 0x9E, 0x5A, 0x9D,
  43954. 0x45, 0x30, 0xB0, 0x85, 0xDF, 0x4A, 0xE7, 0x92,
  43955. 0xC6, 0xC8, 0x18, 0x93, 0x08, 0xCE, 0x9A, 0x8C,
  43956. 0xE2, 0x91, 0x8D, 0x91, 0x57, 0x7B, 0x37, 0xC8,
  43957. 0x80, 0xA2, 0x31, 0x10, 0x0D, 0x4E, 0xEF, 0x51,
  43958. 0x07, 0x94, 0x8E, 0xF8, 0x3C, 0x3C, 0x2E, 0xD5,
  43959. 0x03, 0x26, 0xB8, 0x72, 0x7F, 0xB9, 0xBC, 0xD7,
  43960. 0x95, 0xC4, 0x31, 0x08, 0xEC, 0x6F, 0xEE, 0x11,
  43961. 0xAF, 0xC0, 0xA2, 0xEC, 0xD7, 0xC8, 0x0B, 0xBE,
  43962. 0x15, 0xAE, 0xC9, 0x17, 0xBE, 0x37, 0xE2, 0x40,
  43963. 0x83, 0x65, 0xDE, 0xB3, 0x4E, 0xB4, 0x15, 0xB3,
  43964. 0x5C, 0x14, 0xF6, 0x5F, 0xA9, 0x1F, 0x70, 0xB5,
  43965. 0x23, 0x93, 0x78, 0xB9, 0x47, 0xF9, 0x1D, 0x2B,
  43966. 0x1E, 0x8D, 0xB1, 0x25, 0x7E, 0xE5, 0x85, 0x3C,
  43967. 0x16, 0x9F, 0xD0, 0xC2, 0x67, 0x8B, 0x0D, 0xD2,
  43968. 0x72, 0x4E, 0x74, 0x30, 0xE1, 0xAF, 0xB8, 0x66,
  43969. 0xCB, 0x53, 0xDF, 0xC4, 0xFB, 0xA5, 0x6D, 0x03,
  43970. 0xF2, 0xAE, 0xEE, 0x90, 0xFE, 0xD7, 0x30, 0xAF,
  43971. 0x33, 0x98, 0x09, 0xEB, 0x75, 0xC7, 0x3E, 0xC8,
  43972. 0x2F, 0xE7, 0x22, 0x5F, 0x2F, 0x0A, 0xBD, 0xA4,
  43973. 0x22, 0x88, 0x28, 0x19, 0x35, 0x83, 0x12, 0x86,
  43974. 0xEE, 0x72, 0xB4, 0x26, 0x89, 0x2F, 0xC7, 0x11,
  43975. 0x6E, 0xDD, 0x14, 0x98, 0x22, 0xE7, 0x73, 0x3E,
  43976. 0xFA, 0x46, 0x75, 0xF9, 0x40, 0xC1, 0x84, 0x22,
  43977. 0xBC, 0x75, 0x36, 0xC7, 0x82, 0xD3, 0xAE, 0x6E,
  43978. 0x0D, 0xBF, 0x6F, 0xC3, 0x4B, 0x67, 0x49, 0x19,
  43979. 0xF3, 0x4B, 0x12, 0xF2, 0x83, 0xFD, 0x39, 0x56,
  43980. 0x44, 0x05, 0x3A, 0x24, 0x6A, 0x35, 0x69, 0x12,
  43981. 0xCF, 0xE4, 0x93, 0xFE, 0x26, 0xCC, 0xD6, 0x01,
  43982. 0xA0, 0x4A, 0x84, 0xA8, 0x1D, 0x85, 0xE6, 0x83,
  43983. 0x0F, 0x3C, 0xE6, 0x6D, 0xD2, 0xCB, 0xB1, 0x14,
  43984. 0x8C, 0xEC, 0x10, 0xB3, 0x63, 0x4B, 0x9C, 0xF5,
  43985. 0x11, 0xE0, 0xF9, 0x86, 0x6F, 0xA7, 0xC0, 0x3B,
  43986. 0x9D, 0x25, 0xD7, 0x54, 0xCA, 0x40, 0x4D, 0x26,
  43987. 0xBA, 0x71, 0x8E, 0x25, 0xF5, 0xA7, 0xE3, 0x9B,
  43988. 0x25, 0x20, 0x7F, 0x29, 0x05, 0xB6, 0x27, 0x14,
  43989. 0x17, 0x67, 0x26, 0x10, 0xAD, 0xA3, 0x06, 0x03,
  43990. 0xFE, 0x82, 0x85, 0x5D, 0x01, 0x04, 0x4D, 0xE0,
  43991. 0x64, 0x38, 0x38, 0x5E, 0x83, 0x1E, 0x21, 0x9A,
  43992. 0x39, 0x02, 0xF8, 0xF9, 0x69, 0x85, 0x52, 0xE5,
  43993. 0xEC, 0x6A, 0xAC, 0x96, 0x86, 0xA7, 0x88, 0x69,
  43994. 0xB5, 0xB5, 0x7E, 0x03, 0x1D, 0xA9, 0x68, 0xCA,
  43995. 0x45, 0x0F, 0xF9, 0x14, 0xD6, 0x7B, 0xCF, 0x9C,
  43996. 0x03, 0x6F, 0xD1, 0xD9, 0x6F, 0x01, 0x3D, 0xF8,
  43997. 0xF3, 0x11, 0xF3, 0x29, 0x17, 0x90, 0xE8, 0x9B,
  43998. 0xED, 0x58, 0x9B, 0xF0, 0xBC, 0xC7, 0xBA, 0xF4,
  43999. 0x60, 0xC8, 0xAA, 0x30, 0xB4, 0x2F, 0x22, 0x8F,
  44000. 0xD3, 0xAC, 0x18, 0xC2, 0xB7, 0xC4, 0x7B, 0x31,
  44001. 0x9E, 0x0F, 0x7E, 0x9D, 0xBF, 0xD4, 0x63, 0xC2,
  44002. 0x8B, 0x1B, 0x58, 0x50, 0x33, 0x53, 0x6D, 0x79,
  44003. 0xBB, 0xF8, 0x0D, 0x91, 0x33, 0xD9, 0x07, 0xE7,
  44004. 0xB0, 0x81, 0xD4, 0xB4, 0x47, 0x61, 0x93, 0xF0,
  44005. 0xFB, 0x68, 0xBC, 0x1B, 0x41, 0xC2, 0xF5, 0x43,
  44006. 0x30, 0x7E, 0x76, 0xF9, 0xB1, 0xA3, 0xD6, 0xD4,
  44007. 0x26, 0xEA, 0x77, 0x75, 0x12, 0x7A, 0xC8, 0x30,
  44008. 0x9B, 0xCF, 0x45, 0xBE, 0x74, 0x7D, 0x8A, 0x8B,
  44009. 0xEC, 0xED, 0x11, 0xE6, 0xA1, 0xD1, 0xB8, 0xF1,
  44010. 0x90, 0xAD, 0x6D, 0x6A, 0xC6, 0x54, 0xE9, 0xDB,
  44011. 0xAD, 0x4C, 0x97, 0x39, 0xC8, 0xD8, 0x44, 0xA9,
  44012. 0x1A, 0x37, 0x16, 0x7E, 0x68, 0x45, 0x0C, 0xBB,
  44013. 0x10, 0xF4, 0xAE, 0x8E, 0x2B, 0x69, 0xFA, 0x95,
  44014. 0x3E, 0xA5, 0xC9, 0x91, 0xD3, 0xF1, 0xA3, 0x89,
  44015. 0x3F, 0x90, 0x86, 0x93, 0x1B, 0xF1, 0xA0, 0x89,
  44016. 0xC7, 0xF2, 0x23, 0x57, 0xD4, 0x8E, 0x2F, 0xD5,
  44017. 0x71, 0xCD, 0x36, 0xF1, 0x90, 0xB3, 0x98, 0x3E,
  44018. 0x19, 0xEA, 0xC8, 0x0F, 0x12, 0x9D, 0xBF, 0x58,
  44019. 0xED, 0xDC, 0x6B, 0x9A, 0x79, 0x84, 0xFC, 0xF0,
  44020. 0x4C, 0xC3, 0xB4, 0x0D, 0xB8, 0x7A, 0x8D, 0xAD,
  44021. 0x75, 0x40, 0xD5, 0xD5, 0xDE, 0xC8, 0xCA, 0x39,
  44022. 0x3E, 0x45, 0xE4, 0xBC, 0xF4, 0x33, 0xEA, 0x64,
  44023. 0xE1, 0x5E, 0x94, 0x42, 0x91, 0xAB, 0xBC, 0x42,
  44024. 0x2A, 0xB3, 0xD0, 0x60, 0x23, 0xCE, 0x57, 0x8E,
  44025. 0xFF, 0xAD, 0xA2, 0x2B, 0x64, 0xD9, 0x94, 0xA0,
  44026. 0x80, 0x0F, 0x8E, 0x50, 0x17, 0x08, 0x1D, 0x16,
  44027. 0xCF, 0x51, 0xD0, 0xB9, 0x28, 0xB6, 0x59, 0xEF,
  44028. 0x78, 0xCC, 0xC9, 0x96, 0xF9, 0xCA, 0x87, 0x7A,
  44029. 0xEE, 0xD9, 0x15, 0x5E, 0xDF, 0x5D, 0xBC, 0xC2,
  44030. 0x58, 0xE6, 0x04, 0xEE, 0x17, 0xDC, 0xB3, 0xF9,
  44031. 0x90, 0xF9, 0x88, 0x32, 0x9E, 0xA1, 0xDB, 0x1C,
  44032. 0x38, 0x56, 0x53, 0x90, 0x30, 0x69, 0x2E, 0x52,
  44033. 0x00, 0x2C, 0xF3, 0x0F, 0xD5, 0x80, 0x2E, 0x02,
  44034. 0x5B, 0x99, 0xBF, 0xCD, 0x11, 0x12, 0x64, 0x5B,
  44035. 0x56, 0xC6, 0x0A, 0xE6, 0x38, 0xE7, 0x4D, 0x21,
  44036. 0xE5, 0x98, 0x78, 0x9D, 0xE6, 0xCB, 0x60, 0xB4,
  44037. 0x2E, 0xE4, 0x98, 0x56, 0xCB, 0xAD, 0xE6, 0xDD,
  44038. 0x53, 0xF4, 0xC5, 0x67, 0xA2, 0x9F, 0xA0, 0x5C,
  44039. 0x7C, 0xFB, 0x24, 0x5A, 0xA7, 0x72, 0xD0, 0xE7,
  44040. 0x63, 0xF2, 0x5D, 0xBF, 0xD8, 0xE9, 0xF1, 0x6B,
  44041. 0xB4, 0x29, 0xA6, 0x28, 0xE6, 0x93, 0xD3, 0x87,
  44042. 0xB6, 0xD9, 0x3C, 0x39, 0x8D, 0xEA, 0x28, 0xC0,
  44043. 0x96, 0x3D, 0xF5, 0xC2, 0x3C, 0x29, 0xF2, 0x80,
  44044. 0x21, 0x8A, 0x03, 0x9D, 0x64, 0xF8, 0xBA, 0x81,
  44045. 0xC1, 0xDD, 0xA2, 0x88, 0x2A, 0x84, 0x2E, 0x3C,
  44046. 0xB5, 0x03, 0x95, 0xED, 0xAA, 0x6E, 0xE2, 0x6F,
  44047. 0x5E, 0x99, 0x3C, 0x63, 0xEE, 0xB8, 0x4F, 0x66,
  44048. 0x32, 0x77, 0x42, 0x23, 0x36, 0x29, 0x89, 0xB0,
  44049. 0xED, 0x5F, 0xF2, 0x5A, 0x65, 0x66, 0x3F, 0xD2,
  44050. 0x8B, 0x48, 0x68, 0x65, 0xDC, 0xE0, 0xB0, 0xC2,
  44051. 0x72, 0x73, 0xF1, 0xA4, 0xC6, 0x56, 0x2C, 0x5D,
  44052. 0xD8, 0xC6, 0x5C, 0x41, 0xCE, 0x30, 0x89, 0x59,
  44053. 0xA9, 0xD6, 0x45, 0x96, 0xD0, 0x8E, 0x7B, 0x25,
  44054. 0xE0, 0x13, 0xFB, 0xFE, 0x7C, 0xEA, 0xF3, 0x67,
  44055. 0x0D, 0xB2, 0x9A, 0x21, 0x3C, 0xCE, 0x99, 0x75,
  44056. 0xA9, 0x13, 0xCE, 0xF4, 0x23, 0x6E, 0x64, 0x00,
  44057. 0x30, 0x87, 0x70, 0x9C, 0xAD, 0x61, 0x81, 0x71,
  44058. 0x0E, 0x95, 0x19, 0x26, 0xCA, 0x55, 0x29, 0x71,
  44059. 0x99, 0xA6, 0x08, 0xAE, 0x54, 0x58, 0x75, 0xCD,
  44060. 0xC3, 0x8F, 0xE3, 0x83, 0xC1, 0x45, 0x62, 0xB4,
  44061. 0x8D, 0xCA, 0x66, 0x02, 0xEA, 0x34, 0x05, 0x5D,
  44062. 0x98, 0x3F, 0x38, 0xE6, 0x1C, 0xCE, 0x53, 0x1A,
  44063. 0xD9, 0x3F, 0x58, 0xEC, 0x16, 0x28, 0x45, 0xF5,
  44064. 0x38, 0xCE, 0x48, 0x43, 0x87, 0x1D, 0x3C, 0x4A,
  44065. 0xDF, 0x05, 0xF3, 0x5E, 0x29, 0x7E, 0xA6, 0x2E,
  44066. 0xFC, 0xDD, 0x5E, 0xF9, 0x40, 0x1B, 0xA0, 0x42,
  44067. 0xA2, 0x35, 0x15, 0x0A, 0x09, 0xD9, 0x47, 0x4A,
  44068. 0x3F, 0xB0, 0x3A, 0xAA, 0x19, 0xE7, 0xE3, 0x7A,
  44069. 0x22, 0x8D, 0x5F, 0x5B, 0x07, 0x41, 0x4C, 0x3D,
  44070. 0xA2, 0xAD, 0x2E, 0x5C, 0x75, 0xEC, 0xF0, 0x4C,
  44071. 0x11, 0x2B, 0x90, 0x76, 0x9E, 0x19, 0x96, 0x0E,
  44072. 0x97, 0x5E, 0x8D, 0x19, 0x17, 0xB3, 0xBF, 0xDA,
  44073. 0x84, 0xFD, 0xC6, 0xD2, 0x32, 0x6F, 0xB8, 0xA3,
  44074. 0xB0, 0x0F, 0x95, 0xD9, 0xC5, 0x26, 0x50, 0x11,
  44075. 0x15, 0x72, 0xBE, 0xC2, 0x1B, 0x12, 0x12, 0x7C,
  44076. 0xA5, 0x70, 0xD8, 0xA9, 0x8A, 0xB9, 0x77, 0xEB,
  44077. 0xD8, 0xD7, 0x9A, 0x59, 0x37, 0x5E, 0xE1, 0x4F,
  44078. 0x64, 0xB5, 0xB0, 0x4F, 0xD9, 0x69, 0xFE, 0xB0,
  44079. 0x3D, 0x0A, 0xF7, 0x34, 0x89, 0xE3, 0xBA, 0xEF,
  44080. 0xE7, 0xC7, 0xBC, 0x8D, 0xC7, 0xE8, 0x54, 0x83,
  44081. 0xEE, 0x62, 0xF0, 0x23, 0x98, 0x58, 0x0F, 0x83,
  44082. 0xB9, 0x6D, 0xD8, 0x44, 0x77, 0xB9, 0xC4, 0x8F,
  44083. 0x0B, 0xB3, 0x9F, 0x54, 0x06, 0xA3, 0x70, 0x36,
  44084. 0xD6, 0xF3, 0x6E, 0x2B, 0x1B, 0x6B, 0x53, 0xFE,
  44085. 0x6F, 0xF6, 0x1C, 0x32, 0x7B, 0x29, 0xD4, 0xE0,
  44086. 0x5D, 0xD2, 0xB8, 0x11, 0x74, 0xC6, 0x0B, 0x59,
  44087. 0xC7, 0x9C, 0xB1, 0x97, 0x6B, 0xC0, 0x6E, 0x7A,
  44088. 0xC3, 0x4D, 0xF3, 0xE3, 0x8F, 0x7D, 0x2C, 0x1C,
  44089. 0x0E, 0x31, 0x51, 0xB7, 0x14, 0x7A, 0xB8, 0x31,
  44090. 0x77, 0x47, 0x70, 0x14, 0x3B, 0x92, 0x7B, 0x5F,
  44091. 0xEC, 0x5D, 0xF7, 0x76, 0xC1, 0xD7, 0x2D, 0xB6,
  44092. 0xBC, 0x99, 0x81, 0xD6, 0x58, 0x67, 0x71, 0x3C,
  44093. 0xF2, 0x97, 0xC8, 0xB0, 0xF1, 0xE9, 0x8D, 0x0E,
  44094. 0x16, 0xF0, 0xCC, 0x22, 0x7A, 0x39, 0xE4, 0x7E,
  44095. 0x50, 0xBA, 0x01, 0x16, 0x15, 0x6D, 0x5B, 0x54,
  44096. 0x67, 0x53, 0x66, 0x04, 0xBE, 0x05, 0xCC, 0x2E,
  44097. 0xF4, 0x0A, 0xBC, 0xE8, 0x52, 0xF1, 0x5D, 0xFA,
  44098. 0x2C, 0xAC, 0xF8, 0x6A, 0x78, 0x9E, 0x5B, 0x7B,
  44099. 0x0E, 0x5B, 0xB4, 0xB7, 0x77, 0xCD, 0x7C, 0xC9,
  44100. 0xF6, 0x54, 0x77, 0x9B, 0x10, 0x2F, 0x78, 0xB5,
  44101. 0xAA, 0x4B, 0x94, 0xC3, 0xB4, 0xFD, 0xE5, 0x5F,
  44102. 0xA7, 0xF7, 0xBF, 0x54, 0xAC, 0x22, 0x5E, 0x1F,
  44103. 0x26, 0x16, 0x5B, 0x65, 0xF1, 0x6D, 0x03, 0x21,
  44104. 0x66, 0x9F, 0xD9, 0xF6, 0xE4, 0x7F, 0xCA, 0x1D,
  44105. 0xD3, 0x47, 0x09, 0x6D, 0xF5, 0xDD, 0xA8, 0x64,
  44106. 0x66, 0xA5, 0x7C, 0x5B, 0x06, 0x8D, 0x9C, 0x67,
  44107. 0xB7, 0x32, 0x03, 0x66, 0xEA, 0x19, 0xC8, 0x99,
  44108. 0x3F, 0xF9, 0x0B, 0xD8, 0xFB, 0x06, 0x93, 0xFB,
  44109. 0xA3, 0x70, 0xE6, 0x6D, 0x2B, 0x20, 0x3B, 0x99,
  44110. 0x70, 0x11, 0xB0, 0xD1, 0x5B, 0x94, 0xE2, 0x8B,
  44111. 0xAA, 0x2E, 0xBF, 0x01, 0x77, 0x4F, 0x7A, 0xE7,
  44112. 0x8F, 0x84, 0xED, 0xBD, 0xAD, 0x9F, 0x65, 0xA4,
  44113. 0x50, 0x42, 0x7A, 0x47, 0x74, 0xC6, 0x0C, 0xC8,
  44114. 0x9A, 0x02, 0x0B, 0x37, 0xDA, 0x21, 0xC7, 0x91,
  44115. 0xDA, 0xC8, 0xF7, 0xA7, 0x45, 0x7E, 0x30, 0xD0,
  44116. 0x8B, 0x01, 0x37, 0x51, 0x60, 0x03, 0x9C, 0x30,
  44117. 0x1B, 0x60, 0x51, 0xA9, 0x65, 0xE8, 0xA7, 0xCC,
  44118. 0xA2, 0xAE, 0xF9, 0x3B, 0xD5, 0x2F, 0x82, 0xC0,
  44119. 0x20, 0xBE, 0xCE, 0x90, 0xA1, 0x29, 0x02, 0x4E,
  44120. 0xFE, 0xA4, 0xB2, 0xFA, 0x21, 0x27, 0x0F, 0x8E,
  44121. 0xB5, 0xED, 0x6A, 0xAA, 0xE5, 0x59, 0x29, 0xAA,
  44122. 0xC5, 0x99, 0xA5, 0x77, 0x97, 0x29, 0x57, 0x66,
  44123. 0x0C, 0xC4, 0x7A, 0xC4, 0xE3, 0xCE, 0x77, 0x2B,
  44124. 0xBF, 0x10, 0x05, 0x2D, 0xE7, 0xED, 0xB1, 0xB8,
  44125. 0xA4, 0x49, 0x41, 0xF8, 0x84, 0xC9, 0xF8, 0xBE,
  44126. 0x13, 0x17, 0x46, 0x69, 0x94, 0x56, 0x29, 0xF4,
  44127. 0x6D, 0xE2, 0x46, 0x74, 0x44, 0xF3, 0x10, 0x6A,
  44128. 0x73, 0xFA, 0x27, 0x9C, 0xF0, 0x2A, 0x80, 0x0A,
  44129. 0x04, 0x7E, 0x20, 0xBD, 0x4D, 0x82, 0x0B, 0x38,
  44130. 0x9C, 0x3B, 0xB6, 0xA8, 0x68, 0xA5, 0x38, 0x4C,
  44131. 0xF5, 0x72, 0x4C, 0x20, 0x4C, 0xEF, 0xB1, 0xA6,
  44132. 0xA1, 0xBE, 0xB9, 0x72, 0x3E, 0x36, 0xDD, 0xDD,
  44133. 0xD9, 0xC7, 0x07, 0xC8, 0xF6, 0x3E, 0x8B, 0xC2,
  44134. 0x66, 0x83, 0xCC, 0x8B, 0x43, 0xC7, 0xDF, 0xDA,
  44135. 0xA4, 0x08, 0xAC, 0x4D, 0xD2, 0xBA, 0x9A, 0xEC,
  44136. 0xBC, 0x3B, 0x6D, 0xDA, 0xED, 0xCE, 0x09, 0x4A,
  44137. 0xAB, 0x58, 0xFF, 0x73, 0x2B, 0x19, 0x66, 0x38,
  44138. 0xD8, 0xB8, 0xEF, 0xC4, 0x28, 0xBB, 0xA9, 0x61,
  44139. 0x57, 0x93, 0xC4, 0xDD, 0x9F, 0x00, 0xF9, 0x0D,
  44140. 0x62, 0xC6, 0x76, 0xD1, 0x27, 0xA0, 0xE1, 0x8C,
  44141. 0x14, 0xC6, 0xEE, 0x9C, 0x99, 0x05, 0x10, 0xB0,
  44142. 0x54, 0xAD, 0xB4, 0xB4, 0x17, 0x0A, 0xC7, 0x12,
  44143. 0x7F, 0x93, 0x17, 0x5C, 0x1E, 0xB2, 0x25, 0x12
  44144. };
  44145. static const byte msg_87_draft[] = {
  44146. 0x14, 0x42, 0x63, 0x34, 0x94, 0x09, 0x60, 0x77,
  44147. 0x3B, 0xFF, 0x65, 0xF0, 0x8D, 0x1D, 0xE4, 0x89,
  44148. 0xC4, 0xC3, 0xED, 0x36
  44149. };
  44150. static const byte sig_87_draft[] = {
  44151. 0x13, 0xE8, 0x99, 0xEE, 0xDC, 0xCC, 0x0F, 0xBA,
  44152. 0x62, 0x91, 0x44, 0xE4, 0xAC, 0x06, 0x79, 0x06,
  44153. 0xB5, 0x32, 0x6B, 0x8F, 0x9A, 0x6C, 0xCB, 0xAB,
  44154. 0xE1, 0x44, 0x4A, 0xDD, 0x46, 0x45, 0x16, 0x0D,
  44155. 0x22, 0x57, 0x82, 0x87, 0x10, 0xD1, 0xEE, 0x10,
  44156. 0x60, 0x21, 0xB5, 0x64, 0x1E, 0x78, 0x81, 0x55,
  44157. 0x75, 0xD4, 0xF0, 0x95, 0xD0, 0x15, 0xD8, 0x46,
  44158. 0x5C, 0x92, 0xD2, 0xDD, 0xF4, 0xAB, 0xDF, 0xBE,
  44159. 0xB1, 0x1E, 0xE5, 0xE0, 0x70, 0xE6, 0xDA, 0x52,
  44160. 0xE5, 0x48, 0xDC, 0x04, 0xFD, 0xEF, 0x54, 0x72,
  44161. 0xE7, 0xE5, 0xF1, 0x82, 0x10, 0xAA, 0xCB, 0xA0,
  44162. 0x4F, 0x4F, 0x18, 0xAE, 0x66, 0x86, 0xB9, 0xAF,
  44163. 0x96, 0x57, 0xE3, 0x8E, 0x3B, 0x9B, 0xDD, 0xB4,
  44164. 0xAA, 0x84, 0xE6, 0x7B, 0x4D, 0x81, 0x92, 0xD0,
  44165. 0x03, 0x87, 0x3D, 0xD3, 0xEE, 0xE7, 0x47, 0x00,
  44166. 0xFB, 0xD8, 0x1E, 0x38, 0x1C, 0x21, 0x98, 0xB7,
  44167. 0xCC, 0xC1, 0x37, 0xC1, 0x71, 0xB2, 0x2F, 0x93,
  44168. 0x53, 0x41, 0x9C, 0x48, 0xC1, 0x4B, 0x8D, 0x63,
  44169. 0x0F, 0x99, 0x63, 0x40, 0x27, 0x5F, 0x6E, 0x60,
  44170. 0x4B, 0x95, 0xC4, 0x35, 0x20, 0x8A, 0xED, 0x2B,
  44171. 0xCA, 0x1B, 0x41, 0x9F, 0x83, 0x63, 0xF0, 0x95,
  44172. 0x0E, 0x24, 0x0D, 0x6F, 0x9E, 0xAB, 0x11, 0x8E,
  44173. 0x4B, 0xD3, 0xDA, 0x0E, 0xC3, 0xA2, 0xBE, 0x26,
  44174. 0xA8, 0xA0, 0x98, 0x57, 0x71, 0x3C, 0x36, 0xDD,
  44175. 0x69, 0xC3, 0x4E, 0xDD, 0x2C, 0x61, 0x9E, 0x88,
  44176. 0x26, 0x70, 0x71, 0xCF, 0x9E, 0xE5, 0xA6, 0x0C,
  44177. 0xA3, 0x14, 0x2D, 0xF1, 0x63, 0xF0, 0x1D, 0x8D,
  44178. 0x79, 0x6A, 0xC8, 0x50, 0xCF, 0xF3, 0x66, 0x60,
  44179. 0x78, 0xB3, 0x18, 0xFB, 0x5B, 0xD1, 0x73, 0x60,
  44180. 0xC8, 0x76, 0xC9, 0xC9, 0x0D, 0x8A, 0x7F, 0x41,
  44181. 0x2C, 0x8A, 0x31, 0x61, 0x6B, 0xE7, 0xA3, 0x74,
  44182. 0x58, 0x71, 0x54, 0x84, 0x86, 0x71, 0x5C, 0x94,
  44183. 0x26, 0x3A, 0x17, 0xB3, 0x6C, 0xA4, 0x99, 0x25,
  44184. 0x45, 0x0C, 0x57, 0x8A, 0xD9, 0xD4, 0xB1, 0xC2,
  44185. 0x00, 0x43, 0xF4, 0x5E, 0x84, 0x31, 0x99, 0x4F,
  44186. 0xA6, 0xD2, 0x6A, 0x14, 0x1B, 0xAD, 0x9E, 0x49,
  44187. 0x6E, 0x00, 0x9E, 0x91, 0x46, 0x16, 0xCA, 0x57,
  44188. 0x0C, 0x09, 0xF6, 0x38, 0xD0, 0x62, 0xBE, 0xC6,
  44189. 0x87, 0x33, 0x3A, 0xC7, 0x28, 0x38, 0x34, 0x53,
  44190. 0x7E, 0xFB, 0x60, 0x42, 0xF3, 0x7D, 0x83, 0xF7,
  44191. 0x29, 0x5D, 0xEA, 0x30, 0xD5, 0x00, 0x90, 0xB6,
  44192. 0x38, 0x4C, 0x17, 0x29, 0xEF, 0x17, 0xA0, 0xD5,
  44193. 0x87, 0x50, 0xC0, 0x03, 0x75, 0x14, 0xE5, 0xE1,
  44194. 0x22, 0x78, 0x53, 0xBC, 0x5A, 0xA3, 0x1E, 0x95,
  44195. 0xBE, 0xEC, 0x37, 0xB1, 0x51, 0x82, 0x69, 0x26,
  44196. 0x2E, 0xA3, 0x5A, 0xDA, 0x4F, 0xDA, 0x77, 0x62,
  44197. 0x7E, 0xED, 0xDA, 0xAF, 0x57, 0x97, 0x1B, 0xA3,
  44198. 0x6D, 0x46, 0x7B, 0x19, 0xA9, 0x0B, 0x99, 0x1C,
  44199. 0xD2, 0x55, 0xDB, 0x79, 0xB0, 0x15, 0x48, 0x86,
  44200. 0x52, 0x30, 0x31, 0xD6, 0xC5, 0xB1, 0xAE, 0x8F,
  44201. 0xCF, 0x9A, 0x43, 0x10, 0xBB, 0xC8, 0x19, 0x74,
  44202. 0x84, 0xB2, 0x92, 0x3B, 0xFE, 0x0B, 0x12, 0x15,
  44203. 0xA1, 0xC4, 0xD8, 0xC6, 0x83, 0x90, 0x89, 0x8A,
  44204. 0xD5, 0x3E, 0x33, 0x69, 0xB7, 0x05, 0x3F, 0xB1,
  44205. 0x8B, 0x0D, 0x87, 0x40, 0x70, 0x90, 0x2A, 0x5D,
  44206. 0x3B, 0x3D, 0x91, 0xD8, 0x1D, 0x4D, 0xF1, 0x08,
  44207. 0x7E, 0xF7, 0xDC, 0x05, 0x84, 0xEB, 0xDC, 0x63,
  44208. 0xD7, 0xBA, 0x3C, 0x0D, 0x31, 0xF8, 0x6D, 0xA6,
  44209. 0xC0, 0xFD, 0x08, 0x11, 0x5C, 0x53, 0xF6, 0xAE,
  44210. 0xFE, 0xC0, 0x82, 0x9A, 0x68, 0xD2, 0xA3, 0x44,
  44211. 0x2E, 0xEE, 0x47, 0x36, 0x70, 0x2D, 0x66, 0x81,
  44212. 0x0D, 0x62, 0x30, 0x8A, 0x8C, 0xC8, 0x2A, 0xA6,
  44213. 0x21, 0x82, 0xF5, 0x98, 0xF4, 0x4E, 0x25, 0x37,
  44214. 0x11, 0xB5, 0xD6, 0x07, 0x88, 0xBD, 0x0D, 0x69,
  44215. 0x0E, 0xF9, 0x8F, 0x9A, 0xD5, 0x93, 0xE0, 0x3C,
  44216. 0xEF, 0x38, 0xB9, 0xC9, 0x77, 0x98, 0x3F, 0x69,
  44217. 0x11, 0xBA, 0x1A, 0xB9, 0xF7, 0x35, 0xE9, 0x28,
  44218. 0xCD, 0xA3, 0x8C, 0x03, 0xE6, 0xAD, 0x83, 0x62,
  44219. 0xF4, 0x60, 0xAE, 0x4C, 0xD0, 0xF4, 0x6E, 0x00,
  44220. 0xEE, 0xEC, 0x74, 0xB6, 0x12, 0x34, 0x98, 0xAB,
  44221. 0x31, 0xE7, 0xA7, 0x9D, 0x33, 0x4D, 0x72, 0xA7,
  44222. 0xA7, 0xEE, 0xF3, 0xB5, 0x51, 0xE7, 0x8D, 0x31,
  44223. 0xBC, 0x2C, 0xAF, 0xFB, 0x13, 0x9C, 0xAC, 0xA4,
  44224. 0xD7, 0x9C, 0x8B, 0xBD, 0x52, 0xBD, 0x78, 0xF4,
  44225. 0x90, 0x65, 0x09, 0xBE, 0x42, 0xE7, 0x76, 0x3A,
  44226. 0xE6, 0xAC, 0xB8, 0x98, 0x28, 0x5E, 0xC9, 0x32,
  44227. 0x3E, 0x68, 0x67, 0x6A, 0x8C, 0xC7, 0x4A, 0x58,
  44228. 0xC8, 0xDA, 0x8B, 0xE9, 0x11, 0xED, 0x6F, 0x51,
  44229. 0x3B, 0x66, 0x08, 0x70, 0x73, 0x10, 0xFB, 0x45,
  44230. 0xCB, 0xD9, 0x7D, 0x5F, 0xF0, 0xD2, 0xAB, 0xA3,
  44231. 0x6F, 0xCE, 0xF7, 0x3D, 0x46, 0xCB, 0x7F, 0x01,
  44232. 0xC2, 0xCF, 0xE3, 0x8E, 0x68, 0xE8, 0x4F, 0x4A,
  44233. 0x30, 0x19, 0x16, 0xD2, 0xF5, 0x10, 0xD8, 0x2B,
  44234. 0x49, 0x69, 0xBE, 0x7A, 0x0E, 0x9C, 0xC6, 0x0E,
  44235. 0xFF, 0x5C, 0x0A, 0x87, 0x17, 0xB8, 0x22, 0x83,
  44236. 0x8C, 0x77, 0xAF, 0x42, 0x06, 0xB1, 0x25, 0x45,
  44237. 0x08, 0x9B, 0xB2, 0xDD, 0x6A, 0x3F, 0xF0, 0x12,
  44238. 0xC8, 0x64, 0x15, 0xBB, 0xA0, 0x4F, 0xD7, 0xD4,
  44239. 0xEC, 0x70, 0x7A, 0xF3, 0xB1, 0x7F, 0x25, 0x57,
  44240. 0x47, 0x66, 0xF1, 0xE9, 0x27, 0x38, 0xE0, 0x62,
  44241. 0x10, 0xF4, 0x8A, 0x5E, 0xF2, 0x55, 0x0E, 0xBD,
  44242. 0xF8, 0x5A, 0x5C, 0xA3, 0x44, 0x97, 0xCF, 0x1D,
  44243. 0x4D, 0x3A, 0x75, 0x86, 0x48, 0xEC, 0x41, 0x17,
  44244. 0x24, 0x43, 0x83, 0x5E, 0x50, 0x91, 0xBE, 0x8F,
  44245. 0x04, 0x78, 0x23, 0xD9, 0x62, 0x0C, 0x2A, 0xD5,
  44246. 0x1C, 0x96, 0x11, 0xAA, 0xEE, 0x39, 0xB2, 0x1E,
  44247. 0x6D, 0x6A, 0xEC, 0x87, 0x0C, 0x89, 0x15, 0xE2,
  44248. 0x66, 0x47, 0x6A, 0x50, 0xEE, 0xCA, 0x59, 0x96,
  44249. 0x22, 0xF7, 0x09, 0x1A, 0x34, 0xC2, 0x3F, 0x14,
  44250. 0xB4, 0x04, 0x29, 0xD9, 0x5E, 0x3E, 0xF9, 0x8F,
  44251. 0xED, 0x3E, 0x74, 0x94, 0x37, 0xF0, 0x4B, 0xB4,
  44252. 0xA3, 0x37, 0x52, 0x2E, 0x68, 0x09, 0xFC, 0x10,
  44253. 0x45, 0x03, 0xE2, 0x53, 0xB4, 0x1C, 0x4F, 0x03,
  44254. 0x01, 0xAF, 0x46, 0x7F, 0x74, 0xD3, 0x31, 0x25,
  44255. 0xFA, 0x83, 0xEF, 0x71, 0x24, 0x45, 0xA1, 0x71,
  44256. 0xFA, 0x40, 0xEB, 0xF4, 0xE6, 0x55, 0x3E, 0x45,
  44257. 0x4A, 0xFE, 0x25, 0x68, 0x02, 0x1D, 0x2B, 0x2A,
  44258. 0x19, 0x8D, 0xEC, 0x9B, 0xF7, 0x20, 0xF9, 0xD7,
  44259. 0x2F, 0x81, 0x52, 0x0B, 0xE8, 0x74, 0x66, 0xAF,
  44260. 0x70, 0xD0, 0x0E, 0x0E, 0x86, 0x0F, 0xF9, 0xAB,
  44261. 0xD0, 0x39, 0x78, 0xC3, 0xE4, 0x29, 0xB5, 0xAA,
  44262. 0x17, 0xB9, 0x7F, 0x9A, 0xE9, 0x34, 0x48, 0x85,
  44263. 0x3D, 0x6E, 0xFD, 0x16, 0x8A, 0x30, 0xC6, 0xCB,
  44264. 0xE8, 0xDE, 0x2D, 0x28, 0x8D, 0x9A, 0x24, 0xEA,
  44265. 0x5D, 0x2A, 0x58, 0x23, 0x33, 0x2B, 0x84, 0xFD,
  44266. 0x2C, 0xE7, 0x93, 0xA2, 0x2B, 0xEC, 0x43, 0x98,
  44267. 0x48, 0xD4, 0xE6, 0x0F, 0x3B, 0xB9, 0xC7, 0x5D,
  44268. 0x7E, 0xB0, 0x87, 0x1E, 0x80, 0x3D, 0x61, 0xB0,
  44269. 0x7E, 0x74, 0x9E, 0xD7, 0x60, 0x72, 0xB2, 0x7C,
  44270. 0x87, 0xB6, 0x9D, 0x6C, 0x01, 0x42, 0x61, 0xF6,
  44271. 0x47, 0xAF, 0xA8, 0x8C, 0x4F, 0x1E, 0xC5, 0x5A,
  44272. 0x75, 0xA5, 0x0F, 0xB4, 0xC7, 0x9D, 0x2C, 0x94,
  44273. 0xC0, 0x50, 0x3D, 0xB2, 0x0D, 0xFD, 0xF7, 0x1F,
  44274. 0x62, 0x88, 0x74, 0x18, 0x8C, 0xDD, 0x73, 0x85,
  44275. 0xC0, 0x33, 0x81, 0xDA, 0xBB, 0x85, 0x4D, 0x4A,
  44276. 0xA9, 0xF4, 0x7B, 0x66, 0x43, 0x8C, 0x43, 0xFF,
  44277. 0x53, 0xEF, 0x5E, 0x78, 0xAB, 0x45, 0x0B, 0x45,
  44278. 0x01, 0x91, 0x27, 0x8A, 0xF6, 0xE2, 0x6A, 0x7B,
  44279. 0x5E, 0x64, 0x61, 0xF5, 0x77, 0xF9, 0x85, 0x2F,
  44280. 0x81, 0xC9, 0x02, 0x03, 0xC7, 0x13, 0xF5, 0xB1,
  44281. 0xF6, 0xC3, 0xEF, 0x55, 0x8C, 0x90, 0x32, 0x51,
  44282. 0x6D, 0x8D, 0x62, 0xFD, 0x5E, 0x24, 0xE4, 0xF0,
  44283. 0xF5, 0x07, 0x18, 0xF5, 0x6B, 0x5A, 0x59, 0xA0,
  44284. 0x09, 0xD5, 0x93, 0x8D, 0xAD, 0x55, 0x91, 0xF6,
  44285. 0x1F, 0x4C, 0x65, 0x9A, 0x76, 0x05, 0x26, 0xEF,
  44286. 0x41, 0x20, 0x2F, 0xA7, 0xE5, 0xF6, 0xC7, 0xD5,
  44287. 0xE0, 0xB0, 0xC0, 0xC4, 0x3B, 0x52, 0x4B, 0x66,
  44288. 0x71, 0x2C, 0x5A, 0x7C, 0x53, 0xC8, 0x4C, 0x50,
  44289. 0xB8, 0x3E, 0xB9, 0xC9, 0x8D, 0x2F, 0xD0, 0x84,
  44290. 0xC9, 0xC5, 0xF2, 0x1F, 0xEE, 0x77, 0x42, 0xE6,
  44291. 0xEF, 0xC8, 0xCB, 0xBE, 0x57, 0x18, 0xB7, 0x0C,
  44292. 0x06, 0x2D, 0x82, 0xE2, 0xF9, 0x86, 0xF3, 0x8D,
  44293. 0xF1, 0xE7, 0x15, 0x89, 0xDC, 0x79, 0x87, 0x24,
  44294. 0x35, 0x62, 0xA2, 0x31, 0x9D, 0x7C, 0x00, 0xB2,
  44295. 0x6E, 0x53, 0x1E, 0x93, 0xC3, 0x84, 0x44, 0x61,
  44296. 0x8C, 0xE7, 0x58, 0x73, 0x4F, 0xDE, 0xCF, 0xD0,
  44297. 0xC6, 0x85, 0x37, 0x28, 0xC6, 0x10, 0x00, 0x78,
  44298. 0x4E, 0xDF, 0xFE, 0xD7, 0xB3, 0x30, 0x86, 0xE1,
  44299. 0x68, 0xD6, 0xCB, 0x63, 0xE3, 0xDA, 0xCA, 0xF3,
  44300. 0x55, 0x2F, 0x88, 0x5B, 0x47, 0x82, 0x62, 0xDE,
  44301. 0x5E, 0x1E, 0x63, 0xCE, 0x7A, 0x4C, 0x66, 0x95,
  44302. 0xD1, 0x19, 0x38, 0x35, 0xE4, 0x5A, 0x67, 0x91,
  44303. 0x8C, 0x42, 0xD3, 0x9B, 0xF8, 0x80, 0x38, 0x53,
  44304. 0x30, 0x31, 0x0F, 0x2C, 0x7B, 0xF9, 0x1E, 0x6C,
  44305. 0x3E, 0x29, 0xB7, 0x81, 0xD0, 0x98, 0x70, 0xC2,
  44306. 0x6D, 0x76, 0xBD, 0x8A, 0xE2, 0x09, 0xC4, 0x2B,
  44307. 0xC7, 0x43, 0x2D, 0xBB, 0x4C, 0x16, 0x52, 0x63,
  44308. 0x57, 0xA5, 0x63, 0x4E, 0xEC, 0xDE, 0x93, 0xC5,
  44309. 0x1D, 0xD4, 0xD6, 0xF0, 0x06, 0x5B, 0x2E, 0xC5,
  44310. 0x7A, 0xD3, 0xB5, 0x82, 0x66, 0x53, 0x95, 0x97,
  44311. 0xC8, 0xF4, 0x2B, 0x55, 0x27, 0x1D, 0x6F, 0x90,
  44312. 0xE9, 0x86, 0xF6, 0x82, 0x8D, 0x95, 0x9E, 0xE8,
  44313. 0x00, 0xDB, 0xEB, 0xCF, 0x48, 0x23, 0x6B, 0xA3,
  44314. 0xDE, 0x25, 0x27, 0xE0, 0xEC, 0xA4, 0xA3, 0xC2,
  44315. 0xA3, 0x4B, 0xBC, 0xDD, 0x6C, 0xBB, 0x3A, 0x9C,
  44316. 0x96, 0xDC, 0x3B, 0xE1, 0x10, 0xD3, 0x49, 0x94,
  44317. 0x66, 0xE2, 0x85, 0x7F, 0xBA, 0x98, 0x12, 0x3A,
  44318. 0x6D, 0xBA, 0x90, 0x14, 0x87, 0x7E, 0x24, 0xEA,
  44319. 0xDC, 0xCA, 0x40, 0xF8, 0xAE, 0x94, 0xB2, 0xFE,
  44320. 0xD2, 0x36, 0xCB, 0xE5, 0xBC, 0xA9, 0xDF, 0xE0,
  44321. 0xCB, 0xA9, 0xA0, 0xF8, 0x62, 0x41, 0x33, 0x18,
  44322. 0x59, 0xF9, 0xD6, 0xC0, 0x87, 0xB2, 0x76, 0xDE,
  44323. 0xC9, 0x35, 0x6F, 0x1F, 0xEF, 0x69, 0xB3, 0x59,
  44324. 0xF9, 0xFB, 0x38, 0x4A, 0x84, 0x02, 0x2D, 0xEC,
  44325. 0xB7, 0x01, 0x08, 0xDA, 0xC8, 0xE9, 0x3B, 0xB6,
  44326. 0xC3, 0x00, 0xC0, 0x34, 0x5F, 0xC6, 0x40, 0xC0,
  44327. 0x06, 0xEA, 0xEB, 0xC1, 0x51, 0x13, 0x81, 0x2F,
  44328. 0xB3, 0x7D, 0xD9, 0x6E, 0x2A, 0x06, 0xA4, 0x63,
  44329. 0xAF, 0xCE, 0x66, 0xC5, 0x9F, 0x8D, 0x71, 0x4A,
  44330. 0xA1, 0xFF, 0x49, 0x4F, 0x08, 0x6F, 0xB9, 0xEA,
  44331. 0xDA, 0x18, 0x45, 0x63, 0xCA, 0x9D, 0x88, 0x08,
  44332. 0xB1, 0x6C, 0x19, 0xA8, 0x24, 0xAD, 0x85, 0x7D,
  44333. 0xDE, 0x51, 0xE5, 0x08, 0xB7, 0x04, 0x12, 0x35,
  44334. 0xF3, 0x00, 0xED, 0x2C, 0x79, 0x9C, 0x18, 0x23,
  44335. 0x05, 0x38, 0x95, 0x76, 0xCF, 0x39, 0x3C, 0xAE,
  44336. 0xB0, 0xD3, 0xBA, 0x3E, 0x4E, 0xE4, 0xB5, 0x77,
  44337. 0xA3, 0xE3, 0x7B, 0x27, 0x5F, 0xD8, 0x05, 0x19,
  44338. 0x42, 0xAE, 0x91, 0x54, 0xE5, 0xBD, 0x7C, 0x35,
  44339. 0xE0, 0xF8, 0x95, 0x52, 0x3A, 0x29, 0xB0, 0xE6,
  44340. 0xB7, 0xAE, 0x20, 0xBE, 0x21, 0xDF, 0xF5, 0x67,
  44341. 0xEC, 0x82, 0x52, 0xFF, 0x5B, 0xD0, 0xAA, 0x14,
  44342. 0x50, 0x15, 0xE1, 0x1C, 0x6A, 0x1B, 0x94, 0x1B,
  44343. 0xCC, 0x76, 0x01, 0xBF, 0x03, 0x94, 0x42, 0xF2,
  44344. 0x00, 0x61, 0x96, 0x58, 0xD9, 0xD0, 0x40, 0x21,
  44345. 0xFA, 0xCE, 0x6B, 0xAB, 0x5D, 0x49, 0xD8, 0xD7,
  44346. 0xBC, 0x9A, 0x66, 0xC2, 0xBA, 0x3F, 0xDC, 0x49,
  44347. 0x0D, 0xA5, 0x5C, 0xB4, 0x67, 0x08, 0x38, 0xEB,
  44348. 0x2D, 0x07, 0x24, 0x5B, 0xB1, 0x22, 0x7B, 0x02,
  44349. 0x4A, 0x8A, 0x53, 0x38, 0xE9, 0x42, 0x8E, 0xA5,
  44350. 0x57, 0x41, 0xD6, 0x71, 0xA7, 0x9D, 0x6A, 0x14,
  44351. 0xD2, 0x7D, 0x13, 0xFB, 0x59, 0xD0, 0xDA, 0xE5,
  44352. 0x23, 0x9E, 0x1B, 0xC4, 0x21, 0x87, 0xBB, 0x78,
  44353. 0xE0, 0x38, 0x01, 0x1D, 0xA0, 0xD1, 0x36, 0x3F,
  44354. 0xD0, 0xA7, 0x8F, 0x86, 0x26, 0x1E, 0xB0, 0x26,
  44355. 0xDE, 0x7E, 0x17, 0x3A, 0x90, 0xFC, 0xC0, 0x17,
  44356. 0xDD, 0x78, 0xF5, 0xA3, 0x2D, 0x3E, 0x29, 0xCE,
  44357. 0x38, 0x45, 0x76, 0xA9, 0x55, 0x11, 0xB6, 0xB4,
  44358. 0xE5, 0x6E, 0xDD, 0x01, 0x4B, 0x16, 0x07, 0x99,
  44359. 0xBD, 0x19, 0x77, 0xF5, 0xD7, 0x9E, 0x39, 0x9E,
  44360. 0xAA, 0x8E, 0x2B, 0x75, 0xC5, 0xEB, 0x33, 0x56,
  44361. 0x6C, 0xD8, 0xB6, 0x3F, 0x3F, 0x4E, 0x81, 0x7E,
  44362. 0x29, 0x0A, 0x68, 0xED, 0x1E, 0x9F, 0xDC, 0x6B,
  44363. 0xFA, 0x18, 0xE3, 0xE5, 0x7D, 0x05, 0x7F, 0x22,
  44364. 0xFA, 0xA2, 0xF6, 0x0F, 0xB6, 0x34, 0x56, 0x72,
  44365. 0x55, 0x16, 0x5E, 0xF4, 0x18, 0xD1, 0x82, 0xFA,
  44366. 0xDD, 0xF7, 0xB8, 0x9F, 0x7D, 0x30, 0x10, 0x69,
  44367. 0xC4, 0x85, 0xD8, 0xE8, 0x34, 0x89, 0xD4, 0x93,
  44368. 0xBE, 0x56, 0xEE, 0xDC, 0x43, 0xD4, 0x82, 0x00,
  44369. 0xFD, 0x1E, 0x2B, 0x06, 0x69, 0x07, 0x1B, 0xBF,
  44370. 0x33, 0x61, 0x39, 0x28, 0xCA, 0x31, 0x91, 0x0B,
  44371. 0xF2, 0xEA, 0x32, 0x8E, 0xA8, 0x64, 0x13, 0x9A,
  44372. 0xEF, 0x79, 0x1A, 0x9A, 0xBE, 0x52, 0x13, 0x32,
  44373. 0x49, 0x93, 0x7D, 0xA8, 0x8C, 0x48, 0xD4, 0xC0,
  44374. 0x1D, 0x10, 0x8A, 0x46, 0x85, 0xAD, 0x29, 0xDF,
  44375. 0x2E, 0xCD, 0x41, 0x83, 0x82, 0x01, 0x28, 0x44,
  44376. 0x0E, 0xE5, 0x37, 0x8D, 0x6B, 0xCA, 0x61, 0x98,
  44377. 0xDE, 0x89, 0xA9, 0x7B, 0xBB, 0x44, 0x48, 0xA2,
  44378. 0x8D, 0x82, 0x3A, 0x57, 0x40, 0x60, 0x7C, 0x6E,
  44379. 0x69, 0x98, 0x98, 0x93, 0xFA, 0x7E, 0x29, 0x9A,
  44380. 0x74, 0x53, 0xD8, 0xDC, 0xB3, 0x4B, 0xDB, 0x7E,
  44381. 0xFE, 0x95, 0xB0, 0xC7, 0x23, 0x14, 0xEF, 0xCB,
  44382. 0x49, 0x3C, 0x09, 0xD7, 0x7B, 0xD0, 0x11, 0x9B,
  44383. 0xAC, 0xF2, 0xC2, 0x2E, 0x7C, 0xCB, 0xCD, 0x59,
  44384. 0x7F, 0x6A, 0x09, 0xFE, 0xFE, 0xDF, 0xA0, 0xA7,
  44385. 0xAC, 0x3C, 0x90, 0xBA, 0x75, 0x19, 0xF4, 0x01,
  44386. 0x60, 0x56, 0xD5, 0xFB, 0x41, 0x2B, 0xA0, 0x2D,
  44387. 0x0D, 0x45, 0xCF, 0xF3, 0xA6, 0x3D, 0x36, 0xEE,
  44388. 0xE1, 0xE4, 0x68, 0xE6, 0xEA, 0x2F, 0x67, 0x3A,
  44389. 0x7A, 0x02, 0x92, 0x6B, 0xB3, 0x18, 0xBA, 0x73,
  44390. 0xEE, 0x1B, 0x2C, 0x13, 0x7D, 0xEF, 0x4A, 0x39,
  44391. 0xE8, 0x03, 0xFF, 0x57, 0x35, 0x53, 0xE9, 0xA5,
  44392. 0xC6, 0xAA, 0x1A, 0x17, 0x21, 0xCA, 0x54, 0x38,
  44393. 0x7C, 0xB1, 0xDF, 0xB8, 0xFA, 0x7D, 0xA7, 0x26,
  44394. 0xB2, 0xAE, 0x7A, 0x05, 0x45, 0x3B, 0x40, 0x0A,
  44395. 0x19, 0xE5, 0x32, 0x52, 0x78, 0x9D, 0xC3, 0x20,
  44396. 0x63, 0x24, 0xB2, 0x58, 0x4B, 0x86, 0x1F, 0x00,
  44397. 0xA2, 0x50, 0xF9, 0x9F, 0xD9, 0xDC, 0x7D, 0x51,
  44398. 0x3D, 0xD7, 0xA6, 0x5A, 0x04, 0x03, 0x4E, 0xB3,
  44399. 0x3D, 0x2D, 0x56, 0xA4, 0x96, 0xB3, 0x6A, 0xBA,
  44400. 0x0A, 0x30, 0x08, 0xE3, 0x0F, 0xC1, 0x38, 0x24,
  44401. 0x88, 0x5D, 0x9E, 0x6F, 0x68, 0x1A, 0x7D, 0xB6,
  44402. 0x2D, 0xDD, 0xE3, 0x50, 0x1B, 0xD4, 0x07, 0x75,
  44403. 0xE2, 0xE2, 0xCC, 0x09, 0xCC, 0x8E, 0x4E, 0x67,
  44404. 0x02, 0x72, 0x02, 0xA8, 0x11, 0x70, 0xA5, 0x7F,
  44405. 0x4A, 0xC1, 0x98, 0xC1, 0x7F, 0xBF, 0x95, 0xBB,
  44406. 0xCE, 0xD3, 0x6D, 0x49, 0x30, 0xB9, 0x50, 0x8C,
  44407. 0xFA, 0x3E, 0x8B, 0xF6, 0xE5, 0x54, 0xE9, 0x1B,
  44408. 0xD7, 0xD6, 0xE5, 0x32, 0x33, 0xBB, 0x91, 0xAD,
  44409. 0xC8, 0x15, 0x76, 0x1A, 0x04, 0x35, 0xDE, 0xCC,
  44410. 0xE1, 0x67, 0x26, 0x4C, 0x2F, 0x4E, 0x34, 0x34,
  44411. 0x3D, 0x1E, 0x5A, 0xF7, 0xBC, 0xE6, 0x0C, 0x9B,
  44412. 0x7B, 0x7E, 0xE5, 0xDF, 0x72, 0x9A, 0x0D, 0xDD,
  44413. 0x4B, 0xE6, 0x6F, 0x82, 0xFB, 0x5E, 0x2C, 0xC0,
  44414. 0x7B, 0x03, 0x85, 0x76, 0x11, 0x0E, 0xFD, 0xC7,
  44415. 0xD5, 0x50, 0x26, 0xBE, 0x75, 0x5E, 0xC1, 0xF0,
  44416. 0x2E, 0x47, 0x62, 0xD6, 0xF1, 0xDA, 0xDF, 0xF4,
  44417. 0x1C, 0xEE, 0x63, 0x52, 0xC4, 0x45, 0x37, 0xE6,
  44418. 0x85, 0xA5, 0x0A, 0x07, 0x54, 0x63, 0x21, 0x7B,
  44419. 0x92, 0xF7, 0x33, 0x0C, 0xD9, 0x29, 0xCF, 0xE3,
  44420. 0xAB, 0xB5, 0xFC, 0xAA, 0x26, 0x20, 0x93, 0x55,
  44421. 0x8A, 0x07, 0x33, 0xB2, 0x7D, 0x95, 0x02, 0x7A,
  44422. 0x76, 0x9E, 0x7D, 0xBB, 0xC1, 0xF3, 0x6E, 0x84,
  44423. 0x10, 0x30, 0x4B, 0x5D, 0x59, 0x73, 0x68, 0xEC,
  44424. 0x2A, 0x63, 0x2D, 0x46, 0xE8, 0xC2, 0xF8, 0xEA,
  44425. 0x2B, 0xC4, 0x4F, 0xA7, 0x6E, 0xF4, 0x74, 0xEB,
  44426. 0x96, 0xA3, 0x64, 0x40, 0x9B, 0x23, 0x63, 0x42,
  44427. 0x4B, 0x8F, 0x85, 0x00, 0x43, 0x04, 0xAD, 0x61,
  44428. 0x76, 0x93, 0xBD, 0xC3, 0x88, 0xC3, 0xFC, 0x29,
  44429. 0x61, 0xBD, 0xB1, 0x5A, 0x1F, 0x5B, 0x20, 0xEF,
  44430. 0x95, 0xED, 0x99, 0x84, 0x96, 0xB2, 0x93, 0x81,
  44431. 0x82, 0xFF, 0xE3, 0xB9, 0x27, 0xEA, 0x9A, 0x23,
  44432. 0xF6, 0x42, 0x8D, 0xD3, 0x5C, 0x86, 0x11, 0xC8,
  44433. 0x39, 0xE3, 0x16, 0xE9, 0xA5, 0x32, 0x7C, 0xC9,
  44434. 0xEA, 0x82, 0x50, 0x9B, 0x21, 0x5C, 0xC9, 0x66,
  44435. 0xBE, 0x1C, 0x78, 0x48, 0xEF, 0x39, 0x2D, 0xA1,
  44436. 0xC6, 0xF3, 0x69, 0xA3, 0x36, 0x25, 0x3A, 0xA1,
  44437. 0x15, 0x2B, 0x6D, 0xCF, 0xDA, 0xA7, 0xCA, 0xDD,
  44438. 0x4D, 0x9A, 0x1D, 0x58, 0x9F, 0x73, 0xD3, 0xEF,
  44439. 0x0F, 0xBF, 0x03, 0x88, 0x2F, 0xDE, 0xB9, 0x44,
  44440. 0xB5, 0xB6, 0xCF, 0xE2, 0x6F, 0x6A, 0xB5, 0x12,
  44441. 0x38, 0x29, 0x55, 0x8C, 0x4C, 0x73, 0x6F, 0x0B,
  44442. 0x68, 0x7A, 0xC7, 0x06, 0x83, 0x80, 0xFE, 0x7F,
  44443. 0x61, 0xBE, 0x6B, 0x40, 0xE3, 0xF0, 0x4D, 0x7B,
  44444. 0x36, 0x82, 0x0F, 0xD8, 0x63, 0x29, 0xB3, 0x10,
  44445. 0x9D, 0x02, 0xEC, 0x63, 0x90, 0xEA, 0xFC, 0x8C,
  44446. 0xA7, 0x30, 0x56, 0x2B, 0x68, 0x08, 0x24, 0x24,
  44447. 0xFD, 0xA9, 0x8D, 0x0B, 0x64, 0xBC, 0x97, 0x34,
  44448. 0xB4, 0x0B, 0x63, 0xF7, 0xE3, 0x7A, 0xF6, 0x89,
  44449. 0x0A, 0xF7, 0xC2, 0xD9, 0x2F, 0x79, 0xEE, 0xA3,
  44450. 0xCC, 0xEA, 0xC6, 0x0A, 0x6F, 0x38, 0x06, 0x92,
  44451. 0xF8, 0x02, 0xB1, 0x55, 0x6A, 0x78, 0xFE, 0x55,
  44452. 0x83, 0xFF, 0x20, 0xA9, 0xC6, 0xA7, 0xBF, 0xCC,
  44453. 0x86, 0x3A, 0x9E, 0x7B, 0x62, 0x01, 0x4D, 0x16,
  44454. 0x05, 0xDE, 0x89, 0x4F, 0xB5, 0x85, 0xE2, 0xD4,
  44455. 0xF9, 0x41, 0x15, 0xE0, 0x29, 0xE5, 0x85, 0x7E,
  44456. 0x6A, 0x0A, 0x73, 0x89, 0x27, 0x5F, 0x53, 0x0D,
  44457. 0x3D, 0x80, 0xCF, 0xAB, 0x1F, 0x22, 0x5D, 0x38,
  44458. 0x33, 0x5D, 0x24, 0x67, 0x91, 0x97, 0xD4, 0x8A,
  44459. 0x01, 0x8A, 0x34, 0x18, 0x7D, 0xE3, 0xBC, 0xCE,
  44460. 0xDE, 0x94, 0xFF, 0x8E, 0xC5, 0x34, 0xC0, 0x2D,
  44461. 0xA7, 0x24, 0xD4, 0x59, 0x8D, 0x66, 0x9E, 0x85,
  44462. 0xA9, 0xC6, 0x0E, 0x45, 0x21, 0x4F, 0xAA, 0x65,
  44463. 0x44, 0xD6, 0xA4, 0x7D, 0x1C, 0x4E, 0xD7, 0x40,
  44464. 0x9D, 0x55, 0xB1, 0xA7, 0xF1, 0x15, 0xAE, 0x15,
  44465. 0x44, 0x3A, 0x1C, 0x31, 0x06, 0x40, 0xD1, 0x16,
  44466. 0x23, 0x84, 0x93, 0xEF, 0x3E, 0xE2, 0x87, 0x9B,
  44467. 0xB8, 0x46, 0x1F, 0x7D, 0x68, 0x73, 0x64, 0x70,
  44468. 0xD4, 0xB5, 0x73, 0xAE, 0x45, 0x49, 0x93, 0xF5,
  44469. 0x32, 0x30, 0x1E, 0x35, 0xCB, 0x9E, 0xEE, 0xDF,
  44470. 0xFE, 0xA8, 0x2F, 0xAC, 0x49, 0x77, 0x53, 0xF7,
  44471. 0x50, 0x19, 0xF2, 0xB3, 0xB0, 0x2C, 0x70, 0xB6,
  44472. 0x4A, 0x57, 0x95, 0x31, 0xC3, 0x26, 0x07, 0x2A,
  44473. 0xCF, 0x1B, 0xD0, 0xAA, 0xA0, 0x9F, 0x0A, 0x97,
  44474. 0x8B, 0x78, 0xAB, 0x22, 0xBD, 0x61, 0x19, 0xF8,
  44475. 0x8D, 0xD2, 0xD5, 0x72, 0xF8, 0x91, 0x9D, 0x47,
  44476. 0x4F, 0x59, 0x1D, 0xAE, 0x9F, 0xCE, 0x47, 0x53,
  44477. 0xC9, 0x85, 0xFB, 0x25, 0x04, 0x25, 0xF2, 0x65,
  44478. 0x61, 0xFF, 0xA9, 0x44, 0x3F, 0x23, 0x76, 0x68,
  44479. 0x9F, 0xEB, 0x48, 0xC4, 0xCE, 0x51, 0x46, 0x04,
  44480. 0x52, 0x6A, 0x10, 0x0A, 0xF3, 0x3F, 0x0D, 0x43,
  44481. 0x37, 0xD1, 0x60, 0x42, 0x22, 0xC4, 0xD9, 0xF9,
  44482. 0x3A, 0x8E, 0x69, 0xE4, 0xCC, 0xD3, 0x66, 0x69,
  44483. 0x09, 0x0C, 0x5D, 0xFB, 0x0E, 0x95, 0x49, 0x42,
  44484. 0x29, 0xFF, 0x9B, 0x20, 0xCC, 0xB1, 0xAC, 0x81,
  44485. 0xB8, 0x1A, 0x36, 0xD6, 0x3A, 0x85, 0x0D, 0xDB,
  44486. 0x33, 0x33, 0x4D, 0xAA, 0x51, 0x46, 0xBF, 0x36,
  44487. 0xFE, 0x18, 0x80, 0x1E, 0x3B, 0xEB, 0xD0, 0xE9,
  44488. 0x1B, 0x5E, 0x1C, 0xFE, 0x7A, 0x98, 0x26, 0x85,
  44489. 0x0A, 0xF4, 0x39, 0x7D, 0x1B, 0x07, 0xD3, 0xB7,
  44490. 0x19, 0xE5, 0x7B, 0xB8, 0x32, 0xAF, 0x42, 0x34,
  44491. 0xC0, 0xCD, 0x9F, 0xD4, 0x0B, 0x88, 0x2F, 0xCE,
  44492. 0xDA, 0x93, 0x7E, 0xF9, 0xA2, 0xDA, 0x24, 0x59,
  44493. 0x2B, 0xCB, 0x5D, 0x1B, 0xE8, 0x3E, 0xC5, 0xF0,
  44494. 0x3D, 0xBD, 0xFB, 0xCB, 0x33, 0x5D, 0x90, 0xD5,
  44495. 0xC8, 0xA0, 0x2E, 0xE5, 0x3D, 0x50, 0x8E, 0xB5,
  44496. 0xDE, 0x4A, 0x96, 0x1B, 0x95, 0x8F, 0x75, 0x1E,
  44497. 0x5F, 0x89, 0xA1, 0xD2, 0x88, 0x95, 0xA3, 0xDB,
  44498. 0x7B, 0x62, 0xEF, 0x4A, 0xE1, 0x6D, 0x28, 0xFB,
  44499. 0x78, 0x9B, 0x32, 0x03, 0xAD, 0x24, 0x63, 0xD6,
  44500. 0xEA, 0xB8, 0x3A, 0x6D, 0x20, 0xCE, 0xA1, 0x31,
  44501. 0x4A, 0xE0, 0x2A, 0x3F, 0xF6, 0xF6, 0x53, 0x15,
  44502. 0x4A, 0xE1, 0x44, 0x23, 0x81, 0x86, 0x21, 0x47,
  44503. 0x41, 0xC2, 0x36, 0x14, 0x81, 0x83, 0xBC, 0x39,
  44504. 0xAE, 0xDF, 0x44, 0xDA, 0x97, 0xF7, 0x31, 0xCE,
  44505. 0x3D, 0xCB, 0x61, 0xA4, 0xCF, 0xE1, 0x4F, 0x9E,
  44506. 0x84, 0xAA, 0x05, 0xAB, 0x1C, 0x1B, 0x95, 0x1D,
  44507. 0x20, 0x15, 0x52, 0x33, 0xFA, 0xFA, 0xF1, 0x6C,
  44508. 0xF1, 0xBD, 0x0B, 0xAF, 0xE1, 0x99, 0xE6, 0x5D,
  44509. 0x56, 0x34, 0x53, 0xBF, 0xE5, 0x5D, 0x5F, 0x47,
  44510. 0x4A, 0xB1, 0x05, 0x94, 0xD7, 0x38, 0xA8, 0xC1,
  44511. 0x06, 0x28, 0x8D, 0x69, 0xD0, 0x7A, 0x16, 0x88,
  44512. 0x60, 0x14, 0x63, 0xF3, 0xBD, 0x21, 0x46, 0x81,
  44513. 0x9C, 0x83, 0x72, 0x6D, 0x14, 0xC6, 0xA8, 0x08,
  44514. 0x39, 0xB8, 0x79, 0x0B, 0x57, 0x16, 0xE7, 0x72,
  44515. 0xF6, 0xC2, 0x4C, 0x2B, 0xEB, 0x7E, 0x2C, 0xF3,
  44516. 0x7B, 0x3F, 0x42, 0xAC, 0xDD, 0x47, 0x3E, 0x8C,
  44517. 0xCD, 0xBE, 0x48, 0x4D, 0x6E, 0x07, 0xB0, 0x73,
  44518. 0xDE, 0xCB, 0x17, 0x4A, 0xC3, 0xB8, 0xBB, 0x2E,
  44519. 0xF5, 0x4E, 0x6D, 0xF9, 0xE0, 0x20, 0x71, 0xFA,
  44520. 0x60, 0x0A, 0xE5, 0x59, 0x67, 0xEB, 0x6F, 0x70,
  44521. 0x2F, 0x71, 0x91, 0x59, 0xF0, 0xEB, 0x06, 0x5C,
  44522. 0xC4, 0x60, 0x48, 0xE8, 0x75, 0xE7, 0xCF, 0x42,
  44523. 0x71, 0xAD, 0x2E, 0xDA, 0xF9, 0x10, 0x82, 0x9A,
  44524. 0xF6, 0x13, 0xBA, 0x89, 0xFC, 0x61, 0x2A, 0x00,
  44525. 0xFD, 0xAE, 0x53, 0x7B, 0x09, 0x3A, 0xE8, 0xCB,
  44526. 0xE6, 0xB7, 0x0D, 0x03, 0x01, 0xFA, 0x2E, 0x13,
  44527. 0xA9, 0x16, 0x38, 0x1C, 0x92, 0xEC, 0xB4, 0x51,
  44528. 0xA3, 0x6E, 0x3F, 0xA8, 0xB7, 0x37, 0x36, 0x20,
  44529. 0xC0, 0x71, 0xA3, 0x05, 0x34, 0xED, 0xCB, 0x4A,
  44530. 0x3F, 0x11, 0x31, 0x17, 0xA5, 0x02, 0xD6, 0xA7,
  44531. 0x2D, 0xE6, 0xC7, 0x7B, 0xBB, 0xF6, 0xAE, 0x99,
  44532. 0x85, 0x9A, 0xAC, 0xE6, 0x4A, 0x92, 0x8C, 0x37,
  44533. 0x4B, 0xD2, 0xC4, 0x65, 0x2A, 0xC9, 0x7E, 0xB7,
  44534. 0x44, 0xD2, 0x9A, 0x70, 0xCE, 0xA9, 0xA1, 0x9D,
  44535. 0x70, 0x13, 0x49, 0x7B, 0xCA, 0xB6, 0x96, 0x31,
  44536. 0x43, 0x3F, 0x9E, 0xD1, 0xFE, 0x20, 0xF8, 0x0B,
  44537. 0x59, 0x83, 0xE1, 0x28, 0x8B, 0xB6, 0xA2, 0xBE,
  44538. 0x91, 0x54, 0x3E, 0xD4, 0x79, 0x28, 0xBB, 0x5E,
  44539. 0x46, 0x2D, 0x01, 0xE9, 0xC0, 0xB7, 0xFF, 0xFA,
  44540. 0xC0, 0x6C, 0x10, 0xF1, 0x52, 0xF4, 0x3C, 0x32,
  44541. 0x9E, 0x89, 0xDF, 0x8A, 0x79, 0x99, 0x6A, 0x09,
  44542. 0x79, 0x8A, 0x36, 0x76, 0x40, 0xBE, 0x9F, 0xB5,
  44543. 0x3D, 0xCE, 0x27, 0xBD, 0x0B, 0xAA, 0x9B, 0xF0,
  44544. 0x21, 0xBF, 0x10, 0xD2, 0xFC, 0xFE, 0x5B, 0x13,
  44545. 0xFD, 0x7D, 0x84, 0xD1, 0xC1, 0xEB, 0xC0, 0xBC,
  44546. 0xEC, 0x26, 0xD0, 0x87, 0x80, 0xD1, 0x3B, 0x99,
  44547. 0x47, 0x67, 0x26, 0x61, 0xE0, 0xFA, 0x5F, 0xAE,
  44548. 0x6F, 0x31, 0x5B, 0x6D, 0xE4, 0x01, 0x68, 0xC2,
  44549. 0x35, 0x1D, 0xE3, 0x1F, 0x41, 0xFF, 0x6C, 0x53,
  44550. 0x32, 0x26, 0xE1, 0xBC, 0xE3, 0xF8, 0xE2, 0x16,
  44551. 0xAF, 0x3B, 0xE6, 0x4C, 0x69, 0x33, 0x72, 0xA0,
  44552. 0x66, 0xB1, 0x75, 0xF7, 0x26, 0xCF, 0xCD, 0x64,
  44553. 0x2B, 0xAE, 0x98, 0x02, 0x92, 0xC1, 0xCB, 0x65,
  44554. 0xE0, 0x1F, 0x07, 0x29, 0x64, 0x0A, 0xB0, 0x09,
  44555. 0xCB, 0x98, 0x89, 0x2D, 0x6C, 0xFE, 0x40, 0x03,
  44556. 0x34, 0x55, 0xDE, 0xE7, 0x30, 0x33, 0xB6, 0xD5,
  44557. 0xE1, 0x9C, 0x59, 0x9F, 0x8A, 0x40, 0x0E, 0xB1,
  44558. 0x41, 0x52, 0x7D, 0xF2, 0xBB, 0xDD, 0xEF, 0x50,
  44559. 0xBB, 0xD5, 0xFB, 0x55, 0xAA, 0x5E, 0xFD, 0xB3,
  44560. 0x5D, 0x08, 0x56, 0x9B, 0x02, 0x97, 0xE2, 0x48,
  44561. 0x14, 0x69, 0xF1, 0x7B, 0x87, 0xB5, 0x08, 0x93,
  44562. 0x6A, 0x9C, 0x5C, 0x11, 0x08, 0x9A, 0xE9, 0xE4,
  44563. 0xB0, 0xCA, 0xC5, 0x74, 0x93, 0x93, 0xC8, 0x03,
  44564. 0xE4, 0x70, 0x39, 0xF5, 0x1B, 0x5C, 0xBD, 0x42,
  44565. 0xA6, 0xC9, 0xE1, 0x9E, 0xC3, 0xF6, 0x3C, 0x23,
  44566. 0x32, 0xE8, 0x77, 0x68, 0xA9, 0x60, 0xFA, 0x02,
  44567. 0x18, 0x6B, 0x7A, 0x2B, 0x02, 0x92, 0x65, 0x09,
  44568. 0x11, 0x46, 0x73, 0x04, 0x63, 0xDF, 0x8B, 0x37,
  44569. 0x5F, 0x24, 0xAA, 0x83, 0xBD, 0xD4, 0x1D, 0x13,
  44570. 0x04, 0xFC, 0x2F, 0xB5, 0x2D, 0xA1, 0x0F, 0x1F,
  44571. 0xED, 0x65, 0x29, 0x08, 0xCF, 0x8C, 0x52, 0x8F,
  44572. 0xB2, 0x62, 0x5F, 0x39, 0x3F, 0xC8, 0xC7, 0xB3,
  44573. 0x3F, 0xAD, 0x45, 0xBA, 0xD4, 0x7D, 0x38, 0x3D,
  44574. 0x2C, 0x04, 0xCF, 0x32, 0xE8, 0x07, 0x42, 0x5F,
  44575. 0x93, 0xD2, 0x35, 0x07, 0x21, 0xB7, 0xB2, 0xF5,
  44576. 0x96, 0x64, 0x8E, 0xB5, 0xE1, 0x38, 0x6B, 0x43,
  44577. 0xD1, 0x2E, 0xFD, 0xDB, 0x8F, 0xE2, 0x43, 0x6A,
  44578. 0xEC, 0x27, 0x8E, 0xE7, 0x68, 0x75, 0xB5, 0x23,
  44579. 0xC5, 0x43, 0x1D, 0x99, 0x48, 0x57, 0x73, 0xD9,
  44580. 0xAD, 0xBC, 0xD0, 0x14, 0xDD, 0x87, 0xBC, 0x68,
  44581. 0xFB, 0x82, 0xEE, 0x47, 0x4B, 0x22, 0xA5, 0x43,
  44582. 0x3A, 0xF9, 0xF9, 0x91, 0xFC, 0x34, 0xB2, 0x58,
  44583. 0x34, 0xDF, 0x13, 0x09, 0x9A, 0x46, 0xF5, 0x68,
  44584. 0xAF, 0xD1, 0x15, 0x5F, 0x32, 0x1B, 0x9D, 0xA9,
  44585. 0xE9, 0xC0, 0x63, 0x47, 0xAB, 0x3C, 0x1F, 0x59,
  44586. 0xF7, 0xEA, 0x0E, 0xD6, 0xCF, 0x47, 0xB3, 0xE9,
  44587. 0xAF, 0x65, 0x7A, 0xA7, 0xAE, 0x9B, 0xF8, 0x26,
  44588. 0x0B, 0x96, 0x9D, 0xE4, 0xAD, 0x24, 0xD3, 0xA8,
  44589. 0xCE, 0x95, 0xE5, 0x77, 0xD0, 0x44, 0x13, 0x05,
  44590. 0x06, 0x4E, 0x07, 0xB9, 0xA2, 0xC7, 0x5C, 0x3C,
  44591. 0x43, 0x80, 0x1F, 0xCE, 0xB7, 0x36, 0xFE, 0x3D,
  44592. 0x27, 0x1B, 0xE1, 0xF3, 0x6B, 0xFF, 0xC8, 0xE4,
  44593. 0x3D, 0xB1, 0x4A, 0x16, 0x24, 0x76, 0xBA, 0xEA,
  44594. 0x9D, 0x34, 0x6B, 0x52, 0x11, 0xAB, 0xD0, 0x06,
  44595. 0x08, 0xB1, 0x5A, 0xF3, 0xB5, 0xE6, 0x3A, 0x00,
  44596. 0xFF, 0x92, 0x8D, 0x1E, 0xA1, 0xA1, 0x8D, 0x75,
  44597. 0xFA, 0x7C, 0x6C, 0x1B, 0x0F, 0xB6, 0x27, 0x2E,
  44598. 0x55, 0xC3, 0xFE, 0x7E, 0x4D, 0x42, 0x05, 0xE5,
  44599. 0xCF, 0x0A, 0x1F, 0x87, 0x18, 0x30, 0x4E, 0x14,
  44600. 0xF2, 0xB4, 0xCC, 0x54, 0x3D, 0x04, 0x37, 0x34,
  44601. 0x1A, 0x4A, 0x31, 0x16, 0x01, 0xA9, 0x2E, 0x92,
  44602. 0x56, 0x6B, 0x7D, 0xFB, 0x42, 0x64, 0xE8, 0x70,
  44603. 0xE1, 0xB3, 0xA8, 0x75, 0xED, 0xBC, 0x00, 0x3A,
  44604. 0x56, 0x19, 0x70, 0xCF, 0x8A, 0x66, 0x9F, 0x3D,
  44605. 0x1B, 0x69, 0x28, 0x8C, 0xC6, 0xE3, 0x59, 0xCE,
  44606. 0x28, 0xCA, 0x65, 0xF9, 0xDA, 0xE8, 0xCE, 0xCA,
  44607. 0x74, 0x3C, 0x1C, 0x8D, 0x9F, 0xFB, 0x55, 0x08,
  44608. 0x82, 0x4A, 0x83, 0x61, 0xE3, 0x3B, 0x43, 0x1A,
  44609. 0x2E, 0x9E, 0x9A, 0x99, 0x78, 0x47, 0xD2, 0xE6,
  44610. 0xE4, 0x3C, 0x83, 0xF0, 0x22, 0x62, 0xE2, 0x94,
  44611. 0x6D, 0xF7, 0x72, 0x6D, 0x54, 0xE3, 0xE6, 0xC9,
  44612. 0xCC, 0xDB, 0x6D, 0x3F, 0x13, 0x63, 0x46, 0xC1,
  44613. 0x1E, 0x59, 0x42, 0xE7, 0xA1, 0xBF, 0x85, 0x0C,
  44614. 0x2E, 0x99, 0xB4, 0xFA, 0xCE, 0x75, 0xFD, 0x40,
  44615. 0x88, 0x69, 0x33, 0x90, 0x7C, 0xCD, 0xFC, 0x0D,
  44616. 0xE1, 0x17, 0x70, 0x20, 0x31, 0x94, 0x1D, 0x00,
  44617. 0x1E, 0x2A, 0x68, 0x3C, 0x55, 0x78, 0xFD, 0x33,
  44618. 0x54, 0x21, 0x2C, 0xEA, 0xD9, 0x69, 0xBF, 0x1C,
  44619. 0x81, 0x23, 0x9E, 0xEC, 0xC7, 0x74, 0xFD, 0x0B,
  44620. 0x88, 0x3D, 0x0E, 0xEE, 0x82, 0x4B, 0x10, 0xB8,
  44621. 0x79, 0xCF, 0x70, 0x7C, 0xB2, 0x68, 0x47, 0x45,
  44622. 0x22, 0x06, 0x1E, 0x92, 0x7B, 0x12, 0x43, 0x24,
  44623. 0x41, 0x15, 0xC6, 0x69, 0xE9, 0xEB, 0x27, 0x2B,
  44624. 0x60, 0xA6, 0x44, 0xF5, 0x19, 0xEF, 0xEC, 0x06,
  44625. 0x34, 0x08, 0xB6, 0x58, 0x47, 0x2E, 0x91, 0x61,
  44626. 0xA1, 0xF7, 0x44, 0xFD, 0x66, 0x16, 0x9F, 0x0C,
  44627. 0xAE, 0x36, 0xB4, 0x2E, 0x23, 0x79, 0xCB, 0xE8,
  44628. 0x1E, 0x6E, 0x51, 0xA0, 0xF5, 0x34, 0x15, 0x18,
  44629. 0x4E, 0xA0, 0x06, 0xB2, 0x27, 0x0B, 0x33, 0xE2,
  44630. 0xCA, 0x36, 0x4C, 0xDB, 0x33, 0xAA, 0xAE, 0x77,
  44631. 0xFF, 0xD9, 0x53, 0xDB, 0x39, 0x70, 0x4D, 0x49,
  44632. 0x0C, 0xE9, 0xAC, 0x6F, 0x2D, 0xD1, 0xC7, 0xA1,
  44633. 0x8E, 0x61, 0x74, 0x19, 0xA9, 0xAA, 0xFB, 0x37,
  44634. 0xE7, 0x23, 0x9B, 0x23, 0x6A, 0x4B, 0x74, 0xCE,
  44635. 0x63, 0xE4, 0xA0, 0xAD, 0xFF, 0x85, 0x5D, 0xCD,
  44636. 0x78, 0xF6, 0x45, 0x8E, 0x76, 0x0B, 0xFD, 0x1D,
  44637. 0x2A, 0xB9, 0x5E, 0x83, 0xC0, 0x3B, 0x6F, 0xAE,
  44638. 0x0C, 0xD3, 0xC5, 0xCE, 0xEE, 0xEE, 0x1C, 0x69,
  44639. 0x51, 0x59, 0x65, 0xA3, 0x35, 0xFC, 0xF7, 0x8E,
  44640. 0x80, 0xAA, 0x73, 0x93, 0x39, 0x54, 0x21, 0x27,
  44641. 0x17, 0x0B, 0x2C, 0x3E, 0xE1, 0x0B, 0x0E, 0xAA,
  44642. 0x09, 0x9A, 0xC7, 0xAD, 0x4C, 0xD7, 0x6E, 0x7F,
  44643. 0xE4, 0xC1, 0x16, 0x4E, 0x62, 0xF4, 0xE5, 0x80,
  44644. 0x7D, 0xC0, 0x06, 0x1F, 0x77, 0xE4, 0xA8, 0xA5,
  44645. 0x28, 0xD7, 0x10, 0x37, 0x59, 0x30, 0xCB, 0x75,
  44646. 0x5B, 0x28, 0xBF, 0xFD, 0x92, 0x8C, 0xB0, 0x7B,
  44647. 0xB4, 0xA1, 0x07, 0xCD, 0xCA, 0xBB, 0x30, 0x8A,
  44648. 0x48, 0x65, 0x0D, 0xA4, 0xE5, 0x74, 0xD9, 0xBF,
  44649. 0x56, 0x07, 0xF5, 0x83, 0xDA, 0xC3, 0x40, 0xD7,
  44650. 0x20, 0x93, 0xEF, 0xB1, 0x2B, 0xBF, 0x93, 0x41,
  44651. 0x0F, 0x1E, 0xF5, 0xC9, 0x51, 0x6C, 0x74, 0x4D,
  44652. 0x23, 0x15, 0xEC, 0x9E, 0x00, 0x0A, 0x8D, 0xC5,
  44653. 0xD1, 0x7A, 0x7B, 0x6F, 0x0D, 0x07, 0x9D, 0x78,
  44654. 0x4B, 0x6D, 0x90, 0x19, 0x3F, 0x6E, 0x3E, 0xE7,
  44655. 0xEA, 0x0E, 0xAB, 0xFC, 0x6F, 0x68, 0xC5, 0x2B,
  44656. 0x37, 0xCB, 0xCE, 0x82, 0x18, 0xAF, 0xA3, 0x67,
  44657. 0x0A, 0x80, 0xBC, 0x17, 0xB9, 0x5D, 0x7B, 0x40,
  44658. 0x53, 0x62, 0x26, 0x35, 0x8F, 0x04, 0xAC, 0xD9,
  44659. 0x2A, 0x1B, 0xE1, 0x5B, 0x26, 0xA4, 0xE5, 0x81,
  44660. 0x7E, 0x62, 0x8B, 0xA6, 0x79, 0xB3, 0x52, 0x72,
  44661. 0x03, 0xCD, 0x36, 0x32, 0x62, 0x8E, 0xC8, 0x3A,
  44662. 0xA4, 0xF2, 0x18, 0x6D, 0x2F, 0x00, 0x5D, 0x5D,
  44663. 0xFE, 0x6F, 0x7F, 0xDB, 0x4F, 0xED, 0xAC, 0x9E,
  44664. 0x89, 0xD6, 0x66, 0xE3, 0x03, 0xBB, 0x56, 0x83,
  44665. 0x06, 0x15, 0x6C, 0x56, 0xF0, 0x95, 0x34, 0xE2,
  44666. 0x5C, 0x61, 0x9A, 0xB3, 0xB9, 0x50, 0x18, 0xF4,
  44667. 0x89, 0x6B, 0xAC, 0xAA, 0x48, 0x34, 0xF6, 0xD2,
  44668. 0xD8, 0xFE, 0x14, 0xA9, 0x38, 0xAA, 0x10, 0xE5,
  44669. 0x30, 0x54, 0xF0, 0x00, 0x84, 0x44, 0xAC, 0x2E,
  44670. 0xEA, 0x25, 0x38, 0xC1, 0x23, 0x0E, 0x6A, 0x18,
  44671. 0xC9, 0x2B, 0x01, 0xD9, 0x14, 0x7F, 0xDC, 0xEF,
  44672. 0xC9, 0xC8, 0xDA, 0xC1, 0xD4, 0xEC, 0xC8, 0xCF,
  44673. 0x1F, 0x96, 0x2E, 0xFA, 0x1B, 0x8C, 0xD3, 0xC9,
  44674. 0x69, 0x00, 0x0B, 0x7E, 0xBA, 0xC5, 0x98, 0xDC,
  44675. 0xA4, 0x5E, 0xB4, 0x0B, 0xCF, 0xB1, 0x98, 0x51,
  44676. 0x48, 0x38, 0x51, 0xCF, 0x34, 0x0F, 0x3E, 0x8C,
  44677. 0x23, 0x7A, 0x9E, 0xFF, 0x1C, 0x9F, 0x21, 0xE4,
  44678. 0x97, 0x55, 0x41, 0xC6, 0x1A, 0x8F, 0xEF, 0x2A,
  44679. 0xC6, 0x05, 0x7F, 0x59, 0xDC, 0xB2, 0x3A, 0x80,
  44680. 0xE8, 0x06, 0x10, 0xCD, 0x85, 0xDB, 0x20, 0x3C,
  44681. 0x35, 0xD2, 0x4B, 0xC8, 0x2B, 0x9C, 0xD7, 0x82,
  44682. 0x46, 0xF5, 0x9F, 0xEB, 0xB2, 0x48, 0x32, 0xD7,
  44683. 0xCD, 0x66, 0x4C, 0x99, 0x51, 0x88, 0xE0, 0x28,
  44684. 0x1C, 0xD7, 0x86, 0x79, 0x00, 0xDC, 0x0D, 0xF4,
  44685. 0x4D, 0x40, 0x90, 0x80, 0x26, 0x8B, 0x79, 0xE9,
  44686. 0x56, 0x82, 0x88, 0x5F, 0x22, 0x87, 0x70, 0x73,
  44687. 0x4F, 0xA5, 0x35, 0x18, 0xEC, 0x80, 0xCE, 0x23,
  44688. 0x06, 0xCE, 0x14, 0x48, 0x52, 0x4E, 0xF0, 0x18,
  44689. 0x43, 0x03, 0xD4, 0x50, 0xC7, 0x6E, 0xA6, 0x3B,
  44690. 0x73, 0x3E, 0xB0, 0xC8, 0xDC, 0x48, 0xBF, 0x12,
  44691. 0x42, 0x3A, 0xD2, 0x38, 0x89, 0xCF, 0xCD, 0xD8,
  44692. 0x91, 0xE5, 0x95, 0x00, 0x47, 0x24, 0x0D, 0xC0,
  44693. 0xC3, 0x8A, 0xB2, 0xDB, 0xC1, 0x65, 0xB8, 0x1E,
  44694. 0x63, 0x10, 0x02, 0xEA, 0x6F, 0x74, 0x11, 0x9E,
  44695. 0x27, 0xF9, 0xF8, 0x60, 0x73, 0xBF, 0x2D, 0xF7,
  44696. 0x10, 0x81, 0x86, 0x76, 0x98, 0x0C, 0x4C, 0xB6,
  44697. 0xBD, 0x53, 0xF9, 0xA5, 0x72, 0x17, 0x78, 0xB8,
  44698. 0x9F, 0x59, 0xC6, 0x8C, 0x89, 0x35, 0xF5, 0x03,
  44699. 0x1C, 0x8A, 0x93, 0x36, 0x7D, 0x71, 0x70, 0x57,
  44700. 0xFD, 0x4D, 0x5E, 0xFA, 0xBE, 0xDE, 0x70, 0x2C,
  44701. 0xC6, 0x45, 0xEF, 0xB6, 0xD7, 0xF4, 0x4C, 0x86,
  44702. 0x0F, 0xFF, 0x76, 0x37, 0xAA, 0xD9, 0x72, 0x24,
  44703. 0x8C, 0x84, 0x4D, 0x15, 0x13, 0x39, 0x20, 0x07,
  44704. 0x38, 0x91, 0xC3, 0x13, 0x5D, 0x29, 0x78, 0x68,
  44705. 0xB7, 0xDA, 0x86, 0xF0, 0x97, 0xD8, 0xFB, 0x39,
  44706. 0xC1, 0x3B, 0xA1, 0x4C, 0x4F, 0x24, 0x75, 0x16,
  44707. 0xAB, 0xA4, 0xC5, 0xF8, 0xCE, 0x38, 0x18, 0x48,
  44708. 0x2C, 0x8F, 0xF6, 0x0C, 0xCA, 0x51, 0xFD, 0xB2,
  44709. 0xCE, 0xE9, 0x6B, 0xC1, 0x13, 0x8D, 0xC0, 0x4A,
  44710. 0x86, 0xF8, 0x57, 0x72, 0x75, 0x91, 0xAA, 0xE6,
  44711. 0xF8, 0x7C, 0x30, 0x05, 0x9B, 0x3E, 0x81, 0xB6,
  44712. 0x80, 0x55, 0xB2, 0x4E, 0xA2, 0xFA, 0x98, 0x36,
  44713. 0x86, 0x49, 0x8B, 0xFC, 0x9D, 0x9E, 0x7D, 0x59,
  44714. 0x50, 0x79, 0xEB, 0x64, 0x6E, 0x85, 0xB2, 0x12,
  44715. 0xCE, 0xDD, 0x21, 0xD0, 0x08, 0x7E, 0x0F, 0x2A,
  44716. 0xF6, 0x63, 0xEB, 0x77, 0x2A, 0x98, 0x47, 0xB1,
  44717. 0xDF, 0x21, 0x97, 0xAF, 0x13, 0x62, 0x6B, 0x89,
  44718. 0x7C, 0x24, 0x63, 0x7A, 0xF5, 0xBF, 0xE8, 0x18,
  44719. 0x16, 0xA8, 0xC9, 0x0D, 0x30, 0x48, 0x37, 0x5B,
  44720. 0x69, 0x94, 0x97, 0x14, 0x3E, 0x57, 0x71, 0x85,
  44721. 0xA7, 0x0E, 0x11, 0x50, 0x58, 0xA3, 0xA9, 0x11,
  44722. 0x2B, 0x2C, 0x43, 0x51, 0xB6, 0xCA, 0xD0, 0x09,
  44723. 0x28, 0x2B, 0x4F, 0x7C, 0xB8, 0xBD, 0xFC, 0x28,
  44724. 0x57, 0x77, 0xD7, 0xDF, 0xE8, 0xF5, 0x00, 0x00,
  44725. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  44726. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  44727. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  44728. 0x00, 0x00, 0x00, 0x03, 0x06, 0x0B, 0x11, 0x17,
  44729. 0x1F, 0x27, 0x2E
  44730. };
  44731. #endif
  44732. #endif
  44733. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  44734. ExpectNotNull(key);
  44735. if (key != NULL) {
  44736. XMEMSET(key, 0, sizeof(*key));
  44737. }
  44738. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  44739. #ifndef WOLFSSL_NO_ML_DSA_44
  44740. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  44741. ExpectIntEQ(wc_dilithium_import_public(pk_44, (word32)sizeof(pk_44), key),
  44742. 0);
  44743. ExpectIntEQ(wc_dilithium_verify_msg(sig_44, (word32)sizeof(sig_44), msg_44,
  44744. (word32)sizeof(msg_44), &res, key), 0);
  44745. ExpectIntEQ(res, 1);
  44746. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  44747. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44_DRAFT), 0);
  44748. ExpectIntEQ(wc_dilithium_import_public(pk_44_draft,
  44749. (word32)sizeof(pk_44_draft), key), 0);
  44750. ExpectIntEQ(wc_dilithium_verify_msg(sig_44_draft,
  44751. (word32)sizeof(sig_44_draft), msg_44_draft,
  44752. (word32)sizeof(msg_44_draft), &res, key), 0);
  44753. ExpectIntEQ(res, 1);
  44754. #endif
  44755. #endif
  44756. #ifndef WOLFSSL_NO_ML_DSA_65
  44757. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  44758. ExpectIntEQ(wc_dilithium_import_public(pk_65, (word32)sizeof(pk_65), key),
  44759. 0);
  44760. ExpectIntEQ(wc_dilithium_verify_msg(sig_65, (word32)sizeof(sig_65), msg_65,
  44761. (word32)sizeof(msg_65), &res, key), 0);
  44762. ExpectIntEQ(res, 1);
  44763. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  44764. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65_DRAFT), 0);
  44765. ExpectIntEQ(wc_dilithium_import_public(pk_65_draft,
  44766. (word32)sizeof(pk_65_draft), key), 0);
  44767. ExpectIntEQ(wc_dilithium_verify_msg(sig_65_draft,
  44768. (word32)sizeof(sig_65_draft), msg_65_draft,
  44769. (word32)sizeof(msg_65_draft), &res, key), 0);
  44770. ExpectIntEQ(res, 1);
  44771. #endif
  44772. #endif
  44773. #ifndef WOLFSSL_NO_ML_DSA_87
  44774. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  44775. ExpectIntEQ(wc_dilithium_import_public(pk_87, (word32)sizeof(pk_87), key),
  44776. 0);
  44777. ExpectIntEQ(wc_dilithium_verify_msg(sig_87, (word32)sizeof(sig_87), msg_87,
  44778. (word32)sizeof(msg_87), &res, key), 0);
  44779. ExpectIntEQ(res, 1);
  44780. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  44781. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87_DRAFT), 0);
  44782. ExpectIntEQ(wc_dilithium_import_public(pk_87_draft,
  44783. (word32)sizeof(pk_87_draft), key), 0);
  44784. ExpectIntEQ(wc_dilithium_verify_msg(sig_87_draft,
  44785. (word32)sizeof(sig_87_draft), msg_87_draft,
  44786. (word32)sizeof(msg_87_draft), &res, key), 0);
  44787. ExpectIntEQ(res, 1);
  44788. #endif
  44789. #endif
  44790. wc_dilithium_free(key);
  44791. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  44792. #endif
  44793. return EXPECT_RESULT();
  44794. }
  44795. /*
  44796. * Testing wc_SetSubjectBuffer
  44797. */
  44798. static int test_wc_SetSubjectBuffer(void)
  44799. {
  44800. EXPECT_DECLS;
  44801. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  44802. Cert cert;
  44803. XFILE file = XBADFILE;
  44804. byte* der = NULL;
  44805. word32 derSz;
  44806. derSz = FOURK_BUF;
  44807. ExpectNotNull(der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  44808. DYNAMIC_TYPE_TMP_BUFFER));
  44809. ExpectTrue((file = XFOPEN("./certs/ca-cert.der", "rb")) != XBADFILE);
  44810. ExpectTrue((derSz = (word32)XFREAD(der, 1, FOURK_BUF, file)) > 0);
  44811. if (file != XBADFILE)
  44812. XFCLOSE(file);
  44813. ExpectIntEQ(wc_InitCert(&cert), 0);
  44814. ExpectIntEQ(wc_SetSubjectBuffer(&cert, der, (int)derSz), 0);
  44815. ExpectIntEQ(wc_SetSubjectBuffer(NULL, der, (int)derSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44816. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44817. #endif
  44818. return EXPECT_RESULT();
  44819. } /* End test_wc_SetSubjectBuffer*/
  44820. /*
  44821. * Testing wc_SetSubjectKeyIdFromPublicKey_ex
  44822. */
  44823. static int test_wc_SetSubjectKeyIdFromPublicKey_ex(void)
  44824. {
  44825. EXPECT_DECLS;
  44826. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  44827. WC_RNG rng;
  44828. Cert cert;
  44829. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  44830. RsaKey rsaKey;
  44831. int bits = 2048;
  44832. #endif
  44833. #if defined(HAVE_ECC)
  44834. ecc_key eccKey;
  44835. int ret;
  44836. #endif
  44837. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  44838. ed25519_key ed25519Key;
  44839. #endif
  44840. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  44841. ed448_key ed448Key;
  44842. #endif
  44843. #ifndef HAVE_FIPS
  44844. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  44845. #else
  44846. ExpectIntEQ(wc_InitRng(&rng), 0);
  44847. #endif
  44848. ExpectIntEQ(wc_InitCert(&cert), 0);
  44849. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  44850. /* RSA */
  44851. XMEMSET(&rsaKey, 0, sizeof(RsaKey));
  44852. ExpectIntEQ(wc_InitRsaKey(&rsaKey, HEAP_HINT), 0);
  44853. ExpectIntEQ(MAKE_RSA_KEY(&rsaKey, bits, WC_RSA_EXPONENT, &rng), 0);
  44854. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, RSA_TYPE, &rsaKey),
  44855. 0);
  44856. DoExpectIntEQ(wc_FreeRsaKey(&rsaKey), 0);
  44857. #endif
  44858. #if defined(HAVE_ECC)
  44859. /* ECC */
  44860. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  44861. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  44862. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  44863. #if defined(WOLFSSL_ASYNC_CRYPT)
  44864. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  44865. #endif
  44866. ExpectIntEQ(ret, 0);
  44867. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ECC_TYPE, &eccKey),
  44868. 0);
  44869. DoExpectIntEQ(wc_ecc_free(&eccKey), 0);
  44870. #endif
  44871. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  44872. /* ED25519 */
  44873. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  44874. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  44875. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  44876. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED25519_TYPE,
  44877. &ed25519Key), 0);
  44878. wc_ed25519_free(&ed25519Key);
  44879. #endif
  44880. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  44881. /* ED448 */
  44882. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  44883. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  44884. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  44885. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED448_TYPE,
  44886. &ed448Key), 0);
  44887. wc_ed448_free(&ed448Key);
  44888. #endif
  44889. wc_FreeRng(&rng);
  44890. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  44891. #endif /* WOLFSSL_CERT_EXT && WOLFSSL_CERT_GEN */
  44892. return EXPECT_RESULT();
  44893. } /* End test_wc_SetSubjectKeyIdFromPublicKey_ex*/
  44894. /*
  44895. * Testing wc_SetAuthKeyIdFromPublicKey_ex
  44896. */
  44897. static int test_wc_SetAuthKeyIdFromPublicKey_ex(void)
  44898. {
  44899. EXPECT_DECLS;
  44900. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  44901. WC_RNG rng;
  44902. Cert cert;
  44903. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  44904. RsaKey rsaKey;
  44905. int bits = 2048;
  44906. #endif
  44907. #if defined(HAVE_ECC)
  44908. ecc_key eccKey;
  44909. int ret;
  44910. #endif
  44911. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  44912. ed25519_key ed25519Key;
  44913. #endif
  44914. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  44915. ed448_key ed448Key;
  44916. #endif
  44917. #ifndef HAVE_FIPS
  44918. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  44919. #else
  44920. ExpectIntEQ(wc_InitRng(&rng), 0);
  44921. #endif
  44922. ExpectIntEQ(wc_InitCert(&cert), 0);
  44923. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  44924. /* RSA */
  44925. XMEMSET(&rsaKey, 0, sizeof(RsaKey));
  44926. ExpectIntEQ(wc_InitRsaKey(&rsaKey, HEAP_HINT), 0);
  44927. ExpectIntEQ(MAKE_RSA_KEY(&rsaKey, bits, WC_RSA_EXPONENT, &rng), 0);
  44928. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, RSA_TYPE, &rsaKey), 0);
  44929. DoExpectIntEQ(wc_FreeRsaKey(&rsaKey), 0);
  44930. #endif
  44931. #if defined(HAVE_ECC)
  44932. /* ECC */
  44933. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  44934. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  44935. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  44936. #if defined(WOLFSSL_ASYNC_CRYPT)
  44937. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  44938. #endif
  44939. ExpectIntEQ(ret, 0);
  44940. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ECC_TYPE, &eccKey), 0);
  44941. DoExpectIntEQ(wc_ecc_free(&eccKey), 0);
  44942. #endif
  44943. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  44944. /* ED25519 */
  44945. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  44946. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  44947. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  44948. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED25519_TYPE,
  44949. &ed25519Key), 0);
  44950. wc_ed25519_free(&ed25519Key);
  44951. #endif
  44952. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  44953. /* ED448 */
  44954. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  44955. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  44956. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  44957. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED448_TYPE, &ed448Key),
  44958. 0);
  44959. wc_ed448_free(&ed448Key);
  44960. #endif
  44961. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  44962. #endif /* defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)*/
  44963. return EXPECT_RESULT();
  44964. } /* End test_wc_SetAuthKeyIdFromPublicKey_ex*/
  44965. /*
  44966. * Testing wc_PKCS7_New()
  44967. */
  44968. static int test_wc_PKCS7_New(void)
  44969. {
  44970. EXPECT_DECLS;
  44971. #if defined(HAVE_PKCS7)
  44972. PKCS7* pkcs7 = NULL;
  44973. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, testDevId));
  44974. wc_PKCS7_Free(pkcs7);
  44975. #endif
  44976. return EXPECT_RESULT();
  44977. } /* END test-wc_PKCS7_New */
  44978. /*
  44979. * Testing wc_PKCS7_Init()
  44980. */
  44981. static int test_wc_PKCS7_Init(void)
  44982. {
  44983. EXPECT_DECLS;
  44984. #if defined(HAVE_PKCS7)
  44985. PKCS7* pkcs7 = NULL;
  44986. void* heap = NULL;
  44987. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  44988. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  44989. /* Pass in bad args. */
  44990. ExpectIntEQ(wc_PKCS7_Init(NULL, heap, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44991. wc_PKCS7_Free(pkcs7);
  44992. #endif
  44993. return EXPECT_RESULT();
  44994. } /* END test-wc_PKCS7_Init */
  44995. /*
  44996. * Testing wc_PKCS7_InitWithCert()
  44997. */
  44998. static int test_wc_PKCS7_InitWithCert(void)
  44999. {
  45000. EXPECT_DECLS;
  45001. #if defined(HAVE_PKCS7)
  45002. PKCS7* pkcs7 = NULL;
  45003. #ifndef NO_RSA
  45004. #if defined(USE_CERT_BUFFERS_2048)
  45005. unsigned char cert[sizeof(client_cert_der_2048)];
  45006. int certSz = (int)sizeof(cert);
  45007. XMEMSET(cert, 0, certSz);
  45008. XMEMCPY(cert, client_cert_der_2048, sizeof(client_cert_der_2048));
  45009. #elif defined(USE_CERT_BUFFERS_1024)
  45010. unsigned char cert[sizeof(client_cert_der_1024)];
  45011. int certSz = (int)sizeof(cert);
  45012. XMEMSET(cert, 0, certSz);
  45013. XMEMCPY(cert, client_cert_der_1024, sizeof_client_cert_der_1024);
  45014. #else
  45015. unsigned char cert[ONEK_BUF];
  45016. XFILE fp = XBADFILE;
  45017. int certSz;
  45018. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  45019. XBADFILE);
  45020. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  45021. fp), 0);
  45022. if (fp != XBADFILE)
  45023. XFCLOSE(fp);
  45024. #endif
  45025. #elif defined(HAVE_ECC)
  45026. #if defined(USE_CERT_BUFFERS_256)
  45027. unsigned char cert[sizeof(cliecc_cert_der_256)];
  45028. int certSz = (int)sizeof(cert);
  45029. XMEMSET(cert, 0, certSz);
  45030. XMEMCPY(cert, cliecc_cert_der_256, sizeof(cliecc_cert_der_256));
  45031. #else
  45032. unsigned char cert[ONEK_BUF];
  45033. XFILE fp = XBADFILE;
  45034. int certSz;
  45035. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  45036. XBADFILE);
  45037. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof(cliecc_cert_der_256),
  45038. fp), 0);
  45039. if (fp != XBADFILE)
  45040. XFCLOSE(fp);
  45041. #endif
  45042. #else
  45043. #error PKCS7 requires ECC or RSA
  45044. #endif
  45045. #ifdef HAVE_ECC
  45046. {
  45047. /* bad test case from ZD 11011, malformed cert gives bad ECC key */
  45048. static unsigned char certWithInvalidEccKey[] = {
  45049. 0x30, 0x82, 0x03, 0x5F, 0x30, 0x82, 0x03, 0x04, 0xA0, 0x03, 0x02, 0x01,
  45050. 0x02, 0x02, 0x14, 0x61, 0xB3, 0x1E, 0x59, 0xF3, 0x68, 0x6C, 0xA4, 0x79,
  45051. 0x42, 0x83, 0x2F, 0x1A, 0x50, 0x71, 0x03, 0xBE, 0x31, 0xAA, 0x2C, 0x30,
  45052. 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02, 0x30,
  45053. 0x81, 0x8D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
  45054. 0x02, 0x55, 0x53, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x04, 0x08,
  45055. 0x0C, 0x06, 0x4F, 0x72, 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C,
  45056. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D,
  45057. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43,
  45058. 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30,
  45059. 0x0B, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74,
  45060. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77,
  45061. 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  45062. 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  45063. 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  45064. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30,
  45065. 0x1E, 0x17, 0x0D, 0x32, 0x30, 0x30, 0x36, 0x31, 0x39, 0x31, 0x33, 0x32,
  45066. 0x33, 0x34, 0x31, 0x5A, 0x17, 0x0D, 0x32, 0x33, 0x30, 0x33, 0x31, 0x36,
  45067. 0x31, 0x33, 0x32, 0x33, 0x34, 0x31, 0x5A, 0x30, 0x81, 0x8D, 0x31, 0x0B,
  45068. 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31,
  45069. 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x06, 0x4F, 0x72,
  45070. 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C, 0x06, 0x03, 0x55, 0x04,
  45071. 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D, 0x31, 0x13, 0x30, 0x11,
  45072. 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43, 0x6C, 0x69, 0x65, 0x6E,
  45073. 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03, 0x55,
  45074. 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74, 0x31, 0x18, 0x30, 0x26,
  45075. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77,
  45076. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x31, 0x1F,
  45077. 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  45078. 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77, 0x6F, 0x6C, 0x66,
  45079. 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x59, 0x30, 0x13, 0x06,
  45080. 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86,
  45081. 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07, 0x03, 0x02, 0x00, 0x04, 0x55, 0xBF,
  45082. 0xF4, 0x0F, 0x44, 0x50, 0x9A, 0x3D, 0xCE, 0x9B, 0xB7, 0xF0, 0xC5, 0x4D,
  45083. 0xF5, 0x70, 0x7B, 0xD4, 0xEC, 0x24, 0x8E, 0x19, 0x80, 0xEC, 0x5A, 0x4C,
  45084. 0xA2, 0x24, 0x03, 0x62, 0x2C, 0x9B, 0xDA, 0xEF, 0xA2, 0x35, 0x12, 0x43,
  45085. 0x84, 0x76, 0x16, 0xC6, 0x56, 0x95, 0x06, 0xCC, 0x01, 0xA9, 0xBD, 0xF6,
  45086. 0x75, 0x1A, 0x42, 0xF7, 0xBD, 0xA9, 0xB2, 0x36, 0x22, 0x5F, 0xC7, 0x5D,
  45087. 0x7F, 0xB4, 0xA3, 0x82, 0x01, 0x3E, 0x30, 0x82, 0x01, 0x3A, 0x30, 0x1D,
  45088. 0x06, 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xEB, 0xD4, 0x4B,
  45089. 0x59, 0x6B, 0x95, 0x61, 0x3F, 0x51, 0x57, 0xB6, 0x04, 0x4D, 0x89, 0x41,
  45090. 0x88, 0x44, 0x5C, 0xAB, 0xF2, 0x30, 0x81, 0xCD, 0x06, 0x03, 0x55, 0x1D,
  45091. 0x23, 0x04, 0x81, 0xC5, 0x30, 0x81, 0xC2, 0x80, 0x14, 0xEB, 0xD4, 0x4B,
  45092. 0x59, 0x72, 0x95, 0x61, 0x3F, 0x51, 0x57, 0xB6, 0x04, 0x4D, 0x89, 0x41,
  45093. 0x88, 0x44, 0x5C, 0xAB, 0xF2, 0xA1, 0x81, 0x93, 0xA4, 0x81, 0x90, 0x30,
  45094. 0x81, 0x8D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
  45095. 0x02, 0x55, 0x53, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x08, 0x08,
  45096. 0x0C, 0x06, 0x4F, 0x72, 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C,
  45097. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D,
  45098. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43,
  45099. 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30,
  45100. 0x0B, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74,
  45101. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77,
  45102. 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  45103. 0x6F, 0x6D, 0x30, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  45104. 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  45105. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x82,
  45106. 0x14, 0x61, 0xB3, 0x1E, 0x59, 0xF3, 0x68, 0x6C, 0xA4, 0x79, 0x42, 0x83,
  45107. 0x2F, 0x1A, 0x50, 0x71, 0x03, 0xBE, 0x32, 0xAA, 0x2C, 0x30, 0x0C, 0x06,
  45108. 0x03, 0x55, 0x1D, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xFF, 0x30,
  45109. 0x1C, 0x06, 0x03, 0x55, 0x1D, 0x11, 0x04, 0x15, 0x30, 0x13, 0x82, 0x0B,
  45110. 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x87,
  45111. 0x04, 0x23, 0x00, 0x00, 0x01, 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x25,
  45112. 0x04, 0x16, 0x30, 0x14, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07,
  45113. 0x03, 0x01, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02,
  45114. 0x30, 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02,
  45115. 0x03, 0x49, 0x00, 0x30, 0x46, 0x02, 0x21, 0x00, 0xE4, 0xA0, 0x23, 0x26,
  45116. 0x2B, 0x0B, 0x42, 0x0F, 0x97, 0x37, 0x6D, 0xCB, 0x14, 0x23, 0xC3, 0xC3,
  45117. 0xE6, 0x44, 0xCF, 0x5F, 0x4C, 0x26, 0xA3, 0x72, 0x64, 0x7A, 0x9C, 0xCB,
  45118. 0x64, 0xAB, 0xA6, 0xBE, 0x02, 0x21, 0x00, 0xAA, 0xC5, 0xA3, 0x50, 0xF6,
  45119. 0xF1, 0xA5, 0xDB, 0x05, 0xE0, 0x75, 0xD2, 0xF7, 0xBA, 0x49, 0x5F, 0x8F,
  45120. 0x7D, 0x1C, 0x44, 0xB1, 0x6E, 0xDF, 0xC8, 0xDA, 0x10, 0x48, 0x2D, 0x53,
  45121. 0x08, 0xA8, 0xB4
  45122. };
  45123. #endif
  45124. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45125. /* If initialization is not successful, it's free'd in init func. */
  45126. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz),
  45127. 0);
  45128. wc_PKCS7_Free(pkcs7);
  45129. pkcs7 = NULL;
  45130. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45131. /* Valid initialization usage. */
  45132. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45133. /* Pass in bad args. No need free for null checks, free at end.*/
  45134. ExpectIntEQ(wc_PKCS7_InitWithCert(NULL, (byte*)cert, (word32)certSz),
  45135. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45136. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, (word32)certSz),
  45137. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45138. #ifdef HAVE_ECC
  45139. ExpectIntLT(wc_PKCS7_InitWithCert(pkcs7, certWithInvalidEccKey,
  45140. sizeof(certWithInvalidEccKey)), 0);
  45141. }
  45142. #endif
  45143. wc_PKCS7_Free(pkcs7);
  45144. #endif
  45145. return EXPECT_RESULT();
  45146. } /* END test_wc_PKCS7_InitWithCert */
  45147. /*
  45148. * Testing wc_PKCS7_EncodeData()
  45149. */
  45150. static int test_wc_PKCS7_EncodeData(void)
  45151. {
  45152. EXPECT_DECLS;
  45153. #if defined(HAVE_PKCS7)
  45154. PKCS7* pkcs7 = NULL;
  45155. byte output[FOURK_BUF];
  45156. byte data[] = "My encoded DER cert.";
  45157. #ifndef NO_RSA
  45158. #if defined(USE_CERT_BUFFERS_2048)
  45159. unsigned char cert[sizeof(client_cert_der_2048)];
  45160. unsigned char key[sizeof(client_key_der_2048)];
  45161. int certSz = (int)sizeof(cert);
  45162. int keySz = (int)sizeof(key);
  45163. XMEMSET(cert, 0, certSz);
  45164. XMEMSET(key, 0, keySz);
  45165. XMEMCPY(cert, client_cert_der_2048, certSz);
  45166. XMEMCPY(key, client_key_der_2048, keySz);
  45167. #elif defined(USE_CERT_BUFFERS_1024)
  45168. unsigned char cert[sizeof(sizeof_client_cert_der_1024)];
  45169. unsigned char key[sizeof_client_key_der_1024];
  45170. int certSz = (int)sizeof(cert);
  45171. int keySz = (int)sizeof(key);
  45172. XMEMSET(cert, 0, certSz);
  45173. XMEMSET(key, 0, keySz);
  45174. XMEMCPY(cert, client_cert_der_1024, certSz);
  45175. XMEMCPY(key, client_key_der_1024, keySz);
  45176. #else
  45177. unsigned char cert[ONEK_BUF];
  45178. unsigned char key[ONEK_BUF];
  45179. XFILE fp = XBADFILE;
  45180. int certSz;
  45181. int keySz;
  45182. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  45183. XBADFILE);
  45184. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  45185. fp), 0);
  45186. if (fp != XBADFILE) {
  45187. XFCLOSE(fp);
  45188. fp = XBADFILE;
  45189. }
  45190. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  45191. XBADFILE);
  45192. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  45193. 0);
  45194. if (fp != XBADFILE)
  45195. XFCLOSE(fp);
  45196. #endif
  45197. #elif defined(HAVE_ECC)
  45198. #if defined(USE_CERT_BUFFERS_256)
  45199. unsigned char cert[sizeof(cliecc_cert_der_256)];
  45200. unsigned char key[sizeof(ecc_clikey_der_256)];
  45201. int certSz = (int)sizeof(cert);
  45202. int keySz = (int)sizeof(key);
  45203. XMEMSET(cert, 0, certSz);
  45204. XMEMSET(key, 0, keySz);
  45205. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  45206. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  45207. #else
  45208. unsigned char cert[ONEK_BUF];
  45209. unsigned char key[ONEK_BUF];
  45210. XFILE fp = XBADFILE;
  45211. int certSz, keySz;
  45212. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  45213. XBADFILE);
  45214. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  45215. fp), 0);
  45216. if (fp != XBADFILE) {
  45217. XFCLOSE(fp);
  45218. fp = XBADFILE;
  45219. }
  45220. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  45221. XBADFILE);
  45222. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  45223. 0);
  45224. if (fp != XBADFILE)
  45225. XFCLOSE(fp);
  45226. #endif
  45227. #endif
  45228. XMEMSET(output, 0, sizeof(output));
  45229. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45230. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45231. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz), 0);
  45232. if (pkcs7 != NULL) {
  45233. pkcs7->content = data;
  45234. pkcs7->contentSz = sizeof(data);
  45235. pkcs7->privateKey = key;
  45236. pkcs7->privateKeySz = (word32)keySz;
  45237. }
  45238. ExpectIntGT(wc_PKCS7_EncodeData(pkcs7, output, (word32)sizeof(output)), 0);
  45239. /* Test bad args. */
  45240. ExpectIntEQ(wc_PKCS7_EncodeData(NULL, output, (word32)sizeof(output)),
  45241. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45242. ExpectIntEQ(wc_PKCS7_EncodeData(pkcs7, NULL, (word32)sizeof(output)),
  45243. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45244. ExpectIntEQ(wc_PKCS7_EncodeData(pkcs7, output, 5), WC_NO_ERR_TRACE(BUFFER_E));
  45245. wc_PKCS7_Free(pkcs7);
  45246. #endif
  45247. return EXPECT_RESULT();
  45248. } /* END test_wc_PKCS7_EncodeData */
  45249. #if defined(HAVE_PKCS7) && defined(HAVE_PKCS7_RSA_RAW_SIGN_CALLBACK) && \
  45250. !defined(NO_RSA) && !defined(NO_SHA256)
  45251. /* RSA sign raw digest callback */
  45252. static int rsaSignRawDigestCb(PKCS7* pkcs7, byte* digest, word32 digestSz,
  45253. byte* out, word32 outSz, byte* privateKey,
  45254. word32 privateKeySz, int devid, int hashOID)
  45255. {
  45256. /* specific DigestInfo ASN.1 encoding prefix for a SHA2565 digest */
  45257. byte digInfoEncoding[] = {
  45258. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  45259. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  45260. 0x00, 0x04, 0x20
  45261. };
  45262. int ret;
  45263. byte digestInfo[ONEK_BUF];
  45264. byte sig[FOURK_BUF];
  45265. word32 digestInfoSz = 0;
  45266. word32 idx = 0;
  45267. RsaKey rsa;
  45268. /* SHA-256 required only for this example callback due to above
  45269. * digInfoEncoding[] */
  45270. if (pkcs7 == NULL || digest == NULL || out == NULL ||
  45271. (sizeof(digestInfo) < sizeof(digInfoEncoding) + digestSz) ||
  45272. (hashOID != SHA256h)) {
  45273. return -1;
  45274. }
  45275. /* build DigestInfo */
  45276. XMEMCPY(digestInfo, digInfoEncoding, sizeof(digInfoEncoding));
  45277. digestInfoSz += sizeof(digInfoEncoding);
  45278. XMEMCPY(digestInfo + digestInfoSz, digest, digestSz);
  45279. digestInfoSz += digestSz;
  45280. /* set up RSA key */
  45281. ret = wc_InitRsaKey_ex(&rsa, pkcs7->heap, devid);
  45282. if (ret != 0) {
  45283. return ret;
  45284. }
  45285. ret = wc_RsaPrivateKeyDecode(privateKey, &idx, &rsa, privateKeySz);
  45286. /* sign DigestInfo */
  45287. if (ret == 0) {
  45288. ret = wc_RsaSSL_Sign(digestInfo, digestInfoSz, sig, sizeof(sig),
  45289. &rsa, pkcs7->rng);
  45290. if (ret > 0) {
  45291. if (ret > (int)outSz) {
  45292. /* output buffer too small */
  45293. ret = -1;
  45294. }
  45295. else {
  45296. /* success, ret holds sig size */
  45297. XMEMCPY(out, sig, ret);
  45298. }
  45299. }
  45300. }
  45301. wc_FreeRsaKey(&rsa);
  45302. return ret;
  45303. }
  45304. #endif
  45305. #if defined(HAVE_PKCS7) && defined(ASN_BER_TO_DER)
  45306. typedef struct encodeSignedDataStream {
  45307. byte out[FOURK_BUF*3];
  45308. int idx;
  45309. word32 outIdx;
  45310. } encodeSignedDataStream;
  45311. /* content is 8k of partially created bundle */
  45312. static int GetContentCB(PKCS7* pkcs7, byte** content, void* ctx)
  45313. {
  45314. int ret = 0;
  45315. encodeSignedDataStream* strm = (encodeSignedDataStream*)ctx;
  45316. if (strm->outIdx < pkcs7->contentSz) {
  45317. ret = (pkcs7->contentSz > strm->outIdx + FOURK_BUF)?
  45318. FOURK_BUF : pkcs7->contentSz - strm->outIdx;
  45319. *content = strm->out + strm->outIdx;
  45320. strm->outIdx += ret;
  45321. }
  45322. (void)pkcs7;
  45323. return ret;
  45324. }
  45325. static int StreamOutputCB(PKCS7* pkcs7, const byte* output, word32 outputSz,
  45326. void* ctx)
  45327. {
  45328. encodeSignedDataStream* strm = (encodeSignedDataStream*)ctx;
  45329. XMEMCPY(strm->out + strm->idx, output, outputSz);
  45330. strm->idx += outputSz;
  45331. (void)pkcs7;
  45332. return 0;
  45333. }
  45334. #endif
  45335. /*
  45336. * Testing wc_PKCS7_EncodeSignedData()
  45337. */
  45338. static int test_wc_PKCS7_EncodeSignedData(void)
  45339. {
  45340. EXPECT_DECLS;
  45341. #if defined(HAVE_PKCS7)
  45342. PKCS7* pkcs7 = NULL;
  45343. WC_RNG rng;
  45344. byte output[FOURK_BUF];
  45345. byte badOut[1];
  45346. word32 outputSz = (word32)sizeof(output);
  45347. word32 badOutSz = 0;
  45348. byte data[] = "Test data to encode.";
  45349. #ifndef NO_RSA
  45350. #if defined(USE_CERT_BUFFERS_2048)
  45351. byte key[sizeof(client_key_der_2048)];
  45352. byte cert[sizeof(client_cert_der_2048)];
  45353. word32 keySz = (word32)sizeof(key);
  45354. word32 certSz = (word32)sizeof(cert);
  45355. XMEMSET(key, 0, keySz);
  45356. XMEMSET(cert, 0, certSz);
  45357. XMEMCPY(key, client_key_der_2048, keySz);
  45358. XMEMCPY(cert, client_cert_der_2048, certSz);
  45359. #elif defined(USE_CERT_BUFFERS_1024)
  45360. byte key[sizeof_client_key_der_1024];
  45361. byte cert[sizeof(sizeof_client_cert_der_1024)];
  45362. word32 keySz = (word32)sizeof(key);
  45363. word32 certSz = (word32)sizeof(cert);
  45364. XMEMSET(key, 0, keySz);
  45365. XMEMSET(cert, 0, certSz);
  45366. XMEMCPY(key, client_key_der_1024, keySz);
  45367. XMEMCPY(cert, client_cert_der_1024, certSz);
  45368. #else
  45369. unsigned char cert[ONEK_BUF];
  45370. unsigned char key[ONEK_BUF];
  45371. XFILE fp = XBADFILE;
  45372. int certSz;
  45373. int keySz;
  45374. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  45375. XBADFILE);
  45376. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  45377. fp), 0);
  45378. if (fp != XBADFILE) {
  45379. XFCLOSE(fp);
  45380. fp = XBADFILE;
  45381. }
  45382. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  45383. XBADFILE);
  45384. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  45385. 0);
  45386. if (fp != XBADFILE)
  45387. XFCLOSE(fp);
  45388. #endif
  45389. #elif defined(HAVE_ECC)
  45390. #if defined(USE_CERT_BUFFERS_256)
  45391. unsigned char cert[sizeof(cliecc_cert_der_256)];
  45392. unsigned char key[sizeof(ecc_clikey_der_256)];
  45393. int certSz = (int)sizeof(cert);
  45394. int keySz = (int)sizeof(key);
  45395. XMEMSET(cert, 0, certSz);
  45396. XMEMSET(key, 0, keySz);
  45397. XMEMCPY(cert, cliecc_cert_der_256, certSz);
  45398. XMEMCPY(key, ecc_clikey_der_256, keySz);
  45399. #else
  45400. unsigned char cert[ONEK_BUF];
  45401. unsigned char key[ONEK_BUF];
  45402. XFILE fp = XBADFILE;
  45403. int certSz;
  45404. int keySz;
  45405. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  45406. XBADFILE);
  45407. ExpectIntGT(certSz = (int)XFREAD(cert, 1, ONEK_BUF, fp), 0);
  45408. if (fp != XBADFILE) {
  45409. XFCLOSE(fp);
  45410. fp = XBADFILE;
  45411. }
  45412. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  45413. XBADFILE);
  45414. ExpectIntGT(keySz = (int)XFREAD(key, 1, ONEK_BUF, fp), 0);
  45415. if (fp != XBADFILE)
  45416. XFCLOSE(fp);
  45417. #endif
  45418. #endif
  45419. XMEMSET(&rng, 0, sizeof(WC_RNG));
  45420. XMEMSET(output, 0, outputSz);
  45421. ExpectIntEQ(wc_InitRng(&rng), 0);
  45422. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45423. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45424. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  45425. if (pkcs7 != NULL) {
  45426. pkcs7->content = data;
  45427. pkcs7->contentSz = (word32)sizeof(data);
  45428. pkcs7->privateKey = key;
  45429. pkcs7->privateKeySz = (word32)sizeof(key);
  45430. pkcs7->encryptOID = RSAk;
  45431. #ifdef NO_SHA
  45432. pkcs7->hashOID = SHA256h;
  45433. #else
  45434. pkcs7->hashOID = SHAh;
  45435. #endif
  45436. pkcs7->rng = &rng;
  45437. }
  45438. ExpectIntGT(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz), 0);
  45439. wc_PKCS7_Free(pkcs7);
  45440. pkcs7 = NULL;
  45441. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45442. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45443. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45444. #ifdef ASN_BER_TO_DER
  45445. wc_PKCS7_Free(pkcs7);
  45446. /* reinitialize and test setting stream mode */
  45447. {
  45448. int signedSz = 0;
  45449. encodeSignedDataStream strm;
  45450. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45451. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45452. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  45453. if (pkcs7 != NULL) {
  45454. pkcs7->content = data;
  45455. pkcs7->contentSz = (word32)sizeof(data);
  45456. pkcs7->privateKey = key;
  45457. pkcs7->privateKeySz = (word32)sizeof(key);
  45458. pkcs7->encryptOID = RSAk;
  45459. #ifdef NO_SHA
  45460. pkcs7->hashOID = SHA256h;
  45461. #else
  45462. pkcs7->hashOID = SHAh;
  45463. #endif
  45464. pkcs7->rng = &rng;
  45465. }
  45466. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 0);
  45467. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, NULL, NULL, NULL), 0);
  45468. ExpectIntEQ(wc_PKCS7_SetStreamMode(NULL, 1, NULL, NULL, NULL),
  45469. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45470. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 1);
  45471. ExpectIntGT(signedSz = wc_PKCS7_EncodeSignedData(pkcs7, output,
  45472. outputSz), 0);
  45473. wc_PKCS7_Free(pkcs7);
  45474. pkcs7 = NULL;
  45475. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45476. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45477. /* use exact signed buffer size since BER encoded */
  45478. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, (word32)signedSz), 0);
  45479. wc_PKCS7_Free(pkcs7);
  45480. /* now try with using callbacks for IO */
  45481. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45482. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45483. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  45484. if (pkcs7 != NULL) {
  45485. pkcs7->contentSz = FOURK_BUF*2;
  45486. pkcs7->privateKey = key;
  45487. pkcs7->privateKeySz = (word32)sizeof(key);
  45488. pkcs7->encryptOID = RSAk;
  45489. #ifdef NO_SHA
  45490. pkcs7->hashOID = SHA256h;
  45491. #else
  45492. pkcs7->hashOID = SHAh;
  45493. #endif
  45494. pkcs7->rng = &rng;
  45495. }
  45496. XMEMSET(&strm, 0, sizeof(strm));
  45497. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, GetContentCB,
  45498. StreamOutputCB, (void*)&strm), 0);
  45499. ExpectIntGT(signedSz = wc_PKCS7_EncodeSignedData(pkcs7, NULL, 0), 0);
  45500. wc_PKCS7_Free(pkcs7);
  45501. pkcs7 = NULL;
  45502. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45503. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45504. /* use exact signed buffer size since BER encoded */
  45505. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, strm.out, (word32)signedSz), 0);
  45506. }
  45507. #endif
  45508. #ifndef NO_PKCS7_STREAM
  45509. wc_PKCS7_Free(pkcs7);
  45510. pkcs7 = NULL;
  45511. {
  45512. word32 z;
  45513. int ret;
  45514. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45515. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45516. /* test for streaming mode */
  45517. ret = -1;
  45518. for (z = 0; z < outputSz && ret != 0; z++) {
  45519. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45520. if (ret < 0){
  45521. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45522. }
  45523. }
  45524. ExpectIntEQ(ret, 0);
  45525. ExpectIntNE(pkcs7->contentSz, 0);
  45526. ExpectNotNull(pkcs7->contentDynamic);
  45527. }
  45528. #endif /* !NO_PKCS7_STREAM */
  45529. /* Pass in bad args. */
  45530. ExpectIntEQ(wc_PKCS7_EncodeSignedData(NULL, output, outputSz),
  45531. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45532. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, NULL, outputSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45533. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, badOut,
  45534. badOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45535. if (pkcs7 != NULL) {
  45536. pkcs7->hashOID = 0; /* bad hashOID */
  45537. }
  45538. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz),
  45539. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45540. #if defined(HAVE_PKCS7) && defined(HAVE_PKCS7_RSA_RAW_SIGN_CALLBACK) && \
  45541. !defined(NO_RSA) && !defined(NO_SHA256)
  45542. /* test RSA sign raw digest callback, if using RSA and compiled in.
  45543. * Example callback assumes SHA-256, so only run test if compiled in. */
  45544. wc_PKCS7_Free(pkcs7);
  45545. pkcs7 = NULL;
  45546. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45547. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  45548. if (pkcs7 != NULL) {
  45549. pkcs7->content = data;
  45550. pkcs7->contentSz = (word32)sizeof(data);
  45551. pkcs7->privateKey = key;
  45552. pkcs7->privateKeySz = (word32)sizeof(key);
  45553. pkcs7->encryptOID = RSAk;
  45554. pkcs7->hashOID = SHA256h;
  45555. pkcs7->rng = &rng;
  45556. }
  45557. ExpectIntEQ(wc_PKCS7_SetRsaSignRawDigestCb(pkcs7, rsaSignRawDigestCb), 0);
  45558. ExpectIntGT(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz), 0);
  45559. #endif
  45560. wc_PKCS7_Free(pkcs7);
  45561. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  45562. #endif
  45563. return EXPECT_RESULT();
  45564. } /* END test_wc_PKCS7_EncodeSignedData */
  45565. /*
  45566. * Testing wc_PKCS7_EncodeSignedData_ex() and wc_PKCS7_VerifySignedData_ex()
  45567. */
  45568. static int test_wc_PKCS7_EncodeSignedData_ex(void)
  45569. {
  45570. EXPECT_DECLS;
  45571. #if defined(HAVE_PKCS7)
  45572. int i;
  45573. PKCS7* pkcs7 = NULL;
  45574. WC_RNG rng;
  45575. byte outputHead[FOURK_BUF/2];
  45576. byte outputFoot[FOURK_BUF/2];
  45577. word32 outputHeadSz = (word32)sizeof(outputHead);
  45578. word32 outputFootSz = (word32)sizeof(outputFoot);
  45579. byte data[FOURK_BUF];
  45580. wc_HashAlg hash;
  45581. #ifdef NO_SHA
  45582. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  45583. #else
  45584. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  45585. #endif
  45586. byte hashBuf[WC_MAX_DIGEST_SIZE];
  45587. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  45588. #ifndef NO_RSA
  45589. #if defined(USE_CERT_BUFFERS_2048)
  45590. byte key[sizeof(client_key_der_2048)];
  45591. byte cert[sizeof(client_cert_der_2048)];
  45592. word32 keySz = (word32)sizeof(key);
  45593. word32 certSz = (word32)sizeof(cert);
  45594. XMEMSET(key, 0, keySz);
  45595. XMEMSET(cert, 0, certSz);
  45596. XMEMCPY(key, client_key_der_2048, keySz);
  45597. XMEMCPY(cert, client_cert_der_2048, certSz);
  45598. #elif defined(USE_CERT_BUFFERS_1024)
  45599. byte key[sizeof_client_key_der_1024];
  45600. byte cert[sizeof(sizeof_client_cert_der_1024)];
  45601. word32 keySz = (word32)sizeof(key);
  45602. word32 certSz = (word32)sizeof(cert);
  45603. XMEMSET(key, 0, keySz);
  45604. XMEMSET(cert, 0, certSz);
  45605. XMEMCPY(key, client_key_der_1024, keySz);
  45606. XMEMCPY(cert, client_cert_der_1024, certSz);
  45607. #else
  45608. unsigned char cert[ONEK_BUF];
  45609. unsigned char key[ONEK_BUF];
  45610. XFILE fp = XBADFILE;
  45611. int certSz;
  45612. int keySz;
  45613. ExpectTure((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  45614. XBADFILE);
  45615. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  45616. fp), 0);
  45617. if (fp != XBADFILE) {
  45618. XFCLOSE(fp);
  45619. fp = XBADFILE;
  45620. }
  45621. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  45622. XBADFILE);
  45623. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  45624. 0);
  45625. if (fp != XBADFILE)
  45626. XFCLOSE(fp);
  45627. #endif
  45628. #elif defined(HAVE_ECC)
  45629. #if defined(USE_CERT_BUFFERS_256)
  45630. unsigned char cert[sizeof(cliecc_cert_der_256)];
  45631. unsigned char key[sizeof(ecc_clikey_der_256)];
  45632. int certSz = (int)sizeof(cert);
  45633. int keySz = (int)sizeof(key);
  45634. XMEMSET(cert, 0, certSz);
  45635. XMEMSET(key, 0, keySz);
  45636. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  45637. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  45638. #else
  45639. unsigned char cert[ONEK_BUF];
  45640. unsigned char key[ONEK_BUF];
  45641. XFILE fp = XBADFILE;
  45642. int certSz;
  45643. int keySz;
  45644. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  45645. XBADFILE);
  45646. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  45647. fp), 0);
  45648. if (fp != XBADFILE) {
  45649. XFCLOSE(fp);
  45650. fp = XBADFILE;
  45651. }
  45652. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  45653. XBADFILE);
  45654. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  45655. 0);
  45656. if (fp != XBADFILE)
  45657. XFCLOSE(fp);
  45658. #endif
  45659. #endif
  45660. XMEMSET(&rng, 0, sizeof(WC_RNG));
  45661. /* initialize large data with sequence */
  45662. for (i=0; i<(int)sizeof(data); i++)
  45663. data[i] = i & 0xff;
  45664. XMEMSET(outputHead, 0, outputHeadSz);
  45665. XMEMSET(outputFoot, 0, outputFootSz);
  45666. ExpectIntEQ(wc_InitRng(&rng), 0);
  45667. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45668. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45669. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  45670. if (pkcs7 != NULL) {
  45671. pkcs7->content = NULL; /* not used for ex */
  45672. pkcs7->contentSz = (word32)sizeof(data);
  45673. pkcs7->privateKey = key;
  45674. pkcs7->privateKeySz = (word32)sizeof(key);
  45675. pkcs7->encryptOID = RSAk;
  45676. #ifdef NO_SHA
  45677. pkcs7->hashOID = SHA256h;
  45678. #else
  45679. pkcs7->hashOID = SHAh;
  45680. #endif
  45681. pkcs7->rng = &rng;
  45682. }
  45683. /* calculate hash for content */
  45684. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  45685. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  45686. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  45687. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  45688. DoExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  45689. /* Perform PKCS7 sign using hash directly */
  45690. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  45691. outputHead, &outputHeadSz, outputFoot, &outputFootSz), 0);
  45692. ExpectIntGT(outputHeadSz, 0);
  45693. ExpectIntGT(outputFootSz, 0);
  45694. wc_PKCS7_Free(pkcs7);
  45695. pkcs7 = NULL;
  45696. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45697. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45698. /* required parameter even on verify when using _ex, if using outputHead
  45699. * and outputFoot */
  45700. if (pkcs7 != NULL) {
  45701. pkcs7->contentSz = (word32)sizeof(data);
  45702. }
  45703. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45704. outputHead, outputHeadSz, outputFoot, outputFootSz), 0);
  45705. wc_PKCS7_Free(pkcs7);
  45706. pkcs7 = NULL;
  45707. /* assembly complete PKCS7 sign and use normal verify */
  45708. {
  45709. byte* output = NULL;
  45710. word32 outputSz = 0;
  45711. #ifndef NO_PKCS7_STREAM
  45712. word32 z;
  45713. int ret;
  45714. #endif /* !NO_PKCS7_STREAM */
  45715. ExpectNotNull(output = (byte*)XMALLOC(
  45716. outputHeadSz + sizeof(data) + outputFootSz, HEAP_HINT,
  45717. DYNAMIC_TYPE_TMP_BUFFER));
  45718. if (output != NULL) {
  45719. XMEMCPY(&output[outputSz], outputHead, outputHeadSz);
  45720. outputSz += outputHeadSz;
  45721. XMEMCPY(&output[outputSz], data, sizeof(data));
  45722. outputSz += sizeof(data);
  45723. XMEMCPY(&output[outputSz], outputFoot, outputFootSz);
  45724. outputSz += outputFootSz;
  45725. }
  45726. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45727. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45728. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45729. #ifndef NO_PKCS7_STREAM
  45730. wc_PKCS7_Free(pkcs7);
  45731. pkcs7 = NULL;
  45732. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45733. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45734. /* test for streaming mode */
  45735. ret = -1;
  45736. for (z = 0; z < outputSz && ret != 0; z++) {
  45737. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45738. if (ret < 0){
  45739. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45740. }
  45741. }
  45742. ExpectIntEQ(ret, 0);
  45743. ExpectIntNE(pkcs7->contentSz, 0);
  45744. ExpectNotNull(pkcs7->contentDynamic);
  45745. wc_PKCS7_Free(pkcs7);
  45746. pkcs7 = NULL;
  45747. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45748. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45749. #endif /* !NO_PKCS7_STREAM */
  45750. XFREE(output, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45751. }
  45752. /* Pass in bad args. */
  45753. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(NULL, hashBuf, hashSz, outputHead,
  45754. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45755. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, NULL, hashSz, outputHead,
  45756. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45757. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, 0, outputHead,
  45758. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45759. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz, NULL,
  45760. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45761. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  45762. outputHead, NULL, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45763. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  45764. outputHead, &outputHeadSz, NULL, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45765. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  45766. outputHead, &outputHeadSz, outputFoot, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45767. if (pkcs7 != NULL) {
  45768. pkcs7->hashOID = 0; /* bad hashOID */
  45769. }
  45770. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  45771. outputHead, &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45772. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(NULL, hashBuf, hashSz, outputHead,
  45773. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45774. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, NULL, hashSz, outputHead,
  45775. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45776. #ifndef NO_PKCS7_STREAM
  45777. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, 0, outputHead,
  45778. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45779. #else
  45780. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, 0, outputHead,
  45781. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BUFFER_E));
  45782. #endif
  45783. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz, NULL,
  45784. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45785. #ifndef NO_PKCS7_STREAM
  45786. /* can pass in 0 buffer length with streaming API */
  45787. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45788. outputHead, 0, outputFoot, outputFootSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45789. #else
  45790. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45791. outputHead, 0, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45792. #endif
  45793. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45794. outputHead, outputHeadSz, NULL, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45795. #ifndef NO_PKCS7_STREAM
  45796. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45797. outputHead, outputHeadSz, outputFoot, 0), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45798. #else
  45799. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45800. outputHead, outputHeadSz, outputFoot, 0), WC_NO_ERR_TRACE(BUFFER_E));
  45801. #endif
  45802. wc_PKCS7_Free(pkcs7);
  45803. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  45804. #endif
  45805. return EXPECT_RESULT();
  45806. } /* END test_wc_PKCS7_EncodeSignedData_ex */
  45807. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  45808. /**
  45809. * Loads certs/keys from files or buffers into the argument buffers,
  45810. * helper function called by CreatePKCS7SignedData().
  45811. *
  45812. * Returns 0 on success, negative on error.
  45813. */
  45814. static int LoadPKCS7SignedDataCerts(
  45815. int useIntermediateCertChain, int pkAlgoType,
  45816. byte* intCARoot, word32* intCARootSz,
  45817. byte* intCA1, word32* intCA1Sz,
  45818. byte* intCA2, word32* intCA2Sz,
  45819. byte* cert, word32* certSz,
  45820. byte* key, word32* keySz)
  45821. {
  45822. EXPECT_DECLS;
  45823. int ret = 0;
  45824. XFILE fp = XBADFILE;
  45825. #ifndef NO_RSA
  45826. const char* intCARootRSA = "./certs/ca-cert.der";
  45827. const char* intCA1RSA = "./certs/intermediate/ca-int-cert.der";
  45828. const char* intCA2RSA = "./certs/intermediate/ca-int2-cert.der";
  45829. const char* intServCertRSA = "./certs/intermediate/server-int-cert.der";
  45830. const char* intServKeyRSA = "./certs/server-key.der";
  45831. #if !defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_1024)
  45832. const char* cli1024Cert = "./certs/1024/client-cert.der";
  45833. const char* cli1024Key = "./certs/1024/client-key.der";
  45834. #endif
  45835. #endif
  45836. #ifdef HAVE_ECC
  45837. const char* intCARootECC = "./certs/ca-ecc-cert.der";
  45838. const char* intCA1ECC = "./certs/intermediate/ca-int-ecc-cert.der";
  45839. const char* intCA2ECC = "./certs/intermediate/ca-int2-ecc-cert.der";
  45840. const char* intServCertECC = "./certs/intermediate/server-int-ecc-cert.der";
  45841. const char* intServKeyECC = "./certs/ecc-key.der";
  45842. #ifndef USE_CERT_BUFFERS_256
  45843. const char* cliEccCert = "./certs/client-ecc-cert.der";
  45844. const char* cliEccKey = "./certs/client-ecc-key.der";
  45845. #endif
  45846. #endif
  45847. if (cert == NULL || certSz == NULL || key == NULL || keySz == NULL ||
  45848. ((useIntermediateCertChain == 1) &&
  45849. (intCARoot == NULL || intCARootSz == NULL || intCA1 == NULL ||
  45850. intCA1Sz == NULL || intCA2 == NULL || intCA2Sz == NULL))) {
  45851. return BAD_FUNC_ARG;
  45852. }
  45853. /* Read/load certs and keys to use for signing based on PK type and chain */
  45854. switch (pkAlgoType) {
  45855. #ifndef NO_RSA
  45856. case RSA_TYPE:
  45857. if (useIntermediateCertChain == 1) {
  45858. ExpectTrue((fp = XFOPEN(intCARootRSA, "rb")) != XBADFILE);
  45859. *intCARootSz = (word32)XFREAD(intCARoot, 1, *intCARootSz, fp);
  45860. if (fp != XBADFILE) {
  45861. XFCLOSE(fp);
  45862. fp = XBADFILE;
  45863. }
  45864. ExpectIntGT(*intCARootSz, 0);
  45865. ExpectTrue((fp = XFOPEN(intCA1RSA, "rb")) != XBADFILE);
  45866. if (fp != XBADFILE) {
  45867. *intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
  45868. XFCLOSE(fp);
  45869. fp = XBADFILE;
  45870. }
  45871. ExpectIntGT(*intCA1Sz, 0);
  45872. ExpectTrue((fp = XFOPEN(intCA2RSA, "rb")) != XBADFILE);
  45873. if (fp != XBADFILE) {
  45874. *intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
  45875. XFCLOSE(fp);
  45876. fp = XBADFILE;
  45877. }
  45878. ExpectIntGT(*intCA2Sz, 0);
  45879. ExpectTrue((fp = XFOPEN(intServCertRSA, "rb")) != XBADFILE);
  45880. if (fp != XBADFILE) {
  45881. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  45882. XFCLOSE(fp);
  45883. fp = XBADFILE;
  45884. }
  45885. ExpectIntGT(*certSz, 0);
  45886. ExpectTrue((fp = XFOPEN(intServKeyRSA, "rb")) != XBADFILE);
  45887. if (fp != XBADFILE) {
  45888. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  45889. XFCLOSE(fp);
  45890. fp = XBADFILE;
  45891. }
  45892. ExpectIntGT(*keySz, 0);
  45893. }
  45894. else {
  45895. #if defined(USE_CERT_BUFFERS_2048)
  45896. *keySz = sizeof_client_key_der_2048;
  45897. *certSz = sizeof_client_cert_der_2048;
  45898. XMEMCPY(key, client_key_der_2048, *keySz);
  45899. XMEMCPY(cert, client_cert_der_2048, *certSz);
  45900. #elif defined(USE_CERT_BUFFERS_1024)
  45901. *keySz = sizeof_client_key_der_1024;
  45902. *certSz = sizeof_client_cert_der_1024;
  45903. XMEMCPY(key, client_key_der_1024, *keySz);
  45904. XMEMCPY(cert, client_cert_der_1024, *certSz);
  45905. #else
  45906. ExpectTrue((fp = XFOPEN(cli1024Key, "rb")) != XBADFILE);
  45907. if (fp != XBADFILE) {
  45908. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  45909. XFCLOSE(fp);
  45910. fp = XBADFILE;
  45911. }
  45912. ExpectIntGT(*keySz, 0);
  45913. ExpectTrue((fp = XFOPEN(cli1024Cert, "rb")) != XBADFILE);
  45914. if (fp != XBADFILE) {
  45915. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  45916. XFCLOSE(fp);
  45917. fp = XBADFILE;
  45918. }
  45919. ExpectIntGT(*certSz, 0);
  45920. #endif /* USE_CERT_BUFFERS_2048 */
  45921. }
  45922. break;
  45923. #endif /* !NO_RSA */
  45924. #ifdef HAVE_ECC
  45925. case ECC_TYPE:
  45926. if (useIntermediateCertChain == 1) {
  45927. ExpectTrue((fp = XFOPEN(intCARootECC, "rb")) != XBADFILE);
  45928. if (fp != XBADFILE) {
  45929. *intCARootSz = (word32)XFREAD(intCARoot, 1, *intCARootSz,
  45930. fp);
  45931. XFCLOSE(fp);
  45932. fp = XBADFILE;
  45933. }
  45934. ExpectIntGT(*intCARootSz, 0);
  45935. ExpectTrue((fp = XFOPEN(intCA1ECC, "rb")) != XBADFILE);
  45936. if (fp != XBADFILE) {
  45937. *intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
  45938. XFCLOSE(fp);
  45939. fp = XBADFILE;
  45940. }
  45941. ExpectIntGT(*intCA1Sz, 0);
  45942. ExpectTrue((fp = XFOPEN(intCA2ECC, "rb")) != XBADFILE);
  45943. if (fp != XBADFILE) {
  45944. *intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
  45945. XFCLOSE(fp);
  45946. fp = XBADFILE;
  45947. }
  45948. ExpectIntGT(*intCA2Sz, 0);
  45949. ExpectTrue((fp = XFOPEN(intServCertECC, "rb")) != XBADFILE);
  45950. if (fp != XBADFILE) {
  45951. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  45952. XFCLOSE(fp);
  45953. fp = XBADFILE;
  45954. }
  45955. ExpectIntGT(*certSz, 0);
  45956. ExpectTrue((fp = XFOPEN(intServKeyECC, "rb")) != XBADFILE);
  45957. if (fp != XBADFILE) {
  45958. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  45959. XFCLOSE(fp);
  45960. fp = XBADFILE;
  45961. }
  45962. ExpectIntGT(*keySz, 0);
  45963. }
  45964. else {
  45965. #if defined(USE_CERT_BUFFERS_256)
  45966. *keySz = sizeof_ecc_clikey_der_256;
  45967. *certSz = sizeof_cliecc_cert_der_256;
  45968. XMEMCPY(key, ecc_clikey_der_256, *keySz);
  45969. XMEMCPY(cert, cliecc_cert_der_256, *certSz);
  45970. #else
  45971. ExpectTrue((fp = XFOPEN(cliEccKey, "rb")) != XBADFILE);
  45972. if (fp != XBADFILE) {
  45973. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  45974. XFCLOSE(fp);
  45975. fp = XBADFILE;
  45976. }
  45977. ExpectIntGT(*keySz, 0);
  45978. ExpectTrue((fp = XFOPEN(cliEccCert, "rb")) != XBADFILE);
  45979. if (fp != XBADFILE) {
  45980. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  45981. XFCLOSE(fp);
  45982. fp = XBADFILE;
  45983. }
  45984. ExpectIntGT(*certSz, 0);
  45985. #endif /* USE_CERT_BUFFERS_256 */
  45986. }
  45987. break;
  45988. #endif /* HAVE_ECC */
  45989. default:
  45990. WOLFSSL_MSG("Unsupported SignedData PK type");
  45991. ret = BAD_FUNC_ARG;
  45992. break;
  45993. }
  45994. if (EXPECT_FAIL() && (ret == 0)) {
  45995. ret = BAD_FUNC_ARG;
  45996. }
  45997. return ret;
  45998. }
  45999. /**
  46000. * Creates a PKCS7/CMS SignedData bundle to use for testing.
  46001. *
  46002. * output output buffer to place SignedData
  46003. * outputSz size of output buffer
  46004. * data data buffer to be signed
  46005. * dataSz size of data buffer
  46006. * withAttribs [1/0] include attributes in SignedData message
  46007. * detachedSig [1/0] create detached signature, no content
  46008. * useIntCertChain [1/0] use certificate chain and include intermediate and
  46009. * root CAs in bundle
  46010. * pkAlgoType RSA_TYPE or ECC_TYPE, choose what key/cert type to use
  46011. *
  46012. * Return size of bundle created on success, negative on error */
  46013. static int CreatePKCS7SignedData(unsigned char* output, int outputSz,
  46014. byte* data, word32 dataSz,
  46015. int withAttribs, int detachedSig,
  46016. int useIntermediateCertChain,
  46017. int pkAlgoType)
  46018. {
  46019. EXPECT_DECLS;
  46020. int ret = 0;
  46021. WC_RNG rng;
  46022. PKCS7* pkcs7 = NULL;
  46023. static byte messageTypeOid[] =
  46024. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  46025. 0x09, 0x02 };
  46026. static byte messageType[] = { 0x13, 2, '1', '9' };
  46027. PKCS7Attrib attribs[] =
  46028. {
  46029. { messageTypeOid, sizeof(messageTypeOid), messageType,
  46030. sizeof(messageType) }
  46031. };
  46032. byte intCARoot[TWOK_BUF];
  46033. byte intCA1[TWOK_BUF];
  46034. byte intCA2[TWOK_BUF];
  46035. byte cert[TWOK_BUF];
  46036. byte key[TWOK_BUF];
  46037. word32 intCARootSz = sizeof(intCARoot);
  46038. word32 intCA1Sz = sizeof(intCA1);
  46039. word32 intCA2Sz = sizeof(intCA2);
  46040. word32 certSz = sizeof(cert);
  46041. word32 keySz = sizeof(key);
  46042. XMEMSET(intCARoot, 0, intCARootSz);
  46043. XMEMSET(intCA1, 0, intCA1Sz);
  46044. XMEMSET(intCA2, 0, intCA2Sz);
  46045. XMEMSET(cert, 0, certSz);
  46046. XMEMSET(key, 0, keySz);
  46047. ret = LoadPKCS7SignedDataCerts(useIntermediateCertChain, pkAlgoType,
  46048. intCARoot, &intCARootSz, intCA1, &intCA1Sz, intCA2, &intCA2Sz,
  46049. cert, &certSz, key, &keySz);
  46050. ExpectIntEQ(ret, 0);
  46051. XMEMSET(output, 0, outputSz);
  46052. ExpectIntEQ(wc_InitRng(&rng), 0);
  46053. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46054. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46055. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  46056. if (useIntermediateCertChain == 1) {
  46057. /* Add intermediate and root CA certs into SignedData Certs SET */
  46058. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCA2, intCA2Sz), 0);
  46059. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCA1, intCA1Sz), 0);
  46060. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCARoot, intCARootSz), 0);
  46061. }
  46062. if (pkcs7 != NULL) {
  46063. pkcs7->content = data;
  46064. pkcs7->contentSz = dataSz;
  46065. pkcs7->privateKey = key;
  46066. pkcs7->privateKeySz = (word32)sizeof(key);
  46067. if (pkAlgoType == RSA_TYPE) {
  46068. pkcs7->encryptOID = RSAk;
  46069. }
  46070. else {
  46071. pkcs7->encryptOID = ECDSAk;
  46072. }
  46073. #ifdef NO_SHA
  46074. pkcs7->hashOID = SHA256h;
  46075. #else
  46076. pkcs7->hashOID = SHAh;
  46077. #endif
  46078. pkcs7->rng = &rng;
  46079. if (withAttribs) {
  46080. /* include a signed attribute */
  46081. pkcs7->signedAttribs = attribs;
  46082. pkcs7->signedAttribsSz = (sizeof(attribs)/sizeof(PKCS7Attrib));
  46083. }
  46084. }
  46085. if (detachedSig) {
  46086. ExpectIntEQ(wc_PKCS7_SetDetached(pkcs7, 1), 0);
  46087. }
  46088. outputSz = wc_PKCS7_EncodeSignedData(pkcs7, output, (word32)outputSz);
  46089. ExpectIntGT(outputSz, 0);
  46090. wc_PKCS7_Free(pkcs7);
  46091. pkcs7 = NULL;
  46092. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46093. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46094. if (detachedSig && (pkcs7 != NULL)) {
  46095. pkcs7->content = data;
  46096. pkcs7->contentSz = dataSz;
  46097. }
  46098. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, (word32)outputSz), 0);
  46099. wc_PKCS7_Free(pkcs7);
  46100. wc_FreeRng(&rng);
  46101. if (EXPECT_FAIL()) {
  46102. outputSz = 0;
  46103. }
  46104. return outputSz;
  46105. }
  46106. #endif
  46107. /*
  46108. * Testing wc_PKCS_VerifySignedData()
  46109. */
  46110. static int test_wc_PKCS7_VerifySignedData_RSA(void)
  46111. {
  46112. EXPECT_DECLS;
  46113. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  46114. PKCS7* pkcs7 = NULL;
  46115. byte output[6000]; /* Large size needed for bundles with int CA certs */
  46116. word32 outputSz = sizeof(output);
  46117. byte data[] = "Test data to encode.";
  46118. byte badOut[1];
  46119. word32 badOutSz = 0;
  46120. byte badContent[] = "This is different content than was signed";
  46121. wc_HashAlg hash;
  46122. #ifdef NO_SHA
  46123. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  46124. #else
  46125. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  46126. #endif
  46127. byte hashBuf[WC_MAX_DIGEST_SIZE];
  46128. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  46129. #ifndef NO_RSA
  46130. PKCS7DecodedAttrib* decodedAttrib = NULL;
  46131. /* contentType OID (1.2.840.113549.1.9.3) */
  46132. static const byte contentTypeOid[] =
  46133. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xF7, 0x0d, 0x01, 0x09, 0x03 };
  46134. /* PKCS#7 DATA content type (contentType defaults to DATA) */
  46135. static const byte dataType[] =
  46136. { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01 };
  46137. /* messageDigest OID (1.2.840.113549.1.9.4) */
  46138. static const byte messageDigestOid[] =
  46139. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x04 };
  46140. #ifndef NO_ASN_TIME
  46141. /* signingTime OID () */
  46142. static const byte signingTimeOid[] =
  46143. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x05};
  46144. #endif
  46145. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  46146. int dateLength = 0;
  46147. byte dateFormat;
  46148. const byte* datePart = NULL;
  46149. struct tm timearg;
  46150. time_t now;
  46151. struct tm* nowTm = NULL;
  46152. #ifdef NEED_TMP_TIME
  46153. struct tm tmpTimeStorage;
  46154. struct tm* tmpTime = &tmpTimeStorage;
  46155. #endif
  46156. #endif /* !NO_ASN && !NO_ASN_TIME */
  46157. #ifndef NO_PKCS7_STREAM
  46158. word32 z;
  46159. int ret;
  46160. #endif /* !NO_PKCS7_STREAM */
  46161. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  46162. /* Success test with RSA certs/key */
  46163. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  46164. (word32)sizeof(data), 0, 0, 0, RSA_TYPE)), 0);
  46165. /* calculate hash for content, used later */
  46166. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  46167. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  46168. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  46169. DoExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  46170. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46171. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46172. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46173. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  46174. #ifndef NO_PKCS7_STREAM
  46175. wc_PKCS7_Free(pkcs7);
  46176. pkcs7 = NULL;
  46177. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46178. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46179. /* test for streaming */
  46180. ret = -1;
  46181. for (z = 0; z < outputSz && ret != 0; z++) {
  46182. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  46183. if (ret < 0){
  46184. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46185. }
  46186. }
  46187. ExpectIntEQ(ret, 0);
  46188. ExpectIntNE(pkcs7->contentSz, 0);
  46189. ExpectNotNull(pkcs7->contentDynamic);
  46190. #endif /* !NO_PKCS7_STREAM */
  46191. /* Check that decoded signed attributes are correct */
  46192. /* messageDigest should be first */
  46193. if (pkcs7 != NULL) {
  46194. decodedAttrib = pkcs7->decodedAttrib;
  46195. }
  46196. ExpectNotNull(decodedAttrib);
  46197. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(messageDigestOid));
  46198. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, messageDigestOid,
  46199. decodedAttrib->oidSz), 0);
  46200. /* + 2 for OCTET STRING and length bytes */
  46201. ExpectIntEQ(decodedAttrib->valueSz, hashSz + 2);
  46202. ExpectNotNull(decodedAttrib->value);
  46203. ExpectIntEQ(XMEMCMP(decodedAttrib->value + 2, hashBuf, hashSz), 0);
  46204. #ifndef NO_ASN_TIME
  46205. /* signingTime should be second */
  46206. if (decodedAttrib != NULL) {
  46207. decodedAttrib = decodedAttrib->next;
  46208. }
  46209. ExpectNotNull(decodedAttrib);
  46210. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(signingTimeOid));
  46211. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, signingTimeOid,
  46212. decodedAttrib->oidSz), 0);
  46213. ExpectIntGT(decodedAttrib->valueSz, 0);
  46214. ExpectNotNull(decodedAttrib->value);
  46215. #endif
  46216. /* Verify signingTime if ASN and time are available */
  46217. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  46218. ExpectIntEQ(wc_GetDateInfo(decodedAttrib->value, decodedAttrib->valueSz,
  46219. &datePart, &dateFormat, &dateLength), 0);
  46220. ExpectNotNull(datePart);
  46221. ExpectIntGT(dateLength, 0);
  46222. XMEMSET(&timearg, 0, sizeof(timearg));
  46223. ExpectIntEQ(wc_GetDateAsCalendarTime(datePart, dateLength, dateFormat,
  46224. &timearg), 0);
  46225. /* Get current time and compare year/month/day against attribute value */
  46226. ExpectIntEQ(wc_GetTime(&now, sizeof(now)), 0);
  46227. nowTm = (struct tm*)XGMTIME((time_t*)&now, tmpTime);
  46228. ExpectNotNull(nowTm);
  46229. ExpectIntEQ(timearg.tm_year, nowTm->tm_year);
  46230. ExpectIntEQ(timearg.tm_mon, nowTm->tm_mon);
  46231. ExpectIntEQ(timearg.tm_mday, nowTm->tm_mday);
  46232. #endif /* !NO_ASN && !NO_ASN_TIME */
  46233. /* contentType should be third */
  46234. if (decodedAttrib != NULL) {
  46235. decodedAttrib = decodedAttrib->next;
  46236. }
  46237. ExpectNotNull(decodedAttrib);
  46238. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(contentTypeOid));
  46239. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, contentTypeOid,
  46240. decodedAttrib->oidSz), 0);
  46241. ExpectIntEQ(decodedAttrib->valueSz, (int)sizeof(dataType) + 2);
  46242. ExpectNotNull(decodedAttrib->value);
  46243. ExpectIntEQ(XMEMCMP(decodedAttrib->value + 2, dataType, sizeof(dataType)),
  46244. 0);
  46245. #endif /* !NO_RSA */
  46246. /* Test bad args. */
  46247. ExpectIntEQ(wc_PKCS7_VerifySignedData(NULL, output, outputSz),
  46248. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46249. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, NULL, outputSz),
  46250. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46251. #ifndef NO_PKCS7_STREAM
  46252. /* can pass in 0 buffer length with streaming API */
  46253. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, badOut,
  46254. badOutSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46255. #else
  46256. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, badOut,
  46257. badOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46258. #endif
  46259. wc_PKCS7_Free(pkcs7);
  46260. pkcs7 = NULL;
  46261. #ifndef NO_RSA
  46262. /* Try RSA certs/key/sig first */
  46263. outputSz = sizeof(output);
  46264. XMEMSET(output, 0, outputSz);
  46265. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  46266. (word32)sizeof(data),
  46267. 1, 1, 0, RSA_TYPE)), 0);
  46268. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46269. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46270. if (pkcs7 != NULL) {
  46271. pkcs7->content = badContent;
  46272. pkcs7->contentSz = sizeof(badContent);
  46273. }
  46274. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz),
  46275. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  46276. wc_PKCS7_Free(pkcs7);
  46277. pkcs7 = NULL;
  46278. #ifndef NO_PKCS7_STREAM
  46279. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46280. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46281. if (pkcs7 != NULL) {
  46282. pkcs7->content = badContent;
  46283. pkcs7->contentSz = sizeof(badContent);
  46284. }
  46285. /* test for streaming */
  46286. ret = -1;
  46287. for (z = 0; z < outputSz && ret != 0; z++) {
  46288. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  46289. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  46290. continue;
  46291. }
  46292. else if (ret < 0) {
  46293. break;
  46294. }
  46295. }
  46296. ExpectIntEQ(ret, WC_NO_ERR_TRACE(SIG_VERIFY_E));
  46297. ExpectIntNE(pkcs7->contentSz, 0);
  46298. ExpectNotNull(pkcs7->contentDynamic);
  46299. wc_PKCS7_Free(pkcs7);
  46300. pkcs7 = NULL;
  46301. #endif /* !NO_PKCS7_STREAM */
  46302. /* Test success case with detached signature and valid content */
  46303. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46304. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46305. if (pkcs7 != NULL) {
  46306. pkcs7->content = data;
  46307. pkcs7->contentSz = sizeof(data);
  46308. }
  46309. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  46310. wc_PKCS7_Free(pkcs7);
  46311. pkcs7 = NULL;
  46312. #ifndef NO_PKCS7_STREAM
  46313. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46314. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46315. if (pkcs7 != NULL) {
  46316. pkcs7->content = data;
  46317. pkcs7->contentSz = sizeof(data);
  46318. }
  46319. /* test for streaming */
  46320. ret = -1;
  46321. for (z = 0; z < outputSz && ret != 0; z++) {
  46322. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  46323. if (ret < 0){
  46324. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46325. }
  46326. }
  46327. ExpectIntEQ(ret, 0);
  46328. ExpectIntNE(pkcs7->contentSz, 0);
  46329. ExpectNotNull(pkcs7->contentDynamic);
  46330. wc_PKCS7_Free(pkcs7);
  46331. pkcs7 = NULL;
  46332. #endif /* !NO_PKCS7_STREAM */
  46333. /* verify using pre-computed content digest only (no content) */
  46334. {
  46335. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46336. ExpectIntEQ(wc_PKCS7_Init(pkcs7, NULL, 0), 0);
  46337. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  46338. output, outputSz, NULL, 0), 0);
  46339. wc_PKCS7_Free(pkcs7);
  46340. pkcs7 = NULL;
  46341. }
  46342. #endif /* !NO_RSA */
  46343. /* Test verify on signedData containing intermediate/root CA certs */
  46344. #ifndef NO_RSA
  46345. outputSz = sizeof(output);
  46346. XMEMSET(output, 0, outputSz);
  46347. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  46348. (word32)sizeof(data),
  46349. 0, 0, 1, RSA_TYPE)), 0);
  46350. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46351. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46352. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  46353. wc_PKCS7_Free(pkcs7);
  46354. pkcs7 = NULL;
  46355. #ifndef NO_PKCS7_STREAM
  46356. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46357. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46358. /* test for streaming */
  46359. ret = -1;
  46360. for (z = 0; z < outputSz && ret != 0; z++) {
  46361. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  46362. if (ret < 0){
  46363. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46364. }
  46365. }
  46366. ExpectIntEQ(ret, 0);
  46367. ExpectIntNE(pkcs7->contentSz, 0);
  46368. ExpectNotNull(pkcs7->contentDynamic);
  46369. wc_PKCS7_Free(pkcs7);
  46370. pkcs7 = NULL;
  46371. #endif /* !NO_PKCS7_STREAM */
  46372. #endif /* !NO_RSA */
  46373. #if defined(ASN_BER_TO_DER) && !defined(NO_PKCS7_STREAM) && \
  46374. !defined(NO_FILESYSTEM)
  46375. {
  46376. XFILE signedBundle = XBADFILE;
  46377. int signedBundleSz = 0;
  46378. int chunkSz = 1;
  46379. int i, rc = 0;
  46380. byte* buf = NULL;
  46381. ExpectTrue((signedBundle = XFOPEN("./certs/test-stream-sign.p7b",
  46382. "rb")) != XBADFILE);
  46383. ExpectTrue(XFSEEK(signedBundle, 0, XSEEK_END) == 0);
  46384. ExpectIntGT(signedBundleSz = (int)XFTELL(signedBundle), 0);
  46385. ExpectTrue(XFSEEK(signedBundle, 0, XSEEK_SET) == 0);
  46386. ExpectNotNull(buf = (byte*)XMALLOC(signedBundleSz, HEAP_HINT,
  46387. DYNAMIC_TYPE_FILE));
  46388. if (buf != NULL) {
  46389. ExpectIntEQ(XFREAD(buf, 1, (size_t)signedBundleSz, signedBundle),
  46390. signedBundleSz);
  46391. }
  46392. if (signedBundle != XBADFILE) {
  46393. XFCLOSE(signedBundle);
  46394. signedBundle = XBADFILE;
  46395. }
  46396. if (buf != NULL) {
  46397. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46398. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46399. for (i = 0; i < signedBundleSz;) {
  46400. int sz = (i + chunkSz > signedBundleSz)? signedBundleSz - i :
  46401. chunkSz;
  46402. rc = wc_PKCS7_VerifySignedData(pkcs7, buf + i, (word32)sz);
  46403. if (rc < 0 ) {
  46404. if (rc == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  46405. i += sz;
  46406. continue;
  46407. }
  46408. break;
  46409. }
  46410. else {
  46411. break;
  46412. }
  46413. }
  46414. ExpectIntEQ(rc, WC_NO_ERR_TRACE(PKCS7_SIGNEEDS_CHECK));
  46415. wc_PKCS7_Free(pkcs7);
  46416. pkcs7 = NULL;
  46417. }
  46418. /* now try with malformed bundle */
  46419. if (buf != NULL) {
  46420. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46421. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46422. buf[signedBundleSz - 2] = buf[signedBundleSz - 2] + 1;
  46423. for (i = 0; i < signedBundleSz;) {
  46424. int sz = (i + chunkSz > signedBundleSz)? signedBundleSz - i :
  46425. chunkSz;
  46426. rc = wc_PKCS7_VerifySignedData(pkcs7, buf + i, (word32)sz);
  46427. if (rc < 0 ) {
  46428. if (rc == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  46429. i += sz;
  46430. continue;
  46431. }
  46432. break;
  46433. }
  46434. else {
  46435. break;
  46436. }
  46437. }
  46438. ExpectIntEQ(rc, WC_NO_ERR_TRACE(ASN_PARSE_E));
  46439. wc_PKCS7_Free(pkcs7);
  46440. pkcs7 = NULL;
  46441. }
  46442. if (buf != NULL)
  46443. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  46444. }
  46445. #endif /* BER and stream */
  46446. #endif
  46447. return EXPECT_RESULT();
  46448. } /* END test_wc_PKCS7_VerifySignedData()_RSA */
  46449. /*
  46450. * Testing wc_PKCS_VerifySignedData()
  46451. */
  46452. static int test_wc_PKCS7_VerifySignedData_ECC(void)
  46453. {
  46454. EXPECT_DECLS;
  46455. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC)
  46456. PKCS7* pkcs7 = NULL;
  46457. byte output[6000]; /* Large size needed for bundles with int CA certs */
  46458. word32 outputSz = sizeof(output);
  46459. byte data[] = "Test data to encode.";
  46460. byte badContent[] = "This is different content than was signed";
  46461. wc_HashAlg hash;
  46462. #ifndef NO_PKCS7_STREAM
  46463. word32 z;
  46464. int ret;
  46465. #endif /* !NO_PKCS7_STREAM */
  46466. #ifdef NO_SHA
  46467. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  46468. #else
  46469. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  46470. #endif
  46471. byte hashBuf[WC_MAX_DIGEST_SIZE];
  46472. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  46473. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  46474. /* Success test with ECC certs/key */
  46475. outputSz = sizeof(output);
  46476. XMEMSET(output, 0, outputSz);
  46477. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  46478. (word32)sizeof(data), 0, 0, 0, ECC_TYPE)), 0);
  46479. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46480. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46481. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46482. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  46483. wc_PKCS7_Free(pkcs7);
  46484. pkcs7 = NULL;
  46485. #ifndef NO_PKCS7_STREAM
  46486. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46487. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46488. /* test for streaming */
  46489. ret = -1;
  46490. for (z = 0; z < outputSz && ret != 0; z++) {
  46491. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  46492. if (ret < 0){
  46493. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46494. }
  46495. }
  46496. ExpectIntEQ(ret, 0);
  46497. ExpectIntNE(pkcs7->contentSz, 0);
  46498. ExpectNotNull(pkcs7->contentDynamic);
  46499. wc_PKCS7_Free(pkcs7);
  46500. pkcs7 = NULL;
  46501. #endif /* !NO_PKCS7_STREAM */
  46502. /* Invalid content should error, use detached signature so we can
  46503. * easily change content */
  46504. outputSz = sizeof(output);
  46505. XMEMSET(output, 0, outputSz);
  46506. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  46507. (word32)sizeof(data), 1, 1, 0, ECC_TYPE)), 0);
  46508. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46509. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46510. if (pkcs7 != NULL) {
  46511. pkcs7->content = badContent;
  46512. pkcs7->contentSz = sizeof(badContent);
  46513. }
  46514. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz),
  46515. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  46516. wc_PKCS7_Free(pkcs7);
  46517. pkcs7 = NULL;
  46518. #ifndef NO_PKCS7_STREAM
  46519. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46520. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46521. if (pkcs7 != NULL) {
  46522. pkcs7->content = badContent;
  46523. pkcs7->contentSz = sizeof(badContent);
  46524. }
  46525. /* test for streaming */
  46526. ret = -1;
  46527. for (z = 0; z < outputSz && ret != 0; z++) {
  46528. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  46529. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  46530. continue;
  46531. }
  46532. else if (ret < 0) {
  46533. break;
  46534. }
  46535. }
  46536. ExpectIntEQ(ret, WC_NO_ERR_TRACE(SIG_VERIFY_E));
  46537. ExpectIntNE(pkcs7->contentSz, 0);
  46538. ExpectNotNull(pkcs7->contentDynamic);
  46539. wc_PKCS7_Free(pkcs7);
  46540. pkcs7 = NULL;
  46541. #endif /* !NO_PKCS7_STREAM */
  46542. /* Test success case with detached signature and valid content */
  46543. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46544. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46545. if (pkcs7 != NULL) {
  46546. pkcs7->content = data;
  46547. pkcs7->contentSz = sizeof(data);
  46548. }
  46549. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  46550. wc_PKCS7_Free(pkcs7);
  46551. pkcs7 = NULL;
  46552. #ifndef NO_PKCS7_STREAM
  46553. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46554. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46555. if (pkcs7 != NULL) {
  46556. pkcs7->content = data;
  46557. pkcs7->contentSz = sizeof(data);
  46558. }
  46559. /* test for streaming */
  46560. ret = -1;
  46561. for (z = 0; z < outputSz && ret != 0; z++) {
  46562. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  46563. if (ret < 0){
  46564. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46565. }
  46566. }
  46567. ExpectIntEQ(ret, 0);
  46568. ExpectIntNE(pkcs7->contentSz, 0);
  46569. ExpectNotNull(pkcs7->contentDynamic);
  46570. wc_PKCS7_Free(pkcs7);
  46571. pkcs7 = NULL;
  46572. #endif /* !NO_PKCS7_STREAM */
  46573. /* verify using pre-computed content digest only (no content) */
  46574. {
  46575. /* calculate hash for content */
  46576. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  46577. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  46578. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  46579. ExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  46580. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46581. ExpectIntEQ(wc_PKCS7_Init(pkcs7, NULL, 0), 0);
  46582. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  46583. output, outputSz, NULL, 0), 0);
  46584. wc_PKCS7_Free(pkcs7);
  46585. pkcs7 = NULL;
  46586. }
  46587. /* Test verify on signedData containing intermediate/root CA certs */
  46588. outputSz = sizeof(output);
  46589. XMEMSET(output, 0, outputSz);
  46590. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  46591. (word32)sizeof(data), 0, 0, 1, ECC_TYPE)), 0);
  46592. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46593. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46594. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  46595. wc_PKCS7_Free(pkcs7);
  46596. pkcs7 = NULL;
  46597. #ifndef NO_PKCS7_STREAM
  46598. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46599. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46600. /* test for streaming */
  46601. ret = -1;
  46602. for (z = 0; z < outputSz && ret != 0; z++) {
  46603. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  46604. if (ret < 0){
  46605. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46606. }
  46607. }
  46608. ExpectIntEQ(ret, 0);
  46609. ExpectIntNE(pkcs7->contentSz, 0);
  46610. ExpectNotNull(pkcs7->contentDynamic);
  46611. wc_PKCS7_Free(pkcs7);
  46612. pkcs7 = NULL;
  46613. #endif /* !NO_PKCS7_STREAM */
  46614. #endif
  46615. return EXPECT_RESULT();
  46616. } /* END test_wc_PKCS7_VerifySignedData_ECC() */
  46617. #if defined(HAVE_PKCS7) && !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  46618. !defined(NO_AES_256)
  46619. static const byte defKey[] = {
  46620. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46621. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46622. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46623. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46624. };
  46625. static byte aesHandle[32]; /* simulated hardware key handle */
  46626. /* return 0 on success */
  46627. static int myDecryptionFunc(PKCS7* pkcs7, int encryptOID, byte* iv, int ivSz,
  46628. byte* aad, word32 aadSz, byte* authTag, word32 authTagSz,
  46629. byte* in, int inSz, byte* out, void* usrCtx)
  46630. {
  46631. int ret;
  46632. Aes aes;
  46633. if (usrCtx == NULL) {
  46634. /* no simulated handle passed in */
  46635. return -1;
  46636. }
  46637. switch (encryptOID) {
  46638. case AES256CBCb:
  46639. if (ivSz != AES_BLOCK_SIZE)
  46640. return BAD_FUNC_ARG;
  46641. break;
  46642. default:
  46643. WOLFSSL_MSG("Unsupported content cipher type for test");
  46644. return ALGO_ID_E;
  46645. };
  46646. /* simulate using handle to get key */
  46647. ret = wc_AesInit(&aes, HEAP_HINT, INVALID_DEVID);
  46648. if (ret == 0) {
  46649. ret = wc_AesSetKey(&aes, (byte*)usrCtx, 32, iv, AES_DECRYPTION);
  46650. if (ret == 0)
  46651. ret = wc_AesCbcDecrypt(&aes, out, in, (word32)inSz);
  46652. wc_AesFree(&aes);
  46653. }
  46654. (void)aad;
  46655. (void)aadSz;
  46656. (void)authTag;
  46657. (void)authTagSz;
  46658. (void)pkcs7;
  46659. return ret;
  46660. }
  46661. /* returns key size on success */
  46662. static int myCEKwrapFunc(PKCS7* pkcs7, byte* cek, word32 cekSz, byte* keyId,
  46663. word32 keyIdSz, byte* orginKey, word32 orginKeySz,
  46664. byte* out, word32 outSz, int keyWrapAlgo, int type, int direction)
  46665. {
  46666. int ret = -1;
  46667. (void)cekSz;
  46668. (void)cek;
  46669. (void)outSz;
  46670. (void)keyIdSz;
  46671. (void)direction;
  46672. (void)orginKey; /* used with KAKRI */
  46673. (void)orginKeySz;
  46674. if (out == NULL)
  46675. return BAD_FUNC_ARG;
  46676. if (keyId[0] != 0x00) {
  46677. return -1;
  46678. }
  46679. if (type != (int)PKCS7_KEKRI) {
  46680. return -1;
  46681. }
  46682. switch (keyWrapAlgo) {
  46683. case AES256_WRAP:
  46684. /* simulate setting a handle for later decryption but use key
  46685. * as handle in the test case here */
  46686. ret = wc_AesKeyUnWrap(defKey, sizeof(defKey), cek, cekSz,
  46687. aesHandle, sizeof(aesHandle), NULL);
  46688. if (ret < 0)
  46689. return ret;
  46690. ret = wc_PKCS7_SetDecodeEncryptedCtx(pkcs7, (void*)aesHandle);
  46691. if (ret < 0)
  46692. return ret;
  46693. /* return key size on success */
  46694. return sizeof(defKey);
  46695. default:
  46696. WOLFSSL_MSG("Unsupported key wrap algorithm in example");
  46697. return BAD_KEYWRAP_ALG_E;
  46698. };
  46699. }
  46700. #endif /* HAVE_PKCS7 && !NO_AES && HAVE_AES_CBC && !NO_AES_256 */
  46701. /*
  46702. * Testing wc_PKCS7_EncodeEnvelopedData()
  46703. */
  46704. static int test_wc_PKCS7_EncodeDecodeEnvelopedData(void)
  46705. {
  46706. EXPECT_DECLS;
  46707. #if defined(HAVE_PKCS7)
  46708. PKCS7* pkcs7 = NULL;
  46709. #ifdef ASN_BER_TO_DER
  46710. int encodedSz = 0;
  46711. #endif
  46712. #ifdef ECC_TIMING_RESISTANT
  46713. WC_RNG rng;
  46714. #endif
  46715. word32 tempWrd32 = 0;
  46716. byte* tmpBytePtr = NULL;
  46717. const char input[] = "Test data to encode.";
  46718. int i;
  46719. int testSz = 0;
  46720. #if !defined(NO_RSA) && (!defined(NO_AES) || (!defined(NO_SHA) || \
  46721. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  46722. byte* rsaCert = NULL;
  46723. byte* rsaPrivKey = NULL;
  46724. word32 rsaCertSz;
  46725. word32 rsaPrivKeySz;
  46726. #if !defined(NO_FILESYSTEM) && (!defined(USE_CERT_BUFFERS_1024) && \
  46727. !defined(USE_CERT_BUFFERS_2048) )
  46728. static const char* rsaClientCert = "./certs/client-cert.der";
  46729. static const char* rsaClientKey = "./certs/client-key.der";
  46730. rsaCertSz = (word32)sizeof(rsaClientCert);
  46731. rsaPrivKeySz = (word32)sizeof(rsaClientKey);
  46732. #endif
  46733. #endif
  46734. #if defined(HAVE_ECC) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  46735. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  46736. byte* eccCert = NULL;
  46737. byte* eccPrivKey = NULL;
  46738. word32 eccCertSz;
  46739. word32 eccPrivKeySz;
  46740. #if !defined(NO_FILESYSTEM) && !defined(USE_CERT_BUFFERS_256)
  46741. static const char* eccClientCert = "./certs/client-ecc-cert.der";
  46742. static const char* eccClientKey = "./certs/ecc-client-key.der";
  46743. #endif
  46744. #endif
  46745. /* Generic buffer size. */
  46746. byte output[ONEK_BUF];
  46747. byte decoded[sizeof(input)/sizeof(char)];
  46748. int decodedSz = 0;
  46749. #ifndef NO_FILESYSTEM
  46750. XFILE certFile = XBADFILE;
  46751. XFILE keyFile = XBADFILE;
  46752. #endif
  46753. #ifdef ECC_TIMING_RESISTANT
  46754. XMEMSET(&rng, 0, sizeof(WC_RNG));
  46755. #endif
  46756. #if !defined(NO_RSA) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  46757. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  46758. /* RSA certs and keys. */
  46759. #if defined(USE_CERT_BUFFERS_1024)
  46760. rsaCertSz = (word32)sizeof_client_cert_der_1024;
  46761. /* Allocate buffer space. */
  46762. ExpectNotNull(rsaCert = (byte*)XMALLOC(rsaCertSz, HEAP_HINT,
  46763. DYNAMIC_TYPE_TMP_BUFFER));
  46764. /* Init buffer. */
  46765. if (rsaCert != NULL) {
  46766. XMEMCPY(rsaCert, client_cert_der_1024, rsaCertSz);
  46767. }
  46768. rsaPrivKeySz = (word32)sizeof_client_key_der_1024;
  46769. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(rsaPrivKeySz, HEAP_HINT,
  46770. DYNAMIC_TYPE_TMP_BUFFER));
  46771. if (rsaPrivKey != NULL) {
  46772. XMEMCPY(rsaPrivKey, client_key_der_1024, rsaPrivKeySz);
  46773. }
  46774. #elif defined(USE_CERT_BUFFERS_2048)
  46775. rsaCertSz = (word32)sizeof_client_cert_der_2048;
  46776. /* Allocate buffer */
  46777. ExpectNotNull(rsaCert = (byte*)XMALLOC(rsaCertSz, HEAP_HINT,
  46778. DYNAMIC_TYPE_TMP_BUFFER));
  46779. /* Init buffer. */
  46780. if (rsaCert != NULL) {
  46781. XMEMCPY(rsaCert, client_cert_der_2048, rsaCertSz);
  46782. }
  46783. rsaPrivKeySz = (word32)sizeof_client_key_der_2048;
  46784. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(rsaPrivKeySz, HEAP_HINT,
  46785. DYNAMIC_TYPE_TMP_BUFFER));
  46786. if (rsaPrivKey != NULL) {
  46787. XMEMCPY(rsaPrivKey, client_key_der_2048, rsaPrivKeySz);
  46788. }
  46789. #else
  46790. /* File system. */
  46791. ExpectTrue((certFile = XFOPEN(rsaClientCert, "rb")) != XBADFILE);
  46792. rsaCertSz = (word32)FOURK_BUF;
  46793. ExpectNotNull(rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  46794. DYNAMIC_TYPE_TMP_BUFFER));
  46795. ExpectTrue((rsaCertSz = (word32)XFREAD(rsaCert, 1, rsaCertSz,
  46796. certFile)) > 0);
  46797. if (certFile != XBADFILE)
  46798. XFCLOSE(certFile);
  46799. ExpectTrue((keyFile = XFOPEN(rsaClientKey, "rb")) != XBADFILE);
  46800. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  46801. DYNAMIC_TYPE_TMP_BUFFER));
  46802. rsaPrivKeySz = (word32)FOURK_BUF;
  46803. ExpectTrue((rsaPrivKeySz = (word32)XFREAD(rsaPrivKey, 1, rsaPrivKeySz,
  46804. keyFile)) > 0);
  46805. if (keyFile != XBADFILE)
  46806. XFCLOSE(keyFile);
  46807. #endif /* USE_CERT_BUFFERS */
  46808. #endif /* NO_RSA */
  46809. /* ECC */
  46810. #if defined(HAVE_ECC) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  46811. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  46812. #ifdef USE_CERT_BUFFERS_256
  46813. ExpectNotNull(eccCert = (byte*)XMALLOC(TWOK_BUF, HEAP_HINT,
  46814. DYNAMIC_TYPE_TMP_BUFFER));
  46815. /* Init buffer. */
  46816. eccCertSz = (word32)sizeof_cliecc_cert_der_256;
  46817. if (eccCert != NULL) {
  46818. XMEMCPY(eccCert, cliecc_cert_der_256, eccCertSz);
  46819. }
  46820. ExpectNotNull(eccPrivKey = (byte*)XMALLOC(TWOK_BUF, HEAP_HINT,
  46821. DYNAMIC_TYPE_TMP_BUFFER));
  46822. eccPrivKeySz = (word32)sizeof_ecc_clikey_der_256;
  46823. if (eccPrivKey != NULL) {
  46824. XMEMCPY(eccPrivKey, ecc_clikey_der_256, eccPrivKeySz);
  46825. }
  46826. #else /* File system. */
  46827. ExpectTrue((certFile = XFOPEN(eccClientCert, "rb")) != XBADFILE);
  46828. eccCertSz = (word32)FOURK_BUF;
  46829. ExpectNotNull(eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  46830. DYNAMIC_TYPE_TMP_BUFFER));
  46831. ExpectTrue((eccCertSz = (word32)XFREAD(eccCert, 1, eccCertSz,
  46832. certFile)) > 0);
  46833. if (certFile != XBADFILE) {
  46834. XFCLOSE(certFile);
  46835. }
  46836. ExpectTrue((keyFile = XFOPEN(eccClientKey, "rb")) != XBADFILE);
  46837. eccPrivKeySz = (word32)FOURK_BUF;
  46838. ExpectNotNull(eccPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  46839. DYNAMIC_TYPE_TMP_BUFFER));
  46840. ExpectTrue((eccPrivKeySz = (word32)XFREAD(eccPrivKey, 1, eccPrivKeySz,
  46841. keyFile)) > 0);
  46842. if (keyFile != XBADFILE) {
  46843. XFCLOSE(keyFile);
  46844. }
  46845. #endif /* USE_CERT_BUFFERS_256 */
  46846. #endif /* END HAVE_ECC */
  46847. #ifndef NO_FILESYSTEM
  46848. /* Silence. */
  46849. (void)keyFile;
  46850. (void)certFile;
  46851. #endif
  46852. {
  46853. const pkcs7EnvelopedVector testVectors[] = {
  46854. /* DATA is a global variable defined in the makefile. */
  46855. #if !defined(NO_RSA)
  46856. #ifndef NO_DES3
  46857. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, DES3b, 0, 0,
  46858. rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  46859. #endif /* NO_DES3 */
  46860. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46861. #ifndef NO_AES_128
  46862. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES128CBCb,
  46863. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  46864. #endif
  46865. #ifndef NO_AES_192
  46866. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES192CBCb,
  46867. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  46868. #endif
  46869. #ifndef NO_AES_256
  46870. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES256CBCb,
  46871. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  46872. #endif
  46873. #endif /* NO_AES && HAVE_AES_CBC */
  46874. #endif /* NO_RSA */
  46875. #if defined(HAVE_ECC)
  46876. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46877. #if !defined(NO_SHA) && !defined(NO_AES_128)
  46878. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  46879. AES128CBCb, AES128_WRAP, dhSinglePass_stdDH_sha1kdf_scheme,
  46880. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  46881. #endif
  46882. #if !defined(NO_SHA256) && !defined(NO_AES_256)
  46883. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  46884. AES256CBCb, AES256_WRAP, dhSinglePass_stdDH_sha256kdf_scheme,
  46885. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  46886. #endif
  46887. #if defined(WOLFSSL_SHA512) && !defined(NO_AES_256)
  46888. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  46889. AES256CBCb, AES256_WRAP, dhSinglePass_stdDH_sha512kdf_scheme,
  46890. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  46891. #endif
  46892. #endif /* NO_AES && HAVE_AES_CBC*/
  46893. #endif /* END HAVE_ECC */
  46894. }; /* END pkcs7EnvelopedVector */
  46895. #ifdef ECC_TIMING_RESISTANT
  46896. ExpectIntEQ(wc_InitRng(&rng), 0);
  46897. #endif
  46898. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46899. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  46900. testSz = (int)sizeof(testVectors)/(int)sizeof(pkcs7EnvelopedVector);
  46901. for (i = 0; i < testSz; i++) {
  46902. #ifdef ASN_BER_TO_DER
  46903. encodeSignedDataStream strm;
  46904. /* test setting stream mode, the first one using IO callbacks */
  46905. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (testVectors + i)->cert,
  46906. (word32)(testVectors + i)->certSz), 0);
  46907. if (pkcs7 != NULL) {
  46908. #ifdef ECC_TIMING_RESISTANT
  46909. pkcs7->rng = &rng;
  46910. #endif
  46911. if (i != 0)
  46912. pkcs7->content = (byte*)(testVectors + i)->content;
  46913. pkcs7->contentSz = (testVectors + i)->contentSz;
  46914. pkcs7->contentOID = (testVectors + i)->contentOID;
  46915. pkcs7->encryptOID = (testVectors + i)->encryptOID;
  46916. pkcs7->keyWrapOID = (testVectors + i)->keyWrapOID;
  46917. pkcs7->keyAgreeOID = (testVectors + i)->keyAgreeOID;
  46918. pkcs7->privateKey = (testVectors + i)->privateKey;
  46919. pkcs7->privateKeySz = (testVectors + i)->privateKeySz;
  46920. }
  46921. if (i == 0) {
  46922. XMEMSET(&strm, 0, sizeof(strm));
  46923. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, GetContentCB,
  46924. StreamOutputCB, (void*)&strm), 0);
  46925. encodedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, NULL, 0);
  46926. }
  46927. else {
  46928. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, NULL, NULL, NULL), 0);
  46929. encodedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  46930. (word32)sizeof(output));
  46931. }
  46932. switch ((testVectors + i)->encryptOID) {
  46933. #ifndef NO_DES3
  46934. case DES3b:
  46935. case DESb:
  46936. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46937. break;
  46938. #endif
  46939. #ifdef HAVE_AESCCM
  46940. #ifdef WOLFSSL_AES_128
  46941. case AES128CCMb:
  46942. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46943. break;
  46944. #endif
  46945. #ifdef WOLFSSL_AES_192
  46946. case AES192CCMb:
  46947. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46948. break;
  46949. #endif
  46950. #ifdef WOLFSSL_AES_256
  46951. case AES256CCMb:
  46952. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46953. break;
  46954. #endif
  46955. #endif
  46956. default:
  46957. ExpectIntGE(encodedSz, 0);
  46958. }
  46959. if (encodedSz > 0) {
  46960. if (i == 0) {
  46961. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7,
  46962. strm.out, (word32)encodedSz, decoded,
  46963. (word32)sizeof(decoded));
  46964. }
  46965. else {
  46966. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46967. (word32)encodedSz, decoded, (word32)sizeof(decoded));
  46968. }
  46969. ExpectIntGE(decodedSz, 0);
  46970. /* Verify the size of each buffer. */
  46971. ExpectIntEQ((word32)sizeof(input)/sizeof(char), decodedSz);
  46972. }
  46973. wc_PKCS7_Free(pkcs7);
  46974. pkcs7 = NULL;
  46975. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46976. #endif
  46977. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (testVectors + i)->cert,
  46978. (word32)(testVectors + i)->certSz), 0);
  46979. if (pkcs7 != NULL) {
  46980. #ifdef ECC_TIMING_RESISTANT
  46981. pkcs7->rng = &rng;
  46982. #endif
  46983. pkcs7->content = (byte*)(testVectors + i)->content;
  46984. pkcs7->contentSz = (testVectors + i)->contentSz;
  46985. pkcs7->contentOID = (testVectors + i)->contentOID;
  46986. pkcs7->encryptOID = (testVectors + i)->encryptOID;
  46987. pkcs7->keyWrapOID = (testVectors + i)->keyWrapOID;
  46988. pkcs7->keyAgreeOID = (testVectors + i)->keyAgreeOID;
  46989. pkcs7->privateKey = (testVectors + i)->privateKey;
  46990. pkcs7->privateKeySz = (testVectors + i)->privateKeySz;
  46991. }
  46992. #ifdef ASN_BER_TO_DER
  46993. /* test without setting stream mode */
  46994. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 0);
  46995. #endif
  46996. ExpectIntGE(wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  46997. (word32)sizeof(output)), 0);
  46998. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46999. (word32)sizeof(output), decoded, (word32)sizeof(decoded));
  47000. ExpectIntGE(decodedSz, 0);
  47001. /* Verify the size of each buffer. */
  47002. ExpectIntEQ((word32)sizeof(input)/sizeof(char), decodedSz);
  47003. /* Don't free the last time through the loop. */
  47004. if (i < testSz - 1) {
  47005. wc_PKCS7_Free(pkcs7);
  47006. pkcs7 = NULL;
  47007. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47008. }
  47009. } /* END test loop. */
  47010. }
  47011. /* Test bad args. */
  47012. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(NULL, output,
  47013. (word32)sizeof(output)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47014. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(pkcs7, NULL,
  47015. (word32)sizeof(output)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47016. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(pkcs7, output, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47017. /* Decode. */
  47018. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(NULL, output,
  47019. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  47020. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47021. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47022. (word32)sizeof(output), NULL, (word32)sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47023. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47024. (word32)sizeof(output), decoded, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47025. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, NULL,
  47026. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  47027. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47028. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output, 0, decoded,
  47029. (word32)sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47030. /* Should get a return of BAD_FUNC_ARG with structure data. Order matters.*/
  47031. #if defined(HAVE_ECC) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  47032. /* only a failure for KARI test cases */
  47033. if (pkcs7 != NULL) {
  47034. tempWrd32 = pkcs7->singleCertSz;
  47035. pkcs7->singleCertSz = 0;
  47036. }
  47037. #if defined(WOLFSSL_ASN_TEMPLATE)
  47038. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47039. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  47040. WC_NO_ERR_TRACE(BUFFER_E));
  47041. #else
  47042. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47043. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  47044. WC_NO_ERR_TRACE(ASN_PARSE_E));
  47045. #endif
  47046. if (pkcs7 != NULL) {
  47047. pkcs7->singleCertSz = tempWrd32;
  47048. tmpBytePtr = pkcs7->singleCert;
  47049. pkcs7->singleCert = NULL;
  47050. }
  47051. #ifndef NO_RSA
  47052. #if defined(NO_PKCS7_STREAM)
  47053. /* when none streaming mode is used and PKCS7 is in bad state buffer error
  47054. * is returned from kari parse which gets set to bad func arg */
  47055. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47056. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  47057. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47058. #else
  47059. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47060. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  47061. WC_NO_ERR_TRACE(ASN_PARSE_E));
  47062. #endif
  47063. #endif /* !NO_RSA */
  47064. if (pkcs7 != NULL) {
  47065. pkcs7->singleCert = tmpBytePtr;
  47066. }
  47067. #endif
  47068. if (pkcs7 != NULL) {
  47069. tempWrd32 = pkcs7->privateKeySz;
  47070. pkcs7->privateKeySz = 0;
  47071. }
  47072. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47073. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  47074. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47075. if (pkcs7 != NULL) {
  47076. pkcs7->privateKeySz = tempWrd32;
  47077. tmpBytePtr = pkcs7->privateKey;
  47078. pkcs7->privateKey = NULL;
  47079. }
  47080. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47081. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  47082. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47083. if (pkcs7 != NULL) {
  47084. pkcs7->privateKey = tmpBytePtr;
  47085. }
  47086. wc_PKCS7_Free(pkcs7);
  47087. pkcs7 = NULL;
  47088. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(NO_AES_256)
  47089. /* test of decrypt callback with KEKRI enveloped data */
  47090. {
  47091. int envelopedSz = 0;
  47092. const byte keyId[] = { 0x00 };
  47093. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47094. if (pkcs7 != NULL) {
  47095. pkcs7->content = (byte*)input;
  47096. pkcs7->contentSz = (word32)(sizeof(input)/sizeof(char));
  47097. pkcs7->contentOID = DATA;
  47098. pkcs7->encryptOID = AES256CBCb;
  47099. }
  47100. ExpectIntGT(wc_PKCS7_AddRecipient_KEKRI(pkcs7, AES256_WRAP,
  47101. (byte*)defKey, sizeof(defKey), (byte*)keyId,
  47102. sizeof(keyId), NULL, NULL, 0, NULL, 0, 0), 0);
  47103. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID), 0);
  47104. ExpectIntGT((envelopedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  47105. (word32)sizeof(output))), 0);
  47106. wc_PKCS7_Free(pkcs7);
  47107. pkcs7 = NULL;
  47108. /* decode envelopedData */
  47109. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47110. ExpectIntEQ(wc_PKCS7_SetWrapCEKCb(pkcs7, myCEKwrapFunc), 0);
  47111. ExpectIntEQ(wc_PKCS7_SetDecodeEncryptedCb(pkcs7, myDecryptionFunc), 0);
  47112. ExpectIntGT((decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47113. (word32)envelopedSz, decoded, sizeof(decoded))), 0);
  47114. wc_PKCS7_Free(pkcs7);
  47115. pkcs7 = NULL;
  47116. }
  47117. #endif /* !NO_AES && !NO_AES_256 */
  47118. #ifndef NO_RSA
  47119. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47120. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47121. #endif /* NO_RSA */
  47122. #ifdef HAVE_ECC
  47123. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47124. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47125. #endif /* HAVE_ECC */
  47126. #ifdef ECC_TIMING_RESISTANT
  47127. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  47128. #endif
  47129. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DES3) && \
  47130. !defined(NO_RSA) && !defined(NO_SHA)
  47131. {
  47132. byte out[7];
  47133. byte *cms = NULL;
  47134. word32 cmsSz;
  47135. XFILE cmsFile = XBADFILE;
  47136. XMEMSET(out, 0, sizeof(out));
  47137. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47138. ExpectTrue((cmsFile = XFOPEN("./certs/test/ktri-keyid-cms.msg", "rb"))
  47139. != XBADFILE);
  47140. cmsSz = (word32)FOURK_BUF;
  47141. ExpectNotNull(cms = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  47142. DYNAMIC_TYPE_TMP_BUFFER));
  47143. ExpectTrue((cmsSz = (word32)XFREAD(cms, 1, cmsSz, cmsFile)) > 0);
  47144. if (cmsFile != XBADFILE)
  47145. XFCLOSE(cmsFile);
  47146. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)client_cert_der_2048,
  47147. sizeof_client_cert_der_2048), 0);
  47148. if (pkcs7 != NULL) {
  47149. pkcs7->privateKey = (byte*)client_key_der_2048;
  47150. pkcs7->privateKeySz = sizeof_client_key_der_2048;
  47151. }
  47152. ExpectIntLT(wc_PKCS7_DecodeEnvelopedData(pkcs7, cms, cmsSz, out,
  47153. 2), 0);
  47154. ExpectIntGT(wc_PKCS7_DecodeEnvelopedData(pkcs7, cms, cmsSz, out,
  47155. sizeof(out)), 0);
  47156. XFREE(cms, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47157. ExpectIntEQ(XMEMCMP(out, "test", 4), 0);
  47158. wc_PKCS7_Free(pkcs7);
  47159. pkcs7 = NULL;
  47160. }
  47161. #endif /* USE_CERT_BUFFERS_2048 && !NO_DES3 && !NO_RSA && !NO_SHA */
  47162. #endif /* HAVE_PKCS7 */
  47163. return EXPECT_RESULT();
  47164. } /* END test_wc_PKCS7_EncodeDecodeEnvelopedData() */
  47165. /*
  47166. * Testing wc_PKCS7_EncodeEncryptedData()
  47167. */
  47168. static int test_wc_PKCS7_EncodeEncryptedData(void)
  47169. {
  47170. EXPECT_DECLS;
  47171. #if defined(HAVE_PKCS7) && !defined(NO_PKCS7_ENCRYPTED_DATA)
  47172. PKCS7* pkcs7 = NULL;
  47173. byte* tmpBytePtr = NULL;
  47174. byte encrypted[TWOK_BUF];
  47175. byte decoded[TWOK_BUF];
  47176. word32 tmpWrd32 = 0;
  47177. int tmpInt = 0;
  47178. int decodedSz = 0;
  47179. int encryptedSz = 0;
  47180. int testSz = 0;
  47181. int i = 0;
  47182. const byte data[] = { /* Hello World */
  47183. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47184. 0x72,0x6c,0x64
  47185. };
  47186. #ifndef NO_DES3
  47187. byte desKey[] = {
  47188. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  47189. };
  47190. byte des3Key[] = {
  47191. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  47192. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  47193. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  47194. };
  47195. #endif
  47196. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47197. #ifndef NO_AES_128
  47198. byte aes128Key[] = {
  47199. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47200. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47201. };
  47202. #endif
  47203. #ifndef NO_AES_192
  47204. byte aes192Key[] = {
  47205. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47206. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47207. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47208. };
  47209. #endif
  47210. #ifndef NO_AES_256
  47211. byte aes256Key[] = {
  47212. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47213. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47214. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47215. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47216. };
  47217. #endif
  47218. #endif /* !NO_AES && HAVE_AES_CBC */
  47219. const pkcs7EncryptedVector testVectors[] =
  47220. {
  47221. #ifndef NO_DES3
  47222. {data, (word32)sizeof(data), DATA, DES3b, des3Key, sizeof(des3Key)},
  47223. {data, (word32)sizeof(data), DATA, DESb, desKey, sizeof(desKey)},
  47224. #endif /* !NO_DES3 */
  47225. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47226. #ifndef NO_AES_128
  47227. {data, (word32)sizeof(data), DATA, AES128CBCb, aes128Key,
  47228. sizeof(aes128Key)},
  47229. #endif
  47230. #ifndef NO_AES_192
  47231. {data, (word32)sizeof(data), DATA, AES192CBCb, aes192Key,
  47232. sizeof(aes192Key)},
  47233. #endif
  47234. #ifndef NO_AES_256
  47235. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  47236. sizeof(aes256Key)},
  47237. #endif
  47238. #endif /* !NO_AES && HAVE_AES_CBC */
  47239. };
  47240. testSz = sizeof(testVectors) / sizeof(pkcs7EncryptedVector);
  47241. for (i = 0; i < testSz; i++) {
  47242. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47243. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  47244. if (pkcs7 != NULL) {
  47245. pkcs7->content = (byte*)testVectors[i].content;
  47246. pkcs7->contentSz = testVectors[i].contentSz;
  47247. pkcs7->contentOID = testVectors[i].contentOID;
  47248. pkcs7->encryptOID = testVectors[i].encryptOID;
  47249. pkcs7->encryptionKey = testVectors[i].encryptionKey;
  47250. pkcs7->encryptionKeySz = testVectors[i].encryptionKeySz;
  47251. pkcs7->heap = HEAP_HINT;
  47252. }
  47253. /* encode encryptedData */
  47254. ExpectIntGT(encryptedSz = wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47255. sizeof(encrypted)), 0);
  47256. /* Decode encryptedData */
  47257. ExpectIntGT(decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted,
  47258. (word32)encryptedSz, decoded, sizeof(decoded)), 0);
  47259. ExpectIntEQ(XMEMCMP(decoded, data, decodedSz), 0);
  47260. /* Keep values for last itr. */
  47261. if (i < testSz - 1) {
  47262. wc_PKCS7_Free(pkcs7);
  47263. pkcs7 = NULL;
  47264. }
  47265. }
  47266. if (pkcs7 == NULL || testSz == 0) {
  47267. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47268. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  47269. }
  47270. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(NULL, encrypted,
  47271. sizeof(encrypted)),WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47272. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, NULL,
  47273. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47274. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47275. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47276. /* Testing the struct. */
  47277. if (pkcs7 != NULL) {
  47278. tmpBytePtr = pkcs7->content;
  47279. pkcs7->content = NULL;
  47280. }
  47281. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47282. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47283. if (pkcs7 != NULL) {
  47284. pkcs7->content = tmpBytePtr;
  47285. tmpWrd32 = pkcs7->contentSz;
  47286. pkcs7->contentSz = 0;
  47287. }
  47288. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47289. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47290. if (pkcs7 != NULL) {
  47291. pkcs7->contentSz = tmpWrd32;
  47292. tmpInt = pkcs7->encryptOID;
  47293. pkcs7->encryptOID = 0;
  47294. }
  47295. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47296. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47297. if (pkcs7 != NULL) {
  47298. pkcs7->encryptOID = tmpInt;
  47299. tmpBytePtr = pkcs7->encryptionKey;
  47300. pkcs7->encryptionKey = NULL;
  47301. }
  47302. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47303. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47304. if (pkcs7 != NULL) {
  47305. pkcs7->encryptionKey = tmpBytePtr;
  47306. tmpWrd32 = pkcs7->encryptionKeySz;
  47307. pkcs7->encryptionKeySz = 0;
  47308. }
  47309. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47310. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47311. if (pkcs7 != NULL) {
  47312. pkcs7->encryptionKeySz = tmpWrd32;
  47313. }
  47314. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(NULL, encrypted, (word32)encryptedSz,
  47315. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47316. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, NULL, (word32)encryptedSz,
  47317. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47318. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, 0,
  47319. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47320. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  47321. NULL, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47322. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  47323. decoded, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47324. /* Test struct fields */
  47325. if (pkcs7 != NULL) {
  47326. tmpBytePtr = pkcs7->encryptionKey;
  47327. pkcs7->encryptionKey = NULL;
  47328. }
  47329. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  47330. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47331. if (pkcs7 != NULL) {
  47332. pkcs7->encryptionKey = tmpBytePtr;
  47333. pkcs7->encryptionKeySz = 0;
  47334. }
  47335. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  47336. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47337. wc_PKCS7_Free(pkcs7);
  47338. #endif
  47339. return EXPECT_RESULT();
  47340. } /* END test_wc_PKCS7_EncodeEncryptedData() */
  47341. /*
  47342. * Testing wc_PKCS7_Degenerate()
  47343. */
  47344. static int test_wc_PKCS7_Degenerate(void)
  47345. {
  47346. EXPECT_DECLS;
  47347. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  47348. PKCS7* pkcs7 = NULL;
  47349. char fName[] = "./certs/test-degenerate.p7b";
  47350. XFILE f = XBADFILE;
  47351. byte der[4096];
  47352. word32 derSz = 0;
  47353. #ifndef NO_PKCS7_STREAM
  47354. word32 z;
  47355. int ret;
  47356. #endif /* !NO_PKCS7_STREAM */
  47357. ExpectTrue((f = XFOPEN(fName, "rb")) != XBADFILE);
  47358. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  47359. if (f != XBADFILE)
  47360. XFCLOSE(f);
  47361. /* test degenerate success */
  47362. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47363. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  47364. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47365. #ifndef NO_RSA
  47366. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  47367. #ifndef NO_PKCS7_STREAM
  47368. wc_PKCS7_Free(pkcs7);
  47369. pkcs7 = NULL;
  47370. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47371. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  47372. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47373. /* test for streaming */
  47374. ret = -1;
  47375. for (z = 0; z < derSz && ret != 0; z++) {
  47376. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  47377. if (ret < 0){
  47378. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  47379. }
  47380. }
  47381. ExpectIntEQ(ret, 0);
  47382. #endif /* !NO_PKCS7_STREAM */
  47383. #else
  47384. ExpectIntNE(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  47385. #endif /* NO_RSA */
  47386. wc_PKCS7_Free(pkcs7);
  47387. pkcs7 = NULL;
  47388. /* test with turning off degenerate cases */
  47389. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47390. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  47391. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47392. wc_PKCS7_AllowDegenerate(pkcs7, 0); /* override allowing degenerate case */
  47393. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz),
  47394. WC_NO_ERR_TRACE(PKCS7_NO_SIGNER_E));
  47395. #ifndef NO_PKCS7_STREAM
  47396. wc_PKCS7_Free(pkcs7);
  47397. pkcs7 = NULL;
  47398. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47399. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  47400. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47401. wc_PKCS7_AllowDegenerate(pkcs7, 0); /* override allowing degenerate case */
  47402. /* test for streaming */
  47403. ret = -1;
  47404. for (z = 0; z < derSz && ret != 0; z++) {
  47405. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  47406. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  47407. continue;
  47408. }
  47409. else
  47410. break;
  47411. }
  47412. ExpectIntEQ(ret, WC_NO_ERR_TRACE(PKCS7_NO_SIGNER_E));
  47413. #endif /* !NO_PKCS7_STREAM */
  47414. wc_PKCS7_Free(pkcs7);
  47415. #endif
  47416. return EXPECT_RESULT();
  47417. } /* END test_wc_PKCS7_Degenerate() */
  47418. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  47419. defined(ASN_BER_TO_DER) && !defined(NO_DES3) && !defined(NO_SHA)
  47420. static byte berContent[] = {
  47421. 0x30, 0x80, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  47422. 0xF7, 0x0D, 0x01, 0x07, 0x03, 0xA0, 0x80, 0x30,
  47423. 0x80, 0x02, 0x01, 0x00, 0x31, 0x82, 0x01, 0x48,
  47424. 0x30, 0x82, 0x01, 0x44, 0x02, 0x01, 0x00, 0x30,
  47425. 0x81, 0xAC, 0x30, 0x81, 0x9E, 0x31, 0x0B, 0x30,
  47426. 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  47427. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03,
  47428. 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E,
  47429. 0x74, 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E,
  47430. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42,
  47431. 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x15,
  47432. 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C,
  47433. 0x0C, 0x77, 0x6F, 0x6C, 0x66, 0x53, 0x53, 0x4C,
  47434. 0x5F, 0x31, 0x30, 0x32, 0x34, 0x31, 0x19, 0x30,
  47435. 0x17, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10,
  47436. 0x50, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x6D,
  47437. 0x69, 0x6E, 0x67, 0x2D, 0x31, 0x30, 0x32, 0x34,
  47438. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04,
  47439. 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77,
  47440. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  47441. 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09,
  47442. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  47443. 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  47444. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E,
  47445. 0x63, 0x6F, 0x6D, 0x02, 0x09, 0x00, 0xBB, 0xD3,
  47446. 0x10, 0x03, 0xE6, 0x9D, 0x28, 0x03, 0x30, 0x0D,
  47447. 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  47448. 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x81, 0x80,
  47449. 0x2F, 0xF9, 0x77, 0x4F, 0x04, 0x5C, 0x16, 0x62,
  47450. 0xF0, 0x77, 0x8D, 0x95, 0x4C, 0xB1, 0x44, 0x9A,
  47451. 0x8C, 0x3C, 0x8C, 0xE4, 0xD1, 0xC1, 0x14, 0x72,
  47452. 0xD0, 0x4A, 0x1A, 0x94, 0x27, 0x0F, 0xAA, 0xE8,
  47453. 0xD0, 0xA2, 0xE7, 0xED, 0x4C, 0x7F, 0x0F, 0xC7,
  47454. 0x1B, 0xFB, 0x81, 0x0E, 0x76, 0x8F, 0xDD, 0x32,
  47455. 0x11, 0x68, 0xA0, 0x13, 0xD2, 0x8D, 0x95, 0xEF,
  47456. 0x80, 0x53, 0x81, 0x0E, 0x1F, 0xC8, 0xD6, 0x76,
  47457. 0x5C, 0x31, 0xD3, 0x77, 0x33, 0x29, 0xA6, 0x1A,
  47458. 0xD3, 0xC6, 0x14, 0x36, 0xCA, 0x8E, 0x7D, 0x72,
  47459. 0xA0, 0x29, 0x4C, 0xC7, 0x3A, 0xAF, 0xFE, 0xF7,
  47460. 0xFC, 0xD7, 0xE2, 0x8F, 0x6A, 0x20, 0x46, 0x09,
  47461. 0x40, 0x22, 0x2D, 0x79, 0x38, 0x11, 0xB1, 0x4A,
  47462. 0xE3, 0x48, 0xE8, 0x10, 0x37, 0xA0, 0x22, 0xF7,
  47463. 0xB4, 0x79, 0xD1, 0xA9, 0x3D, 0xC2, 0xAB, 0x37,
  47464. 0xAE, 0x82, 0x68, 0x1A, 0x16, 0xEF, 0x33, 0x0C,
  47465. 0x30, 0x80, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  47466. 0xF7, 0x0D, 0x01, 0x07, 0x01, 0x30, 0x14, 0x06,
  47467. 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x03,
  47468. 0x07, 0x04, 0x08, 0xAD, 0xD0, 0x38, 0x9B, 0x16,
  47469. 0x4B, 0x7F, 0x99, 0xA0, 0x80, 0x04, 0x82, 0x03,
  47470. 0xE8, 0x6D, 0x48, 0xFB, 0x8A, 0xBD, 0xED, 0x6C,
  47471. 0xCD, 0xC6, 0x48, 0xFD, 0xB7, 0xB0, 0x7C, 0x86,
  47472. 0x2C, 0x8D, 0xF0, 0x23, 0x12, 0xD8, 0xA3, 0x2A,
  47473. 0x21, 0x6F, 0x8B, 0x75, 0xBB, 0x47, 0x7F, 0xC9,
  47474. 0xBA, 0xBA, 0xFF, 0x91, 0x09, 0x01, 0x7A, 0x5C,
  47475. 0x96, 0x02, 0xB8, 0x8E, 0xF8, 0x67, 0x7E, 0x8F,
  47476. 0xF9, 0x51, 0x0E, 0xFF, 0x8E, 0xE2, 0x61, 0xC0,
  47477. 0xDF, 0xFA, 0xE2, 0x4C, 0x50, 0x90, 0xAE, 0xA1,
  47478. 0x15, 0x38, 0x3D, 0xBE, 0x88, 0xD7, 0x57, 0xC0,
  47479. 0x11, 0x44, 0xA2, 0x61, 0x05, 0x49, 0x6A, 0x94,
  47480. 0x04, 0x10, 0xD9, 0xC2, 0x2D, 0x15, 0x20, 0x0D,
  47481. 0xBD, 0xA2, 0xEF, 0xE4, 0x68, 0xFA, 0x39, 0x75,
  47482. 0x7E, 0xD8, 0x64, 0x44, 0xCB, 0xE0, 0x00, 0x6D,
  47483. 0x57, 0x4E, 0x8A, 0x17, 0xA9, 0x83, 0x6C, 0x7F,
  47484. 0xFE, 0x01, 0xEE, 0xDE, 0x99, 0x3A, 0xB2, 0xFF,
  47485. 0xD3, 0x72, 0x78, 0xBA, 0xF1, 0x23, 0x54, 0x48,
  47486. 0x02, 0xD8, 0x38, 0xA9, 0x54, 0xE5, 0x4A, 0x81,
  47487. 0xB9, 0xC0, 0x67, 0xB2, 0x7D, 0x3C, 0x6F, 0xCE,
  47488. 0xA4, 0xDD, 0x34, 0x5F, 0x60, 0xB1, 0xA3, 0x7A,
  47489. 0xE4, 0x43, 0xF2, 0x89, 0x64, 0x35, 0x09, 0x32,
  47490. 0x51, 0xFB, 0x5C, 0x67, 0x0C, 0x3B, 0xFC, 0x36,
  47491. 0x6B, 0x37, 0x43, 0x6C, 0x03, 0xCD, 0x44, 0xC7,
  47492. 0x2B, 0x62, 0xD6, 0xD1, 0xF4, 0x07, 0x7B, 0x19,
  47493. 0x91, 0xF0, 0xD7, 0xF5, 0x54, 0xBC, 0x0F, 0x42,
  47494. 0x6B, 0x69, 0xF7, 0xA3, 0xC8, 0xEE, 0xB9, 0x7A,
  47495. 0x9E, 0x3D, 0xDF, 0x53, 0x47, 0xF7, 0x50, 0x67,
  47496. 0x00, 0xCF, 0x2B, 0x3B, 0xE9, 0x85, 0xEE, 0xBD,
  47497. 0x4C, 0x64, 0x66, 0x0B, 0x77, 0x80, 0x9D, 0xEF,
  47498. 0x11, 0x32, 0x77, 0xA8, 0xA4, 0x5F, 0xEE, 0x2D,
  47499. 0xE0, 0x43, 0x87, 0x76, 0x87, 0x53, 0x4E, 0xD7,
  47500. 0x1A, 0x04, 0x7B, 0xE1, 0xD1, 0xE1, 0xF5, 0x87,
  47501. 0x51, 0x13, 0xE0, 0xC2, 0xAA, 0xA3, 0x4B, 0xAA,
  47502. 0x9E, 0xB4, 0xA6, 0x1D, 0x4E, 0x28, 0x57, 0x0B,
  47503. 0x80, 0x90, 0x81, 0x4E, 0x04, 0xF5, 0x30, 0x8D,
  47504. 0x51, 0xCE, 0x57, 0x2F, 0x88, 0xC5, 0x70, 0xC4,
  47505. 0x06, 0x8F, 0xDD, 0x37, 0xC1, 0x34, 0x1E, 0x0E,
  47506. 0x15, 0x32, 0x23, 0x92, 0xAB, 0x40, 0xEA, 0xF7,
  47507. 0x43, 0xE2, 0x1D, 0xE2, 0x4B, 0xC9, 0x91, 0xF4,
  47508. 0x63, 0x21, 0x34, 0xDB, 0xE9, 0x86, 0x83, 0x1A,
  47509. 0xD2, 0x52, 0xEF, 0x7A, 0xA2, 0xEE, 0xA4, 0x11,
  47510. 0x56, 0xD3, 0x6C, 0xF5, 0x6D, 0xE4, 0xA5, 0x2D,
  47511. 0x99, 0x02, 0x10, 0xDF, 0x29, 0xC5, 0xE3, 0x0B,
  47512. 0xC4, 0xA1, 0xEE, 0x5F, 0x4A, 0x10, 0xEE, 0x85,
  47513. 0x73, 0x2A, 0x92, 0x15, 0x2C, 0xC8, 0xF4, 0x8C,
  47514. 0xD7, 0x3D, 0xBC, 0xAD, 0x18, 0xE0, 0x59, 0xD3,
  47515. 0xEE, 0x75, 0x90, 0x1C, 0xCC, 0x76, 0xC6, 0x64,
  47516. 0x17, 0xD2, 0xD0, 0x91, 0xA6, 0xD0, 0xC1, 0x4A,
  47517. 0xAA, 0x58, 0x22, 0xEC, 0x45, 0x98, 0xF2, 0xCC,
  47518. 0x4C, 0xE4, 0xBF, 0xED, 0xF6, 0x44, 0x72, 0x36,
  47519. 0x65, 0x3F, 0xE3, 0xB5, 0x8B, 0x3E, 0x54, 0x9C,
  47520. 0x82, 0x86, 0x5E, 0xB0, 0xF2, 0x12, 0xE5, 0x69,
  47521. 0xFA, 0x46, 0xA2, 0x54, 0xFC, 0xF5, 0x4B, 0xE0,
  47522. 0x24, 0x3B, 0x99, 0x04, 0x1A, 0x7A, 0xF7, 0xD1,
  47523. 0xFF, 0x68, 0x97, 0xB2, 0x85, 0x82, 0x95, 0x27,
  47524. 0x2B, 0xF4, 0xE7, 0x1A, 0x74, 0x19, 0xEC, 0x8C,
  47525. 0x4E, 0xA7, 0x0F, 0xAD, 0x4F, 0x5A, 0x02, 0x80,
  47526. 0xC1, 0x6A, 0x9E, 0x54, 0xE4, 0x8E, 0xA3, 0x41,
  47527. 0x3F, 0x6F, 0x9C, 0x82, 0x9F, 0x83, 0xB0, 0x44,
  47528. 0x01, 0x5F, 0x10, 0x9D, 0xD3, 0xB6, 0x33, 0x5B,
  47529. 0xAF, 0xAC, 0x6B, 0x57, 0x2A, 0x01, 0xED, 0x0E,
  47530. 0x17, 0xB9, 0x80, 0x76, 0x12, 0x1C, 0x51, 0x56,
  47531. 0xDD, 0x6D, 0x94, 0xAB, 0xD2, 0xE5, 0x15, 0x2D,
  47532. 0x3C, 0xC5, 0xE8, 0x62, 0x05, 0x8B, 0x40, 0xB1,
  47533. 0xC2, 0x83, 0xCA, 0xAC, 0x4B, 0x8B, 0x39, 0xF7,
  47534. 0xA0, 0x08, 0x43, 0x5C, 0xF7, 0xE8, 0xED, 0x40,
  47535. 0x72, 0x73, 0xE3, 0x6B, 0x18, 0x67, 0xA0, 0xB6,
  47536. 0x0F, 0xED, 0x8F, 0x9A, 0xE4, 0x27, 0x62, 0x23,
  47537. 0xAA, 0x6D, 0x6C, 0x31, 0xC9, 0x9D, 0x6B, 0xE0,
  47538. 0xBF, 0x9D, 0x7D, 0x2E, 0x76, 0x71, 0x06, 0x39,
  47539. 0xAC, 0x96, 0x1C, 0xAF, 0x30, 0xF2, 0x62, 0x9C,
  47540. 0x84, 0x3F, 0x43, 0x5E, 0x19, 0xA8, 0xE5, 0x3C,
  47541. 0x9D, 0x43, 0x3C, 0x43, 0x41, 0xE8, 0x82, 0xE7,
  47542. 0x5B, 0xF3, 0xE2, 0x15, 0xE3, 0x52, 0x20, 0xFD,
  47543. 0x0D, 0xB2, 0x4D, 0x48, 0xAD, 0x53, 0x7E, 0x0C,
  47544. 0xF0, 0xB9, 0xBE, 0xC9, 0x58, 0x4B, 0xC8, 0xA8,
  47545. 0xA3, 0x36, 0xF1, 0x2C, 0xD2, 0xE1, 0xC8, 0xC4,
  47546. 0x3C, 0x48, 0x70, 0xC2, 0x6D, 0x6C, 0x3D, 0x99,
  47547. 0xAC, 0x43, 0x19, 0x69, 0xCA, 0x67, 0x1A, 0xC9,
  47548. 0xE1, 0x47, 0xFA, 0x0A, 0xE6, 0x5B, 0x6F, 0x61,
  47549. 0xD0, 0x03, 0xE4, 0x03, 0x4B, 0xFD, 0xE2, 0xA5,
  47550. 0x8D, 0x83, 0x01, 0x7E, 0xC0, 0x7B, 0x2E, 0x0B,
  47551. 0x29, 0xDD, 0xD6, 0xDC, 0x71, 0x46, 0xBD, 0x9A,
  47552. 0x40, 0x46, 0x1E, 0x0A, 0xB1, 0x00, 0xE7, 0x71,
  47553. 0x29, 0x77, 0xFC, 0x9A, 0x76, 0x8A, 0x5F, 0x66,
  47554. 0x9B, 0x63, 0x91, 0x12, 0x78, 0xBF, 0x67, 0xAD,
  47555. 0xA1, 0x72, 0x9E, 0xC5, 0x3E, 0xE5, 0xCB, 0xAF,
  47556. 0xD6, 0x5A, 0x0D, 0xB6, 0x9B, 0xA3, 0x78, 0xE8,
  47557. 0xB0, 0x8F, 0x69, 0xED, 0xC1, 0x73, 0xD5, 0xE5,
  47558. 0x1C, 0x18, 0xA0, 0x58, 0x4C, 0x49, 0xBD, 0x91,
  47559. 0xCE, 0x15, 0x0D, 0xAA, 0x5A, 0x07, 0xEA, 0x1C,
  47560. 0xA7, 0x4B, 0x11, 0x31, 0x80, 0xAF, 0xA1, 0x0A,
  47561. 0xED, 0x6C, 0x70, 0xE4, 0xDB, 0x75, 0x86, 0xAE,
  47562. 0xBF, 0x4A, 0x05, 0x72, 0xDE, 0x84, 0x8C, 0x7B,
  47563. 0x59, 0x81, 0x58, 0xE0, 0xC0, 0x15, 0xB5, 0xF3,
  47564. 0xD5, 0x73, 0x78, 0x83, 0x53, 0xDA, 0x92, 0xC1,
  47565. 0xE6, 0x71, 0x74, 0xC7, 0x7E, 0xAA, 0x36, 0x06,
  47566. 0xF0, 0xDF, 0xBA, 0xFB, 0xEF, 0x54, 0xE8, 0x11,
  47567. 0xB2, 0x33, 0xA3, 0x0B, 0x9E, 0x0C, 0x59, 0x75,
  47568. 0x13, 0xFA, 0x7F, 0x88, 0xB9, 0x86, 0xBD, 0x1A,
  47569. 0xDB, 0x52, 0x12, 0xFB, 0x6D, 0x1A, 0xCB, 0x49,
  47570. 0x94, 0x94, 0xC4, 0xA9, 0x99, 0xC0, 0xA4, 0xB6,
  47571. 0x60, 0x36, 0x09, 0x94, 0x2A, 0xD5, 0xC4, 0x26,
  47572. 0xF4, 0xA3, 0x6A, 0x0E, 0x57, 0x8B, 0x7C, 0xA4,
  47573. 0x1D, 0x75, 0xE8, 0x2A, 0xF3, 0xC4, 0x3C, 0x7D,
  47574. 0x45, 0x6D, 0xD8, 0x24, 0xD1, 0x3B, 0xF7, 0xCF,
  47575. 0xE4, 0x45, 0x2A, 0x55, 0xE5, 0xA9, 0x1F, 0x1C,
  47576. 0x8F, 0x55, 0x8D, 0xC1, 0xF7, 0x74, 0xCC, 0x26,
  47577. 0xC7, 0xBA, 0x2E, 0x5C, 0xC1, 0x71, 0x0A, 0xAA,
  47578. 0xD9, 0x6D, 0x76, 0xA7, 0xF9, 0xD1, 0x18, 0xCB,
  47579. 0x5A, 0x52, 0x98, 0xA8, 0x0D, 0x3F, 0x06, 0xFC,
  47580. 0x49, 0x11, 0x21, 0x5F, 0x86, 0x19, 0x33, 0x81,
  47581. 0xB5, 0x7A, 0xDA, 0xA1, 0x47, 0xBF, 0x7C, 0xD7,
  47582. 0x05, 0x96, 0xC7, 0xF5, 0xC1, 0x61, 0xE5, 0x18,
  47583. 0xA5, 0x38, 0x68, 0xED, 0xB4, 0x17, 0x62, 0x0D,
  47584. 0x01, 0x5E, 0xC3, 0x04, 0xA6, 0xBA, 0xB1, 0x01,
  47585. 0x60, 0x5C, 0xC1, 0x3A, 0x34, 0x97, 0xD6, 0xDB,
  47586. 0x67, 0x73, 0x4D, 0x33, 0x96, 0x01, 0x67, 0x44,
  47587. 0xEA, 0x47, 0x5E, 0x44, 0xB5, 0xE5, 0xD1, 0x6C,
  47588. 0x20, 0xA9, 0x6D, 0x4D, 0xBC, 0x02, 0xF0, 0x70,
  47589. 0xE4, 0xDD, 0xE9, 0xD5, 0x5C, 0x28, 0x29, 0x0B,
  47590. 0xB4, 0x60, 0x2A, 0xF1, 0xF7, 0x1A, 0xF0, 0x36,
  47591. 0xAE, 0x51, 0x3A, 0xAE, 0x6E, 0x48, 0x7D, 0xC7,
  47592. 0x5C, 0xF3, 0xDC, 0xF6, 0xED, 0x27, 0x4E, 0x8E,
  47593. 0x48, 0x18, 0x3E, 0x08, 0xF1, 0xD8, 0x3D, 0x0D,
  47594. 0xE7, 0x2F, 0x65, 0x8A, 0x6F, 0xE2, 0x1E, 0x06,
  47595. 0xC1, 0x04, 0x58, 0x7B, 0x4A, 0x75, 0x60, 0x92,
  47596. 0x13, 0xC6, 0x40, 0x2D, 0x3A, 0x8A, 0xD1, 0x03,
  47597. 0x05, 0x1F, 0x28, 0x66, 0xC2, 0x57, 0x2A, 0x4C,
  47598. 0xE1, 0xA3, 0xCB, 0xA1, 0x95, 0x30, 0x10, 0xED,
  47599. 0xDF, 0xAE, 0x70, 0x49, 0x4E, 0xF6, 0xB4, 0x5A,
  47600. 0xB6, 0x22, 0x56, 0x37, 0x05, 0xE7, 0x3E, 0xB2,
  47601. 0xE3, 0x96, 0x62, 0xEC, 0x09, 0x53, 0xC0, 0x50,
  47602. 0x3D, 0xA7, 0xBC, 0x9B, 0x39, 0x02, 0x26, 0x16,
  47603. 0xB5, 0x34, 0x17, 0xD4, 0xCA, 0xFE, 0x1D, 0xE4,
  47604. 0x5A, 0xDA, 0x4C, 0xC2, 0xCA, 0x8E, 0x79, 0xBF,
  47605. 0xD8, 0x4C, 0xBB, 0xFA, 0x30, 0x7B, 0xA9, 0x3E,
  47606. 0x52, 0x19, 0xB1, 0x00, 0x00, 0x00, 0x00, 0x00,
  47607. 0x00, 0x00, 0x00, 0x00, 0x00
  47608. };
  47609. #endif /* HAVE_PKCS7 && !NO_FILESYSTEM && ASN_BER_TO_DER &&
  47610. * !NO_DES3 && !NO_SHA
  47611. */
  47612. /*
  47613. * Testing wc_PKCS7_BER()
  47614. */
  47615. static int test_wc_PKCS7_BER(void)
  47616. {
  47617. EXPECT_DECLS;
  47618. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  47619. !defined(NO_SHA) && defined(ASN_BER_TO_DER)
  47620. PKCS7* pkcs7 = NULL;
  47621. char fName[] = "./certs/test-ber-exp02-05-2022.p7b";
  47622. XFILE f = XBADFILE;
  47623. byte der[4096];
  47624. #ifndef NO_DES3
  47625. byte decoded[2048];
  47626. #endif
  47627. word32 derSz = 0;
  47628. #ifndef NO_PKCS7_STREAM
  47629. word32 z;
  47630. int ret;
  47631. #endif /* !NO_PKCS7_STREAM */
  47632. ExpectTrue((f = XFOPEN(fName, "rb")) != XBADFILE);
  47633. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  47634. if (f != XBADFILE) {
  47635. XFCLOSE(f);
  47636. f = XBADFILE;
  47637. }
  47638. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47639. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  47640. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47641. #ifndef NO_RSA
  47642. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  47643. #ifndef NO_PKCS7_STREAM
  47644. wc_PKCS7_Free(pkcs7);
  47645. pkcs7 = NULL;
  47646. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47647. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  47648. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47649. /* test for streaming */
  47650. ret = -1;
  47651. for (z = 0; z < derSz && ret != 0; z++) {
  47652. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  47653. if (ret < 0){
  47654. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  47655. }
  47656. }
  47657. ExpectIntEQ(ret, 0);
  47658. #endif /* !NO_PKCS7_STREAM */
  47659. #else
  47660. ExpectIntNE(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  47661. #endif
  47662. wc_PKCS7_Free(pkcs7);
  47663. pkcs7 = NULL;
  47664. #ifndef NO_DES3
  47665. /* decode BER content */
  47666. ExpectTrue((f = XFOPEN("./certs/1024/client-cert.der", "rb")) != XBADFILE);
  47667. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  47668. if (f != XBADFILE) {
  47669. XFCLOSE(f);
  47670. f = XBADFILE;
  47671. }
  47672. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47673. #ifndef NO_RSA
  47674. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, der, derSz), 0);
  47675. #else
  47676. ExpectIntNE(wc_PKCS7_InitWithCert(pkcs7, der, derSz), 0);
  47677. #endif
  47678. ExpectTrue((f = XFOPEN("./certs/1024/client-key.der", "rb")) != XBADFILE);
  47679. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  47680. if (f != XBADFILE) {
  47681. XFCLOSE(f);
  47682. f = XBADFILE;
  47683. }
  47684. if (pkcs7 != NULL) {
  47685. pkcs7->privateKey = der;
  47686. pkcs7->privateKeySz = derSz;
  47687. }
  47688. #ifndef NO_RSA
  47689. #ifdef WOLFSSL_SP_MATH
  47690. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  47691. sizeof(berContent), decoded, sizeof(decoded)), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  47692. #else
  47693. ExpectIntGT(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  47694. sizeof(berContent), decoded, sizeof(decoded)), 0);
  47695. #endif
  47696. #else
  47697. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  47698. sizeof(berContent), decoded, sizeof(decoded)), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  47699. #endif
  47700. wc_PKCS7_Free(pkcs7);
  47701. #endif /* !NO_DES3 */
  47702. #endif
  47703. return EXPECT_RESULT();
  47704. } /* END test_wc_PKCS7_BER() */
  47705. static int test_wc_PKCS7_signed_enveloped(void)
  47706. {
  47707. EXPECT_DECLS;
  47708. #if defined(HAVE_PKCS7) && !defined(NO_RSA) && !defined(NO_AES) && \
  47709. !defined(NO_FILESYSTEM)
  47710. XFILE f = XBADFILE;
  47711. PKCS7* pkcs7 = NULL;
  47712. #ifdef HAVE_AES_CBC
  47713. PKCS7* inner = NULL;
  47714. #endif
  47715. WC_RNG rng;
  47716. unsigned char key[FOURK_BUF/2];
  47717. unsigned char cert[FOURK_BUF/2];
  47718. unsigned char env[FOURK_BUF];
  47719. int envSz = FOURK_BUF;
  47720. int keySz = 0;
  47721. int certSz = 0;
  47722. unsigned char sig[FOURK_BUF * 2];
  47723. int sigSz = FOURK_BUF * 2;
  47724. #ifdef HAVE_AES_CBC
  47725. unsigned char decoded[FOURK_BUF];
  47726. int decodedSz = FOURK_BUF;
  47727. #endif
  47728. #ifndef NO_PKCS7_STREAM
  47729. int z;
  47730. int ret;
  47731. #endif /* !NO_PKCS7_STREAM */
  47732. XMEMSET(&rng, 0, sizeof(WC_RNG));
  47733. /* load cert */
  47734. ExpectTrue((f = XFOPEN(cliCertDerFile, "rb")) != XBADFILE);
  47735. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), f)), 0);
  47736. if (f != XBADFILE) {
  47737. XFCLOSE(f);
  47738. f = XBADFILE;
  47739. }
  47740. /* load key */
  47741. ExpectTrue((f = XFOPEN(cliKeyFile, "rb")) != XBADFILE);
  47742. ExpectIntGT((keySz = (int)XFREAD(key, 1, sizeof(key), f)), 0);
  47743. if (f != XBADFILE) {
  47744. XFCLOSE(f);
  47745. f = XBADFILE;
  47746. }
  47747. ExpectIntGT(keySz = wolfSSL_KeyPemToDer(key, keySz, key, keySz, NULL), 0);
  47748. /* sign cert for envelope */
  47749. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47750. ExpectIntEQ(wc_InitRng(&rng), 0);
  47751. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  47752. if (pkcs7 != NULL) {
  47753. pkcs7->content = cert;
  47754. pkcs7->contentSz = (word32)certSz;
  47755. pkcs7->contentOID = DATA;
  47756. pkcs7->privateKey = key;
  47757. pkcs7->privateKeySz = (word32)keySz;
  47758. pkcs7->encryptOID = RSAk;
  47759. pkcs7->hashOID = SHA256h;
  47760. pkcs7->rng = &rng;
  47761. }
  47762. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  47763. wc_PKCS7_Free(pkcs7);
  47764. pkcs7 = NULL;
  47765. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  47766. #ifdef HAVE_AES_CBC
  47767. /* create envelope */
  47768. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47769. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  47770. if (pkcs7 != NULL) {
  47771. pkcs7->content = sig;
  47772. pkcs7->contentSz = (word32)sigSz;
  47773. pkcs7->contentOID = DATA;
  47774. pkcs7->encryptOID = AES256CBCb;
  47775. pkcs7->privateKey = key;
  47776. pkcs7->privateKeySz = (word32)keySz;
  47777. }
  47778. ExpectIntGT((envSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, env, (word32)envSz)), 0);
  47779. ExpectIntLT(wc_PKCS7_EncodeEnvelopedData(pkcs7, env, 2), 0);
  47780. wc_PKCS7_Free(pkcs7);
  47781. pkcs7 = NULL;
  47782. #endif
  47783. /* create bad signed enveloped data */
  47784. sigSz = FOURK_BUF * 2;
  47785. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47786. ExpectIntEQ(wc_InitRng(&rng), 0);
  47787. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  47788. if (pkcs7 != NULL) {
  47789. pkcs7->content = env;
  47790. pkcs7->contentSz = (word32)envSz;
  47791. pkcs7->contentOID = DATA;
  47792. pkcs7->privateKey = key;
  47793. pkcs7->privateKeySz = (word32)keySz;
  47794. pkcs7->encryptOID = RSAk;
  47795. pkcs7->hashOID = SHA256h;
  47796. pkcs7->rng = &rng;
  47797. }
  47798. /* Set no certs in bundle for this test. */
  47799. if (pkcs7 != NULL) {
  47800. ExpectIntEQ(wc_PKCS7_SetNoCerts(pkcs7, 1), 0);
  47801. ExpectIntEQ(wc_PKCS7_SetNoCerts(NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47802. ExpectIntEQ(wc_PKCS7_GetNoCerts(pkcs7), 1);
  47803. }
  47804. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  47805. wc_PKCS7_Free(pkcs7);
  47806. pkcs7 = NULL;
  47807. /* check verify fails */
  47808. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47809. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47810. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz),
  47811. WC_NO_ERR_TRACE(PKCS7_SIGNEEDS_CHECK));
  47812. /* try verifying the signature manually */
  47813. {
  47814. RsaKey rKey;
  47815. word32 idx = 0;
  47816. byte digest[MAX_SEQ_SZ + MAX_ALGO_SZ + MAX_OCTET_STR_SZ +
  47817. WC_MAX_DIGEST_SIZE];
  47818. int digestSz = 0;
  47819. ExpectIntEQ(wc_InitRsaKey(&rKey, HEAP_HINT), 0);
  47820. ExpectIntEQ(wc_RsaPrivateKeyDecode(key, &idx, &rKey, (word32)keySz), 0);
  47821. ExpectIntGT(digestSz = wc_RsaSSL_Verify(pkcs7->signature,
  47822. pkcs7->signatureSz, digest, sizeof(digest), &rKey), 0);
  47823. ExpectIntEQ(digestSz, pkcs7->pkcs7DigestSz);
  47824. ExpectIntEQ(XMEMCMP(digest, pkcs7->pkcs7Digest, digestSz), 0);
  47825. ExpectIntEQ(wc_FreeRsaKey(&rKey), 0);
  47826. /* verify was success */
  47827. }
  47828. wc_PKCS7_Free(pkcs7);
  47829. pkcs7 = NULL;
  47830. /* initializing the PKCS7 struct with the signing certificate should pass */
  47831. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47832. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  47833. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz), 0);
  47834. #ifndef NO_PKCS7_STREAM
  47835. wc_PKCS7_Free(pkcs7);
  47836. pkcs7 = NULL;
  47837. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47838. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  47839. /* test for streaming */
  47840. ret = -1;
  47841. for (z = 0; z < sigSz && ret != 0; z++) {
  47842. ret = wc_PKCS7_VerifySignedData(pkcs7, sig + z, 1);
  47843. if (ret < 0){
  47844. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  47845. }
  47846. }
  47847. ExpectIntEQ(ret, 0);
  47848. #endif /* !NO_PKCS7_STREAM */
  47849. wc_PKCS7_Free(pkcs7);
  47850. pkcs7 = NULL;
  47851. /* create valid degenerate bundle */
  47852. sigSz = FOURK_BUF * 2;
  47853. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47854. if (pkcs7 != NULL) {
  47855. pkcs7->content = env;
  47856. pkcs7->contentSz = (word32)envSz;
  47857. pkcs7->contentOID = DATA;
  47858. pkcs7->privateKey = key;
  47859. pkcs7->privateKeySz = (word32)keySz;
  47860. pkcs7->encryptOID = RSAk;
  47861. pkcs7->hashOID = SHA256h;
  47862. pkcs7->rng = &rng;
  47863. }
  47864. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, DEGENERATE_SID), 0);
  47865. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  47866. wc_PKCS7_Free(pkcs7);
  47867. pkcs7 = NULL;
  47868. wc_FreeRng(&rng);
  47869. /* check verify */
  47870. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47871. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  47872. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz), 0);
  47873. ExpectNotNull(pkcs7->content);
  47874. #ifndef NO_PKCS7_STREAM
  47875. wc_PKCS7_Free(pkcs7);
  47876. pkcs7 = NULL;
  47877. /* create valid degenerate bundle */
  47878. sigSz = FOURK_BUF * 2;
  47879. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47880. if (pkcs7 != NULL) {
  47881. pkcs7->content = env;
  47882. pkcs7->contentSz = (word32)envSz;
  47883. pkcs7->contentOID = DATA;
  47884. pkcs7->privateKey = key;
  47885. pkcs7->privateKeySz = (word32)keySz;
  47886. pkcs7->encryptOID = RSAk;
  47887. pkcs7->hashOID = SHA256h;
  47888. pkcs7->rng = &rng;
  47889. }
  47890. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, DEGENERATE_SID), 0);
  47891. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  47892. wc_PKCS7_Free(pkcs7);
  47893. pkcs7 = NULL;
  47894. wc_FreeRng(&rng);
  47895. /* check verify */
  47896. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47897. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  47898. /* test for streaming */
  47899. ret = -1;
  47900. for (z = 0; z < sigSz && ret != 0; z++) {
  47901. ret = wc_PKCS7_VerifySignedData(pkcs7, sig + z, 1);
  47902. if (ret < 0){
  47903. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  47904. }
  47905. }
  47906. ExpectIntEQ(ret, 0);
  47907. #endif /* !NO_PKCS7_STREAM */
  47908. #ifdef HAVE_AES_CBC
  47909. /* check decode */
  47910. ExpectNotNull(inner = wc_PKCS7_New(NULL, 0));
  47911. ExpectIntEQ(wc_PKCS7_InitWithCert(inner, cert, (word32)certSz), 0);
  47912. if (inner != NULL) {
  47913. inner->privateKey = key;
  47914. inner->privateKeySz = (word32)keySz;
  47915. }
  47916. ExpectIntGT((decodedSz = wc_PKCS7_DecodeEnvelopedData(inner, pkcs7->content,
  47917. pkcs7->contentSz, decoded, (word32)decodedSz)), 0);
  47918. wc_PKCS7_Free(inner);
  47919. inner = NULL;
  47920. #endif
  47921. wc_PKCS7_Free(pkcs7);
  47922. pkcs7 = NULL;
  47923. #ifdef HAVE_AES_CBC
  47924. /* check cert set */
  47925. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47926. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47927. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, decoded, (word32)decodedSz), 0);
  47928. ExpectNotNull(pkcs7->singleCert);
  47929. ExpectIntNE(pkcs7->singleCertSz, 0);
  47930. wc_PKCS7_Free(pkcs7);
  47931. pkcs7 = NULL;
  47932. #ifndef NO_PKCS7_STREAM
  47933. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47934. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47935. /* test for streaming */
  47936. ret = -1;
  47937. for (z = 0; z < decodedSz && ret != 0; z++) {
  47938. ret = wc_PKCS7_VerifySignedData(pkcs7, decoded + z, 1);
  47939. if (ret < 0){
  47940. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  47941. }
  47942. }
  47943. ExpectIntEQ(ret, 0);
  47944. ExpectNotNull(pkcs7->singleCert);
  47945. ExpectIntNE(pkcs7->singleCertSz, 0);
  47946. wc_PKCS7_Free(pkcs7);
  47947. pkcs7 = NULL;
  47948. #endif /* !NO_PKCS7_STREAM */
  47949. #endif
  47950. {
  47951. /* arbitrary custom SKID */
  47952. const byte customSKID[] = {
  47953. 0x40, 0x25, 0x77, 0x56
  47954. };
  47955. ExpectIntEQ(wc_InitRng(&rng), 0);
  47956. sigSz = FOURK_BUF * 2;
  47957. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47958. if (pkcs7 != NULL) {
  47959. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  47960. pkcs7->content = cert;
  47961. pkcs7->contentSz = (word32)certSz;
  47962. pkcs7->contentOID = DATA;
  47963. pkcs7->privateKey = key;
  47964. pkcs7->privateKeySz = (word32)keySz;
  47965. pkcs7->encryptOID = RSAk;
  47966. pkcs7->hashOID = SHA256h;
  47967. pkcs7->rng = &rng;
  47968. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID), 0);
  47969. ExpectIntEQ(wc_PKCS7_SetCustomSKID(pkcs7, customSKID,
  47970. sizeof(customSKID)), 0);
  47971. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig,
  47972. (word32)sigSz)), 0);
  47973. }
  47974. wc_PKCS7_Free(pkcs7);
  47975. pkcs7 = NULL;
  47976. wc_FreeRng(&rng);
  47977. }
  47978. #endif /* HAVE_PKCS7 && !NO_RSA && !NO_AES */
  47979. return EXPECT_RESULT();
  47980. }
  47981. static int test_wc_PKCS7_NoDefaultSignedAttribs(void)
  47982. {
  47983. EXPECT_DECLS;
  47984. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  47985. && !defined(NO_AES)
  47986. PKCS7* pkcs7 = NULL;
  47987. void* heap = NULL;
  47988. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  47989. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  47990. ExpectIntEQ(wc_PKCS7_NoDefaultSignedAttribs(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47991. ExpectIntEQ(wc_PKCS7_NoDefaultSignedAttribs(pkcs7), 0);
  47992. wc_PKCS7_Free(pkcs7);
  47993. #endif
  47994. return EXPECT_RESULT();
  47995. }
  47996. static int test_wc_PKCS7_SetOriEncryptCtx(void)
  47997. {
  47998. EXPECT_DECLS;
  47999. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  48000. && !defined(NO_AES)
  48001. PKCS7* pkcs7 = NULL;
  48002. void* heap = NULL;
  48003. WOLFSSL_CTX* ctx = NULL;
  48004. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  48005. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  48006. ExpectIntEQ(wc_PKCS7_SetOriEncryptCtx(NULL, ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48007. ExpectIntEQ(wc_PKCS7_SetOriEncryptCtx(pkcs7, ctx), 0);
  48008. wc_PKCS7_Free(pkcs7);
  48009. #endif
  48010. return EXPECT_RESULT();
  48011. }
  48012. static int test_wc_PKCS7_SetOriDecryptCtx(void)
  48013. {
  48014. EXPECT_DECLS;
  48015. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  48016. && !defined(NO_AES)
  48017. PKCS7* pkcs7 = NULL;
  48018. void* heap = NULL;
  48019. WOLFSSL_CTX* ctx = NULL;
  48020. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  48021. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  48022. ExpectIntEQ(wc_PKCS7_SetOriDecryptCtx(NULL, ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48023. ExpectIntEQ(wc_PKCS7_SetOriDecryptCtx(pkcs7, ctx), 0);
  48024. wc_PKCS7_Free(pkcs7);
  48025. #endif
  48026. return EXPECT_RESULT();
  48027. }
  48028. static int test_wc_PKCS7_DecodeCompressedData(void)
  48029. {
  48030. EXPECT_DECLS;
  48031. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  48032. && !defined(NO_AES) && defined(HAVE_LIBZ)
  48033. PKCS7* pkcs7 = NULL;
  48034. void* heap = NULL;
  48035. byte out[4096];
  48036. byte* decompressed = NULL;
  48037. int outSz;
  48038. int decompressedSz;
  48039. const char* cert = "./certs/client-cert.pem";
  48040. byte* cert_buf = NULL;
  48041. size_t cert_sz = 0;
  48042. ExpectIntEQ(load_file(cert, &cert_buf, &cert_sz), 0);
  48043. ExpectNotNull((decompressed = (byte*)XMALLOC(cert_sz, heap,
  48044. DYNAMIC_TYPE_TMP_BUFFER)));
  48045. decompressedSz = (int)cert_sz;
  48046. ExpectNotNull((pkcs7 = wc_PKCS7_New(heap, testDevId)));
  48047. if (pkcs7 != NULL) {
  48048. pkcs7->content = (byte*)cert_buf;
  48049. pkcs7->contentSz = (word32)cert_sz;
  48050. pkcs7->contentOID = DATA;
  48051. }
  48052. ExpectIntGT((outSz = wc_PKCS7_EncodeCompressedData(pkcs7, out,
  48053. sizeof(out))), 0);
  48054. wc_PKCS7_Free(pkcs7);
  48055. pkcs7 = NULL;
  48056. /* compressed key should be smaller than when started */
  48057. ExpectIntLT(outSz, cert_sz);
  48058. /* test decompression */
  48059. ExpectNotNull((pkcs7 = wc_PKCS7_New(heap, testDevId)));
  48060. ExpectIntEQ(pkcs7->contentOID, 0);
  48061. /* fail case with out buffer too small */
  48062. ExpectIntLT(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz,
  48063. decompressed, outSz), 0);
  48064. /* success case */
  48065. ExpectIntEQ(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz,
  48066. decompressed, decompressedSz), cert_sz);
  48067. ExpectIntEQ(pkcs7->contentOID, DATA);
  48068. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  48069. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  48070. decompressed = NULL;
  48071. /* test decompression function with different 'max' inputs */
  48072. outSz = sizeof(out);
  48073. ExpectIntGT((outSz = wc_Compress(out, outSz, cert_buf, (word32)cert_sz, 0)),
  48074. 0);
  48075. ExpectIntLT(wc_DeCompressDynamic(&decompressed, 1, DYNAMIC_TYPE_TMP_BUFFER,
  48076. out, outSz, 0, heap), 0);
  48077. ExpectNull(decompressed);
  48078. ExpectIntGT(wc_DeCompressDynamic(&decompressed, -1, DYNAMIC_TYPE_TMP_BUFFER,
  48079. out, outSz, 0, heap), 0);
  48080. ExpectNotNull(decompressed);
  48081. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  48082. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  48083. decompressed = NULL;
  48084. ExpectIntGT(wc_DeCompressDynamic(&decompressed, DYNAMIC_TYPE_TMP_BUFFER, 5,
  48085. out, outSz, 0, heap), 0);
  48086. ExpectNotNull(decompressed);
  48087. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  48088. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  48089. if (cert_buf != NULL)
  48090. free(cert_buf);
  48091. wc_PKCS7_Free(pkcs7);
  48092. #endif
  48093. return EXPECT_RESULT();
  48094. }
  48095. static int test_wc_i2d_PKCS12(void)
  48096. {
  48097. EXPECT_DECLS;
  48098. #if !defined(NO_ASN) && !defined(NO_PWDBASED) && defined(HAVE_PKCS12) \
  48099. && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  48100. && !defined(NO_AES) && !defined(NO_SHA)
  48101. WC_PKCS12* pkcs12 = NULL;
  48102. unsigned char der[FOURK_BUF * 2];
  48103. unsigned char* pt;
  48104. int derSz = 0;
  48105. unsigned char out[FOURK_BUF * 2];
  48106. int outSz = FOURK_BUF * 2;
  48107. const char p12_f[] = "./certs/test-servercert.p12";
  48108. XFILE f = XBADFILE;
  48109. ExpectTrue((f = XFOPEN(p12_f, "rb")) != XBADFILE);
  48110. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  48111. if (f != XBADFILE)
  48112. XFCLOSE(f);
  48113. ExpectNotNull(pkcs12 = wc_PKCS12_new());
  48114. ExpectIntEQ(wc_d2i_PKCS12(der, (word32)derSz, pkcs12), 0);
  48115. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  48116. ExpectIntEQ(outSz, derSz);
  48117. outSz = derSz - 1;
  48118. pt = out;
  48119. ExpectIntLE(wc_i2d_PKCS12(pkcs12, &pt, &outSz), 0);
  48120. outSz = derSz;
  48121. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, &pt, &outSz), derSz);
  48122. ExpectIntEQ((pt == out), 0);
  48123. pt = NULL;
  48124. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, &pt, NULL), derSz);
  48125. XFREE(pt, NULL, DYNAMIC_TYPE_PKCS);
  48126. wc_PKCS12_free(pkcs12);
  48127. pkcs12 = NULL;
  48128. /* Run the same test but use wc_d2i_PKCS12_fp. */
  48129. ExpectNotNull(pkcs12 = wc_PKCS12_new());
  48130. ExpectIntEQ(wc_d2i_PKCS12_fp("./certs/test-servercert.p12", &pkcs12), 0);
  48131. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  48132. ExpectIntEQ(outSz, derSz);
  48133. wc_PKCS12_free(pkcs12);
  48134. pkcs12 = NULL;
  48135. /* wc_d2i_PKCS12_fp can also allocate the PKCS12 object for the caller. */
  48136. ExpectIntEQ(wc_d2i_PKCS12_fp("./certs/test-servercert.p12", &pkcs12), 0);
  48137. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  48138. ExpectIntEQ(outSz, derSz);
  48139. wc_PKCS12_free(pkcs12);
  48140. pkcs12 = NULL;
  48141. #endif
  48142. return EXPECT_RESULT();
  48143. }
  48144. /* Testing wc_SignatureGetSize() for signature type ECC */
  48145. static int test_wc_SignatureGetSize_ecc(void)
  48146. {
  48147. EXPECT_DECLS;
  48148. #if !defined(NO_SIG_WRAPPER) && defined(HAVE_ECC) && !defined(NO_ECC256)
  48149. enum wc_SignatureType sig_type;
  48150. word32 key_len;
  48151. ecc_key ecc;
  48152. const char* qx =
  48153. "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
  48154. const char* qy =
  48155. "d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09";
  48156. const char* d =
  48157. "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
  48158. XMEMSET(&ecc, 0, sizeof(ecc_key));
  48159. ExpectIntEQ(wc_ecc_init(&ecc), 0);
  48160. ExpectIntEQ(wc_ecc_import_raw(&ecc, qx, qy, d, "SECP256R1"), 0);
  48161. /* Input for signature type ECC */
  48162. sig_type = WC_SIGNATURE_TYPE_ECC;
  48163. key_len = sizeof(ecc_key);
  48164. ExpectIntGT(wc_SignatureGetSize(sig_type, &ecc, key_len), 0);
  48165. /* Test bad args */
  48166. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  48167. sig_type = (enum wc_SignatureType) 100;
  48168. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  48169. ExpectIntEQ(wc_SignatureGetSize(sig_type, &ecc, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48170. sig_type = WC_SIGNATURE_TYPE_ECC;
  48171. ExpectIntEQ(wc_SignatureGetSize(sig_type, NULL, key_len), 0);
  48172. key_len = (word32)0;
  48173. ExpectIntEQ(wc_SignatureGetSize(sig_type, &ecc, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48174. DoExpectIntEQ(wc_ecc_free(&ecc), 0);
  48175. #endif /* !NO_SIG_WRAPPER && HAVE_ECC && !NO_ECC256 */
  48176. return EXPECT_RESULT();
  48177. } /* END test_wc_SignatureGetSize_ecc() */
  48178. /* Testing wc_SignatureGetSize() for signature type rsa */
  48179. static int test_wc_SignatureGetSize_rsa(void)
  48180. {
  48181. EXPECT_DECLS;
  48182. #if !defined(NO_SIG_WRAPPER) && !defined(NO_RSA)
  48183. enum wc_SignatureType sig_type;
  48184. word32 key_len;
  48185. word32 idx = 0;
  48186. RsaKey rsa_key;
  48187. byte* tmp = NULL;
  48188. size_t bytes;
  48189. XMEMSET(&rsa_key, 0, sizeof(RsaKey));
  48190. #ifdef USE_CERT_BUFFERS_1024
  48191. bytes = (size_t)sizeof_client_key_der_1024;
  48192. if (bytes < (size_t)sizeof_client_key_der_1024)
  48193. bytes = (size_t)sizeof_client_cert_der_1024;
  48194. #elif defined(USE_CERT_BUFFERS_2048)
  48195. bytes = (size_t)sizeof_client_key_der_2048;
  48196. if (bytes < (size_t)sizeof_client_cert_der_2048)
  48197. bytes = (size_t)sizeof_client_cert_der_2048;
  48198. #else
  48199. bytes = FOURK_BUF;
  48200. #endif
  48201. ExpectNotNull(tmp = (byte*)XMALLOC(bytes, HEAP_HINT,
  48202. DYNAMIC_TYPE_TMP_BUFFER));
  48203. if (tmp != NULL) {
  48204. #ifdef USE_CERT_BUFFERS_1024
  48205. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  48206. #elif defined(USE_CERT_BUFFERS_2048)
  48207. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  48208. #elif !defined(NO_FILESYSTEM)
  48209. XFILE file = XBADFILE;
  48210. ExpectTrue((file = XFOPEN(clientKey, "rb")) != XBADFILE);
  48211. ExpectIntGT(bytes = (size_t)XFREAD(tmp, 1, FOURK_BUF, file), 0);
  48212. if (file != XBADFILE)
  48213. XFCLOSE(file);
  48214. }
  48215. #else
  48216. ExpectFail();
  48217. #endif
  48218. }
  48219. ExpectIntEQ(wc_InitRsaKey_ex(&rsa_key, HEAP_HINT, testDevId), 0);
  48220. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, &rsa_key, (word32)bytes), 0);
  48221. /* Input for signature type RSA */
  48222. sig_type = WC_SIGNATURE_TYPE_RSA;
  48223. key_len = sizeof(RsaKey);
  48224. ExpectIntGT(wc_SignatureGetSize(sig_type, &rsa_key, key_len), 0);
  48225. /* Test bad args */
  48226. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  48227. sig_type = (enum wc_SignatureType)100;
  48228. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  48229. ExpectIntEQ(wc_SignatureGetSize(sig_type, &rsa_key, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48230. sig_type = WC_SIGNATURE_TYPE_RSA;
  48231. ExpectIntEQ(wc_SignatureGetSize(sig_type, NULL, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48232. key_len = (word32)0;
  48233. ExpectIntEQ(wc_SignatureGetSize(sig_type, &rsa_key, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48234. DoExpectIntEQ(wc_FreeRsaKey(&rsa_key), 0);
  48235. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48236. #endif /* !NO_SIG_WRAPPER && !NO_RSA */
  48237. return EXPECT_RESULT();
  48238. } /* END test_wc_SignatureGetSize_rsa(void) */
  48239. /*----------------------------------------------------------------------------*
  48240. | hash.h Tests
  48241. *----------------------------------------------------------------------------*/
  48242. static int test_wc_HashInit(void)
  48243. {
  48244. EXPECT_DECLS;
  48245. int i; /* 0 indicates tests passed, 1 indicates failure */
  48246. wc_HashAlg hash;
  48247. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  48248. enum wc_HashType enumArray[] = {
  48249. #ifndef NO_MD5
  48250. WC_HASH_TYPE_MD5,
  48251. #endif
  48252. #ifndef NO_SHA
  48253. WC_HASH_TYPE_SHA,
  48254. #endif
  48255. #ifdef WOLFSSL_SHA224
  48256. WC_HASH_TYPE_SHA224,
  48257. #endif
  48258. #ifndef NO_SHA256
  48259. WC_HASH_TYPE_SHA256,
  48260. #endif
  48261. #ifdef WOLFSSL_SHA384
  48262. WC_HASH_TYPE_SHA384,
  48263. #endif
  48264. #ifdef WOLFSSL_SHA512
  48265. WC_HASH_TYPE_SHA512,
  48266. #endif
  48267. };
  48268. /* dynamically finds the length */
  48269. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  48270. /* For loop to test various arguments... */
  48271. for (i = 0; i < enumlen; i++) {
  48272. /* check for bad args */
  48273. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  48274. wc_HashFree(&hash, enumArray[i]);
  48275. /* check for null ptr */
  48276. ExpectIntEQ(wc_HashInit(NULL, enumArray[i]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48277. } /* end of for loop */
  48278. return EXPECT_RESULT();
  48279. } /* end of test_wc_HashInit */
  48280. /*
  48281. * Unit test function for wc_HashSetFlags()
  48282. */
  48283. static int test_wc_HashSetFlags(void)
  48284. {
  48285. EXPECT_DECLS;
  48286. #ifdef WOLFSSL_HASH_FLAGS
  48287. wc_HashAlg hash;
  48288. word32 flags = 0;
  48289. int i, j;
  48290. int notSupportedLen;
  48291. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  48292. enum wc_HashType enumArray[] = {
  48293. #ifndef NO_MD5
  48294. WC_HASH_TYPE_MD5,
  48295. #endif
  48296. #ifndef NO_SHA
  48297. WC_HASH_TYPE_SHA,
  48298. #endif
  48299. #ifdef WOLFSSL_SHA224
  48300. WC_HASH_TYPE_SHA224,
  48301. #endif
  48302. #ifndef NO_SHA256
  48303. WC_HASH_TYPE_SHA256,
  48304. #endif
  48305. #ifdef WOLFSSL_SHA384
  48306. WC_HASH_TYPE_SHA384,
  48307. #endif
  48308. #ifdef WOLFSSL_SHA512
  48309. WC_HASH_TYPE_SHA512,
  48310. #endif
  48311. #ifdef WOLFSSL_SHA3
  48312. WC_HASH_TYPE_SHA3_224,
  48313. #endif
  48314. };
  48315. enum wc_HashType notSupported[] = {
  48316. WC_HASH_TYPE_MD5_SHA,
  48317. WC_HASH_TYPE_MD2,
  48318. WC_HASH_TYPE_MD4,
  48319. WC_HASH_TYPE_BLAKE2B,
  48320. WC_HASH_TYPE_BLAKE2S,
  48321. WC_HASH_TYPE_NONE,
  48322. };
  48323. /* dynamically finds the length */
  48324. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  48325. /* For loop to test various arguments... */
  48326. for (i = 0; i < enumlen; i++) {
  48327. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  48328. ExpectIntEQ(wc_HashSetFlags(&hash, enumArray[i], flags), 0);
  48329. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  48330. ExpectIntEQ(wc_HashSetFlags(NULL, enumArray[i], flags), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48331. wc_HashFree(&hash, enumArray[i]);
  48332. }
  48333. /* For loop to test not supported cases */
  48334. notSupportedLen = (sizeof(notSupported)/sizeof(enum wc_HashType));
  48335. for (j = 0; j < notSupportedLen; j++) {
  48336. ExpectIntEQ(wc_HashInit(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48337. ExpectIntEQ(wc_HashSetFlags(&hash, notSupported[j], flags),
  48338. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48339. ExpectIntEQ(wc_HashFree(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48340. }
  48341. #endif
  48342. return EXPECT_RESULT();
  48343. } /* END test_wc_HashSetFlags */
  48344. /*
  48345. * Unit test function for wc_HashGetFlags()
  48346. */
  48347. static int test_wc_HashGetFlags(void)
  48348. {
  48349. EXPECT_DECLS;
  48350. #ifdef WOLFSSL_HASH_FLAGS
  48351. wc_HashAlg hash;
  48352. word32 flags = 0;
  48353. int i, j;
  48354. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  48355. enum wc_HashType enumArray[] = {
  48356. #ifndef NO_MD5
  48357. WC_HASH_TYPE_MD5,
  48358. #endif
  48359. #ifndef NO_SHA
  48360. WC_HASH_TYPE_SHA,
  48361. #endif
  48362. #ifdef WOLFSSL_SHA224
  48363. WC_HASH_TYPE_SHA224,
  48364. #endif
  48365. #ifndef NO_SHA256
  48366. WC_HASH_TYPE_SHA256,
  48367. #endif
  48368. #ifdef WOLFSSL_SHA384
  48369. WC_HASH_TYPE_SHA384,
  48370. #endif
  48371. #ifdef WOLFSSL_SHA512
  48372. WC_HASH_TYPE_SHA512,
  48373. #endif
  48374. #ifdef WOLFSSL_SHA3
  48375. WC_HASH_TYPE_SHA3_224,
  48376. #endif
  48377. };
  48378. enum wc_HashType notSupported[] = {
  48379. WC_HASH_TYPE_MD5_SHA,
  48380. WC_HASH_TYPE_MD2,
  48381. WC_HASH_TYPE_MD4,
  48382. WC_HASH_TYPE_BLAKE2B,
  48383. WC_HASH_TYPE_BLAKE2S,
  48384. WC_HASH_TYPE_NONE,
  48385. };
  48386. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  48387. int notSupportedLen;
  48388. /* For loop to test various arguments... */
  48389. for (i = 0; i < enumlen; i++) {
  48390. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  48391. ExpectIntEQ(wc_HashGetFlags(&hash, enumArray[i], &flags), 0);
  48392. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  48393. ExpectIntEQ(wc_HashGetFlags(NULL, enumArray[i], &flags), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48394. wc_HashFree(&hash, enumArray[i]);
  48395. }
  48396. /* For loop to test not supported cases */
  48397. notSupportedLen = (sizeof(notSupported)/sizeof(enum wc_HashType));
  48398. for (j = 0; j < notSupportedLen; j++) {
  48399. ExpectIntEQ(wc_HashInit(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48400. ExpectIntEQ(wc_HashGetFlags(&hash, notSupported[j], &flags),
  48401. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48402. ExpectIntEQ(wc_HashFree(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48403. }
  48404. #endif
  48405. return EXPECT_RESULT();
  48406. } /* END test_wc_HashGetFlags */
  48407. /*----------------------------------------------------------------------------*
  48408. | Compatibility Tests
  48409. *----------------------------------------------------------------------------*/
  48410. /*----------------------------------------------------------------------------*
  48411. | ASN.1 Tests
  48412. *----------------------------------------------------------------------------*/
  48413. static int test_wolfSSL_ASN1_BIT_STRING(void)
  48414. {
  48415. EXPECT_DECLS;
  48416. #if !defined(NO_CERTS) && defined(OPENSSL_ALL)
  48417. ASN1_BIT_STRING* str = NULL;
  48418. ASN1_BIT_STRING* str2 = NULL;
  48419. unsigned char* der = NULL;
  48420. ExpectNotNull(str = ASN1_BIT_STRING_new());
  48421. /* Empty data testing. */
  48422. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 1), 0);
  48423. ASN1_BIT_STRING_free(str);
  48424. str = NULL;
  48425. ExpectNotNull(str = ASN1_BIT_STRING_new());
  48426. /* Invalid parameter testing. */
  48427. ExpectIntEQ(ASN1_BIT_STRING_set_bit(NULL, 42, 1), 0);
  48428. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, -1, 1), 0);
  48429. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 2), 0);
  48430. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, -1), 0);
  48431. /* No bit string - bit is always 0. */
  48432. ExpectIntEQ(ASN1_BIT_STRING_get_bit(NULL, 42), 0);
  48433. ExpectIntEQ(ASN1_BIT_STRING_get_bit(NULL, -1), 0);
  48434. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, -1), 0);
  48435. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 0), 0);
  48436. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 1), 1);
  48437. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 42), 1);
  48438. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 41), 0);
  48439. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, -1), 0);
  48440. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 84, 1), 1);
  48441. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 84), 1);
  48442. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 83), 0);
  48443. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 91, 0), 1);
  48444. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 91), 0);
  48445. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 89, 0), 1);
  48446. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 89), 0);
  48447. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 0), 1);
  48448. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 42), 0);
  48449. ExpectIntEQ(i2d_ASN1_BIT_STRING(str, NULL), 14);
  48450. ExpectIntEQ(i2d_ASN1_BIT_STRING(str, &der), 14);
  48451. #ifdef WOLFSSL_ASN_TEMPLATE
  48452. {
  48453. const unsigned char* tmp = der;
  48454. ExpectNotNull(d2i_ASN1_BIT_STRING(&str2, &tmp, 14));
  48455. }
  48456. #endif
  48457. ASN1_BIT_STRING_free(str);
  48458. ASN1_BIT_STRING_free(str2);
  48459. ASN1_BIT_STRING_free(NULL);
  48460. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  48461. #endif
  48462. return EXPECT_RESULT();
  48463. }
  48464. static int test_wolfSSL_ASN1_INTEGER(void)
  48465. {
  48466. EXPECT_DECLS;
  48467. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  48468. ASN1_INTEGER* a = NULL;
  48469. ASN1_INTEGER* dup = NULL;
  48470. const unsigned char invalidLenDer[] = {
  48471. 0x02, 0x20, 0x00
  48472. };
  48473. const unsigned char longDer[] = {
  48474. 0x02, 0x20,
  48475. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  48476. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  48477. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  48478. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
  48479. };
  48480. const unsigned char* p;
  48481. /* Invalid parameter testing. */
  48482. ASN1_INTEGER_free(NULL);
  48483. ExpectNull(wolfSSL_ASN1_INTEGER_dup(NULL));
  48484. ExpectNotNull(a = ASN1_INTEGER_new());
  48485. ExpectNotNull(dup = wolfSSL_ASN1_INTEGER_dup(a));
  48486. ASN1_INTEGER_free(dup);
  48487. dup = NULL;
  48488. ASN1_INTEGER_free(a);
  48489. a = NULL;
  48490. p = longDer;
  48491. ExpectNull(d2i_ASN1_INTEGER(NULL, &p, sizeof(invalidLenDer)));
  48492. p = longDer;
  48493. ExpectNotNull(a = d2i_ASN1_INTEGER(NULL, &p, sizeof(longDer)));
  48494. ExpectPtrNE(p, longDer);
  48495. ExpectNotNull(dup = wolfSSL_ASN1_INTEGER_dup(a));
  48496. ASN1_INTEGER_free(dup);
  48497. ASN1_INTEGER_free(a);
  48498. #endif
  48499. return EXPECT_RESULT();
  48500. }
  48501. static int test_wolfSSL_ASN1_INTEGER_cmp(void)
  48502. {
  48503. EXPECT_DECLS;
  48504. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  48505. ASN1_INTEGER* a = NULL;
  48506. ASN1_INTEGER* b = NULL;
  48507. ExpectNotNull(a = ASN1_INTEGER_new());
  48508. ExpectNotNull(b = ASN1_INTEGER_new());
  48509. ExpectIntEQ(ASN1_INTEGER_set(a, 1), 1);
  48510. ExpectIntEQ(ASN1_INTEGER_set(b, 1), 1);
  48511. /* Invalid parameter testing. */
  48512. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(NULL, NULL), -1);
  48513. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, NULL), -1);
  48514. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(NULL, b), -1);
  48515. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  48516. ExpectIntEQ(ASN1_INTEGER_set(b, -1), 1);
  48517. ExpectIntGT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  48518. ExpectIntEQ(ASN1_INTEGER_set(a, -2), 1);
  48519. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  48520. ExpectIntEQ(ASN1_INTEGER_set(b, 1), 1);
  48521. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  48522. ExpectIntEQ(ASN1_INTEGER_set(a, 0x01), 1);
  48523. ExpectIntEQ(ASN1_INTEGER_set(b, 0x1000), 1);
  48524. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  48525. ExpectIntGT(wolfSSL_ASN1_INTEGER_cmp(b, a), 0);
  48526. ASN1_INTEGER_free(b);
  48527. ASN1_INTEGER_free(a);
  48528. #endif
  48529. return EXPECT_RESULT();
  48530. }
  48531. static int test_wolfSSL_ASN1_INTEGER_BN(void)
  48532. {
  48533. EXPECT_DECLS;
  48534. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  48535. ASN1_INTEGER* ai = NULL;
  48536. ASN1_INTEGER* ai2 = NULL;
  48537. BIGNUM* bn = NULL;
  48538. BIGNUM* bn2 = NULL;
  48539. ExpectNotNull(ai = ASN1_INTEGER_new());
  48540. ExpectNotNull(bn2 = BN_new());
  48541. /* Invalid parameter testing. */
  48542. ExpectNull(bn = ASN1_INTEGER_to_BN(NULL, NULL));
  48543. ExpectNull(ai2 = BN_to_ASN1_INTEGER(NULL, NULL));
  48544. /* at the moment hard setting since no set function */
  48545. if (ai != NULL) {
  48546. ai->data[0] = 0xff; /* No DER encoding. */
  48547. ai->length = 1;
  48548. }
  48549. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  48550. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  48551. BN_free(bn);
  48552. bn = NULL;
  48553. #else
  48554. ExpectNull(ASN1_INTEGER_to_BN(ai, NULL));
  48555. #endif
  48556. if (ai != NULL) {
  48557. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  48558. ai->data[1] = 0x04; /* bad length of integer */
  48559. ai->data[2] = 0x03;
  48560. ai->length = 3;
  48561. }
  48562. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  48563. /* Interpreted as a number 0x020403. */
  48564. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  48565. BN_free(bn);
  48566. bn = NULL;
  48567. #else
  48568. ExpectNull(ASN1_INTEGER_to_BN(ai, NULL));
  48569. #endif
  48570. if (ai != NULL) {
  48571. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  48572. ai->data[1] = 0x01; /* length of integer */
  48573. ai->data[2] = 0x03;
  48574. ai->length = 3;
  48575. }
  48576. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  48577. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, NULL));
  48578. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  48579. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  48580. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  48581. if (ai != NULL) {
  48582. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  48583. ai->data[1] = 0x02; /* length of integer */
  48584. ai->data[2] = 0x00; /* padding byte to ensure positive */
  48585. ai->data[3] = 0xff;
  48586. ai->length = 4;
  48587. }
  48588. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  48589. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  48590. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  48591. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  48592. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  48593. if (ai != NULL) {
  48594. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  48595. ai->data[1] = 0x01; /* length of integer */
  48596. ai->data[2] = 0x00;
  48597. ai->length = 3;
  48598. }
  48599. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  48600. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  48601. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  48602. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  48603. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  48604. if (ai != NULL) {
  48605. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  48606. ai->data[1] = 0x01; /* length of integer */
  48607. ai->data[2] = 0x01;
  48608. ai->length = 3;
  48609. ai->negative = 1;
  48610. }
  48611. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  48612. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  48613. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  48614. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  48615. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  48616. BN_free(bn2);
  48617. BN_free(bn);
  48618. ASN1_INTEGER_free(ai2);
  48619. ASN1_INTEGER_free(ai);
  48620. #endif
  48621. return EXPECT_RESULT();
  48622. }
  48623. static int test_wolfSSL_ASN1_INTEGER_get_set(void)
  48624. {
  48625. EXPECT_DECLS;
  48626. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  48627. ASN1_INTEGER *a = NULL;
  48628. long val;
  48629. ExpectNotNull(a = ASN1_INTEGER_new());
  48630. /* Invalid parameter testing. */
  48631. ExpectIntEQ(ASN1_INTEGER_get(NULL), 0);
  48632. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  48633. ExpectIntEQ(ASN1_INTEGER_get(a), 0);
  48634. #else
  48635. ExpectIntEQ(ASN1_INTEGER_get(a), -1);
  48636. #endif
  48637. ASN1_INTEGER_free(a);
  48638. a = NULL;
  48639. ExpectNotNull(a = ASN1_INTEGER_new());
  48640. val = 0;
  48641. ExpectIntEQ(ASN1_INTEGER_set(NULL, val), 0);
  48642. ASN1_INTEGER_free(a);
  48643. a = NULL;
  48644. /* 0 */
  48645. ExpectNotNull(a = ASN1_INTEGER_new());
  48646. val = 0;
  48647. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48648. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48649. ASN1_INTEGER_free(a);
  48650. a = NULL;
  48651. /* 40 */
  48652. ExpectNotNull(a = ASN1_INTEGER_new());
  48653. val = 40;
  48654. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48655. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48656. ASN1_INTEGER_free(a);
  48657. a = NULL;
  48658. /* -40 */
  48659. ExpectNotNull(a = ASN1_INTEGER_new());
  48660. val = -40;
  48661. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48662. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48663. ASN1_INTEGER_free(a);
  48664. a = NULL;
  48665. /* 128 */
  48666. ExpectNotNull(a = ASN1_INTEGER_new());
  48667. val = 128;
  48668. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48669. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48670. ASN1_INTEGER_free(a);
  48671. a = NULL;
  48672. /* -128 */
  48673. ExpectNotNull(a = ASN1_INTEGER_new());
  48674. val = -128;
  48675. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48676. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48677. ASN1_INTEGER_free(a);
  48678. a = NULL;
  48679. /* 200 */
  48680. ExpectNotNull(a = ASN1_INTEGER_new());
  48681. val = 200;
  48682. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48683. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48684. ASN1_INTEGER_free(a);
  48685. a = NULL;
  48686. /* int max (2147483647) */
  48687. ExpectNotNull(a = ASN1_INTEGER_new());
  48688. val = 2147483647;
  48689. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48690. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48691. ASN1_INTEGER_free(a);
  48692. a = NULL;
  48693. /* int min (-2147483648) */
  48694. ExpectNotNull(a = ASN1_INTEGER_new());
  48695. val = -2147483647 - 1;
  48696. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48697. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48698. ASN1_INTEGER_free(a);
  48699. a = NULL;
  48700. /* long max positive */
  48701. ExpectNotNull(a = ASN1_INTEGER_new());
  48702. val = (long)(((unsigned long)-1) >> 1);
  48703. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48704. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48705. ASN1_INTEGER_free(a);
  48706. #endif
  48707. return EXPECT_RESULT();
  48708. }
  48709. #if defined(OPENSSL_EXTRA)
  48710. typedef struct ASN1IntTestVector {
  48711. const byte* der;
  48712. const size_t derSz;
  48713. const long value;
  48714. } ASN1IntTestVector;
  48715. #endif
  48716. static int test_wolfSSL_d2i_ASN1_INTEGER(void)
  48717. {
  48718. EXPECT_DECLS;
  48719. #if defined(OPENSSL_EXTRA)
  48720. size_t i;
  48721. WOLFSSL_ASN1_INTEGER* a = NULL;
  48722. WOLFSSL_ASN1_INTEGER* b = NULL;
  48723. WOLFSSL_ASN1_INTEGER* c = NULL;
  48724. const byte* p = NULL;
  48725. byte* p2 = NULL;
  48726. byte* reEncoded = NULL;
  48727. int reEncodedSz = 0;
  48728. static const byte zeroDer[] = {
  48729. 0x02, 0x01, 0x00
  48730. };
  48731. static const byte oneDer[] = {
  48732. 0x02, 0x01, 0x01
  48733. };
  48734. static const byte negativeDer[] = {
  48735. 0x02, 0x03, 0xC1, 0x16, 0x0D
  48736. };
  48737. static const byte positiveDer[] = {
  48738. 0x02, 0x03, 0x01, 0x00, 0x01
  48739. };
  48740. static const byte primeDer[] = {
  48741. 0x02, 0x82, 0x01, 0x01, 0x00, 0xc0, 0x95, 0x08, 0xe1, 0x57, 0x41,
  48742. 0xf2, 0x71, 0x6d, 0xb7, 0xd2, 0x45, 0x41, 0x27, 0x01, 0x65, 0xc6,
  48743. 0x45, 0xae, 0xf2, 0xbc, 0x24, 0x30, 0xb8, 0x95, 0xce, 0x2f, 0x4e,
  48744. 0xd6, 0xf6, 0x1c, 0x88, 0xbc, 0x7c, 0x9f, 0xfb, 0xa8, 0x67, 0x7f,
  48745. 0xfe, 0x5c, 0x9c, 0x51, 0x75, 0xf7, 0x8a, 0xca, 0x07, 0xe7, 0x35,
  48746. 0x2f, 0x8f, 0xe1, 0xbd, 0x7b, 0xc0, 0x2f, 0x7c, 0xab, 0x64, 0xa8,
  48747. 0x17, 0xfc, 0xca, 0x5d, 0x7b, 0xba, 0xe0, 0x21, 0xe5, 0x72, 0x2e,
  48748. 0x6f, 0x2e, 0x86, 0xd8, 0x95, 0x73, 0xda, 0xac, 0x1b, 0x53, 0xb9,
  48749. 0x5f, 0x3f, 0xd7, 0x19, 0x0d, 0x25, 0x4f, 0xe1, 0x63, 0x63, 0x51,
  48750. 0x8b, 0x0b, 0x64, 0x3f, 0xad, 0x43, 0xb8, 0xa5, 0x1c, 0x5c, 0x34,
  48751. 0xb3, 0xae, 0x00, 0xa0, 0x63, 0xc5, 0xf6, 0x7f, 0x0b, 0x59, 0x68,
  48752. 0x78, 0x73, 0xa6, 0x8c, 0x18, 0xa9, 0x02, 0x6d, 0xaf, 0xc3, 0x19,
  48753. 0x01, 0x2e, 0xb8, 0x10, 0xe3, 0xc6, 0xcc, 0x40, 0xb4, 0x69, 0xa3,
  48754. 0x46, 0x33, 0x69, 0x87, 0x6e, 0xc4, 0xbb, 0x17, 0xa6, 0xf3, 0xe8,
  48755. 0xdd, 0xad, 0x73, 0xbc, 0x7b, 0x2f, 0x21, 0xb5, 0xfd, 0x66, 0x51,
  48756. 0x0c, 0xbd, 0x54, 0xb3, 0xe1, 0x6d, 0x5f, 0x1c, 0xbc, 0x23, 0x73,
  48757. 0xd1, 0x09, 0x03, 0x89, 0x14, 0xd2, 0x10, 0xb9, 0x64, 0xc3, 0x2a,
  48758. 0xd0, 0xa1, 0x96, 0x4a, 0xbc, 0xe1, 0xd4, 0x1a, 0x5b, 0xc7, 0xa0,
  48759. 0xc0, 0xc1, 0x63, 0x78, 0x0f, 0x44, 0x37, 0x30, 0x32, 0x96, 0x80,
  48760. 0x32, 0x23, 0x95, 0xa1, 0x77, 0xba, 0x13, 0xd2, 0x97, 0x73, 0xe2,
  48761. 0x5d, 0x25, 0xc9, 0x6a, 0x0d, 0xc3, 0x39, 0x60, 0xa4, 0xb4, 0xb0,
  48762. 0x69, 0x42, 0x42, 0x09, 0xe9, 0xd8, 0x08, 0xbc, 0x33, 0x20, 0xb3,
  48763. 0x58, 0x22, 0xa7, 0xaa, 0xeb, 0xc4, 0xe1, 0xe6, 0x61, 0x83, 0xc5,
  48764. 0xd2, 0x96, 0xdf, 0xd9, 0xd0, 0x4f, 0xad, 0xd7
  48765. };
  48766. static const byte garbageDer[] = {0xDE, 0xAD, 0xBE, 0xEF};
  48767. static const ASN1IntTestVector testVectors[] = {
  48768. {zeroDer, sizeof(zeroDer), 0},
  48769. {oneDer, sizeof(oneDer), 1},
  48770. {negativeDer, sizeof(negativeDer), -4123123},
  48771. {positiveDer, sizeof(positiveDer), 65537},
  48772. {primeDer, sizeof(primeDer), 0}
  48773. };
  48774. static const size_t NUM_TEST_VECTORS =
  48775. sizeof(testVectors)/sizeof(testVectors[0]);
  48776. /* Check d2i error conditions */
  48777. /* NULL pointer to input. */
  48778. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, NULL, 1)));
  48779. ExpectNull(b);
  48780. /* NULL input. */
  48781. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, 1)));
  48782. ExpectNull(b);
  48783. /* 0 length. */
  48784. p = testVectors[0].der;
  48785. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, 0)));
  48786. ExpectNull(b);
  48787. /* Negative length. */
  48788. p = testVectors[0].der;
  48789. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, -1)));
  48790. ExpectNull(b);
  48791. /* Garbage DER input. */
  48792. p = garbageDer;
  48793. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, sizeof(garbageDer))));
  48794. ExpectNull(b);
  48795. /* Check i2d error conditions */
  48796. /* NULL input. */
  48797. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(NULL, &p2), 0);
  48798. /* 0 length input data buffer (a->length == 0). */
  48799. ExpectNotNull((a = wolfSSL_ASN1_INTEGER_new()));
  48800. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(a, &p2), 0);
  48801. if (a != NULL)
  48802. a->data = NULL;
  48803. /* NULL input data buffer. */
  48804. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(a, &p2), 0);
  48805. if (a != NULL) {
  48806. /* Reset a->data. */
  48807. a->data = a->intData;
  48808. }
  48809. /* Set a to valid value. */
  48810. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(a, 1), WOLFSSL_SUCCESS);
  48811. /* NULL output buffer. */
  48812. ExpectIntEQ(wolfSSL_i2d_ASN1_INTEGER(a, NULL), 3);
  48813. wolfSSL_ASN1_INTEGER_free(a);
  48814. a = NULL;
  48815. for (i = 0; i < NUM_TEST_VECTORS; ++i) {
  48816. p = testVectors[i].der;
  48817. ExpectNotNull(a = wolfSSL_d2i_ASN1_INTEGER(&b, &p,
  48818. testVectors[i].derSz));
  48819. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  48820. if (testVectors[i].derSz <= sizeof(long)) {
  48821. ExpectNotNull(c = wolfSSL_ASN1_INTEGER_new());
  48822. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(c, testVectors[i].value), 1);
  48823. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, c), 0);
  48824. wolfSSL_ASN1_INTEGER_free(c);
  48825. c = NULL;
  48826. }
  48827. /* Convert to DER without a pre-allocated output buffer. */
  48828. ExpectIntGT((reEncodedSz = wolfSSL_i2d_ASN1_INTEGER(a, &reEncoded)), 0);
  48829. ExpectIntEQ(reEncodedSz, testVectors[i].derSz);
  48830. ExpectIntEQ(XMEMCMP(reEncoded, testVectors[i].der, reEncodedSz), 0);
  48831. /* Convert to DER with a pre-allocated output buffer. In this case, the
  48832. * output buffer pointer should be incremented just past the end of the
  48833. * encoded data. */
  48834. p2 = reEncoded;
  48835. ExpectIntGT((reEncodedSz = wolfSSL_i2d_ASN1_INTEGER(a, &p2)), 0);
  48836. ExpectIntEQ(reEncodedSz, testVectors[i].derSz);
  48837. ExpectPtrEq(reEncoded, p2 - reEncodedSz);
  48838. ExpectIntEQ(XMEMCMP(reEncoded, testVectors[i].der, reEncodedSz), 0);
  48839. XFREE(reEncoded, NULL, DYNAMIC_TYPE_ASN1);
  48840. reEncoded = NULL;
  48841. wolfSSL_ASN1_INTEGER_free(a);
  48842. a = NULL;
  48843. }
  48844. #endif /* OPENSSL_EXTRA */
  48845. return EXPECT_RESULT();
  48846. }
  48847. static int test_wolfSSL_a2i_ASN1_INTEGER(void)
  48848. {
  48849. EXPECT_DECLS;
  48850. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  48851. BIO* bio = NULL;
  48852. BIO* out = NULL;
  48853. BIO* fixed = NULL;
  48854. ASN1_INTEGER* ai = NULL;
  48855. char buf[] = "123456\n12345\n1123456789123456\\\n78901234567890 \r\n\n";
  48856. char tmp[1024];
  48857. int tmpSz;
  48858. const char expected1[] = "123456";
  48859. const char expected2[] = "112345678912345678901234567890";
  48860. char longStr[] = "123456781234567812345678123456781234567812345678\n"
  48861. "123456781234567812345678123456781234567812345678\\\n12345678\n";
  48862. ExpectNotNull(out = BIO_new(BIO_s_mem()));
  48863. ExpectNotNull(ai = ASN1_INTEGER_new());
  48864. ExpectNotNull(bio = BIO_new_mem_buf(buf, -1));
  48865. /* Invalid parameter testing. */
  48866. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, NULL, -1), 0);
  48867. ExpectIntEQ(a2i_ASN1_INTEGER(bio, NULL, NULL, -1), 0);
  48868. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, ai, NULL, -1), 0);
  48869. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, tmp, -1), 0);
  48870. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, NULL, 1024), 0);
  48871. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, ai, tmp, 1024), 0);
  48872. ExpectIntEQ(a2i_ASN1_INTEGER(bio, NULL, tmp, 1024), 0);
  48873. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, NULL, 1024), 0);
  48874. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, -1), 0);
  48875. ExpectIntEQ(i2a_ASN1_INTEGER(NULL, NULL), 0);
  48876. ExpectIntEQ(i2a_ASN1_INTEGER(bio, NULL), 0);
  48877. ExpectIntEQ(i2a_ASN1_INTEGER(NULL, ai), 0);
  48878. /* No data to read from BIO. */
  48879. ExpectIntEQ(a2i_ASN1_INTEGER(out, ai, tmp, 1024), 0);
  48880. /* read first line */
  48881. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  48882. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 6);
  48883. XMEMSET(tmp, 0, 1024);
  48884. tmpSz = BIO_read(out, tmp, 1024);
  48885. ExpectIntEQ(tmpSz, 6);
  48886. ExpectIntEQ(XMEMCMP(tmp, expected1, tmpSz), 0);
  48887. /* fail on second line (not % 2) */
  48888. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 0);
  48889. /* read 3rd long line */
  48890. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  48891. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 30);
  48892. XMEMSET(tmp, 0, 1024);
  48893. tmpSz = BIO_read(out, tmp, 1024);
  48894. ExpectIntEQ(tmpSz, 30);
  48895. ExpectIntEQ(XMEMCMP(tmp, expected2, tmpSz), 0);
  48896. /* fail on empty line */
  48897. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 0);
  48898. BIO_free(bio);
  48899. bio = NULL;
  48900. /* Make long integer, requiring dynamic memory, even longer. */
  48901. ExpectNotNull(bio = BIO_new_mem_buf(longStr, -1));
  48902. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  48903. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 48);
  48904. XMEMSET(tmp, 0, 1024);
  48905. tmpSz = BIO_read(out, tmp, 1024);
  48906. ExpectIntEQ(tmpSz, 48);
  48907. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  48908. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 56);
  48909. XMEMSET(tmp, 0, 1024);
  48910. tmpSz = BIO_read(out, tmp, 1024);
  48911. ExpectIntEQ(tmpSz, 56);
  48912. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(ai, 1), 1);
  48913. BIO_free(bio);
  48914. BIO_free(out);
  48915. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  48916. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48917. /* Ensure there is 0 bytes available to write into. */
  48918. ExpectIntEQ(BIO_write(fixed, tmp, 1), 1);
  48919. ExpectIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0);
  48920. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48921. ExpectIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0);
  48922. BIO_free(fixed);
  48923. ASN1_INTEGER_free(ai);
  48924. #endif
  48925. return EXPECT_RESULT();
  48926. }
  48927. static int test_wolfSSL_i2c_ASN1_INTEGER(void)
  48928. {
  48929. EXPECT_DECLS;
  48930. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  48931. ASN1_INTEGER *a = NULL;
  48932. unsigned char *pp = NULL,*tpp = NULL;
  48933. int ret = 0;
  48934. ExpectNotNull(a = wolfSSL_ASN1_INTEGER_new());
  48935. /* Invalid parameter testing. */
  48936. /* Set pp to an invalid value. */
  48937. pp = NULL;
  48938. ExpectIntEQ(i2c_ASN1_INTEGER(NULL, &pp), 0);
  48939. ExpectIntEQ(i2c_ASN1_INTEGER(a, &pp), 0);
  48940. ExpectIntEQ(i2c_ASN1_INTEGER(NULL, NULL), 0);
  48941. /* 40 */
  48942. if (a != NULL) {
  48943. a->intData[0] = ASN_INTEGER;
  48944. a->intData[1] = 1;
  48945. a->intData[2] = 40;
  48946. }
  48947. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  48948. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48949. DYNAMIC_TYPE_TMP_BUFFER));
  48950. tpp = pp;
  48951. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48952. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  48953. tpp--;
  48954. ExpectIntEQ(*tpp, 40);
  48955. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48956. pp = NULL;
  48957. /* 128 */
  48958. if (a != NULL) {
  48959. a->intData[0] = ASN_INTEGER;
  48960. a->intData[1] = 1;
  48961. a->intData[2] = 128;
  48962. }
  48963. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  48964. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48965. DYNAMIC_TYPE_TMP_BUFFER));
  48966. tpp = pp;
  48967. if (tpp != NULL) {
  48968. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48969. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  48970. tpp--;
  48971. ExpectIntEQ(*(tpp--), 128);
  48972. ExpectIntEQ(*tpp, 0);
  48973. }
  48974. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48975. pp = NULL;
  48976. /* -40 */
  48977. if (a != NULL) {
  48978. a->intData[0] = ASN_INTEGER;
  48979. a->intData[1] = 1;
  48980. a->intData[2] = 40;
  48981. a->negative = 1;
  48982. }
  48983. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  48984. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48985. DYNAMIC_TYPE_TMP_BUFFER));
  48986. tpp = pp;
  48987. if (tpp != NULL) {
  48988. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48989. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  48990. tpp--;
  48991. ExpectIntEQ(*tpp, 216);
  48992. }
  48993. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48994. pp = NULL;
  48995. /* -128 */
  48996. if (a != NULL) {
  48997. a->intData[0] = ASN_INTEGER;
  48998. a->intData[1] = 1;
  48999. a->intData[2] = 128;
  49000. a->negative = 1;
  49001. }
  49002. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  49003. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  49004. DYNAMIC_TYPE_TMP_BUFFER));
  49005. tpp = pp;
  49006. if (tpp != NULL) {
  49007. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  49008. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  49009. tpp--;
  49010. ExpectIntEQ(*tpp, 128);
  49011. }
  49012. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49013. pp = NULL;
  49014. /* -200 */
  49015. if (a != NULL) {
  49016. a->intData[0] = ASN_INTEGER;
  49017. a->intData[1] = 1;
  49018. a->intData[2] = 200;
  49019. a->negative = 1;
  49020. }
  49021. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  49022. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  49023. DYNAMIC_TYPE_TMP_BUFFER));
  49024. tpp = pp;
  49025. if (tpp != NULL) {
  49026. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  49027. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  49028. tpp--;
  49029. ExpectIntEQ(*(tpp--), 56);
  49030. ExpectIntEQ(*tpp, 255);
  49031. }
  49032. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49033. pp = NULL;
  49034. /* Empty */
  49035. if (a != NULL) {
  49036. a->intData[0] = ASN_INTEGER;
  49037. a->intData[1] = 0;
  49038. a->negative = 0;
  49039. }
  49040. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  49041. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  49042. DYNAMIC_TYPE_TMP_BUFFER));
  49043. tpp = pp;
  49044. if (tpp != NULL) {
  49045. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  49046. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  49047. tpp--;
  49048. ExpectIntEQ(*tpp, 0);
  49049. }
  49050. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49051. pp = NULL;
  49052. /* 0 */
  49053. if (a != NULL) {
  49054. a->intData[0] = ASN_INTEGER;
  49055. a->intData[1] = 1;
  49056. a->intData[2] = 0;
  49057. a->negative = 1;
  49058. }
  49059. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  49060. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  49061. DYNAMIC_TYPE_TMP_BUFFER));
  49062. if (tpp != NULL) {
  49063. tpp = pp;
  49064. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  49065. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  49066. tpp--;
  49067. ExpectIntEQ(*tpp, 0);
  49068. }
  49069. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49070. pp = NULL;
  49071. /* 0x100 */
  49072. if (a != NULL) {
  49073. a->intData[0] = ASN_INTEGER;
  49074. a->intData[1] = 2;
  49075. a->intData[2] = 0x01;
  49076. a->intData[3] = 0x00;
  49077. a->negative = 0;
  49078. }
  49079. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  49080. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  49081. DYNAMIC_TYPE_TMP_BUFFER));
  49082. if (tpp != NULL) {
  49083. tpp = pp;
  49084. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  49085. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  49086. tpp -= 2;
  49087. ExpectIntEQ(tpp[0], 0x01);
  49088. ExpectIntEQ(tpp[1], 0x00);
  49089. }
  49090. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49091. pp = NULL;
  49092. /* -0x8000 => 0x8000 */
  49093. if (a != NULL) {
  49094. a->intData[0] = ASN_INTEGER;
  49095. a->intData[1] = 2;
  49096. a->intData[2] = 0x80;
  49097. a->intData[3] = 0x00;
  49098. a->negative = 1;
  49099. }
  49100. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  49101. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  49102. DYNAMIC_TYPE_TMP_BUFFER));
  49103. tpp = pp;
  49104. if (tpp != NULL) {
  49105. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  49106. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  49107. tpp -= 2;
  49108. ExpectIntEQ(tpp[0], 0x80);
  49109. ExpectIntEQ(tpp[1], 0x00);
  49110. }
  49111. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49112. pp = NULL;
  49113. /* -0x8001 => 0xFF7FFF */
  49114. if (a != NULL) {
  49115. a->intData[0] = ASN_INTEGER;
  49116. a->intData[1] = 2;
  49117. a->intData[2] = 0x80;
  49118. a->intData[3] = 0x01;
  49119. a->negative = 1;
  49120. }
  49121. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 3);
  49122. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  49123. DYNAMIC_TYPE_TMP_BUFFER));
  49124. tpp = pp;
  49125. if (tpp != NULL) {
  49126. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  49127. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 3);
  49128. tpp -= 3;
  49129. ExpectIntEQ(tpp[0], 0xFF);
  49130. ExpectIntEQ(tpp[1], 0x7F);
  49131. ExpectIntEQ(tpp[2], 0xFF);
  49132. }
  49133. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49134. wolfSSL_ASN1_INTEGER_free(a);
  49135. #endif /* OPENSSL_EXTRA && !NO_ASN */
  49136. return EXPECT_RESULT();
  49137. }
  49138. static int test_wolfSSL_ASN1_OBJECT(void)
  49139. {
  49140. EXPECT_DECLS;
  49141. #if defined(OPENSSL_EXTRA)
  49142. ASN1_OBJECT* a = NULL;
  49143. ASN1_OBJECT s;
  49144. const unsigned char der[] = { 0x06, 0x01, 0x00 };
  49145. /* Invalid parameter testing. */
  49146. ASN1_OBJECT_free(NULL);
  49147. ExpectNull(wolfSSL_ASN1_OBJECT_dup(NULL));
  49148. /* Test that a static ASN1_OBJECT can be freed. */
  49149. XMEMSET(&s, 0, sizeof(ASN1_OBJECT));
  49150. ASN1_OBJECT_free(&s);
  49151. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_dup(&s));
  49152. ASN1_OBJECT_free(a);
  49153. a = NULL;
  49154. s.obj = der;
  49155. s.objSz = sizeof(der);
  49156. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_dup(&s));
  49157. ASN1_OBJECT_free(a);
  49158. ASN1_OBJECT_free(&s);
  49159. #endif /* OPENSSL_EXTRA */
  49160. return EXPECT_RESULT();
  49161. }
  49162. static int test_wolfSSL_ASN1_get_object(void)
  49163. {
  49164. EXPECT_DECLS;
  49165. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  49166. const unsigned char* derBuf = cliecc_cert_der_256;
  49167. const unsigned char* nullPtr = NULL;
  49168. const unsigned char objDerInvalidLen[] = { 0x30, 0x81 };
  49169. const unsigned char objDerBadLen[] = { 0x30, 0x04 };
  49170. const unsigned char objDerNotObj[] = { 0x02, 0x01, 0x00 };
  49171. const unsigned char objDerNoData[] = { 0x06, 0x00 };
  49172. const unsigned char* p;
  49173. unsigned char objDer[10];
  49174. unsigned char* der;
  49175. unsigned char* derPtr;
  49176. int len = sizeof_cliecc_cert_der_256;
  49177. long asnLen = 0;
  49178. int tag = 0;
  49179. int cls = 0;
  49180. ASN1_OBJECT* a = NULL;
  49181. ASN1_OBJECT s;
  49182. XMEMSET(&s, 0, sizeof(ASN1_OBJECT));
  49183. /* Invalid encoding at length. */
  49184. p = objDerInvalidLen;
  49185. ExpectIntEQ(ASN1_get_object(&p, &asnLen, &tag, &cls, sizeof(objDerBadLen)),
  49186. 0x80);
  49187. p = objDerBadLen;
  49188. /* Error = 0x80, Constructed = 0x20 */
  49189. ExpectIntEQ(ASN1_get_object(&p, &asnLen, &tag, &cls, sizeof(objDerBadLen)),
  49190. 0x80 | 0x20);
  49191. /* Read a couple TLV triplets and make sure they match the expected values
  49192. */
  49193. /* SEQUENCE */
  49194. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, len) & 0x80, 0);
  49195. ExpectIntEQ(asnLen, 861);
  49196. ExpectIntEQ(tag, 0x10);
  49197. ExpectIntEQ(cls, 0);
  49198. /* SEQUENCE */
  49199. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  49200. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  49201. ExpectIntEQ(asnLen, 772);
  49202. ExpectIntEQ(tag, 0x10);
  49203. ExpectIntEQ(cls, 0);
  49204. /* [0] */
  49205. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  49206. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  49207. ExpectIntEQ(asnLen, 3);
  49208. ExpectIntEQ(tag, 0);
  49209. ExpectIntEQ(cls, 0x80);
  49210. /* INTEGER */
  49211. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  49212. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  49213. ExpectIntEQ(asnLen, 1);
  49214. ExpectIntEQ(tag, 0x2);
  49215. ExpectIntEQ(cls, 0);
  49216. derBuf += asnLen;
  49217. /* INTEGER */
  49218. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  49219. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  49220. ExpectIntEQ(asnLen, 20);
  49221. ExpectIntEQ(tag, 0x2);
  49222. ExpectIntEQ(cls, 0);
  49223. derBuf += asnLen;
  49224. /* SEQUENCE */
  49225. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  49226. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  49227. ExpectIntEQ(asnLen, 10);
  49228. ExpectIntEQ(tag, 0x10);
  49229. ExpectIntEQ(cls, 0);
  49230. /* Found OBJECT_ID. */
  49231. /* Invalid parameter testing. */
  49232. ExpectIntEQ(ASN1_get_object(NULL, NULL, NULL, NULL, 0), 0x80);
  49233. ExpectIntEQ(ASN1_get_object(&nullPtr, NULL, NULL, NULL, 0), 0x80);
  49234. ExpectIntEQ(ASN1_get_object(NULL, &asnLen, &tag, &cls, len), 0x80);
  49235. ExpectIntEQ(ASN1_get_object(&nullPtr, &asnLen, &tag, &cls, len), 0x80);
  49236. ExpectIntEQ(ASN1_get_object(&derBuf, NULL, &tag, &cls, len), 0x80);
  49237. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, NULL, &cls, len), 0x80);
  49238. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, NULL, len), 0x80);
  49239. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, 0), 0x80);
  49240. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, -1), 0x80);
  49241. ExpectNull(d2i_ASN1_OBJECT(NULL, NULL, -1));
  49242. ExpectNull(d2i_ASN1_OBJECT(NULL, &nullPtr, -1));
  49243. ExpectNull(d2i_ASN1_OBJECT(NULL, &derBuf, -1));
  49244. ExpectNull(d2i_ASN1_OBJECT(NULL, NULL, 0));
  49245. ExpectNull(d2i_ASN1_OBJECT(&a, NULL, len));
  49246. ExpectNull(d2i_ASN1_OBJECT(&a, &nullPtr, len));
  49247. ExpectNull(d2i_ASN1_OBJECT(&a, &derBuf, -1));
  49248. ExpectNull(c2i_ASN1_OBJECT(NULL, NULL, -1));
  49249. ExpectNull(c2i_ASN1_OBJECT(NULL, &nullPtr, -1));
  49250. ExpectNull(c2i_ASN1_OBJECT(NULL, &derBuf, -1));
  49251. ExpectNull(c2i_ASN1_OBJECT(NULL, NULL, 1));
  49252. ExpectNull(c2i_ASN1_OBJECT(NULL, &nullPtr, 1));
  49253. /* Invalid encoding at length. */
  49254. p = objDerInvalidLen;
  49255. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerInvalidLen)));
  49256. p = objDerBadLen;
  49257. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerBadLen)));
  49258. p = objDerNotObj;
  49259. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerNotObj)));
  49260. p = objDerNoData;
  49261. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerNoData)));
  49262. /* Create an ASN OBJECT from content */
  49263. p = derBuf + 2;
  49264. ExpectNotNull(a = c2i_ASN1_OBJECT(NULL, &p, 8));
  49265. ASN1_OBJECT_free(a);
  49266. a = NULL;
  49267. /* Create an ASN OBJECT from DER */
  49268. ExpectNotNull(d2i_ASN1_OBJECT(&a, &derBuf, len));
  49269. /* Invalid parameter testing. */
  49270. ExpectIntEQ(i2d_ASN1_OBJECT(NULL, NULL), 0);
  49271. ExpectIntEQ(i2d_ASN1_OBJECT(&s, NULL), 0);
  49272. ExpectIntEQ(i2d_ASN1_OBJECT(a, NULL), 10);
  49273. der = NULL;
  49274. ExpectIntEQ(i2d_ASN1_OBJECT(a, &der), 10);
  49275. derPtr = objDer;
  49276. ExpectIntEQ(i2d_ASN1_OBJECT(a, &derPtr), 10);
  49277. ExpectPtrNE(derPtr, objDer);
  49278. ExpectIntEQ(XMEMCMP(der, objDer, 10), 0);
  49279. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  49280. ASN1_OBJECT_free(a);
  49281. #endif /* OPENSSL_EXTRA && HAVE_ECC && USE_CERT_BUFFERS_256 */
  49282. return EXPECT_RESULT();
  49283. }
  49284. static int test_wolfSSL_i2a_ASN1_OBJECT(void)
  49285. {
  49286. EXPECT_DECLS;
  49287. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(NO_BIO)
  49288. ASN1_OBJECT* obj = NULL;
  49289. ASN1_OBJECT* a = NULL;
  49290. BIO *bio = NULL;
  49291. const unsigned char notObjDer[] = { 0x04, 0x01, 0xff };
  49292. const unsigned char* p;
  49293. ExpectNotNull(obj = OBJ_nid2obj(NID_sha256));
  49294. ExpectTrue((bio = BIO_new(BIO_s_mem())) != NULL);
  49295. ExpectIntGT(wolfSSL_i2a_ASN1_OBJECT(bio, obj), 0);
  49296. ExpectIntGT(wolfSSL_i2a_ASN1_OBJECT(bio, NULL), 0);
  49297. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(NULL, obj), 0);
  49298. /* No DER encoding in ASN1_OBJECT. */
  49299. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_new());
  49300. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(bio, a), 0);
  49301. ASN1_OBJECT_free(a);
  49302. a = NULL;
  49303. /* DER encoding */
  49304. p = notObjDer;
  49305. ExpectNotNull(a = c2i_ASN1_OBJECT(NULL, &p, 3));
  49306. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(bio, a), 5);
  49307. ASN1_OBJECT_free(a);
  49308. BIO_free(bio);
  49309. ASN1_OBJECT_free(obj);
  49310. #endif
  49311. return EXPECT_RESULT();
  49312. }
  49313. static int test_wolfSSL_i2t_ASN1_OBJECT(void)
  49314. {
  49315. EXPECT_DECLS;
  49316. #if defined(OPENSSL_EXTRA) && \
  49317. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  49318. char buf[50] = {0};
  49319. ASN1_OBJECT* obj;
  49320. const char* oid = "2.5.29.19";
  49321. const char* ln = "X509v3 Basic Constraints";
  49322. obj = NULL;
  49323. ExpectIntEQ(i2t_ASN1_OBJECT(NULL, sizeof(buf), obj), 0);
  49324. ExpectIntEQ(i2t_ASN1_OBJECT(buf, sizeof(buf), NULL), 0);
  49325. ExpectIntEQ(i2t_ASN1_OBJECT(buf, 0, NULL), 0);
  49326. ExpectNotNull(obj = OBJ_txt2obj(oid, 0));
  49327. XMEMSET(buf, 0, sizeof(buf));
  49328. ExpectIntEQ(i2t_ASN1_OBJECT(buf, sizeof(buf), obj), XSTRLEN(ln));
  49329. ExpectIntEQ(XSTRNCMP(buf, ln, XSTRLEN(ln)), 0);
  49330. ASN1_OBJECT_free(obj);
  49331. #endif /* OPENSSL_EXTRA && WOLFSSL_CERT_EXT && WOLFSSL_CERT_GEN */
  49332. return EXPECT_RESULT();
  49333. }
  49334. static int test_wolfSSL_sk_ASN1_OBJECT(void)
  49335. {
  49336. EXPECT_DECLS;
  49337. #if !defined(NO_ASN) && (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL))
  49338. WOLFSSL_STACK* sk = NULL;
  49339. WOLFSSL_ASN1_OBJECT* obj;
  49340. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  49341. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  49342. wolfSSL_sk_ASN1_OBJECT_free(sk);
  49343. sk = NULL;
  49344. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  49345. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(NULL, NULL), -1);
  49346. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, NULL), 0);
  49347. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(NULL, obj), -1);
  49348. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, obj), 1);
  49349. wolfSSL_sk_ASN1_OBJECT_pop_free(sk, NULL);
  49350. sk = NULL;
  49351. /* obj freed in pop_free call. */
  49352. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  49353. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  49354. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, obj), 1);
  49355. ExpectPtrEq(obj, wolfSSL_sk_ASN1_OBJECT_pop(sk));
  49356. wolfSSL_sk_ASN1_OBJECT_free(sk);
  49357. wolfSSL_ASN1_OBJECT_free(obj);
  49358. #endif /* !NO_ASN && (OPENSSL_EXTRA || WOLFSSL_WPAS_SMALL) */
  49359. return EXPECT_RESULT();
  49360. }
  49361. static int test_wolfSSL_ASN1_STRING(void)
  49362. {
  49363. EXPECT_DECLS;
  49364. #if defined(OPENSSL_EXTRA)
  49365. ASN1_STRING* str = NULL;
  49366. ASN1_STRING* c = NULL;
  49367. const char data[] = "hello wolfSSL";
  49368. const char data2[] = "Same len data";
  49369. const char longData[] =
  49370. "This string must be longer than CTC_NAME_SIZE that is defined as 64.";
  49371. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  49372. ASN1_STRING_free(str);
  49373. str = NULL;
  49374. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  49375. ExpectIntEQ(ASN1_STRING_type(str), V_ASN1_OCTET_STRING);
  49376. ExpectIntEQ(ASN1_STRING_type(NULL), 0);
  49377. /* Check setting to NULL works. */
  49378. ExpectIntEQ(ASN1_STRING_set(str, NULL, 0), 1);
  49379. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, sizeof(data)), 1);
  49380. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, -1), 1);
  49381. ExpectIntEQ(ASN1_STRING_set(str, NULL, -1), 0);
  49382. ExpectIntEQ(ASN1_STRING_set(NULL, NULL, 0), 0);
  49383. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(NULL, NULL), 0);
  49384. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(str, NULL), 0);
  49385. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(NULL, str), 0);
  49386. ExpectNull(wolfSSL_ASN1_STRING_dup(NULL));
  49387. ExpectNotNull(c = wolfSSL_ASN1_STRING_dup(str));
  49388. ExpectIntEQ(ASN1_STRING_cmp(NULL, NULL), -1);
  49389. ExpectIntEQ(ASN1_STRING_cmp(str, NULL), -1);
  49390. ExpectIntEQ(ASN1_STRING_cmp(NULL, c), -1);
  49391. ExpectIntEQ(ASN1_STRING_cmp(str, c), 0);
  49392. ExpectIntEQ(ASN1_STRING_set(c, (const void*)data2, -1), 1);
  49393. ExpectIntGT(ASN1_STRING_cmp(str, c), 0);
  49394. ExpectIntEQ(ASN1_STRING_set(str, (const void*)longData, -1), 1);
  49395. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(c, str), 1);
  49396. ExpectIntEQ(ASN1_STRING_cmp(str, c), 0);
  49397. /* Check setting back to smaller size frees dynamic data. */
  49398. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, -1), 1);
  49399. ExpectIntLT(ASN1_STRING_cmp(str, c), 0);
  49400. ExpectIntGT(ASN1_STRING_cmp(c, str), 0);
  49401. ExpectNull(ASN1_STRING_get0_data(NULL));
  49402. ExpectNotNull(ASN1_STRING_get0_data(str));
  49403. ExpectNull(ASN1_STRING_data(NULL));
  49404. ExpectNotNull(ASN1_STRING_data(str));
  49405. ExpectIntEQ(ASN1_STRING_length(NULL), 0);
  49406. ExpectIntGT(ASN1_STRING_length(str), 0);
  49407. ASN1_STRING_free(c);
  49408. ASN1_STRING_free(str);
  49409. ASN1_STRING_free(NULL);
  49410. #ifndef NO_WOLFSSL_STUB
  49411. ExpectNull(d2i_DISPLAYTEXT(NULL, NULL, 0));
  49412. #endif
  49413. #endif
  49414. return EXPECT_RESULT();
  49415. }
  49416. static int test_wolfSSL_ASN1_STRING_to_UTF8(void)
  49417. {
  49418. EXPECT_DECLS;
  49419. #if defined(OPENSSL_ALL) && !defined(NO_ASN) && !defined(NO_RSA) && \
  49420. !defined(NO_FILESYSTEM)
  49421. WOLFSSL_X509* x509 = NULL;
  49422. WOLFSSL_X509_NAME* subject = NULL;
  49423. WOLFSSL_X509_NAME_ENTRY* e = NULL;
  49424. WOLFSSL_ASN1_STRING* a = NULL;
  49425. FILE* file = XBADFILE;
  49426. int idx = 0;
  49427. char targetOutput[16] = "www.wolfssl.com";
  49428. unsigned char* actual_output = NULL;
  49429. int len = 0;
  49430. ExpectNotNull(file = fopen("./certs/server-cert.pem", "rb"));
  49431. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  49432. if (file != XBADFILE)
  49433. fclose(file);
  49434. /* wolfSSL_ASN1_STRING_to_UTF8(): NID_commonName */
  49435. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(x509));
  49436. ExpectIntEQ((idx = wolfSSL_X509_NAME_get_index_by_NID(subject,
  49437. NID_commonName, -1)), 5);
  49438. ExpectNotNull(e = wolfSSL_X509_NAME_get_entry(subject, idx));
  49439. ExpectNotNull(a = wolfSSL_X509_NAME_ENTRY_get_data(e));
  49440. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(&actual_output, a)), 15);
  49441. ExpectIntEQ(strncmp((const char*)actual_output, targetOutput, (size_t)len), 0);
  49442. a = NULL;
  49443. /* wolfSSL_ASN1_STRING_to_UTF8(NULL, valid) */
  49444. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(NULL, a)), -1);
  49445. /* wolfSSL_ASN1_STRING_to_UTF8(valid, NULL) */
  49446. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(&actual_output, NULL)), -1);
  49447. /* wolfSSL_ASN1_STRING_to_UTF8(NULL, NULL) */
  49448. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(NULL, NULL)), -1);
  49449. wolfSSL_X509_free(x509);
  49450. XFREE(actual_output, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49451. ExpectNotNull(a = ASN1_STRING_new());
  49452. ExpectIntEQ(wolfSSL_ASN1_STRING_to_UTF8(&actual_output, a), -1);
  49453. ASN1_STRING_free(a);
  49454. #endif
  49455. return EXPECT_RESULT();
  49456. }
  49457. static int test_wolfSSL_i2s_ASN1_STRING(void)
  49458. {
  49459. EXPECT_DECLS;
  49460. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  49461. WOLFSSL_ASN1_STRING* str = NULL;
  49462. const char* data = "test_wolfSSL_i2s_ASN1_STRING";
  49463. char* ret = NULL;
  49464. ExpectNotNull(str = ASN1_STRING_new());
  49465. ExpectNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, NULL));
  49466. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49467. ret = NULL;
  49468. /* No data. */
  49469. ExpectNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, str));
  49470. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49471. ret = NULL;
  49472. ExpectIntEQ(ASN1_STRING_set(str, data, 0), 1);
  49473. ExpectNotNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, str));
  49474. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49475. ret = NULL;
  49476. ExpectIntEQ(ASN1_STRING_set(str, data, -1), 1);
  49477. /* No type. */
  49478. ExpectNotNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, str));
  49479. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49480. ASN1_STRING_free(str);
  49481. #endif
  49482. return EXPECT_RESULT();
  49483. }
  49484. static int test_wolfSSL_ASN1_STRING_canon(void)
  49485. {
  49486. EXPECT_DECLS;
  49487. #if defined(WOLFSSL_TEST_STATIC_BUILD)
  49488. #if !defined(NO_CERTS) && (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \
  49489. defined(OPENSSL_EXTRA_X509_SMALL))
  49490. WOLFSSL_ASN1_STRING* orig = NULL;
  49491. WOLFSSL_ASN1_STRING* canon = NULL;
  49492. const char* data = "test_wolfSSL_ASN1_STRING_canon";
  49493. const char* whitespaceOnly = "\t\r\n";
  49494. const char* modData = " \x01\f\t\x02\r\n\v\xff\nTt \n";
  49495. const char* canonData = "\x01 \x02 \xff tt";
  49496. const char longData[] =
  49497. "This string must be longer than CTC_NAME_SIZE that is defined as 64.";
  49498. ExpectNotNull(orig = ASN1_STRING_new());
  49499. ExpectNotNull(canon = ASN1_STRING_new());
  49500. /* Invalid parameter testing. */
  49501. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49502. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49503. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(NULL, orig), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49504. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  49505. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  49506. ExpectIntEQ(ASN1_STRING_set(orig, longData, (int)XSTRLEN(data)), 1);
  49507. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  49508. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  49509. ExpectIntEQ(ASN1_STRING_set(orig, data, (int)XSTRLEN(data)), 1);
  49510. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  49511. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  49512. ASN1_STRING_free(orig);
  49513. orig = NULL;
  49514. ExpectNotNull(orig = ASN1_STRING_type_new(MBSTRING_UTF8));
  49515. ExpectIntEQ(ASN1_STRING_set(orig, modData, 15), 1);
  49516. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  49517. ExpectIntEQ(ASN1_STRING_set(orig, canonData, 8), 1);
  49518. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  49519. ASN1_STRING_free(orig);
  49520. orig = NULL;
  49521. ExpectNotNull(orig = ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING));
  49522. ExpectIntEQ(ASN1_STRING_set(orig, whitespaceOnly, 3), 1);
  49523. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  49524. ASN1_STRING_free(orig);
  49525. orig = NULL;
  49526. ExpectNotNull(orig = ASN1_STRING_type_new(MBSTRING_UTF8));
  49527. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  49528. ASN1_STRING_free(orig);
  49529. ASN1_STRING_free(canon);
  49530. #endif
  49531. #endif
  49532. return EXPECT_RESULT();
  49533. }
  49534. static int test_wolfSSL_ASN1_STRING_print(void)
  49535. {
  49536. EXPECT_DECLS;
  49537. #if defined(OPENSSL_ALL) && !defined(NO_ASN) && !defined(NO_CERTS) && \
  49538. !defined(NO_BIO)
  49539. ASN1_STRING* asnStr = NULL;
  49540. const char HELLO_DATA[]= \
  49541. {'H','e','l','l','o',' ','w','o','l','f','S','S','L','!'};
  49542. #define MAX_UNPRINTABLE_CHAR 32
  49543. #define MAX_BUF 255
  49544. unsigned char unprintableData[MAX_UNPRINTABLE_CHAR + sizeof(HELLO_DATA)];
  49545. unsigned char expected[sizeof(unprintableData)+1];
  49546. unsigned char rbuf[MAX_BUF];
  49547. BIO *bio = NULL;
  49548. int p_len;
  49549. int i;
  49550. /* setup */
  49551. for (i = 0; i < (int)sizeof(HELLO_DATA); i++) {
  49552. unprintableData[i] = (unsigned char)HELLO_DATA[i];
  49553. expected[i] = (unsigned char)HELLO_DATA[i];
  49554. }
  49555. for (i = 0; i < (int)MAX_UNPRINTABLE_CHAR; i++) {
  49556. unprintableData[sizeof(HELLO_DATA)+i] = i;
  49557. if (i == (int)'\n' || i == (int)'\r')
  49558. expected[sizeof(HELLO_DATA)+i] = i;
  49559. else
  49560. expected[sizeof(HELLO_DATA)+i] = '.';
  49561. }
  49562. unprintableData[sizeof(unprintableData)-1] = '\0';
  49563. expected[sizeof(expected)-1] = '\0';
  49564. XMEMSET(rbuf, 0, MAX_BUF);
  49565. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  49566. ExpectIntEQ(BIO_set_write_buf_size(bio, MAX_BUF), 0);
  49567. ExpectNotNull(asnStr = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  49568. ExpectIntEQ(ASN1_STRING_set(asnStr,(const void*)unprintableData,
  49569. (int)sizeof(unprintableData)), 1);
  49570. /* test */
  49571. ExpectIntEQ(wolfSSL_ASN1_STRING_print(NULL, NULL), 0);
  49572. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, NULL), 0);
  49573. ExpectIntEQ(wolfSSL_ASN1_STRING_print(NULL, asnStr), 0);
  49574. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print(bio, asnStr), 46);
  49575. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 46), 46);
  49576. ExpectStrEQ((char*)rbuf, (const char*)expected);
  49577. BIO_free(bio);
  49578. bio = NULL;
  49579. ExpectNotNull(bio = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  49580. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  49581. /* Ensure there is 0 bytes available to write into. */
  49582. ExpectIntEQ(BIO_write(bio, rbuf, 1), 1);
  49583. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  49584. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  49585. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  49586. ExpectIntEQ(BIO_set_write_buf_size(bio, 45), 1);
  49587. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  49588. BIO_free(bio);
  49589. ASN1_STRING_free(asnStr);
  49590. #endif /* OPENSSL_EXTRA && !NO_ASN && !NO_CERTS && !NO_BIO */
  49591. return EXPECT_RESULT();
  49592. }
  49593. static int test_wolfSSL_ASN1_STRING_print_ex(void)
  49594. {
  49595. EXPECT_DECLS;
  49596. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(NO_BIO)
  49597. ASN1_STRING* asn_str = NULL;
  49598. const char data[] = "Hello wolfSSL!";
  49599. ASN1_STRING* esc_str = NULL;
  49600. const char esc_data[] = "a+;<>";
  49601. ASN1_STRING* neg_int = NULL;
  49602. const char neg_int_data[] = "\xff";
  49603. ASN1_STRING* neg_enum = NULL;
  49604. const char neg_enum_data[] = "\xff";
  49605. BIO *bio = NULL;
  49606. BIO *fixed = NULL;
  49607. unsigned long flags;
  49608. int p_len;
  49609. unsigned char rbuf[255];
  49610. /* setup */
  49611. XMEMSET(rbuf, 0, 255);
  49612. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  49613. ExpectIntEQ(BIO_set_write_buf_size(bio, 255), 0);
  49614. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  49615. ExpectNotNull(asn_str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  49616. ExpectIntEQ(ASN1_STRING_set(asn_str, (const void*)data, sizeof(data)), 1);
  49617. ExpectNotNull(esc_str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  49618. ExpectIntEQ(ASN1_STRING_set(esc_str, (const void*)esc_data,
  49619. sizeof(esc_data)), 1);
  49620. ExpectNotNull(neg_int = ASN1_STRING_type_new(V_ASN1_NEG_INTEGER));
  49621. ExpectIntEQ(ASN1_STRING_set(neg_int, (const void*)neg_int_data,
  49622. sizeof(neg_int_data) - 1), 1);
  49623. ExpectNotNull(neg_enum = ASN1_STRING_type_new(V_ASN1_NEG_ENUMERATED));
  49624. ExpectIntEQ(ASN1_STRING_set(neg_enum, (const void*)neg_enum_data,
  49625. sizeof(neg_enum_data) - 1), 1);
  49626. /* Invalid parameter testing. */
  49627. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(NULL, NULL, 0), 0);
  49628. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(bio, NULL, 0), 0);
  49629. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(NULL, asn_str, 0), 0);
  49630. /* no flags */
  49631. XMEMSET(rbuf, 0, 255);
  49632. flags = 0;
  49633. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 15);
  49634. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 15), 15);
  49635. ExpectStrEQ((char*)rbuf, "Hello wolfSSL!");
  49636. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49637. /* Ensure there is 0 bytes available to write into. */
  49638. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  49639. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49640. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49641. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49642. ExpectIntEQ(BIO_set_write_buf_size(fixed, 14), 1);
  49643. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49644. /* RFC2253 Escape */
  49645. XMEMSET(rbuf, 0, 255);
  49646. flags = ASN1_STRFLGS_ESC_2253;
  49647. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, esc_str, flags), 9);
  49648. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 9), 9);
  49649. ExpectStrEQ((char*)rbuf, "a\\+\\;\\<\\>");
  49650. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49651. /* Ensure there is 0 bytes available to write into. */
  49652. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  49653. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  49654. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49655. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  49656. ExpectIntEQ(BIO_set_write_buf_size(fixed, 8), 1);
  49657. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  49658. /* Show type */
  49659. XMEMSET(rbuf, 0, 255);
  49660. flags = ASN1_STRFLGS_SHOW_TYPE;
  49661. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 28);
  49662. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 28), 28);
  49663. ExpectStrEQ((char*)rbuf, "OCTET STRING:Hello wolfSSL!");
  49664. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49665. /* Ensure there is 0 bytes available to write into. */
  49666. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  49667. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49668. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49669. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49670. ExpectIntEQ(BIO_set_write_buf_size(fixed, 12), 1);
  49671. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49672. ExpectIntEQ(BIO_set_write_buf_size(fixed, 27), 1);
  49673. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49674. /* Dump All */
  49675. XMEMSET(rbuf, 0, 255);
  49676. flags = ASN1_STRFLGS_DUMP_ALL;
  49677. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 31);
  49678. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 31), 31);
  49679. ExpectStrEQ((char*)rbuf, "#48656C6C6F20776F6C6653534C2100");
  49680. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49681. /* Ensure there is 0 bytes available to write into. */
  49682. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  49683. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49684. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49685. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49686. ExpectIntEQ(BIO_set_write_buf_size(fixed, 30), 1);
  49687. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49688. /* Dump Der */
  49689. XMEMSET(rbuf, 0, 255);
  49690. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_DUMP_DER;
  49691. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 35);
  49692. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 35), 35);
  49693. ExpectStrEQ((char*)rbuf, "#040F48656C6C6F20776F6C6653534C2100");
  49694. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49695. /* Ensure there is 0 bytes available to write into. */
  49696. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  49697. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49698. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49699. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49700. ExpectIntEQ(BIO_set_write_buf_size(fixed, 2), 1);
  49701. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49702. ExpectIntEQ(BIO_set_write_buf_size(fixed, 30), 1);
  49703. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49704. /* Dump All + Show type */
  49705. XMEMSET(rbuf, 0, 255);
  49706. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  49707. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 44);
  49708. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 44), 44);
  49709. ExpectStrEQ((char*)rbuf, "OCTET STRING:#48656C6C6F20776F6C6653534C2100");
  49710. /* Dump All + Show type - Negative Integer. */
  49711. XMEMSET(rbuf, 0, 255);
  49712. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  49713. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, neg_int, flags), 11);
  49714. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 11), 11);
  49715. ExpectStrEQ((char*)rbuf, "INTEGER:#FF");
  49716. /* Dump All + Show type - Negative Enumerated. */
  49717. XMEMSET(rbuf, 0, 255);
  49718. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  49719. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, neg_enum, flags), 14);
  49720. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 14), 14);
  49721. ExpectStrEQ((char*)rbuf, "ENUMERATED:#FF");
  49722. BIO_free(fixed);
  49723. BIO_free(bio);
  49724. ASN1_STRING_free(asn_str);
  49725. ASN1_STRING_free(esc_str);
  49726. ASN1_STRING_free(neg_int);
  49727. ASN1_STRING_free(neg_enum);
  49728. ExpectStrEQ(wolfSSL_ASN1_tag2str(-1), "(unknown)");
  49729. ExpectStrEQ(wolfSSL_ASN1_tag2str(31), "(unknown)");
  49730. #endif
  49731. return EXPECT_RESULT();
  49732. }
  49733. static int test_wolfSSL_ASN1_UNIVERSALSTRING_to_string(void)
  49734. {
  49735. EXPECT_DECLS;
  49736. #if defined(OPENSSL_ALL) && !defined(NO_ASN)
  49737. ASN1_STRING* asn1str_test = NULL;
  49738. ASN1_STRING* asn1str_answer = NULL;
  49739. /* Each character is encoded using 4 bytes */
  49740. char input[] = {
  49741. 0, 0, 0, 'T',
  49742. 0, 0, 0, 'e',
  49743. 0, 0, 0, 's',
  49744. 0, 0, 0, 't',
  49745. };
  49746. char output[] = "Test";
  49747. char badInput[] = {
  49748. 1, 0, 0, 'T',
  49749. 0, 1, 0, 'e',
  49750. 0, 0, 1, 's',
  49751. };
  49752. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(NULL), 0);
  49753. /* Test wrong type. */
  49754. ExpectNotNull(asn1str_test = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  49755. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  49756. ASN1_STRING_free(asn1str_test);
  49757. asn1str_test = NULL;
  49758. ExpectNotNull(asn1str_test = ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING));
  49759. /* Test bad length. */
  49760. ExpectIntEQ(ASN1_STRING_set(asn1str_test, input, sizeof(input) - 1), 1);
  49761. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  49762. /* Test bad input. */
  49763. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 0, 4), 1);
  49764. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  49765. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 4, 4), 1);
  49766. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  49767. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 8, 4), 1);
  49768. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  49769. ExpectIntEQ(ASN1_STRING_set(asn1str_test, input, sizeof(input)), 1);
  49770. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 1);
  49771. ExpectNotNull(
  49772. asn1str_answer = ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING));
  49773. ExpectIntEQ(ASN1_STRING_set(asn1str_answer, output, sizeof(output)-1), 1);
  49774. ExpectIntEQ(ASN1_STRING_cmp(asn1str_test, asn1str_answer), 0);
  49775. ASN1_STRING_free(asn1str_test);
  49776. ASN1_STRING_free(asn1str_answer);
  49777. #endif /* OPENSSL_ALL && !NO_ASN */
  49778. return EXPECT_RESULT();
  49779. }
  49780. static int test_wolfSSL_ASN1_GENERALIZEDTIME_free(void)
  49781. {
  49782. EXPECT_DECLS;
  49783. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  49784. WOLFSSL_ASN1_GENERALIZEDTIME* asn1_gtime = NULL;
  49785. ExpectNotNull(asn1_gtime = ASN1_GENERALIZEDTIME_new());
  49786. if (asn1_gtime != NULL)
  49787. XMEMCPY(asn1_gtime->data, "20180504123500Z", ASN_GENERALIZED_TIME_SIZE);
  49788. ASN1_GENERALIZEDTIME_free(asn1_gtime);
  49789. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME */
  49790. return EXPECT_RESULT();
  49791. }
  49792. static int test_wolfSSL_ASN1_GENERALIZEDTIME_print(void)
  49793. {
  49794. EXPECT_DECLS;
  49795. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && !defined(NO_BIO)
  49796. WOLFSSL_ASN1_GENERALIZEDTIME* gtime = NULL;
  49797. BIO* bio = NULL;
  49798. unsigned char buf[24];
  49799. int i;
  49800. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  49801. BIO_set_write_buf_size(bio, 24);
  49802. ExpectNotNull(gtime = ASN1_GENERALIZEDTIME_new());
  49803. /* Type not set. */
  49804. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  49805. ExpectIntEQ(wolfSSL_ASN1_TIME_set_string(gtime, "20180504123500Z"), 1);
  49806. /* Invalid parameters testing. */
  49807. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49808. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49809. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(NULL, gtime), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49810. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 1);
  49811. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 20);
  49812. ExpectIntEQ(XMEMCMP(buf, "May 04 12:35:00 2018", 20), 0);
  49813. BIO_free(bio);
  49814. bio = NULL;
  49815. ExpectNotNull(bio = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  49816. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  49817. /* Ensure there is 0 bytes available to write into. */
  49818. ExpectIntEQ(BIO_write(bio, buf, 1), 1);
  49819. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  49820. for (i = 1; i < 20; i++) {
  49821. ExpectIntEQ(BIO_set_write_buf_size(bio, i), 1);
  49822. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  49823. }
  49824. BIO_free(bio);
  49825. wolfSSL_ASN1_GENERALIZEDTIME_free(gtime);
  49826. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME && !NO_BIO */
  49827. return EXPECT_RESULT();
  49828. }
  49829. static int test_wolfSSL_ASN1_TIME(void)
  49830. {
  49831. EXPECT_DECLS;
  49832. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  49833. WOLFSSL_ASN1_TIME* asn_time = NULL;
  49834. unsigned char *data = NULL;
  49835. ExpectNotNull(asn_time = ASN1_TIME_new());
  49836. #ifndef NO_WOLFSSL_STUB
  49837. ExpectNotNull(ASN1_TIME_set(asn_time, 1));
  49838. #endif
  49839. ExpectIntEQ(ASN1_TIME_set_string(NULL, NULL), 0);
  49840. ExpectIntEQ(ASN1_TIME_set_string(asn_time, NULL), 0);
  49841. ExpectIntEQ(ASN1_TIME_set_string(NULL,
  49842. "String longer than CTC_DATA_SIZE that is 32 bytes"), 0);
  49843. ExpectIntEQ(ASN1_TIME_set_string(NULL, "101219181011Z"), 1);
  49844. ExpectIntEQ(ASN1_TIME_set_string(asn_time, "101219181011Z"), 1);
  49845. ExpectIntEQ(wolfSSL_ASN1_TIME_get_length(NULL), 0);
  49846. ExpectIntEQ(wolfSSL_ASN1_TIME_get_length(asn_time), ASN_UTC_TIME_SIZE - 1);
  49847. ExpectNull(wolfSSL_ASN1_TIME_get_data(NULL));
  49848. ExpectNotNull(data = wolfSSL_ASN1_TIME_get_data(asn_time));
  49849. ExpectIntEQ(XMEMCMP(data, "101219181011Z", 14), 0);
  49850. ExpectIntEQ(ASN1_TIME_check(NULL), 0);
  49851. ExpectIntEQ(ASN1_TIME_check(asn_time), 1);
  49852. ExpectIntEQ(ASN1_TIME_set_string_X509(asn_time, "101219181011Z"), 1);
  49853. ExpectIntEQ(ASN1_TIME_set_string_X509(asn_time, "101219181011Za"), 0);
  49854. ASN1_TIME_free(asn_time);
  49855. ASN1_TIME_free(NULL);
  49856. #endif
  49857. return EXPECT_RESULT();
  49858. }
  49859. static int test_wolfSSL_ASN1_TIME_to_string(void)
  49860. {
  49861. EXPECT_DECLS;
  49862. #ifndef NO_ASN_TIME
  49863. #if defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  49864. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  49865. WOLFSSL_ASN1_TIME* t = NULL;
  49866. char buf[ASN_GENERALIZED_TIME_SIZE];
  49867. ExpectNotNull((t = ASN1_TIME_new()));
  49868. ExpectIntEQ(ASN1_TIME_set_string(t, "030222211515Z"), 1);
  49869. /* Invalid parameter testing. */
  49870. ExpectNull(ASN1_TIME_to_string(NULL, NULL, 4));
  49871. ExpectNull(ASN1_TIME_to_string(t, NULL, 4));
  49872. ExpectNull(ASN1_TIME_to_string(NULL, buf, 4));
  49873. ExpectNull(ASN1_TIME_to_string(NULL, NULL, 5));
  49874. ExpectNull(ASN1_TIME_to_string(NULL, buf, 5));
  49875. ExpectNull(ASN1_TIME_to_string(t, NULL, 5));
  49876. ExpectNull(ASN1_TIME_to_string(t, buf, 4));
  49877. /* Buffer needs to be longer than minimum of 5 characters. */
  49878. ExpectNull(ASN1_TIME_to_string(t, buf, 5));
  49879. ASN1_TIME_free(t);
  49880. #endif
  49881. #endif /* NO_ASN_TIME */
  49882. return EXPECT_RESULT();
  49883. }
  49884. static int test_wolfSSL_ASN1_TIME_diff_compare(void)
  49885. {
  49886. EXPECT_DECLS;
  49887. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  49888. ASN1_TIME* fromTime = NULL;
  49889. ASN1_TIME* closeToTime = NULL;
  49890. ASN1_TIME* toTime = NULL;
  49891. ASN1_TIME* invalidTime = NULL;
  49892. int daysDiff = 0;
  49893. int secsDiff = 0;
  49894. ExpectNotNull((fromTime = ASN1_TIME_new()));
  49895. /* Feb 22, 2003, 21:15:15 */
  49896. ExpectIntEQ(ASN1_TIME_set_string(fromTime, "030222211515Z"), 1);
  49897. ExpectNotNull((closeToTime = ASN1_TIME_new()));
  49898. /* Feb 22, 2003, 21:16:15 */
  49899. ExpectIntEQ(ASN1_TIME_set_string(closeToTime, "030222211615Z"), 1);
  49900. ExpectNotNull((toTime = ASN1_TIME_new()));
  49901. /* Dec 19, 2010, 18:10:11 */
  49902. ExpectIntEQ(ASN1_TIME_set_string(toTime, "101219181011Z"), 1);
  49903. ExpectNotNull((invalidTime = ASN1_TIME_new()));
  49904. /* Dec 19, 2010, 18:10:11 but 'U' instead of 'Z' which is invalid. */
  49905. ExpectIntEQ(ASN1_TIME_set_string(invalidTime, "102519181011U"), 1);
  49906. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, invalidTime), 0);
  49907. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, invalidTime, toTime), 0);
  49908. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  49909. /* Error conditions. */
  49910. ExpectIntEQ(ASN1_TIME_diff(NULL, &secsDiff, fromTime, toTime), 0);
  49911. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, NULL, fromTime, toTime), 0);
  49912. /* If both times are NULL, difference is 0. */
  49913. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, NULL, NULL), 1);
  49914. ExpectIntEQ(daysDiff, 0);
  49915. ExpectIntEQ(secsDiff, 0);
  49916. /* If one time is NULL, it defaults to the current time. */
  49917. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, NULL, toTime), 1);
  49918. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, NULL), 1);
  49919. /* Normal operation. Both times non-NULL. */
  49920. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  49921. ExpectIntEQ(daysDiff, 2856);
  49922. ExpectIntEQ(secsDiff, 75296);
  49923. /* Swapping the times should return negative values. */
  49924. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, toTime, fromTime), 1);
  49925. ExpectIntEQ(daysDiff, -2856);
  49926. ExpectIntEQ(secsDiff, -75296);
  49927. /* Compare with invalid time string. */
  49928. ExpectIntEQ(ASN1_TIME_compare(fromTime, invalidTime), -2);
  49929. ExpectIntEQ(ASN1_TIME_compare(invalidTime, toTime), -2);
  49930. /* Compare with days difference of 0. */
  49931. ExpectIntEQ(ASN1_TIME_compare(fromTime, closeToTime), -1);
  49932. ExpectIntEQ(ASN1_TIME_compare(closeToTime, fromTime), 1);
  49933. /* Days and seconds differences not 0. */
  49934. ExpectIntEQ(ASN1_TIME_compare(fromTime, toTime), -1);
  49935. ExpectIntEQ(ASN1_TIME_compare(toTime, fromTime), 1);
  49936. /* Same time. */
  49937. ExpectIntEQ(ASN1_TIME_compare(fromTime, fromTime), 0);
  49938. /* Compare regression test: No seconds difference, just difference in days.
  49939. */
  49940. ASN1_TIME_set_string(fromTime, "19700101000000Z");
  49941. ASN1_TIME_set_string(toTime, "19800101000000Z");
  49942. ExpectIntEQ(ASN1_TIME_compare(fromTime, toTime), -1);
  49943. ExpectIntEQ(ASN1_TIME_compare(toTime, fromTime), 1);
  49944. ExpectIntEQ(ASN1_TIME_compare(fromTime, fromTime), 0);
  49945. /* Edge case with Unix epoch. */
  49946. ExpectNotNull(ASN1_TIME_set_string(fromTime, "19700101000000Z"));
  49947. ExpectNotNull(ASN1_TIME_set_string(toTime, "19800101000000Z"));
  49948. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  49949. ExpectIntEQ(daysDiff, 3652);
  49950. ExpectIntEQ(secsDiff, 0);
  49951. /* Edge case with year > 2038 (year 2038 problem). */
  49952. ExpectNotNull(ASN1_TIME_set_string(toTime, "99991231235959Z"));
  49953. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  49954. ExpectIntEQ(daysDiff, 2932896);
  49955. ExpectIntEQ(secsDiff, 86399);
  49956. ASN1_TIME_free(fromTime);
  49957. ASN1_TIME_free(closeToTime);
  49958. ASN1_TIME_free(toTime);
  49959. ASN1_TIME_free(invalidTime);
  49960. #endif
  49961. return EXPECT_RESULT();
  49962. }
  49963. static int test_wolfSSL_ASN1_TIME_adj(void)
  49964. {
  49965. EXPECT_DECLS;
  49966. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && \
  49967. !defined(USER_TIME) && !defined(TIME_OVERRIDES)
  49968. const int year = 365*24*60*60;
  49969. const int day = 24*60*60;
  49970. const int hour = 60*60;
  49971. const int mini = 60;
  49972. const byte asn_utc_time = ASN_UTC_TIME;
  49973. #if !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT)
  49974. const byte asn_gen_time = ASN_GENERALIZED_TIME;
  49975. #endif
  49976. WOLFSSL_ASN1_TIME* asn_time = NULL;
  49977. WOLFSSL_ASN1_TIME* s = NULL;
  49978. int offset_day;
  49979. long offset_sec;
  49980. char date_str[CTC_DATE_SIZE + 1];
  49981. time_t t;
  49982. ExpectNotNull(s = wolfSSL_ASN1_TIME_new());
  49983. /* UTC notation test */
  49984. /* 2000/2/15 20:30:00 */
  49985. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 7 * day;
  49986. offset_day = 7;
  49987. offset_sec = 45 * mini;
  49988. /* offset_sec = -45 * min;*/
  49989. ExpectNotNull(asn_time =
  49990. wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec));
  49991. ExpectTrue(asn_time->type == asn_utc_time);
  49992. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  49993. CTC_DATE_SIZE));
  49994. date_str[CTC_DATE_SIZE] = '\0';
  49995. ExpectIntEQ(0, XMEMCMP(date_str, "000222211500Z", 13));
  49996. /* negative offset */
  49997. offset_sec = -45 * mini;
  49998. asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec);
  49999. ExpectNotNull(asn_time);
  50000. ExpectTrue(asn_time->type == asn_utc_time);
  50001. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  50002. CTC_DATE_SIZE));
  50003. date_str[CTC_DATE_SIZE] = '\0';
  50004. ExpectIntEQ(0, XMEMCMP(date_str, "000222194500Z", 13));
  50005. XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
  50006. s = NULL;
  50007. XMEMSET(date_str, 0, sizeof(date_str));
  50008. /* Generalized time will overflow time_t if not long */
  50009. #if !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT)
  50010. s = (WOLFSSL_ASN1_TIME*)XMALLOC(sizeof(WOLFSSL_ASN1_TIME), NULL,
  50011. DYNAMIC_TYPE_OPENSSL);
  50012. /* GeneralizedTime notation test */
  50013. /* 2055/03/01 09:00:00 */
  50014. t = (time_t)85 * year + 59 * day + 9 * hour + 21 * day;
  50015. offset_day = 12;
  50016. offset_sec = 10 * mini;
  50017. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
  50018. offset_sec));
  50019. ExpectTrue(asn_time->type == asn_gen_time);
  50020. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  50021. CTC_DATE_SIZE));
  50022. date_str[CTC_DATE_SIZE] = '\0';
  50023. ExpectIntEQ(0, XMEMCMP(date_str, "20550313091000Z", 15));
  50024. XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
  50025. s = NULL;
  50026. XMEMSET(date_str, 0, sizeof(date_str));
  50027. #endif /* !TIME_T_NOT_64BIT && !NO_64BIT */
  50028. /* if WOLFSSL_ASN1_TIME struct is not allocated */
  50029. s = NULL;
  50030. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 15 + 7 * day;
  50031. offset_day = 7;
  50032. offset_sec = 45 * mini;
  50033. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
  50034. offset_sec));
  50035. ExpectTrue(asn_time->type == asn_utc_time);
  50036. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  50037. CTC_DATE_SIZE));
  50038. date_str[CTC_DATE_SIZE] = '\0';
  50039. ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
  50040. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  50041. asn_time = NULL;
  50042. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day,
  50043. offset_sec));
  50044. ExpectTrue(asn_time->type == asn_utc_time);
  50045. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  50046. CTC_DATE_SIZE));
  50047. date_str[CTC_DATE_SIZE] = '\0';
  50048. ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
  50049. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  50050. #endif
  50051. return EXPECT_RESULT();
  50052. }
  50053. static int test_wolfSSL_ASN1_TIME_to_tm(void)
  50054. {
  50055. EXPECT_DECLS;
  50056. #if (defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  50057. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || \
  50058. defined(OPENSSL_ALL)) && !defined(NO_ASN_TIME)
  50059. ASN1_TIME asnTime;
  50060. struct tm tm;
  50061. time_t testTime = 1683926567; /* Fri May 12 09:22:47 PM UTC 2023 */
  50062. XMEMSET(&tm, 0, sizeof(struct tm));
  50063. XMEMSET(&asnTime, 0, sizeof(ASN1_TIME));
  50064. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "000222211515Z"), 1);
  50065. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, NULL), 1);
  50066. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  50067. ExpectIntEQ(tm.tm_sec, 15);
  50068. ExpectIntEQ(tm.tm_min, 15);
  50069. ExpectIntEQ(tm.tm_hour, 21);
  50070. ExpectIntEQ(tm.tm_mday, 22);
  50071. ExpectIntEQ(tm.tm_mon, 1);
  50072. ExpectIntEQ(tm.tm_year, 100);
  50073. ExpectIntEQ(tm.tm_isdst, 0);
  50074. #ifdef XMKTIME
  50075. ExpectIntEQ(tm.tm_wday, 2);
  50076. ExpectIntEQ(tm.tm_yday, 52);
  50077. #endif
  50078. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "500222211515Z"), 1);
  50079. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  50080. ExpectIntEQ(tm.tm_year, 50);
  50081. /* Get current time. */
  50082. ExpectIntEQ(ASN1_TIME_to_tm(NULL, NULL), 0);
  50083. ExpectIntEQ(ASN1_TIME_to_tm(NULL, &tm), 1);
  50084. XMEMSET(&asnTime, 0, sizeof(ASN1_TIME));
  50085. /* 0 length. */
  50086. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  50087. /* No type. */
  50088. asnTime.length = 1;
  50089. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  50090. /* Not UTCTIME length. */
  50091. asnTime.type = V_ASN1_UTCTIME;
  50092. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  50093. /* Not GENERALIZEDTIME length. */
  50094. asnTime.type = V_ASN1_GENERALIZEDTIME;
  50095. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  50096. /* Not Zulu timezone. */
  50097. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "000222211515U"), 1);
  50098. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  50099. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "20000222211515U"), 1);
  50100. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  50101. #ifdef XMKTIME
  50102. ExpectNotNull(ASN1_TIME_adj(&asnTime, testTime, 0, 0));
  50103. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  50104. ExpectIntEQ(tm.tm_sec, 47);
  50105. ExpectIntEQ(tm.tm_min, 22);
  50106. ExpectIntEQ(tm.tm_hour, 21);
  50107. ExpectIntEQ(tm.tm_mday, 12);
  50108. ExpectIntEQ(tm.tm_mon, 4);
  50109. ExpectIntEQ(tm.tm_year, 123);
  50110. ExpectIntEQ(tm.tm_wday, 5);
  50111. ExpectIntEQ(tm.tm_yday, 131);
  50112. /* Confirm that when used with a tm struct from ASN1_TIME_adj, all other
  50113. fields are zeroed out as expected. */
  50114. ExpectIntEQ(tm.tm_isdst, 0);
  50115. #endif
  50116. #endif
  50117. return EXPECT_RESULT();
  50118. }
  50119. static int test_wolfSSL_ASN1_TIME_to_generalizedtime(void)
  50120. {
  50121. EXPECT_DECLS;
  50122. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  50123. WOLFSSL_ASN1_TIME *t = NULL;
  50124. WOLFSSL_ASN1_TIME *out = NULL;
  50125. WOLFSSL_ASN1_TIME *gtime = NULL;
  50126. int tlen = 0;
  50127. unsigned char *data = NULL;
  50128. ExpectNotNull(t = wolfSSL_ASN1_TIME_new());
  50129. ExpectNull(wolfSSL_ASN1_TIME_to_generalizedtime(NULL, &out));
  50130. /* type not set. */
  50131. ExpectNull(wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  50132. XFREE(t, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  50133. t = NULL;
  50134. /* UTC Time test */
  50135. ExpectNotNull(t = wolfSSL_ASN1_TIME_new());
  50136. if (t != NULL) {
  50137. XMEMSET(t->data, 0, ASN_GENERALIZED_TIME_SIZE);
  50138. t->type = ASN_UTC_TIME;
  50139. t->length = ASN_UTC_TIME_SIZE;
  50140. XMEMCPY(t->data, "050727123456Z", ASN_UTC_TIME_SIZE);
  50141. }
  50142. ExpectIntEQ(tlen = wolfSSL_ASN1_TIME_get_length(t), ASN_UTC_TIME_SIZE);
  50143. ExpectStrEQ((char*)(data = wolfSSL_ASN1_TIME_get_data(t)), "050727123456Z");
  50144. out = NULL;
  50145. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  50146. wolfSSL_ASN1_TIME_free(gtime);
  50147. gtime = NULL;
  50148. ExpectNotNull(out = wolfSSL_ASN1_TIME_new());
  50149. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  50150. ExpectPtrEq(gtime, out);
  50151. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  50152. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  50153. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  50154. /* Generalized Time test */
  50155. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  50156. ExpectNotNull(XMEMSET(out, 0, ASN_GENERALIZED_TIME_SIZE));
  50157. ExpectNotNull(XMEMSET(data, 0, ASN_GENERALIZED_TIME_SIZE));
  50158. if (t != NULL) {
  50159. t->type = ASN_GENERALIZED_TIME;
  50160. t->length = ASN_GENERALIZED_TIME_SIZE;
  50161. XMEMCPY(t->data, "20050727123456Z", ASN_GENERALIZED_TIME_SIZE);
  50162. }
  50163. ExpectIntEQ(tlen = wolfSSL_ASN1_TIME_get_length(t),
  50164. ASN_GENERALIZED_TIME_SIZE);
  50165. ExpectStrEQ((char*)(data = wolfSSL_ASN1_TIME_get_data(t)),
  50166. "20050727123456Z");
  50167. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  50168. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  50169. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  50170. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  50171. /* UTC Time to Generalized Time 1900's test */
  50172. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  50173. ExpectNotNull(XMEMSET(out, 0, ASN_GENERALIZED_TIME_SIZE));
  50174. ExpectNotNull(XMEMSET(data, 0, ASN_GENERALIZED_TIME_SIZE));
  50175. if (t != NULL) {
  50176. t->type = ASN_UTC_TIME;
  50177. t->length = ASN_UTC_TIME_SIZE;
  50178. XMEMCPY(t->data, "500727123456Z", ASN_UTC_TIME_SIZE);
  50179. }
  50180. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  50181. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  50182. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  50183. ExpectStrEQ((char*)gtime->data, "19500727123456Z");
  50184. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  50185. /* Null parameter test */
  50186. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  50187. gtime = NULL;
  50188. out = NULL;
  50189. if (t != NULL) {
  50190. t->type = ASN_UTC_TIME;
  50191. t->length = ASN_UTC_TIME_SIZE;
  50192. XMEMCPY(t->data, "050727123456Z", ASN_UTC_TIME_SIZE);
  50193. }
  50194. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, NULL));
  50195. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  50196. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  50197. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  50198. XFREE(gtime, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  50199. XFREE(t, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  50200. #endif
  50201. return EXPECT_RESULT();
  50202. }
  50203. static int test_wolfSSL_ASN1_TIME_print(void)
  50204. {
  50205. EXPECT_DECLS;
  50206. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_BIO) && \
  50207. (defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  50208. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || \
  50209. defined(OPENSSL_ALL)) && defined(USE_CERT_BUFFERS_2048) && \
  50210. !defined(NO_ASN_TIME)
  50211. BIO* bio = NULL;
  50212. BIO* fixed = NULL;
  50213. X509* x509 = NULL;
  50214. const unsigned char* der = client_cert_der_2048;
  50215. ASN1_TIME* notAfter = NULL;
  50216. ASN1_TIME* notBefore = NULL;
  50217. unsigned char buf[25];
  50218. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  50219. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  50220. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(der,
  50221. sizeof_client_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  50222. ExpectNotNull(notBefore = X509_get_notBefore(x509));
  50223. ExpectIntEQ(ASN1_TIME_print(NULL, NULL), 0);
  50224. ExpectIntEQ(ASN1_TIME_print(bio, NULL), 0);
  50225. ExpectIntEQ(ASN1_TIME_print(NULL, notBefore), 0);
  50226. ExpectIntEQ(ASN1_TIME_print(bio, notBefore), 1);
  50227. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  50228. ExpectIntEQ(XMEMCMP(buf, "Dec 13 22:19:28 2023 GMT", sizeof(buf) - 1), 0);
  50229. /* Test BIO_write fails. */
  50230. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  50231. /* Ensure there is 0 bytes available to write into. */
  50232. ExpectIntEQ(BIO_write(fixed, buf, 1), 1);
  50233. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  50234. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  50235. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  50236. ExpectIntEQ(BIO_set_write_buf_size(fixed, 23), 1);
  50237. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  50238. /* create a bad time and test results */
  50239. ExpectNotNull(notAfter = X509_get_notAfter(x509));
  50240. ExpectIntEQ(ASN1_TIME_check(notAfter), 1);
  50241. if (EXPECT_SUCCESS()) {
  50242. notAfter->data[8] = 0;
  50243. notAfter->data[3] = 0;
  50244. }
  50245. ExpectIntNE(ASN1_TIME_print(bio, notAfter), 1);
  50246. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 14);
  50247. ExpectIntEQ(XMEMCMP(buf, "Bad time value", 14), 0);
  50248. ExpectIntEQ(ASN1_TIME_check(notAfter), 0);
  50249. BIO_free(bio);
  50250. BIO_free(fixed);
  50251. X509_free(x509);
  50252. #endif
  50253. return EXPECT_RESULT();
  50254. }
  50255. static int test_wolfSSL_ASN1_UTCTIME_print(void)
  50256. {
  50257. EXPECT_DECLS;
  50258. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && !defined(NO_BIO)
  50259. BIO* bio = NULL;
  50260. ASN1_UTCTIME* utc = NULL;
  50261. unsigned char buf[25];
  50262. const char* validDate = "190424111501Z"; /* UTC = YYMMDDHHMMSSZ */
  50263. const char* invalidDate = "190424111501X"; /* UTC = YYMMDDHHMMSSZ */
  50264. const char* genDate = "20190424111501Z"; /* GEN = YYYYMMDDHHMMSSZ */
  50265. /* Valid date */
  50266. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  50267. ExpectNotNull(utc = (ASN1_UTCTIME*)XMALLOC(sizeof(ASN1_UTCTIME), NULL,
  50268. DYNAMIC_TYPE_ASN1));
  50269. if (utc != NULL) {
  50270. utc->type = ASN_UTC_TIME;
  50271. utc->length = ASN_UTC_TIME_SIZE;
  50272. XMEMCPY(utc->data, (byte*)validDate, ASN_UTC_TIME_SIZE);
  50273. }
  50274. ExpectIntEQ(ASN1_UTCTIME_print(NULL, NULL), 0);
  50275. ExpectIntEQ(ASN1_UTCTIME_print(bio, NULL), 0);
  50276. ExpectIntEQ(ASN1_UTCTIME_print(NULL, utc), 0);
  50277. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 1);
  50278. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  50279. ExpectIntEQ(XMEMCMP(buf, "Apr 24 11:15:01 2019 GMT", sizeof(buf)-1), 0);
  50280. XMEMSET(buf, 0, sizeof(buf));
  50281. BIO_free(bio);
  50282. bio = NULL;
  50283. /* Invalid format */
  50284. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  50285. if (utc != NULL) {
  50286. utc->type = ASN_UTC_TIME;
  50287. utc->length = ASN_UTC_TIME_SIZE;
  50288. XMEMCPY(utc->data, (byte*)invalidDate, ASN_UTC_TIME_SIZE);
  50289. }
  50290. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 0);
  50291. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 14);
  50292. ExpectIntEQ(XMEMCMP(buf, "Bad time value", 14), 0);
  50293. /* Invalid type */
  50294. if (utc != NULL) {
  50295. utc->type = ASN_GENERALIZED_TIME;
  50296. utc->length = ASN_GENERALIZED_TIME_SIZE;
  50297. XMEMCPY(utc->data, (byte*)genDate, ASN_GENERALIZED_TIME_SIZE);
  50298. }
  50299. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 0);
  50300. XFREE(utc, NULL, DYNAMIC_TYPE_ASN1);
  50301. BIO_free(bio);
  50302. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME && !NO_BIO */
  50303. return EXPECT_RESULT();
  50304. }
  50305. static int test_wolfSSL_ASN1_TYPE(void)
  50306. {
  50307. EXPECT_DECLS;
  50308. #if defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD) || \
  50309. defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_WPAS)
  50310. WOLFSSL_ASN1_TYPE* t = NULL;
  50311. WOLFSSL_ASN1_OBJECT* obj = NULL;
  50312. #ifndef NO_ASN_TIME
  50313. WOLFSSL_ASN1_TIME* time = NULL;
  50314. #endif
  50315. WOLFSSL_ASN1_STRING* str = NULL;
  50316. unsigned char data[] = { 0x00 };
  50317. ASN1_TYPE_set(NULL, V_ASN1_NULL, NULL);
  50318. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50319. ASN1_TYPE_set(t, V_ASN1_EOC, NULL);
  50320. wolfSSL_ASN1_TYPE_free(t);
  50321. t = NULL;
  50322. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50323. ASN1_TYPE_set(t, V_ASN1_NULL, NULL);
  50324. ASN1_TYPE_set(t, V_ASN1_NULL, data);
  50325. wolfSSL_ASN1_TYPE_free(t);
  50326. t = NULL;
  50327. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50328. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  50329. ASN1_TYPE_set(t, V_ASN1_OBJECT, obj);
  50330. wolfSSL_ASN1_TYPE_free(t);
  50331. t = NULL;
  50332. #ifndef NO_ASN_TIME
  50333. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50334. ExpectNotNull(time = wolfSSL_ASN1_TIME_new());
  50335. ASN1_TYPE_set(t, V_ASN1_UTCTIME, time);
  50336. wolfSSL_ASN1_TYPE_free(t);
  50337. t = NULL;
  50338. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50339. ExpectNotNull(time = wolfSSL_ASN1_TIME_new());
  50340. ASN1_TYPE_set(t, V_ASN1_GENERALIZEDTIME, time);
  50341. wolfSSL_ASN1_TYPE_free(t);
  50342. t = NULL;
  50343. #endif
  50344. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50345. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  50346. ASN1_TYPE_set(t, V_ASN1_UTF8STRING, str);
  50347. wolfSSL_ASN1_TYPE_free(t);
  50348. t = NULL;
  50349. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50350. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  50351. ASN1_TYPE_set(t, V_ASN1_PRINTABLESTRING, str);
  50352. wolfSSL_ASN1_TYPE_free(t);
  50353. t = NULL;
  50354. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50355. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  50356. ASN1_TYPE_set(t, V_ASN1_T61STRING, str);
  50357. wolfSSL_ASN1_TYPE_free(t);
  50358. t = NULL;
  50359. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50360. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  50361. ASN1_TYPE_set(t, V_ASN1_IA5STRING, str);
  50362. wolfSSL_ASN1_TYPE_free(t);
  50363. t = NULL;
  50364. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50365. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  50366. ASN1_TYPE_set(t, V_ASN1_UNIVERSALSTRING, str);
  50367. wolfSSL_ASN1_TYPE_free(t);
  50368. t = NULL;
  50369. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50370. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  50371. ASN1_TYPE_set(t, V_ASN1_SEQUENCE, str);
  50372. wolfSSL_ASN1_TYPE_free(t);
  50373. t = NULL;
  50374. #endif
  50375. return EXPECT_RESULT();
  50376. }
  50377. /* Testing code used in old dpp.c in hostap */
  50378. #if defined(OPENSSL_ALL) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  50379. typedef struct {
  50380. /* AlgorithmIdentifier ecPublicKey with optional parameters present
  50381. * as an OID identifying the curve */
  50382. X509_ALGOR *alg;
  50383. /* Compressed format public key per ANSI X9.63 */
  50384. ASN1_BIT_STRING *pub_key;
  50385. } DPP_BOOTSTRAPPING_KEY;
  50386. ASN1_SEQUENCE(DPP_BOOTSTRAPPING_KEY) = {
  50387. ASN1_SIMPLE(DPP_BOOTSTRAPPING_KEY, alg, X509_ALGOR),
  50388. ASN1_SIMPLE(DPP_BOOTSTRAPPING_KEY, pub_key, ASN1_BIT_STRING)
  50389. } ASN1_SEQUENCE_END(DPP_BOOTSTRAPPING_KEY)
  50390. IMPLEMENT_ASN1_FUNCTIONS(DPP_BOOTSTRAPPING_KEY)
  50391. typedef struct {
  50392. int type;
  50393. union {
  50394. ASN1_BIT_STRING *str1;
  50395. ASN1_BIT_STRING *str2;
  50396. ASN1_BIT_STRING *str3;
  50397. } d;
  50398. } ASN1_CHOICE_TEST;
  50399. ASN1_CHOICE(ASN1_CHOICE_TEST) = {
  50400. ASN1_IMP(ASN1_CHOICE_TEST, d.str1, ASN1_BIT_STRING, 1),
  50401. ASN1_IMP(ASN1_CHOICE_TEST, d.str2, ASN1_BIT_STRING, 2),
  50402. ASN1_IMP(ASN1_CHOICE_TEST, d.str3, ASN1_BIT_STRING, 3)
  50403. } ASN1_CHOICE_END(ASN1_CHOICE_TEST)
  50404. IMPLEMENT_ASN1_FUNCTIONS(ASN1_CHOICE_TEST)
  50405. /* Test nested objects */
  50406. typedef struct {
  50407. DPP_BOOTSTRAPPING_KEY* key;
  50408. ASN1_INTEGER* asnNum;
  50409. ASN1_INTEGER* expNum;
  50410. STACK_OF(ASN1_GENERALSTRING) *strList;
  50411. ASN1_CHOICE_TEST* str;
  50412. } TEST_ASN1_NEST1;
  50413. ASN1_SEQUENCE(TEST_ASN1_NEST1) = {
  50414. ASN1_SIMPLE(TEST_ASN1_NEST1, key, DPP_BOOTSTRAPPING_KEY),
  50415. ASN1_SIMPLE(TEST_ASN1_NEST1, asnNum, ASN1_INTEGER),
  50416. ASN1_EXP(TEST_ASN1_NEST1, expNum, ASN1_INTEGER, 0),
  50417. ASN1_EXP_SEQUENCE_OF(TEST_ASN1_NEST1, strList, ASN1_GENERALSTRING, 1),
  50418. ASN1_SIMPLE(TEST_ASN1_NEST1, str, ASN1_CHOICE_TEST)
  50419. } ASN1_SEQUENCE_END(TEST_ASN1_NEST1)
  50420. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_NEST1)
  50421. typedef struct {
  50422. ASN1_INTEGER* num;
  50423. DPP_BOOTSTRAPPING_KEY* key;
  50424. TEST_ASN1_NEST1* asn1_obj;
  50425. } TEST_ASN1_NEST2;
  50426. ASN1_SEQUENCE(TEST_ASN1_NEST2) = {
  50427. ASN1_SIMPLE(TEST_ASN1_NEST2, num, ASN1_INTEGER),
  50428. ASN1_SIMPLE(TEST_ASN1_NEST2, key, DPP_BOOTSTRAPPING_KEY),
  50429. ASN1_SIMPLE(TEST_ASN1_NEST2, asn1_obj, TEST_ASN1_NEST1)
  50430. } ASN1_SEQUENCE_END(TEST_ASN1_NEST2)
  50431. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_NEST2)
  50432. /* End nested objects */
  50433. typedef struct {
  50434. ASN1_INTEGER *integer;
  50435. } TEST_ASN1;
  50436. ASN1_SEQUENCE(TEST_ASN1) = {
  50437. ASN1_SIMPLE(TEST_ASN1, integer, ASN1_INTEGER),
  50438. } ASN1_SEQUENCE_END(TEST_ASN1)
  50439. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1)
  50440. typedef STACK_OF(ASN1_INTEGER) TEST_ASN1_ITEM;
  50441. ASN1_ITEM_TEMPLATE(TEST_ASN1_ITEM) =
  50442. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, MemName, ASN1_INTEGER)
  50443. ASN1_ITEM_TEMPLATE_END(TEST_ASN1_ITEM)
  50444. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_ITEM)
  50445. #endif
  50446. static int test_wolfSSL_IMPLEMENT_ASN1_FUNCTIONS(void)
  50447. {
  50448. EXPECT_DECLS;
  50449. /* Testing code used in dpp.c in hostap */
  50450. #if defined(OPENSSL_ALL) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  50451. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  50452. EC_KEY *eckey = NULL;
  50453. EVP_PKEY *key = NULL;
  50454. size_t len = 0;
  50455. unsigned char *der = NULL;
  50456. unsigned char *der2 = NULL;
  50457. const unsigned char *tmp = NULL;
  50458. DPP_BOOTSTRAPPING_KEY *bootstrap = NULL, *bootstrap2 = NULL;
  50459. const unsigned char *in = ecc_clikey_der_256;
  50460. WOLFSSL_ASN1_OBJECT* ec_obj = NULL;
  50461. WOLFSSL_ASN1_OBJECT* group_obj = NULL;
  50462. const EC_GROUP *group = NULL;
  50463. const EC_POINT *point = NULL;
  50464. int nid;
  50465. TEST_ASN1 *test_asn1 = NULL;
  50466. TEST_ASN1 *test_asn1_2 = NULL;
  50467. const unsigned char badObjDer[] = { 0x06, 0x00 };
  50468. const unsigned char goodObjDer[] = {
  50469. 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01
  50470. };
  50471. WOLFSSL_ASN1_ITEM emptyTemplate;
  50472. XMEMSET(&emptyTemplate, 0, sizeof(WOLFSSL_ASN1_ITEM));
  50473. ExpectNotNull(bootstrap = DPP_BOOTSTRAPPING_KEY_new());
  50474. der = NULL;
  50475. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(NULL, &der), -1);
  50476. ExpectIntEQ(wolfSSL_ASN1_item_i2d(bootstrap, &der, NULL), -1);
  50477. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), -1);
  50478. ExpectNotNull(key = d2i_PrivateKey(EVP_PKEY_EC, NULL, &in,
  50479. (long)sizeof_ecc_clikey_der_256));
  50480. ExpectNotNull(eckey = EVP_PKEY_get1_EC_KEY(key));
  50481. ExpectNotNull(group = EC_KEY_get0_group(eckey));
  50482. ExpectNotNull(point = EC_KEY_get0_public_key(eckey));
  50483. nid = EC_GROUP_get_curve_name(group);
  50484. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  50485. group_obj = OBJ_nid2obj(nid);
  50486. if ((ec_obj != NULL) && (group_obj != NULL)) {
  50487. ExpectIntEQ(X509_ALGOR_set0(bootstrap->alg, ec_obj, V_ASN1_OBJECT,
  50488. group_obj), 1);
  50489. if (EXPECT_SUCCESS()) {
  50490. ec_obj = NULL;
  50491. group_obj = NULL;
  50492. }
  50493. }
  50494. wolfSSL_ASN1_OBJECT_free(group_obj);
  50495. wolfSSL_ASN1_OBJECT_free(ec_obj);
  50496. ExpectIntEQ(EC_POINT_point2oct(group, point, 0, NULL, 0, NULL), 0);
  50497. #ifdef HAVE_COMP_KEY
  50498. ExpectIntGT((len = EC_POINT_point2oct(
  50499. group, point, POINT_CONVERSION_COMPRESSED,
  50500. NULL, 0, NULL)), 0);
  50501. #else
  50502. ExpectIntGT((len = EC_POINT_point2oct(
  50503. group, point, POINT_CONVERSION_UNCOMPRESSED,
  50504. NULL, 0, NULL)), 0);
  50505. #endif
  50506. ExpectNotNull(der = (unsigned char*)XMALLOC(len, NULL, DYNAMIC_TYPE_ASN1));
  50507. #ifdef HAVE_COMP_KEY
  50508. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_COMPRESSED,
  50509. der, len-1, NULL), 0);
  50510. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_COMPRESSED,
  50511. der, len, NULL), len);
  50512. #else
  50513. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_UNCOMPRESSED,
  50514. der, len-1, NULL), 0);
  50515. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_UNCOMPRESSED,
  50516. der, len, NULL), len);
  50517. #endif
  50518. if (EXPECT_SUCCESS()) {
  50519. bootstrap->pub_key->data = der;
  50520. bootstrap->pub_key->length = (int)len;
  50521. /* Not actually used */
  50522. bootstrap->pub_key->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
  50523. bootstrap->pub_key->flags |= ASN1_STRING_FLAG_BITS_LEFT;
  50524. }
  50525. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, NULL), 16+len);
  50526. der = NULL;
  50527. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), 16+len);
  50528. der2 = NULL;
  50529. #ifdef WOLFSSL_ASN_TEMPLATE
  50530. tmp = der;
  50531. ExpectNotNull(d2i_DPP_BOOTSTRAPPING_KEY(&bootstrap2, &tmp, 16+len));
  50532. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap2, &der2), 16+len);
  50533. ExpectBufEQ(der, der2, 49);
  50534. #endif
  50535. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50536. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  50537. EVP_PKEY_free(key);
  50538. EC_KEY_free(eckey);
  50539. DPP_BOOTSTRAPPING_KEY_free(bootstrap);
  50540. DPP_BOOTSTRAPPING_KEY_free(bootstrap2);
  50541. bootstrap = NULL;
  50542. DPP_BOOTSTRAPPING_KEY_free(NULL);
  50543. /* Create bootstrap key with bad OBJECT_ID DER data, parameter that is
  50544. * a NULL and an empty BIT_STRING. */
  50545. ExpectNotNull(bootstrap = DPP_BOOTSTRAPPING_KEY_new());
  50546. ExpectNotNull(bootstrap->alg->algorithm = wolfSSL_ASN1_OBJECT_new());
  50547. if (EXPECT_SUCCESS()) {
  50548. bootstrap->alg->algorithm->obj = badObjDer;
  50549. bootstrap->alg->algorithm->objSz = (unsigned int)sizeof(badObjDer);
  50550. }
  50551. ExpectNotNull(bootstrap->alg->parameter = wolfSSL_ASN1_TYPE_new());
  50552. if (EXPECT_SUCCESS()) {
  50553. bootstrap->alg->parameter->type = V_ASN1_NULL;
  50554. bootstrap->alg->parameter->value.ptr = NULL;
  50555. bootstrap->pub_key->data = NULL;
  50556. bootstrap->pub_key->length = 0;
  50557. /* Not actually used */
  50558. bootstrap->pub_key->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
  50559. bootstrap->pub_key->flags |= ASN1_STRING_FLAG_BITS_LEFT;
  50560. }
  50561. /* Encode with bad OBJECT_ID. */
  50562. der = NULL;
  50563. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), -1);
  50564. /* Fix OBJECT_ID and encode with empty BIT_STRING. */
  50565. if (EXPECT_SUCCESS()) {
  50566. bootstrap->alg->algorithm->obj = goodObjDer;
  50567. bootstrap->alg->algorithm->objSz = (unsigned int)sizeof(goodObjDer);
  50568. bootstrap->alg->algorithm->grp = 2;
  50569. }
  50570. der = NULL;
  50571. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), 16);
  50572. ExpectIntEQ(wolfSSL_ASN1_item_i2d(bootstrap, &der, &emptyTemplate), -1);
  50573. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50574. DPP_BOOTSTRAPPING_KEY_free(bootstrap);
  50575. /* Test integer */
  50576. ExpectNotNull(test_asn1 = TEST_ASN1_new());
  50577. der = NULL;
  50578. ExpectIntEQ(ASN1_INTEGER_set(test_asn1->integer, 100), 1);
  50579. ExpectIntEQ(i2d_TEST_ASN1(test_asn1, &der), 5);
  50580. tmp = der;
  50581. ExpectNotNull(d2i_TEST_ASN1(&test_asn1_2, &tmp, 5));
  50582. der2 = NULL;
  50583. ExpectIntEQ(i2d_TEST_ASN1(test_asn1_2, &der2), 5);
  50584. ExpectBufEQ(der, der2, 5);
  50585. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50586. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  50587. TEST_ASN1_free(test_asn1);
  50588. TEST_ASN1_free(test_asn1_2);
  50589. /* Test integer cases. */
  50590. ExpectNull(wolfSSL_ASN1_item_new(NULL));
  50591. TEST_ASN1_free(NULL);
  50592. /* Test nested asn1 objects */
  50593. {
  50594. TEST_ASN1_NEST2 *nested_asn1 = NULL;
  50595. TEST_ASN1_NEST2 *nested_asn1_2 = NULL;
  50596. int i;
  50597. ExpectNotNull(nested_asn1 = TEST_ASN1_NEST2_new());
  50598. /* Populate nested_asn1 with some random data */
  50599. /* nested_asn1->num */
  50600. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->num, 30003), 1);
  50601. /* nested_asn1->key */
  50602. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  50603. group_obj = OBJ_nid2obj(NID_secp256k1);
  50604. ExpectIntEQ(X509_ALGOR_set0(nested_asn1->key->alg, ec_obj,
  50605. V_ASN1_OBJECT, group_obj), 1);
  50606. ec_obj = NULL;
  50607. group_obj = NULL;
  50608. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->key->pub_key, 50, 1),
  50609. 1);
  50610. /* nested_asn1->asn1_obj->key */
  50611. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  50612. group_obj = OBJ_nid2obj(NID_secp256k1);
  50613. ExpectIntEQ(X509_ALGOR_set0(nested_asn1->asn1_obj->key->alg, ec_obj,
  50614. V_ASN1_OBJECT, group_obj), 1);
  50615. ec_obj = NULL;
  50616. group_obj = NULL;
  50617. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->asn1_obj->key->pub_key,
  50618. 500, 1), 1);
  50619. /* nested_asn1->asn1_obj->asnNum */
  50620. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->asn1_obj->asnNum, 666666), 1);
  50621. /* nested_asn1->asn1_obj->expNum */
  50622. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->asn1_obj->expNum, 22222), 1);
  50623. /* nested_asn1->asn1_obj->strList */
  50624. for (i = 10; i >= 0; i--) {
  50625. ASN1_GENERALSTRING* genStr = NULL;
  50626. char fmtStr[20];
  50627. ExpectIntGT(snprintf(fmtStr, sizeof(fmtStr), "Bonjour #%d", i), 0);
  50628. ExpectNotNull(genStr = ASN1_GENERALSTRING_new());
  50629. ExpectIntEQ(ASN1_GENERALSTRING_set(genStr, fmtStr, -1), 1);
  50630. ExpectIntGT(
  50631. sk_ASN1_GENERALSTRING_push(nested_asn1->asn1_obj->strList,
  50632. genStr), 0);
  50633. }
  50634. /* nested_asn1->asn1_obj->str */
  50635. ExpectNotNull(nested_asn1->asn1_obj->str->d.str2
  50636. = ASN1_BIT_STRING_new());
  50637. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->asn1_obj->str->d.str2,
  50638. 150, 1), 1);
  50639. nested_asn1->asn1_obj->str->type = 2;
  50640. der = NULL;
  50641. ExpectIntEQ(i2d_TEST_ASN1_NEST2(nested_asn1, &der), 285);
  50642. #ifdef WOLFSSL_ASN_TEMPLATE
  50643. tmp = der;
  50644. ExpectNotNull(d2i_TEST_ASN1_NEST2(&nested_asn1_2, &tmp, 285));
  50645. der2 = NULL;
  50646. ExpectIntEQ(i2d_TEST_ASN1_NEST2(nested_asn1_2, &der2), 285);
  50647. ExpectBufEQ(der, der2, 285);
  50648. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  50649. #endif
  50650. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50651. TEST_ASN1_NEST2_free(nested_asn1);
  50652. TEST_ASN1_NEST2_free(nested_asn1_2);
  50653. }
  50654. /* Test ASN1_ITEM_TEMPLATE */
  50655. {
  50656. TEST_ASN1_ITEM* asn1_item = NULL;
  50657. TEST_ASN1_ITEM* asn1_item2 = NULL;
  50658. int i;
  50659. ExpectNotNull(asn1_item = TEST_ASN1_ITEM_new());
  50660. for (i = 0; i < 11; i++) {
  50661. ASN1_INTEGER* asn1_num = NULL;
  50662. ExpectNotNull(asn1_num = ASN1_INTEGER_new());
  50663. ExpectIntEQ(ASN1_INTEGER_set(asn1_num, i), 1);
  50664. ExpectIntGT(wolfSSL_sk_insert(asn1_item, asn1_num, -1), 0);
  50665. }
  50666. der = NULL;
  50667. ExpectIntEQ(i2d_TEST_ASN1_ITEM(asn1_item, &der), 35);
  50668. tmp = der;
  50669. ExpectNotNull(d2i_TEST_ASN1_ITEM(&asn1_item2, &tmp, 35));
  50670. der2 = NULL;
  50671. ExpectIntEQ(i2d_TEST_ASN1_ITEM(asn1_item2, &der2), 35);
  50672. ExpectBufEQ(der, der2, 35);
  50673. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50674. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  50675. TEST_ASN1_ITEM_free(asn1_item);
  50676. TEST_ASN1_ITEM_free(asn1_item2);
  50677. }
  50678. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  50679. #endif /* OPENSSL_ALL && HAVE_ECC && USE_CERT_BUFFERS_256 */
  50680. return EXPECT_RESULT();
  50681. }
  50682. static int test_wolfSSL_i2d_ASN1_TYPE(void)
  50683. {
  50684. EXPECT_DECLS;
  50685. #if defined(OPENSSL_EXTRA)
  50686. /* Taken from one of sssd's certs othernames */
  50687. unsigned char str_bin[] = {
  50688. 0x04, 0x10, 0xa4, 0x9b, 0xc8, 0xf4, 0x85, 0x8e, 0x89, 0x4d, 0x85, 0x8d,
  50689. 0x27, 0xbd, 0x63, 0xaa, 0x93, 0x93
  50690. };
  50691. ASN1_TYPE* asn1type = NULL;
  50692. unsigned char* der = NULL;
  50693. /* Create ASN1_TYPE manually as we don't have a d2i version yet */
  50694. {
  50695. ASN1_STRING* str = NULL;
  50696. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_SEQUENCE));
  50697. ExpectIntEQ(ASN1_STRING_set(str, str_bin, sizeof(str_bin)), 1);
  50698. ExpectNotNull(asn1type = ASN1_TYPE_new());
  50699. ASN1_TYPE_set(asn1type, V_ASN1_SEQUENCE, str);
  50700. }
  50701. ExpectIntEQ(i2d_ASN1_TYPE(asn1type, NULL), sizeof(str_bin));
  50702. ExpectIntEQ(i2d_ASN1_TYPE(asn1type, &der), sizeof(str_bin));
  50703. ExpectBufEQ(der, str_bin, sizeof(str_bin));
  50704. ASN1_TYPE_free(asn1type);
  50705. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50706. #endif
  50707. return EXPECT_RESULT();
  50708. }
  50709. static int test_wolfSSL_i2d_ASN1_SEQUENCE(void)
  50710. {
  50711. EXPECT_DECLS;
  50712. #if defined(OPENSSL_EXTRA)
  50713. /* Taken from one of sssd's certs othernames */
  50714. unsigned char str_bin[] = {
  50715. 0x04, 0x10, 0xa4, 0x9b, 0xc8, 0xf4, 0x85, 0x8e, 0x89, 0x4d, 0x85, 0x8d,
  50716. 0x27, 0xbd, 0x63, 0xaa, 0x93, 0x93
  50717. };
  50718. ASN1_STRING* str = NULL;
  50719. unsigned char* der = NULL;
  50720. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_SEQUENCE));
  50721. ExpectIntEQ(ASN1_STRING_set(str, str_bin, sizeof(str_bin)), 1);
  50722. ExpectIntEQ(i2d_ASN1_SEQUENCE(str, NULL), sizeof(str_bin));
  50723. ExpectIntEQ(i2d_ASN1_SEQUENCE(str, &der), sizeof(str_bin));
  50724. ASN1_STRING_free(str);
  50725. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50726. #endif
  50727. return EXPECT_RESULT();
  50728. }
  50729. static int test_ASN1_strings(void)
  50730. {
  50731. EXPECT_DECLS;
  50732. #if defined(OPENSSL_EXTRA)
  50733. char text[] = "\0\0test string";
  50734. unsigned char* der = NULL;
  50735. ASN1_STRING* str = NULL;
  50736. /* Set the length byte */
  50737. text[1] = XSTRLEN(text + 2);
  50738. /* GENERALSTRING */
  50739. {
  50740. const unsigned char* p = (const unsigned char*)text;
  50741. text[0] = ASN_GENERALSTRING;
  50742. ExpectNotNull(d2i_ASN1_GENERALSTRING(&str, &p, sizeof(text)));
  50743. ExpectIntEQ(i2d_ASN1_GENERALSTRING(str, &der), 13);
  50744. ASN1_STRING_free(str);
  50745. str = NULL;
  50746. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50747. der = NULL;
  50748. }
  50749. /* OCTET_STRING */
  50750. {
  50751. const unsigned char* p = (const unsigned char*)text;
  50752. text[0] = ASN_OCTET_STRING;
  50753. ExpectNotNull(d2i_ASN1_OCTET_STRING(&str, &p, sizeof(text)));
  50754. ExpectIntEQ(i2d_ASN1_OCTET_STRING(str, &der), 13);
  50755. ASN1_STRING_free(str);
  50756. str = NULL;
  50757. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50758. der = NULL;
  50759. }
  50760. /* UTF8STRING */
  50761. {
  50762. const unsigned char* p = (const unsigned char*)text;
  50763. text[0] = ASN_UTF8STRING;
  50764. ExpectNotNull(d2i_ASN1_UTF8STRING(&str, &p, sizeof(text)));
  50765. ExpectIntEQ(i2d_ASN1_UTF8STRING(str, &der), 13);
  50766. ASN1_STRING_free(str);
  50767. str = NULL;
  50768. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50769. der = NULL;
  50770. }
  50771. #endif
  50772. return EXPECT_RESULT();
  50773. }
  50774. static int test_wolfSSL_lhash(void)
  50775. {
  50776. EXPECT_DECLS;
  50777. #ifdef OPENSSL_ALL
  50778. const char testStr[] = "Like a true nature's child\n"
  50779. "We were born\n"
  50780. "Born to be wild";
  50781. #ifdef NO_SHA
  50782. ExpectIntEQ(lh_strhash(testStr), 0xf9dc8a43);
  50783. #else
  50784. ExpectIntEQ(lh_strhash(testStr), 0x5b7541dc);
  50785. #endif
  50786. #endif
  50787. return EXPECT_RESULT();
  50788. }
  50789. static int test_wolfSSL_X509_NAME(void)
  50790. {
  50791. EXPECT_DECLS;
  50792. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
  50793. !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  50794. !defined(NO_RSA) && defined(WOLFSSL_CERT_GEN) && \
  50795. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT) || \
  50796. defined(OPENSSL_EXTRA))
  50797. X509* x509 = NULL;
  50798. const unsigned char* c = NULL;
  50799. unsigned char buf[4096];
  50800. int bytes = 0;
  50801. XFILE f = XBADFILE;
  50802. const X509_NAME* a = NULL;
  50803. const X509_NAME* b = NULL;
  50804. X509_NAME* d2i_name = NULL;
  50805. int sz = 0;
  50806. unsigned char* tmp = NULL;
  50807. char file[] = "./certs/ca-cert.der";
  50808. #ifndef OPENSSL_EXTRA_X509_SMALL
  50809. byte empty[] = { /* CN=empty emailAddress= */
  50810. 0x30, 0x21, 0x31, 0x0E, 0x30, 0x0C, 0x06, 0x03,
  50811. 0x55, 0x04, 0x03, 0x0C, 0x05, 0x65, 0x6D, 0x70,
  50812. 0x74, 0x79, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x09,
  50813. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  50814. 0x01, 0x16, 0x00
  50815. };
  50816. #endif
  50817. #ifndef OPENSSL_EXTRA_X509_SMALL
  50818. /* test compile of deprecated function, returns 0 */
  50819. ExpectIntEQ(CRYPTO_thread_id(), 0);
  50820. #endif
  50821. ExpectNotNull(a = X509_NAME_new());
  50822. X509_NAME_free((X509_NAME*)a);
  50823. a = NULL;
  50824. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  50825. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  50826. if (f != XBADFILE)
  50827. XFCLOSE(f);
  50828. c = buf;
  50829. ExpectNotNull(x509 = wolfSSL_X509_d2i_ex(NULL, c, bytes, HEAP_HINT));
  50830. /* test cmp function */
  50831. ExpectNotNull(a = X509_get_issuer_name(x509));
  50832. ExpectNotNull(b = X509_get_subject_name(x509));
  50833. #ifndef OPENSSL_EXTRA_X509_SMALL
  50834. ExpectIntEQ(X509_NAME_cmp(a, b), 0); /* self signed should be 0 */
  50835. #endif
  50836. tmp = buf;
  50837. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)a, &tmp)), 0);
  50838. if (sz > 0 && tmp == buf) {
  50839. fprintf(stderr, "\nERROR - %s line %d failed with:", __FILE__,
  50840. __LINE__);
  50841. fprintf(stderr, " Expected pointer to be incremented\n");
  50842. abort();
  50843. }
  50844. #ifndef OPENSSL_EXTRA_X509_SMALL
  50845. tmp = buf;
  50846. ExpectNotNull(d2i_name = d2i_X509_NAME(NULL, &tmp, sz));
  50847. #endif
  50848. /* if output parameter is NULL, should still return required size. */
  50849. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, NULL)), 0);
  50850. /* retry but with the function creating a buffer */
  50851. tmp = NULL;
  50852. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, &tmp)), 0);
  50853. XFREE(tmp, NULL, DYNAMIC_TYPE_OPENSSL);
  50854. tmp = NULL;
  50855. #ifdef WOLFSSL_CERT_NAME_ALL
  50856. /* test for givenName and name */
  50857. {
  50858. WOLFSSL_X509_NAME_ENTRY* entry = NULL;
  50859. const byte gName[] = "test-given-name";
  50860. const byte name[] = "test-name";
  50861. ExpectNotNull(entry = wolfSSL_X509_NAME_ENTRY_create_by_NID(NULL,
  50862. NID_givenName, ASN_UTF8STRING, gName, sizeof(gName)));
  50863. ExpectIntEQ(wolfSSL_X509_NAME_add_entry((X509_NAME*)b, entry, -1, 0),
  50864. 1);
  50865. wolfSSL_X509_NAME_ENTRY_free(entry);
  50866. entry = NULL;
  50867. ExpectNotNull(entry = wolfSSL_X509_NAME_ENTRY_create_by_NID(NULL,
  50868. NID_name, ASN_UTF8STRING, name, sizeof(name)));
  50869. ExpectIntEQ(wolfSSL_X509_NAME_add_entry((X509_NAME*)b, entry, -1, 0),
  50870. 1);
  50871. wolfSSL_X509_NAME_ENTRY_free(entry);
  50872. tmp = NULL;
  50873. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, &tmp)), 0);
  50874. XFREE(tmp, NULL, DYNAMIC_TYPE_OPENSSL);
  50875. }
  50876. #endif
  50877. b = NULL;
  50878. ExpectNotNull(b = X509_NAME_dup((X509_NAME*)a));
  50879. #ifndef OPENSSL_EXTRA_X509_SMALL
  50880. ExpectIntEQ(X509_NAME_cmp(a, b), 0);
  50881. #endif
  50882. X509_NAME_free((X509_NAME*)b);
  50883. X509_NAME_free(d2i_name);
  50884. d2i_name = NULL;
  50885. X509_free(x509);
  50886. #ifndef OPENSSL_EXTRA_X509_SMALL
  50887. /* test with an empty domain component */
  50888. tmp = empty;
  50889. sz = sizeof(empty);
  50890. ExpectNotNull(d2i_name = d2i_X509_NAME(NULL, &tmp, sz));
  50891. ExpectIntEQ(X509_NAME_entry_count(d2i_name), 2);
  50892. /* size of empty emailAddress will be 0 */
  50893. tmp = buf;
  50894. ExpectIntEQ(X509_NAME_get_text_by_NID(d2i_name, NID_emailAddress,
  50895. (char*)tmp, sizeof(buf)), 0);
  50896. /* should contain no organization name */
  50897. tmp = buf;
  50898. ExpectIntEQ(X509_NAME_get_text_by_NID(d2i_name, NID_organizationName,
  50899. (char*)tmp, sizeof(buf)), -1);
  50900. X509_NAME_free(d2i_name);
  50901. #endif
  50902. #endif
  50903. return EXPECT_RESULT();
  50904. }
  50905. static int test_wolfSSL_X509_NAME_hash(void)
  50906. {
  50907. EXPECT_DECLS;
  50908. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  50909. !defined(NO_RSA) && !defined(NO_SHA) && !defined(NO_BIO)
  50910. BIO* bio = NULL;
  50911. X509* x509 = NULL;
  50912. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  50913. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  50914. ExpectNotNull(PEM_read_bio_X509(bio, &x509, NULL, NULL));
  50915. ExpectIntEQ(X509_NAME_hash(X509_get_subject_name(x509)), 0x137DC03F);
  50916. ExpectIntEQ(X509_NAME_hash(X509_get_issuer_name(x509)), 0xFDB2DA4);
  50917. X509_free(x509);
  50918. BIO_free(bio);
  50919. #endif
  50920. return EXPECT_RESULT();
  50921. }
  50922. static int test_wolfSSL_X509_NAME_print_ex(void)
  50923. {
  50924. EXPECT_DECLS;
  50925. #if (defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  50926. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  50927. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  50928. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))) && \
  50929. !defined(NO_BIO) && !defined(NO_RSA)
  50930. int memSz = 0;
  50931. byte* mem = NULL;
  50932. BIO* bio = NULL;
  50933. BIO* membio = NULL;
  50934. X509* x509 = NULL;
  50935. X509_NAME* name = NULL;
  50936. const char* expNormal = "C=US, CN=wolfssl.com";
  50937. const char* expEqSpace = "C = US, CN = wolfssl.com";
  50938. const char* expReverse = "CN=wolfssl.com, C=US";
  50939. const char* expNotEscaped = "C= US,+\"\\ , CN=#wolfssl.com<>;";
  50940. const char* expNotEscapedRev = "CN=#wolfssl.com<>;, C= US,+\"\\ ";
  50941. const char* expRFC5523 =
  50942. "CN=\\#wolfssl.com\\<\\>\\;, C=\\ US\\,\\+\\\"\\\\\\ ";
  50943. /* Test with real cert (svrCertFile) first */
  50944. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  50945. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  50946. ExpectNotNull(PEM_read_bio_X509(bio, &x509, NULL, NULL));
  50947. ExpectNotNull(name = X509_get_subject_name(x509));
  50948. /* Test without flags */
  50949. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50950. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  50951. BIO_free(membio);
  50952. membio = NULL;
  50953. /* Test flag: XN_FLAG_RFC2253 */
  50954. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50955. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  50956. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  50957. BIO_free(membio);
  50958. membio = NULL;
  50959. /* Test flag: XN_FLAG_RFC2253 | XN_FLAG_DN_REV */
  50960. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50961. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  50962. XN_FLAG_RFC2253 | XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  50963. BIO_free(membio);
  50964. membio = NULL;
  50965. X509_free(x509);
  50966. BIO_free(bio);
  50967. name = NULL;
  50968. /* Test normal case without escaped characters */
  50969. {
  50970. /* Create name: "/C=US/CN=wolfssl.com" */
  50971. ExpectNotNull(name = X509_NAME_new());
  50972. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName",
  50973. MBSTRING_UTF8, (byte*)"US", 2, -1, 0),
  50974. WOLFSSL_SUCCESS);
  50975. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName",
  50976. MBSTRING_UTF8, (byte*)"wolfssl.com", 11, -1, 0),
  50977. WOLFSSL_SUCCESS);
  50978. /* Test without flags */
  50979. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50980. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  50981. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  50982. ExpectIntEQ(memSz, XSTRLEN(expNormal));
  50983. ExpectIntEQ(XSTRNCMP((char*)mem, expNormal, XSTRLEN(expNormal)), 0);
  50984. BIO_free(membio);
  50985. membio = NULL;
  50986. /* Test with XN_FLAG_ONELINE which should enable XN_FLAG_SPC_EQ for
  50987. spaces aroun '=' */
  50988. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50989. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, XN_FLAG_ONELINE),
  50990. WOLFSSL_SUCCESS);
  50991. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  50992. ExpectIntEQ(memSz, XSTRLEN(expEqSpace));
  50993. ExpectIntEQ(XSTRNCMP((char*)mem, expEqSpace, XSTRLEN(expEqSpace)), 0);
  50994. BIO_free(membio);
  50995. membio = NULL;
  50996. /* Test flags: XN_FLAG_RFC2253 - should be reversed */
  50997. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50998. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  50999. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  51000. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  51001. ExpectIntEQ(memSz, XSTRLEN(expReverse));
  51002. BIO_free(membio);
  51003. membio = NULL;
  51004. /* Test flags: XN_FLAG_DN_REV - reversed */
  51005. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  51006. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  51007. XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  51008. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  51009. ExpectIntEQ(memSz, XSTRLEN(expReverse));
  51010. ExpectIntEQ(XSTRNCMP((char*)mem, expReverse, XSTRLEN(expReverse)), 0);
  51011. BIO_free(membio);
  51012. membio = NULL;
  51013. X509_NAME_free(name);
  51014. name = NULL;
  51015. }
  51016. /* Test RFC2253 characters are escaped with backslashes */
  51017. {
  51018. ExpectNotNull(name = X509_NAME_new());
  51019. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName",
  51020. /* space at beginning and end, and: ,+"\ */
  51021. MBSTRING_UTF8, (byte*)" US,+\"\\ ", 8, -1, 0),
  51022. WOLFSSL_SUCCESS);
  51023. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName",
  51024. /* # at beginning, and: <>;*/
  51025. MBSTRING_UTF8, (byte*)"#wolfssl.com<>;", 15, -1, 0),
  51026. WOLFSSL_SUCCESS);
  51027. /* Test without flags */
  51028. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  51029. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  51030. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  51031. ExpectIntEQ(memSz, XSTRLEN(expNotEscaped));
  51032. ExpectIntEQ(XSTRNCMP((char*)mem, expNotEscaped,
  51033. XSTRLEN(expNotEscaped)), 0);
  51034. BIO_free(membio);
  51035. membio = NULL;
  51036. /* Test flags: XN_FLAG_RFC5523 - should be reversed and escaped */
  51037. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  51038. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  51039. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  51040. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  51041. ExpectIntEQ(memSz, XSTRLEN(expRFC5523));
  51042. ExpectIntEQ(XSTRNCMP((char*)mem, expRFC5523, XSTRLEN(expRFC5523)), 0);
  51043. BIO_free(membio);
  51044. membio = NULL;
  51045. /* Test flags: XN_FLAG_DN_REV - reversed but not escaped */
  51046. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  51047. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  51048. XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  51049. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  51050. ExpectIntEQ(memSz, XSTRLEN(expNotEscapedRev));
  51051. ExpectIntEQ(XSTRNCMP((char*)mem, expNotEscapedRev,
  51052. XSTRLEN(expNotEscapedRev)), 0);
  51053. BIO_free(membio);
  51054. X509_NAME_free(name);
  51055. }
  51056. #endif
  51057. return EXPECT_RESULT();
  51058. }
  51059. #ifndef NO_BIO
  51060. static int test_wolfSSL_X509_INFO_multiple_info(void)
  51061. {
  51062. EXPECT_DECLS;
  51063. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  51064. STACK_OF(X509_INFO) *info_stack = NULL;
  51065. X509_INFO *info = NULL;
  51066. int len;
  51067. int i;
  51068. const char* files[] = {
  51069. cliCertFile,
  51070. cliKeyFile,
  51071. /* This needs to be the order as svrCertFile contains the
  51072. * intermediate cert as well. */
  51073. svrKeyFile,
  51074. svrCertFile,
  51075. NULL,
  51076. };
  51077. const char** curFile;
  51078. BIO *fileBIO = NULL;
  51079. BIO *concatBIO = NULL;
  51080. byte tmp[FOURK_BUF];
  51081. /* concatenate the cert and the key file to force PEM_X509_INFO_read_bio
  51082. * to group objects together. */
  51083. ExpectNotNull(concatBIO = BIO_new(BIO_s_mem()));
  51084. for (curFile = files; EXPECT_SUCCESS() && *curFile != NULL; curFile++) {
  51085. int fileLen = 0;
  51086. ExpectNotNull(fileBIO = BIO_new_file(*curFile, "rb"));
  51087. ExpectIntGT(fileLen = wolfSSL_BIO_get_len(fileBIO), 0);
  51088. if (EXPECT_SUCCESS()) {
  51089. while ((len = BIO_read(fileBIO, tmp, sizeof(tmp))) > 0) {
  51090. ExpectIntEQ(BIO_write(concatBIO, tmp, len), len);
  51091. fileLen -= len;
  51092. if (EXPECT_FAIL())
  51093. break;
  51094. }
  51095. /* Make sure we read the entire file */
  51096. ExpectIntEQ(fileLen, 0);
  51097. }
  51098. BIO_free(fileBIO);
  51099. fileBIO = NULL;
  51100. }
  51101. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(concatBIO, NULL, NULL,
  51102. NULL));
  51103. ExpectIntEQ(sk_X509_INFO_num(info_stack), 3);
  51104. for (i = 0; i < sk_X509_INFO_num(info_stack); i++) {
  51105. ExpectNotNull(info = sk_X509_INFO_value(info_stack, i));
  51106. ExpectNotNull(info->x509);
  51107. ExpectNull(info->crl);
  51108. if (i != 0) {
  51109. ExpectNotNull(info->x_pkey);
  51110. ExpectIntEQ(X509_check_private_key(info->x509,
  51111. info->x_pkey->dec_pkey), 1);
  51112. }
  51113. else {
  51114. ExpectNull(info->x_pkey);
  51115. }
  51116. }
  51117. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  51118. BIO_free(concatBIO);
  51119. #endif
  51120. return EXPECT_RESULT();
  51121. }
  51122. #endif
  51123. #ifndef NO_BIO
  51124. static int test_wolfSSL_X509_INFO(void)
  51125. {
  51126. EXPECT_DECLS;
  51127. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  51128. STACK_OF(X509_INFO) *info_stack = NULL;
  51129. X509_INFO *info = NULL;
  51130. BIO *cert = NULL;
  51131. int i;
  51132. /* PEM in hex format to avoid null terminator */
  51133. byte data[] = {
  51134. 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47,
  51135. 0x49, 0x4e, 0x20, 0x43, 0x45, 0x52, 0x54, 0x63, 0x2d, 0x2d, 0x2d, 0x2d,
  51136. 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x44, 0x4d, 0x54, 0x42, 0x75, 0x51, 0x3d,
  51137. 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x2d, 0x2d,
  51138. 0x2d, 0x2d, 0x2d
  51139. };
  51140. /* PEM in hex format to avoid null terminator */
  51141. byte data2[] = {
  51142. 0x41, 0x53, 0x4e, 0x31, 0x20, 0x4f, 0x49, 0x44, 0x3a, 0x20, 0x70, 0x72,
  51143. 0x69, 0x6d, 0x65, 0x32, 0x35, 0x36, 0x76, 0x31, 0x0a, 0x2d, 0x2d, 0x2d,
  51144. 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x45, 0x43, 0x20, 0x50,
  51145. 0x41, 0x52, 0x41, 0x4d, 0x45, 0x54, 0x45, 0x52, 0x53, 0x2d, 0x2d, 0x2d,
  51146. 0x2d, 0x43, 0x65, 0x72, 0x74, 0x69, 0x2d, 0x0a, 0x42, 0x67, 0x67, 0x71,
  51147. 0x68, 0x6b, 0x6a, 0x4f, 0x50, 0x51, 0x4d, 0x42, 0x42, 0x77, 0x3d, 0x3d,
  51148. 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d
  51149. };
  51150. ExpectNotNull(cert = BIO_new_file(cliCertFileExt, "rb"));
  51151. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  51152. for (i = 0; i < sk_X509_INFO_num(info_stack); i++) {
  51153. ExpectNotNull(info = sk_X509_INFO_value(info_stack, i));
  51154. ExpectNotNull(info->x509);
  51155. ExpectNull(info->crl);
  51156. ExpectNull(info->x_pkey);
  51157. }
  51158. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  51159. info_stack = NULL;
  51160. BIO_free(cert);
  51161. cert = NULL;
  51162. ExpectNotNull(cert = BIO_new_file(cliCertFileExt, "rb"));
  51163. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  51164. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  51165. info_stack = NULL;
  51166. BIO_free(cert);
  51167. cert = NULL;
  51168. /* This case should fail due to invalid input. */
  51169. ExpectNotNull(cert = BIO_new(BIO_s_mem()));
  51170. ExpectIntEQ(BIO_write(cert, data, sizeof(data)), sizeof(data));
  51171. ExpectNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  51172. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  51173. info_stack = NULL;
  51174. BIO_free(cert);
  51175. cert = NULL;
  51176. ExpectNotNull(cert = BIO_new(BIO_s_mem()));
  51177. ExpectIntEQ(BIO_write(cert, data2, sizeof(data2)), sizeof(data2));
  51178. ExpectNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  51179. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  51180. BIO_free(cert);
  51181. #endif
  51182. return EXPECT_RESULT();
  51183. }
  51184. #endif
  51185. static int test_wolfSSL_X509_subject_name_hash(void)
  51186. {
  51187. EXPECT_DECLS;
  51188. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  51189. !defined(NO_RSA) && (!defined(NO_SHA) || !defined(NO_SHA256))
  51190. X509* x509 = NULL;
  51191. X509_NAME* subjectName = NULL;
  51192. unsigned long ret1 = 0;
  51193. unsigned long ret2 = 0;
  51194. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  51195. SSL_FILETYPE_PEM));
  51196. ExpectNotNull(subjectName = wolfSSL_X509_get_subject_name(x509));
  51197. /* These two
  51198. * - X509_subject_name_hash(x509)
  51199. * - X509_NAME_hash(X509_get_subject_name(x509))
  51200. * should give the same hash, if !defined(NO_SHA) is true. */
  51201. ret1 = X509_subject_name_hash(x509);
  51202. ExpectIntNE(ret1, 0);
  51203. #if !defined(NO_SHA)
  51204. ret2 = X509_NAME_hash(X509_get_subject_name(x509));
  51205. ExpectIntNE(ret2, 0);
  51206. ExpectIntEQ(ret1, ret2);
  51207. #else
  51208. (void) ret2;
  51209. #endif
  51210. X509_free(x509);
  51211. #endif
  51212. return EXPECT_RESULT();
  51213. }
  51214. static int test_wolfSSL_X509_issuer_name_hash(void)
  51215. {
  51216. EXPECT_DECLS;
  51217. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  51218. && !defined(NO_RSA) && (!defined(NO_SHA) || !defined(NO_SHA256))
  51219. X509* x509 = NULL;
  51220. X509_NAME* issuertName = NULL;
  51221. unsigned long ret1 = 0;
  51222. unsigned long ret2 = 0;
  51223. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  51224. SSL_FILETYPE_PEM));
  51225. ExpectNotNull(issuertName = wolfSSL_X509_get_issuer_name(x509));
  51226. /* These two
  51227. * - X509_issuer_name_hash(x509)
  51228. * - X509_NAME_hash(X509_get_issuer_name(x509))
  51229. * should give the same hash, if !defined(NO_SHA) is true. */
  51230. ret1 = X509_issuer_name_hash(x509);
  51231. ExpectIntNE(ret1, 0);
  51232. #if !defined(NO_SHA)
  51233. ret2 = X509_NAME_hash(X509_get_issuer_name(x509));
  51234. ExpectIntNE(ret2, 0);
  51235. ExpectIntEQ(ret1, ret2);
  51236. #else
  51237. (void) ret2;
  51238. #endif
  51239. X509_free(x509);
  51240. #endif
  51241. return EXPECT_RESULT();
  51242. }
  51243. static int test_wolfSSL_X509_check_host(void)
  51244. {
  51245. EXPECT_DECLS;
  51246. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  51247. && !defined(NO_SHA) && !defined(NO_RSA)
  51248. X509* x509 = NULL;
  51249. const char altName[] = "example.com";
  51250. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  51251. SSL_FILETYPE_PEM));
  51252. ExpectIntEQ(X509_check_host(x509, altName, XSTRLEN(altName), 0, NULL),
  51253. WOLFSSL_SUCCESS);
  51254. ExpectIntEQ(X509_check_host(x509, NULL, 0, 0, NULL),
  51255. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51256. X509_free(x509);
  51257. ExpectIntEQ(X509_check_host(NULL, altName, XSTRLEN(altName), 0, NULL),
  51258. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51259. #endif
  51260. return EXPECT_RESULT();
  51261. }
  51262. static int test_wolfSSL_X509_check_email(void)
  51263. {
  51264. EXPECT_DECLS;
  51265. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA)
  51266. X509* x509 = NULL;
  51267. const char goodEmail[] = "info@wolfssl.com";
  51268. const char badEmail[] = "disinfo@wolfssl.com";
  51269. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  51270. SSL_FILETYPE_PEM));
  51271. /* Should fail on non-matching email address */
  51272. ExpectIntEQ(wolfSSL_X509_check_email(x509, badEmail, XSTRLEN(badEmail), 0),
  51273. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51274. /* Should succeed on matching email address */
  51275. ExpectIntEQ(wolfSSL_X509_check_email(x509, goodEmail, XSTRLEN(goodEmail), 0),
  51276. WOLFSSL_SUCCESS);
  51277. /* Should compute length internally when not provided */
  51278. ExpectIntEQ(wolfSSL_X509_check_email(x509, goodEmail, 0, 0),
  51279. WOLFSSL_SUCCESS);
  51280. /* Should fail when email address is NULL */
  51281. ExpectIntEQ(wolfSSL_X509_check_email(x509, NULL, 0, 0),
  51282. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51283. X509_free(x509);
  51284. /* Should fail when x509 is NULL */
  51285. ExpectIntEQ(wolfSSL_X509_check_email(NULL, goodEmail, 0, 0),
  51286. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51287. #endif /* OPENSSL_EXTRA && WOLFSSL_CERT_GEN */
  51288. return EXPECT_RESULT();
  51289. }
  51290. static int test_wc_PemToDer(void)
  51291. {
  51292. EXPECT_DECLS;
  51293. #if !defined(NO_CERTS) && defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM)
  51294. int ret;
  51295. DerBuffer* pDer = NULL;
  51296. const char* ca_cert = "./certs/server-cert.pem";
  51297. byte* cert_buf = NULL;
  51298. size_t cert_sz = 0;
  51299. int eccKey = 0;
  51300. EncryptedInfo info;
  51301. XMEMSET(&info, 0, sizeof(info));
  51302. ExpectIntEQ(ret = load_file(ca_cert, &cert_buf, &cert_sz), 0);
  51303. ExpectIntEQ(ret = wc_PemToDer(cert_buf, (long int)cert_sz, CERT_TYPE, &pDer, NULL,
  51304. &info, &eccKey), 0);
  51305. wc_FreeDer(&pDer);
  51306. pDer = NULL;
  51307. if (cert_buf != NULL) {
  51308. free(cert_buf);
  51309. cert_buf = NULL;
  51310. }
  51311. #ifdef HAVE_ECC
  51312. {
  51313. const char* ecc_private_key = "./certs/ecc-privOnlyKey.pem";
  51314. byte key_buf[256] = {0};
  51315. /* Test fail of loading a key with cert type */
  51316. ExpectIntEQ(load_file(ecc_private_key, &cert_buf, &cert_sz), 0);
  51317. key_buf[0] = '\n';
  51318. ExpectNotNull(XMEMCPY(key_buf + 1, cert_buf, cert_sz));
  51319. ExpectIntNE((ret = wc_PemToDer(key_buf, (long int)cert_sz + 1, CERT_TYPE,
  51320. &pDer, NULL, &info, &eccKey)), 0);
  51321. #ifdef OPENSSL_EXTRA
  51322. ExpectIntEQ((ret = wc_PemToDer(key_buf, cert_sz + 1, PRIVATEKEY_TYPE,
  51323. &pDer, NULL, &info, &eccKey)), 0);
  51324. #endif
  51325. wc_FreeDer(&pDer);
  51326. if (cert_buf != NULL)
  51327. free(cert_buf);
  51328. }
  51329. #endif
  51330. #endif
  51331. return EXPECT_RESULT();
  51332. }
  51333. static int test_wc_AllocDer(void)
  51334. {
  51335. EXPECT_DECLS;
  51336. #if !defined(NO_CERTS)
  51337. DerBuffer* pDer = NULL;
  51338. word32 testSize = 1024;
  51339. ExpectIntEQ(wc_AllocDer(NULL, testSize, CERT_TYPE, HEAP_HINT),
  51340. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51341. ExpectIntEQ(wc_AllocDer(&pDer, testSize, CERT_TYPE, HEAP_HINT), 0);
  51342. ExpectNotNull(pDer);
  51343. wc_FreeDer(&pDer);
  51344. #endif
  51345. return EXPECT_RESULT();
  51346. }
  51347. static int test_wc_CertPemToDer(void)
  51348. {
  51349. EXPECT_DECLS;
  51350. #if !defined(NO_CERTS) && defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM)
  51351. const char* ca_cert = "./certs/ca-cert.pem";
  51352. byte* cert_buf = NULL;
  51353. size_t cert_sz = 0;
  51354. size_t cert_dersz = 0;
  51355. byte* cert_der = NULL;
  51356. ExpectIntEQ(load_file(ca_cert, &cert_buf, &cert_sz), 0);
  51357. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  51358. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  51359. ExpectIntGE(wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der,
  51360. (int)cert_dersz, CERT_TYPE), 0);
  51361. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, NULL, -1, CERT_TYPE),
  51362. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51363. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, NULL, -1, CERT_TYPE),
  51364. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51365. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, cert_der, -1, CERT_TYPE),
  51366. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51367. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, NULL, (int)cert_dersz,
  51368. CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51369. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, cert_der,
  51370. (int)cert_dersz, CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51371. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, NULL,
  51372. (int)cert_dersz, CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51373. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der, -1,
  51374. CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51375. if (cert_der != NULL)
  51376. free(cert_der);
  51377. if (cert_buf != NULL)
  51378. free(cert_buf);
  51379. #endif
  51380. return EXPECT_RESULT();
  51381. }
  51382. static int test_wc_KeyPemToDer(void)
  51383. {
  51384. EXPECT_DECLS;
  51385. #if defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  51386. int ret = 0;
  51387. const byte cert_buf[] = \
  51388. "-----BEGIN PRIVATE KEY-----\n"
  51389. "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDMG5KgWxP002pA\n"
  51390. "QJIdA4H5N0oM1Wf0LrHcos5RYUlrHDkC2b5p2BUpVRPmgDAFD2+8leim98x0BvcB\n"
  51391. "k48TNzrVynuwyVEY664+iQyzEBO5v27HPRydOddprbLCvRO036XINGIjauy1jHFi\n"
  51392. "HaDVx3bexSwgp9aefUGAszFXi4q1J4GacV7Cr2b/wBqUHqWv4ZXPu6R9/UYngTkD\n"
  51393. "UDJL5gLlLfcLzNyyodKPHPCIAKdWn6mSVdcHk8XVpK4y9lgz4E7YDWA6ohKZgWgG\n"
  51394. "2RDha8CMilFMDgYa0G0SiS9g3PQx0qh3AMXJJsKSVhScFCZufAE0kV6KvjP7jAqP\n"
  51395. "XBiSkRGPAgMBAAECggEAW7hmRyY2jRX2UMJThrM9VIs6fRLnYI0dQ0tsEJj536ay\n"
  51396. "nevQjArc05KWW0Yujg+WRDZPcry3RUqd9Djlmhp/F3Si6dpF1b+PMS3wJYVrf9Sd\n"
  51397. "SO5W7faArU4vnyBNe0HnY1Ta5xSVI65lg1RSIs88RTZwsooJwXYDGf0shq0/21CE\n"
  51398. "V8HOb27DDYNcEnm35lzaONjFnMqQQT2Vs9anRrPiSEXNleEvTgLVXZtGTyCGTz6v\n"
  51399. "x86Y8eSWL9YNHvPE1I+mDPuocfSR7eRNgRu7SK3mn94W5mqd7Ns072YKX/2XN1mO\n"
  51400. "66+ZFHO6v4dK1u7cSjuwrU1EhLHpUsgDz6Bna5InyQKBgQDv5l8RPy8UneKSADaf\n"
  51401. "M5L/5675I/5t4nqVjvbnQje00YveLTAEjlJBNR93Biln3sYgnvNamYDCxyEuUZ/I\n"
  51402. "S/vmBL9PoxfGZow4FcsIBOEbIn3E0SYJgCBNWthquUvGpKsYDnThJuhO+1cVmxAJ\n"
  51403. "BUOjLFnJYHM0a+Vmk9GexT2OBwKBgQDZzkUBOK7Im3eiYytFocUJyhqMH30d49X9\n"
  51404. "ujC7kGw4UWAqVe7YCSvlBa8nzWpRWK2kRpu3M0272RU0V4geyWqT+nr/SvRRPtNP\n"
  51405. "F5dY8l3yR7hjtSejqqjOfBcZT6ETJxI4tiG0+Nl5BlfM5M+0nxnkWpRcHuOR3j79\n"
  51406. "YUFERyN+OQKBgQCjlOKeUAc6d65W/+4/AFvsQ378Q57qLtSHxsR1TKHPmlNVXFqx\n"
  51407. "wJo1/JNIBduWCEHxXHF0BdfW+RGXE/FwEt/hKLuLAhrkHmjelX2sKieU6R/5ZOQa\n"
  51408. "9lMQbDHGFDOncAF6leD85hriQGBRSzrT69MDIOrYdfwYcroqCAGX0cb3YQKBgQC8\n"
  51409. "iIFQylj5SyHmjcMSNjKSA8CxFDzAV8yPIdE3Oo+CvGXqn5HsrRuy1hXE9VmXapR8\n"
  51410. "A6ackSszdHiXY0FvrNe1mfdH7wDHJwPQjdIzazCJHS3uGQxj7sDKY7226ie6pXJv\n"
  51411. "ZrCMr2/IBAaSVGm6ppHKCeIsT4ybYm7R85KEYLPHeQKBgBeJOMBinXQfWN/1jT9b\n"
  51412. "6Ywrutvp2zP8hVxQGSZJ0WG4iewZyFLsPUlbWRXOSYNPElHmdD0ZomdLVm+lSpAA\n"
  51413. "XSH5FJ/IFCwqq7Eft6Gf8NFRV+NjPMUny+PnjHe4oFP8YK/Ek22K3ttNG8Hw69Aw\n"
  51414. "AQue5o6oVfhgLiJzMdo/77gw\n"
  51415. "-----END PRIVATE KEY-----\n";
  51416. const int cert_sz = sizeof(cert_buf);
  51417. const char cert_pw[] = "password";
  51418. int cert_dersz = 0;
  51419. byte* cert_der = NULL;
  51420. /* Bad arg: Cert buffer is NULL */
  51421. ExpectIntEQ(wc_KeyPemToDer(NULL, cert_sz, cert_der, cert_dersz, ""),
  51422. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51423. /* Bad arg: Cert DER buffer non-NULL but size zero (or less) */
  51424. ExpectIntEQ(wc_KeyPemToDer(cert_buf, cert_sz, (byte*)&cert_der, 0, ""),
  51425. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51426. /* Test normal operation */
  51427. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  51428. ExpectNotNull(cert_der = (byte*)malloc((size_t)cert_dersz));
  51429. ExpectIntGE(ret = wc_KeyPemToDer(cert_buf, cert_sz, cert_der, cert_dersz,
  51430. cert_pw), 0);
  51431. ExpectIntLE(ret, cert_sz);
  51432. if (cert_der != NULL) {
  51433. free(cert_der);
  51434. cert_der = NULL;
  51435. }
  51436. /* Test NULL for DER buffer to return needed DER buffer size */
  51437. ExpectIntGT(ret = wc_KeyPemToDer(cert_buf, cert_sz, NULL, 0, ""), 0);
  51438. ExpectIntLE(ret, cert_sz);
  51439. if (EXPECT_SUCCESS())
  51440. cert_dersz = ret;
  51441. ExpectNotNull(cert_der = (byte*)malloc((size_t)cert_dersz));
  51442. ExpectIntGE(ret = wc_KeyPemToDer(cert_buf, cert_sz, cert_der, cert_dersz,
  51443. cert_pw), 0);
  51444. ExpectIntLE(ret, cert_sz);
  51445. if (cert_der != NULL)
  51446. free(cert_der);
  51447. #endif
  51448. return EXPECT_RESULT();
  51449. }
  51450. static int test_wc_PubKeyPemToDer(void)
  51451. {
  51452. EXPECT_DECLS;
  51453. #if defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM) && \
  51454. (defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_PUB_PEM_TO_DER))
  51455. int ret = 0;
  51456. const char* key = "./certs/ecc-client-keyPub.pem";
  51457. byte* cert_buf = NULL;
  51458. size_t cert_sz = 0, cert_dersz = 0;
  51459. byte* cert_der = NULL;
  51460. ExpectIntEQ(wc_PubKeyPemToDer(cert_buf, (int)cert_sz,
  51461. cert_der, (int)cert_dersz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51462. ExpectIntEQ(load_file(key, &cert_buf, &cert_sz), 0);
  51463. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  51464. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  51465. ExpectIntGE(wc_PubKeyPemToDer(cert_buf, (int)cert_sz, cert_der,
  51466. (int)cert_dersz), 0);
  51467. if (cert_der != NULL) {
  51468. free(cert_der);
  51469. cert_der = NULL;
  51470. }
  51471. /* Test NULL for DER buffer to return needed DER buffer size */
  51472. ExpectIntGT(ret = wc_PubKeyPemToDer(cert_buf, (int)cert_sz, NULL, 0), 0);
  51473. ExpectIntLE(ret, cert_sz);
  51474. cert_dersz = (size_t)ret;
  51475. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  51476. ExpectIntGE(wc_PubKeyPemToDer(cert_buf, (int)cert_sz, cert_der,
  51477. (int)cert_dersz), 0);
  51478. if (cert_der != NULL) {
  51479. free(cert_der);
  51480. }
  51481. if (cert_buf != NULL) {
  51482. free(cert_buf);
  51483. }
  51484. #endif
  51485. return EXPECT_RESULT();
  51486. }
  51487. static int test_wc_PemPubKeyToDer(void)
  51488. {
  51489. EXPECT_DECLS;
  51490. #if !defined(NO_FILESYSTEM) && \
  51491. (defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_PUB_PEM_TO_DER))
  51492. const char* key = "./certs/ecc-client-keyPub.pem";
  51493. size_t cert_dersz = 1024;
  51494. byte* cert_der = NULL;
  51495. ExpectIntGE(wc_PemPubKeyToDer(NULL, cert_der, (int)cert_dersz),
  51496. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51497. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  51498. ExpectIntGE(wc_PemPubKeyToDer(key, cert_der, (int)cert_dersz), 0);
  51499. if (cert_der != NULL) {
  51500. free(cert_der);
  51501. }
  51502. #endif
  51503. return EXPECT_RESULT();
  51504. }
  51505. static int test_wc_GetPubKeyDerFromCert(void)
  51506. {
  51507. EXPECT_DECLS;
  51508. #if !defined(NO_RSA) || defined(HAVE_ECC)
  51509. int ret;
  51510. word32 idx = 0;
  51511. byte keyDer[TWOK_BUF]; /* large enough for up to RSA 2048 */
  51512. word32 keyDerSz = (word32)sizeof(keyDer);
  51513. DecodedCert decoded;
  51514. #if !defined(NO_RSA) && defined(WOLFSSL_CERT_REQ) && !defined(NO_FILESYSTEM)
  51515. byte certBuf[6000]; /* for PEM and CSR, client-cert.pem is 5-6kB */
  51516. word32 certBufSz = sizeof(certBuf);
  51517. #endif
  51518. #if ((!defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_1024)) || \
  51519. defined(WOLFSSL_CERT_REQ)) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  51520. XFILE fp = XBADFILE;
  51521. #endif
  51522. #ifndef NO_RSA
  51523. RsaKey rsaKey;
  51524. #if defined(USE_CERT_BUFFERS_2048)
  51525. byte* rsaCertDer = (byte*)client_cert_der_2048;
  51526. word32 rsaCertDerSz = sizeof_client_cert_der_2048;
  51527. #elif defined(USE_CERT_BUFFERS_1024)
  51528. byte* rsaCertDer = (byte*)client_cert_der_1024;
  51529. word32 rsaCertDerSz = sizeof_client_cert_der_1024;
  51530. #else
  51531. unsigned char rsaCertDer[TWOK_BUF];
  51532. word32 rsaCertDerSz;
  51533. #endif
  51534. #endif
  51535. #ifdef HAVE_ECC
  51536. ecc_key eccKey;
  51537. #if defined(USE_CERT_BUFFERS_256)
  51538. byte* eccCert = (byte*)cliecc_cert_der_256;
  51539. word32 eccCertSz = sizeof_cliecc_cert_der_256;
  51540. #else
  51541. unsigned char eccCert[ONEK_BUF];
  51542. word32 eccCertSz;
  51543. XFILE fp2 = XBADFILE;
  51544. #endif
  51545. #endif
  51546. #ifndef NO_RSA
  51547. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  51548. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) != XBADFILE);
  51549. ExpectIntGT(rsaCertDerSz = (word32)XFREAD(rsaCertDer, 1, sizeof(rsaCertDer),
  51550. fp), 0);
  51551. if (fp != XBADFILE) {
  51552. XFCLOSE(fp);
  51553. fp = XBADFILE;
  51554. }
  51555. #endif
  51556. /* good test case - RSA DER cert */
  51557. wc_InitDecodedCert(&decoded, rsaCertDer, rsaCertDerSz, NULL);
  51558. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  51559. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  51560. ExpectIntGT(keyDerSz, 0);
  51561. /* sanity check, verify we can import DER public key */
  51562. ret = wc_InitRsaKey(&rsaKey, HEAP_HINT);
  51563. ExpectIntEQ(ret, 0);
  51564. ExpectIntEQ(wc_RsaPublicKeyDecode(keyDer, &idx, &rsaKey, keyDerSz), 0);
  51565. if (ret == 0) {
  51566. wc_FreeRsaKey(&rsaKey);
  51567. }
  51568. /* test LENGTH_ONLY_E case */
  51569. keyDerSz = 0;
  51570. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, NULL, &keyDerSz),
  51571. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  51572. ExpectIntGT(keyDerSz, 0);
  51573. /* bad args: DecodedCert NULL */
  51574. ExpectIntEQ(wc_GetPubKeyDerFromCert(NULL, keyDer, &keyDerSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51575. /* bad args: output key buff size */
  51576. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51577. /* bad args: zero size output key buffer */
  51578. keyDerSz = 0;
  51579. ExpectIntEQ(ret = wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz),
  51580. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51581. wc_FreeDecodedCert(&decoded);
  51582. /* Certificate Request Tests */
  51583. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_FILESYSTEM)
  51584. {
  51585. XMEMSET(certBuf, 0, sizeof(certBuf));
  51586. ExpectTrue((fp = XFOPEN("./certs/csr.signed.der", "rb")) != XBADFILE);
  51587. ExpectIntGT(certBufSz = (word32)XFREAD(certBuf, 1, certBufSz, fp), 0);
  51588. if (fp != XBADFILE) {
  51589. XFCLOSE(fp);
  51590. }
  51591. wc_InitDecodedCert(&decoded, certBuf, certBufSz, NULL);
  51592. ExpectIntEQ(wc_ParseCert(&decoded, CERTREQ_TYPE, VERIFY, NULL), 0);
  51593. /* good test case - RSA DER certificate request */
  51594. keyDerSz = sizeof(keyDer);
  51595. ExpectIntEQ(ret = wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz),
  51596. 0);
  51597. ExpectIntGT(keyDerSz, 0);
  51598. /* sanity check, verify we can import DER public key */
  51599. ret = wc_InitRsaKey(&rsaKey, HEAP_HINT);
  51600. ExpectIntEQ(ret, 0);
  51601. idx = 0;
  51602. ExpectIntEQ(wc_RsaPublicKeyDecode(keyDer, &idx, &rsaKey, keyDerSz), 0);
  51603. if (ret == 0) {
  51604. wc_FreeRsaKey(&rsaKey);
  51605. }
  51606. wc_FreeDecodedCert(&decoded);
  51607. }
  51608. #endif /* WOLFSSL_CERT_REQ */
  51609. #endif /* NO_RSA */
  51610. #ifdef HAVE_ECC
  51611. #ifndef USE_CERT_BUFFERS_256
  51612. ExpectTrue((fp2 = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  51613. XBADFILE);
  51614. ExpectIntGT(eccCertSz = (word32)XFREAD(eccCert, 1, ONEK_BUF, fp2), 0);
  51615. if (fp2 != XBADFILE) {
  51616. XFCLOSE(fp2);
  51617. }
  51618. #endif
  51619. wc_InitDecodedCert(&decoded, eccCert, eccCertSz, NULL);
  51620. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  51621. /* good test case - ECC */
  51622. XMEMSET(keyDer, 0, sizeof(keyDer));
  51623. keyDerSz = sizeof(keyDer);
  51624. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  51625. ExpectIntGT(keyDerSz, 0);
  51626. /* sanity check, verify we can import DER public key */
  51627. ret = wc_ecc_init(&eccKey);
  51628. ExpectIntEQ(ret, 0);
  51629. idx = 0; /* reset idx to 0, used above in RSA case */
  51630. ExpectIntEQ(wc_EccPublicKeyDecode(keyDer, &idx, &eccKey, keyDerSz), 0);
  51631. if (ret == 0) {
  51632. wc_ecc_free(&eccKey);
  51633. }
  51634. /* test LENGTH_ONLY_E case */
  51635. keyDerSz = 0;
  51636. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, NULL, &keyDerSz),
  51637. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  51638. ExpectIntGT(keyDerSz, 0);
  51639. wc_FreeDecodedCert(&decoded);
  51640. #endif
  51641. #endif /* !NO_RSA || HAVE_ECC */
  51642. return EXPECT_RESULT();
  51643. }
  51644. static int test_wc_CheckCertSigPubKey(void)
  51645. {
  51646. EXPECT_DECLS;
  51647. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  51648. !defined(NO_RSA) && defined(WOLFSSL_PEM_TO_DER) && defined(HAVE_ECC)
  51649. int ret = 0;
  51650. const char* ca_cert = "./certs/ca-cert.pem";
  51651. byte* cert_buf = NULL;
  51652. size_t cert_sz = 0;
  51653. byte* cert_der = NULL;
  51654. word32 cert_dersz = 0;
  51655. byte keyDer[TWOK_BUF]; /* large enough for up to RSA 2048 */
  51656. word32 keyDerSz = (word32)sizeof(keyDer);
  51657. DecodedCert decoded;
  51658. ExpectIntEQ(load_file(ca_cert, &cert_buf, &cert_sz), 0);
  51659. cert_dersz = (word32)cert_sz; /* DER will be smaller than PEM */
  51660. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  51661. ExpectIntGE(ret = wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der,
  51662. (int)cert_dersz, CERT_TYPE), 0);
  51663. wc_InitDecodedCert(&decoded, cert_der, cert_dersz, NULL);
  51664. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  51665. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  51666. ExpectIntGT(keyDerSz, 0);
  51667. /* Good test case. */
  51668. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer,
  51669. keyDerSz, RSAk), 0);
  51670. /* No certificate. */
  51671. ExpectIntEQ(wc_CheckCertSigPubKey(NULL, cert_dersz, NULL, keyDer, keyDerSz,
  51672. ECDSAk), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51673. /* Bad cert size. */
  51674. ExpectIntNE(ret = wc_CheckCertSigPubKey(cert_der, 0, NULL, keyDer, keyDerSz,
  51675. RSAk), 0);
  51676. ExpectTrue(ret == WC_NO_ERR_TRACE(ASN_PARSE_E) || ret == WC_NO_ERR_TRACE(BUFFER_E));
  51677. /* No public key. */
  51678. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, NULL,
  51679. keyDerSz, RSAk), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  51680. /* Bad public key size. */
  51681. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer, 0,
  51682. RSAk), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51683. /* Wrong aglo. */
  51684. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer,
  51685. keyDerSz, ECDSAk), WC_NO_ERR_TRACE(ASN_PARSE_E));
  51686. wc_FreeDecodedCert(&decoded);
  51687. if (cert_der != NULL)
  51688. free(cert_der);
  51689. if (cert_buf != NULL)
  51690. free(cert_buf);
  51691. #endif
  51692. return EXPECT_RESULT();
  51693. }
  51694. static int test_wolfSSL_certs(void)
  51695. {
  51696. EXPECT_DECLS;
  51697. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  51698. !defined(NO_RSA)
  51699. X509* x509ext = NULL;
  51700. X509* x509 = NULL;
  51701. #ifdef OPENSSL_ALL
  51702. WOLFSSL_X509_EXTENSION* ext = NULL;
  51703. ASN1_OBJECT* obj = NULL;
  51704. #endif
  51705. WOLFSSL* ssl = NULL;
  51706. WOLFSSL_CTX* ctx = NULL;
  51707. STACK_OF(ASN1_OBJECT)* sk = NULL;
  51708. ASN1_STRING* asn1_str = NULL;
  51709. AUTHORITY_KEYID* akey = NULL;
  51710. BASIC_CONSTRAINTS* bc = NULL;
  51711. int crit = 0;
  51712. #ifndef NO_WOLFSSL_SERVER
  51713. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  51714. #else
  51715. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  51716. #endif
  51717. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile, SSL_FILETYPE_PEM));
  51718. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  51719. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  51720. #if !defined(NO_CHECK_PRIVATE_KEY)
  51721. ExpectIntEQ(SSL_CTX_check_private_key(ctx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51722. #endif
  51723. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  51724. #if !defined(NO_CHECK_PRIVATE_KEY)
  51725. ExpectIntEQ(SSL_CTX_check_private_key(ctx), SSL_SUCCESS);
  51726. #endif
  51727. ExpectNotNull(ssl = SSL_new(ctx));
  51728. /* Invalid parameters. */
  51729. ExpectIntEQ(SSL_use_certificate_file(NULL, NULL, WOLFSSL_FILETYPE_PEM),
  51730. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51731. ExpectIntEQ(SSL_use_certificate_file(ssl, NULL, WOLFSSL_FILETYPE_PEM),
  51732. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51733. ExpectIntEQ(SSL_use_certificate_file(NULL, "./certs/server-cert.pem",
  51734. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51735. #if !defined(NO_CHECK_PRIVATE_KEY)
  51736. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51737. #endif
  51738. #ifdef HAVE_PK_CALLBACKS
  51739. ExpectIntEQ((int)SSL_set_tlsext_debug_arg(ssl, NULL), WOLFSSL_SUCCESS);
  51740. #endif /* HAVE_PK_CALLBACKS */
  51741. /* Invalid parameters. */
  51742. ExpectNotNull(x509 = wolfSSL_X509_new());
  51743. ExpectIntEQ(SSL_use_certificate(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51744. ExpectIntEQ(SSL_use_certificate(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51745. ExpectIntEQ(SSL_use_certificate(NULL, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51746. /* No data in certificate. */
  51747. ExpectIntEQ(SSL_use_certificate(ssl, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51748. wolfSSL_X509_free(x509);
  51749. x509 = NULL;
  51750. /* create and use x509 */
  51751. #ifdef OPENSSL_ALL
  51752. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  51753. WOLFSSL_FILETYPE_PEM));
  51754. #endif
  51755. ExpectNotNull(x509ext = wolfSSL_X509_load_certificate_file(cliCertFileExt,
  51756. WOLFSSL_FILETYPE_PEM));
  51757. ExpectIntEQ(SSL_use_certificate(ssl, x509ext), WOLFSSL_SUCCESS);
  51758. #if !defined(NO_CHECK_PRIVATE_KEY)
  51759. /* with loading in a new cert the check on private key should now fail */
  51760. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51761. #endif
  51762. #if defined(USE_CERT_BUFFERS_2048)
  51763. /* Invalid parameters. */
  51764. ExpectIntEQ(SSL_use_certificate_ASN1(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51765. ExpectIntEQ(SSL_use_certificate_ASN1(ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51766. ExpectIntEQ(SSL_use_certificate_ASN1(NULL,
  51767. (unsigned char*)server_cert_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51768. /* No data. */
  51769. ExpectIntEQ(SSL_use_certificate_ASN1(ssl,
  51770. (unsigned char*)server_cert_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51771. ExpectIntEQ(SSL_use_certificate_ASN1(ssl,
  51772. (unsigned char*)server_cert_der_2048,
  51773. sizeof_server_cert_der_2048), WOLFSSL_SUCCESS);
  51774. #endif
  51775. #if !defined(NO_SHA) && !defined(NO_SHA256) && !defined(NO_PWDBASED)
  51776. /************* Get Digest of Certificate ******************/
  51777. {
  51778. byte digest[64]; /* max digest size */
  51779. word32 digestSz;
  51780. XMEMSET(digest, 0, sizeof(digest));
  51781. ExpectIntEQ(X509_digest(x509ext, wolfSSL_EVP_sha1(), digest, &digestSz),
  51782. WOLFSSL_SUCCESS);
  51783. ExpectIntEQ(X509_digest(x509ext, wolfSSL_EVP_sha256(), digest, &digestSz),
  51784. WOLFSSL_SUCCESS);
  51785. ExpectIntEQ(X509_digest(NULL, wolfSSL_EVP_sha1(), digest, &digestSz),
  51786. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51787. }
  51788. #endif /* !NO_SHA && !NO_SHA256 && !NO_PWDBASED */
  51789. /* test and checkout X509 extensions */
  51790. ExpectNotNull(bc = (BASIC_CONSTRAINTS*)X509_get_ext_d2i(x509ext,
  51791. NID_basic_constraints, &crit, NULL));
  51792. ExpectIntEQ(crit, 0);
  51793. #ifdef OPENSSL_ALL
  51794. ExpectNotNull(ext = X509V3_EXT_i2d(NID_basic_constraints, crit, bc));
  51795. X509_EXTENSION_free(ext);
  51796. ext = NULL;
  51797. ExpectNotNull(ext = X509_EXTENSION_new());
  51798. X509_EXTENSION_set_critical(ext, 1);
  51799. ExpectNotNull(obj = OBJ_nid2obj(NID_basic_constraints));
  51800. ExpectIntEQ(X509_EXTENSION_set_object(ext, obj), SSL_SUCCESS);
  51801. ASN1_OBJECT_free(obj);
  51802. obj = NULL;
  51803. X509_EXTENSION_free(ext);
  51804. ext = NULL;
  51805. ExpectNotNull(ext = X509_EXTENSION_new());
  51806. X509_EXTENSION_set_critical(ext, 0);
  51807. ExpectIntEQ(X509_EXTENSION_set_data(ext, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51808. asn1_str = (ASN1_STRING*)X509_get_ext_d2i(x509ext, NID_key_usage, &crit,
  51809. NULL);
  51810. ExpectIntEQ(X509_EXTENSION_set_data(ext, asn1_str), SSL_SUCCESS);
  51811. ASN1_STRING_free(asn1_str); /* X509_EXTENSION_set_data has made a copy
  51812. * and X509_get_ext_d2i has created new */
  51813. asn1_str = NULL;
  51814. X509_EXTENSION_free(ext);
  51815. ext = NULL;
  51816. #endif
  51817. BASIC_CONSTRAINTS_free(bc);
  51818. bc = NULL;
  51819. ExpectNotNull(asn1_str = (ASN1_STRING*)X509_get_ext_d2i(x509ext,
  51820. NID_key_usage, &crit, NULL));
  51821. ExpectIntEQ(crit, 1);
  51822. ExpectIntEQ(asn1_str->type, NID_key_usage);
  51823. #ifdef OPENSSL_ALL
  51824. ExpectNotNull(ext = X509V3_EXT_i2d(NID_key_usage, crit, asn1_str));
  51825. X509_EXTENSION_free(ext);
  51826. ext = NULL;
  51827. #endif
  51828. ASN1_STRING_free(asn1_str);
  51829. asn1_str = NULL;
  51830. #ifdef OPENSSL_ALL
  51831. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  51832. NID_ext_key_usage, &crit, NULL));
  51833. ExpectNotNull(ext = X509V3_EXT_i2d(NID_ext_key_usage, crit, sk));
  51834. X509_EXTENSION_free(ext);
  51835. ext = NULL;
  51836. EXTENDED_KEY_USAGE_free(sk);
  51837. sk = NULL;
  51838. #else
  51839. sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext, NID_ext_key_usage,
  51840. &crit, NULL);
  51841. ExpectNull(sk);
  51842. #endif
  51843. ExpectNotNull(akey = (AUTHORITY_KEYID*)X509_get_ext_d2i(x509ext,
  51844. NID_authority_key_identifier, &crit, NULL));
  51845. #ifdef OPENSSL_ALL
  51846. ExpectNotNull(ext = X509V3_EXT_i2d(NID_authority_key_identifier, crit,
  51847. akey));
  51848. X509_EXTENSION_free(ext);
  51849. ext = NULL;
  51850. #endif
  51851. wolfSSL_AUTHORITY_KEYID_free(akey);
  51852. akey = NULL;
  51853. /* NID not yet supported */
  51854. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51855. NID_private_key_usage_period, &crit, NULL));
  51856. ExpectIntEQ(crit, -1);
  51857. sk_ASN1_OBJECT_free(sk);
  51858. sk = NULL;
  51859. ExpectNotNull(sk = (STACK_OF(GENERAL_NAME)*)X509_get_ext_d2i(x509ext,
  51860. NID_subject_alt_name, &crit, NULL));
  51861. {
  51862. int i;
  51863. for (i = 0; i < sk_GENERAL_NAME_num(sk); i++) {
  51864. GENERAL_NAME* gen = sk_GENERAL_NAME_value(sk, i);
  51865. ExpectIntEQ(gen->type, GEN_DNS);
  51866. ExpectIntEQ(gen->d.dNSName->type, V_ASN1_IA5STRING);
  51867. }
  51868. }
  51869. sk_GENERAL_NAME_free(sk);
  51870. sk = NULL;
  51871. /* NID not yet supported */
  51872. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51873. NID_issuer_alt_name, &crit, NULL));
  51874. ExpectIntEQ(crit, -1);
  51875. sk_ASN1_OBJECT_free(sk);
  51876. sk = NULL;
  51877. /* NID not yet supported */
  51878. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51879. NID_info_access, &crit, NULL));
  51880. sk_ASN1_OBJECT_free(sk);
  51881. sk = NULL;
  51882. /* NID not yet supported */
  51883. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51884. NID_sinfo_access, &crit, NULL));
  51885. ExpectIntEQ(crit, -1);
  51886. sk_ASN1_OBJECT_free(sk);
  51887. sk = NULL;
  51888. /* NID not yet supported */
  51889. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51890. NID_name_constraints, &crit, NULL));
  51891. ExpectIntEQ(crit, -1);
  51892. sk_ASN1_OBJECT_free(sk);
  51893. sk = NULL;
  51894. /* no cert policy set */
  51895. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51896. NID_certificate_policies, &crit, NULL));
  51897. sk_ASN1_OBJECT_free(sk);
  51898. sk = NULL;
  51899. /* NID not yet supported */
  51900. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51901. NID_policy_mappings, &crit, NULL));
  51902. ExpectIntEQ(crit, -1);
  51903. sk_ASN1_OBJECT_free(sk);
  51904. sk = NULL;
  51905. /* NID not yet supported */
  51906. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51907. NID_policy_constraints, &crit, NULL));
  51908. ExpectIntEQ(crit, -1);
  51909. sk_ASN1_OBJECT_free(sk);
  51910. sk = NULL;
  51911. /* NID not yet supported */
  51912. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51913. NID_inhibit_any_policy, &crit, NULL));
  51914. ExpectIntEQ(crit, -1);
  51915. sk_ASN1_OBJECT_free(sk);
  51916. sk = NULL;
  51917. /* NID not yet supported */
  51918. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51919. NID_tlsfeature, &crit, NULL));
  51920. ExpectIntEQ(crit, -1);
  51921. sk_ASN1_OBJECT_free(sk);
  51922. sk = NULL;
  51923. /* test invalid cases */
  51924. crit = 0;
  51925. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext, -1, &crit,
  51926. NULL));
  51927. ExpectIntEQ(crit, -1);
  51928. /* NULL passed for criticality. */
  51929. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(NULL,
  51930. NID_tlsfeature, NULL, NULL));
  51931. ExpectIntEQ(SSL_get_hit(ssl), 0);
  51932. #ifdef OPENSSL_ALL
  51933. X509_free(x509);
  51934. #endif
  51935. X509_free(x509ext);
  51936. SSL_free(ssl);
  51937. SSL_CTX_free(ctx);
  51938. #endif /* OPENSSL_EXTRA && !NO_CERTS */
  51939. return EXPECT_RESULT();
  51940. }
  51941. static int test_wolfSSL_X509_check_private_key(void)
  51942. {
  51943. EXPECT_DECLS;
  51944. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  51945. defined(USE_CERT_BUFFERS_2048) && !defined(NO_CHECK_PRIVATE_KEY)
  51946. X509* x509 = NULL;
  51947. EVP_PKEY* pkey = NULL;
  51948. const byte* key;
  51949. /* Check with correct key */
  51950. ExpectNotNull((x509 = X509_load_certificate_file(cliCertFile,
  51951. SSL_FILETYPE_PEM)));
  51952. key = client_key_der_2048;
  51953. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &key,
  51954. (long)sizeof_client_key_der_2048));
  51955. ExpectIntEQ(X509_check_private_key(x509, pkey), 1);
  51956. EVP_PKEY_free(pkey);
  51957. pkey = NULL;
  51958. /* Check with wrong key */
  51959. key = server_key_der_2048;
  51960. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &key,
  51961. (long)sizeof_server_key_der_2048));
  51962. ExpectIntEQ(X509_check_private_key(x509, pkey), 0);
  51963. /* test for incorrect parameter */
  51964. ExpectIntEQ(X509_check_private_key(NULL, pkey), 0);
  51965. ExpectIntEQ(X509_check_private_key(x509, NULL), 0);
  51966. ExpectIntEQ(X509_check_private_key(NULL, NULL), 0);
  51967. EVP_PKEY_free(pkey);
  51968. X509_free(x509);
  51969. #endif
  51970. return EXPECT_RESULT();
  51971. }
  51972. static int test_wolfSSL_private_keys(void)
  51973. {
  51974. EXPECT_DECLS;
  51975. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  51976. !defined(NO_FILESYSTEM)
  51977. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  51978. WOLFSSL* ssl = NULL;
  51979. WOLFSSL_CTX* ctx = NULL;
  51980. EVP_PKEY* pkey = NULL;
  51981. OpenSSL_add_all_digests();
  51982. OpenSSL_add_all_algorithms();
  51983. #ifndef NO_RSA
  51984. #ifndef NO_WOLFSSL_SERVER
  51985. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  51986. #else
  51987. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  51988. #endif
  51989. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  51990. WOLFSSL_FILETYPE_PEM));
  51991. /* Have to load a cert before you can check the private key against that
  51992. * certificates public key! */
  51993. #if !defined(NO_CHECK_PRIVATE_KEY)
  51994. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51995. #endif
  51996. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  51997. WOLFSSL_FILETYPE_PEM));
  51998. #if !defined(NO_CHECK_PRIVATE_KEY)
  51999. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  52000. #endif
  52001. ExpectNotNull(ssl = SSL_new(ctx));
  52002. #if !defined(NO_CHECK_PRIVATE_KEY)
  52003. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52004. #endif
  52005. /* Invalid parameters. */
  52006. ExpectIntEQ(SSL_use_PrivateKey_file(NULL, NULL, WOLFSSL_FILETYPE_PEM),
  52007. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52008. ExpectIntEQ(SSL_use_PrivateKey_file(NULL, svrKeyFile, WOLFSSL_FILETYPE_PEM),
  52009. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52010. ExpectIntEQ(SSL_use_PrivateKey_file(ssl, NULL, WOLFSSL_FILETYPE_PEM),
  52011. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52012. #ifdef USE_CERT_BUFFERS_2048
  52013. {
  52014. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  52015. unsigned char buf[FOURK_BUF];
  52016. word32 bufSz;
  52017. /* Invalid parameters. */
  52018. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52019. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52020. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(NULL,
  52021. (unsigned char*)client_key_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52022. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52023. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52024. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, NULL, (unsigned char*)server_key, 0),
  52025. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52026. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52027. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52028. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, NULL, (unsigned char*)server_key,
  52029. 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52030. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(ssl,
  52031. (unsigned char*)client_key_der_2048,
  52032. sizeof_client_key_der_2048), WOLFSSL_SUCCESS);
  52033. #if !defined(NO_CHECK_PRIVATE_KEY)
  52034. /* Should mismatch now that a different private key loaded */
  52035. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52036. #endif
  52037. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, ssl,
  52038. (unsigned char*)server_key,
  52039. sizeof_server_key_der_2048), WOLFSSL_SUCCESS);
  52040. #if !defined(NO_CHECK_PRIVATE_KEY)
  52041. /* After loading back in DER format of original key, should match */
  52042. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52043. #endif
  52044. /* test loading private key to the WOLFSSL_CTX */
  52045. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx,
  52046. (unsigned char*)client_key_der_2048,
  52047. sizeof_client_key_der_2048), WOLFSSL_SUCCESS);
  52048. #if !defined(NO_CHECK_PRIVATE_KEY)
  52049. /* Should mismatch now that a different private key loaded */
  52050. ExpectIntNE(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  52051. #endif
  52052. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx,
  52053. (unsigned char*)server_key,
  52054. sizeof_server_key_der_2048), WOLFSSL_SUCCESS);
  52055. #if !defined(NO_CHECK_PRIVATE_KEY)
  52056. /* After loading back in DER format of original key, should match */
  52057. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  52058. #endif
  52059. /* Invalid parameters. */
  52060. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  52061. ExpectIntEQ(SSL_use_PrivateKey(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52062. ExpectIntEQ(SSL_use_PrivateKey(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52063. ExpectIntEQ(SSL_use_PrivateKey(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52064. /* pkey is empty - no key data to use. */
  52065. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WC_NO_ERR_TRACE(ASN_PARSE_E));
  52066. wolfSSL_EVP_PKEY_free(pkey);
  52067. pkey = NULL;
  52068. /* set PKEY and test again */
  52069. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey,
  52070. &server_key, (long)sizeof_server_key_der_2048));
  52071. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WOLFSSL_SUCCESS);
  52072. /* reuse PKEY structure and test
  52073. * this should be checked with a memory management sanity checker */
  52074. ExpectFalse(server_key == (const unsigned char*)server_key_der_2048);
  52075. server_key = (const unsigned char*)server_key_der_2048;
  52076. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey,
  52077. &server_key, (long)sizeof_server_key_der_2048));
  52078. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WOLFSSL_SUCCESS);
  52079. /* check striping PKCS8 header with wolfSSL_d2i_PrivateKey */
  52080. bufSz = FOURK_BUF;
  52081. ExpectIntGT((bufSz = (word32)wc_CreatePKCS8Key(buf, &bufSz,
  52082. (byte*)server_key_der_2048, sizeof_server_key_der_2048,
  52083. RSAk, NULL, 0)), 0);
  52084. server_key = (const unsigned char*)buf;
  52085. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key,
  52086. (long)bufSz));
  52087. }
  52088. #endif
  52089. EVP_PKEY_free(pkey);
  52090. pkey = NULL;
  52091. SSL_free(ssl); /* frees x509 also since loaded into ssl */
  52092. ssl = NULL;
  52093. SSL_CTX_free(ctx);
  52094. ctx = NULL;
  52095. #endif /* end of RSA private key match tests */
  52096. #ifdef HAVE_ECC
  52097. #ifndef NO_WOLFSSL_SERVER
  52098. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  52099. #else
  52100. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  52101. #endif
  52102. ExpectTrue(SSL_CTX_use_certificate_file(ctx, eccCertFile,
  52103. WOLFSSL_FILETYPE_PEM));
  52104. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  52105. WOLFSSL_FILETYPE_PEM));
  52106. ExpectNotNull(ssl = SSL_new(ctx));
  52107. #if !defined(NO_CHECK_PRIVATE_KEY)
  52108. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52109. #endif
  52110. SSL_free(ssl);
  52111. ssl = NULL;
  52112. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEccKeyFile,
  52113. WOLFSSL_FILETYPE_PEM));
  52114. ExpectNotNull(ssl = SSL_new(ctx));
  52115. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  52116. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52117. #endif
  52118. SSL_free(ssl);
  52119. ssl = NULL;
  52120. SSL_CTX_free(ctx);
  52121. ctx = NULL;
  52122. #endif /* end of ECC private key match tests */
  52123. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  52124. #ifndef NO_WOLFSSL_SERVER
  52125. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  52126. #else
  52127. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  52128. #endif
  52129. ExpectTrue(SSL_CTX_use_certificate_file(ctx, edCertFile,
  52130. WOLFSSL_FILETYPE_PEM));
  52131. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, edKeyFile,
  52132. WOLFSSL_FILETYPE_PEM));
  52133. ExpectNotNull(ssl = SSL_new(ctx));
  52134. #if !defined(NO_CHECK_PRIVATE_KEY)
  52135. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52136. #endif
  52137. SSL_free(ssl);
  52138. ssl = NULL;
  52139. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEdKeyFile,
  52140. WOLFSSL_FILETYPE_PEM));
  52141. ExpectNotNull(ssl = SSL_new(ctx));
  52142. #if !defined(NO_CHECK_PRIVATE_KEY)
  52143. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52144. #endif
  52145. SSL_free(ssl);
  52146. ssl = NULL;
  52147. SSL_CTX_free(ctx);
  52148. ctx = NULL;
  52149. #endif /* end of Ed25519 private key match tests */
  52150. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  52151. #ifndef NO_WOLFSSL_SERVER
  52152. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  52153. #else
  52154. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  52155. #endif
  52156. ExpectTrue(SSL_CTX_use_certificate_file(ctx, ed448CertFile,
  52157. WOLFSSL_FILETYPE_PEM));
  52158. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, ed448KeyFile,
  52159. WOLFSSL_FILETYPE_PEM));
  52160. ExpectNotNull(ssl = SSL_new(ctx));
  52161. #if !defined(NO_CHECK_PRIVATE_KEY)
  52162. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52163. #endif
  52164. SSL_free(ssl);
  52165. ssl = NULL;
  52166. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEd448KeyFile,
  52167. WOLFSSL_FILETYPE_PEM));
  52168. ExpectNotNull(ssl = SSL_new(ctx));
  52169. #if !defined(NO_CHECK_PRIVATE_KEY)
  52170. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52171. #endif
  52172. SSL_free(ssl);
  52173. ssl = NULL;
  52174. SSL_CTX_free(ctx);
  52175. ctx = NULL;
  52176. #endif /* end of Ed448 private key match tests */
  52177. EVP_cleanup();
  52178. /* test existence of no-op macros in wolfssl/openssl/ssl.h */
  52179. CONF_modules_free();
  52180. ENGINE_cleanup();
  52181. CONF_modules_unload();
  52182. (void)ssl;
  52183. (void)ctx;
  52184. (void)pkey;
  52185. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  52186. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  52187. return EXPECT_RESULT();
  52188. }
  52189. static int test_wolfSSL_PEM_def_callback(void)
  52190. {
  52191. EXPECT_DECLS;
  52192. #ifdef OPENSSL_EXTRA
  52193. char buf[10];
  52194. const char* defpwd = "DEF PWD";
  52195. int defpwdLen = (int)XSTRLEN(defpwd);
  52196. int smallLen = 1;
  52197. /* Bad parameters. */
  52198. ExpectIntEQ(wolfSSL_PEM_def_callback(NULL, sizeof(buf), 0, NULL), 0);
  52199. ExpectIntEQ(wolfSSL_PEM_def_callback(NULL, sizeof(buf), 0, (void*)defpwd),
  52200. 0);
  52201. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, sizeof(buf), 0, NULL), 0);
  52202. XMEMSET(buf, 0, sizeof(buf));
  52203. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, sizeof(buf), 0, (void*)defpwd),
  52204. defpwdLen);
  52205. ExpectIntEQ(XMEMCMP(buf, defpwd, defpwdLen), 0);
  52206. ExpectIntEQ(buf[defpwdLen], 0);
  52207. /* Size of buffer is smaller than default password. */
  52208. XMEMSET(buf, 0, sizeof(buf));
  52209. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, smallLen, 0, (void*)defpwd),
  52210. smallLen);
  52211. ExpectIntEQ(XMEMCMP(buf, defpwd, smallLen), 0);
  52212. ExpectIntEQ(buf[smallLen], 0);
  52213. #endif /* OPENSSL_EXTRA */
  52214. return EXPECT_RESULT();
  52215. }
  52216. static int test_wolfSSL_PEM_read_PrivateKey(void)
  52217. {
  52218. EXPECT_DECLS;
  52219. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || \
  52220. !defined(NO_DSA) || defined(HAVE_ECC) || !defined(NO_DH))
  52221. XFILE file = XBADFILE;
  52222. #if !defined(NO_RSA)
  52223. const char* fname_rsa = "./certs/server-key.pem";
  52224. RSA* rsa = NULL;
  52225. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  52226. unsigned char* sig = NULL;
  52227. size_t sigLen = 0;
  52228. const unsigned char tbs[] = {0, 1, 2, 3, 4, 5, 6, 7};
  52229. size_t tbsLen = sizeof(tbs);
  52230. #endif
  52231. #if !defined(NO_DSA)
  52232. const char* fname_dsa = "./certs/dsa2048.pem";
  52233. #endif
  52234. #if defined(HAVE_ECC)
  52235. const char* fname_ec = "./certs/ecc-key.pem";
  52236. #endif
  52237. #if !defined(NO_DH)
  52238. const char* fname_dh = "./certs/dh-priv-2048.pem";
  52239. #endif
  52240. EVP_PKEY* pkey = NULL;
  52241. /* Check error case. */
  52242. ExpectNull(pkey = PEM_read_PrivateKey(NULL, NULL, NULL, NULL));
  52243. /* not a PEM key. */
  52244. ExpectTrue((file = XFOPEN("./certs/ecc-key.der", "rb")) != XBADFILE);
  52245. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  52246. if (file != XBADFILE)
  52247. XFCLOSE(file);
  52248. file = XBADFILE;
  52249. #ifndef NO_RSA
  52250. /* Read in an RSA key. */
  52251. ExpectTrue((file = XFOPEN(fname_rsa, "rb")) != XBADFILE);
  52252. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  52253. if (file != XBADFILE)
  52254. XFCLOSE(file);
  52255. file = XBADFILE;
  52256. /* Make sure the key is usable by signing some data with it. */
  52257. ExpectNotNull(rsa = EVP_PKEY_get0_RSA(pkey));
  52258. ExpectIntGT((sigLen = RSA_size(rsa)), 0);
  52259. ExpectNotNull(sig = (unsigned char*)XMALLOC(sigLen, HEAP_HINT,
  52260. DYNAMIC_TYPE_TMP_BUFFER));
  52261. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  52262. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  52263. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &sigLen, tbs, tbsLen),
  52264. WOLFSSL_SUCCESS);
  52265. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52266. EVP_PKEY_CTX_free(ctx);
  52267. EVP_PKEY_free(pkey);
  52268. pkey = NULL;
  52269. #endif
  52270. #ifndef NO_DSA
  52271. /* Read in a DSA key. */
  52272. ExpectTrue((file = XFOPEN(fname_dsa, "rb")) != XBADFILE);
  52273. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH)
  52274. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  52275. EVP_PKEY_free(pkey);
  52276. pkey = NULL;
  52277. #else
  52278. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  52279. #endif
  52280. if (file != XBADFILE)
  52281. XFCLOSE(file);
  52282. file = XBADFILE;
  52283. #endif
  52284. #ifdef HAVE_ECC
  52285. /* Read in an EC key. */
  52286. ExpectTrue((file = XFOPEN(fname_ec, "rb")) != XBADFILE);
  52287. ExpectNotNull(pkey = EVP_PKEY_new());
  52288. ExpectPtrEq(PEM_read_PrivateKey(file, &pkey, NULL, NULL), pkey);
  52289. if (file != XBADFILE)
  52290. XFCLOSE(file);
  52291. file = XBADFILE;
  52292. EVP_PKEY_free(pkey);
  52293. pkey = NULL;
  52294. #endif
  52295. #ifndef NO_DH
  52296. /* Read in a DH key. */
  52297. ExpectTrue((file = XFOPEN(fname_dh, "rb")) != XBADFILE);
  52298. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  52299. defined(WOLFSSL_OPENSSH)) && (!defined(HAVE_FIPS) || \
  52300. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  52301. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  52302. EVP_PKEY_free(pkey);
  52303. pkey = NULL;
  52304. #else
  52305. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  52306. #endif
  52307. if (file != XBADFILE)
  52308. XFCLOSE(file);
  52309. file = XBADFILE;
  52310. #endif
  52311. #endif
  52312. return EXPECT_RESULT();
  52313. }
  52314. static int test_wolfSSL_PEM_read_PUBKEY(void)
  52315. {
  52316. EXPECT_DECLS;
  52317. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) \
  52318. && !defined(NO_FILESYSTEM)
  52319. XFILE file = XBADFILE;
  52320. const char* fname = "./certs/client-keyPub.pem";
  52321. EVP_PKEY* pkey = NULL;
  52322. /* Check error case. */
  52323. ExpectNull(pkey = PEM_read_PUBKEY(NULL, NULL, NULL, NULL));
  52324. /* Read in an RSA key. */
  52325. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  52326. ExpectNotNull(pkey = PEM_read_PUBKEY(file, NULL, NULL, NULL));
  52327. EVP_PKEY_free(pkey);
  52328. pkey = NULL;
  52329. if (file != XBADFILE)
  52330. XFCLOSE(file);
  52331. file = XBADFILE;
  52332. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  52333. ExpectNotNull(pkey = EVP_PKEY_new());
  52334. ExpectPtrEq(PEM_read_PUBKEY(file, &pkey, NULL, NULL), pkey);
  52335. EVP_PKEY_free(pkey);
  52336. if (file != XBADFILE)
  52337. XFCLOSE(file);
  52338. #endif
  52339. return EXPECT_RESULT();
  52340. }
  52341. /* test loading RSA key using BIO */
  52342. static int test_wolfSSL_PEM_PrivateKey_rsa(void)
  52343. {
  52344. EXPECT_DECLS;
  52345. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  52346. defined(USE_CERT_BUFFERS_2048) && !defined(NO_FILESYSTEM) && \
  52347. !defined(NO_BIO)
  52348. BIO* bio = NULL;
  52349. XFILE file = XBADFILE;
  52350. const char* fname = "./certs/server-key.pem";
  52351. const char* fname_rsa_p8 = "./certs/server-keyPkcs8.pem";
  52352. EVP_PKEY* pkey = NULL;
  52353. size_t sz = 0;
  52354. byte* buf = NULL;
  52355. EVP_PKEY* pkey2 = NULL;
  52356. EVP_PKEY* pkey3 = NULL;
  52357. RSA* rsa_key = NULL;
  52358. #if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)
  52359. unsigned char extra[10];
  52360. int i;
  52361. BIO* pub_bio = NULL;
  52362. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  52363. #endif
  52364. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  52365. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  52366. ExpectIntGT(sz = XFTELL(file), 0);
  52367. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  52368. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  52369. if (buf != NULL) {
  52370. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  52371. }
  52372. if (file != XBADFILE) {
  52373. XFCLOSE(file);
  52374. file = XBADFILE;
  52375. }
  52376. /* Test using BIO new mem and loading PEM private key */
  52377. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  52378. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  52379. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  52380. buf = NULL;
  52381. BIO_free(bio);
  52382. bio = NULL;
  52383. /* New empty EVP_PKEY */
  52384. ExpectNotNull(pkey2 = EVP_PKEY_new());
  52385. if (pkey2 != NULL) {
  52386. pkey2->type = EVP_PKEY_RSA;
  52387. }
  52388. /* Test parameter copy */
  52389. ExpectIntEQ(EVP_PKEY_copy_parameters(pkey2, pkey), 0);
  52390. EVP_PKEY_free(pkey2);
  52391. EVP_PKEY_free(pkey);
  52392. pkey = NULL;
  52393. /* Qt unit test case : rsa pkcs8 key */
  52394. ExpectTrue((file = XFOPEN(fname_rsa_p8, "rb")) != XBADFILE);
  52395. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  52396. ExpectIntGT(sz = XFTELL(file), 0);
  52397. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  52398. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  52399. if (buf) {
  52400. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  52401. }
  52402. if (file != XBADFILE) {
  52403. XFCLOSE(file);
  52404. file = XBADFILE;
  52405. }
  52406. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  52407. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  52408. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  52409. buf = NULL;
  52410. BIO_free(bio);
  52411. bio = NULL;
  52412. ExpectNotNull(pkey3 = EVP_PKEY_new());
  52413. ExpectNotNull(rsa_key = EVP_PKEY_get1_RSA(pkey));
  52414. ExpectIntEQ(EVP_PKEY_set1_RSA(pkey3, rsa_key), WOLFSSL_SUCCESS);
  52415. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  52416. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  52417. #else
  52418. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  52419. #endif
  52420. RSA_free(rsa_key);
  52421. EVP_PKEY_free(pkey3);
  52422. EVP_PKEY_free(pkey);
  52423. pkey = NULL;
  52424. pkey2 = NULL;
  52425. #if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)
  52426. #define BIO_PEM_TEST_CHAR 'a'
  52427. XMEMSET(extra, BIO_PEM_TEST_CHAR, sizeof(extra));
  52428. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52429. ExpectIntEQ(BIO_set_write_buf_size(bio, 4096), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52430. ExpectNotNull(pub_bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52431. ExpectIntEQ(BIO_set_write_buf_size(pub_bio, 4096), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52432. ExpectNull(d2i_PrivateKey(EVP_PKEY_EC, &pkey, &server_key,
  52433. (long)sizeof_server_key_der_2048));
  52434. ExpectNull(pkey);
  52435. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key,
  52436. (long)sizeof_server_key_der_2048));
  52437. ExpectIntEQ(PEM_write_bio_PrivateKey(NULL, pkey, NULL, NULL, 0, NULL, NULL),
  52438. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52439. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, NULL, NULL, NULL, 0, NULL, NULL),
  52440. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52441. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  52442. WOLFSSL_SUCCESS);
  52443. ExpectIntGT(BIO_pending(bio), 0);
  52444. ExpectIntEQ(BIO_pending(bio), 1679);
  52445. /* Check if the pubkey API writes only the public key */
  52446. #ifdef WOLFSSL_KEY_GEN
  52447. ExpectIntEQ(PEM_write_bio_PUBKEY(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52448. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52449. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), WOLFSSL_SUCCESS);
  52450. ExpectIntGT(BIO_pending(pub_bio), 0);
  52451. /* Previously both the private key and the pubkey calls would write
  52452. * out the private key and the PEM header was the only difference.
  52453. * The public PEM should be significantly shorter than the
  52454. * private key versison. */
  52455. ExpectIntEQ(BIO_pending(pub_bio), 451);
  52456. #else
  52457. /* Not supported. */
  52458. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), 0);
  52459. #endif
  52460. /* test creating new EVP_PKEY with good args */
  52461. ExpectNotNull((pkey2 = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  52462. if (pkey && pkey->pkey.ptr && pkey2 && pkey2->pkey.ptr) {
  52463. ExpectIntEQ((int)XMEMCMP(pkey->pkey.ptr, pkey2->pkey.ptr,
  52464. pkey->pkey_sz), 0);
  52465. }
  52466. /* test of reuse of EVP_PKEY */
  52467. ExpectNull(PEM_read_bio_PrivateKey(bio, &pkey, NULL, NULL));
  52468. ExpectIntEQ(BIO_pending(bio), 0);
  52469. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  52470. SSL_SUCCESS);
  52471. /* add 10 extra bytes after PEM */
  52472. ExpectIntEQ(BIO_write(bio, extra, 10), 10);
  52473. ExpectNotNull(PEM_read_bio_PrivateKey(bio, &pkey, NULL, NULL));
  52474. ExpectNotNull(pkey);
  52475. if (pkey && pkey->pkey.ptr && pkey2 && pkey2->pkey.ptr) {
  52476. ExpectIntEQ((int)XMEMCMP(pkey->pkey.ptr, pkey2->pkey.ptr,
  52477. pkey->pkey_sz), 0);
  52478. }
  52479. /* check 10 extra bytes still there */
  52480. ExpectIntEQ(BIO_pending(bio), 10);
  52481. ExpectIntEQ(BIO_read(bio, extra, 10), 10);
  52482. for (i = 0; i < 10; i++) {
  52483. ExpectIntEQ(extra[i], BIO_PEM_TEST_CHAR);
  52484. }
  52485. BIO_free(pub_bio);
  52486. BIO_free(bio);
  52487. bio = NULL;
  52488. EVP_PKEY_free(pkey);
  52489. pkey = NULL;
  52490. EVP_PKEY_free(pkey2);
  52491. #endif /* WOLFSSL_KEY_GEN || WOLFSSL_CERT_GEN */
  52492. #endif /* OPENSSL_EXTRA && !NO_CERTS && !NO_RSA && USE_CERT_BUFFERS_2048 &&
  52493. * !NO_FILESYSTEM && !NO_BIO */
  52494. return EXPECT_RESULT();
  52495. }
  52496. /* test loading ECC key using BIO */
  52497. static int test_wolfSSL_PEM_PrivateKey_ecc(void)
  52498. {
  52499. EXPECT_DECLS;
  52500. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && defined(HAVE_ECC) && \
  52501. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  52502. BIO* bio = NULL;
  52503. EVP_PKEY* pkey = NULL;
  52504. XFILE file = XBADFILE;
  52505. const char* fname = "./certs/ecc-key.pem";
  52506. const char* fname_ecc_p8 = "./certs/ecc-keyPkcs8.pem";
  52507. size_t sz = 0;
  52508. byte* buf = NULL;
  52509. EVP_PKEY* pkey2 = NULL;
  52510. EVP_PKEY* pkey3 = NULL;
  52511. EC_KEY* ec_key = NULL;
  52512. int nid = 0;
  52513. BIO* pub_bio = NULL;
  52514. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  52515. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  52516. ExpectIntGT(sz = XFTELL(file), 0);
  52517. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  52518. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  52519. if (buf) {
  52520. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  52521. }
  52522. if (file != XBADFILE) {
  52523. XFCLOSE(file);
  52524. file = XBADFILE;
  52525. }
  52526. /* Test using BIO new mem and loading PEM private key */
  52527. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  52528. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  52529. BIO_free(bio);
  52530. bio = NULL;
  52531. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  52532. buf = NULL;
  52533. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52534. ExpectNotNull(pub_bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52535. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  52536. WOLFSSL_SUCCESS);
  52537. ExpectIntGT(BIO_pending(bio), 0);
  52538. /* No parameters. */
  52539. ExpectIntEQ(BIO_pending(bio), 227);
  52540. /* Check if the pubkey API writes only the public key */
  52541. #ifdef WOLFSSL_KEY_GEN
  52542. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), WOLFSSL_SUCCESS);
  52543. ExpectIntGT(BIO_pending(pub_bio), 0);
  52544. /* Previously both the private key and the pubkey calls would write
  52545. * out the private key and the PEM header was the only difference.
  52546. * The public PEM should be significantly shorter than the
  52547. * private key versison. */
  52548. ExpectIntEQ(BIO_pending(pub_bio), 178);
  52549. #endif
  52550. BIO_free(pub_bio);
  52551. BIO_free(bio);
  52552. bio = NULL;
  52553. ExpectNotNull(pkey2 = EVP_PKEY_new());
  52554. ExpectNotNull(pkey3 = EVP_PKEY_new());
  52555. if (pkey2 != NULL) {
  52556. pkey2->type = EVP_PKEY_EC;
  52557. }
  52558. /* Test parameter copy */
  52559. ExpectIntEQ(EVP_PKEY_copy_parameters(pkey2, pkey), 1);
  52560. /* Qt unit test case 1*/
  52561. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  52562. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey3, ec_key), WOLFSSL_SUCCESS);
  52563. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  52564. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  52565. #else
  52566. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  52567. #endif
  52568. /* Test default digest */
  52569. ExpectIntEQ(EVP_PKEY_get_default_digest_nid(pkey, &nid), 1);
  52570. ExpectIntEQ(nid, NID_sha256);
  52571. EC_KEY_free(ec_key);
  52572. ec_key = NULL;
  52573. EVP_PKEY_free(pkey3);
  52574. pkey3 = NULL;
  52575. EVP_PKEY_free(pkey2);
  52576. pkey2 = NULL;
  52577. EVP_PKEY_free(pkey);
  52578. pkey = NULL;
  52579. /* Qt unit test case ec pkcs8 key */
  52580. ExpectTrue((file = XFOPEN(fname_ecc_p8, "rb")) != XBADFILE);
  52581. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  52582. ExpectIntGT(sz = XFTELL(file), 0);
  52583. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  52584. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  52585. if (buf) {
  52586. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  52587. }
  52588. if (file != XBADFILE) {
  52589. XFCLOSE(file);
  52590. file = XBADFILE;
  52591. }
  52592. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  52593. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  52594. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  52595. buf = NULL;
  52596. BIO_free(bio);
  52597. bio = NULL;
  52598. ExpectNotNull(pkey3 = EVP_PKEY_new());
  52599. /* Qt unit test case */
  52600. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  52601. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey3, ec_key), WOLFSSL_SUCCESS);
  52602. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  52603. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  52604. #else
  52605. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  52606. #endif
  52607. EC_KEY_free(ec_key);
  52608. EVP_PKEY_free(pkey3);
  52609. EVP_PKEY_free(pkey);
  52610. pkey = NULL;
  52611. #endif
  52612. return EXPECT_RESULT();
  52613. }
  52614. /* test loading DSA key using BIO */
  52615. static int test_wolfSSL_PEM_PrivateKey_dsa(void)
  52616. {
  52617. EXPECT_DECLS;
  52618. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_DSA) && \
  52619. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  52620. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL)
  52621. BIO* bio = NULL;
  52622. EVP_PKEY* pkey = NULL;
  52623. ExpectNotNull(bio = BIO_new_file("./certs/dsa2048.pem", "rb"));
  52624. /* Private DSA EVP_PKEY */
  52625. ExpectNotNull(pkey = wolfSSL_PEM_read_bio_PrivateKey(bio, NULL, NULL,
  52626. NULL));
  52627. BIO_free(bio);
  52628. bio = NULL;
  52629. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52630. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  52631. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  52632. NULL), 0);
  52633. #endif
  52634. #ifdef WOLFSSL_KEY_GEN
  52635. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), 1);
  52636. ExpectIntEQ(BIO_pending(bio), 1178);
  52637. BIO_reset(bio);
  52638. #endif
  52639. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  52640. 1);
  52641. ExpectIntEQ(BIO_pending(bio), 1196);
  52642. BIO_free(bio);
  52643. bio = NULL;
  52644. EVP_PKEY_free(pkey);
  52645. pkey = NULL;
  52646. #endif
  52647. #endif
  52648. return EXPECT_RESULT();
  52649. }
  52650. /* test loading DH key using BIO */
  52651. static int test_wolfSSL_PEM_PrivateKey_dh(void)
  52652. {
  52653. EXPECT_DECLS;
  52654. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_DH) && \
  52655. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  52656. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  52657. defined(WOLFSSL_OPENSSH)) && (!defined(HAVE_FIPS) || \
  52658. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  52659. BIO* bio = NULL;
  52660. EVP_PKEY* pkey = NULL;
  52661. ExpectNotNull(bio = BIO_new_file("./certs/dh-priv-2048.pem", "rb"));
  52662. /* Private DH EVP_PKEY */
  52663. ExpectNotNull(pkey = wolfSSL_PEM_read_bio_PrivateKey(bio, NULL, NULL,
  52664. NULL));
  52665. BIO_free(bio);
  52666. bio = NULL;
  52667. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52668. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  52669. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  52670. NULL), 0);
  52671. #endif
  52672. #ifdef WOLFSSL_KEY_GEN
  52673. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), 0);
  52674. #endif
  52675. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  52676. 1);
  52677. ExpectIntEQ(BIO_pending(bio), 806);
  52678. BIO_free(bio);
  52679. bio = NULL;
  52680. EVP_PKEY_free(pkey);
  52681. pkey = NULL;
  52682. #endif
  52683. #endif
  52684. return EXPECT_RESULT();
  52685. }
  52686. static int test_wolfSSL_PEM_PrivateKey(void)
  52687. {
  52688. EXPECT_DECLS;
  52689. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  52690. (!defined(NO_RSA) || defined(HAVE_ECC)) && defined(USE_CERT_BUFFERS_2048)
  52691. #ifndef NO_BIO
  52692. BIO* bio = NULL;
  52693. #endif
  52694. EVP_PKEY* pkey = NULL;
  52695. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  52696. #ifndef NO_BIO
  52697. /* test creating new EVP_PKEY with bad arg */
  52698. ExpectNull((pkey = PEM_read_bio_PrivateKey(NULL, NULL, NULL, NULL)));
  52699. /* Test bad EVP_PKEY type. */
  52700. /* New HMAC EVP_PKEY */
  52701. ExpectNotNull(bio = BIO_new_mem_buf("", 1));
  52702. ExpectNotNull(pkey = EVP_PKEY_new());
  52703. if (pkey != NULL) {
  52704. pkey->type = EVP_PKEY_HMAC;
  52705. }
  52706. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  52707. 0);
  52708. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  52709. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  52710. NULL), 0);
  52711. #endif
  52712. #ifdef WOLFSSL_KEY_GEN
  52713. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52714. #endif
  52715. EVP_PKEY_free(pkey);
  52716. pkey = NULL;
  52717. BIO_free(bio);
  52718. bio = NULL;
  52719. /* key is DES encrypted */
  52720. #if !defined(NO_DES3) && defined(WOLFSSL_ENCRYPTED_KEYS) && \
  52721. !defined(NO_RSA) && !defined(NO_BIO) && !defined(NO_FILESYSTEM) && \
  52722. !defined(NO_MD5) && defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  52723. {
  52724. XFILE f = XBADFILE;
  52725. wc_pem_password_cb* passwd_cb = NULL;
  52726. void* passwd_cb_userdata;
  52727. SSL_CTX* ctx = NULL;
  52728. char passwd[] = "bad password";
  52729. #ifndef WOLFSSL_NO_TLS12
  52730. #ifndef NO_WOLFSSL_SERVER
  52731. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_server_method()));
  52732. #else
  52733. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_client_method()));
  52734. #endif
  52735. #else
  52736. #ifndef NO_WOLFSSL_SERVER
  52737. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_server_method()));
  52738. #else
  52739. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_client_method()));
  52740. #endif
  52741. #endif
  52742. ExpectNotNull(bio = BIO_new_file("./certs/server-keyEnc.pem", "rb"));
  52743. SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  52744. ExpectNotNull(passwd_cb = SSL_CTX_get_default_passwd_cb(ctx));
  52745. ExpectNull(passwd_cb_userdata =
  52746. SSL_CTX_get_default_passwd_cb_userdata(ctx));
  52747. /* fail case with password call back */
  52748. ExpectNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL,
  52749. (void*)passwd));
  52750. BIO_free(bio);
  52751. ExpectNotNull(bio = BIO_new_file("./certs/server-keyEnc.pem", "rb"));
  52752. ExpectNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, passwd_cb,
  52753. (void*)passwd));
  52754. BIO_free(bio);
  52755. ExpectTrue((f = XFOPEN("./certs/server-keyEnc.pem", "rb")) != XBADFILE);
  52756. ExpectNotNull(bio = BIO_new_fp(f, BIO_CLOSE));
  52757. if ((bio == NULL) && (f != XBADFILE)) {
  52758. XFCLOSE(f);
  52759. }
  52760. /* use callback that works */
  52761. ExpectNotNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, passwd_cb,
  52762. (void*)"yassl123"));
  52763. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), SSL_SUCCESS);
  52764. EVP_PKEY_free(pkey);
  52765. pkey = NULL;
  52766. BIO_free(bio);
  52767. bio = NULL;
  52768. SSL_CTX_free(ctx);
  52769. }
  52770. #endif /* !defined(NO_DES3) */
  52771. #endif /* !NO_BIO */
  52772. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  52773. {
  52774. unsigned char buf[2048];
  52775. size_t bytes = 0;
  52776. XFILE f = XBADFILE;
  52777. SSL_CTX* ctx = NULL;
  52778. #ifndef WOLFSSL_NO_TLS12
  52779. #ifndef NO_WOLFSSL_SERVER
  52780. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_server_method()));
  52781. #else
  52782. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_client_method()));
  52783. #endif
  52784. #else
  52785. #ifndef NO_WOLFSSL_SERVER
  52786. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_server_method()));
  52787. #else
  52788. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_client_method()));
  52789. #endif
  52790. #endif
  52791. ExpectTrue((f = XFOPEN("./certs/ecc-key.der", "rb")) != XBADFILE);
  52792. ExpectIntGT(bytes = (size_t)XFREAD(buf, 1, sizeof(buf), f), 0);
  52793. if (f != XBADFILE)
  52794. XFCLOSE(f);
  52795. server_key = buf;
  52796. pkey = NULL;
  52797. ExpectNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key, (long int)bytes));
  52798. ExpectNull(pkey);
  52799. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_EC, &pkey, &server_key, (long int)bytes));
  52800. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), SSL_SUCCESS);
  52801. EVP_PKEY_free(pkey);
  52802. pkey = NULL;
  52803. SSL_CTX_free(ctx);
  52804. server_key = NULL;
  52805. }
  52806. #endif
  52807. #ifndef NO_BIO
  52808. (void)bio;
  52809. #endif
  52810. (void)pkey;
  52811. (void)server_key;
  52812. #endif /* OPENSSL_EXTRA && !NO_CERTS && !NO_RSA && USE_CERT_BUFFERS_2048 */
  52813. return EXPECT_RESULT();
  52814. }
  52815. static int test_wolfSSL_PEM_file_RSAKey(void)
  52816. {
  52817. EXPECT_DECLS;
  52818. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  52819. defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && \
  52820. !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  52821. RSA* rsa = NULL;
  52822. XFILE fp = XBADFILE;
  52823. ExpectTrue((fp = XFOPEN("./certs/rsa-pub-2048.pem", "rb")) != XBADFILE);
  52824. ExpectNotNull((rsa = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL)));
  52825. if (fp != XBADFILE)
  52826. XFCLOSE(fp);
  52827. ExpectIntEQ(RSA_size(rsa), 256);
  52828. ExpectIntEQ(PEM_write_RSAPublicKey(XBADFILE, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52829. ExpectIntEQ(PEM_write_RSAPublicKey(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52830. ExpectIntEQ(PEM_write_RSAPublicKey(stderr, rsa), WOLFSSL_SUCCESS);
  52831. ExpectIntEQ(PEM_write_RSA_PUBKEY(XBADFILE, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52832. ExpectIntEQ(PEM_write_RSA_PUBKEY(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52833. ExpectIntEQ(PEM_write_RSA_PUBKEY(stderr, rsa), WOLFSSL_SUCCESS);
  52834. RSA_free(rsa);
  52835. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  52836. (defined(WOLFSSL_KEY_GEN) || WOLFSSL_CERT_GEN) && \
  52837. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_CERTS) */
  52838. return EXPECT_RESULT();
  52839. }
  52840. static int test_wolfSSL_PEM_file_RSAPrivateKey(void)
  52841. {
  52842. EXPECT_DECLS;
  52843. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  52844. !defined(NO_FILESYSTEM) && \
  52845. (defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM))
  52846. RSA* rsa = NULL;
  52847. XFILE f = NULL;
  52848. ExpectTrue((f = XFOPEN(svrKeyFile, "r")) != XBADFILE);
  52849. ExpectNotNull((rsa = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL)));
  52850. ExpectIntEQ(RSA_size(rsa), 256);
  52851. if (f != XBADFILE) {
  52852. XFCLOSE(f);
  52853. f = XBADFILE;
  52854. }
  52855. ExpectIntEQ(PEM_write_RSAPrivateKey(XBADFILE, rsa, NULL, NULL, 0, NULL,
  52856. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52857. ExpectIntEQ(PEM_write_RSAPrivateKey(stderr, NULL, NULL, NULL, 0, NULL,
  52858. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52859. ExpectIntEQ(PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0, NULL, NULL),
  52860. WOLFSSL_SUCCESS);
  52861. RSA_free(rsa);
  52862. #ifdef HAVE_ECC
  52863. ExpectTrue((f = XFOPEN(eccKeyFile, "r")) != XBADFILE);
  52864. ExpectNull((rsa = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL)));
  52865. if (f != XBADFILE)
  52866. XFCLOSE(f);
  52867. #endif /* HAVE_ECC */
  52868. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  52869. return EXPECT_RESULT();
  52870. }
  52871. static int test_wolfSSL_PEM_read_RSA_PUBKEY(void)
  52872. {
  52873. EXPECT_DECLS;
  52874. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  52875. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  52876. XFILE file = XBADFILE;
  52877. const char* fname = "./certs/client-keyPub.pem";
  52878. RSA *rsa = NULL;
  52879. ExpectNull(wolfSSL_PEM_read_RSA_PUBKEY(XBADFILE, NULL, NULL, NULL));
  52880. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  52881. ExpectNotNull((rsa = PEM_read_RSA_PUBKEY(file, NULL, NULL, NULL)));
  52882. ExpectIntEQ(RSA_size(rsa), 256);
  52883. RSA_free(rsa);
  52884. if (file != XBADFILE)
  52885. XFCLOSE(file);
  52886. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  52887. return EXPECT_RESULT();
  52888. }
  52889. #ifndef NO_BIO
  52890. static int test_wolfSSL_PEM_bio_RSAKey(void)
  52891. {
  52892. EXPECT_DECLS;
  52893. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  52894. defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && \
  52895. !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  52896. RSA* rsa = NULL;
  52897. BIO* bio = NULL;
  52898. /* PrivateKey */
  52899. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb"));
  52900. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(NULL, NULL, NULL, NULL)));
  52901. ExpectNotNull(PEM_read_bio_RSAPrivateKey(bio, &rsa, NULL, NULL));
  52902. ExpectNotNull(rsa);
  52903. ExpectIntEQ(RSA_size(rsa), 256);
  52904. ExpectIntEQ(PEM_write_bio_RSAPrivateKey(NULL, NULL, NULL, NULL, 0, NULL, \
  52905. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52906. BIO_free(bio);
  52907. bio = NULL;
  52908. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52909. ExpectIntEQ(PEM_write_bio_RSAPrivateKey(bio, rsa, NULL, NULL, 0, NULL, \
  52910. NULL), WOLFSSL_SUCCESS);
  52911. BIO_free(bio);
  52912. bio = NULL;
  52913. RSA_free(rsa);
  52914. rsa = NULL;
  52915. /* PUBKEY */
  52916. ExpectNotNull(bio = BIO_new_file("./certs/rsa-pub-2048.pem", "rb"));
  52917. ExpectNull((rsa = PEM_read_bio_RSA_PUBKEY(NULL, NULL, NULL, NULL)));
  52918. ExpectNotNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  52919. ExpectIntEQ(RSA_size(rsa), 256);
  52920. ExpectIntEQ(PEM_write_bio_RSA_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52921. BIO_free(bio);
  52922. bio = NULL;
  52923. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52924. ExpectIntEQ(PEM_write_bio_RSA_PUBKEY(bio, rsa), WOLFSSL_SUCCESS);
  52925. BIO_free(bio);
  52926. bio = NULL;
  52927. RSA_free(rsa);
  52928. rsa = NULL;
  52929. /* Ensure that keys beginning with BEGIN RSA PUBLIC KEY can be read, too. */
  52930. ExpectNotNull(bio = BIO_new_file("./certs/server-keyPub.pem", "rb"));
  52931. ExpectNotNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  52932. BIO_free(bio);
  52933. bio = NULL;
  52934. RSA_free(rsa);
  52935. rsa = NULL;
  52936. #ifdef HAVE_ECC
  52937. /* ensure that non-rsa keys do not work */
  52938. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb")); /* ecc key */
  52939. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  52940. ExpectNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  52941. BIO_free(bio);
  52942. bio = NULL;
  52943. RSA_free(rsa);
  52944. rsa = NULL;
  52945. #endif /* HAVE_ECC */
  52946. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  52947. (defined(WOLFSSL_KEY_GEN) || WOLFSSL_CERT_GEN) && \
  52948. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_CERTS) */
  52949. return EXPECT_RESULT();
  52950. }
  52951. static int test_wolfSSL_PEM_bio_RSAPrivateKey(void)
  52952. {
  52953. EXPECT_DECLS;
  52954. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  52955. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  52956. RSA* rsa = NULL;
  52957. RSA* rsa_dup = NULL;
  52958. BIO* bio = NULL;
  52959. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb"));
  52960. ExpectNotNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  52961. ExpectIntEQ(RSA_size(rsa), 256);
  52962. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  52963. ExpectNull(rsa_dup = RSAPublicKey_dup(NULL));
  52964. /* Test duplicating empty key. */
  52965. ExpectNotNull(rsa_dup = RSA_new());
  52966. ExpectNull(RSAPublicKey_dup(rsa_dup));
  52967. RSA_free(rsa_dup);
  52968. rsa_dup = NULL;
  52969. ExpectNotNull(rsa_dup = RSAPublicKey_dup(rsa));
  52970. ExpectPtrNE(rsa_dup, rsa);
  52971. #endif
  52972. /* test if valgrind complains about unreleased memory */
  52973. RSA_up_ref(rsa);
  52974. RSA_free(rsa);
  52975. BIO_free(bio);
  52976. bio = NULL;
  52977. RSA_free(rsa);
  52978. rsa = NULL;
  52979. RSA_free(rsa_dup);
  52980. rsa_dup = NULL;
  52981. #ifdef HAVE_ECC
  52982. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb"));
  52983. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  52984. BIO_free(bio);
  52985. #endif /* HAVE_ECC */
  52986. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  52987. return EXPECT_RESULT();
  52988. }
  52989. static int test_wolfSSL_PEM_bio_DSAKey(void)
  52990. {
  52991. EXPECT_DECLS;
  52992. #ifndef HAVE_SELFTEST
  52993. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL)) && !defined(NO_CERTS) && \
  52994. defined(WOLFSSL_KEY_GEN) && !defined(NO_FILESYSTEM) && !defined(NO_DSA)
  52995. DSA* dsa = NULL;
  52996. BIO* bio = NULL;
  52997. /* PrivateKey */
  52998. ExpectNotNull(bio = BIO_new_file("./certs/1024/dsa1024.pem", "rb"));
  52999. ExpectNull((dsa = PEM_read_bio_DSAPrivateKey(NULL, NULL, NULL, NULL)));
  53000. ExpectNotNull((dsa = PEM_read_bio_DSAPrivateKey(bio, NULL, NULL, NULL)));
  53001. ExpectIntEQ(BN_num_bytes(dsa->g), 128);
  53002. ExpectIntEQ(PEM_write_bio_DSAPrivateKey(NULL, NULL, NULL, NULL, 0, NULL,
  53003. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53004. BIO_free(bio);
  53005. bio = NULL;
  53006. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  53007. ExpectIntEQ(PEM_write_bio_DSAPrivateKey(bio, dsa, NULL, NULL, 0, NULL,
  53008. NULL), WOLFSSL_SUCCESS);
  53009. BIO_free(bio);
  53010. bio = NULL;
  53011. DSA_free(dsa);
  53012. dsa = NULL;
  53013. /* PUBKEY */
  53014. ExpectNotNull(bio = BIO_new_file("./certs/1024/dsa-pub-1024.pem", "rb"));
  53015. ExpectNull((dsa = PEM_read_bio_DSA_PUBKEY(NULL, NULL, NULL, NULL)));
  53016. ExpectNotNull((dsa = PEM_read_bio_DSA_PUBKEY(bio, NULL, NULL, NULL)));
  53017. ExpectIntEQ(BN_num_bytes(dsa->g), 128);
  53018. ExpectIntEQ(PEM_write_bio_DSA_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53019. BIO_free(bio);
  53020. bio = NULL;
  53021. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  53022. ExpectIntEQ(PEM_write_bio_DSA_PUBKEY(bio, dsa), WOLFSSL_SUCCESS);
  53023. BIO_free(bio);
  53024. bio = NULL;
  53025. DSA_free(dsa);
  53026. dsa = NULL;
  53027. #ifdef HAVE_ECC
  53028. /* ensure that non-dsa keys do not work */
  53029. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb")); /* ecc key */
  53030. ExpectNull((dsa = PEM_read_bio_DSAPrivateKey(bio, NULL, NULL, NULL)));
  53031. ExpectNull((dsa = PEM_read_bio_DSA_PUBKEY(bio, NULL, NULL, NULL)));
  53032. BIO_free(bio);
  53033. bio = NULL;
  53034. DSA_free(dsa);
  53035. dsa = NULL;
  53036. #endif /* HAVE_ECC */
  53037. #endif /* defined(WOLFSSL_QT) || defined(OPENSSL_ALL)) && \
  53038. !defined(NO_CERTS) && defined(WOLFSSL_KEY_GEN) && \
  53039. !defined(NO_FILESYSTEM) && !defined(NO_DSA) */
  53040. #endif /* HAVE_SELFTEST */
  53041. return EXPECT_RESULT();
  53042. }
  53043. static int test_wolfSSL_PEM_bio_ECKey(void)
  53044. {
  53045. EXPECT_DECLS;
  53046. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  53047. defined(WOLFSSL_KEY_GEN) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC)
  53048. EC_KEY* ec = NULL;
  53049. EC_KEY* ec2;
  53050. BIO* bio = NULL;
  53051. #if defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM)
  53052. unsigned char* pem = NULL;
  53053. int pLen;
  53054. #endif
  53055. static char ec_key_bad_1[] = "-----BEGIN PUBLIC KEY-----\n"
  53056. "MAA=\n"
  53057. "-----END PUBLIC KEY-----";
  53058. static char ec_priv_key_bad_1[] = "-----BEGIN EC PRIVATE KEY-----\n"
  53059. "MAA=\n"
  53060. "-----END EC PRIVATE KEY-----";
  53061. /* PrivateKey */
  53062. ExpectNotNull(bio = BIO_new_file("./certs/ecc-key.pem", "rb"));
  53063. ExpectNull((ec = PEM_read_bio_ECPrivateKey(NULL, NULL, NULL, NULL)));
  53064. ec2 = NULL;
  53065. ExpectNotNull((ec = PEM_read_bio_ECPrivateKey(bio, &ec2, NULL, NULL)));
  53066. ExpectIntEQ(ec == ec2, 1);
  53067. ExpectIntEQ(wc_ecc_size((ecc_key*)ec->internal), 32);
  53068. ExpectIntEQ(PEM_write_bio_ECPrivateKey(NULL, NULL, NULL, NULL, 0, NULL,
  53069. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53070. ExpectIntEQ(PEM_write_bio_ECPrivateKey(bio, NULL, NULL, NULL, 0, NULL,
  53071. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53072. ExpectIntEQ(PEM_write_bio_ECPrivateKey(NULL, ec, NULL, NULL, 0, NULL, NULL),
  53073. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53074. BIO_free(bio);
  53075. bio = NULL;
  53076. /* Public key data - fail. */
  53077. ExpectNotNull(bio = BIO_new_file("./certs/ecc-client-keyPub.pem", "rb"));
  53078. ExpectNull(PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL));
  53079. BIO_free(bio);
  53080. bio = NULL;
  53081. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  53082. ExpectIntEQ(PEM_write_bio_ECPrivateKey(bio, ec, NULL, NULL, 0, NULL, \
  53083. NULL), WOLFSSL_SUCCESS);
  53084. BIO_free(bio);
  53085. bio = NULL;
  53086. ExpectIntEQ(PEM_write_ECPrivateKey(XBADFILE, NULL, NULL, NULL, 0, NULL,
  53087. NULL),WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53088. ExpectIntEQ(PEM_write_ECPrivateKey(stderr, NULL, NULL, NULL, 0, NULL, NULL),
  53089. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53090. ExpectIntEQ(PEM_write_ECPrivateKey(XBADFILE, ec, NULL, NULL, 0, NULL, NULL),
  53091. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53092. ExpectIntEQ(PEM_write_ECPrivateKey(stderr, ec, NULL, NULL, 0, NULL, NULL),
  53093. WOLFSSL_SUCCESS);
  53094. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, NULL,
  53095. NULL), 0);
  53096. #if defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM)
  53097. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, NULL,
  53098. NULL), 0);
  53099. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, &pem,
  53100. NULL), 0);
  53101. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, NULL,
  53102. &pLen), 0);
  53103. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, &pem,
  53104. &pLen), 0);
  53105. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, NULL,
  53106. &pLen), 0);
  53107. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, &pem,
  53108. NULL), 0);
  53109. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, &pem,
  53110. &pLen), 1);
  53111. ExpectIntGT(pLen, 0);
  53112. XFREE(pem, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  53113. #endif
  53114. EC_KEY_free(ec);
  53115. ec = NULL;
  53116. /* PUBKEY */
  53117. ExpectNotNull(bio = BIO_new_file("./certs/ecc-client-keyPub.pem", "rb"));
  53118. ExpectNull((ec = PEM_read_bio_EC_PUBKEY(NULL, NULL, NULL, NULL)));
  53119. ec2 = NULL;
  53120. ExpectNotNull((ec = PEM_read_bio_EC_PUBKEY(bio, &ec2, NULL, NULL)));
  53121. ExpectIntEQ(ec == ec2, 1);
  53122. ExpectIntEQ(wc_ecc_size((ecc_key*)ec->internal), 32);
  53123. ExpectIntEQ(PEM_write_bio_EC_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53124. BIO_free(bio);
  53125. bio = NULL;
  53126. /* Test 0x30, 0x00 fails. */
  53127. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_key_bad_1,
  53128. sizeof(ec_key_bad_1)));
  53129. ExpectNull(PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  53130. BIO_free(bio);
  53131. bio = NULL;
  53132. /* Private key data - fail. */
  53133. ExpectNotNull(bio = BIO_new_file("./certs/ecc-key.pem", "rb"));
  53134. ExpectNull(PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  53135. BIO_free(bio);
  53136. bio = NULL;
  53137. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  53138. ExpectIntEQ(PEM_write_bio_EC_PUBKEY(bio, ec), WOLFSSL_SUCCESS);
  53139. BIO_free(bio);
  53140. bio = NULL;
  53141. /* Same test as above, but with a file pointer rather than a BIO. */
  53142. ExpectIntEQ(PEM_write_EC_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53143. ExpectIntEQ(PEM_write_EC_PUBKEY(NULL, ec), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53144. ExpectIntEQ(PEM_write_EC_PUBKEY(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53145. ExpectIntEQ(PEM_write_EC_PUBKEY(stderr, ec), WOLFSSL_SUCCESS);
  53146. EC_KEY_free(ec);
  53147. ec = NULL;
  53148. #ifndef NO_RSA
  53149. /* ensure that non-ec keys do not work */
  53150. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb")); /* rsa key */
  53151. ExpectNull((ec = PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL)));
  53152. ExpectNull((ec = PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL)));
  53153. BIO_free(bio);
  53154. bio = NULL;
  53155. EC_KEY_free(ec);
  53156. ec = NULL;
  53157. #endif /* !NO_RSA */
  53158. /* Test 0x30, 0x00 fails. */
  53159. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_priv_key_bad_1,
  53160. sizeof(ec_priv_key_bad_1)));
  53161. ExpectNull(PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL));
  53162. BIO_free(bio);
  53163. bio = NULL;
  53164. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  53165. return EXPECT_RESULT();
  53166. }
  53167. static int test_wolfSSL_PEM_PUBKEY(void)
  53168. {
  53169. EXPECT_DECLS;
  53170. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  53171. BIO* bio = NULL;
  53172. EVP_PKEY* pkey = NULL;
  53173. /* test creating new EVP_PKEY with bad arg */
  53174. ExpectNull((pkey = PEM_read_bio_PUBKEY(NULL, NULL, NULL, NULL)));
  53175. /* test loading ECC key using BIO */
  53176. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  53177. {
  53178. XFILE file = XBADFILE;
  53179. const char* fname = "./certs/ecc-client-keyPub.pem";
  53180. size_t sz = 0;
  53181. byte* buf = NULL;
  53182. EVP_PKEY* pkey2 = NULL;
  53183. EC_KEY* ec_key = NULL;
  53184. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  53185. ExpectIntEQ(XFSEEK(file, 0, XSEEK_END), 0);
  53186. ExpectIntGT(sz = XFTELL(file), 0);
  53187. ExpectIntEQ(XFSEEK(file, 0, XSEEK_SET), 0);
  53188. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  53189. if (buf != NULL) {
  53190. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  53191. }
  53192. if (file != XBADFILE) {
  53193. XFCLOSE(file);
  53194. }
  53195. /* Test using BIO new mem and loading PEM private key */
  53196. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  53197. ExpectNotNull((pkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL)));
  53198. BIO_free(bio);
  53199. bio = NULL;
  53200. EVP_PKEY_free(pkey);
  53201. pkey = NULL;
  53202. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  53203. ExpectNotNull(pkey = EVP_PKEY_new());
  53204. ExpectPtrEq(PEM_read_bio_PUBKEY(bio, &pkey, NULL, NULL), pkey);
  53205. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  53206. BIO_free(bio);
  53207. bio = NULL;
  53208. /* Qt unit test case*/
  53209. ExpectNotNull(pkey2 = EVP_PKEY_new());
  53210. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  53211. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey2, ec_key), WOLFSSL_SUCCESS);
  53212. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  53213. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey2), 1/* match */);
  53214. #else
  53215. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey2), 0);
  53216. #endif
  53217. EC_KEY_free(ec_key);
  53218. EVP_PKEY_free(pkey2);
  53219. EVP_PKEY_free(pkey);
  53220. pkey = NULL;
  53221. }
  53222. #endif
  53223. (void)bio;
  53224. (void)pkey;
  53225. #endif
  53226. return EXPECT_RESULT();
  53227. }
  53228. #endif /* !NO_BIO */
  53229. static int test_DSA_do_sign_verify(void)
  53230. {
  53231. EXPECT_DECLS;
  53232. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  53233. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  53234. !defined(NO_DSA)
  53235. unsigned char digest[WC_SHA_DIGEST_SIZE];
  53236. DSA_SIG* sig = NULL;
  53237. DSA* dsa = NULL;
  53238. word32 bytes;
  53239. byte sigBin[DSA_SIG_SIZE];
  53240. int dsacheck;
  53241. #ifdef USE_CERT_BUFFERS_1024
  53242. byte tmp[ONEK_BUF];
  53243. XMEMSET(tmp, 0, sizeof(tmp));
  53244. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  53245. bytes = sizeof_dsa_key_der_1024;
  53246. #elif defined(USE_CERT_BUFFERS_2048)
  53247. byte tmp[TWOK_BUF];
  53248. XMEMSET(tmp, 0, sizeof(tmp));
  53249. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  53250. bytes = sizeof_dsa_key_der_2048;
  53251. #else
  53252. byte tmp[TWOK_BUF];
  53253. XFILE fp = XBADFILE;
  53254. XMEMSET(tmp, 0, sizeof(tmp));
  53255. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb") != XBADFILE);
  53256. ExpectIntGT(bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  53257. if (fp != XBADFILE)
  53258. XFCLOSE(fp);
  53259. #endif /* END USE_CERT_BUFFERS_1024 */
  53260. XMEMSET(digest, 202, sizeof(digest));
  53261. ExpectNotNull(dsa = DSA_new());
  53262. ExpectIntEQ(DSA_LoadDer(dsa, tmp, (int)bytes), 1);
  53263. ExpectIntEQ(wolfSSL_DSA_do_sign(digest, sigBin, dsa), 1);
  53264. ExpectIntEQ(wolfSSL_DSA_do_verify(digest, sigBin, dsa, &dsacheck), 1);
  53265. ExpectNotNull(sig = DSA_do_sign(digest, WC_SHA_DIGEST_SIZE, dsa));
  53266. ExpectIntEQ(DSA_do_verify(digest, WC_SHA_DIGEST_SIZE, sig, dsa), 1);
  53267. DSA_SIG_free(sig);
  53268. DSA_free(dsa);
  53269. #endif
  53270. #endif /* !HAVE_SELFTEST && !HAVE_FIPS */
  53271. return EXPECT_RESULT();
  53272. }
  53273. static int test_wolfSSL_tmp_dh(void)
  53274. {
  53275. EXPECT_DECLS;
  53276. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  53277. !defined(NO_RSA) && !defined(NO_DH) && !defined(NO_BIO)
  53278. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  53279. byte buff[6000];
  53280. static const unsigned char p[] = {
  53281. 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13, 0xba,
  53282. 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5, 0x00,
  53283. 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a, 0xc6,
  53284. 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53, 0x0a,
  53285. 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84, 0xbf,
  53286. 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1, 0x8a,
  53287. 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91, 0xe6,
  53288. 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66, 0x48,
  53289. 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9, 0x3d,
  53290. 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e, 0x19,
  53291. 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d, 0x9f,
  53292. 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d, 0x2a,
  53293. 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75, 0xe6,
  53294. 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa, 0x04,
  53295. 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93, 0x38,
  53296. 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c, 0xe5,
  53297. 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35, 0x8e,
  53298. 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e, 0x5a,
  53299. 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76, 0xcc,
  53300. 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62, 0xa7,
  53301. 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0, 0x36,
  53302. 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40, 0x90,
  53303. 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a, 0xc3,
  53304. 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4, 0x48,
  53305. 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4, 0x9a,
  53306. 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90, 0xab,
  53307. 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58, 0x4b,
  53308. 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f, 0x08,
  53309. 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6, 0xb6,
  53310. 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67, 0x6b,
  53311. 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7, 0xfa,
  53312. 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f, 0x93
  53313. };
  53314. int pSz = (int)sizeof(p);
  53315. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  53316. !defined(HAVE_SELFTEST)
  53317. static const unsigned char bad_p[] = {
  53318. 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13, 0xba,
  53319. 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5, 0x00,
  53320. 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a, 0xc6,
  53321. 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53, 0x0a,
  53322. 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84, 0xbf,
  53323. 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1, 0x8a,
  53324. 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91, 0xe6,
  53325. 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66, 0x48,
  53326. 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9, 0x3d,
  53327. 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e, 0x19,
  53328. 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d, 0x9f,
  53329. 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d, 0x2a,
  53330. 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75, 0xe6,
  53331. 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa, 0x04,
  53332. 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93, 0x38,
  53333. 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c, 0xe5,
  53334. 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35, 0x8e,
  53335. 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e, 0x5a,
  53336. 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76, 0xcc,
  53337. 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62, 0xa7,
  53338. 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0, 0x36,
  53339. 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40, 0x90,
  53340. 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a, 0xc3,
  53341. 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4, 0x48,
  53342. 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4, 0x9a,
  53343. 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90, 0xab,
  53344. 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58, 0x4b,
  53345. 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f, 0x08,
  53346. 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6, 0xb6,
  53347. 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67, 0x6b,
  53348. 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7, 0xfa,
  53349. 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f, 0x91
  53350. };
  53351. #endif
  53352. static const unsigned char g[] = { 0x02 };
  53353. int gSz = (int)sizeof(g);
  53354. #if !defined(NO_DSA)
  53355. char file[] = "./certs/dsaparams.pem";
  53356. DSA* dsa = NULL;
  53357. #else
  53358. char file[] = "./certs/dh2048.pem";
  53359. #endif
  53360. XFILE f = XBADFILE;
  53361. int bytes = 0;
  53362. DH* dh = NULL;
  53363. DH* dh2 = NULL;
  53364. BIO* bio = NULL;
  53365. SSL* ssl = NULL;
  53366. SSL_CTX* ctx = NULL;
  53367. #ifndef NO_WOLFSSL_CLIENT
  53368. SSL* ssl_c = NULL;
  53369. SSL_CTX* ctx_c = NULL;
  53370. #endif
  53371. #ifndef NO_WOLFSSL_SERVER
  53372. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  53373. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  53374. WOLFSSL_FILETYPE_PEM));
  53375. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  53376. WOLFSSL_FILETYPE_PEM));
  53377. ExpectNotNull(ssl = SSL_new(ctx));
  53378. #endif
  53379. #ifndef NO_WOLFSSL_CLIENT
  53380. ExpectNotNull(ctx_c = SSL_CTX_new(wolfSSLv23_client_method()));
  53381. ExpectTrue(SSL_CTX_use_certificate_file(ctx_c, svrCertFile,
  53382. WOLFSSL_FILETYPE_PEM));
  53383. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx_c, svrKeyFile,
  53384. WOLFSSL_FILETYPE_PEM));
  53385. ExpectNotNull(ssl_c = SSL_new(ctx_c));
  53386. #ifdef NO_WOLFSSL_SERVER
  53387. ctx = ctx_c;
  53388. ssl = ssl_c;
  53389. #endif
  53390. #endif
  53391. XMEMSET(buff, 0, sizeof(buff));
  53392. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  53393. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  53394. if (f != XBADFILE)
  53395. XFCLOSE(f);
  53396. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  53397. #if !defined(NO_DSA)
  53398. dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL);
  53399. ExpectNotNull(dsa);
  53400. dh = wolfSSL_DSA_dup_DH(dsa);
  53401. #else
  53402. dh = wolfSSL_PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
  53403. #endif
  53404. ExpectNotNull(dh);
  53405. #if defined(WOLFSSL_DH_EXTRA) && \
  53406. (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH))
  53407. ExpectNotNull(dh2 = wolfSSL_DH_dup(dh));
  53408. DH_free(dh2);
  53409. dh2 = NULL;
  53410. #endif
  53411. /* Failure cases */
  53412. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, NULL, 0, NULL, 0),
  53413. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53414. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , NULL, 0, NULL, 0),
  53415. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53416. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, p , 0, NULL, 0),
  53417. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53418. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, NULL, 0, g , 0),
  53419. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53420. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , p , 0, NULL, 0),
  53421. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53422. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , NULL, 0, g , 0),
  53423. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53424. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, p , 0, g , 0),
  53425. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53426. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , p , 1, g , 1),
  53427. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  53428. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , buff, 6000, g , 1),
  53429. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  53430. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  53431. !defined(HAVE_SELFTEST)
  53432. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx, bad_p, pSz, g, gSz),
  53433. WC_NO_ERR_TRACE(DH_CHECK_PUB_E));
  53434. #endif
  53435. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, NULL, 0, NULL, 0),
  53436. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53437. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , NULL, 0, NULL, 0),
  53438. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53439. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, p , 0, NULL, 0),
  53440. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53441. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, NULL, 0, g , 0),
  53442. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53443. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , p , 0, NULL, 0),
  53444. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53445. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , NULL, 0, g , 0),
  53446. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53447. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, p , 0, g , 0),
  53448. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53449. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , p , 1, g , 1),
  53450. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  53451. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , buff, 6000, g , 1),
  53452. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  53453. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  53454. !defined(HAVE_SELFTEST)
  53455. #ifndef NO_WOLFSSL_SERVER
  53456. /* Parameters will be tested later so it passes now. */
  53457. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl, bad_p, pSz, g, gSz),
  53458. WOLFSSL_SUCCESS);
  53459. #endif
  53460. #endif
  53461. #ifndef NO_WOLFSSL_CLIENT
  53462. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl_c, p, pSz, g, gSz),
  53463. WC_NO_ERR_TRACE(SIDE_ERROR));
  53464. #endif
  53465. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53466. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx , NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53467. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(NULL, dh ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53468. ExpectIntEQ((int)SSL_set_tmp_dh(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53469. ExpectIntEQ((int)SSL_set_tmp_dh(ssl , NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53470. ExpectIntEQ((int)SSL_set_tmp_dh(NULL, dh ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53471. /* No p/g to use. */
  53472. dh2 = wolfSSL_DH_new();
  53473. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx , dh2 ), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  53474. ExpectIntEQ((int)SSL_set_tmp_dh(ssl , dh2 ), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  53475. DH_free(dh2);
  53476. dh2 = NULL;
  53477. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx, p, pSz, g, gSz),
  53478. WOLFSSL_SUCCESS);
  53479. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx, dh), WOLFSSL_SUCCESS);
  53480. #ifndef NO_WOLFSSL_SERVER
  53481. ExpectIntEQ((int)SSL_set_tmp_dh(ssl, dh), WOLFSSL_SUCCESS);
  53482. #else
  53483. ExpectIntEQ((int)SSL_set_tmp_dh(ssl, dh), WC_NO_ERR_TRACE(SIDE_ERROR));
  53484. #endif
  53485. BIO_free(bio);
  53486. #if !defined(NO_DSA)
  53487. DSA_free(dsa);
  53488. #endif
  53489. DH_free(dh);
  53490. dh = NULL;
  53491. #ifndef NO_WOLFSSL_CLIENT
  53492. if (ssl != ssl_c) {
  53493. SSL_free(ssl_c);
  53494. }
  53495. #endif
  53496. SSL_free(ssl);
  53497. #ifndef NO_WOLFSSL_CLIENT
  53498. if (ctx != ctx_c) {
  53499. SSL_CTX_free(ctx_c);
  53500. }
  53501. #endif
  53502. SSL_CTX_free(ctx);
  53503. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  53504. #endif
  53505. return EXPECT_RESULT();
  53506. }
  53507. static int test_wolfSSL_ctrl(void)
  53508. {
  53509. EXPECT_DECLS;
  53510. #if defined (OPENSSL_EXTRA) && !defined(NO_BIO)
  53511. byte buff[6000];
  53512. BIO* bio = NULL;
  53513. int bytes;
  53514. BUF_MEM* ptr = NULL;
  53515. XMEMSET(buff, 0, sizeof(buff));
  53516. bytes = sizeof(buff);
  53517. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  53518. ExpectNotNull(BIO_s_socket());
  53519. ExpectIntEQ((int)wolfSSL_BIO_get_mem_ptr(bio, &ptr), WOLFSSL_SUCCESS);
  53520. /* needs tested after stubs filled out @TODO
  53521. SSL_ctrl
  53522. SSL_CTX_ctrl
  53523. */
  53524. BIO_free(bio);
  53525. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_BIO) */
  53526. return EXPECT_RESULT();
  53527. }
  53528. static int test_wolfSSL_EVP_PKEY_new_mac_key(void)
  53529. {
  53530. EXPECT_DECLS;
  53531. #ifdef OPENSSL_EXTRA
  53532. static const unsigned char pw[] = "password";
  53533. static const int pwSz = sizeof(pw) - 1;
  53534. size_t checkPwSz = 0;
  53535. const unsigned char* checkPw = NULL;
  53536. WOLFSSL_EVP_PKEY* key = NULL;
  53537. ExpectNull(key = wolfSSL_EVP_PKEY_new_mac_key(0, NULL, pw, pwSz));
  53538. ExpectNull(key = wolfSSL_EVP_PKEY_new_mac_key(0, NULL, NULL, pwSz));
  53539. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, pw,
  53540. pwSz));
  53541. if (key != NULL) {
  53542. ExpectIntEQ(key->type, EVP_PKEY_HMAC);
  53543. ExpectIntEQ(key->save_type, EVP_PKEY_HMAC);
  53544. ExpectIntEQ(key->pkey_sz, pwSz);
  53545. ExpectIntEQ(XMEMCMP(key->pkey.ptr, pw, pwSz), 0);
  53546. }
  53547. ExpectNotNull(checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz));
  53548. ExpectIntEQ((int)checkPwSz, pwSz);
  53549. ExpectIntEQ(XMEMCMP(checkPw, pw, pwSz), 0);
  53550. wolfSSL_EVP_PKEY_free(key);
  53551. key = NULL;
  53552. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, pw,
  53553. 0));
  53554. ExpectIntEQ(key->pkey_sz, 0);
  53555. if (EXPECT_SUCCESS()) {
  53556. /* Allocation for key->pkey.ptr may fail - OK key len is 0 */
  53557. checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz);
  53558. }
  53559. ExpectTrue((checkPwSz == 0) || (checkPw != NULL));
  53560. ExpectIntEQ((int)checkPwSz, 0);
  53561. wolfSSL_EVP_PKEY_free(key);
  53562. key = NULL;
  53563. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, NULL,
  53564. 0));
  53565. ExpectIntEQ(key->pkey_sz, 0);
  53566. if (EXPECT_SUCCESS()) {
  53567. /* Allocation for key->pkey.ptr may fail - OK key len is 0 */
  53568. checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz);
  53569. }
  53570. ExpectTrue((checkPwSz == 0) || (checkPw != NULL));
  53571. ExpectIntEQ((int)checkPwSz, 0);
  53572. wolfSSL_EVP_PKEY_free(key);
  53573. key = NULL;
  53574. #endif /* OPENSSL_EXTRA */
  53575. return EXPECT_RESULT();
  53576. }
  53577. static int test_wolfSSL_EVP_PKEY_new_CMAC_key(void)
  53578. {
  53579. EXPECT_DECLS;
  53580. #ifdef OPENSSL_EXTRA
  53581. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_DIRECT)
  53582. const char *priv = "ABCDEFGHIJKLMNOP";
  53583. const WOLFSSL_EVP_CIPHER* cipher = EVP_aes_128_cbc();
  53584. WOLFSSL_EVP_PKEY* key = NULL;
  53585. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  53586. NULL, NULL, AES_128_KEY_SIZE, cipher));
  53587. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  53588. NULL, (const unsigned char *)priv, 0, cipher));
  53589. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  53590. NULL, (const unsigned char *)priv, AES_128_KEY_SIZE, NULL));
  53591. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  53592. NULL, (const unsigned char *)priv, AES_128_KEY_SIZE, cipher));
  53593. wolfSSL_EVP_PKEY_free(key);
  53594. #endif /* WOLFSSL_CMAC && !NO_AES && WOLFSSL_AES_DIRECT */
  53595. #endif /* OPENSSL_EXTRA */
  53596. return EXPECT_RESULT();
  53597. }
  53598. static int test_wolfSSL_EVP_Digest(void)
  53599. {
  53600. EXPECT_DECLS;
  53601. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && !defined(NO_PWDBASED)
  53602. const char* in = "abc";
  53603. int inLen = (int)XSTRLEN(in);
  53604. byte out[WC_SHA256_DIGEST_SIZE];
  53605. unsigned int outLen;
  53606. const char* expOut =
  53607. "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  53608. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  53609. "\x15\xAD";
  53610. ExpectIntEQ(wolfSSL_EVP_Digest((unsigned char*)in, inLen, out, &outLen,
  53611. "SHA256", NULL), 1);
  53612. ExpectIntEQ(outLen, WC_SHA256_DIGEST_SIZE);
  53613. ExpectIntEQ(XMEMCMP(out, expOut, WC_SHA256_DIGEST_SIZE), 0);
  53614. #endif /* OPEN_EXTRA && ! NO_SHA256 */
  53615. return EXPECT_RESULT();
  53616. }
  53617. static int test_wolfSSL_EVP_Digest_all(void)
  53618. {
  53619. EXPECT_DECLS;
  53620. #ifdef OPENSSL_EXTRA
  53621. const char* digests[] = {
  53622. #ifndef NO_MD5
  53623. "MD5",
  53624. #endif
  53625. #ifndef NO_SHA
  53626. "SHA",
  53627. #endif
  53628. #ifdef WOLFSSL_SHA224
  53629. "SHA224",
  53630. #endif
  53631. #ifndef NO_SHA256
  53632. "SHA256",
  53633. #endif
  53634. #ifdef WOLFSSL_SHA384
  53635. "SHA384",
  53636. #endif
  53637. #ifdef WOLFSSL_SHA512
  53638. "SHA512",
  53639. #endif
  53640. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  53641. "SHA512_224",
  53642. #endif
  53643. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  53644. "SHA512_256",
  53645. #endif
  53646. #ifdef WOLFSSL_SHA3
  53647. #ifndef WOLFSSL_NOSHA3_224
  53648. "SHA3_224",
  53649. #endif
  53650. #ifndef WOLFSSL_NOSHA3_256
  53651. "SHA3_256",
  53652. #endif
  53653. "SHA3_384",
  53654. #ifndef WOLFSSL_NOSHA3_512
  53655. "SHA3_512",
  53656. #endif
  53657. #endif /* WOLFSSL_SHA3 */
  53658. NULL
  53659. };
  53660. const char** d;
  53661. const unsigned char in[] = "abc";
  53662. int inLen = XSTR_SIZEOF(in);
  53663. byte out[WC_MAX_DIGEST_SIZE];
  53664. unsigned int outLen;
  53665. for (d = digests; *d != NULL; d++) {
  53666. ExpectIntEQ(EVP_Digest(in, inLen, out, &outLen, *d, NULL), 1);
  53667. ExpectIntGT(outLen, 0);
  53668. ExpectIntEQ(EVP_MD_size(*d), outLen);
  53669. }
  53670. #endif
  53671. return EXPECT_RESULT();
  53672. }
  53673. static int test_wolfSSL_EVP_MD_size(void)
  53674. {
  53675. EXPECT_DECLS;
  53676. #ifdef OPENSSL_EXTRA
  53677. WOLFSSL_EVP_MD_CTX mdCtx;
  53678. #ifdef WOLFSSL_SHA3
  53679. #ifndef WOLFSSL_NOSHA3_224
  53680. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53681. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_224"), 1);
  53682. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_224_DIGEST_SIZE);
  53683. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_224_BLOCK_SIZE);
  53684. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53685. #endif
  53686. #ifndef WOLFSSL_NOSHA3_256
  53687. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53688. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_256"), 1);
  53689. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_256_DIGEST_SIZE);
  53690. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_256_BLOCK_SIZE);
  53691. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53692. #endif
  53693. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53694. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_384"), 1);
  53695. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_384_DIGEST_SIZE);
  53696. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_384_BLOCK_SIZE);
  53697. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53698. #ifndef WOLFSSL_NOSHA3_512
  53699. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53700. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_512"), 1);
  53701. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_512_DIGEST_SIZE);
  53702. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_512_BLOCK_SIZE);
  53703. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53704. #endif
  53705. #endif /* WOLFSSL_SHA3 */
  53706. #ifndef NO_SHA256
  53707. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53708. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA256"), 1);
  53709. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53710. WC_SHA256_DIGEST_SIZE);
  53711. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53712. WC_SHA256_BLOCK_SIZE);
  53713. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA256_DIGEST_SIZE);
  53714. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA256_BLOCK_SIZE);
  53715. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53716. #endif
  53717. #ifndef NO_MD5
  53718. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53719. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "MD5"), 1);
  53720. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53721. WC_MD5_DIGEST_SIZE);
  53722. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53723. WC_MD5_BLOCK_SIZE);
  53724. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_MD5_DIGEST_SIZE);
  53725. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_MD5_BLOCK_SIZE);
  53726. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53727. #endif
  53728. #ifdef WOLFSSL_SHA224
  53729. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53730. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA224"), 1);
  53731. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53732. WC_SHA224_DIGEST_SIZE);
  53733. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53734. WC_SHA224_BLOCK_SIZE);
  53735. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA224_DIGEST_SIZE);
  53736. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA224_BLOCK_SIZE);
  53737. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53738. #endif
  53739. #ifdef WOLFSSL_SHA384
  53740. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53741. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA384"), 1);
  53742. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53743. WC_SHA384_DIGEST_SIZE);
  53744. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53745. WC_SHA384_BLOCK_SIZE);
  53746. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA384_DIGEST_SIZE);
  53747. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA384_BLOCK_SIZE);
  53748. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53749. #endif
  53750. #ifdef WOLFSSL_SHA512
  53751. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53752. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA512"), 1);
  53753. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53754. WC_SHA512_DIGEST_SIZE);
  53755. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53756. WC_SHA512_BLOCK_SIZE);
  53757. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA512_DIGEST_SIZE);
  53758. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA512_BLOCK_SIZE);
  53759. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53760. #endif
  53761. #ifndef NO_SHA
  53762. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53763. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA"), 1);
  53764. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53765. WC_SHA_DIGEST_SIZE);
  53766. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53767. WC_SHA_BLOCK_SIZE);
  53768. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA_DIGEST_SIZE);
  53769. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA_BLOCK_SIZE);
  53770. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53771. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53772. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA1"), 1);
  53773. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53774. WC_SHA_DIGEST_SIZE);
  53775. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53776. WC_SHA_BLOCK_SIZE);
  53777. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA_DIGEST_SIZE);
  53778. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA_BLOCK_SIZE);
  53779. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53780. #endif
  53781. /* error case */
  53782. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53783. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, ""), 0);
  53784. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)), 0);
  53785. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), 0);
  53786. /* Cleanup is valid on uninit'ed struct */
  53787. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53788. #endif /* OPENSSL_EXTRA */
  53789. return EXPECT_RESULT();
  53790. }
  53791. static int test_wolfSSL_EVP_MD_pkey_type(void)
  53792. {
  53793. EXPECT_DECLS;
  53794. #ifdef OPENSSL_EXTRA
  53795. const WOLFSSL_EVP_MD* md;
  53796. #ifndef NO_MD5
  53797. ExpectNotNull(md = EVP_md5());
  53798. ExpectIntEQ(EVP_MD_pkey_type(md), NID_md5WithRSAEncryption);
  53799. #endif
  53800. #ifndef NO_SHA
  53801. ExpectNotNull(md = EVP_sha1());
  53802. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha1WithRSAEncryption);
  53803. #endif
  53804. #ifdef WOLFSSL_SHA224
  53805. ExpectNotNull(md = EVP_sha224());
  53806. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha224WithRSAEncryption);
  53807. #endif
  53808. ExpectNotNull(md = EVP_sha256());
  53809. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha256WithRSAEncryption);
  53810. #ifdef WOLFSSL_SHA384
  53811. ExpectNotNull(md = EVP_sha384());
  53812. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha384WithRSAEncryption);
  53813. #endif
  53814. #ifdef WOLFSSL_SHA512
  53815. ExpectNotNull(md = EVP_sha512());
  53816. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha512WithRSAEncryption);
  53817. #endif
  53818. #endif
  53819. return EXPECT_RESULT();
  53820. }
  53821. #ifdef OPENSSL_EXTRA
  53822. static int test_hmac_signing(const WOLFSSL_EVP_MD *type, const byte* testKey,
  53823. size_t testKeySz, const char* testData, size_t testDataSz,
  53824. const byte* testResult, size_t testResultSz)
  53825. {
  53826. EXPECT_DECLS;
  53827. unsigned char check[WC_MAX_DIGEST_SIZE];
  53828. size_t checkSz = -1;
  53829. WOLFSSL_EVP_PKEY* key = NULL;
  53830. WOLFSSL_EVP_MD_CTX mdCtx;
  53831. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,
  53832. testKey, (int)testKeySz));
  53833. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53834. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, type, NULL, key), 1);
  53835. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  53836. (unsigned int)testDataSz), 1);
  53837. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53838. ExpectIntEQ((int)checkSz, (int)testResultSz);
  53839. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53840. ExpectIntEQ((int)checkSz,(int)testResultSz);
  53841. ExpectIntEQ(XMEMCMP(testResult, check, testResultSz), 0);
  53842. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53843. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, type, NULL, key), 1);
  53844. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  53845. (unsigned int)testDataSz), 1);
  53846. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, testResult, checkSz), 1);
  53847. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53848. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53849. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, type, NULL, key), 1);
  53850. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  53851. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53852. ExpectIntEQ((int)checkSz, (int)testResultSz);
  53853. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53854. ExpectIntEQ((int)checkSz,(int)testResultSz);
  53855. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  53856. (unsigned int)testDataSz - 4), 1);
  53857. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53858. ExpectIntEQ((int)checkSz,(int)testResultSz);
  53859. ExpectIntEQ(XMEMCMP(testResult, check, testResultSz), 0);
  53860. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53861. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, type, NULL, key), 1);
  53862. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  53863. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  53864. (unsigned int)testDataSz - 4), 1);
  53865. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, testResult, checkSz), 1);
  53866. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53867. wolfSSL_EVP_PKEY_free(key);
  53868. return EXPECT_RESULT();
  53869. }
  53870. #endif
  53871. static int test_wolfSSL_EVP_MD_hmac_signing(void)
  53872. {
  53873. EXPECT_DECLS;
  53874. #ifdef OPENSSL_EXTRA
  53875. static const unsigned char testKey[] =
  53876. {
  53877. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  53878. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  53879. 0x0b, 0x0b, 0x0b, 0x0b
  53880. };
  53881. static const char testData[] = "Hi There";
  53882. #ifdef WOLFSSL_SHA224
  53883. static const unsigned char testResultSha224[] =
  53884. {
  53885. 0x89, 0x6f, 0xb1, 0x12, 0x8a, 0xbb, 0xdf, 0x19,
  53886. 0x68, 0x32, 0x10, 0x7c, 0xd4, 0x9d, 0xf3, 0x3f,
  53887. 0x47, 0xb4, 0xb1, 0x16, 0x99, 0x12, 0xba, 0x4f,
  53888. 0x53, 0x68, 0x4b, 0x22
  53889. };
  53890. #endif
  53891. #ifndef NO_SHA256
  53892. static const unsigned char testResultSha256[] =
  53893. {
  53894. 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
  53895. 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
  53896. 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
  53897. 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7
  53898. };
  53899. #endif
  53900. #ifdef WOLFSSL_SHA384
  53901. static const unsigned char testResultSha384[] =
  53902. {
  53903. 0xaf, 0xd0, 0x39, 0x44, 0xd8, 0x48, 0x95, 0x62,
  53904. 0x6b, 0x08, 0x25, 0xf4, 0xab, 0x46, 0x90, 0x7f,
  53905. 0x15, 0xf9, 0xda, 0xdb, 0xe4, 0x10, 0x1e, 0xc6,
  53906. 0x82, 0xaa, 0x03, 0x4c, 0x7c, 0xeb, 0xc5, 0x9c,
  53907. 0xfa, 0xea, 0x9e, 0xa9, 0x07, 0x6e, 0xde, 0x7f,
  53908. 0x4a, 0xf1, 0x52, 0xe8, 0xb2, 0xfa, 0x9c, 0xb6
  53909. };
  53910. #endif
  53911. #ifdef WOLFSSL_SHA512
  53912. static const unsigned char testResultSha512[] =
  53913. {
  53914. 0x87, 0xaa, 0x7c, 0xde, 0xa5, 0xef, 0x61, 0x9d,
  53915. 0x4f, 0xf0, 0xb4, 0x24, 0x1a, 0x1d, 0x6c, 0xb0,
  53916. 0x23, 0x79, 0xf4, 0xe2, 0xce, 0x4e, 0xc2, 0x78,
  53917. 0x7a, 0xd0, 0xb3, 0x05, 0x45, 0xe1, 0x7c, 0xde,
  53918. 0xda, 0xa8, 0x33, 0xb7, 0xd6, 0xb8, 0xa7, 0x02,
  53919. 0x03, 0x8b, 0x27, 0x4e, 0xae, 0xa3, 0xf4, 0xe4,
  53920. 0xbe, 0x9d, 0x91, 0x4e, 0xeb, 0x61, 0xf1, 0x70,
  53921. 0x2e, 0x69, 0x6c, 0x20, 0x3a, 0x12, 0x68, 0x54
  53922. };
  53923. #endif
  53924. #ifdef WOLFSSL_SHA3
  53925. #ifndef WOLFSSL_NOSHA3_224
  53926. static const unsigned char testResultSha3_224[] =
  53927. {
  53928. 0x3b, 0x16, 0x54, 0x6b, 0xbc, 0x7b, 0xe2, 0x70,
  53929. 0x6a, 0x03, 0x1d, 0xca, 0xfd, 0x56, 0x37, 0x3d,
  53930. 0x98, 0x84, 0x36, 0x76, 0x41, 0xd8, 0xc5, 0x9a,
  53931. 0xf3, 0xc8, 0x60, 0xf7
  53932. };
  53933. #endif
  53934. #ifndef WOLFSSL_NOSHA3_256
  53935. static const unsigned char testResultSha3_256[] =
  53936. {
  53937. 0xba, 0x85, 0x19, 0x23, 0x10, 0xdf, 0xfa, 0x96,
  53938. 0xe2, 0xa3, 0xa4, 0x0e, 0x69, 0x77, 0x43, 0x51,
  53939. 0x14, 0x0b, 0xb7, 0x18, 0x5e, 0x12, 0x02, 0xcd,
  53940. 0xcc, 0x91, 0x75, 0x89, 0xf9, 0x5e, 0x16, 0xbb
  53941. };
  53942. #endif
  53943. #ifndef WOLFSSL_NOSHA3_384
  53944. static const unsigned char testResultSha3_384[] =
  53945. {
  53946. 0x68, 0xd2, 0xdc, 0xf7, 0xfd, 0x4d, 0xdd, 0x0a,
  53947. 0x22, 0x40, 0xc8, 0xa4, 0x37, 0x30, 0x5f, 0x61,
  53948. 0xfb, 0x73, 0x34, 0xcf, 0xb5, 0xd0, 0x22, 0x6e,
  53949. 0x1b, 0xc2, 0x7d, 0xc1, 0x0a, 0x2e, 0x72, 0x3a,
  53950. 0x20, 0xd3, 0x70, 0xb4, 0x77, 0x43, 0x13, 0x0e,
  53951. 0x26, 0xac, 0x7e, 0x3d, 0x53, 0x28, 0x86, 0xbd
  53952. };
  53953. #endif
  53954. #ifndef WOLFSSL_NOSHA3_512
  53955. static const unsigned char testResultSha3_512[] =
  53956. {
  53957. 0xeb, 0x3f, 0xbd, 0x4b, 0x2e, 0xaa, 0xb8, 0xf5,
  53958. 0xc5, 0x04, 0xbd, 0x3a, 0x41, 0x46, 0x5a, 0xac,
  53959. 0xec, 0x15, 0x77, 0x0a, 0x7c, 0xab, 0xac, 0x53,
  53960. 0x1e, 0x48, 0x2f, 0x86, 0x0b, 0x5e, 0xc7, 0xba,
  53961. 0x47, 0xcc, 0xb2, 0xc6, 0xf2, 0xaf, 0xce, 0x8f,
  53962. 0x88, 0xd2, 0x2b, 0x6d, 0xc6, 0x13, 0x80, 0xf2,
  53963. 0x3a, 0x66, 0x8f, 0xd3, 0x88, 0x8b, 0xb8, 0x05,
  53964. 0x37, 0xc0, 0xa0, 0xb8, 0x64, 0x07, 0x68, 0x9e
  53965. };
  53966. #endif
  53967. #endif
  53968. #ifndef NO_SHA256
  53969. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha256(), testKey,
  53970. sizeof(testKey), testData, XSTRLEN(testData), testResultSha256,
  53971. sizeof(testResultSha256)), TEST_SUCCESS);
  53972. #endif
  53973. #ifdef WOLFSSL_SHA224
  53974. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha224(), testKey,
  53975. sizeof(testKey), testData, XSTRLEN(testData), testResultSha224,
  53976. sizeof(testResultSha224)), TEST_SUCCESS);
  53977. #endif
  53978. #ifdef WOLFSSL_SHA384
  53979. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha384(), testKey,
  53980. sizeof(testKey), testData, XSTRLEN(testData), testResultSha384,
  53981. sizeof(testResultSha384)), TEST_SUCCESS);
  53982. #endif
  53983. #ifdef WOLFSSL_SHA512
  53984. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha512(), testKey,
  53985. sizeof(testKey), testData, XSTRLEN(testData), testResultSha512,
  53986. sizeof(testResultSha512)), TEST_SUCCESS);
  53987. #endif
  53988. #ifdef WOLFSSL_SHA3
  53989. #ifndef WOLFSSL_NOSHA3_224
  53990. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_224(), testKey,
  53991. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_224,
  53992. sizeof(testResultSha3_224)), TEST_SUCCESS);
  53993. #endif
  53994. #ifndef WOLFSSL_NOSHA3_256
  53995. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_256(), testKey,
  53996. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_256,
  53997. sizeof(testResultSha3_256)), TEST_SUCCESS);
  53998. #endif
  53999. #ifndef WOLFSSL_NOSHA3_384
  54000. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_384(), testKey,
  54001. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_384,
  54002. sizeof(testResultSha3_384)), TEST_SUCCESS);
  54003. #endif
  54004. #ifndef WOLFSSL_NOSHA3_512
  54005. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_512(), testKey,
  54006. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_512,
  54007. sizeof(testResultSha3_512)), TEST_SUCCESS);
  54008. #endif
  54009. #endif
  54010. #endif /* OPENSSL_EXTRA */
  54011. return EXPECT_RESULT();
  54012. }
  54013. static int test_wolfSSL_EVP_MD_rsa_signing(void)
  54014. {
  54015. EXPECT_DECLS;
  54016. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  54017. WOLFSSL_EVP_PKEY* privKey = NULL;
  54018. WOLFSSL_EVP_PKEY* pubKey = NULL;
  54019. WOLFSSL_EVP_PKEY_CTX* keyCtx = NULL;
  54020. const char testData[] = "Hi There";
  54021. WOLFSSL_EVP_MD_CTX mdCtx;
  54022. WOLFSSL_EVP_MD_CTX mdCtxCopy;
  54023. int ret;
  54024. size_t checkSz = -1;
  54025. int sz = 2048 / 8;
  54026. const unsigned char* cp;
  54027. const unsigned char* p;
  54028. unsigned char check[2048/8];
  54029. size_t i;
  54030. int paddings[] = {
  54031. RSA_PKCS1_PADDING,
  54032. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && defined(WC_RSA_PSS)
  54033. RSA_PKCS1_PSS_PADDING,
  54034. #endif
  54035. };
  54036. cp = client_key_der_2048;
  54037. ExpectNotNull((privKey = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &cp,
  54038. sizeof_client_key_der_2048)));
  54039. p = client_keypub_der_2048;
  54040. ExpectNotNull((pubKey = wolfSSL_d2i_PUBKEY(NULL, &p,
  54041. sizeof_client_keypub_der_2048)));
  54042. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54043. wolfSSL_EVP_MD_CTX_init(&mdCtxCopy);
  54044. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  54045. NULL, privKey), 1);
  54046. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  54047. (unsigned int)XSTRLEN(testData)), 1);
  54048. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  54049. ExpectIntEQ((int)checkSz, sz);
  54050. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  54051. ExpectIntEQ((int)checkSz,sz);
  54052. ExpectIntEQ(wolfSSL_EVP_MD_CTX_copy_ex(&mdCtxCopy, &mdCtx), 1);
  54053. ExpectIntEQ(wolfSSL_EVP_MD_CTX_copy_ex(&mdCtxCopy, &mdCtx), 1);
  54054. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtxCopy);
  54055. ExpectIntEQ(ret, 1);
  54056. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54057. ExpectIntEQ(ret, 1);
  54058. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54059. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  54060. NULL, pubKey), 1);
  54061. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  54062. (unsigned int)XSTRLEN(testData)),
  54063. 1);
  54064. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  54065. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54066. ExpectIntEQ(ret, 1);
  54067. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54068. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  54069. NULL, privKey), 1);
  54070. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  54071. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  54072. ExpectIntEQ((int)checkSz, sz);
  54073. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  54074. ExpectIntEQ((int)checkSz, sz);
  54075. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  54076. (unsigned int)XSTRLEN(testData) - 4), 1);
  54077. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  54078. ExpectIntEQ((int)checkSz, sz);
  54079. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54080. ExpectIntEQ(ret, 1);
  54081. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54082. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  54083. NULL, pubKey), 1);
  54084. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  54085. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  54086. (unsigned int)XSTRLEN(testData) - 4),
  54087. 1);
  54088. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  54089. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54090. ExpectIntEQ(ret, 1);
  54091. /* Check all signing padding types */
  54092. for (i = 0; i < sizeof(paddings)/sizeof(int); i++) {
  54093. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54094. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, &keyCtx,
  54095. wolfSSL_EVP_sha256(), NULL, privKey), 1);
  54096. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_padding(keyCtx,
  54097. paddings[i]), 1);
  54098. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  54099. (unsigned int)XSTRLEN(testData)), 1);
  54100. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  54101. ExpectIntEQ((int)checkSz, sz);
  54102. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  54103. ExpectIntEQ((int)checkSz,sz);
  54104. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54105. ExpectIntEQ(ret, 1);
  54106. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54107. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, &keyCtx,
  54108. wolfSSL_EVP_sha256(), NULL, pubKey), 1);
  54109. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_padding(keyCtx,
  54110. paddings[i]), 1);
  54111. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  54112. (unsigned int)XSTRLEN(testData)), 1);
  54113. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  54114. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54115. ExpectIntEQ(ret, 1);
  54116. }
  54117. wolfSSL_EVP_PKEY_free(pubKey);
  54118. wolfSSL_EVP_PKEY_free(privKey);
  54119. #endif
  54120. return EXPECT_RESULT();
  54121. }
  54122. static int test_wolfSSL_EVP_MD_ecc_signing(void)
  54123. {
  54124. EXPECT_DECLS;
  54125. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  54126. WOLFSSL_EVP_PKEY* privKey = NULL;
  54127. WOLFSSL_EVP_PKEY* pubKey = NULL;
  54128. const char testData[] = "Hi There";
  54129. WOLFSSL_EVP_MD_CTX mdCtx;
  54130. int ret;
  54131. size_t checkSz = -1;
  54132. const unsigned char* cp;
  54133. const unsigned char* p;
  54134. unsigned char check[2048/8];
  54135. cp = ecc_clikey_der_256;
  54136. ExpectNotNull(privKey = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL, &cp,
  54137. sizeof_ecc_clikey_der_256));
  54138. p = ecc_clikeypub_der_256;
  54139. ExpectNotNull((pubKey = wolfSSL_d2i_PUBKEY(NULL, &p,
  54140. sizeof_ecc_clikeypub_der_256)));
  54141. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54142. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  54143. NULL, privKey), 1);
  54144. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  54145. (unsigned int)XSTRLEN(testData)), 1);
  54146. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  54147. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  54148. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54149. ExpectIntEQ(ret, 1);
  54150. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54151. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  54152. NULL, pubKey), 1);
  54153. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  54154. (unsigned int)XSTRLEN(testData)),
  54155. 1);
  54156. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  54157. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54158. ExpectIntEQ(ret, 1);
  54159. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54160. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  54161. NULL, privKey), 1);
  54162. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  54163. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  54164. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  54165. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  54166. (unsigned int)XSTRLEN(testData) - 4), 1);
  54167. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  54168. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54169. ExpectIntEQ(ret, 1);
  54170. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54171. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  54172. NULL, pubKey), 1);
  54173. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  54174. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  54175. (unsigned int)XSTRLEN(testData) - 4),
  54176. 1);
  54177. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  54178. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54179. ExpectIntEQ(ret, 1);
  54180. wolfSSL_EVP_PKEY_free(pubKey);
  54181. wolfSSL_EVP_PKEY_free(privKey);
  54182. #endif
  54183. return EXPECT_RESULT();
  54184. }
  54185. static int test_wolfSSL_CTX_add_extra_chain_cert(void)
  54186. {
  54187. EXPECT_DECLS;
  54188. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54189. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_BIO)
  54190. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  54191. char caFile[] = "./certs/client-ca.pem";
  54192. char clientFile[] = "./certs/client-cert.pem";
  54193. SSL_CTX* ctx = NULL;
  54194. X509* x509 = NULL;
  54195. BIO *bio = NULL;
  54196. X509 *cert = NULL;
  54197. X509 *ca = NULL;
  54198. STACK_OF(X509) *chain = NULL;
  54199. STACK_OF(X509) *chain2 = NULL;
  54200. #ifndef NO_WOLFSSL_SERVER
  54201. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  54202. #else
  54203. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54204. #endif
  54205. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caFile,
  54206. WOLFSSL_FILETYPE_PEM));
  54207. /* Negative tests. */
  54208. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54209. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54210. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(NULL, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54211. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WOLFSSL_SUCCESS);
  54212. ExpectNotNull(x509 = wolfSSL_X509_new());
  54213. /* Empty certificate. */
  54214. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54215. wolfSSL_X509_free(x509);
  54216. x509 = NULL;
  54217. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(clientFile,
  54218. WOLFSSL_FILETYPE_PEM));
  54219. /* additional test of getting EVP_PKEY key size from X509
  54220. * Do not run with user RSA because wolfSSL_RSA_size is not currently
  54221. * allowed with user RSA */
  54222. {
  54223. EVP_PKEY* pkey = NULL;
  54224. #if defined(HAVE_ECC)
  54225. X509* ecX509 = NULL;
  54226. #endif /* HAVE_ECC */
  54227. ExpectNotNull(pkey = X509_get_pubkey(x509));
  54228. /* current RSA key is 2048 bit (256 bytes) */
  54229. ExpectIntEQ(EVP_PKEY_size(pkey), 256);
  54230. EVP_PKEY_free(pkey);
  54231. pkey = NULL;
  54232. #if defined(HAVE_ECC)
  54233. #if defined(USE_CERT_BUFFERS_256)
  54234. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_buffer(
  54235. cliecc_cert_der_256, sizeof_cliecc_cert_der_256,
  54236. SSL_FILETYPE_ASN1));
  54237. #else
  54238. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_file(
  54239. cliEccCertFile, SSL_FILETYPE_PEM));
  54240. #endif
  54241. pkey = X509_get_pubkey(ecX509);
  54242. ExpectNotNull(pkey);
  54243. /* current ECC key is 256 bit (32 bytes) */
  54244. ExpectIntEQ(EVP_PKEY_size(pkey), 32);
  54245. X509_free(ecX509);
  54246. ecX509 = NULL;
  54247. EVP_PKEY_free(pkey);
  54248. pkey = NULL;
  54249. #endif /* HAVE_ECC */
  54250. }
  54251. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), SSL_SUCCESS);
  54252. if (EXPECT_SUCCESS()) {
  54253. x509 = NULL;
  54254. }
  54255. #ifdef WOLFSSL_ENCRYPTED_KEYS
  54256. ExpectNull(SSL_CTX_get_default_passwd_cb(ctx));
  54257. ExpectNull(SSL_CTX_get_default_passwd_cb_userdata(ctx));
  54258. #endif
  54259. SSL_CTX_free(ctx);
  54260. ctx = NULL;
  54261. #ifndef NO_WOLFSSL_SERVER
  54262. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  54263. #else
  54264. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54265. #endif
  54266. /* Test haproxy use case */
  54267. ExpectNotNull(bio = BIO_new_file(svrCertFile, "r"));
  54268. /* Read Certificate */
  54269. ExpectNotNull(cert = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  54270. ExpectNotNull(ca = PEM_read_bio_X509(bio, NULL, NULL, NULL));
  54271. ExpectNotNull(chain = sk_X509_new_null());
  54272. ExpectIntEQ(sk_X509_push(chain, ca), 1);
  54273. if (EXPECT_SUCCESS()) {
  54274. ca = NULL;
  54275. }
  54276. ExpectNotNull(chain2 = X509_chain_up_ref(chain));
  54277. ExpectNotNull(ca = sk_X509_shift(chain2));
  54278. ExpectIntEQ(SSL_CTX_use_certificate(ctx, cert), 1);
  54279. ExpectIntEQ(SSL_CTX_add_extra_chain_cert(ctx, ca), 1);
  54280. if (EXPECT_SUCCESS()) {
  54281. ca = NULL;
  54282. }
  54283. BIO_free(bio);
  54284. X509_free(cert);
  54285. X509_free(ca);
  54286. X509_free(x509);
  54287. sk_X509_pop_free(chain, X509_free);
  54288. sk_X509_pop_free(chain2, X509_free);
  54289. SSL_CTX_free(ctx);
  54290. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  54291. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54292. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined (NO_BIO) */
  54293. return EXPECT_RESULT();
  54294. }
  54295. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  54296. static int test_wolfSSL_ERR_peek_last_error_line(void)
  54297. {
  54298. EXPECT_DECLS;
  54299. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54300. !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL) && \
  54301. !defined(NO_OLD_TLS) && !defined(WOLFSSL_NO_TLS12) && \
  54302. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(NO_ERROR_QUEUE)
  54303. callback_functions client_cb;
  54304. callback_functions server_cb;
  54305. int line = 0;
  54306. int flag = ERR_TXT_STRING;
  54307. const char* file = NULL;
  54308. const char* data = NULL;
  54309. /* create a failed connection and inspect the error */
  54310. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  54311. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  54312. client_cb.method = wolfTLSv1_1_client_method;
  54313. server_cb.method = wolfTLSv1_2_server_method;
  54314. test_wolfSSL_client_server_nofail(&client_cb, &server_cb);
  54315. ExpectIntGT(ERR_get_error_line_data(NULL, NULL, &data, &flag), 0);
  54316. ExpectNotNull(data);
  54317. /* check clearing error state */
  54318. ERR_remove_state(0);
  54319. ExpectIntEQ((int)ERR_peek_last_error_line(NULL, NULL), 0);
  54320. ERR_peek_last_error_line(NULL, &line);
  54321. ExpectIntEQ(line, 0);
  54322. ERR_peek_last_error_line(&file, NULL);
  54323. ExpectNull(file);
  54324. /* retry connection to fill error queue */
  54325. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  54326. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  54327. client_cb.method = wolfTLSv1_1_client_method;
  54328. server_cb.method = wolfTLSv1_2_server_method;
  54329. test_wolfSSL_client_server_nofail(&client_cb, &server_cb);
  54330. /* check that error code was stored */
  54331. ExpectIntNE((int)ERR_peek_last_error_line(NULL, NULL), 0);
  54332. ERR_peek_last_error_line(NULL, &line);
  54333. ExpectIntNE(line, 0);
  54334. ERR_peek_last_error_line(&file, NULL);
  54335. ExpectNotNull(file);
  54336. fprintf(stderr, "\nTesting error print out\n");
  54337. ERR_print_errors_fp(stderr);
  54338. fprintf(stderr, "Done testing print out\n\n");
  54339. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  54340. * !defined(NO_FILESYSTEM) && !defined(DEBUG_WOLFSSL) */
  54341. return EXPECT_RESULT();
  54342. }
  54343. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  54344. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54345. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  54346. static int verify_cb(int ok, X509_STORE_CTX *ctx)
  54347. {
  54348. (void) ok;
  54349. (void) ctx;
  54350. fprintf(stderr, "ENTER verify_cb\n");
  54351. return SSL_SUCCESS;
  54352. }
  54353. #endif
  54354. static int test_wolfSSL_X509_Name_canon(void)
  54355. {
  54356. EXPECT_DECLS;
  54357. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  54358. !defined(NO_FILESYSTEM) && !defined(NO_SHA) && \
  54359. defined(WOLFSSL_CERT_GEN) && \
  54360. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && !defined(NO_RSA)
  54361. const long ex_hash1 = 0x0fdb2da4;
  54362. const long ex_hash2 = 0x9f3e8c9e;
  54363. X509_NAME *name = NULL;
  54364. X509 *x509 = NULL;
  54365. XFILE file = XBADFILE;
  54366. unsigned long hash = 0;
  54367. byte digest[WC_MAX_DIGEST_SIZE] = {0};
  54368. byte *pbuf = NULL;
  54369. word32 len = 0;
  54370. (void) ex_hash2;
  54371. ExpectTrue((file = XFOPEN(caCertFile, "rb")) != XBADFILE);
  54372. ExpectNotNull(x509 = PEM_read_X509(file, NULL, NULL, NULL));
  54373. ExpectNotNull(name = X509_get_issuer_name(x509));
  54374. /* When output buffer is NULL, should return necessary output buffer
  54375. * length.*/
  54376. ExpectIntGT(wolfSSL_i2d_X509_NAME_canon(name, NULL), 0);
  54377. ExpectIntGT((len = (word32)wolfSSL_i2d_X509_NAME_canon(name, &pbuf)), 0);
  54378. ExpectIntEQ(wc_ShaHash((const byte*)pbuf, (word32)len, digest), 0);
  54379. hash = (((unsigned long)digest[3] << 24) |
  54380. ((unsigned long)digest[2] << 16) |
  54381. ((unsigned long)digest[1] << 8) |
  54382. ((unsigned long)digest[0]));
  54383. ExpectIntEQ(hash, ex_hash1);
  54384. if (file != XBADFILE) {
  54385. XFCLOSE(file);
  54386. file = XBADFILE;
  54387. }
  54388. X509_free(x509);
  54389. x509 = NULL;
  54390. XFREE(pbuf, NULL, DYNAMIC_TYPE_OPENSSL);
  54391. pbuf = NULL;
  54392. ExpectTrue((file = XFOPEN(cliCertFile, "rb")) != XBADFILE);
  54393. ExpectNotNull(x509 = PEM_read_X509(file, NULL, NULL, NULL));
  54394. ExpectNotNull(name = X509_get_issuer_name(x509));
  54395. ExpectIntGT((len = (word32)wolfSSL_i2d_X509_NAME_canon(name, &pbuf)), 0);
  54396. ExpectIntEQ(wc_ShaHash((const byte*)pbuf, (word32)len, digest), 0);
  54397. hash = (((unsigned long)digest[3] << 24) |
  54398. ((unsigned long)digest[2] << 16) |
  54399. ((unsigned long)digest[1] << 8) |
  54400. ((unsigned long)digest[0]));
  54401. ExpectIntEQ(hash, ex_hash2);
  54402. if (file != XBADFILE)
  54403. XFCLOSE(file);
  54404. X509_free(x509);
  54405. XFREE(pbuf, NULL, DYNAMIC_TYPE_OPENSSL);
  54406. #endif
  54407. return EXPECT_RESULT();
  54408. }
  54409. static int test_wolfSSL_X509_LOOKUP_ctrl_hash_dir(void)
  54410. {
  54411. EXPECT_DECLS;
  54412. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR)
  54413. const int MAX_DIR = 4;
  54414. const char paths[][32] = {
  54415. "./certs/ed25519",
  54416. "./certs/ecc",
  54417. "./certs/crl",
  54418. "./certs/",
  54419. };
  54420. char CertCrl_path[MAX_FILENAME_SZ];
  54421. char *p;
  54422. X509_STORE* str = NULL;
  54423. X509_LOOKUP* lookup = NULL;
  54424. WOLFSSL_STACK* sk = NULL;
  54425. int len, total_len, i;
  54426. (void)sk;
  54427. XMEMSET(CertCrl_path, 0, MAX_FILENAME_SZ);
  54428. /* illegal string */
  54429. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  54430. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  54431. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, "",
  54432. SSL_FILETYPE_PEM,NULL), 0);
  54433. /* free store */
  54434. X509_STORE_free(str);
  54435. str = NULL;
  54436. /* short folder string */
  54437. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  54438. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  54439. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, "./",
  54440. SSL_FILETYPE_PEM,NULL), 1);
  54441. #if defined(WOLFSSL_INT_H)
  54442. /* only available when including internal.h */
  54443. ExpectNotNull(sk = lookup->dirs->dir_entry);
  54444. #endif
  54445. /* free store */
  54446. X509_STORE_free(str);
  54447. str = NULL;
  54448. /* typical function check */
  54449. p = &CertCrl_path[0];
  54450. total_len = 0;
  54451. for (i = MAX_DIR - 1; i>=0 && total_len < MAX_FILENAME_SZ; i--) {
  54452. len = (int)XSTRLEN((const char*)&paths[i]);
  54453. total_len += len;
  54454. XSTRNCPY(p, paths[i], MAX_FILENAME_SZ - total_len);
  54455. p += len;
  54456. if (i != 0) *(p++) = SEPARATOR_CHAR;
  54457. }
  54458. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  54459. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  54460. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, CertCrl_path,
  54461. SSL_FILETYPE_PEM,NULL), 1);
  54462. #if defined(WOLFSSL_INT_H)
  54463. /* only available when including internal.h */
  54464. ExpectNotNull(sk = lookup->dirs->dir_entry);
  54465. #endif
  54466. X509_STORE_free(str);
  54467. #endif
  54468. return EXPECT_RESULT();
  54469. }
  54470. static int test_wolfSSL_X509_LOOKUP_ctrl_file(void)
  54471. {
  54472. EXPECT_DECLS;
  54473. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  54474. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  54475. defined(WOLFSSL_SIGNER_DER_CERT)
  54476. X509_STORE_CTX* ctx = NULL;
  54477. X509_STORE* str = NULL;
  54478. X509_LOOKUP* lookup = NULL;
  54479. X509* cert1 = NULL;
  54480. X509* x509Ca = NULL;
  54481. X509* x509Svr = NULL;
  54482. X509* issuer = NULL;
  54483. WOLFSSL_STACK* sk = NULL;
  54484. X509_NAME* caName = NULL;
  54485. X509_NAME* issuerName = NULL;
  54486. XFILE file1 = XBADFILE;
  54487. int i;
  54488. int cert_count = 0;
  54489. int cmp;
  54490. char der[] = "certs/ca-cert.der";
  54491. #ifdef HAVE_CRL
  54492. char pem[][100] = {
  54493. "./certs/crl/crl.pem",
  54494. "./certs/crl/crl2.pem",
  54495. "./certs/crl/caEccCrl.pem",
  54496. "./certs/crl/eccCliCRL.pem",
  54497. "./certs/crl/eccSrvCRL.pem",
  54498. ""
  54499. };
  54500. #endif
  54501. ExpectTrue((file1 = XFOPEN("./certs/ca-cert.pem", "rb")) != XBADFILE);
  54502. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  54503. if (file1 != XBADFILE)
  54504. XFCLOSE(file1);
  54505. ExpectNotNull(ctx = X509_STORE_CTX_new());
  54506. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  54507. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  54508. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, caCertFile,
  54509. SSL_FILETYPE_PEM,NULL), 1);
  54510. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(str->cm));
  54511. ExpectIntEQ((cert_count = sk_X509_num(sk)), 1);
  54512. /* check if CA cert is loaded into the store */
  54513. for (i = 0; i < cert_count; i++) {
  54514. x509Ca = sk_X509_value(sk, i);
  54515. ExpectIntEQ(0, wolfSSL_X509_cmp(x509Ca, cert1));
  54516. }
  54517. ExpectNotNull((x509Svr =
  54518. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  54519. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509Svr, NULL), SSL_SUCCESS);
  54520. ExpectNull(X509_STORE_CTX_get0_current_issuer(NULL));
  54521. issuer = X509_STORE_CTX_get0_current_issuer(ctx);
  54522. ExpectNotNull(issuer);
  54523. caName = X509_get_subject_name(x509Ca);
  54524. ExpectNotNull(caName);
  54525. issuerName = X509_get_subject_name(issuer);
  54526. ExpectNotNull(issuerName);
  54527. cmp = X509_NAME_cmp(caName, issuerName);
  54528. ExpectIntEQ(cmp, 0);
  54529. /* load der format */
  54530. X509_free(issuer);
  54531. issuer = NULL;
  54532. X509_STORE_CTX_free(ctx);
  54533. ctx = NULL;
  54534. X509_STORE_free(str);
  54535. str = NULL;
  54536. sk_X509_pop_free(sk, NULL);
  54537. sk = NULL;
  54538. X509_free(x509Svr);
  54539. x509Svr = NULL;
  54540. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  54541. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  54542. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, der,
  54543. SSL_FILETYPE_ASN1,NULL), 1);
  54544. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(str->cm));
  54545. ExpectIntEQ((cert_count = sk_X509_num(sk)), 1);
  54546. /* check if CA cert is loaded into the store */
  54547. for (i = 0; i < cert_count; i++) {
  54548. x509Ca = sk_X509_value(sk, i);
  54549. ExpectIntEQ(0, wolfSSL_X509_cmp(x509Ca, cert1));
  54550. }
  54551. X509_STORE_free(str);
  54552. str = NULL;
  54553. sk_X509_pop_free(sk, NULL);
  54554. sk = NULL;
  54555. X509_free(cert1);
  54556. cert1 = NULL;
  54557. #ifdef HAVE_CRL
  54558. ExpectNotNull(str = wolfSSL_X509_STORE_new());
  54559. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  54560. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, caCertFile,
  54561. SSL_FILETYPE_PEM,NULL), 1);
  54562. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD,
  54563. "certs/server-revoked-cert.pem",
  54564. SSL_FILETYPE_PEM,NULL), 1);
  54565. if (str) {
  54566. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm, svrCertFile,
  54567. WOLFSSL_FILETYPE_PEM), 1);
  54568. /* since store hasn't yet known the revoked cert*/
  54569. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm,
  54570. "certs/server-revoked-cert.pem",
  54571. WOLFSSL_FILETYPE_PEM), 1);
  54572. }
  54573. for (i = 0; pem[i][0] != '\0'; i++)
  54574. {
  54575. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, pem[i],
  54576. SSL_FILETYPE_PEM, NULL), 1);
  54577. }
  54578. if (str) {
  54579. /* since store knows crl list */
  54580. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm,
  54581. "certs/server-revoked-cert.pem",
  54582. WOLFSSL_FILETYPE_PEM ), WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  54583. }
  54584. ExpectIntEQ(X509_LOOKUP_ctrl(NULL, 0, NULL, 0, NULL), 0);
  54585. X509_STORE_free(str);
  54586. #endif
  54587. #endif
  54588. return EXPECT_RESULT();
  54589. }
  54590. static int test_wolfSSL_X509_STORE_CTX_trusted_stack_cleanup(void)
  54591. {
  54592. int res = TEST_SKIPPED;
  54593. #if defined(OPENSSL_EXTRA)
  54594. X509_STORE_CTX_cleanup(NULL);
  54595. X509_STORE_CTX_trusted_stack(NULL, NULL);
  54596. res = TEST_SUCCESS;
  54597. #endif
  54598. return res;
  54599. }
  54600. static int test_wolfSSL_X509_STORE_CTX_get0_current_issuer(void)
  54601. {
  54602. EXPECT_DECLS;
  54603. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  54604. X509_STORE_CTX* ctx = NULL;
  54605. X509_STORE* str = NULL;
  54606. X509* x509Ca = NULL;
  54607. X509* x509Svr = NULL;
  54608. X509* issuer = NULL;
  54609. X509_NAME* caName = NULL;
  54610. X509_NAME* issuerName = NULL;
  54611. ExpectNotNull(ctx = X509_STORE_CTX_new());
  54612. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  54613. ExpectNotNull((x509Ca =
  54614. wolfSSL_X509_load_certificate_file(caCertFile, SSL_FILETYPE_PEM)));
  54615. ExpectIntEQ(X509_STORE_add_cert(str, x509Ca), SSL_SUCCESS);
  54616. ExpectNotNull((x509Svr =
  54617. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  54618. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509Svr, NULL), SSL_SUCCESS);
  54619. ExpectNull(X509_STORE_CTX_get0_current_issuer(NULL));
  54620. ExpectNotNull(issuer = X509_STORE_CTX_get0_current_issuer(ctx));
  54621. ExpectNotNull(caName = X509_get_subject_name(x509Ca));
  54622. ExpectNotNull(issuerName = X509_get_subject_name(issuer));
  54623. #ifdef WOLFSSL_SIGNER_DER_CERT
  54624. ExpectIntEQ(X509_NAME_cmp(caName, issuerName), 0);
  54625. #endif
  54626. X509_free(issuer);
  54627. X509_STORE_CTX_free(ctx);
  54628. X509_free(x509Svr);
  54629. X509_STORE_free(str);
  54630. X509_free(x509Ca);
  54631. #endif
  54632. return EXPECT_RESULT();
  54633. }
  54634. static int test_wolfSSL_PKCS7_certs(void)
  54635. {
  54636. EXPECT_DECLS;
  54637. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && !defined(NO_BIO) && \
  54638. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(HAVE_PKCS7)
  54639. STACK_OF(X509)* sk = NULL;
  54640. STACK_OF(X509_INFO)* info_sk = NULL;
  54641. PKCS7 *p7 = NULL;
  54642. BIO* bio = NULL;
  54643. const byte* p = NULL;
  54644. int buflen = 0;
  54645. int i;
  54646. /* Test twice. Once with d2i and once without to test
  54647. * that everything is free'd correctly. */
  54648. for (i = 0; i < 2; i++) {
  54649. ExpectNotNull(p7 = PKCS7_new());
  54650. if (p7 != NULL) {
  54651. p7->version = 1;
  54652. #ifdef NO_SHA
  54653. p7->hashOID = SHA256h;
  54654. #else
  54655. p7->hashOID = SHAh;
  54656. #endif
  54657. }
  54658. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  54659. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  54660. ExpectNotNull(info_sk = PEM_X509_INFO_read_bio(bio, NULL, NULL, NULL));
  54661. ExpectIntEQ(sk_X509_INFO_num(info_sk), 2);
  54662. ExpectNotNull(sk = sk_X509_new_null());
  54663. while (EXPECT_SUCCESS() && (sk_X509_INFO_num(info_sk) > 0)) {
  54664. X509_INFO* info = NULL;
  54665. ExpectNotNull(info = sk_X509_INFO_shift(info_sk));
  54666. ExpectIntGT(sk_X509_push(sk, info->x509), 0);
  54667. if (EXPECT_SUCCESS() && (info != NULL)) {
  54668. info->x509 = NULL;
  54669. }
  54670. X509_INFO_free(info);
  54671. }
  54672. sk_X509_INFO_pop_free(info_sk, X509_INFO_free);
  54673. info_sk = NULL;
  54674. BIO_free(bio);
  54675. bio = NULL;
  54676. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  54677. ExpectIntEQ(wolfSSL_PKCS7_encode_certs(p7, sk, bio), 1);
  54678. if ((sk != NULL) && ((p7 == NULL) || (bio == NULL))) {
  54679. sk_X509_pop_free(sk, X509_free);
  54680. }
  54681. sk = NULL;
  54682. ExpectIntGT((buflen = BIO_get_mem_data(bio, &p)), 0);
  54683. if (i == 0) {
  54684. PKCS7_free(p7);
  54685. p7 = NULL;
  54686. ExpectNotNull(d2i_PKCS7(&p7, &p, buflen));
  54687. if (p7 != NULL) {
  54688. /* Reset certs to force wolfSSL_PKCS7_to_stack to regenerate
  54689. * them */
  54690. ((WOLFSSL_PKCS7*)p7)->certs = NULL;
  54691. }
  54692. /* PKCS7_free free's the certs */
  54693. ExpectNotNull(wolfSSL_PKCS7_to_stack(p7));
  54694. }
  54695. BIO_free(bio);
  54696. bio = NULL;
  54697. PKCS7_free(p7);
  54698. p7 = NULL;
  54699. }
  54700. #endif /* defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  54701. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(HAVE_PKCS7) */
  54702. return EXPECT_RESULT();
  54703. }
  54704. static int test_wolfSSL_X509_STORE_CTX(void)
  54705. {
  54706. EXPECT_DECLS;
  54707. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54708. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  54709. X509_STORE_CTX* ctx = NULL;
  54710. X509_STORE* str = NULL;
  54711. X509* x509 = NULL;
  54712. #ifdef OPENSSL_ALL
  54713. X509* x5092 = NULL;
  54714. STACK_OF(X509) *sk = NULL;
  54715. STACK_OF(X509) *sk2 = NULL;
  54716. STACK_OF(X509) *sk3 = NULL;
  54717. #endif
  54718. ExpectNotNull(ctx = X509_STORE_CTX_new());
  54719. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  54720. ExpectNotNull((x509 =
  54721. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  54722. ExpectIntEQ(X509_STORE_add_cert(str, x509), SSL_SUCCESS);
  54723. #ifdef OPENSSL_ALL
  54724. /* sk_X509_new only in OPENSSL_ALL */
  54725. sk = sk_X509_new_null();
  54726. ExpectNotNull(sk);
  54727. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509, sk), SSL_SUCCESS);
  54728. #else
  54729. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509, NULL), SSL_SUCCESS);
  54730. #endif
  54731. ExpectIntEQ(SSL_get_ex_data_X509_STORE_CTX_idx(), 0);
  54732. X509_STORE_CTX_set_error(ctx, -5);
  54733. X509_STORE_CTX_set_error(NULL, -5);
  54734. X509_STORE_CTX_free(ctx);
  54735. ctx = NULL;
  54736. #ifdef OPENSSL_ALL
  54737. sk_X509_pop_free(sk, NULL);
  54738. sk = NULL;
  54739. #endif
  54740. X509_STORE_free(str);
  54741. str = NULL;
  54742. X509_free(x509);
  54743. x509 = NULL;
  54744. ExpectNotNull(ctx = X509_STORE_CTX_new());
  54745. X509_STORE_CTX_set_verify_cb(ctx, verify_cb);
  54746. X509_STORE_CTX_free(ctx);
  54747. ctx = NULL;
  54748. #ifdef OPENSSL_ALL
  54749. /* test X509_STORE_CTX_get(1)_chain */
  54750. ExpectNotNull((x509 = X509_load_certificate_file(svrCertFile,
  54751. SSL_FILETYPE_PEM)));
  54752. ExpectNotNull((x5092 = X509_load_certificate_file(cliCertFile,
  54753. SSL_FILETYPE_PEM)));
  54754. ExpectNotNull((sk = sk_X509_new_null()));
  54755. ExpectIntEQ(sk_X509_push(sk, x509), 1);
  54756. if (EXPECT_FAIL()) {
  54757. X509_free(x509);
  54758. x509 = NULL;
  54759. }
  54760. ExpectNotNull((str = X509_STORE_new()));
  54761. ExpectNotNull((ctx = X509_STORE_CTX_new()));
  54762. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x5092, sk), 1);
  54763. ExpectNull((sk2 = X509_STORE_CTX_get_chain(NULL)));
  54764. ExpectNotNull((sk2 = X509_STORE_CTX_get_chain(ctx)));
  54765. ExpectIntEQ(sk_num(sk2), 1); /* sanity, make sure chain has 1 cert */
  54766. ExpectNull((sk3 = X509_STORE_CTX_get1_chain(NULL)));
  54767. ExpectNotNull((sk3 = X509_STORE_CTX_get1_chain(ctx)));
  54768. ExpectIntEQ(sk_num(sk3), 1); /* sanity, make sure chain has 1 cert */
  54769. X509_STORE_CTX_free(ctx);
  54770. ctx = NULL;
  54771. X509_STORE_free(str);
  54772. str = NULL;
  54773. /* CTX certs not freed yet */
  54774. X509_free(x5092);
  54775. x5092 = NULL;
  54776. sk_X509_pop_free(sk, NULL);
  54777. sk = NULL;
  54778. /* sk3 is dup so free here */
  54779. sk_X509_pop_free(sk3, NULL);
  54780. sk3 = NULL;
  54781. #endif
  54782. /* test X509_STORE_CTX_get/set_ex_data */
  54783. {
  54784. int i = 0, tmpData = 5;
  54785. void* tmpDataRet;
  54786. ExpectNotNull(ctx = X509_STORE_CTX_new());
  54787. #ifdef HAVE_EX_DATA
  54788. for (i = 0; i < MAX_EX_DATA; i++) {
  54789. ExpectIntEQ(X509_STORE_CTX_set_ex_data(ctx, i, &tmpData),
  54790. WOLFSSL_SUCCESS);
  54791. tmpDataRet = (int*)X509_STORE_CTX_get_ex_data(ctx, i);
  54792. ExpectNotNull(tmpDataRet);
  54793. ExpectIntEQ(tmpData, *(int*)tmpDataRet);
  54794. }
  54795. #else
  54796. ExpectIntEQ(X509_STORE_CTX_set_ex_data(ctx, i, &tmpData),
  54797. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54798. tmpDataRet = (int*)X509_STORE_CTX_get_ex_data(ctx, i);
  54799. ExpectNull(tmpDataRet);
  54800. #endif
  54801. X509_STORE_CTX_free(ctx);
  54802. ctx = NULL;
  54803. }
  54804. /* test X509_STORE_get/set_ex_data */
  54805. {
  54806. int i = 0, tmpData = 99;
  54807. void* tmpDataRet;
  54808. ExpectNotNull(str = X509_STORE_new());
  54809. #ifdef HAVE_EX_DATA
  54810. for (i = 0; i < MAX_EX_DATA; i++) {
  54811. ExpectIntEQ(X509_STORE_set_ex_data(str, i, &tmpData),
  54812. WOLFSSL_SUCCESS);
  54813. tmpDataRet = (int*)X509_STORE_get_ex_data(str, i);
  54814. ExpectNotNull(tmpDataRet);
  54815. ExpectIntEQ(tmpData, *(int*)tmpDataRet);
  54816. }
  54817. #else
  54818. ExpectIntEQ(X509_STORE_set_ex_data(str, i, &tmpData),
  54819. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54820. tmpDataRet = (int*)X509_STORE_get_ex_data(str, i);
  54821. ExpectNull(tmpDataRet);
  54822. #endif
  54823. X509_STORE_free(str);
  54824. str = NULL;
  54825. }
  54826. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54827. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  54828. return EXPECT_RESULT();
  54829. }
  54830. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  54831. static int test_X509_STORE_untrusted_load_cert_to_stack(const char* filename,
  54832. STACK_OF(X509)* chain)
  54833. {
  54834. EXPECT_DECLS;
  54835. XFILE fp = XBADFILE;
  54836. X509* cert = NULL;
  54837. ExpectTrue((fp = XFOPEN(filename, "rb"))
  54838. != XBADFILE);
  54839. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  54840. if (fp != XBADFILE) {
  54841. XFCLOSE(fp);
  54842. fp = XBADFILE;
  54843. }
  54844. ExpectIntGT(sk_X509_push(chain, cert), 0);
  54845. if (EXPECT_FAIL())
  54846. X509_free(cert);
  54847. return EXPECT_RESULT();
  54848. }
  54849. static int test_X509_STORE_untrusted_certs(const char** filenames, int ret,
  54850. int err, int loadCA)
  54851. {
  54852. EXPECT_DECLS;
  54853. X509_STORE_CTX* ctx = NULL;
  54854. X509_STORE* str = NULL;
  54855. XFILE fp = XBADFILE;
  54856. X509* cert = NULL;
  54857. STACK_OF(X509)* untrusted = NULL;
  54858. ExpectTrue((fp = XFOPEN("./certs/intermediate/server-int-cert.pem", "rb"))
  54859. != XBADFILE);
  54860. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  54861. if (fp != XBADFILE) {
  54862. XFCLOSE(fp);
  54863. fp = XBADFILE;
  54864. }
  54865. ExpectNotNull(str = X509_STORE_new());
  54866. ExpectNotNull(ctx = X509_STORE_CTX_new());
  54867. ExpectNotNull(untrusted = sk_X509_new_null());
  54868. ExpectIntEQ(X509_STORE_set_flags(str, 0), 1);
  54869. if (loadCA) {
  54870. ExpectIntEQ(X509_STORE_load_locations(str, "./certs/ca-cert.pem", NULL),
  54871. 1);
  54872. }
  54873. for (; *filenames; filenames++) {
  54874. ExpectIntEQ(test_X509_STORE_untrusted_load_cert_to_stack(*filenames,
  54875. untrusted), TEST_SUCCESS);
  54876. }
  54877. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, cert, untrusted), 1);
  54878. ExpectIntEQ(X509_verify_cert(ctx), ret);
  54879. ExpectIntEQ(X509_STORE_CTX_get_error(ctx), err);
  54880. X509_free(cert);
  54881. X509_STORE_free(str);
  54882. X509_STORE_CTX_free(ctx);
  54883. sk_X509_pop_free(untrusted, NULL);
  54884. return EXPECT_RESULT();
  54885. }
  54886. #endif
  54887. static int test_X509_STORE_untrusted(void)
  54888. {
  54889. EXPECT_DECLS;
  54890. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  54891. const char* untrusted1[] = {
  54892. "./certs/intermediate/ca-int2-cert.pem",
  54893. NULL
  54894. };
  54895. const char* untrusted2[] = {
  54896. "./certs/intermediate/ca-int-cert.pem",
  54897. "./certs/intermediate/ca-int2-cert.pem",
  54898. NULL
  54899. };
  54900. const char* untrusted3[] = {
  54901. "./certs/intermediate/ca-int-cert.pem",
  54902. "./certs/intermediate/ca-int2-cert.pem",
  54903. "./certs/ca-cert.pem",
  54904. NULL
  54905. };
  54906. /* Adding unrelated certs that should be ignored */
  54907. const char* untrusted4[] = {
  54908. "./certs/client-ca.pem",
  54909. "./certs/intermediate/ca-int-cert.pem",
  54910. "./certs/server-cert.pem",
  54911. "./certs/intermediate/ca-int2-cert.pem",
  54912. NULL
  54913. };
  54914. /* Only immediate issuer in untrusted chain. Fails since can't build chain
  54915. * to loaded CA. */
  54916. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted1, 0,
  54917. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, 1), TEST_SUCCESS);
  54918. /* Succeeds because path to loaded CA is available. */
  54919. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted2, 1, 0, 1),
  54920. TEST_SUCCESS);
  54921. /* Fails because root CA is in the untrusted stack */
  54922. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted3, 0,
  54923. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, 0), TEST_SUCCESS);
  54924. /* Succeeds because path to loaded CA is available. */
  54925. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted4, 1, 0, 1),
  54926. TEST_SUCCESS);
  54927. #endif
  54928. return EXPECT_RESULT();
  54929. }
  54930. static int test_wolfSSL_X509_STORE_set_flags(void)
  54931. {
  54932. EXPECT_DECLS;
  54933. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54934. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  54935. X509_STORE* store = NULL;
  54936. X509* x509 = NULL;
  54937. ExpectNotNull((store = wolfSSL_X509_STORE_new()));
  54938. ExpectNotNull((x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  54939. WOLFSSL_FILETYPE_PEM)));
  54940. ExpectIntEQ(X509_STORE_add_cert(store, x509), WOLFSSL_SUCCESS);
  54941. #ifdef HAVE_CRL
  54942. ExpectIntEQ(X509_STORE_set_flags(store, WOLFSSL_CRL_CHECKALL),
  54943. WOLFSSL_SUCCESS);
  54944. #else
  54945. ExpectIntEQ(X509_STORE_set_flags(store, WOLFSSL_CRL_CHECKALL),
  54946. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  54947. #endif
  54948. wolfSSL_X509_free(x509);
  54949. wolfSSL_X509_STORE_free(store);
  54950. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  54951. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  54952. return EXPECT_RESULT();
  54953. }
  54954. static int test_wolfSSL_X509_LOOKUP_load_file(void)
  54955. {
  54956. EXPECT_DECLS;
  54957. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && \
  54958. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  54959. (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH))
  54960. WOLFSSL_X509_STORE* store = NULL;
  54961. WOLFSSL_X509_LOOKUP* lookup = NULL;
  54962. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  54963. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  54964. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/client-ca.pem",
  54965. X509_FILETYPE_PEM), 1);
  54966. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/crl/crl2.pem",
  54967. X509_FILETYPE_PEM), 1);
  54968. if (store != NULL) {
  54969. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, cliCertFile,
  54970. WOLFSSL_FILETYPE_PEM), 1);
  54971. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  54972. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  54973. }
  54974. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  54975. X509_FILETYPE_PEM), 1);
  54976. if (store != NULL) {
  54977. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  54978. WOLFSSL_FILETYPE_PEM), 1);
  54979. }
  54980. wolfSSL_X509_STORE_free(store);
  54981. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_CRL) &&
  54982. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  54983. return EXPECT_RESULT();
  54984. }
  54985. static int test_wolfSSL_X509_STORE_CTX_set_time(void)
  54986. {
  54987. EXPECT_DECLS;
  54988. #if defined(OPENSSL_EXTRA)
  54989. WOLFSSL_X509_STORE_CTX* ctx = NULL;
  54990. time_t c_time;
  54991. ExpectNotNull(ctx = wolfSSL_X509_STORE_CTX_new());
  54992. c_time = 365*24*60*60;
  54993. wolfSSL_X509_STORE_CTX_set_time(ctx, 0, c_time);
  54994. ExpectTrue((ctx->param->flags & WOLFSSL_USE_CHECK_TIME) ==
  54995. WOLFSSL_USE_CHECK_TIME);
  54996. ExpectTrue(ctx->param->check_time == c_time);
  54997. wolfSSL_X509_STORE_CTX_free(ctx);
  54998. #endif /* OPENSSL_EXTRA */
  54999. return EXPECT_RESULT();
  55000. }
  55001. static int test_wolfSSL_CTX_get0_set1_param(void)
  55002. {
  55003. EXPECT_DECLS;
  55004. #if defined(OPENSSL_EXTRA)
  55005. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  55006. SSL_CTX* ctx = NULL;
  55007. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  55008. WOLFSSL_X509_VERIFY_PARAM* pvpm = NULL;
  55009. char testIPv4[] = "127.0.0.1";
  55010. char testhostName[] = "foo.hoge.com";
  55011. #ifndef NO_WOLFSSL_SERVER
  55012. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  55013. #else
  55014. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  55015. #endif
  55016. ExpectNull(SSL_CTX_get0_param(NULL));
  55017. ExpectNotNull(pParam = SSL_CTX_get0_param(ctx));
  55018. ExpectNotNull(pvpm = (WOLFSSL_X509_VERIFY_PARAM *)XMALLOC(
  55019. sizeof(WOLFSSL_X509_VERIFY_PARAM), NULL, DYNAMIC_TYPE_OPENSSL));
  55020. ExpectNotNull(XMEMSET(pvpm, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM)));
  55021. ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(pvpm, testhostName,
  55022. (int)XSTRLEN(testhostName)), WOLFSSL_SUCCESS);
  55023. ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_ip_asc(pvpm, testIPv4),
  55024. WOLFSSL_SUCCESS);
  55025. wolfSSL_X509_VERIFY_PARAM_set_hostflags(pvpm, 0x01);
  55026. ExpectIntEQ(SSL_CTX_set1_param(ctx, pvpm), 1);
  55027. ExpectIntEQ(0, XSTRNCMP(pParam->hostName, testhostName,
  55028. (int)XSTRLEN(testhostName)));
  55029. ExpectIntEQ(0x01, pParam->hostFlags);
  55030. ExpectIntEQ(0, XSTRNCMP(pParam->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  55031. /* test for incorrect parameter */
  55032. ExpectIntEQ(1,SSL_CTX_set1_param(ctx, NULL));
  55033. ExpectIntEQ(1,SSL_CTX_set1_param(NULL, pvpm));
  55034. ExpectIntEQ(1,SSL_CTX_set1_param(NULL, NULL));
  55035. SSL_CTX_free(ctx);
  55036. XFREE(pvpm, NULL, DYNAMIC_TYPE_OPENSSL);
  55037. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  55038. #endif /* OPENSSL_EXTRA && !defined(NO_RSA)*/
  55039. return EXPECT_RESULT();
  55040. }
  55041. static int test_wolfSSL_get0_param(void)
  55042. {
  55043. EXPECT_DECLS;
  55044. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  55045. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  55046. SSL_CTX* ctx = NULL;
  55047. SSL* ssl = NULL;
  55048. #ifndef NO_WOLFSSL_SERVER
  55049. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  55050. #else
  55051. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  55052. #endif
  55053. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  55054. SSL_FILETYPE_PEM));
  55055. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  55056. ExpectNotNull(ssl = SSL_new(ctx));
  55057. ExpectNotNull(SSL_get0_param(ssl));
  55058. SSL_free(ssl);
  55059. SSL_CTX_free(ctx);
  55060. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  55061. #endif /* OPENSSL_EXTRA && !defined(NO_RSA)*/
  55062. return EXPECT_RESULT();
  55063. }
  55064. static int test_wolfSSL_X509_VERIFY_PARAM_set1_host(void)
  55065. {
  55066. EXPECT_DECLS;
  55067. #if defined(OPENSSL_EXTRA)
  55068. const char host[] = "www.example.com";
  55069. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  55070. ExpectNotNull(pParam = (WOLFSSL_X509_VERIFY_PARAM*)XMALLOC(
  55071. sizeof(WOLFSSL_X509_VERIFY_PARAM), HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  55072. if (pParam != NULL) {
  55073. XMEMSET(pParam, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM));
  55074. X509_VERIFY_PARAM_set1_host(pParam, host, sizeof(host));
  55075. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  55076. XMEMSET(pParam, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM));
  55077. ExpectIntNE(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  55078. XFREE(pParam, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  55079. }
  55080. #endif /* OPENSSL_EXTRA */
  55081. return EXPECT_RESULT();
  55082. }
  55083. static int test_wolfSSL_set1_host(void)
  55084. {
  55085. EXPECT_DECLS;
  55086. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  55087. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  55088. const char host[] = "www.test_wolfSSL_set1_host.com";
  55089. const char emptyStr[] = "";
  55090. SSL_CTX* ctx = NULL;
  55091. SSL* ssl = NULL;
  55092. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  55093. #ifndef NO_WOLFSSL_SERVER
  55094. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  55095. #else
  55096. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  55097. #endif
  55098. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  55099. SSL_FILETYPE_PEM));
  55100. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  55101. ExpectNotNull(ssl = SSL_new(ctx));
  55102. pParam = SSL_get0_param(ssl);
  55103. /* we should get back host string */
  55104. ExpectIntEQ(SSL_set1_host(ssl, host), WOLFSSL_SUCCESS);
  55105. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  55106. /* we should get back empty string */
  55107. ExpectIntEQ(SSL_set1_host(ssl, emptyStr), WOLFSSL_SUCCESS);
  55108. ExpectIntEQ(XMEMCMP(pParam->hostName, emptyStr, sizeof(emptyStr)), 0);
  55109. /* we should get back host string */
  55110. ExpectIntEQ(SSL_set1_host(ssl, host), WOLFSSL_SUCCESS);
  55111. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  55112. /* we should get back empty string */
  55113. ExpectIntEQ(SSL_set1_host(ssl, NULL), WOLFSSL_SUCCESS);
  55114. ExpectIntEQ(XMEMCMP(pParam->hostName, emptyStr, sizeof(emptyStr)), 0);
  55115. SSL_free(ssl);
  55116. SSL_CTX_free(ctx);
  55117. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  55118. #endif /* OPENSSL_EXTRA */
  55119. return EXPECT_RESULT();
  55120. }
  55121. static int test_wolfSSL_X509_VERIFY_PARAM_set1_ip(void)
  55122. {
  55123. EXPECT_DECLS;
  55124. #if defined(OPENSSL_EXTRA)
  55125. unsigned char buf[16] = {0};
  55126. WOLFSSL_X509_VERIFY_PARAM* param = NULL;
  55127. ExpectNotNull(param = X509_VERIFY_PARAM_new());
  55128. /* test 127.0.0.1 */
  55129. buf[0] =0x7f; buf[1] = 0; buf[2] = 0; buf[3] = 1;
  55130. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 4), SSL_SUCCESS);
  55131. ExpectIntEQ(XSTRNCMP(param->ipasc, "127.0.0.1", sizeof(param->ipasc)), 0);
  55132. /* test 2001:db8:3333:4444:5555:6666:7777:8888 */
  55133. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  55134. buf[4]=51;buf[5]=51;buf[6]=68;buf[7]=68;
  55135. buf[8]=85;buf[9]=85;buf[10]=102;buf[11]=102;
  55136. buf[12]=119;buf[13]=119;buf[14]=136;buf[15]=136;
  55137. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  55138. ExpectIntEQ(XSTRNCMP(param->ipasc,
  55139. "2001:db8:3333:4444:5555:6666:7777:8888", sizeof(param->ipasc)), 0);
  55140. /* test 2001:db8:: */
  55141. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  55142. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  55143. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  55144. buf[12]=0;buf[13]=0;buf[14]=0;buf[15]=0;
  55145. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  55146. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8::", sizeof(param->ipasc)), 0);
  55147. /* test ::1234:5678 */
  55148. buf[0]=0;buf[1]=0;buf[2]=0;buf[3]=0;
  55149. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  55150. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  55151. buf[12]=18;buf[13]=52;buf[14]=86;buf[15]=120;
  55152. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  55153. ExpectIntEQ(XSTRNCMP(param->ipasc, "::1234:5678", sizeof(param->ipasc)), 0);
  55154. /* test 2001:db8::1234:5678 */
  55155. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  55156. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  55157. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  55158. buf[12]=18;buf[13]=52;buf[14]=86;buf[15]=120;
  55159. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  55160. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8::1234:5678",
  55161. sizeof(param->ipasc)), 0);
  55162. /* test 2001:0db8:0001:0000:0000:0ab9:c0a8:0102*/
  55163. /* 2001:db8:1::ab9:c0a8:102 */
  55164. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  55165. buf[4]=0;buf[5]=1;buf[6]=0;buf[7]=0;
  55166. buf[8]=0;buf[9]=0;buf[10]=10;buf[11]=185;
  55167. buf[12]=192;buf[13]=168;buf[14]=1;buf[15]=2;
  55168. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  55169. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8:1::ab9:c0a8:102",
  55170. sizeof(param->ipasc)), 0);
  55171. XFREE(param, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  55172. #endif /* OPENSSL_EXTRA */
  55173. return EXPECT_RESULT();
  55174. }
  55175. static int test_wolfSSL_X509_STORE_CTX_get0_store(void)
  55176. {
  55177. EXPECT_DECLS;
  55178. #if defined(OPENSSL_EXTRA)
  55179. X509_STORE* store = NULL;
  55180. X509_STORE_CTX* ctx = NULL;
  55181. X509_STORE_CTX* ctx_no_init = NULL;
  55182. ExpectNotNull((store = X509_STORE_new()));
  55183. ExpectNotNull(ctx = X509_STORE_CTX_new());
  55184. ExpectNotNull(ctx_no_init = X509_STORE_CTX_new());
  55185. ExpectIntEQ(X509_STORE_CTX_init(ctx, store, NULL, NULL), SSL_SUCCESS);
  55186. ExpectNull(X509_STORE_CTX_get0_store(NULL));
  55187. /* should return NULL if ctx has not bee initialized */
  55188. ExpectNull(X509_STORE_CTX_get0_store(ctx_no_init));
  55189. ExpectNotNull(X509_STORE_CTX_get0_store(ctx));
  55190. wolfSSL_X509_STORE_CTX_free(ctx);
  55191. wolfSSL_X509_STORE_CTX_free(ctx_no_init);
  55192. X509_STORE_free(store);
  55193. #endif /* OPENSSL_EXTRA */
  55194. return EXPECT_RESULT();
  55195. }
  55196. static int test_wolfSSL_CTX_set_client_CA_list(void)
  55197. {
  55198. EXPECT_DECLS;
  55199. #if defined(OPENSSL_ALL) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  55200. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_BIO)
  55201. WOLFSSL_CTX* ctx = NULL;
  55202. WOLFSSL* ssl = NULL;
  55203. X509_NAME* name = NULL;
  55204. STACK_OF(X509_NAME)* names = NULL;
  55205. STACK_OF(X509_NAME)* ca_list = NULL;
  55206. int names_len = 0;
  55207. int i;
  55208. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  55209. /* Send two X501 names in cert request */
  55210. names = SSL_load_client_CA_file(cliCertFile);
  55211. ExpectNotNull(names);
  55212. ca_list = SSL_load_client_CA_file(caCertFile);
  55213. ExpectNotNull(ca_list);
  55214. ExpectNotNull(name = sk_X509_NAME_value(ca_list, 0));
  55215. ExpectIntEQ(sk_X509_NAME_push(names, name), 2);
  55216. if (EXPECT_FAIL()) {
  55217. wolfSSL_X509_NAME_free(name);
  55218. name = NULL;
  55219. }
  55220. SSL_CTX_set_client_CA_list(ctx, names);
  55221. /* This should only free the stack structure */
  55222. sk_X509_NAME_free(ca_list);
  55223. ca_list = NULL;
  55224. ExpectNotNull(ca_list = SSL_CTX_get_client_CA_list(ctx));
  55225. ExpectIntEQ(sk_X509_NAME_num(ca_list), sk_X509_NAME_num(names));
  55226. ExpectIntGT((names_len = sk_X509_NAME_num(names)), 0);
  55227. for (i = 0; i < names_len; i++) {
  55228. ExpectNotNull(name = sk_X509_NAME_value(names, i));
  55229. ExpectIntEQ(sk_X509_NAME_find(names, name), i);
  55230. }
  55231. /* Needed to be able to create ssl object */
  55232. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  55233. SSL_FILETYPE_PEM));
  55234. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  55235. ExpectNotNull(ssl = wolfSSL_new(ctx));
  55236. /* load again as old names are responsibility of ctx to free*/
  55237. names = SSL_load_client_CA_file(cliCertFile);
  55238. ExpectNotNull(names);
  55239. SSL_set_client_CA_list(ssl, names);
  55240. ExpectNotNull(ca_list = SSL_get_client_CA_list(ssl));
  55241. ExpectIntEQ(sk_X509_NAME_num(ca_list), sk_X509_NAME_num(names));
  55242. ExpectIntGT((names_len = sk_X509_NAME_num(names)), 0);
  55243. for (i = 0; i < names_len; i++) {
  55244. ExpectNotNull(name = sk_X509_NAME_value(names, i));
  55245. ExpectIntEQ(sk_X509_NAME_find(names, name), i);
  55246. }
  55247. #if !defined(SINGLE_THREADED) && defined(SESSION_CERTS)
  55248. {
  55249. tcp_ready ready;
  55250. func_args server_args;
  55251. callback_functions server_cb;
  55252. THREAD_TYPE serverThread;
  55253. WOLFSSL* ssl_client = NULL;
  55254. WOLFSSL_CTX* ctx_client = NULL;
  55255. SOCKET_T sockfd = 0;
  55256. /* wolfSSL_get_client_CA_list() with handshake */
  55257. StartTCP();
  55258. InitTcpReady(&ready);
  55259. XMEMSET(&server_args, 0, sizeof(func_args));
  55260. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  55261. server_args.signal = &ready;
  55262. server_args.callbacks = &server_cb;
  55263. /* we are responsible for free'ing WOLFSSL_CTX */
  55264. server_cb.ctx = ctx;
  55265. server_cb.isSharedCtx = 1;
  55266. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  55267. cliCertFile, 0));
  55268. start_thread(test_server_nofail, &server_args, &serverThread);
  55269. wait_tcp_ready(&server_args);
  55270. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  55271. ExpectNotNull(ctx_client =
  55272. wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  55273. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(
  55274. ctx_client, caCertFile, 0));
  55275. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(
  55276. ctx_client, cliCertFile, SSL_FILETYPE_PEM));
  55277. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(
  55278. ctx_client, cliKeyFile, SSL_FILETYPE_PEM));
  55279. ExpectNotNull(ssl_client = wolfSSL_new(ctx_client));
  55280. ExpectIntEQ(wolfSSL_set_fd(ssl_client, sockfd), WOLFSSL_SUCCESS);
  55281. ExpectIntEQ(wolfSSL_connect(ssl_client), WOLFSSL_SUCCESS);
  55282. ExpectNotNull(ca_list = SSL_get_client_CA_list(ssl_client));
  55283. /* We are expecting two cert names to be sent */
  55284. ExpectIntEQ(sk_X509_NAME_num(ca_list), 2);
  55285. ExpectNotNull(names = SSL_CTX_get_client_CA_list(ctx));
  55286. for (i=0; i<sk_X509_NAME_num(ca_list); i++) {
  55287. ExpectNotNull(name = sk_X509_NAME_value(ca_list, i));
  55288. ExpectIntGE(sk_X509_NAME_find(names, name), 0);
  55289. }
  55290. wolfSSL_shutdown(ssl_client);
  55291. wolfSSL_free(ssl_client);
  55292. wolfSSL_CTX_free(ctx_client);
  55293. CloseSocket(sockfd);
  55294. join_thread(serverThread);
  55295. FreeTcpReady(&ready);
  55296. }
  55297. #endif
  55298. wolfSSL_free(ssl);
  55299. wolfSSL_CTX_free(ctx);
  55300. #endif /* OPENSSL_EXTRA && !NO_RSA && !NO_CERTS && !NO_WOLFSSL_CLIENT &&
  55301. * !NO_BIO */
  55302. return EXPECT_RESULT();
  55303. }
  55304. static int test_wolfSSL_CTX_add_client_CA(void)
  55305. {
  55306. EXPECT_DECLS;
  55307. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  55308. !defined(NO_WOLFSSL_CLIENT)
  55309. WOLFSSL_CTX* ctx = NULL;
  55310. WOLFSSL_X509* x509 = NULL;
  55311. WOLFSSL_X509* x509_a = NULL;
  55312. STACK_OF(X509_NAME)* ca_list = NULL;
  55313. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  55314. /* Add client cert */
  55315. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  55316. SSL_FILETYPE_PEM));
  55317. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, x509), SSL_SUCCESS);
  55318. ExpectNotNull(ca_list = SSL_CTX_get_client_CA_list(ctx));
  55319. /* Add another client cert */
  55320. ExpectNotNull(x509_a = X509_load_certificate_file(cliCertFile,
  55321. SSL_FILETYPE_PEM));
  55322. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, x509_a), SSL_SUCCESS);
  55323. /* test for incorrect parameter */
  55324. ExpectIntEQ(SSL_CTX_add_client_CA(NULL, x509), 0);
  55325. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, NULL), 0);
  55326. ExpectIntEQ(SSL_CTX_add_client_CA(NULL, NULL), 0);
  55327. X509_free(x509);
  55328. X509_free(x509_a);
  55329. SSL_CTX_free(ctx);
  55330. #endif /* OPENSSL_EXTRA && !NO_RSA && !NO_CERTS && !NO_WOLFSSL_CLIENT */
  55331. return EXPECT_RESULT();
  55332. }
  55333. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  55334. defined(HAVE_IO_TESTS_DEPENDENCIES)
  55335. static THREAD_RETURN WOLFSSL_THREAD server_task_ech(void* args)
  55336. {
  55337. callback_functions* callbacks = ((func_args*)args)->callbacks;
  55338. WOLFSSL_CTX* ctx = callbacks->ctx;
  55339. WOLFSSL* ssl = NULL;
  55340. SOCKET_T sfd = 0;
  55341. SOCKET_T cfd = 0;
  55342. word16 port;
  55343. char input[1024];
  55344. int idx;
  55345. int ret, err = 0;
  55346. const char* privateName = "ech-private-name.com";
  55347. int privateNameLen = (int)XSTRLEN(privateName);
  55348. ((func_args*)args)->return_code = TEST_FAIL;
  55349. port = ((func_args*)args)->signal->port;
  55350. AssertIntEQ(WOLFSSL_SUCCESS,
  55351. wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0));
  55352. AssertIntEQ(WOLFSSL_SUCCESS,
  55353. wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  55354. WOLFSSL_FILETYPE_PEM));
  55355. AssertIntEQ(WOLFSSL_SUCCESS,
  55356. wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  55357. WOLFSSL_FILETYPE_PEM));
  55358. if (callbacks->ctx_ready)
  55359. callbacks->ctx_ready(ctx);
  55360. ssl = wolfSSL_new(ctx);
  55361. /* set the sni for the server */
  55362. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, privateName, privateNameLen);
  55363. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, NULL, NULL);
  55364. CloseSocket(sfd);
  55365. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, cfd));
  55366. if (callbacks->ssl_ready)
  55367. callbacks->ssl_ready(ssl);
  55368. do {
  55369. err = 0; /* Reset error */
  55370. ret = wolfSSL_accept(ssl);
  55371. if (ret != WOLFSSL_SUCCESS) {
  55372. err = wolfSSL_get_error(ssl, 0);
  55373. }
  55374. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  55375. if (ret != WOLFSSL_SUCCESS) {
  55376. char buff[WOLFSSL_MAX_ERROR_SZ];
  55377. fprintf(stderr, "error = %d, %s\n", err, wolfSSL_ERR_error_string(err, buff));
  55378. }
  55379. else {
  55380. if (0 < (idx = wolfSSL_read(ssl, input, sizeof(input)-1))) {
  55381. input[idx] = 0;
  55382. fprintf(stderr, "Client message: %s\n", input);
  55383. }
  55384. AssertIntEQ(privateNameLen, wolfSSL_write(ssl, privateName,
  55385. privateNameLen));
  55386. ((func_args*)args)->return_code = TEST_SUCCESS;
  55387. }
  55388. if (callbacks->on_result)
  55389. callbacks->on_result(ssl);
  55390. wolfSSL_shutdown(ssl);
  55391. wolfSSL_free(ssl);
  55392. wolfSSL_CTX_free(ctx);
  55393. CloseSocket(cfd);
  55394. #ifdef FP_ECC
  55395. wc_ecc_fp_free();
  55396. #endif
  55397. WOLFSSL_RETURN_FROM_THREAD(0);
  55398. }
  55399. #endif /* HAVE_ECH && WOLFSSL_TLS13 */
  55400. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  55401. static void keyLog_callback(const WOLFSSL* ssl, const char* line)
  55402. {
  55403. XFILE fp;
  55404. const byte lf = '\n';
  55405. AssertNotNull(ssl);
  55406. AssertNotNull(line);
  55407. fp = XFOPEN("./MyKeyLog.txt", "a");
  55408. XFWRITE(line, 1, XSTRLEN(line), fp);
  55409. XFWRITE((void*)&lf, 1, 1, fp);
  55410. XFFLUSH(fp);
  55411. XFCLOSE(fp);
  55412. }
  55413. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK */
  55414. static int test_wolfSSL_CTX_set_keylog_callback(void)
  55415. {
  55416. EXPECT_DECLS;
  55417. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK) && \
  55418. !defined(NO_WOLFSSL_CLIENT)
  55419. SSL_CTX* ctx = NULL;
  55420. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  55421. SSL_CTX_set_keylog_callback(ctx, keyLog_callback );
  55422. SSL_CTX_free(ctx);
  55423. SSL_CTX_set_keylog_callback(NULL, NULL);
  55424. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && !NO_WOLFSSL_CLIENT */
  55425. return EXPECT_RESULT();
  55426. }
  55427. static int test_wolfSSL_CTX_get_keylog_callback(void)
  55428. {
  55429. EXPECT_DECLS;
  55430. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK) && \
  55431. !defined(NO_WOLFSSL_CLIENT)
  55432. SSL_CTX* ctx = NULL;
  55433. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  55434. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),NULL);
  55435. SSL_CTX_set_keylog_callback(ctx, keyLog_callback );
  55436. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),keyLog_callback);
  55437. SSL_CTX_set_keylog_callback(ctx, NULL );
  55438. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),NULL);
  55439. SSL_CTX_free(ctx);
  55440. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && !NO_WOLFSSL_CLIENT */
  55441. return EXPECT_RESULT();
  55442. }
  55443. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  55444. static int test_wolfSSL_Tls12_Key_Logging_client_ctx_ready(WOLFSSL_CTX* ctx)
  55445. {
  55446. /* set keylog callback */
  55447. wolfSSL_CTX_set_keylog_callback(ctx, keyLog_callback);
  55448. return TEST_SUCCESS;
  55449. }
  55450. #endif
  55451. static int test_wolfSSL_Tls12_Key_Logging_test(void)
  55452. {
  55453. EXPECT_DECLS;
  55454. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  55455. /* This test is intended for checking whether keylog callback is called
  55456. * in client during TLS handshake between the client and a server.
  55457. */
  55458. test_ssl_cbf server_cbf;
  55459. test_ssl_cbf client_cbf;
  55460. XFILE fp = XBADFILE;
  55461. char buff[500];
  55462. int found = 0;
  55463. XMEMSET(&server_cbf, 0, sizeof(test_ssl_cbf));
  55464. XMEMSET(&client_cbf, 0, sizeof(test_ssl_cbf));
  55465. server_cbf.method = wolfTLSv1_2_server_method;
  55466. client_cbf.ctx_ready = &test_wolfSSL_Tls12_Key_Logging_client_ctx_ready;
  55467. /* clean up keylog file */
  55468. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "w")) != XBADFILE);
  55469. if (fp != XBADFILE) {
  55470. XFFLUSH(fp);
  55471. XFCLOSE(fp);
  55472. fp = XBADFILE;
  55473. }
  55474. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  55475. &server_cbf, NULL), TEST_SUCCESS);
  55476. /* check if the keylog file exists */
  55477. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "r")) != XBADFILE);
  55478. XFFLUSH(fp); /* Just to make sure any buffers get flushed */
  55479. XMEMSET(buff, 0, sizeof(buff));
  55480. while (EXPECT_SUCCESS() && XFGETS(buff, (int)sizeof(buff), fp) != NULL) {
  55481. if (0 == strncmp(buff,"CLIENT_RANDOM ", sizeof("CLIENT_RANDOM ")-1)) {
  55482. found = 1;
  55483. break;
  55484. }
  55485. }
  55486. if (fp != XBADFILE) {
  55487. XFCLOSE(fp);
  55488. }
  55489. /* a log starting with "CLIENT_RANDOM " should exit in the file */
  55490. ExpectIntEQ(found, 1);
  55491. /* clean up */
  55492. ExpectIntEQ(rem_file("./MyKeyLog.txt"), 0);
  55493. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK */
  55494. return EXPECT_RESULT();
  55495. }
  55496. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  55497. defined(HAVE_SECRET_CALLBACK)
  55498. static int test_wolfSSL_Tls13_Key_Logging_client_ctx_ready(WOLFSSL_CTX* ctx)
  55499. {
  55500. /* set keylog callback */
  55501. wolfSSL_CTX_set_keylog_callback(ctx, keyLog_callback);
  55502. return TEST_SUCCESS;
  55503. }
  55504. #endif
  55505. static int test_wolfSSL_Tls13_Key_Logging_test(void)
  55506. {
  55507. EXPECT_DECLS;
  55508. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  55509. defined(HAVE_SECRET_CALLBACK)
  55510. /* This test is intended for checking whether keylog callback is called
  55511. * in client during TLS handshake between the client and a server.
  55512. */
  55513. test_ssl_cbf server_cbf;
  55514. test_ssl_cbf client_cbf;
  55515. XFILE fp = XBADFILE;
  55516. XMEMSET(&server_cbf, 0, sizeof(test_ssl_cbf));
  55517. XMEMSET(&client_cbf, 0, sizeof(test_ssl_cbf));
  55518. server_cbf.method = wolfTLSv1_3_server_method; /* TLS1.3 */
  55519. client_cbf.ctx_ready = &test_wolfSSL_Tls13_Key_Logging_client_ctx_ready;
  55520. /* clean up keylog file */
  55521. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "w")) != XBADFILE);
  55522. if (fp != XBADFILE) {
  55523. XFCLOSE(fp);
  55524. fp = XBADFILE;
  55525. }
  55526. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  55527. &server_cbf, NULL), TEST_SUCCESS);
  55528. /* check if the keylog file exists */
  55529. {
  55530. char buff[300] = {0};
  55531. int found[4] = {0};
  55532. int numfnd = 0;
  55533. int i;
  55534. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "r")) != XBADFILE);
  55535. while (EXPECT_SUCCESS() &&
  55536. XFGETS(buff, (int)sizeof(buff), fp) != NULL) {
  55537. if (0 == strncmp(buff, "CLIENT_HANDSHAKE_TRAFFIC_SECRET ",
  55538. sizeof("CLIENT_HANDSHAKE_TRAFFIC_SECRET ")-1)) {
  55539. found[0] = 1;
  55540. continue;
  55541. }
  55542. else if (0 == strncmp(buff, "SERVER_HANDSHAKE_TRAFFIC_SECRET ",
  55543. sizeof("SERVER_HANDSHAKE_TRAFFIC_SECRET ")-1)) {
  55544. found[1] = 1;
  55545. continue;
  55546. }
  55547. else if (0 == strncmp(buff, "CLIENT_TRAFFIC_SECRET_0 ",
  55548. sizeof("CLIENT_TRAFFIC_SECRET_0 ")-1)) {
  55549. found[2] = 1;
  55550. continue;
  55551. }
  55552. else if (0 == strncmp(buff, "SERVER_TRAFFIC_SECRET_0 ",
  55553. sizeof("SERVER_TRAFFIC_SECRET_0 ")-1)) {
  55554. found[3] = 1;
  55555. continue;
  55556. }
  55557. }
  55558. if (fp != XBADFILE)
  55559. XFCLOSE(fp);
  55560. for (i = 0; i < 4; i++) {
  55561. if (found[i] != 0)
  55562. numfnd++;
  55563. }
  55564. ExpectIntEQ(numfnd, 4);
  55565. }
  55566. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && WOLFSSL_TLS13 */
  55567. return EXPECT_RESULT();
  55568. }
  55569. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  55570. defined(HAVE_IO_TESTS_DEPENDENCIES)
  55571. static int test_wolfSSL_Tls13_ECH_params(void)
  55572. {
  55573. EXPECT_DECLS;
  55574. #if !defined(NO_WOLFSSL_CLIENT)
  55575. word32 outputLen = 0;
  55576. byte testBuf[72];
  55577. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method());
  55578. WOLFSSL *ssl = wolfSSL_new(ctx);
  55579. ExpectNotNull(ctx);
  55580. ExpectNotNull(ssl);
  55581. /* invalid ctx */
  55582. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(NULL,
  55583. "ech-public-name.com", 0, 0, 0));
  55584. /* invalid public name */
  55585. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(ctx, NULL, 0,
  55586. 0, 0));
  55587. /* invalid algorithms */
  55588. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(ctx,
  55589. "ech-public-name.com", 1000, 1000, 1000));
  55590. /* invalid ctx */
  55591. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GetEchConfigs(NULL, NULL,
  55592. &outputLen));
  55593. /* invalid output len */
  55594. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GetEchConfigs(ctx, NULL, NULL));
  55595. /* invalid ssl */
  55596. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(NULL,
  55597. (char*)testBuf, sizeof(testBuf)));
  55598. /* invalid configs64 */
  55599. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(ssl, NULL,
  55600. sizeof(testBuf)));
  55601. /* invalid size */
  55602. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(ssl,
  55603. (char*)testBuf, 0));
  55604. /* invalid ssl */
  55605. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(NULL, testBuf,
  55606. sizeof(testBuf)));
  55607. /* invalid configs */
  55608. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, NULL,
  55609. sizeof(testBuf)));
  55610. /* invalid size */
  55611. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, testBuf, 0));
  55612. /* invalid ssl */
  55613. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_GetEchConfigs(NULL, NULL, &outputLen));
  55614. /* invalid size */
  55615. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_GetEchConfigs(ssl, NULL, NULL));
  55616. wolfSSL_free(ssl);
  55617. wolfSSL_CTX_free(ctx);
  55618. #endif /* !NO_WOLFSSL_CLIENT */
  55619. return EXPECT_RESULT();
  55620. }
  55621. static int test_wolfSSL_Tls13_ECH(void)
  55622. {
  55623. EXPECT_DECLS;
  55624. tcp_ready ready;
  55625. func_args client_args;
  55626. func_args server_args;
  55627. THREAD_TYPE serverThread;
  55628. callback_functions server_cbf;
  55629. callback_functions client_cbf;
  55630. SOCKET_T sockfd = 0;
  55631. WOLFSSL_CTX* ctx = NULL;
  55632. WOLFSSL* ssl = NULL;
  55633. const char* publicName = "ech-public-name.com";
  55634. const char* privateName = "ech-private-name.com";
  55635. int privateNameLen = 20;
  55636. char reply[1024];
  55637. int replyLen = 0;
  55638. byte rawEchConfig[128];
  55639. word32 rawEchConfigLen = sizeof(rawEchConfig);
  55640. InitTcpReady(&ready);
  55641. ready.port = 22222;
  55642. XMEMSET(&client_args, 0, sizeof(func_args));
  55643. XMEMSET(&server_args, 0, sizeof(func_args));
  55644. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  55645. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  55646. server_cbf.method = wolfTLSv1_3_server_method; /* TLS1.3 */
  55647. /* create the server context here so we can get the ech config */
  55648. ExpectNotNull(server_cbf.ctx =
  55649. wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  55650. /* generate ech config */
  55651. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(server_cbf.ctx,
  55652. publicName, 0, 0, 0));
  55653. /* get the config for the client to use */
  55654. ExpectIntEQ(WOLFSSL_SUCCESS,
  55655. wolfSSL_CTX_GetEchConfigs(server_cbf.ctx, rawEchConfig,
  55656. &rawEchConfigLen));
  55657. server_args.callbacks = &server_cbf;
  55658. server_args.signal = &ready;
  55659. /* start server task */
  55660. start_thread(server_task_ech, &server_args, &serverThread);
  55661. wait_tcp_ready(&server_args);
  55662. /* run as a TLS1.3 client */
  55663. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  55664. ExpectIntEQ(WOLFSSL_SUCCESS,
  55665. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  55666. ExpectIntEQ(WOLFSSL_SUCCESS,
  55667. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  55668. ExpectIntEQ(WOLFSSL_SUCCESS,
  55669. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  55670. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  55671. /* get connected the server task */
  55672. ExpectNotNull(ssl = wolfSSL_new(ctx));
  55673. /* set the ech configs for the client */
  55674. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, rawEchConfig,
  55675. rawEchConfigLen));
  55676. /* set the sni for the client */
  55677. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME,
  55678. privateName, privateNameLen));
  55679. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  55680. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  55681. ExpectIntEQ(wolfSSL_write(ssl, privateName, privateNameLen),
  55682. privateNameLen);
  55683. ExpectIntGT((replyLen = wolfSSL_read(ssl, reply, sizeof(reply))), 0);
  55684. /* add th null terminator for string compare */
  55685. reply[replyLen] = 0;
  55686. /* check that the server replied with the private name */
  55687. ExpectStrEQ(privateName, reply);
  55688. wolfSSL_free(ssl);
  55689. wolfSSL_CTX_free(ctx);
  55690. CloseSocket(sockfd);
  55691. join_thread(serverThread);
  55692. FreeTcpReady(&ready);
  55693. return EXPECT_RESULT();
  55694. }
  55695. #endif /* HAVE_ECH && WOLFSSL_TLS13 */
  55696. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  55697. defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  55698. defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  55699. static int post_auth_version_cb(WOLFSSL* ssl)
  55700. {
  55701. EXPECT_DECLS;
  55702. /* do handshake and then test version error */
  55703. ExpectIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  55704. ExpectStrEQ("TLSv1.2", wolfSSL_get_version(ssl));
  55705. return EXPECT_RESULT();
  55706. }
  55707. static int post_auth_version_client_cb(WOLFSSL* ssl)
  55708. {
  55709. EXPECT_DECLS;
  55710. /* do handshake and then test version error */
  55711. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  55712. ExpectStrEQ("TLSv1.2", wolfSSL_get_version(ssl));
  55713. ExpectIntEQ(wolfSSL_verify_client_post_handshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55714. #if defined(OPENSSL_ALL) && !defined(NO_ERROR_QUEUE)
  55715. /* check was added to error queue */
  55716. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(UNSUPPORTED_PROTO_VERSION));
  55717. /* check the string matches expected string */
  55718. #ifndef NO_ERROR_STRINGS
  55719. ExpectStrEQ(wolfSSL_ERR_error_string(-WC_NO_ERR_TRACE(UNSUPPORTED_PROTO_VERSION), NULL),
  55720. "WRONG_SSL_VERSION");
  55721. #endif
  55722. #endif
  55723. return EXPECT_RESULT();
  55724. }
  55725. static int post_auth_cb(WOLFSSL* ssl)
  55726. {
  55727. EXPECT_DECLS;
  55728. WOLFSSL_X509* x509 = NULL;
  55729. /* do handshake and then test version error */
  55730. ExpectIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  55731. ExpectStrEQ("TLSv1.3", wolfSSL_get_version(ssl));
  55732. ExpectNull(x509 = wolfSSL_get_peer_certificate(ssl));
  55733. wolfSSL_X509_free(x509);
  55734. ExpectIntEQ(wolfSSL_verify_client_post_handshake(ssl), WOLFSSL_SUCCESS);
  55735. return EXPECT_RESULT();
  55736. }
  55737. static int set_post_auth_cb(WOLFSSL* ssl)
  55738. {
  55739. if (!wolfSSL_is_server(ssl)) {
  55740. EXPECT_DECLS;
  55741. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(ssl), 0);
  55742. return EXPECT_RESULT();
  55743. }
  55744. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_POST_HANDSHAKE, NULL);
  55745. return TEST_SUCCESS;
  55746. }
  55747. #endif
  55748. static int test_wolfSSL_Tls13_postauth(void)
  55749. {
  55750. EXPECT_DECLS;
  55751. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  55752. defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  55753. defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  55754. test_ssl_cbf server_cbf;
  55755. test_ssl_cbf client_cbf;
  55756. /* test version failure doing post auth with TLS 1.2 connection */
  55757. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  55758. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  55759. server_cbf.method = wolfTLSv1_2_server_method;
  55760. server_cbf.ssl_ready = set_post_auth_cb;
  55761. server_cbf.on_result = post_auth_version_cb;
  55762. client_cbf.ssl_ready = set_post_auth_cb;
  55763. client_cbf.on_result = post_auth_version_client_cb;
  55764. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  55765. &server_cbf, NULL), TEST_SUCCESS);
  55766. /* tests on post auth with TLS 1.3 */
  55767. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  55768. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  55769. server_cbf.method = wolfTLSv1_3_server_method;
  55770. server_cbf.ssl_ready = set_post_auth_cb;
  55771. client_cbf.ssl_ready = set_post_auth_cb;
  55772. server_cbf.on_result = post_auth_cb;
  55773. client_cbf.on_result = NULL;
  55774. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  55775. &server_cbf, NULL), TEST_SUCCESS);
  55776. #endif
  55777. return EXPECT_RESULT();
  55778. }
  55779. static int test_wolfSSL_X509_NID(void)
  55780. {
  55781. EXPECT_DECLS;
  55782. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
  55783. !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048) && !defined(NO_ASN)
  55784. int sigType;
  55785. int nameSz;
  55786. X509* cert = NULL;
  55787. EVP_PKEY* pubKeyTmp = NULL;
  55788. X509_NAME* name = NULL;
  55789. char commonName[80];
  55790. char countryName[80];
  55791. char localityName[80];
  55792. char stateName[80];
  55793. char orgName[80];
  55794. char orgUnit[80];
  55795. /* ------ PARSE ORIGINAL SELF-SIGNED CERTIFICATE ------ */
  55796. /* convert cert from DER to internal WOLFSSL_X509 struct */
  55797. ExpectNotNull(cert = wolfSSL_X509_d2i_ex(&cert, client_cert_der_2048,
  55798. sizeof_client_cert_der_2048, HEAP_HINT));
  55799. /* ------ EXTRACT CERTIFICATE ELEMENTS ------ */
  55800. /* extract PUBLIC KEY from cert */
  55801. ExpectNotNull(pubKeyTmp = X509_get_pubkey(cert));
  55802. /* extract signatureType */
  55803. ExpectIntNE((sigType = wolfSSL_X509_get_signature_type(cert)), 0);
  55804. /* extract subjectName info */
  55805. ExpectNotNull(name = X509_get_subject_name(cert));
  55806. ExpectIntEQ(X509_NAME_get_text_by_NID(name, -1, NULL, 0), -1);
  55807. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  55808. NULL, 0)), 0);
  55809. ExpectIntEQ(nameSz, 15);
  55810. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  55811. commonName, sizeof(commonName))), 0);
  55812. ExpectIntEQ(nameSz, 15);
  55813. ExpectIntEQ(XMEMCMP(commonName, "www.wolfssl.com", nameSz), 0);
  55814. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  55815. commonName, 9)), 0);
  55816. ExpectIntEQ(nameSz, 8);
  55817. ExpectIntEQ(XMEMCMP(commonName, "www.wolf", nameSz), 0);
  55818. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_countryName,
  55819. countryName, sizeof(countryName))), 0);
  55820. ExpectIntEQ(XMEMCMP(countryName, "US", nameSz), 0);
  55821. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_localityName,
  55822. localityName, sizeof(localityName))), 0);
  55823. ExpectIntEQ(XMEMCMP(localityName, "Bozeman", nameSz), 0);
  55824. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name,
  55825. NID_stateOrProvinceName, stateName, sizeof(stateName))), 0);
  55826. ExpectIntEQ(XMEMCMP(stateName, "Montana", nameSz), 0);
  55827. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_organizationName,
  55828. orgName, sizeof(orgName))), 0);
  55829. ExpectIntEQ(XMEMCMP(orgName, "wolfSSL_2048", nameSz), 0);
  55830. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name,
  55831. NID_organizationalUnitName, orgUnit, sizeof(orgUnit))), 0);
  55832. ExpectIntEQ(XMEMCMP(orgUnit, "Programming-2048", nameSz), 0);
  55833. EVP_PKEY_free(pubKeyTmp);
  55834. X509_free(cert);
  55835. #endif
  55836. return EXPECT_RESULT();
  55837. }
  55838. static int test_wolfSSL_CTX_set_srp_username(void)
  55839. {
  55840. EXPECT_DECLS;
  55841. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) \
  55842. && !defined(NO_SHA256) && !defined(WC_NO_RNG) && !defined(NO_WOLFSSL_CLIENT)
  55843. WOLFSSL_CTX* ctx = NULL;
  55844. WOLFSSL* ssl = NULL;
  55845. const char *username = "TESTUSER";
  55846. const char *password = "TESTPASSWORD";
  55847. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  55848. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  55849. SSL_SUCCESS);
  55850. wolfSSL_CTX_free(ctx);
  55851. ctx = NULL;
  55852. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  55853. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  55854. SSL_SUCCESS);
  55855. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  55856. SSL_SUCCESS);
  55857. ExpectNotNull(ssl = SSL_new(ctx));
  55858. ExpectNotNull(SSL_get_srp_username(ssl));
  55859. ExpectStrEQ(SSL_get_srp_username(ssl), username);
  55860. wolfSSL_free(ssl);
  55861. wolfSSL_CTX_free(ctx);
  55862. #endif /* OPENSSL_EXTRA && WOLFCRYPT_HAVE_SRP */
  55863. /* && !NO_SHA256 && !WC_NO_RNG && !NO_WOLFSSL_CLIENT */
  55864. return EXPECT_RESULT();
  55865. }
  55866. static int test_wolfSSL_CTX_set_srp_password(void)
  55867. {
  55868. EXPECT_DECLS;
  55869. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) && \
  55870. !defined(NO_SHA256) && !defined(WC_NO_RNG) && !defined(NO_WOLFSSL_CLIENT)
  55871. WOLFSSL_CTX* ctx = NULL;
  55872. const char *username = "TESTUSER";
  55873. const char *password = "TESTPASSWORD";
  55874. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  55875. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  55876. SSL_SUCCESS);
  55877. wolfSSL_CTX_free(ctx);
  55878. ctx = NULL;
  55879. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  55880. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  55881. SSL_SUCCESS);
  55882. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  55883. SSL_SUCCESS);
  55884. wolfSSL_CTX_free(ctx);
  55885. #endif /* OPENSSL_EXTRA && WOLFCRYPT_HAVE_SRP */
  55886. /* && !NO_SHA256 && !WC_NO_RNG && !NO_WOLFSSL_CLIENT */
  55887. return EXPECT_RESULT();
  55888. }
  55889. static int test_wolfSSL_X509_STORE(void)
  55890. {
  55891. EXPECT_DECLS;
  55892. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  55893. X509_STORE *store = NULL;
  55894. #ifdef HAVE_CRL
  55895. X509_STORE_CTX *storeCtx = NULL;
  55896. X509 *ca = NULL;
  55897. X509 *cert = NULL;
  55898. const char srvCert[] = "./certs/server-revoked-cert.pem";
  55899. const char caCert[] = "./certs/ca-cert.pem";
  55900. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  55901. X509_CRL *crl = NULL;
  55902. const char crlPem[] = "./certs/crl/crl.revoked";
  55903. XFILE fp = XBADFILE;
  55904. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  55905. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  55906. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  55907. SSL_FILETYPE_PEM)));
  55908. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  55909. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  55910. SSL_FILETYPE_PEM)));
  55911. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  55912. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  55913. ExpectIntEQ(X509_verify_cert(storeCtx), SSL_SUCCESS);
  55914. X509_STORE_free(store);
  55915. store = NULL;
  55916. X509_STORE_CTX_free(storeCtx);
  55917. storeCtx = NULL;
  55918. X509_free(cert);
  55919. cert = NULL;
  55920. X509_free(ca);
  55921. ca = NULL;
  55922. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  55923. /* should fail to verify now after adding in CRL */
  55924. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  55925. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  55926. SSL_FILETYPE_PEM)));
  55927. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  55928. ExpectTrue((fp = XFOPEN(crlPem, "rb")) != XBADFILE);
  55929. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  55930. NULL, NULL));
  55931. if (fp != XBADFILE)
  55932. XFCLOSE(fp);
  55933. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  55934. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),SSL_SUCCESS);
  55935. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  55936. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  55937. SSL_FILETYPE_PEM)));
  55938. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  55939. ExpectIntNE(X509_verify_cert(storeCtx), SSL_SUCCESS);
  55940. ExpectIntEQ(X509_STORE_CTX_get_error(storeCtx),
  55941. WOLFSSL_X509_V_ERR_CERT_REVOKED);
  55942. X509_CRL_free(crl);
  55943. crl = NULL;
  55944. X509_STORE_free(store);
  55945. store = NULL;
  55946. X509_STORE_CTX_free(storeCtx);
  55947. storeCtx = NULL;
  55948. X509_free(cert);
  55949. cert = NULL;
  55950. X509_free(ca);
  55951. ca = NULL;
  55952. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  55953. #endif /* HAVE_CRL */
  55954. #ifndef WOLFCRYPT_ONLY
  55955. {
  55956. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  55957. SSL_CTX* ctx = NULL;
  55958. SSL* ssl = NULL;
  55959. int i;
  55960. for (i = 0; i < 2; i++) {
  55961. #ifndef NO_WOLFSSL_SERVER
  55962. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  55963. #else
  55964. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  55965. #endif
  55966. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  55967. SSL_CTX_set_cert_store(ctx, store);
  55968. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  55969. SSL_CTX_set_cert_store(ctx, store);
  55970. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  55971. ExpectIntEQ(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  55972. SSL_FILETYPE_PEM), SSL_SUCCESS);
  55973. ExpectIntEQ(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  55974. SSL_FILETYPE_PEM), SSL_SUCCESS);
  55975. ExpectNotNull(ssl = SSL_new(ctx));
  55976. if (i == 0) {
  55977. ExpectIntEQ(SSL_set0_verify_cert_store(ssl, store),
  55978. SSL_SUCCESS);
  55979. }
  55980. else {
  55981. ExpectIntEQ(SSL_set1_verify_cert_store(ssl, store), SSL_SUCCESS);
  55982. #ifdef OPENSSL_ALL
  55983. ExpectIntEQ(SSL_CTX_set1_verify_cert_store(ctx, store), SSL_SUCCESS);
  55984. #endif
  55985. }
  55986. if (EXPECT_FAIL() || (i == 1)) {
  55987. X509_STORE_free(store);
  55988. store = NULL;
  55989. }
  55990. SSL_free(ssl);
  55991. ssl = NULL;
  55992. SSL_CTX_free(ctx);
  55993. ctx = NULL;
  55994. }
  55995. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  55996. }
  55997. #endif
  55998. #endif
  55999. return EXPECT_RESULT();
  56000. }
  56001. static int test_wolfSSL_X509_STORE_load_locations(void)
  56002. {
  56003. EXPECT_DECLS;
  56004. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  56005. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && !defined(NO_RSA)
  56006. SSL_CTX *ctx = NULL;
  56007. X509_STORE *store = NULL;
  56008. const char ca_file[] = "./certs/ca-cert.pem";
  56009. const char client_pem_file[] = "./certs/client-cert.pem";
  56010. const char client_der_file[] = "./certs/client-cert.der";
  56011. const char ecc_file[] = "./certs/ecc-key.pem";
  56012. const char certs_path[] = "./certs/";
  56013. const char bad_path[] = "./bad-path/";
  56014. #ifdef HAVE_CRL
  56015. const char crl_path[] = "./certs/crl/";
  56016. const char crl_file[] = "./certs/crl/crl.pem";
  56017. #endif
  56018. #ifndef NO_WOLFSSL_SERVER
  56019. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  56020. #else
  56021. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  56022. #endif
  56023. ExpectNotNull(store = SSL_CTX_get_cert_store(ctx));
  56024. ExpectIntEQ(wolfSSL_CertManagerLoadCA(store->cm, ca_file, NULL),
  56025. WOLFSSL_SUCCESS);
  56026. /* Test bad arguments */
  56027. ExpectIntEQ(X509_STORE_load_locations(NULL, ca_file, NULL),
  56028. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56029. ExpectIntEQ(X509_STORE_load_locations(store, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56030. ExpectIntEQ(X509_STORE_load_locations(store, client_der_file, NULL),
  56031. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56032. ExpectIntEQ(X509_STORE_load_locations(store, ecc_file, NULL),
  56033. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56034. ExpectIntEQ(X509_STORE_load_locations(store, NULL, bad_path),
  56035. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56036. #ifdef HAVE_CRL
  56037. /* Test with CRL */
  56038. ExpectIntEQ(X509_STORE_load_locations(store, crl_file, NULL),
  56039. WOLFSSL_SUCCESS);
  56040. ExpectIntEQ(X509_STORE_load_locations(store, NULL, crl_path),
  56041. WOLFSSL_SUCCESS);
  56042. #endif
  56043. /* Test with CA */
  56044. ExpectIntEQ(X509_STORE_load_locations(store, ca_file, NULL),
  56045. WOLFSSL_SUCCESS);
  56046. /* Test with client_cert and certs path */
  56047. ExpectIntEQ(X509_STORE_load_locations(store, client_pem_file, NULL),
  56048. WOLFSSL_SUCCESS);
  56049. ExpectIntEQ(X509_STORE_load_locations(store, NULL, certs_path),
  56050. WOLFSSL_SUCCESS);
  56051. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  56052. /* Clear nodes */
  56053. ERR_clear_error();
  56054. #endif
  56055. SSL_CTX_free(ctx);
  56056. #endif
  56057. return EXPECT_RESULT();
  56058. }
  56059. static int test_X509_STORE_get0_objects(void)
  56060. {
  56061. EXPECT_DECLS;
  56062. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && \
  56063. !defined(NO_WOLFSSL_DIR) && !defined(NO_RSA)
  56064. X509_STORE *store = NULL;
  56065. X509_STORE *store_cpy = NULL;
  56066. SSL_CTX *ctx = NULL;
  56067. X509_OBJECT *obj = NULL;
  56068. STACK_OF(X509_OBJECT) *objs = NULL;
  56069. int i;
  56070. /* Setup store */
  56071. #ifndef NO_WOLFSSL_SERVER
  56072. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  56073. #else
  56074. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  56075. #endif
  56076. ExpectNotNull(store_cpy = X509_STORE_new());
  56077. ExpectNotNull(store = SSL_CTX_get_cert_store(ctx));
  56078. ExpectIntEQ(X509_STORE_load_locations(store, cliCertFile, NULL),
  56079. WOLFSSL_SUCCESS);
  56080. ExpectIntEQ(X509_STORE_load_locations(store, caCertFile, NULL),
  56081. WOLFSSL_SUCCESS);
  56082. ExpectIntEQ(X509_STORE_load_locations(store, svrCertFile, NULL),
  56083. WOLFSSL_SUCCESS);
  56084. #ifdef HAVE_CRL
  56085. ExpectIntEQ(X509_STORE_load_locations(store, NULL, crlPemDir),
  56086. WOLFSSL_SUCCESS);
  56087. #endif
  56088. /* Store ready */
  56089. /* Similar to HaProxy ssl_set_cert_crl_file use case */
  56090. ExpectNotNull(objs = X509_STORE_get0_objects(store));
  56091. #ifdef HAVE_CRL
  56092. #ifdef WOLFSSL_SIGNER_DER_CERT
  56093. ExpectIntEQ(sk_X509_OBJECT_num(objs), 4);
  56094. #else
  56095. ExpectIntEQ(sk_X509_OBJECT_num(objs), 1);
  56096. #endif
  56097. #else
  56098. #ifdef WOLFSSL_SIGNER_DER_CERT
  56099. ExpectIntEQ(sk_X509_OBJECT_num(objs), 3);
  56100. #else
  56101. ExpectIntEQ(sk_X509_OBJECT_num(objs), 0);
  56102. #endif
  56103. #endif
  56104. for (i = 0; i < sk_X509_OBJECT_num(objs); i++) {
  56105. obj = (X509_OBJECT*)sk_X509_OBJECT_value(objs, i);
  56106. switch (X509_OBJECT_get_type(obj)) {
  56107. case X509_LU_X509:
  56108. {
  56109. X509* x509 = NULL;
  56110. X509_NAME *subj_name = NULL;
  56111. ExpectNotNull(x509 = X509_OBJECT_get0_X509(obj));
  56112. ExpectIntEQ(X509_STORE_add_cert(store_cpy, x509), WOLFSSL_SUCCESS);
  56113. ExpectNotNull(subj_name = X509_get_subject_name(x509));
  56114. ExpectPtrEq(obj, X509_OBJECT_retrieve_by_subject(objs, X509_LU_X509,
  56115. subj_name));
  56116. break;
  56117. }
  56118. case X509_LU_CRL:
  56119. #ifdef HAVE_CRL
  56120. {
  56121. X509_CRL* crl = NULL;
  56122. ExpectNotNull(crl = X509_OBJECT_get0_X509_CRL(obj));
  56123. ExpectIntEQ(X509_STORE_add_crl(store_cpy, crl), WOLFSSL_SUCCESS);
  56124. break;
  56125. }
  56126. #endif
  56127. case X509_LU_NONE:
  56128. default:
  56129. Fail(("X509_OBJECT_get_type should return x509 or crl "
  56130. "(when built with crl support)"),
  56131. ("Unrecognized X509_OBJECT type or none"));
  56132. }
  56133. }
  56134. X509_STORE_free(store_cpy);
  56135. SSL_CTX_free(ctx);
  56136. #endif
  56137. return EXPECT_RESULT();
  56138. }
  56139. static int test_wolfSSL_BN_CTX(void)
  56140. {
  56141. EXPECT_DECLS;
  56142. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56143. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56144. WOLFSSL_BN_CTX* bn_ctx = NULL;
  56145. WOLFSSL_BIGNUM* t = NULL;
  56146. ExpectNotNull(bn_ctx = wolfSSL_BN_CTX_new());
  56147. /* No implementation. */
  56148. BN_CTX_init(NULL);
  56149. ExpectNotNull(t = BN_CTX_get(NULL));
  56150. BN_free(t);
  56151. ExpectNotNull(t = BN_CTX_get(bn_ctx));
  56152. BN_free(t);
  56153. #ifndef NO_WOLFSSL_STUB
  56154. /* No implementation. */
  56155. BN_CTX_start(NULL);
  56156. BN_CTX_start(bn_ctx);
  56157. #endif
  56158. BN_CTX_free(NULL);
  56159. BN_CTX_free(bn_ctx);
  56160. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  56161. return EXPECT_RESULT();
  56162. }
  56163. static int test_wolfSSL_BN(void)
  56164. {
  56165. EXPECT_DECLS;
  56166. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56167. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56168. BIGNUM* a = NULL;
  56169. BIGNUM* b = NULL;
  56170. BIGNUM* c = NULL;
  56171. BIGNUM* d = NULL;
  56172. BIGNUM emptyBN;
  56173. /* Setup */
  56174. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56175. /* internal not set emptyBN. */
  56176. ExpectNotNull(a = BN_new());
  56177. ExpectNotNull(b = BN_new());
  56178. ExpectNotNull(c = BN_dup(b));
  56179. ExpectNotNull(d = BN_new());
  56180. /* Invalid parameter testing. */
  56181. BN_free(NULL);
  56182. ExpectNull(BN_dup(NULL));
  56183. ExpectNull(BN_dup(&emptyBN));
  56184. ExpectNull(BN_copy(NULL, NULL));
  56185. ExpectNull(BN_copy(b, NULL));
  56186. ExpectNull(BN_copy(NULL, c));
  56187. ExpectNull(BN_copy(b, &emptyBN));
  56188. ExpectNull(BN_copy(&emptyBN, c));
  56189. BN_clear(NULL);
  56190. BN_clear(&emptyBN);
  56191. ExpectIntEQ(BN_num_bytes(NULL), 0);
  56192. ExpectIntEQ(BN_num_bytes(&emptyBN), 0);
  56193. ExpectIntEQ(BN_num_bits(NULL), 0);
  56194. ExpectIntEQ(BN_num_bits(&emptyBN), 0);
  56195. ExpectIntEQ(BN_is_negative(NULL), 0);
  56196. ExpectIntEQ(BN_is_negative(&emptyBN), 0);
  56197. /* END Invalid Parameters */
  56198. ExpectIntEQ(BN_set_word(a, 3), SSL_SUCCESS);
  56199. ExpectIntEQ(BN_set_word(b, 2), SSL_SUCCESS);
  56200. ExpectIntEQ(BN_set_word(c, 5), SSL_SUCCESS);
  56201. ExpectIntEQ(BN_num_bits(a), 2);
  56202. ExpectIntEQ(BN_num_bytes(a), 1);
  56203. #if !defined(WOLFSSL_SP_MATH) && (!defined(WOLFSSL_SP_MATH_ALL) || \
  56204. defined(WOLFSSL_SP_INT_NEGATIVE))
  56205. ExpectIntEQ(BN_set_word(a, 1), SSL_SUCCESS);
  56206. ExpectIntEQ(BN_set_word(b, 5), SSL_SUCCESS);
  56207. ExpectIntEQ(BN_is_word(a, (WOLFSSL_BN_ULONG)BN_get_word(a)), SSL_SUCCESS);
  56208. ExpectIntEQ(BN_is_word(a, 3), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56209. ExpectIntEQ(BN_sub(c, a, b), SSL_SUCCESS);
  56210. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  56211. {
  56212. /* Do additional tests on negative BN conversions. */
  56213. char* ret = NULL;
  56214. ASN1_INTEGER* asn1 = NULL;
  56215. BIGNUM* tmp = NULL;
  56216. /* Sanity check we have a negative BN. */
  56217. ExpectIntEQ(BN_is_negative(c), 1);
  56218. ExpectNotNull(ret = BN_bn2dec(c));
  56219. ExpectIntEQ(XMEMCMP(ret, "-4", sizeof("-4")), 0);
  56220. XFREE(ret, NULL, DYNAMIC_TYPE_OPENSSL);
  56221. ret = NULL;
  56222. /* Convert to ASN1_INTEGER and back to BN. */
  56223. ExpectNotNull(asn1 = BN_to_ASN1_INTEGER(c, NULL));
  56224. ExpectNotNull(tmp = ASN1_INTEGER_to_BN(asn1, NULL));
  56225. /* After converting back BN should be negative and correct. */
  56226. ExpectIntEQ(BN_is_negative(tmp), 1);
  56227. ExpectNotNull(ret = BN_bn2dec(tmp));
  56228. ExpectIntEQ(XMEMCMP(ret, "-4", sizeof("-4")), 0);
  56229. XFREE(ret, NULL, DYNAMIC_TYPE_OPENSSL);
  56230. ASN1_INTEGER_free(asn1);
  56231. BN_free(tmp);
  56232. }
  56233. #endif
  56234. ExpectIntEQ(BN_get_word(c), 4);
  56235. #endif
  56236. ExpectIntEQ(BN_set_word(a, 3), 1);
  56237. ExpectIntEQ(BN_set_word(b, 3), 1);
  56238. ExpectIntEQ(BN_set_word(c, 4), 1);
  56239. /* NULL == NULL, NULL < num, num > NULL */
  56240. ExpectIntEQ(BN_cmp(NULL, NULL), 0);
  56241. ExpectIntEQ(BN_cmp(&emptyBN, &emptyBN), 0);
  56242. ExpectIntLT(BN_cmp(NULL, b), 0);
  56243. ExpectIntLT(BN_cmp(&emptyBN, b), 0);
  56244. ExpectIntGT(BN_cmp(a, NULL), 0);
  56245. ExpectIntGT(BN_cmp(a, &emptyBN), 0);
  56246. ExpectIntEQ(BN_cmp(a, b), 0);
  56247. ExpectIntLT(BN_cmp(a, c), 0);
  56248. ExpectIntGT(BN_cmp(c, b), 0);
  56249. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
  56250. ExpectIntEQ(BN_print_fp(XBADFILE, NULL), 0);
  56251. ExpectIntEQ(BN_print_fp(XBADFILE, &emptyBN), 0);
  56252. ExpectIntEQ(BN_print_fp(stderr, NULL), 0);
  56253. ExpectIntEQ(BN_print_fp(stderr, &emptyBN), 0);
  56254. ExpectIntEQ(BN_print_fp(XBADFILE, a), 0);
  56255. ExpectIntEQ(BN_print_fp(stderr, a), 1);
  56256. #endif
  56257. BN_clear(a);
  56258. BN_free(a);
  56259. BN_free(b);
  56260. BN_free(c);
  56261. BN_clear_free(d);
  56262. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  56263. return EXPECT_RESULT();
  56264. }
  56265. static int test_wolfSSL_BN_init(void)
  56266. {
  56267. EXPECT_DECLS;
  56268. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56269. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56270. #if !defined(USE_INTEGER_HEAP_MATH) && !defined(HAVE_WOLF_BIGINT)
  56271. BIGNUM* ap = NULL;
  56272. BIGNUM bv;
  56273. BIGNUM cv;
  56274. BIGNUM dv;
  56275. ExpectNotNull(ap = BN_new());
  56276. BN_init(NULL);
  56277. XMEMSET(&bv, 0, sizeof(bv));
  56278. ExpectNull(BN_dup(&bv));
  56279. BN_init(&bv);
  56280. BN_init(&cv);
  56281. BN_init(&dv);
  56282. ExpectIntEQ(BN_set_word(ap, 3), SSL_SUCCESS);
  56283. ExpectIntEQ(BN_set_word(&bv, 2), SSL_SUCCESS);
  56284. ExpectIntEQ(BN_set_word(&cv, 5), SSL_SUCCESS);
  56285. /* a^b mod c = */
  56286. ExpectIntEQ(BN_mod_exp(&dv, NULL, &bv, &cv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56287. ExpectIntEQ(BN_mod_exp(&dv, ap, &bv, &cv, NULL), WOLFSSL_SUCCESS);
  56288. /* check result 3^2 mod 5 */
  56289. ExpectIntEQ(BN_get_word(&dv), 4);
  56290. /* a*b mod c = */
  56291. ExpectIntEQ(BN_mod_mul(&dv, NULL, &bv, &cv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56292. ExpectIntEQ(BN_mod_mul(&dv, ap, &bv, &cv, NULL), SSL_SUCCESS);
  56293. /* check result 3*2 mod 5 */
  56294. ExpectIntEQ(BN_get_word(&dv), 1);
  56295. BN_free(ap);
  56296. #endif
  56297. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  56298. return EXPECT_RESULT();
  56299. }
  56300. static int test_wolfSSL_BN_enc_dec(void)
  56301. {
  56302. EXPECT_DECLS;
  56303. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(WOLFSSL_SP_MATH)
  56304. BIGNUM* a = NULL;
  56305. BIGNUM* b = NULL;
  56306. BIGNUM* c = NULL;
  56307. BIGNUM emptyBN;
  56308. char* str = NULL;
  56309. const char* emptyStr = "";
  56310. const char* numberStr = "12345";
  56311. const char* badStr = "g12345";
  56312. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  56313. const char* twoStr = "2";
  56314. #endif
  56315. unsigned char binNum[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
  56316. unsigned char outNum[5];
  56317. /* Setup */
  56318. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56319. ExpectNotNull(a = BN_new());
  56320. ExpectNotNull(b = BN_new());
  56321. /* Invalid parameters */
  56322. ExpectIntEQ(BN_bn2bin(NULL, NULL), -1);
  56323. ExpectIntEQ(BN_bn2bin(&emptyBN, NULL), -1);
  56324. ExpectIntEQ(BN_bn2bin(NULL, outNum), -1);
  56325. ExpectIntEQ(BN_bn2bin(&emptyBN, outNum), -1);
  56326. ExpectNull(BN_bn2hex(NULL));
  56327. ExpectNull(BN_bn2hex(&emptyBN));
  56328. ExpectNull(BN_bn2dec(NULL));
  56329. ExpectNull(BN_bn2dec(&emptyBN));
  56330. ExpectNotNull(BN_bin2bn(NULL, sizeof(binNum), a));
  56331. BN_free(a);
  56332. ExpectNotNull(a = BN_new());
  56333. ExpectIntEQ(BN_set_word(a, 2), 1);
  56334. ExpectNull(BN_bin2bn(binNum, -1, a));
  56335. ExpectNull(BN_bin2bn(binNum, -1, NULL));
  56336. ExpectNull(BN_bin2bn(binNum, sizeof(binNum), &emptyBN));
  56337. ExpectIntEQ(BN_hex2bn(NULL, NULL), 0);
  56338. ExpectIntEQ(BN_hex2bn(NULL, numberStr), 0);
  56339. ExpectIntEQ(BN_hex2bn(&a, NULL), 0);
  56340. ExpectIntEQ(BN_hex2bn(&a, emptyStr), 0);
  56341. ExpectIntEQ(BN_hex2bn(&a, badStr), 0);
  56342. ExpectIntEQ(BN_hex2bn(&c, badStr), 0);
  56343. ExpectIntEQ(BN_dec2bn(NULL, NULL), 0);
  56344. ExpectIntEQ(BN_dec2bn(NULL, numberStr), 0);
  56345. ExpectIntEQ(BN_dec2bn(&a, NULL), 0);
  56346. ExpectIntEQ(BN_dec2bn(&a, emptyStr), 0);
  56347. ExpectIntEQ(BN_dec2bn(&a, badStr), 0);
  56348. ExpectIntEQ(BN_dec2bn(&c, badStr), 0);
  56349. ExpectIntEQ(BN_set_word(a, 2), 1);
  56350. ExpectIntEQ(BN_bn2bin(a, NULL), 1);
  56351. ExpectIntEQ(BN_bn2bin(a, outNum), 1);
  56352. ExpectNotNull(BN_bin2bn(outNum, 1, b));
  56353. ExpectIntEQ(BN_cmp(a, b), 0);
  56354. ExpectNotNull(BN_bin2bn(binNum, sizeof(binNum), b));
  56355. ExpectIntEQ(BN_cmp(a, b), -1);
  56356. ExpectNotNull(str = BN_bn2hex(a));
  56357. ExpectNotNull(BN_hex2bn(&b, str));
  56358. ExpectIntEQ(BN_cmp(a, b), 0);
  56359. ExpectNotNull(BN_hex2bn(&b, numberStr));
  56360. ExpectIntEQ(BN_cmp(a, b), -1);
  56361. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  56362. str = NULL;
  56363. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  56364. ExpectNotNull(str = BN_bn2dec(a));
  56365. ExpectStrEQ(str, twoStr);
  56366. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  56367. str = NULL;
  56368. #ifndef NO_RSA
  56369. ExpectNotNull(str = BN_bn2dec(a));
  56370. ExpectNotNull(BN_dec2bn(&b, str));
  56371. ExpectIntEQ(BN_cmp(a, b), 0);
  56372. ExpectNotNull(BN_dec2bn(&b, numberStr));
  56373. ExpectIntEQ(BN_cmp(a, b), -1);
  56374. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  56375. str = NULL;
  56376. #else
  56377. /* No implementation - fail with good parameters. */
  56378. ExpectIntEQ(BN_dec2bn(&a, numberStr), 0);
  56379. #endif
  56380. #endif
  56381. BN_free(b);
  56382. BN_free(a);
  56383. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  56384. return EXPECT_RESULT();
  56385. }
  56386. static int test_wolfSSL_BN_word(void)
  56387. {
  56388. EXPECT_DECLS;
  56389. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(WOLFSSL_SP_MATH)
  56390. BIGNUM* a = NULL;
  56391. BIGNUM* b = NULL;
  56392. BIGNUM* c = NULL;
  56393. BIGNUM av;
  56394. ExpectNotNull(a = BN_new());
  56395. ExpectNotNull(b = BN_new());
  56396. ExpectNotNull(c = BN_new());
  56397. XMEMSET(&av, 0, sizeof(av));
  56398. /* Invalid parameter. */
  56399. ExpectIntEQ(BN_add_word(NULL, 3), 0);
  56400. ExpectIntEQ(BN_add_word(&av, 3), 0);
  56401. ExpectIntEQ(BN_sub_word(NULL, 3), 0);
  56402. ExpectIntEQ(BN_sub_word(&av, 3), 0);
  56403. ExpectIntEQ(BN_set_word(NULL, 3), 0);
  56404. ExpectIntEQ(BN_set_word(&av, 3), 0);
  56405. ExpectIntEQ(BN_get_word(NULL), 0);
  56406. ExpectIntEQ(BN_get_word(&av), 0);
  56407. ExpectIntEQ(BN_is_word(NULL, 3), 0);
  56408. ExpectIntEQ(BN_is_word(&av, 3), 0);
  56409. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || \
  56410. !defined(NO_DSA))
  56411. ExpectIntEQ(BN_mod_word(NULL, 3), -1);
  56412. ExpectIntEQ(BN_mod_word(&av, 3), -1);
  56413. #endif
  56414. ExpectIntEQ(BN_one(NULL), 0);
  56415. ExpectIntEQ(BN_one(&av), 0);
  56416. BN_zero(NULL);
  56417. BN_zero(&av);
  56418. ExpectIntEQ(BN_is_one(NULL), 0);
  56419. ExpectIntEQ(BN_is_one(&av), 0);
  56420. ExpectIntEQ(BN_is_zero(NULL), 0);
  56421. ExpectIntEQ(BN_is_zero(&av), 0);
  56422. ExpectIntEQ(BN_set_word(a, 3), 1);
  56423. ExpectIntEQ(BN_set_word(b, 2), 1);
  56424. ExpectIntEQ(BN_set_word(c, 5), 1);
  56425. /* a + 3 = */
  56426. ExpectIntEQ(BN_add_word(a, 3), 1);
  56427. /* check result 3 + 3*/
  56428. ExpectIntEQ(BN_get_word(a), 6);
  56429. ExpectIntEQ(BN_is_word(a, 6), 1);
  56430. ExpectIntEQ(BN_is_word(a, 5), 0);
  56431. /* set a back to 3 */
  56432. ExpectIntEQ(BN_set_word(a, 3), 1);
  56433. /* a - 3 = */
  56434. ExpectIntEQ(BN_sub_word(a, 3), 1);
  56435. /* check result 3 - 3*/
  56436. ExpectIntEQ(BN_get_word(a), 0);
  56437. ExpectIntEQ(BN_one(a), 1);
  56438. ExpectIntEQ(BN_is_word(a, 1), 1);
  56439. ExpectIntEQ(BN_is_word(a, 0), 0);
  56440. ExpectIntEQ(BN_is_one(a), 1);
  56441. ExpectIntEQ(BN_is_zero(a), 0);
  56442. BN_zero(a);
  56443. ExpectIntEQ(BN_is_word(a, 0), 1);
  56444. ExpectIntEQ(BN_is_word(a, 1), 0);
  56445. ExpectIntEQ(BN_is_zero(a), 1);
  56446. ExpectIntEQ(BN_is_one(a), 0);
  56447. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || \
  56448. !defined(NO_DSA))
  56449. ExpectIntEQ(BN_set_word(a, 5), 1);
  56450. ExpectIntEQ(BN_mod_word(a, 3), 2);
  56451. ExpectIntEQ(BN_mod_word(a, 0), -1);
  56452. #endif
  56453. BN_free(c);
  56454. BN_free(b);
  56455. BN_free(a);
  56456. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  56457. return EXPECT_RESULT();
  56458. }
  56459. static int test_wolfSSL_BN_bits(void)
  56460. {
  56461. EXPECT_DECLS;
  56462. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56463. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56464. BIGNUM* a = NULL;
  56465. BIGNUM emptyBN;
  56466. /* Setup */
  56467. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56468. ExpectNotNull(a = BN_new());
  56469. /* Invalid parameters. */
  56470. ExpectIntEQ(BN_set_bit(NULL, 1), 0);
  56471. ExpectIntEQ(BN_set_bit(&emptyBN, 1), 0);
  56472. ExpectIntEQ(BN_set_bit(a, -1), 0);
  56473. ExpectIntEQ(BN_clear_bit(NULL, 1), 0);
  56474. ExpectIntEQ(BN_clear_bit(&emptyBN, 1), 0);
  56475. ExpectIntEQ(BN_clear_bit(a, -1), 0);
  56476. ExpectIntEQ(BN_is_bit_set(NULL, 1), 0);
  56477. ExpectIntEQ(BN_is_bit_set(&emptyBN, 1), 0);
  56478. ExpectIntEQ(BN_is_bit_set(a, -1), 0);
  56479. ExpectIntEQ(BN_is_odd(NULL), 0);
  56480. ExpectIntEQ(BN_is_odd(&emptyBN), 0);
  56481. ExpectIntEQ(BN_set_word(a, 0), 1);
  56482. ExpectIntEQ(BN_is_zero(a), 1);
  56483. ExpectIntEQ(BN_set_bit(a, 0x45), 1);
  56484. ExpectIntEQ(BN_is_zero(a), 0);
  56485. ExpectIntEQ(BN_is_bit_set(a, 0x45), 1);
  56486. ExpectIntEQ(BN_clear_bit(a, 0x45), 1);
  56487. ExpectIntEQ(BN_is_bit_set(a, 0x45), 0);
  56488. ExpectIntEQ(BN_is_zero(a), 1);
  56489. ExpectIntEQ(BN_set_bit(a, 0), 1);
  56490. ExpectIntEQ(BN_is_odd(a), 1);
  56491. ExpectIntEQ(BN_clear_bit(a, 0), 1);
  56492. ExpectIntEQ(BN_is_odd(a), 0);
  56493. ExpectIntEQ(BN_set_bit(a, 1), 1);
  56494. ExpectIntEQ(BN_is_odd(a), 0);
  56495. ExpectIntEQ(BN_set_bit(a, 129), 1);
  56496. ExpectIntEQ(BN_get_word(a), WOLFSSL_BN_MAX_VAL);
  56497. #ifndef NO_WOLFSSL_STUB
  56498. ExpectIntEQ(BN_mask_bits(a, 1), 0);
  56499. #endif
  56500. BN_free(a);
  56501. #endif
  56502. return EXPECT_RESULT();
  56503. }
  56504. static int test_wolfSSL_BN_shift(void)
  56505. {
  56506. EXPECT_DECLS;
  56507. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56508. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56509. BIGNUM* a = NULL;
  56510. BIGNUM* b = NULL;
  56511. BIGNUM emptyBN;
  56512. /* Setup */
  56513. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56514. ExpectNotNull(a = BN_new());
  56515. ExpectNotNull(b = BN_new());
  56516. /* Invalid parameters. */
  56517. ExpectIntEQ(BN_lshift(NULL, NULL, 1), 0);
  56518. ExpectIntEQ(BN_lshift(&emptyBN, NULL, 1), 0);
  56519. ExpectIntEQ(BN_lshift(NULL, &emptyBN, 1), 0);
  56520. ExpectIntEQ(BN_lshift(b, NULL, 1), 0);
  56521. ExpectIntEQ(BN_lshift(b, &emptyBN, 1), 0);
  56522. ExpectIntEQ(BN_lshift(NULL, a, 1), 0);
  56523. ExpectIntEQ(BN_lshift(&emptyBN, a, 1), 0);
  56524. ExpectIntEQ(BN_lshift(b, a, -1), 0);
  56525. ExpectIntEQ(BN_rshift(NULL, NULL, 1), 0);
  56526. ExpectIntEQ(BN_rshift(&emptyBN, NULL, 1), 0);
  56527. ExpectIntEQ(BN_rshift(NULL, &emptyBN, 1), 0);
  56528. ExpectIntEQ(BN_rshift(b, NULL, 1), 0);
  56529. ExpectIntEQ(BN_rshift(b, &emptyBN, 1), 0);
  56530. ExpectIntEQ(BN_rshift(NULL, a, 1), 0);
  56531. ExpectIntEQ(BN_rshift(&emptyBN, a, 1), 0);
  56532. ExpectIntEQ(BN_rshift(b, a, -1), 0);
  56533. ExpectIntEQ(BN_set_word(a, 1), 1);
  56534. ExpectIntEQ(BN_lshift(b, a, 1), 1);
  56535. ExpectIntEQ(BN_is_word(b, 2), 1);
  56536. ExpectIntEQ(BN_lshift(a, a, 1), 1);
  56537. ExpectIntEQ(BN_is_word(a, 2), 1);
  56538. ExpectIntEQ(BN_rshift(b, a, 1), 1);
  56539. ExpectIntEQ(BN_is_word(b, 1), 1);
  56540. ExpectIntEQ(BN_rshift(a, a, 1), 1);
  56541. ExpectIntEQ(BN_is_word(a, 1), 1);
  56542. BN_free(b);
  56543. BN_free(a);
  56544. #endif
  56545. return EXPECT_RESULT();
  56546. }
  56547. static int test_wolfSSL_BN_math(void)
  56548. {
  56549. EXPECT_DECLS;
  56550. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56551. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56552. BIGNUM* a = NULL;
  56553. BIGNUM* b = NULL;
  56554. BIGNUM* r = NULL;
  56555. BIGNUM* rem = NULL;
  56556. BIGNUM emptyBN;
  56557. BN_ULONG val1;
  56558. BN_ULONG val2;
  56559. /* Setup */
  56560. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56561. ExpectNotNull(a = BN_new());
  56562. ExpectNotNull(b = BN_new());
  56563. ExpectNotNull(r = BN_new());
  56564. ExpectNotNull(rem = BN_new());
  56565. /* Invalid parameters. */
  56566. ExpectIntEQ(BN_add(NULL, NULL, NULL), 0);
  56567. ExpectIntEQ(BN_add(r, NULL, NULL), 0);
  56568. ExpectIntEQ(BN_add(NULL, a, NULL), 0);
  56569. ExpectIntEQ(BN_add(NULL, NULL, b), 0);
  56570. ExpectIntEQ(BN_add(r, a, NULL), 0);
  56571. ExpectIntEQ(BN_add(r, NULL, b), 0);
  56572. ExpectIntEQ(BN_add(NULL, a, b), 0);
  56573. ExpectIntEQ(BN_add(&emptyBN, &emptyBN, &emptyBN), 0);
  56574. ExpectIntEQ(BN_add(r, &emptyBN, &emptyBN), 0);
  56575. ExpectIntEQ(BN_add(&emptyBN, a, &emptyBN), 0);
  56576. ExpectIntEQ(BN_add(&emptyBN, &emptyBN, b), 0);
  56577. ExpectIntEQ(BN_add(r, a, &emptyBN), 0);
  56578. ExpectIntEQ(BN_add(r, &emptyBN, b), 0);
  56579. ExpectIntEQ(BN_add(&emptyBN, a, b), 0);
  56580. ExpectIntEQ(BN_sub(NULL, NULL, NULL), 0);
  56581. ExpectIntEQ(BN_sub(r, NULL, NULL), 0);
  56582. ExpectIntEQ(BN_sub(NULL, a, NULL), 0);
  56583. ExpectIntEQ(BN_sub(NULL, NULL, b), 0);
  56584. ExpectIntEQ(BN_sub(r, a, NULL), 0);
  56585. ExpectIntEQ(BN_sub(r, NULL, b), 0);
  56586. ExpectIntEQ(BN_sub(NULL, a, b), 0);
  56587. ExpectIntEQ(BN_sub(&emptyBN, &emptyBN, &emptyBN), 0);
  56588. ExpectIntEQ(BN_sub(r, &emptyBN, &emptyBN), 0);
  56589. ExpectIntEQ(BN_sub(&emptyBN, a, &emptyBN), 0);
  56590. ExpectIntEQ(BN_sub(&emptyBN, &emptyBN, b), 0);
  56591. ExpectIntEQ(BN_sub(r, a, &emptyBN), 0);
  56592. ExpectIntEQ(BN_sub(r, &emptyBN, b), 0);
  56593. ExpectIntEQ(BN_sub(&emptyBN, a, b), 0);
  56594. ExpectIntEQ(BN_mul(NULL, NULL, NULL, NULL), 0);
  56595. ExpectIntEQ(BN_mul(r, NULL, NULL, NULL), 0);
  56596. ExpectIntEQ(BN_mul(NULL, a, NULL, NULL), 0);
  56597. ExpectIntEQ(BN_mul(NULL, NULL, b, NULL), 0);
  56598. ExpectIntEQ(BN_mul(r, a, NULL, NULL), 0);
  56599. ExpectIntEQ(BN_mul(r, NULL, b, NULL), 0);
  56600. ExpectIntEQ(BN_mul(NULL, a, b, NULL), 0);
  56601. ExpectIntEQ(BN_mul(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56602. ExpectIntEQ(BN_mul(r, &emptyBN, &emptyBN, NULL), 0);
  56603. ExpectIntEQ(BN_mul(&emptyBN, a, &emptyBN, NULL), 0);
  56604. ExpectIntEQ(BN_mul(&emptyBN, &emptyBN, b, NULL), 0);
  56605. ExpectIntEQ(BN_mul(r, a, &emptyBN, NULL), 0);
  56606. ExpectIntEQ(BN_mul(r, &emptyBN, b, NULL), 0);
  56607. ExpectIntEQ(BN_mul(&emptyBN, a, b, NULL), 0);
  56608. ExpectIntEQ(BN_div(NULL, NULL, NULL, NULL, NULL), 0);
  56609. ExpectIntEQ(BN_div(r, NULL, NULL, NULL, NULL), 0);
  56610. ExpectIntEQ(BN_div(NULL, rem, NULL, NULL, NULL), 0);
  56611. ExpectIntEQ(BN_div(NULL, NULL, a, NULL, NULL), 0);
  56612. ExpectIntEQ(BN_div(NULL, NULL, NULL, b, NULL), 0);
  56613. ExpectIntEQ(BN_div(NULL, rem, a, b, NULL), 0);
  56614. ExpectIntEQ(BN_div(r, NULL, a, b, NULL), 0);
  56615. ExpectIntEQ(BN_div(r, rem, NULL, b, NULL), 0);
  56616. ExpectIntEQ(BN_div(r, rem, a, NULL, NULL), 0);
  56617. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56618. ExpectIntEQ(BN_div(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56619. ExpectIntEQ(BN_div(&emptyBN, rem, &emptyBN, &emptyBN, NULL), 0);
  56620. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, a, &emptyBN, NULL), 0);
  56621. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, &emptyBN, b, NULL), 0);
  56622. ExpectIntEQ(BN_div(&emptyBN, rem, a, b, NULL), 0);
  56623. ExpectIntEQ(BN_div(r, &emptyBN, a, b, NULL), 0);
  56624. ExpectIntEQ(BN_div(r, rem, &emptyBN, b, NULL), 0);
  56625. ExpectIntEQ(BN_div(r, rem, a, &emptyBN, NULL), 0);
  56626. ExpectIntEQ(BN_mod(NULL, NULL, NULL, NULL), 0);
  56627. ExpectIntEQ(BN_mod(r, NULL, NULL, NULL), 0);
  56628. ExpectIntEQ(BN_mod(NULL, a, NULL, NULL), 0);
  56629. ExpectIntEQ(BN_mod(NULL, NULL, b, NULL), 0);
  56630. ExpectIntEQ(BN_mod(r, a, NULL, NULL), 0);
  56631. ExpectIntEQ(BN_mod(r, NULL, b, NULL), 0);
  56632. ExpectIntEQ(BN_mod(NULL, a, b, NULL), 0);
  56633. ExpectIntEQ(BN_mod(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56634. ExpectIntEQ(BN_mod(r, &emptyBN, &emptyBN, NULL), 0);
  56635. ExpectIntEQ(BN_mod(&emptyBN, a, &emptyBN, NULL), 0);
  56636. ExpectIntEQ(BN_mod(&emptyBN, &emptyBN, b, NULL), 0);
  56637. ExpectIntEQ(BN_mod(r, a, &emptyBN, NULL), 0);
  56638. ExpectIntEQ(BN_mod(r, &emptyBN, b, NULL), 0);
  56639. ExpectIntEQ(BN_mod(&emptyBN, a, b, NULL), 0);
  56640. /* END Invalid parameters. */
  56641. val1 = 8;
  56642. val2 = 3;
  56643. ExpectIntEQ(BN_set_word(a, val1), 1);
  56644. ExpectIntEQ(BN_set_word(b, val2), 1);
  56645. ExpectIntEQ(BN_add(r, a, b), 1);
  56646. ExpectIntEQ(BN_is_word(r, val1 + val2), 1);
  56647. ExpectIntEQ(BN_sub(r, a, b), 1);
  56648. ExpectIntEQ(BN_is_word(r, val1 - val2), 1);
  56649. ExpectIntEQ(BN_mul(r, a, b, NULL), 1);
  56650. ExpectIntEQ(BN_is_word(r, val1 * val2), 1);
  56651. ExpectIntEQ(BN_div(r, rem, a, b, NULL), 1);
  56652. ExpectIntEQ(BN_is_word(r, val1 / val2), 1);
  56653. ExpectIntEQ(BN_is_word(rem, val1 % val2), 1);
  56654. ExpectIntEQ(BN_mod(r, a, b, NULL), 1);
  56655. ExpectIntEQ(BN_is_word(r, val1 % val2), 1);
  56656. BN_free(rem);
  56657. BN_free(r);
  56658. BN_free(b);
  56659. BN_free(a);
  56660. #endif
  56661. return EXPECT_RESULT();
  56662. }
  56663. static int test_wolfSSL_BN_math_mod(void)
  56664. {
  56665. EXPECT_DECLS;
  56666. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56667. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56668. BIGNUM* a = NULL;
  56669. BIGNUM* b = NULL;
  56670. BIGNUM* m = NULL;
  56671. BIGNUM* r = NULL;
  56672. BIGNUM* t = NULL;
  56673. BIGNUM emptyBN;
  56674. BN_ULONG val1;
  56675. BN_ULONG val2;
  56676. BN_ULONG val3;
  56677. /* Setup */
  56678. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56679. ExpectNotNull(a = BN_new());
  56680. ExpectNotNull(b = BN_new());
  56681. ExpectNotNull(m = BN_new());
  56682. ExpectNotNull(r = BN_new());
  56683. /* Invalid parameters. */
  56684. ExpectIntEQ(BN_mod_add(NULL, NULL, NULL, NULL, NULL), 0);
  56685. ExpectIntEQ(BN_mod_add(r, NULL, NULL, NULL, NULL), 0);
  56686. ExpectIntEQ(BN_mod_add(NULL, a, NULL, NULL, NULL), 0);
  56687. ExpectIntEQ(BN_mod_add(NULL, NULL, b, NULL, NULL), 0);
  56688. ExpectIntEQ(BN_mod_add(NULL, NULL, NULL, m, NULL), 0);
  56689. ExpectIntEQ(BN_mod_add(NULL, a, b, m, NULL), 0);
  56690. ExpectIntEQ(BN_mod_add(r, NULL, b, m, NULL), 0);
  56691. ExpectIntEQ(BN_mod_add(r, a, NULL, m, NULL), 0);
  56692. ExpectIntEQ(BN_mod_add(r, a, m, NULL, NULL), 0);
  56693. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56694. ExpectIntEQ(BN_mod_add(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56695. ExpectIntEQ(BN_mod_add(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  56696. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  56697. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  56698. ExpectIntEQ(BN_mod_add(&emptyBN, a, b, m, NULL), 0);
  56699. ExpectIntEQ(BN_mod_add(r, &emptyBN, b, m, NULL), 0);
  56700. ExpectIntEQ(BN_mod_add(r, a, &emptyBN, m, NULL), 0);
  56701. ExpectIntEQ(BN_mod_add(r, a, m, &emptyBN, NULL), 0);
  56702. ExpectIntEQ(BN_mod_mul(NULL, NULL, NULL, NULL, NULL), 0);
  56703. ExpectIntEQ(BN_mod_mul(r, NULL, NULL, NULL, NULL), 0);
  56704. ExpectIntEQ(BN_mod_mul(NULL, a, NULL, NULL, NULL), 0);
  56705. ExpectIntEQ(BN_mod_mul(NULL, NULL, b, NULL, NULL), 0);
  56706. ExpectIntEQ(BN_mod_mul(NULL, NULL, NULL, m, NULL), 0);
  56707. ExpectIntEQ(BN_mod_mul(NULL, a, b, m, NULL), 0);
  56708. ExpectIntEQ(BN_mod_mul(r, NULL, b, m, NULL), 0);
  56709. ExpectIntEQ(BN_mod_mul(r, a, NULL, m, NULL), 0);
  56710. ExpectIntEQ(BN_mod_mul(r, a, m, NULL, NULL), 0);
  56711. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56712. ExpectIntEQ(BN_mod_mul(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56713. ExpectIntEQ(BN_mod_mul(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  56714. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  56715. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  56716. ExpectIntEQ(BN_mod_mul(&emptyBN, a, b, m, NULL), 0);
  56717. ExpectIntEQ(BN_mod_mul(r, &emptyBN, b, m, NULL), 0);
  56718. ExpectIntEQ(BN_mod_mul(r, a, &emptyBN, m, NULL), 0);
  56719. ExpectIntEQ(BN_mod_mul(r, a, m, &emptyBN, NULL), 0);
  56720. ExpectIntEQ(BN_mod_exp(NULL, NULL, NULL, NULL, NULL), 0);
  56721. ExpectIntEQ(BN_mod_exp(r, NULL, NULL, NULL, NULL), 0);
  56722. ExpectIntEQ(BN_mod_exp(NULL, a, NULL, NULL, NULL), 0);
  56723. ExpectIntEQ(BN_mod_exp(NULL, NULL, b, NULL, NULL), 0);
  56724. ExpectIntEQ(BN_mod_exp(NULL, NULL, NULL, m, NULL), 0);
  56725. ExpectIntEQ(BN_mod_exp(NULL, a, b, m, NULL), 0);
  56726. ExpectIntEQ(BN_mod_exp(r, NULL, b, m, NULL), 0);
  56727. ExpectIntEQ(BN_mod_exp(r, a, NULL, m, NULL), 0);
  56728. ExpectIntEQ(BN_mod_exp(r, a, m, NULL, NULL), 0);
  56729. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56730. ExpectIntEQ(BN_mod_exp(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56731. ExpectIntEQ(BN_mod_exp(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  56732. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  56733. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  56734. ExpectIntEQ(BN_mod_exp(&emptyBN, a, b, m, NULL), 0);
  56735. ExpectIntEQ(BN_mod_exp(r, &emptyBN, b, m, NULL), 0);
  56736. ExpectIntEQ(BN_mod_exp(r, a, &emptyBN, m, NULL), 0);
  56737. ExpectIntEQ(BN_mod_exp(r, a, m, &emptyBN, NULL), 0);
  56738. ExpectNull(BN_mod_inverse(r, NULL, NULL, NULL));
  56739. ExpectNull(BN_mod_inverse(r, a, NULL, NULL));
  56740. ExpectNull(BN_mod_inverse(r, NULL, m, NULL));
  56741. ExpectNull(BN_mod_inverse(r, NULL, m, NULL));
  56742. ExpectNull(BN_mod_inverse(r, a, NULL, NULL));
  56743. ExpectNull(BN_mod_inverse(&emptyBN, &emptyBN, &emptyBN, NULL));
  56744. ExpectNull(BN_mod_inverse(r, &emptyBN, &emptyBN, NULL));
  56745. ExpectNull(BN_mod_inverse(&emptyBN, a, &emptyBN, NULL));
  56746. ExpectNull(BN_mod_inverse(&emptyBN, &emptyBN, m, NULL));
  56747. ExpectNull(BN_mod_inverse(&emptyBN, a, m, NULL));
  56748. ExpectNull(BN_mod_inverse(r, &emptyBN, m, NULL));
  56749. ExpectNull(BN_mod_inverse(r, a, &emptyBN, NULL));
  56750. /* END Invalid parameters. */
  56751. val1 = 9;
  56752. val2 = 13;
  56753. val3 = 5;
  56754. ExpectIntEQ(BN_set_word(a, val1), 1);
  56755. ExpectIntEQ(BN_set_word(b, val2), 1);
  56756. ExpectIntEQ(BN_set_word(m, val3), 1);
  56757. ExpectIntEQ(BN_mod_add(r, a, b, m, NULL), 1);
  56758. ExpectIntEQ(BN_is_word(r, (val1 + val2) % val3), 1);
  56759. ExpectIntEQ(BN_mod_mul(r, a, b, m, NULL), 1);
  56760. ExpectIntEQ(BN_is_word(r, (val1 * val2) % val3), 1);
  56761. ExpectIntEQ(BN_set_word(a, 2), 1);
  56762. ExpectIntEQ(BN_set_word(b, 3), 1);
  56763. ExpectIntEQ(BN_set_word(m, 5), 1);
  56764. /* (2 ^ 3) % 5 = 8 % 5 = 3 */
  56765. ExpectIntEQ(BN_mod_exp(r, a, b, m, NULL), 1);
  56766. ExpectIntEQ(BN_is_word(r, 3), 1);
  56767. /* (2 * 3) % 5 = 6 % 5 = 1 => inv = 3 */
  56768. ExpectNotNull(BN_mod_inverse(r, a, m, NULL));
  56769. ExpectIntEQ(BN_is_word(r, 3), 1);
  56770. ExpectNotNull(t = BN_mod_inverse(NULL, a, m, NULL));
  56771. ExpectIntEQ(BN_is_word(t, 3), 1);
  56772. BN_free(t);
  56773. /* No inverse case. No inverse when a divides b. */
  56774. ExpectIntEQ(BN_set_word(a, 3), 1);
  56775. ExpectIntEQ(BN_set_word(m, 9), 1);
  56776. ExpectNull(BN_mod_inverse(r, a, m, NULL));
  56777. BN_free(r);
  56778. BN_free(m);
  56779. BN_free(b);
  56780. BN_free(a);
  56781. #endif
  56782. return EXPECT_RESULT();
  56783. }
  56784. static int test_wolfSSL_BN_math_other(void)
  56785. {
  56786. EXPECT_DECLS;
  56787. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56788. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56789. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  56790. BIGNUM* a = NULL;
  56791. BIGNUM* b = NULL;
  56792. BIGNUM* r = NULL;
  56793. BIGNUM emptyBN;
  56794. /* Setup */
  56795. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56796. ExpectNotNull(a = BN_new());
  56797. ExpectNotNull(b = BN_new());
  56798. ExpectNotNull(r = BN_new());
  56799. /* Invalid parameters. */
  56800. ExpectIntEQ(BN_gcd(NULL, NULL, NULL, NULL), 0);
  56801. ExpectIntEQ(BN_gcd(r, NULL, NULL, NULL), 0);
  56802. ExpectIntEQ(BN_gcd(NULL, a, NULL, NULL), 0);
  56803. ExpectIntEQ(BN_gcd(NULL, NULL, b, NULL), 0);
  56804. ExpectIntEQ(BN_gcd(NULL, a, b, NULL), 0);
  56805. ExpectIntEQ(BN_gcd(r, NULL, b, NULL), 0);
  56806. ExpectIntEQ(BN_gcd(r, a, NULL, NULL), 0);
  56807. ExpectIntEQ(BN_gcd(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56808. ExpectIntEQ(BN_gcd(r, &emptyBN, &emptyBN, NULL), 0);
  56809. ExpectIntEQ(BN_gcd(&emptyBN, a, &emptyBN, NULL), 0);
  56810. ExpectIntEQ(BN_gcd(&emptyBN, &emptyBN, b, NULL), 0);
  56811. ExpectIntEQ(BN_gcd(&emptyBN, a, b, NULL), 0);
  56812. ExpectIntEQ(BN_gcd(r, &emptyBN, b, NULL), 0);
  56813. ExpectIntEQ(BN_gcd(r, a, &emptyBN, NULL), 0);
  56814. /* END Invalid parameters. */
  56815. /* No common factors between 2 and 3. */
  56816. ExpectIntEQ(BN_set_word(a, 2), 1);
  56817. ExpectIntEQ(BN_set_word(b, 3), 1);
  56818. ExpectIntEQ(BN_gcd(r, a, b, NULL), 1);
  56819. ExpectIntEQ(BN_is_word(r, 1), 1);
  56820. /* 3 is largest value that divides both 6 and 9. */
  56821. ExpectIntEQ(BN_set_word(a, 6), 1);
  56822. ExpectIntEQ(BN_set_word(b, 9), 1);
  56823. ExpectIntEQ(BN_gcd(r, a, b, NULL), 1);
  56824. ExpectIntEQ(BN_is_word(r, 3), 1);
  56825. /* GCD of 0 and 0 is undefined. */
  56826. ExpectIntEQ(BN_set_word(a, 0), 1);
  56827. ExpectIntEQ(BN_set_word(b, 0), 1);
  56828. ExpectIntEQ(BN_gcd(r, a, b, NULL), 0);
  56829. /* Teardown */
  56830. BN_free(r);
  56831. BN_free(b);
  56832. BN_free(a);
  56833. #endif
  56834. #endif
  56835. return EXPECT_RESULT();
  56836. }
  56837. static int test_wolfSSL_BN_rand(void)
  56838. {
  56839. EXPECT_DECLS;
  56840. #if defined(OPENSSL_EXTRA) && !defined(OPENSSL_EXTRA_NO_BN)
  56841. BIGNUM* bn = NULL;
  56842. BIGNUM* range = NULL;
  56843. BIGNUM emptyBN;
  56844. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56845. ExpectNotNull(bn = BN_new());
  56846. ExpectNotNull(range = BN_new());
  56847. /* Invalid parameters. */
  56848. ExpectIntEQ(BN_rand(NULL, -1, 0, 0), 0);
  56849. ExpectIntEQ(BN_rand(bn, -1, 0, 0), 0);
  56850. ExpectIntEQ(BN_rand(NULL, 1, 0, 0), 0);
  56851. ExpectIntEQ(BN_rand(&emptyBN, -1, 0, 0), 0);
  56852. ExpectIntEQ(BN_rand(bn, -1, 0, 0), 0);
  56853. ExpectIntEQ(BN_rand(&emptyBN, 1, 0, 0), 0);
  56854. ExpectIntEQ(BN_pseudo_rand(NULL, -1, 0, 0), 0);
  56855. ExpectIntEQ(BN_pseudo_rand(bn, -1, 0, 0), 0);
  56856. ExpectIntEQ(BN_pseudo_rand(NULL, 1, 0, 0), 0);
  56857. ExpectIntEQ(BN_pseudo_rand(&emptyBN, -1, 0, 0), 0);
  56858. ExpectIntEQ(BN_pseudo_rand(bn, -1, 0, 0), 0);
  56859. ExpectIntEQ(BN_pseudo_rand(&emptyBN, 1, 0, 0), 0);
  56860. ExpectIntEQ(BN_rand_range(NULL, NULL), 0);
  56861. ExpectIntEQ(BN_rand_range(bn, NULL), 0);
  56862. ExpectIntEQ(BN_rand_range(NULL, range), 0);
  56863. ExpectIntEQ(BN_rand_range(&emptyBN, &emptyBN), 0);
  56864. ExpectIntEQ(BN_rand_range(bn, &emptyBN), 0);
  56865. ExpectIntEQ(BN_rand_range(&emptyBN, range), 0);
  56866. /* 0 bit random value must be 0 and so cannot set bit in any position. */
  56867. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  56868. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56869. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  56870. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56871. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  56872. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56873. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  56874. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56875. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  56876. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56877. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  56878. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56879. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  56880. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56881. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  56882. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56883. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  56884. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56885. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  56886. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56887. /* 1 bit random value must have no more than one top bit set. */
  56888. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  56889. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56890. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  56891. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56892. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  56893. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56894. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  56895. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56896. /* END Invalid parameters. */
  56897. /* 0 bit random: 0. */
  56898. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  56899. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56900. ExpectIntEQ(BN_is_zero(bn), 1);
  56901. ExpectIntEQ(BN_set_word(bn, 2), 1); /* Make sure not zero. */
  56902. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  56903. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56904. ExpectIntEQ(BN_is_zero(bn), 1);
  56905. /* 1 bit random: 0 or 1. */
  56906. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ANY,
  56907. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56908. ExpectIntLT(BN_get_word(bn), 2); /* Make sure valid range. */
  56909. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  56910. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56911. ExpectIntEQ(BN_get_word(bn), 1);
  56912. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  56913. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  56914. ExpectIntEQ(BN_get_word(bn), 1);
  56915. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ANY,
  56916. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56917. ExpectIntLT(BN_get_word(bn), 2); /* Make sure valid range. */
  56918. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  56919. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56920. ExpectIntEQ(BN_get_word(bn), 1);
  56921. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  56922. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  56923. ExpectIntEQ(BN_get_word(bn), 1);
  56924. ExpectIntEQ(BN_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  56925. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56926. ExpectIntEQ(BN_num_bits(bn), 8);
  56927. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  56928. ExpectIntEQ(BN_pseudo_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  56929. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56930. ExpectIntEQ(BN_num_bits(bn), 8);
  56931. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  56932. ExpectIntEQ(BN_rand(bn, 8, WOLFSSL_BN_RAND_TOP_TWO,
  56933. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56934. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  56935. ExpectIntEQ(BN_is_bit_set(bn, 6), 1);
  56936. ExpectIntEQ(BN_pseudo_rand(bn, 8, WOLFSSL_BN_RAND_TOP_TWO,
  56937. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56938. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  56939. ExpectIntEQ(BN_is_bit_set(bn, 6), 1);
  56940. ExpectIntEQ(BN_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  56941. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  56942. ExpectIntEQ(BN_is_bit_set(bn, 0), 1);
  56943. ExpectIntEQ(BN_pseudo_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  56944. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  56945. ExpectIntEQ(BN_is_bit_set(bn, 0), 1);
  56946. /* Regression test: Older versions of wolfSSL_BN_rand would round the
  56947. * requested number of bits up to the nearest multiple of 8. E.g. in this
  56948. * case, requesting a 13-bit random number would actually return a 16-bit
  56949. * random number. */
  56950. ExpectIntEQ(BN_rand(bn, 13, WOLFSSL_BN_RAND_TOP_ONE,
  56951. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56952. ExpectIntEQ(BN_num_bits(bn), 13);
  56953. ExpectIntEQ(BN_rand(range, 64, WOLFSSL_BN_RAND_TOP_ONE,
  56954. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56955. ExpectIntEQ(BN_rand_range(bn, range), 1);
  56956. ExpectIntEQ(BN_set_word(range, 0), 1);
  56957. ExpectIntEQ(BN_rand_range(bn, range), 1);
  56958. ExpectIntEQ(BN_set_word(range, 1), 1);
  56959. ExpectIntEQ(BN_rand_range(bn, range), 1);
  56960. BN_free(bn);
  56961. BN_free(range);
  56962. #endif
  56963. return EXPECT_RESULT();
  56964. }
  56965. static int test_wolfSSL_BN_prime(void)
  56966. {
  56967. EXPECT_DECLS;
  56968. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56969. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56970. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || !defined(NO_DSA))
  56971. BIGNUM* a = NULL;
  56972. BIGNUM* add = NULL;
  56973. BIGNUM* rem = NULL;
  56974. BIGNUM emptyBN;
  56975. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56976. ExpectNotNull(a = BN_new());
  56977. ExpectNotNull(add = BN_new());
  56978. ExpectNotNull(rem = BN_new());
  56979. /* Invalid parameters. */
  56980. /* BN_generate_prime_ex()
  56981. * prime - must have valid BIGNUM
  56982. * bits - Greater then 0
  56983. * safe - not supported, must be 0
  56984. * add - not supported, must be NULL
  56985. * rem - not supported, must be NULL
  56986. * cb - anything
  56987. */
  56988. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, add, rem, NULL), 0);
  56989. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, add, rem, NULL), 0);
  56990. ExpectIntEQ(BN_generate_prime_ex(a, -1, 1, add, rem, NULL), 0);
  56991. ExpectIntEQ(BN_generate_prime_ex(NULL, 2, 1, add, rem, NULL), 0);
  56992. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, 2, 1, add, rem, NULL), 0);
  56993. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 0, add, rem, NULL), 0);
  56994. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 0, add, rem, NULL), 0);
  56995. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, NULL, rem, NULL), 0);
  56996. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, NULL, rem, NULL), 0);
  56997. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, add, NULL, NULL), 0);
  56998. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, add, NULL, NULL), 0);
  56999. ExpectIntEQ(BN_generate_prime_ex(NULL, 2, 0, NULL, NULL, NULL), 0);
  57000. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, 2, 0, NULL, NULL, NULL), 0);
  57001. ExpectIntEQ(BN_generate_prime_ex(a, -1, 0, NULL, NULL, NULL), 0);
  57002. ExpectIntEQ(BN_generate_prime_ex(a, 0, 0, NULL, NULL, NULL), 0);
  57003. ExpectIntEQ(BN_generate_prime_ex(a, 2, 1, NULL, NULL, NULL), 0);
  57004. ExpectIntEQ(BN_generate_prime_ex(a, 2, 0, add, NULL, NULL), 0);
  57005. ExpectIntEQ(BN_generate_prime_ex(a, 2, 0, NULL, rem, NULL), 0);
  57006. ExpectIntEQ(BN_is_prime_ex(NULL, -1, NULL, NULL), -1);
  57007. ExpectIntEQ(BN_is_prime_ex(&emptyBN, -1, NULL, NULL), -1);
  57008. ExpectIntEQ(BN_is_prime_ex(a, -1, NULL, NULL), -1);
  57009. ExpectIntEQ(BN_is_prime_ex(a, 2048, NULL, NULL), -1);
  57010. ExpectIntEQ(BN_is_prime_ex(NULL, 1, NULL, NULL), -1);
  57011. ExpectIntEQ(BN_is_prime_ex(&emptyBN, 1, NULL, NULL), -1);
  57012. /* END Invalid parameters. */
  57013. ExpectIntEQ(BN_generate_prime_ex(a, 512, 0, NULL, NULL, NULL), 1);
  57014. ExpectIntEQ(BN_is_prime_ex(a, 8, NULL, NULL), 1);
  57015. ExpectIntEQ(BN_clear_bit(a, 0), 1);
  57016. ExpectIntEQ(BN_is_prime_ex(a, 8, NULL, NULL), 0);
  57017. BN_free(rem);
  57018. BN_free(add);
  57019. BN_free(a);
  57020. #endif
  57021. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  57022. return EXPECT_RESULT();
  57023. }
  57024. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  57025. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  57026. #define TEST_ARG 0x1234
  57027. static void msg_cb(int write_p, int version, int content_type,
  57028. const void *buf, size_t len, SSL *ssl, void *arg)
  57029. {
  57030. (void)write_p;
  57031. (void)version;
  57032. (void)content_type;
  57033. (void)buf;
  57034. (void)len;
  57035. (void)ssl;
  57036. AssertTrue(arg == (void*)TEST_ARG);
  57037. }
  57038. #endif
  57039. #if defined(OPENSSL_EXTRA) && defined(DEBUG_WOLFSSL) && \
  57040. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  57041. #if defined(SESSION_CERTS)
  57042. #include "wolfssl/internal.h"
  57043. #endif
  57044. static int msgCb(SSL_CTX *ctx, SSL *ssl)
  57045. {
  57046. EXPECT_DECLS;
  57047. #if defined(OPENSSL_ALL) && defined(SESSION_CERTS) && !defined(NO_BIO)
  57048. STACK_OF(X509)* sk = NULL;
  57049. X509* x509 = NULL;
  57050. int i, num;
  57051. BIO* bio = NULL;
  57052. #endif
  57053. ExpectNotNull(ctx);
  57054. ExpectNotNull(ssl);
  57055. fprintf(stderr, "\n===== msgcb called ====\n");
  57056. #if defined(SESSION_CERTS) && defined(TEST_PEER_CERT_CHAIN)
  57057. ExpectTrue(SSL_get_peer_cert_chain(ssl) != NULL);
  57058. ExpectIntEQ(((WOLFSSL_X509_CHAIN *)SSL_get_peer_cert_chain(ssl))->count, 2);
  57059. ExpectNotNull(SSL_get0_verified_chain(ssl));
  57060. #endif
  57061. #if defined(OPENSSL_ALL) && defined(SESSION_CERTS) && !defined(NO_BIO)
  57062. ExpectNotNull(bio = BIO_new_fp(stderr, BIO_NOCLOSE));
  57063. ExpectNotNull(sk = SSL_get_peer_cert_chain(ssl));
  57064. if (sk == NULL) {
  57065. BIO_free(bio);
  57066. return TEST_FAIL;
  57067. }
  57068. num = sk_X509_num(sk);
  57069. ExpectTrue(num > 0);
  57070. for (i = 0; i < num; i++) {
  57071. ExpectNotNull(x509 = sk_X509_value(sk,i));
  57072. if (x509 == NULL)
  57073. break;
  57074. fprintf(stderr, "Certificate at index [%d] = :\n",i);
  57075. X509_print(bio,x509);
  57076. fprintf(stderr, "\n\n");
  57077. }
  57078. BIO_free(bio);
  57079. #endif
  57080. return EXPECT_RESULT();
  57081. }
  57082. #endif
  57083. static int test_wolfSSL_msgCb(void)
  57084. {
  57085. EXPECT_DECLS;
  57086. #if defined(OPENSSL_EXTRA) && defined(DEBUG_WOLFSSL) && \
  57087. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  57088. test_ssl_cbf client_cb;
  57089. test_ssl_cbf server_cb;
  57090. XMEMSET(&client_cb, 0, sizeof(client_cb));
  57091. XMEMSET(&server_cb, 0, sizeof(server_cb));
  57092. #ifndef WOLFSSL_NO_TLS12
  57093. client_cb.method = wolfTLSv1_2_client_method;
  57094. server_cb.method = wolfTLSv1_2_server_method;
  57095. #else
  57096. client_cb.method = wolfTLSv1_3_client_method;
  57097. server_cb.method = wolfTLSv1_3_server_method;
  57098. #endif
  57099. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  57100. &server_cb, msgCb), TEST_SUCCESS);
  57101. #endif
  57102. return EXPECT_RESULT();
  57103. }
  57104. static int test_wolfSSL_either_side(void)
  57105. {
  57106. EXPECT_DECLS;
  57107. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)) && \
  57108. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  57109. test_ssl_cbf client_cb;
  57110. test_ssl_cbf server_cb;
  57111. XMEMSET(&client_cb, 0, sizeof(client_cb));
  57112. XMEMSET(&server_cb, 0, sizeof(server_cb));
  57113. /* Use different CTX for client and server */
  57114. client_cb.ctx = wolfSSL_CTX_new(wolfSSLv23_method());
  57115. ExpectNotNull(client_cb.ctx);
  57116. server_cb.ctx = wolfSSL_CTX_new(wolfSSLv23_method());
  57117. ExpectNotNull(server_cb.ctx);
  57118. /* we are responsible for free'ing WOLFSSL_CTX */
  57119. server_cb.isSharedCtx = client_cb.isSharedCtx = 1;
  57120. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  57121. &server_cb, NULL), TEST_SUCCESS);
  57122. wolfSSL_CTX_free(client_cb.ctx);
  57123. wolfSSL_CTX_free(server_cb.ctx);
  57124. #endif
  57125. return EXPECT_RESULT();
  57126. }
  57127. static int test_wolfSSL_DTLS_either_side(void)
  57128. {
  57129. EXPECT_DECLS;
  57130. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)) && \
  57131. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS)
  57132. test_ssl_cbf client_cb;
  57133. test_ssl_cbf server_cb;
  57134. XMEMSET(&client_cb, 0, sizeof(client_cb));
  57135. XMEMSET(&server_cb, 0, sizeof(server_cb));
  57136. /* Use different CTX for client and server */
  57137. client_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method());
  57138. ExpectNotNull(client_cb.ctx);
  57139. server_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method());
  57140. ExpectNotNull(server_cb.ctx);
  57141. /* we are responsible for free'ing WOLFSSL_CTX */
  57142. server_cb.isSharedCtx = client_cb.isSharedCtx = 1;
  57143. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  57144. &server_cb, NULL), TEST_SUCCESS);
  57145. wolfSSL_CTX_free(client_cb.ctx);
  57146. wolfSSL_CTX_free(server_cb.ctx);
  57147. #endif
  57148. return EXPECT_RESULT();
  57149. }
  57150. static int test_generate_cookie(void)
  57151. {
  57152. EXPECT_DECLS;
  57153. #if defined(WOLFSSL_DTLS) && defined(OPENSSL_EXTRA) && defined(USE_WOLFSSL_IO)
  57154. SSL_CTX* ctx = NULL;
  57155. SSL* ssl = NULL;
  57156. byte buf[FOURK_BUF] = {0};
  57157. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLS_method()));
  57158. ExpectNotNull(ssl = SSL_new(ctx));
  57159. /* Test unconnected */
  57160. ExpectIntEQ(EmbedGenerateCookie(ssl, buf, FOURK_BUF, NULL), WC_NO_ERR_TRACE(GEN_COOKIE_E));
  57161. wolfSSL_CTX_SetGenCookie(ctx, EmbedGenerateCookie);
  57162. wolfSSL_SetCookieCtx(ssl, ctx);
  57163. ExpectNotNull(wolfSSL_GetCookieCtx(ssl));
  57164. ExpectNull(wolfSSL_GetCookieCtx(NULL));
  57165. SSL_free(ssl);
  57166. SSL_CTX_free(ctx);
  57167. #endif
  57168. return EXPECT_RESULT();
  57169. }
  57170. static int test_wolfSSL_set_options(void)
  57171. {
  57172. EXPECT_DECLS;
  57173. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  57174. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  57175. WOLFSSL* ssl = NULL;
  57176. WOLFSSL_CTX* ctx = NULL;
  57177. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  57178. char appData[] = "extra msg";
  57179. #endif
  57180. #ifdef OPENSSL_EXTRA
  57181. unsigned char protos[] = {
  57182. 7, 't', 'l', 's', '/', '1', '.', '2',
  57183. 8, 'h', 't', 't', 'p', '/', '1', '.', '1'
  57184. };
  57185. unsigned int len = sizeof(protos);
  57186. void *arg = (void *)TEST_ARG;
  57187. #endif
  57188. #ifndef NO_WOLFSSL_SERVER
  57189. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  57190. #else
  57191. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  57192. #endif
  57193. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  57194. WOLFSSL_FILETYPE_PEM));
  57195. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  57196. WOLFSSL_FILETYPE_PEM));
  57197. ExpectTrue(wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TLSv1)
  57198. == WOLFSSL_OP_NO_TLSv1);
  57199. ExpectTrue(wolfSSL_CTX_get_options(ctx) == WOLFSSL_OP_NO_TLSv1);
  57200. ExpectIntGT((int)wolfSSL_CTX_set_options(ctx, (WOLFSSL_OP_COOKIE_EXCHANGE |
  57201. WOLFSSL_OP_NO_SSLv2)), 0);
  57202. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_COOKIE_EXCHANGE) &
  57203. WOLFSSL_OP_COOKIE_EXCHANGE) == WOLFSSL_OP_COOKIE_EXCHANGE);
  57204. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TLSv1_2) &
  57205. WOLFSSL_OP_NO_TLSv1_2) == WOLFSSL_OP_NO_TLSv1_2);
  57206. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_COMPRESSION) &
  57207. WOLFSSL_OP_NO_COMPRESSION) == WOLFSSL_OP_NO_COMPRESSION);
  57208. ExpectFalse((wolfSSL_CTX_clear_options(ctx, WOLFSSL_OP_NO_COMPRESSION) &
  57209. WOLFSSL_OP_NO_COMPRESSION));
  57210. wolfSSL_CTX_free(ctx);
  57211. ctx = NULL;
  57212. #ifndef NO_WOLFSSL_SERVER
  57213. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  57214. #else
  57215. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  57216. #endif
  57217. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  57218. WOLFSSL_FILETYPE_PEM));
  57219. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  57220. WOLFSSL_FILETYPE_PEM));
  57221. #ifdef OPENSSL_EXTRA
  57222. ExpectTrue(wolfSSL_CTX_set_msg_callback(ctx, msg_cb) == WOLFSSL_SUCCESS);
  57223. #endif
  57224. ExpectNotNull(ssl = wolfSSL_new(ctx));
  57225. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  57226. #ifdef HAVE_EX_DATA
  57227. ExpectIntEQ(wolfSSL_set_app_data(ssl, (void*)appData), WOLFSSL_SUCCESS);
  57228. ExpectNotNull(wolfSSL_get_app_data((const WOLFSSL*)ssl));
  57229. if (ssl != NULL) {
  57230. ExpectIntEQ(XMEMCMP(wolfSSL_get_app_data((const WOLFSSL*)ssl),
  57231. appData, sizeof(appData)), 0);
  57232. }
  57233. #else
  57234. ExpectIntEQ(wolfSSL_set_app_data(ssl, (void*)appData), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57235. ExpectNull(wolfSSL_get_app_data((const WOLFSSL*)ssl));
  57236. #endif
  57237. #endif
  57238. ExpectTrue(wolfSSL_set_options(ssl, WOLFSSL_OP_NO_TLSv1) ==
  57239. WOLFSSL_OP_NO_TLSv1);
  57240. ExpectTrue(wolfSSL_get_options(ssl) == WOLFSSL_OP_NO_TLSv1);
  57241. ExpectIntGT((int)wolfSSL_set_options(ssl, (WOLFSSL_OP_COOKIE_EXCHANGE |
  57242. WOLFSSL_OP_NO_SSLv2)), 0);
  57243. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_COOKIE_EXCHANGE) &
  57244. WOLFSSL_OP_COOKIE_EXCHANGE) == WOLFSSL_OP_COOKIE_EXCHANGE);
  57245. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_NO_TLSv1_2) &
  57246. WOLFSSL_OP_NO_TLSv1_2) == WOLFSSL_OP_NO_TLSv1_2);
  57247. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_NO_COMPRESSION) &
  57248. WOLFSSL_OP_NO_COMPRESSION) == WOLFSSL_OP_NO_COMPRESSION);
  57249. #ifdef OPENSSL_EXTRA
  57250. ExpectFalse((wolfSSL_clear_options(ssl, WOLFSSL_OP_NO_COMPRESSION) &
  57251. WOLFSSL_OP_NO_COMPRESSION));
  57252. #endif
  57253. #ifdef OPENSSL_EXTRA
  57254. ExpectTrue(wolfSSL_set_msg_callback(ssl, msg_cb) == WOLFSSL_SUCCESS);
  57255. wolfSSL_set_msg_callback_arg(ssl, arg);
  57256. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  57257. ExpectTrue(wolfSSL_CTX_set_alpn_protos(ctx, protos, len) == 0);
  57258. #else
  57259. ExpectTrue(wolfSSL_CTX_set_alpn_protos(ctx, protos, len) == WOLFSSL_SUCCESS);
  57260. #endif
  57261. #endif
  57262. #if defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \
  57263. defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(OPENSSL_ALL) || \
  57264. defined(HAVE_LIGHTY) || defined(HAVE_STUNNEL)
  57265. #if defined(HAVE_ALPN) && !defined(NO_BIO)
  57266. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  57267. ExpectTrue(wolfSSL_set_alpn_protos(ssl, protos, len) == 0);
  57268. #else
  57269. ExpectTrue(wolfSSL_set_alpn_protos(ssl, protos, len) == WOLFSSL_SUCCESS);
  57270. #endif
  57271. #endif /* HAVE_ALPN && !NO_BIO */
  57272. #endif
  57273. wolfSSL_free(ssl);
  57274. wolfSSL_CTX_free(ctx);
  57275. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  57276. #endif /* !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  57277. return EXPECT_RESULT();
  57278. }
  57279. static int test_wolfSSL_sk_SSL_CIPHER(void)
  57280. {
  57281. EXPECT_DECLS;
  57282. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  57283. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  57284. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  57285. SSL* ssl = NULL;
  57286. SSL_CTX* ctx = NULL;
  57287. STACK_OF(SSL_CIPHER) *sk = NULL;
  57288. STACK_OF(SSL_CIPHER) *dupSk = NULL;
  57289. #ifndef NO_WOLFSSL_SERVER
  57290. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  57291. #else
  57292. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  57293. #endif
  57294. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile, SSL_FILETYPE_PEM));
  57295. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  57296. ExpectNotNull(ssl = SSL_new(ctx));
  57297. ExpectNotNull(sk = SSL_get_ciphers(ssl));
  57298. ExpectNotNull(dupSk = sk_SSL_CIPHER_dup(sk));
  57299. ExpectIntGT(sk_SSL_CIPHER_num(sk), 0);
  57300. ExpectIntEQ(sk_SSL_CIPHER_num(sk), sk_SSL_CIPHER_num(dupSk));
  57301. /* error case because connection has not been established yet */
  57302. ExpectIntEQ(sk_SSL_CIPHER_find(sk, SSL_get_current_cipher(ssl)), -1);
  57303. sk_SSL_CIPHER_free(dupSk);
  57304. /* sk is pointer to internal struct that should be free'd in SSL_free */
  57305. SSL_free(ssl);
  57306. SSL_CTX_free(ctx);
  57307. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  57308. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  57309. !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  57310. return EXPECT_RESULT();
  57311. }
  57312. static int test_wolfSSL_set1_curves_list(void)
  57313. {
  57314. EXPECT_DECLS;
  57315. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  57316. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  57317. SSL* ssl = NULL;
  57318. SSL_CTX* ctx = NULL;
  57319. #ifndef NO_WOLFSSL_SERVER
  57320. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  57321. #else
  57322. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  57323. #endif
  57324. ExpectTrue(SSL_CTX_use_certificate_file(ctx, eccCertFile,
  57325. SSL_FILETYPE_PEM));
  57326. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, eccKeyFile, SSL_FILETYPE_PEM));
  57327. ExpectNotNull(ssl = SSL_new(ctx));
  57328. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57329. #ifdef HAVE_ECC
  57330. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "P-25X"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57331. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "P-256"), WOLFSSL_SUCCESS);
  57332. #endif
  57333. #ifdef HAVE_CURVE25519
  57334. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X25519"), WOLFSSL_SUCCESS);
  57335. #else
  57336. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X25519"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57337. #endif
  57338. #ifdef HAVE_CURVE448
  57339. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X448"), WOLFSSL_SUCCESS);
  57340. #else
  57341. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X448"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57342. #endif
  57343. ExpectIntEQ(SSL_set1_curves_list(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57344. #ifdef HAVE_ECC
  57345. ExpectIntEQ(SSL_set1_curves_list(ssl, "P-25X"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57346. ExpectIntEQ(SSL_set1_curves_list(ssl, "P-256"), WOLFSSL_SUCCESS);
  57347. #endif
  57348. #ifdef HAVE_CURVE25519
  57349. ExpectIntEQ(SSL_set1_curves_list(ssl, "X25519"), WOLFSSL_SUCCESS);
  57350. #else
  57351. ExpectIntEQ(SSL_set1_curves_list(ssl, "X25519"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57352. #endif
  57353. #ifdef HAVE_CURVE448
  57354. ExpectIntEQ(SSL_set1_curves_list(ssl, "X448"), WOLFSSL_SUCCESS);
  57355. #else
  57356. ExpectIntEQ(SSL_set1_curves_list(ssl, "X448"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57357. #endif
  57358. SSL_free(ssl);
  57359. SSL_CTX_free(ctx);
  57360. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  57361. #endif
  57362. return EXPECT_RESULT();
  57363. }
  57364. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  57365. (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && defined(HAVE_ECC)
  57366. static int test_wolfSSL_curves_mismatch_ctx_ready(WOLFSSL_CTX* ctx)
  57367. {
  57368. static int counter = 0;
  57369. EXPECT_DECLS;
  57370. if (counter % 2) {
  57371. ExpectIntEQ(wolfSSL_CTX_set1_curves_list(ctx, "P-256"),
  57372. WOLFSSL_SUCCESS);
  57373. }
  57374. else {
  57375. ExpectIntEQ(wolfSSL_CTX_set1_curves_list(ctx, "P-384"),
  57376. WOLFSSL_SUCCESS);
  57377. }
  57378. /* Ciphersuites that require curves */
  57379. wolfSSL_CTX_set_cipher_list(ctx, "TLS13-AES256-GCM-SHA384:"
  57380. "TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES128-GCM-SHA256:"
  57381. "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:"
  57382. "ECDHE-ECDSA-AES128-GCM-SHA256:"
  57383. "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305:"
  57384. "ECDHE-ECDSA-CHACHA20-POLY1305");
  57385. counter++;
  57386. return EXPECT_RESULT();
  57387. }
  57388. #endif
  57389. static int test_wolfSSL_curves_mismatch(void)
  57390. {
  57391. EXPECT_DECLS;
  57392. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  57393. (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && defined(HAVE_ECC)
  57394. test_ssl_cbf func_cb_client;
  57395. test_ssl_cbf func_cb_server;
  57396. size_t i;
  57397. struct {
  57398. method_provider client_meth;
  57399. method_provider server_meth;
  57400. const char* desc;
  57401. int client_last_err;
  57402. int server_last_err;
  57403. } test_params[] = {
  57404. #ifdef WOLFSSL_TLS13
  57405. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLS 1.3",
  57406. WC_NO_ERR_TRACE(FATAL_ERROR), WC_NO_ERR_TRACE(BAD_KEY_SHARE_DATA)},
  57407. #endif
  57408. #ifndef WOLFSSL_NO_TLS12
  57409. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLS 1.2",
  57410. WC_NO_ERR_TRACE(FATAL_ERROR),
  57411. #ifdef OPENSSL_EXTRA
  57412. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL)
  57413. #else
  57414. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR)
  57415. #endif
  57416. },
  57417. #endif
  57418. #ifndef NO_OLD_TLS
  57419. {wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLS 1.1",
  57420. WC_NO_ERR_TRACE(FATAL_ERROR),
  57421. #ifdef OPENSSL_EXTRA
  57422. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL)
  57423. #else
  57424. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR)
  57425. #endif
  57426. },
  57427. #endif
  57428. };
  57429. for (i = 0; i < XELEM_CNT(test_params) && !EXPECT_FAIL(); i++) {
  57430. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  57431. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  57432. printf("\tTesting with %s...\n", test_params[i].desc);
  57433. func_cb_client.ctx_ready = &test_wolfSSL_curves_mismatch_ctx_ready;
  57434. func_cb_server.ctx_ready = &test_wolfSSL_curves_mismatch_ctx_ready;
  57435. func_cb_client.method = test_params[i].client_meth;
  57436. func_cb_server.method = test_params[i].server_meth;
  57437. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  57438. &func_cb_server, NULL), -1001);
  57439. ExpectIntEQ(func_cb_client.last_err, test_params[i].client_last_err);
  57440. ExpectIntEQ(func_cb_server.last_err, test_params[i].server_last_err);
  57441. if (!EXPECT_SUCCESS())
  57442. break;
  57443. printf("\t%s passed\n", test_params[i].desc);
  57444. }
  57445. #endif
  57446. return EXPECT_RESULT();
  57447. }
  57448. static int test_wolfSSL_set1_sigalgs_list(void)
  57449. {
  57450. EXPECT_DECLS;
  57451. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  57452. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  57453. SSL* ssl = NULL;
  57454. SSL_CTX* ctx = NULL;
  57455. #ifndef NO_WOLFSSL_SERVER
  57456. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  57457. #else
  57458. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  57459. #endif
  57460. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  57461. SSL_FILETYPE_PEM));
  57462. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  57463. ExpectNotNull(ssl = SSL_new(ctx));
  57464. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57465. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57466. ExpectIntEQ(wolfSSL_set1_sigalgs_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57467. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57468. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, ""), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57469. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, ""), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57470. #ifndef NO_RSA
  57471. #ifndef NO_SHA256
  57472. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(NULL, "RSA+SHA256"),
  57473. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57474. ExpectIntEQ(wolfSSL_set1_sigalgs_list(NULL, "RSA+SHA256"),
  57475. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57476. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA+SHA256"),
  57477. WOLFSSL_SUCCESS);
  57478. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA+SHA256"),
  57479. WOLFSSL_SUCCESS);
  57480. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA-SHA256"),
  57481. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57482. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA-SHA256"),
  57483. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57484. #ifdef WC_RSA_PSS
  57485. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA-PSS+SHA256"),
  57486. WOLFSSL_SUCCESS);
  57487. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA-PSS+SHA256"),
  57488. WOLFSSL_SUCCESS);
  57489. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "PSS+SHA256"),
  57490. WOLFSSL_SUCCESS);
  57491. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "PSS+SHA256"),
  57492. WOLFSSL_SUCCESS);
  57493. #endif
  57494. #ifdef WOLFSSL_SHA512
  57495. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  57496. "RSA+SHA256:RSA+SHA512"), WOLFSSL_SUCCESS);
  57497. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  57498. "RSA+SHA256:RSA+SHA512"), WOLFSSL_SUCCESS);
  57499. #elif defined(WOLFSSL_SHA384)
  57500. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  57501. "RSA+SHA256:RSA+SHA384"), WOLFSSL_SUCCESS);
  57502. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  57503. "RSA+SHA256:RSA+SHA384"), WOLFSSL_SUCCESS);
  57504. #endif
  57505. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57506. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57507. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA:RSA+SHA256"),
  57508. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57509. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA:RSA+SHA256"),
  57510. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57511. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA+SHA256+SHA256"),
  57512. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57513. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA+SHA256+RSA"),
  57514. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57515. #endif
  57516. #endif
  57517. #ifdef HAVE_ECC
  57518. #ifndef NO_SHA256
  57519. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ECDSA+SHA256"),
  57520. WOLFSSL_SUCCESS);
  57521. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ECDSA+SHA256"),
  57522. WOLFSSL_SUCCESS);
  57523. #ifdef WOLFSSL_SHA512
  57524. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  57525. "ECDSA+SHA256:ECDSA+SHA512"), WOLFSSL_SUCCESS);
  57526. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  57527. "ECDSA+SHA256:ECDSA+SHA512"), WOLFSSL_SUCCESS);
  57528. #elif defined(WOLFSSL_SHA384)
  57529. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  57530. "ECDSA+SHA256:ECDSA+SHA384"), WOLFSSL_SUCCESS);
  57531. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  57532. "ECDSA+SHA256:ECDSA+SHA384"), WOLFSSL_SUCCESS);
  57533. #endif
  57534. #endif
  57535. #endif
  57536. #ifdef HAVE_ED25519
  57537. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ED25519"), WOLFSSL_SUCCESS);
  57538. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ED25519"), WOLFSSL_SUCCESS);
  57539. #endif
  57540. #ifdef HAVE_ED448
  57541. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ED448"), WOLFSSL_SUCCESS);
  57542. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ED448"), WOLFSSL_SUCCESS);
  57543. #endif
  57544. #ifndef NO_DSA
  57545. #ifndef NO_SHA256
  57546. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "DSA+SHA256"),
  57547. WOLFSSL_SUCCESS);
  57548. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "DSA+SHA256"),
  57549. WOLFSSL_SUCCESS);
  57550. #endif
  57551. #if !defined(NO_SHA) && (!defined(NO_OLD_TLS) || \
  57552. defined(WOLFSSL_ALLOW_TLS_SHA1))
  57553. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "DSA+SHA1"),
  57554. WOLFSSL_SUCCESS);
  57555. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "DSA+SHA1"),
  57556. WOLFSSL_SUCCESS);
  57557. #endif
  57558. #endif
  57559. SSL_free(ssl);
  57560. SSL_CTX_free(ctx);
  57561. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  57562. #endif
  57563. return EXPECT_RESULT();
  57564. }
  57565. /* Testing wolfSSL_set_tlsext_status_type function.
  57566. * PRE: OPENSSL and HAVE_CERTIFICATE_STATUS_REQUEST defined.
  57567. */
  57568. static int test_wolfSSL_set_tlsext_status_type(void)
  57569. {
  57570. EXPECT_DECLS;
  57571. #if defined(OPENSSL_EXTRA) && defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  57572. !defined(NO_RSA) && !defined(NO_WOLFSSL_SERVER)
  57573. SSL* ssl = NULL;
  57574. SSL_CTX* ctx = NULL;
  57575. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  57576. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  57577. SSL_FILETYPE_PEM));
  57578. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  57579. ExpectNotNull(ssl = SSL_new(ctx));
  57580. ExpectIntEQ(SSL_set_tlsext_status_type(ssl,TLSEXT_STATUSTYPE_ocsp),
  57581. SSL_SUCCESS);
  57582. ExpectIntEQ(SSL_get_tlsext_status_type(ssl), TLSEXT_STATUSTYPE_ocsp);
  57583. SSL_free(ssl);
  57584. SSL_CTX_free(ctx);
  57585. #endif /* OPENSSL_EXTRA && HAVE_CERTIFICATE_STATUS_REQUEST && !NO_RSA */
  57586. return EXPECT_RESULT();
  57587. }
  57588. #ifndef NO_BIO
  57589. static int test_wolfSSL_PEM_read_bio(void)
  57590. {
  57591. EXPECT_DECLS;
  57592. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  57593. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  57594. byte buff[6000];
  57595. XFILE f = XBADFILE;
  57596. int bytes = 0;
  57597. X509* x509 = NULL;
  57598. BIO* bio = NULL;
  57599. BUF_MEM* buf = NULL;
  57600. ExpectTrue((f = XFOPEN(cliCertFile, "rb")) != XBADFILE);
  57601. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  57602. if (f != XBADFILE)
  57603. XFCLOSE(f);
  57604. ExpectNull(x509 = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  57605. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  57606. ExpectIntEQ(BIO_set_mem_eof_return(bio, -0xDEAD), 1);
  57607. ExpectNotNull(x509 = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  57608. ExpectIntEQ((int)BIO_set_fd(bio, 0, BIO_CLOSE), 1);
  57609. /* BIO should return the set EOF value */
  57610. ExpectIntEQ(BIO_read(bio, buff, sizeof(buff)), -0xDEAD);
  57611. ExpectIntEQ(BIO_set_close(bio, BIO_NOCLOSE), 1);
  57612. ExpectIntEQ(BIO_set_close(NULL, BIO_NOCLOSE), 1);
  57613. ExpectIntEQ(SSL_SUCCESS, BIO_get_mem_ptr(bio, &buf));
  57614. BIO_free(bio);
  57615. BUF_MEM_free(buf);
  57616. X509_free(x509);
  57617. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  57618. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  57619. return EXPECT_RESULT();
  57620. }
  57621. #if defined(OPENSSL_EXTRA)
  57622. static long bioCallback(BIO *bio, int cmd, const char* argp, int argi,
  57623. long argl, long ret)
  57624. {
  57625. (void)bio;
  57626. (void)cmd;
  57627. (void)argp;
  57628. (void)argi;
  57629. (void)argl;
  57630. return ret;
  57631. }
  57632. #endif
  57633. static int test_wolfSSL_BIO(void)
  57634. {
  57635. EXPECT_DECLS;
  57636. #if defined(OPENSSL_EXTRA)
  57637. const unsigned char* p = NULL;
  57638. byte buff[20];
  57639. BIO* bio1 = NULL;
  57640. BIO* bio2 = NULL;
  57641. BIO* bio3 = NULL;
  57642. char* bufPt = NULL;
  57643. int i;
  57644. for (i = 0; i < 20; i++) {
  57645. buff[i] = i;
  57646. }
  57647. /* test BIO_free with NULL */
  57648. ExpectIntEQ(BIO_free(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57649. /* Creating and testing type BIO_s_bio */
  57650. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  57651. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  57652. ExpectNotNull(bio3 = BIO_new(BIO_s_bio()));
  57653. /* read/write before set up */
  57654. ExpectIntEQ(BIO_read(bio1, buff, 2), WOLFSSL_BIO_UNSET);
  57655. ExpectIntEQ(BIO_write(bio1, buff, 2), WOLFSSL_BIO_UNSET);
  57656. ExpectIntEQ(BIO_set_nbio(bio1, 1), 1);
  57657. ExpectIntEQ(BIO_set_write_buf_size(bio1, 20), WOLFSSL_SUCCESS);
  57658. ExpectIntEQ(BIO_set_write_buf_size(bio2, 8), WOLFSSL_SUCCESS);
  57659. ExpectIntEQ(BIO_make_bio_pair(bio1, bio2), WOLFSSL_SUCCESS);
  57660. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 10), 10);
  57661. ExpectNotNull(XMEMCPY(bufPt, buff, 10));
  57662. ExpectIntEQ(BIO_write(bio1, buff + 10, 10), 10);
  57663. /* write buffer full */
  57664. ExpectIntEQ(BIO_write(bio1, buff, 10), WOLFSSL_BIO_ERROR);
  57665. ExpectIntEQ(BIO_flush(bio1), WOLFSSL_SUCCESS);
  57666. ExpectIntEQ((int)BIO_ctrl_pending(bio1), 0);
  57667. /* write the other direction with pair */
  57668. ExpectIntEQ((int)BIO_nwrite(bio2, &bufPt, 10), 8);
  57669. ExpectNotNull(XMEMCPY(bufPt, buff, 8));
  57670. ExpectIntEQ(BIO_write(bio2, buff, 10), WOLFSSL_BIO_ERROR);
  57671. /* try read */
  57672. ExpectIntEQ((int)BIO_ctrl_pending(bio1), 8);
  57673. ExpectIntEQ((int)BIO_ctrl_pending(bio2), 20);
  57674. /* try read using ctrl function */
  57675. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_WPENDING, 0, NULL), 8);
  57676. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_PENDING, 0, NULL), 8);
  57677. ExpectIntEQ((int)BIO_ctrl(bio2, BIO_CTRL_WPENDING, 0, NULL), 20);
  57678. ExpectIntEQ((int)BIO_ctrl(bio2, BIO_CTRL_PENDING, 0, NULL), 20);
  57679. ExpectIntEQ(BIO_nread(bio2, &bufPt, (int)BIO_ctrl_pending(bio2)), 20);
  57680. for (i = 0; i < 20; i++) {
  57681. ExpectIntEQ((int)bufPt[i], i);
  57682. }
  57683. ExpectIntEQ(BIO_nread(bio2, &bufPt, 1), 0);
  57684. ExpectIntEQ(BIO_nread(bio1, &bufPt, (int)BIO_ctrl_pending(bio1)), 8);
  57685. for (i = 0; i < 8; i++) {
  57686. ExpectIntEQ((int)bufPt[i], i);
  57687. }
  57688. ExpectIntEQ(BIO_nread(bio1, &bufPt, 1), 0);
  57689. ExpectIntEQ(BIO_ctrl_reset_read_request(bio1), 1);
  57690. /* new pair */
  57691. ExpectIntEQ(BIO_make_bio_pair(bio1, bio3), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57692. BIO_free(bio2); /* free bio2 and automatically remove from pair */
  57693. bio2 = NULL;
  57694. ExpectIntEQ(BIO_make_bio_pair(bio1, bio3), WOLFSSL_SUCCESS);
  57695. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 0);
  57696. ExpectIntEQ(BIO_nread(bio3, &bufPt, 10), 0);
  57697. /* test wrap around... */
  57698. ExpectIntEQ(BIO_reset(bio1), 1);
  57699. ExpectIntEQ(BIO_reset(bio3), 1);
  57700. /* fill write buffer, read only small amount then write again */
  57701. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  57702. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  57703. ExpectIntEQ(BIO_nread(bio3, &bufPt, 4), 4);
  57704. for (i = 0; i < 4; i++) {
  57705. ExpectIntEQ(bufPt[i], i);
  57706. }
  57707. /* try writing over read index */
  57708. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 5), 4);
  57709. ExpectNotNull(XMEMSET(bufPt, 0, 4));
  57710. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 20);
  57711. /* read and write 0 bytes */
  57712. ExpectIntEQ(BIO_nread(bio3, &bufPt, 0), 0);
  57713. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 0), 0);
  57714. /* should read only to end of write buffer then need to read again */
  57715. ExpectIntEQ(BIO_nread(bio3, &bufPt, 20), 16);
  57716. for (i = 0; i < 16; i++) {
  57717. ExpectIntEQ(bufPt[i], buff[4 + i]);
  57718. }
  57719. ExpectIntEQ(BIO_nread(bio3, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57720. ExpectIntEQ(BIO_nread0(bio3, &bufPt), 4);
  57721. for (i = 0; i < 4; i++) {
  57722. ExpectIntEQ(bufPt[i], 0);
  57723. }
  57724. /* read index should not have advanced with nread0 */
  57725. ExpectIntEQ(BIO_nread(bio3, &bufPt, 5), 4);
  57726. for (i = 0; i < 4; i++) {
  57727. ExpectIntEQ(bufPt[i], 0);
  57728. }
  57729. /* write and fill up buffer checking reset of index state */
  57730. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  57731. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  57732. /* test reset on data in bio1 write buffer */
  57733. ExpectIntEQ(BIO_reset(bio1), 1);
  57734. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 0);
  57735. ExpectIntEQ(BIO_nread(bio3, &bufPt, 3), 0);
  57736. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  57737. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_INFO, 0, &p), 20);
  57738. ExpectNotNull(p);
  57739. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  57740. ExpectIntEQ(BIO_nread(bio3, &bufPt, 6), 6);
  57741. for (i = 0; i < 6; i++) {
  57742. ExpectIntEQ(bufPt[i], i);
  57743. }
  57744. /* test case of writing twice with offset read index */
  57745. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 3), 3);
  57746. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), 3); /* try overwriting */
  57747. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  57748. ExpectIntEQ(BIO_nread(bio3, &bufPt, 0), 0);
  57749. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  57750. ExpectIntEQ(BIO_nread(bio3, &bufPt, 1), 1);
  57751. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), 1);
  57752. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  57753. BIO_free(bio1);
  57754. bio1 = NULL;
  57755. BIO_free(bio3);
  57756. bio3 = NULL;
  57757. #if defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)
  57758. {
  57759. BIO* bioA = NULL;
  57760. BIO* bioB = NULL;
  57761. ExpectIntEQ(BIO_new_bio_pair(NULL, 256, NULL, 256), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  57762. ExpectIntEQ(BIO_new_bio_pair(&bioA, 256, &bioB, 256), WOLFSSL_SUCCESS);
  57763. BIO_free(bioA);
  57764. bioA = NULL;
  57765. BIO_free(bioB);
  57766. bioB = NULL;
  57767. }
  57768. #endif /* OPENSSL_ALL || WOLFSSL_ASIO */
  57769. /* BIOs with file pointers */
  57770. #if !defined(NO_FILESYSTEM)
  57771. {
  57772. XFILE f1 = XBADFILE;
  57773. XFILE f2 = XBADFILE;
  57774. BIO* f_bio1 = NULL;
  57775. BIO* f_bio2 = NULL;
  57776. unsigned char cert[300];
  57777. char testFile[] = "tests/bio_write_test.txt";
  57778. char msg[] = "bio_write_test.txt contains the first 300 bytes of certs/server-cert.pem\ncreated by tests/unit.test\n\n";
  57779. ExpectNotNull(f_bio1 = BIO_new(BIO_s_file()));
  57780. ExpectNotNull(f_bio2 = BIO_new(BIO_s_file()));
  57781. /* Failure due to wrong BIO type */
  57782. ExpectIntEQ((int)BIO_set_mem_eof_return(f_bio1, -1), 0);
  57783. ExpectIntEQ((int)BIO_set_mem_eof_return(NULL, -1), 0);
  57784. ExpectTrue((f1 = XFOPEN(svrCertFile, "rwb")) != XBADFILE);
  57785. ExpectIntEQ((int)BIO_set_fp(f_bio1, f1, BIO_CLOSE), WOLFSSL_SUCCESS);
  57786. ExpectIntEQ(BIO_write_filename(f_bio2, testFile),
  57787. WOLFSSL_SUCCESS);
  57788. ExpectIntEQ(BIO_read(f_bio1, cert, sizeof(cert)), sizeof(cert));
  57789. ExpectIntEQ(BIO_tell(f_bio1),sizeof(cert));
  57790. ExpectIntEQ(BIO_write(f_bio2, msg, sizeof(msg)), sizeof(msg));
  57791. ExpectIntEQ(BIO_tell(f_bio2),sizeof(msg));
  57792. ExpectIntEQ(BIO_write(f_bio2, cert, sizeof(cert)), sizeof(cert));
  57793. ExpectIntEQ(BIO_tell(f_bio2),sizeof(cert) + sizeof(msg));
  57794. ExpectIntEQ((int)BIO_get_fp(f_bio2, &f2), WOLFSSL_SUCCESS);
  57795. ExpectIntEQ(BIO_reset(f_bio2), 1);
  57796. ExpectIntEQ(BIO_tell(NULL),-1);
  57797. ExpectIntEQ(BIO_tell(f_bio2),0);
  57798. ExpectIntEQ(BIO_seek(f_bio2, 4), 0);
  57799. ExpectIntEQ(BIO_tell(f_bio2),4);
  57800. BIO_free(f_bio1);
  57801. f_bio1 = NULL;
  57802. BIO_free(f_bio2);
  57803. f_bio2 = NULL;
  57804. ExpectNotNull(f_bio1 = BIO_new_file(svrCertFile, "rwb"));
  57805. ExpectIntEQ((int)BIO_set_mem_eof_return(f_bio1, -1), 0);
  57806. ExpectIntEQ(BIO_read(f_bio1, cert, sizeof(cert)), sizeof(cert));
  57807. BIO_free(f_bio1);
  57808. f_bio1 = NULL;
  57809. }
  57810. #endif /* !defined(NO_FILESYSTEM) */
  57811. /* BIO info callback */
  57812. {
  57813. const char* testArg = "test";
  57814. BIO* cb_bio = NULL;
  57815. ExpectNotNull(cb_bio = BIO_new(BIO_s_mem()));
  57816. BIO_set_callback(cb_bio, bioCallback);
  57817. ExpectNotNull(BIO_get_callback(cb_bio));
  57818. BIO_set_callback(cb_bio, NULL);
  57819. ExpectNull(BIO_get_callback(cb_bio));
  57820. BIO_set_callback_arg(cb_bio, (char*)testArg);
  57821. ExpectStrEQ(BIO_get_callback_arg(cb_bio), testArg);
  57822. ExpectNull(BIO_get_callback_arg(NULL));
  57823. BIO_free(cb_bio);
  57824. cb_bio = NULL;
  57825. }
  57826. /* BIO_vfree */
  57827. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  57828. BIO_vfree(NULL);
  57829. BIO_vfree(bio1);
  57830. #endif
  57831. return EXPECT_RESULT();
  57832. }
  57833. static int test_wolfSSL_BIO_BIO_ring_read(void)
  57834. {
  57835. EXPECT_DECLS;
  57836. #if defined(OPENSSL_ALL)
  57837. BIO* bio1 = NULL;
  57838. BIO* bio2 = NULL;
  57839. byte data[50];
  57840. byte tmp[50];
  57841. XMEMSET(data, 42, sizeof(data));
  57842. ExpectIntEQ(BIO_new_bio_pair(&bio1, sizeof(data), &bio2, sizeof(data)),
  57843. SSL_SUCCESS);
  57844. ExpectIntEQ(BIO_write(bio1, data, 40), 40);
  57845. ExpectIntEQ(BIO_read(bio1, tmp, 20), -1);
  57846. ExpectIntEQ(BIO_read(bio2, tmp, 20), 20);
  57847. ExpectBufEQ(tmp, data, 20);
  57848. ExpectIntEQ(BIO_write(bio1, data, 20), 20);
  57849. ExpectIntEQ(BIO_read(bio2, tmp, 40), 40);
  57850. ExpectBufEQ(tmp, data, 40);
  57851. BIO_free(bio1);
  57852. BIO_free(bio2);
  57853. #endif
  57854. return EXPECT_RESULT();
  57855. }
  57856. #endif /* !NO_BIO */
  57857. static int test_wolfSSL_a2i_IPADDRESS(void)
  57858. {
  57859. EXPECT_DECLS;
  57860. #if defined(OPENSSL_ALL) && !defined(WOLFSSL_USER_IO)
  57861. const unsigned char* data = NULL;
  57862. int dataSz = 0;
  57863. ASN1_OCTET_STRING *st = NULL;
  57864. const unsigned char ipv4_exp[] = {0x7F, 0, 0, 1};
  57865. const unsigned char ipv6_exp[] = {
  57866. 0x20, 0x21, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
  57867. 0x00, 0x00, 0xff, 0x00, 0x00, 0x42, 0x77, 0x77
  57868. };
  57869. const unsigned char ipv6_home[] = {
  57870. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  57871. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
  57872. };
  57873. ExpectNull(st = a2i_IPADDRESS("127.0.0.1bad"));
  57874. ExpectNotNull(st = a2i_IPADDRESS("127.0.0.1"));
  57875. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  57876. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP4_ADDR_LEN);
  57877. ExpectIntEQ(XMEMCMP(data, ipv4_exp, dataSz), 0);
  57878. ASN1_STRING_free(st);
  57879. st = NULL;
  57880. ExpectNotNull(st = a2i_IPADDRESS("::1"));
  57881. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  57882. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP6_ADDR_LEN);
  57883. ExpectIntEQ(XMEMCMP(data, ipv6_home, dataSz), 0);
  57884. ASN1_STRING_free(st);
  57885. st = NULL;
  57886. ExpectNotNull(st = a2i_IPADDRESS("2021:db8::ff00:42:7777"));
  57887. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  57888. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP6_ADDR_LEN);
  57889. ExpectIntEQ(XMEMCMP(data, ipv6_exp, dataSz), 0);
  57890. ASN1_STRING_free(st);
  57891. #endif
  57892. return EXPECT_RESULT();
  57893. }
  57894. static int test_wolfSSL_X509_cmp_time(void)
  57895. {
  57896. EXPECT_DECLS;
  57897. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) \
  57898. && !defined(USER_TIME) && !defined(TIME_OVERRIDES)
  57899. WOLFSSL_ASN1_TIME asn_time;
  57900. time_t t;
  57901. ExpectIntEQ(0, wolfSSL_X509_cmp_time(NULL, &t));
  57902. XMEMSET(&asn_time, 0, sizeof(WOLFSSL_ASN1_TIME));
  57903. ExpectIntEQ(0, wolfSSL_X509_cmp_time(&asn_time, &t));
  57904. ExpectIntEQ(ASN1_TIME_set_string(&asn_time, "000222211515Z"), 1);
  57905. ExpectIntEQ(-1, wolfSSL_X509_cmp_time(&asn_time, NULL));
  57906. #endif
  57907. return EXPECT_RESULT();
  57908. }
  57909. static int test_wolfSSL_X509_time_adj(void)
  57910. {
  57911. EXPECT_DECLS;
  57912. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && \
  57913. !defined(USER_TIME) && !defined(TIME_OVERRIDES) && \
  57914. defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA) && \
  57915. !defined(NO_ASN_TIME)
  57916. X509* x509 = NULL;
  57917. time_t t;
  57918. time_t not_before;
  57919. time_t not_after;
  57920. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  57921. client_cert_der_2048, sizeof_client_cert_der_2048,
  57922. WOLFSSL_FILETYPE_ASN1));
  57923. t = 0;
  57924. not_before = wc_Time(0);
  57925. not_after = wc_Time(0) + (60 * 24 * 30); /* 30 days after */
  57926. ExpectNotNull(X509_time_adj(X509_get_notBefore(x509), not_before, &t));
  57927. ExpectNotNull(X509_time_adj(X509_get_notAfter(x509), not_after, &t));
  57928. /* Check X509_gmtime_adj, too. */
  57929. ExpectNotNull(X509_gmtime_adj(X509_get_notAfter(x509), not_after));
  57930. X509_free(x509);
  57931. #endif
  57932. return EXPECT_RESULT();
  57933. }
  57934. static int test_wolfSSL_X509_bad_altname(void)
  57935. {
  57936. EXPECT_DECLS;
  57937. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  57938. const unsigned char malformed_alt_name_cert[] = {
  57939. 0x30, 0x82, 0x02, 0xf9, 0x30, 0x82, 0x01, 0xe1, 0xa0, 0x03, 0x02, 0x01,
  57940. 0x02, 0x02, 0x02, 0x10, 0x21, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  57941. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x0f, 0x31, 0x0d,
  57942. 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04, 0x61, 0x61, 0x31,
  57943. 0x31, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x32, 0x30, 0x37, 0x31,
  57944. 0x37, 0x32, 0x34, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x33, 0x34, 0x30, 0x32,
  57945. 0x31, 0x34, 0x30, 0x36, 0x32, 0x36, 0x35, 0x33, 0x5a, 0x30, 0x0f, 0x31,
  57946. 0x0d, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04, 0x61, 0x61,
  57947. 0x61, 0x61, 0x30, 0x82, 0x01, 0x20, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
  57948. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01,
  57949. 0x0d, 0x00, 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01, 0x00, 0xa8,
  57950. 0x8a, 0x5e, 0x26, 0x23, 0x1b, 0x31, 0xd3, 0x37, 0x1a, 0x70, 0xb2, 0xec,
  57951. 0x3f, 0x74, 0xd4, 0xb4, 0x44, 0xe3, 0x7a, 0xa5, 0xc0, 0xf5, 0xaa, 0x97,
  57952. 0x26, 0x9a, 0x04, 0xff, 0xda, 0xbe, 0xe5, 0x09, 0x03, 0x98, 0x3d, 0xb5,
  57953. 0xbf, 0x01, 0x2c, 0x9a, 0x0a, 0x3a, 0xfb, 0xbc, 0x3c, 0xe7, 0xbe, 0x83,
  57954. 0x5c, 0xb3, 0x70, 0xe8, 0x5c, 0xe3, 0xd1, 0x83, 0xc3, 0x94, 0x08, 0xcd,
  57955. 0x1a, 0x87, 0xe5, 0xe0, 0x5b, 0x9c, 0x5c, 0x6e, 0xb0, 0x7d, 0xe2, 0x58,
  57956. 0x6c, 0xc3, 0xb5, 0xc8, 0x9d, 0x11, 0xf1, 0x5d, 0x96, 0x0d, 0x66, 0x1e,
  57957. 0x56, 0x7f, 0x8f, 0x59, 0xa7, 0xa5, 0xe1, 0xc5, 0xe7, 0x81, 0x4c, 0x09,
  57958. 0x9d, 0x5e, 0x96, 0xf0, 0x9a, 0xc2, 0x8b, 0x70, 0xd5, 0xab, 0x79, 0x58,
  57959. 0x5d, 0xb7, 0x58, 0xaa, 0xfd, 0x75, 0x52, 0xaa, 0x4b, 0xa7, 0x25, 0x68,
  57960. 0x76, 0x59, 0x00, 0xee, 0x78, 0x2b, 0x91, 0xc6, 0x59, 0x91, 0x99, 0x38,
  57961. 0x3e, 0xa1, 0x76, 0xc3, 0xf5, 0x23, 0x6b, 0xe6, 0x07, 0xea, 0x63, 0x1c,
  57962. 0x97, 0x49, 0xef, 0xa0, 0xfe, 0xfd, 0x13, 0xc9, 0xa9, 0x9f, 0xc2, 0x0b,
  57963. 0xe6, 0x87, 0x92, 0x5b, 0xcc, 0xf5, 0x42, 0x95, 0x4a, 0xa4, 0x6d, 0x64,
  57964. 0xba, 0x7d, 0xce, 0xcb, 0x04, 0xd0, 0xf8, 0xe7, 0xe3, 0xda, 0x75, 0x60,
  57965. 0xd3, 0x8b, 0x6a, 0x64, 0xfc, 0x78, 0x56, 0x21, 0x69, 0x5a, 0xe8, 0xa7,
  57966. 0x8f, 0xfb, 0x8f, 0x82, 0xe3, 0xae, 0x36, 0xa2, 0x93, 0x66, 0x92, 0xcb,
  57967. 0x82, 0xa3, 0xbe, 0x84, 0x00, 0x86, 0xdc, 0x7e, 0x6d, 0x53, 0x77, 0x84,
  57968. 0x17, 0xb9, 0x55, 0x43, 0x0d, 0xf1, 0x16, 0x1f, 0xd5, 0x43, 0x75, 0x99,
  57969. 0x66, 0x19, 0x52, 0xd0, 0xac, 0x5f, 0x74, 0xad, 0xb2, 0x90, 0x15, 0x50,
  57970. 0x04, 0x74, 0x43, 0xdf, 0x6c, 0x35, 0xd0, 0xfd, 0x32, 0x37, 0xb3, 0x8d,
  57971. 0xf5, 0xe5, 0x09, 0x02, 0x01, 0x03, 0xa3, 0x61, 0x30, 0x5f, 0x30, 0x0c,
  57972. 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00,
  57973. 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x08, 0x30, 0x06, 0x82,
  57974. 0x04, 0x61, 0x2a, 0x00, 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e,
  57975. 0x04, 0x16, 0x04, 0x14, 0x92, 0x6a, 0x1e, 0x52, 0x3a, 0x1a, 0x57, 0x9f,
  57976. 0xc9, 0x82, 0x9a, 0xce, 0xc8, 0xc0, 0xa9, 0x51, 0x9d, 0x2f, 0xc7, 0x72,
  57977. 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80,
  57978. 0x14, 0x6b, 0xf9, 0xa4, 0x2d, 0xa5, 0xe9, 0x39, 0x89, 0xa8, 0x24, 0x58,
  57979. 0x79, 0x87, 0x11, 0xfc, 0x6f, 0x07, 0x91, 0xef, 0xa6, 0x30, 0x0d, 0x06,
  57980. 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00,
  57981. 0x03, 0x82, 0x01, 0x01, 0x00, 0x3f, 0xd5, 0x37, 0x2f, 0xc7, 0xf8, 0x8b,
  57982. 0x39, 0x1c, 0xe3, 0xdf, 0x77, 0xee, 0xc6, 0x4b, 0x5f, 0x84, 0xcf, 0xfa,
  57983. 0x33, 0x2c, 0xb2, 0xb5, 0x4b, 0x09, 0xee, 0x56, 0xc0, 0xf2, 0xf0, 0xeb,
  57984. 0xad, 0x1c, 0x02, 0xef, 0xae, 0x09, 0x53, 0xc0, 0x06, 0xad, 0x4e, 0xfd,
  57985. 0x3e, 0x8c, 0x13, 0xb3, 0xbf, 0x80, 0x05, 0x36, 0xb5, 0x3f, 0x2b, 0xc7,
  57986. 0x60, 0x53, 0x14, 0xbf, 0x33, 0x63, 0x47, 0xc3, 0xc6, 0x28, 0xda, 0x10,
  57987. 0x12, 0xe2, 0xc4, 0xeb, 0xc5, 0x64, 0x66, 0xc0, 0xcc, 0x6b, 0x84, 0xda,
  57988. 0x0c, 0xe9, 0xf6, 0xe3, 0xf8, 0x8e, 0x3d, 0x95, 0x5f, 0xba, 0x9f, 0xe1,
  57989. 0xc7, 0xed, 0x6e, 0x97, 0xcc, 0xbd, 0x7d, 0xe5, 0x4e, 0xab, 0xbc, 0x1b,
  57990. 0xf1, 0x3a, 0x09, 0x33, 0x09, 0xe1, 0xcc, 0xec, 0x21, 0x16, 0x8e, 0xb1,
  57991. 0x74, 0x9e, 0xc8, 0x13, 0x7c, 0xdf, 0x07, 0xaa, 0xeb, 0x70, 0xd7, 0x91,
  57992. 0x5c, 0xc4, 0xef, 0x83, 0x88, 0xc3, 0xe4, 0x97, 0xfa, 0xe4, 0xdf, 0xd7,
  57993. 0x0d, 0xff, 0xba, 0x78, 0x22, 0xfc, 0x3f, 0xdc, 0xd8, 0x02, 0x8d, 0x93,
  57994. 0x57, 0xf9, 0x9e, 0x39, 0x3a, 0x77, 0x00, 0xd9, 0x19, 0xaa, 0x68, 0xa1,
  57995. 0xe6, 0x9e, 0x13, 0xeb, 0x37, 0x16, 0xf5, 0x77, 0xa4, 0x0b, 0x40, 0x04,
  57996. 0xd3, 0xa5, 0x49, 0x78, 0x35, 0xfa, 0x3b, 0xf6, 0x02, 0xab, 0x85, 0xee,
  57997. 0xcb, 0x9b, 0x62, 0xda, 0x05, 0x00, 0x22, 0x2f, 0xf8, 0xbd, 0x0b, 0xe5,
  57998. 0x2c, 0xb2, 0x53, 0x78, 0x0a, 0xcb, 0x69, 0xc0, 0xb6, 0x9f, 0x96, 0xff,
  57999. 0x58, 0x22, 0x70, 0x9c, 0x01, 0x2e, 0x56, 0x60, 0x5d, 0x37, 0xe3, 0x40,
  58000. 0x25, 0xc9, 0x90, 0xc8, 0x0f, 0x41, 0x68, 0xb4, 0xfd, 0x10, 0xe2, 0x09,
  58001. 0x99, 0x08, 0x5d, 0x7b, 0xc9, 0xe3, 0x29, 0xd4, 0x5a, 0xcf, 0xc9, 0x34,
  58002. 0x55, 0xa1, 0x40, 0x44, 0xd6, 0x88, 0x16, 0xbb, 0xdd
  58003. };
  58004. X509* x509 = NULL;
  58005. int certSize = (int)sizeof(malformed_alt_name_cert) / sizeof(unsigned char);
  58006. const char *name = "aaaaa";
  58007. int nameLen = (int)XSTRLEN(name);
  58008. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  58009. malformed_alt_name_cert, certSize, SSL_FILETYPE_ASN1));
  58010. /* malformed_alt_name_cert has a malformed alternative
  58011. * name of "a*\0*". Ensure that it does not match "aaaaa" */
  58012. ExpectIntNE(wolfSSL_X509_check_host(x509, name, nameLen,
  58013. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), 1);
  58014. X509_free(x509);
  58015. #endif
  58016. return EXPECT_RESULT();
  58017. }
  58018. static int test_wolfSSL_X509_name_match(void)
  58019. {
  58020. EXPECT_DECLS;
  58021. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  58022. /* A certificate with the subject alternative name a* */
  58023. const unsigned char cert_der[] = {
  58024. 0x30, 0x82, 0x03, 0xac, 0x30, 0x82, 0x02, 0x94, 0xa0, 0x03, 0x02, 0x01,
  58025. 0x02, 0x02, 0x14, 0x0f, 0xa5, 0x10, 0x85, 0xef, 0x58, 0x10, 0x59, 0xfc,
  58026. 0x0f, 0x20, 0x1f, 0x53, 0xf5, 0x30, 0x39, 0x34, 0x49, 0x54, 0x05, 0x30,
  58027. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  58028. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  58029. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  58030. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  58031. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  58032. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  58033. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  58034. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  58035. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  58036. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  58037. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  58038. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  58039. 0x30, 0x32, 0x30, 0x31, 0x35, 0x35, 0x38, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  58040. 0x30, 0x35, 0x32, 0x38, 0x32, 0x30, 0x31, 0x35, 0x35, 0x38, 0x5a, 0x30,
  58041. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  58042. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  58043. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  58044. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  58045. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  58046. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  58047. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  58048. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  58049. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  58050. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  58051. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  58052. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  58053. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xf4, 0xca, 0x3d,
  58054. 0xd4, 0xbc, 0x9b, 0xea, 0x74, 0xfe, 0x73, 0xf4, 0x16, 0x23, 0x0b, 0x4a,
  58055. 0x09, 0x54, 0xf6, 0x7b, 0x10, 0x99, 0x11, 0x93, 0xb2, 0xdb, 0x4d, 0x7d,
  58056. 0x23, 0xab, 0xf9, 0xcd, 0xf6, 0x54, 0xd4, 0xf6, 0x39, 0x57, 0xee, 0x97,
  58057. 0xb2, 0xb9, 0xfc, 0x7e, 0x9c, 0xb3, 0xfb, 0x56, 0xb6, 0x84, 0xd6, 0x2d,
  58058. 0x59, 0x1c, 0xed, 0xda, 0x9b, 0x19, 0xf5, 0x8a, 0xa7, 0x8a, 0x89, 0xd6,
  58059. 0xa1, 0xc0, 0xe6, 0x16, 0xad, 0x04, 0xcf, 0x5a, 0x1f, 0xdf, 0x62, 0x6c,
  58060. 0x68, 0x45, 0xe9, 0x55, 0x2e, 0x42, 0xa3, 0x1b, 0x3b, 0x86, 0x23, 0x22,
  58061. 0xa1, 0x20, 0x48, 0xd1, 0x52, 0xc0, 0x8b, 0xab, 0xe2, 0x8a, 0x15, 0x68,
  58062. 0xbd, 0x89, 0x6f, 0x9f, 0x45, 0x75, 0xb4, 0x27, 0xc1, 0x72, 0x41, 0xfd,
  58063. 0x79, 0x89, 0xb0, 0x74, 0xa2, 0xe9, 0x61, 0x48, 0x4c, 0x54, 0xad, 0x6b,
  58064. 0x61, 0xbf, 0x0e, 0x27, 0x58, 0xb4, 0xf6, 0x9c, 0x2c, 0x9f, 0xc2, 0x3e,
  58065. 0x3b, 0xb3, 0x90, 0x41, 0xbc, 0x61, 0xcd, 0x01, 0x57, 0x90, 0x82, 0xec,
  58066. 0x46, 0xba, 0x4f, 0x89, 0x8e, 0x7f, 0x49, 0x4f, 0x46, 0x69, 0x37, 0x8b,
  58067. 0xa0, 0xba, 0x85, 0xe8, 0x42, 0xff, 0x9a, 0xa1, 0x53, 0x81, 0x5c, 0xf3,
  58068. 0x8e, 0x85, 0x1c, 0xd4, 0x90, 0x60, 0xa0, 0x37, 0x59, 0x04, 0x65, 0xa6,
  58069. 0xb5, 0x12, 0x00, 0xc3, 0x04, 0x51, 0xa7, 0x83, 0x96, 0x62, 0x3d, 0x49,
  58070. 0x97, 0xe8, 0x6b, 0x9a, 0x5d, 0x51, 0x24, 0xee, 0xad, 0x45, 0x18, 0x0f,
  58071. 0x3f, 0x97, 0xec, 0xdf, 0xcf, 0x42, 0x8a, 0x96, 0xc7, 0xd8, 0x82, 0x87,
  58072. 0x7f, 0x57, 0x70, 0x22, 0xfb, 0x29, 0x3e, 0x3c, 0xa3, 0xc1, 0xd5, 0x71,
  58073. 0xb3, 0x84, 0x06, 0x53, 0xa3, 0x86, 0x20, 0x35, 0xe3, 0x41, 0xb9, 0xd8,
  58074. 0x00, 0x22, 0x4f, 0x6d, 0xe6, 0xfd, 0xf0, 0xf4, 0xa2, 0x39, 0x0a, 0x1a,
  58075. 0x23, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x30, 0x30, 0x2e, 0x30, 0x0d,
  58076. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x06, 0x30, 0x04, 0x82, 0x02, 0x61,
  58077. 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14,
  58078. 0x45, 0x05, 0xf3, 0x4d, 0x3e, 0x7e, 0x9c, 0xf5, 0x08, 0xee, 0x2c, 0x13,
  58079. 0x32, 0xe3, 0xf2, 0x14, 0xe8, 0x0e, 0x71, 0x21, 0x30, 0x0d, 0x06, 0x09,
  58080. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03,
  58081. 0x82, 0x01, 0x01, 0x00, 0xa8, 0x28, 0xe5, 0x22, 0x65, 0xcf, 0x47, 0xfe,
  58082. 0x82, 0x17, 0x99, 0x20, 0xdb, 0xb1, 0x57, 0xd4, 0x91, 0x1a, 0x83, 0xde,
  58083. 0xc1, 0xaf, 0xc4, 0x1f, 0xfb, 0xa4, 0x6a, 0xad, 0xdc, 0x58, 0x72, 0xd9,
  58084. 0x9b, 0xab, 0xa5, 0xbb, 0xf4, 0x98, 0xd4, 0xdf, 0x36, 0xcb, 0xb5, 0x78,
  58085. 0xce, 0x4b, 0x25, 0x5b, 0x24, 0x92, 0xfe, 0xe8, 0xd4, 0xe4, 0xbd, 0x6f,
  58086. 0x71, 0x1a, 0x81, 0x2a, 0x6f, 0x35, 0x93, 0xf7, 0xcc, 0xed, 0xe5, 0x06,
  58087. 0xd2, 0x96, 0x41, 0xb5, 0xa9, 0x8a, 0xc0, 0xc9, 0x17, 0xe3, 0x13, 0x5e,
  58088. 0x94, 0x5e, 0xfa, 0xfc, 0xf0, 0x00, 0x2e, 0xe1, 0xd8, 0x1b, 0x23, 0x3f,
  58089. 0x7c, 0x4d, 0x9f, 0xfb, 0xb7, 0x95, 0xc1, 0x94, 0x7f, 0x7f, 0xb5, 0x4f,
  58090. 0x93, 0x6d, 0xc3, 0x2b, 0xb2, 0x28, 0x36, 0xd2, 0x7c, 0x01, 0x3c, 0xae,
  58091. 0x35, 0xdb, 0xc8, 0x95, 0x1b, 0x5f, 0x6c, 0x0f, 0x57, 0xb3, 0xcc, 0x97,
  58092. 0x98, 0x80, 0x06, 0xaa, 0xe4, 0x93, 0x1f, 0xb7, 0xa0, 0x54, 0xf1, 0x4f,
  58093. 0x6f, 0x11, 0xdf, 0xab, 0xd3, 0xbf, 0xf0, 0x3a, 0x81, 0x60, 0xaf, 0x7a,
  58094. 0xf7, 0x09, 0xd5, 0xae, 0x0c, 0x7d, 0xae, 0x8d, 0x47, 0x06, 0xbe, 0x11,
  58095. 0x6e, 0xf8, 0x7e, 0x49, 0xf8, 0xac, 0x24, 0x0a, 0x4b, 0xc2, 0xf6, 0xe8,
  58096. 0x2c, 0xec, 0x35, 0xef, 0xa9, 0x13, 0xb8, 0xd2, 0x9c, 0x92, 0x61, 0x91,
  58097. 0xec, 0x7b, 0x0c, 0xea, 0x9a, 0x71, 0x36, 0x15, 0x34, 0x2b, 0x7a, 0x25,
  58098. 0xac, 0xfe, 0xc7, 0x26, 0x89, 0x70, 0x3e, 0x64, 0x68, 0x97, 0x4b, 0xaa,
  58099. 0xc1, 0x24, 0x14, 0xbd, 0x45, 0x2f, 0xe0, 0xfe, 0xf4, 0x2b, 0x8e, 0x08,
  58100. 0x3e, 0xe4, 0xb5, 0x3d, 0x5d, 0xf4, 0xc3, 0xd6, 0x9c, 0xb5, 0x33, 0x1b,
  58101. 0x3b, 0xda, 0x6e, 0x99, 0x7b, 0x09, 0xd1, 0x30, 0x97, 0x23, 0x52, 0x6d,
  58102. 0x1b, 0x71, 0x3a, 0xf4, 0x54, 0xf0, 0xe5, 0x9e
  58103. };
  58104. WOLFSSL_X509* x509 = NULL;
  58105. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  58106. const char *name1 = "aaaaa";
  58107. int nameLen1 = (int)(XSTRLEN(name1));
  58108. const char *name2 = "a";
  58109. int nameLen2 = (int)(XSTRLEN(name2));
  58110. const char *name3 = "abbbb";
  58111. int nameLen3 = (int)(XSTRLEN(name3));
  58112. const char *name4 = "bbb";
  58113. int nameLen4 = (int)(XSTRLEN(name4));
  58114. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  58115. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  58116. /* Ensure that "a*" matches "aaaaa" */
  58117. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  58118. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58119. /* Ensure that "a*" matches "a" */
  58120. ExpectIntEQ(wolfSSL_X509_check_host(x509, name2, nameLen2,
  58121. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58122. /* Ensure that "a*" matches "abbbb" */
  58123. ExpectIntEQ(wolfSSL_X509_check_host(x509, name3, nameLen3,
  58124. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58125. /* Ensure that "a*" does not match "bbb" */
  58126. ExpectIntNE(wolfSSL_X509_check_host(x509, name4, nameLen4,
  58127. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), 1);
  58128. wolfSSL_X509_free(x509);
  58129. #endif
  58130. return EXPECT_RESULT();
  58131. }
  58132. static int test_wolfSSL_X509_name_match2(void)
  58133. {
  58134. EXPECT_DECLS;
  58135. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  58136. /* A certificate with the subject alternative name a*b* */
  58137. const unsigned char cert_der[] = {
  58138. 0x30, 0x82, 0x03, 0xae, 0x30, 0x82, 0x02, 0x96, 0xa0, 0x03, 0x02, 0x01,
  58139. 0x02, 0x02, 0x14, 0x41, 0x8c, 0x8b, 0xaa, 0x0e, 0xd8, 0x5a, 0xc0, 0x52,
  58140. 0x46, 0x0e, 0xe5, 0xd8, 0xb9, 0x48, 0x93, 0x7e, 0x8a, 0x7c, 0x65, 0x30,
  58141. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  58142. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  58143. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  58144. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  58145. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  58146. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  58147. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  58148. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  58149. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  58150. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  58151. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  58152. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  58153. 0x30, 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  58154. 0x30, 0x35, 0x32, 0x38, 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x5a, 0x30,
  58155. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  58156. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  58157. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  58158. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  58159. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  58160. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  58161. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  58162. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  58163. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  58164. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  58165. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  58166. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  58167. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xa5, 0x60, 0x80,
  58168. 0xf3, 0xee, 0x19, 0xd2, 0xe4, 0x15, 0x94, 0x54, 0x12, 0x88, 0xee, 0xda,
  58169. 0x11, 0x11, 0x87, 0x99, 0x88, 0xb3, 0x71, 0xc7, 0x97, 0x78, 0x1b, 0x57,
  58170. 0x37, 0x1d, 0x0b, 0x1f, 0x2f, 0x2c, 0x35, 0x13, 0x75, 0xd3, 0x31, 0x3e,
  58171. 0x6f, 0x80, 0x21, 0xa5, 0xa3, 0xad, 0x10, 0x81, 0xb6, 0x37, 0xd4, 0x55,
  58172. 0x2e, 0xc1, 0xb8, 0x37, 0xa3, 0x3c, 0xe8, 0x81, 0x03, 0x3c, 0xda, 0x5f,
  58173. 0x6f, 0x45, 0x32, 0x2b, 0x0e, 0x99, 0x27, 0xfd, 0xe5, 0x6c, 0x07, 0xd9,
  58174. 0x4e, 0x0a, 0x8b, 0x23, 0x74, 0x96, 0x25, 0x97, 0xae, 0x6d, 0x19, 0xba,
  58175. 0xbf, 0x0f, 0xc8, 0xa1, 0xe5, 0xea, 0xa8, 0x00, 0x09, 0xc3, 0x9a, 0xef,
  58176. 0x09, 0x33, 0xc1, 0x33, 0x2e, 0x7b, 0x6d, 0xa7, 0x66, 0x87, 0xb6, 0x3a,
  58177. 0xb9, 0xdb, 0x4c, 0x5e, 0xb5, 0x55, 0x69, 0x37, 0x17, 0x92, 0x1f, 0xe3,
  58178. 0x53, 0x1a, 0x2d, 0x25, 0xd0, 0xcf, 0x72, 0x37, 0xc2, 0x89, 0x83, 0x78,
  58179. 0xcf, 0xac, 0x2e, 0x46, 0x92, 0x5c, 0x4a, 0xba, 0x7d, 0xa0, 0x22, 0x34,
  58180. 0xb1, 0x22, 0x26, 0x99, 0xda, 0xe8, 0x97, 0xe2, 0x0c, 0xd3, 0xbc, 0x97,
  58181. 0x7e, 0xa8, 0xb9, 0xe3, 0xe2, 0x7f, 0x56, 0xef, 0x22, 0xee, 0x15, 0x95,
  58182. 0xa6, 0xd1, 0xf4, 0xa7, 0xac, 0x4a, 0xab, 0xc1, 0x1a, 0xda, 0xc5, 0x5f,
  58183. 0xa5, 0x5e, 0x2f, 0x15, 0x9c, 0x36, 0xbe, 0xd3, 0x47, 0xb6, 0x86, 0xb9,
  58184. 0xc6, 0x59, 0x39, 0x36, 0xad, 0x84, 0x53, 0x95, 0x72, 0x91, 0x89, 0x51,
  58185. 0x32, 0x77, 0xf1, 0xa5, 0x93, 0xfe, 0xf0, 0x41, 0x7c, 0x64, 0xf1, 0xb0,
  58186. 0x8b, 0x81, 0x8d, 0x3a, 0x2c, 0x9e, 0xbe, 0x2e, 0x8b, 0xf7, 0x80, 0x63,
  58187. 0x35, 0x32, 0xfa, 0x26, 0xe0, 0x63, 0xbf, 0x5e, 0xaf, 0xf0, 0x08, 0xe0,
  58188. 0x80, 0x65, 0x38, 0xfa, 0x21, 0xaa, 0x91, 0x34, 0x48, 0x3d, 0x32, 0x5c,
  58189. 0xbf, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x32, 0x30, 0x30, 0x30, 0x0f,
  58190. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x08, 0x30, 0x06, 0x82, 0x04, 0x61,
  58191. 0x2a, 0x62, 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16,
  58192. 0x04, 0x14, 0x3d, 0x55, 0x74, 0xf8, 0x3a, 0x26, 0x03, 0x8c, 0x6a, 0x2e,
  58193. 0x91, 0x0e, 0x18, 0x70, 0xb4, 0xa4, 0xcc, 0x04, 0x00, 0xd3, 0x30, 0x0d,
  58194. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
  58195. 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x8f, 0x3b, 0xff, 0x46, 0x0c, 0xb5,
  58196. 0x21, 0xdc, 0xcf, 0x61, 0x9a, 0x25, 0x93, 0x99, 0x68, 0x2f, 0x16, 0x71,
  58197. 0x15, 0x00, 0x5f, 0xb0, 0x9b, 0x43, 0x5c, 0x47, 0xe2, 0x8e, 0xc8, 0xea,
  58198. 0xb3, 0x30, 0x4d, 0x87, 0x90, 0xcf, 0x24, 0x37, 0x5c, 0xfd, 0xc8, 0xc6,
  58199. 0x09, 0x36, 0xb2, 0xfb, 0xfd, 0xc1, 0x82, 0x92, 0x77, 0x5b, 0x9d, 0xeb,
  58200. 0xac, 0x47, 0xbc, 0xda, 0x7c, 0x89, 0x19, 0x03, 0x9e, 0xcd, 0x96, 0x2a,
  58201. 0x90, 0x55, 0x23, 0x19, 0xac, 0x9d, 0x49, 0xfb, 0xa0, 0x31, 0x7d, 0x6b,
  58202. 0x1a, 0x16, 0x13, 0xb1, 0xa9, 0xc9, 0xc4, 0xaf, 0xf1, 0xb4, 0xa7, 0x9b,
  58203. 0x08, 0x64, 0x6a, 0x09, 0xcd, 0x4a, 0x03, 0x4c, 0x93, 0xb6, 0xcf, 0x29,
  58204. 0xdb, 0x56, 0x88, 0x8e, 0xed, 0x08, 0x6d, 0x8d, 0x76, 0xa3, 0xd7, 0xc6,
  58205. 0x69, 0xa1, 0xf5, 0xd2, 0xd0, 0x0a, 0x4b, 0xfa, 0x88, 0x66, 0x6c, 0xe5,
  58206. 0x4a, 0xee, 0x13, 0xad, 0xad, 0x22, 0x25, 0x73, 0x39, 0x56, 0x74, 0x0e,
  58207. 0xda, 0xcd, 0x35, 0x67, 0xe3, 0x81, 0x5c, 0xc5, 0xae, 0x3c, 0x4f, 0x47,
  58208. 0x3e, 0x97, 0xde, 0xac, 0xf6, 0xe1, 0x26, 0xe2, 0xe0, 0x66, 0x48, 0x20,
  58209. 0x7c, 0x02, 0x81, 0x3e, 0x7d, 0x34, 0xb7, 0x73, 0x3e, 0x2e, 0xd6, 0x20,
  58210. 0x1c, 0xdf, 0xf1, 0xae, 0x86, 0x8b, 0xb2, 0xc2, 0x9b, 0x68, 0x9c, 0xf6,
  58211. 0x1a, 0x5e, 0x30, 0x06, 0x39, 0x0a, 0x1f, 0x7b, 0xd7, 0x18, 0x4b, 0x06,
  58212. 0x9d, 0xff, 0x84, 0x57, 0xcc, 0x92, 0xad, 0x81, 0x0a, 0x19, 0x11, 0xc4,
  58213. 0xac, 0x59, 0x00, 0xe8, 0x5a, 0x70, 0x78, 0xd6, 0x9f, 0xe0, 0x82, 0x2a,
  58214. 0x1f, 0x09, 0x36, 0x1c, 0x52, 0x98, 0xf7, 0x95, 0x8f, 0xf9, 0x48, 0x4f,
  58215. 0x30, 0x52, 0xb5, 0xf3, 0x8d, 0x13, 0x93, 0x27, 0xbe, 0xb4, 0x75, 0x39,
  58216. 0x65, 0xc6, 0x48, 0x4e, 0x32, 0xd7, 0xf4, 0xc3, 0x26, 0x8d
  58217. };
  58218. WOLFSSL_X509* x509 = NULL;
  58219. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  58220. const char *name1 = "ab";
  58221. int nameLen1 = (int)(XSTRLEN(name1));
  58222. const char *name2 = "acccbccc";
  58223. int nameLen2 = (int)(XSTRLEN(name2));
  58224. const char *name3 = "accb";
  58225. int nameLen3 = (int)(XSTRLEN(name3));
  58226. const char *name4 = "accda";
  58227. int nameLen4 = (int)(XSTRLEN(name4));
  58228. const char *name5 = "acc\0bcc";
  58229. int nameLen5 = 7;
  58230. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  58231. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  58232. /* Ensure that "a*b*" matches "ab" */
  58233. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  58234. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58235. /* Ensure that "a*b*" matches "acccbccc" */
  58236. ExpectIntEQ(wolfSSL_X509_check_host(x509, name2, nameLen2,
  58237. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58238. /* Ensure that "a*b*" matches "accb" */
  58239. ExpectIntEQ(wolfSSL_X509_check_host(x509, name3, nameLen3,
  58240. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58241. /* Ensure that "a*b*" does not match "accda" */
  58242. ExpectIntNE(wolfSSL_X509_check_host(x509, name4, nameLen4,
  58243. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58244. /* Ensure that "a*b*" matches "ab", testing openssl behavior replication
  58245. * on check len input handling, 0 for len is OK as it should then use
  58246. * strlen(name1) */
  58247. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, 0,
  58248. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58249. /* Openssl also allows for len to include NULL terminator */
  58250. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1 + 1,
  58251. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58252. /* Ensure that check string with NULL terminator in middle is
  58253. * rejected */
  58254. ExpectIntNE(wolfSSL_X509_check_host(x509, name5, nameLen5,
  58255. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58256. wolfSSL_X509_free(x509);
  58257. #endif
  58258. return EXPECT_RESULT();
  58259. }
  58260. static int test_wolfSSL_X509_name_match3(void)
  58261. {
  58262. EXPECT_DECLS;
  58263. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  58264. /* A certificate with the subject alternative name *.example.com */
  58265. const unsigned char cert_der[] = {
  58266. 0x30, 0x82, 0x03, 0xb7, 0x30, 0x82, 0x02, 0x9f, 0xa0, 0x03, 0x02, 0x01,
  58267. 0x02, 0x02, 0x14, 0x59, 0xbb, 0xf6, 0xde, 0xb8, 0x3d, 0x0e, 0x8c, 0xe4,
  58268. 0xbd, 0x98, 0xa3, 0xbe, 0x3e, 0x8f, 0xdc, 0xbd, 0x7f, 0xcc, 0xae, 0x30,
  58269. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  58270. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  58271. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  58272. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  58273. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  58274. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  58275. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  58276. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  58277. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  58278. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  58279. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  58280. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  58281. 0x31, 0x30, 0x30, 0x33, 0x37, 0x34, 0x39, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  58282. 0x30, 0x35, 0x32, 0x39, 0x30, 0x30, 0x33, 0x37, 0x34, 0x39, 0x5a, 0x30,
  58283. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  58284. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  58285. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  58286. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  58287. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  58288. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  58289. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  58290. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  58291. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  58292. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  58293. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  58294. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  58295. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xda, 0x78, 0x16,
  58296. 0x05, 0x65, 0xf2, 0x85, 0xf2, 0x61, 0x7f, 0xb1, 0x4d, 0x73, 0xe2, 0x82,
  58297. 0xb5, 0x3d, 0xf7, 0x9d, 0x05, 0x65, 0xed, 0x9d, 0xc3, 0x29, 0x7a, 0x92,
  58298. 0x2c, 0x06, 0x5f, 0xc8, 0x13, 0x55, 0x42, 0x4e, 0xbd, 0xe2, 0x56, 0x2a,
  58299. 0x4b, 0xac, 0xe6, 0x1b, 0x10, 0xc9, 0xdb, 0x9a, 0x45, 0x36, 0xed, 0xf3,
  58300. 0x26, 0x8c, 0x22, 0x88, 0x1e, 0x6d, 0x2b, 0x41, 0xfa, 0x0d, 0x43, 0x88,
  58301. 0x88, 0xde, 0x8d, 0x2e, 0xca, 0x6e, 0x7c, 0x62, 0x66, 0x3e, 0xfa, 0x4e,
  58302. 0x71, 0xea, 0x7d, 0x3b, 0x32, 0x33, 0x5c, 0x7a, 0x7e, 0xea, 0x74, 0xbd,
  58303. 0xb6, 0x8f, 0x4c, 0x1c, 0x7a, 0x79, 0x94, 0xf1, 0xe8, 0x02, 0x67, 0x98,
  58304. 0x25, 0xb4, 0x31, 0x80, 0xc1, 0xae, 0xbf, 0xef, 0xf2, 0x6c, 0x78, 0x42,
  58305. 0xef, 0xb5, 0xc6, 0x01, 0x47, 0x79, 0x8d, 0x92, 0xce, 0xc1, 0xb5, 0x98,
  58306. 0x76, 0xf0, 0x84, 0xa2, 0x53, 0x90, 0xe5, 0x39, 0xc7, 0xbd, 0xf2, 0xbb,
  58307. 0xe3, 0x3f, 0x00, 0xf6, 0xf0, 0x46, 0x86, 0xee, 0x55, 0xbd, 0x2c, 0x1f,
  58308. 0x97, 0x24, 0x7c, 0xbc, 0xda, 0x2f, 0x1b, 0x53, 0xef, 0x26, 0x56, 0xcc,
  58309. 0xb7, 0xd8, 0xca, 0x17, 0x20, 0x4e, 0x62, 0x03, 0x66, 0x32, 0xb3, 0xd1,
  58310. 0x71, 0x26, 0x6c, 0xff, 0xd1, 0x9e, 0x44, 0x86, 0x2a, 0xae, 0xba, 0x43,
  58311. 0x00, 0x13, 0x7e, 0x50, 0xdd, 0x3e, 0x27, 0x39, 0x70, 0x1c, 0x0c, 0x0b,
  58312. 0xe8, 0xa2, 0xae, 0x03, 0x09, 0x2e, 0xd8, 0x71, 0xee, 0x7b, 0x1a, 0x09,
  58313. 0x2d, 0xe1, 0xd5, 0xde, 0xf5, 0xa3, 0x36, 0x77, 0x90, 0x97, 0x99, 0xd7,
  58314. 0x6c, 0xb7, 0x5c, 0x9d, 0xf7, 0x7e, 0x41, 0x89, 0xfe, 0xe4, 0x08, 0xc6,
  58315. 0x0b, 0xe4, 0x9b, 0x5f, 0x51, 0xa6, 0x08, 0xb8, 0x99, 0x81, 0xe9, 0xce,
  58316. 0xb4, 0x2d, 0xb2, 0x92, 0x9f, 0xe5, 0x1a, 0x98, 0x76, 0x20, 0x70, 0x54,
  58317. 0x93, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x3b, 0x30, 0x39, 0x30, 0x18,
  58318. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x11, 0x30, 0x0f, 0x82, 0x0d, 0x2a,
  58319. 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d,
  58320. 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x60,
  58321. 0xd4, 0x26, 0xbb, 0xcc, 0x7c, 0x29, 0xa2, 0x88, 0x3c, 0x76, 0x7d, 0xb4,
  58322. 0x86, 0x8b, 0x47, 0x64, 0x5b, 0x87, 0xe0, 0x30, 0x0d, 0x06, 0x09, 0x2a,
  58323. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82,
  58324. 0x01, 0x01, 0x00, 0xc3, 0x0d, 0x03, 0x67, 0xbb, 0x47, 0x8b, 0xf3, 0x20,
  58325. 0xdc, 0x7d, 0x2e, 0xe1, 0xd9, 0xf0, 0x01, 0xc4, 0x66, 0xc2, 0xe1, 0xcd,
  58326. 0xc3, 0x4a, 0x72, 0xf0, 0x6e, 0x38, 0xcf, 0x63, 0x01, 0x96, 0x9e, 0x84,
  58327. 0xb9, 0xce, 0x1d, 0xba, 0x4b, 0xe0, 0x70, 0x86, 0x2b, 0x5a, 0xab, 0xec,
  58328. 0xbf, 0xc2, 0xaa, 0x64, 0xa2, 0x6c, 0xd2, 0x42, 0x52, 0xd4, 0xbe, 0x8a,
  58329. 0xca, 0x9c, 0x03, 0xf3, 0xd6, 0x5f, 0xcd, 0x23, 0x9f, 0xf5, 0xa9, 0x04,
  58330. 0x40, 0x5b, 0x66, 0x78, 0xc0, 0xac, 0xa1, 0xdb, 0x5d, 0xd1, 0x94, 0xfc,
  58331. 0x47, 0x94, 0xf5, 0x45, 0xe3, 0x70, 0x13, 0x3f, 0x66, 0x6d, 0xdd, 0x73,
  58332. 0x68, 0x68, 0xe2, 0xd2, 0x89, 0xcb, 0x7f, 0xc6, 0xca, 0xd6, 0x96, 0x0b,
  58333. 0xcc, 0xdd, 0xa1, 0x74, 0xda, 0x33, 0xe8, 0x9e, 0xda, 0xb7, 0xd9, 0x12,
  58334. 0xab, 0x85, 0x9d, 0x0c, 0xde, 0xa0, 0x7d, 0x7e, 0xa1, 0x91, 0xed, 0xe5,
  58335. 0x32, 0x7c, 0xc5, 0xea, 0x1d, 0x4a, 0xb5, 0x38, 0x63, 0x17, 0xf3, 0x4f,
  58336. 0x2c, 0x4a, 0x58, 0x86, 0x09, 0x33, 0x86, 0xc4, 0xe7, 0x56, 0x6f, 0x32,
  58337. 0x71, 0xb7, 0xd0, 0x83, 0x12, 0x9e, 0x26, 0x0a, 0x3a, 0x45, 0xcb, 0xd7,
  58338. 0x4e, 0xab, 0xa4, 0xc3, 0xee, 0x4c, 0xc0, 0x38, 0xa1, 0xfa, 0xba, 0xfa,
  58339. 0xb7, 0x80, 0x69, 0x67, 0xa3, 0xef, 0x89, 0xba, 0xce, 0x89, 0x91, 0x3d,
  58340. 0x6a, 0x76, 0xe9, 0x3b, 0x32, 0x86, 0x76, 0x85, 0x6b, 0x4f, 0x7f, 0xbc,
  58341. 0x7a, 0x5b, 0x31, 0x92, 0x79, 0x35, 0xf8, 0xb9, 0xb1, 0xd7, 0xdb, 0xa9,
  58342. 0x6a, 0x8a, 0x91, 0x60, 0x65, 0xd4, 0x76, 0x54, 0x55, 0x57, 0xb9, 0x35,
  58343. 0xe0, 0xf5, 0xbb, 0x8f, 0xd4, 0x40, 0x75, 0xbb, 0x47, 0xa8, 0xf9, 0x0f,
  58344. 0xea, 0xc9, 0x6e, 0x84, 0xd5, 0xf5, 0x58, 0x2d, 0xe5, 0x76, 0x7b, 0xdf,
  58345. 0x97, 0x05, 0x5e, 0xaf, 0x50, 0xf5, 0x48
  58346. };
  58347. WOLFSSL_X509* x509 = NULL;
  58348. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  58349. const char *name1 = "foo.example.com";
  58350. int nameLen1 = (int)(XSTRLEN(name1));
  58351. const char *name2 = "x.y.example.com";
  58352. int nameLen2 = (int)(XSTRLEN(name2));
  58353. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  58354. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  58355. /* Ensure that "*.example.com" matches "foo.example.com" */
  58356. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  58357. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58358. /* Ensure that "*.example.com" does NOT match "x.y.example.com" */
  58359. ExpectIntNE(wolfSSL_X509_check_host(x509, name2, nameLen2,
  58360. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58361. wolfSSL_X509_free(x509);
  58362. #endif
  58363. return EXPECT_RESULT();
  58364. }
  58365. static int test_wolfSSL_X509_max_altnames(void)
  58366. {
  58367. EXPECT_DECLS;
  58368. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  58369. /* Only test if max alt names has not been modified */
  58370. #if WOLFSSL_MAX_ALT_NAMES <= 1024
  58371. WOLFSSL_CTX* ctx = NULL;
  58372. /* File contains a certificate encoded with 130 subject alternative names */
  58373. const char* over_max_altnames_cert = \
  58374. "./certs/test/cert-over-max-altnames.pem";
  58375. #ifndef NO_WOLFSSL_SERVER
  58376. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  58377. #else
  58378. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  58379. #endif
  58380. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx,
  58381. over_max_altnames_cert, NULL, WOLFSSL_LOAD_FLAG_NONE),
  58382. WOLFSSL_SUCCESS);
  58383. wolfSSL_CTX_free(ctx);
  58384. #endif
  58385. #endif
  58386. return EXPECT_RESULT();
  58387. }
  58388. static int test_wolfSSL_X509_max_name_constraints(void)
  58389. {
  58390. EXPECT_DECLS;
  58391. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  58392. !defined(IGNORE_NAME_CONSTRAINTS)
  58393. /* Only test if max name constraints has not been modified */
  58394. #if WOLFSSL_MAX_NAME_CONSTRAINTS == 128
  58395. WOLFSSL_CTX* ctx = NULL;
  58396. /* File contains a certificate with 130 name constraints */
  58397. const char* over_max_nc = "./certs/test/cert-over-max-nc.pem";
  58398. #ifndef NO_WOLFSSL_SERVER
  58399. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  58400. #else
  58401. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  58402. #endif
  58403. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, over_max_nc,
  58404. NULL, WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  58405. wolfSSL_CTX_free(ctx);
  58406. #endif
  58407. #endif
  58408. return EXPECT_RESULT();
  58409. }
  58410. static int test_wolfSSL_X509(void)
  58411. {
  58412. EXPECT_DECLS;
  58413. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  58414. !defined(NO_RSA)
  58415. X509* x509 = NULL;
  58416. #ifndef NO_BIO
  58417. BIO* bio = NULL;
  58418. X509_STORE_CTX* ctx = NULL;
  58419. X509_STORE* store = NULL;
  58420. #endif
  58421. char der[] = "certs/ca-cert.der";
  58422. XFILE fp = XBADFILE;
  58423. ExpectNotNull(x509 = X509_new());
  58424. X509_free(x509);
  58425. x509 = NULL;
  58426. #ifndef NO_BIO
  58427. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  58428. SSL_FILETYPE_PEM));
  58429. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58430. #ifdef WOLFSSL_CERT_GEN
  58431. ExpectIntEQ(i2d_X509_bio(bio, x509), SSL_SUCCESS);
  58432. #endif
  58433. ExpectNotNull(ctx = X509_STORE_CTX_new());
  58434. ExpectIntEQ(X509_verify_cert(ctx), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  58435. ExpectNotNull(store = X509_STORE_new());
  58436. ExpectIntEQ(X509_STORE_add_cert(store, x509), SSL_SUCCESS);
  58437. ExpectIntEQ(X509_STORE_CTX_init(ctx, store, x509, NULL), SSL_SUCCESS);
  58438. ExpectIntEQ(X509_verify_cert(ctx), SSL_SUCCESS);
  58439. X509_STORE_CTX_free(ctx);
  58440. X509_STORE_free(store);
  58441. X509_free(x509);
  58442. x509 = NULL;
  58443. BIO_free(bio);
  58444. #endif
  58445. /** d2i_X509_fp test **/
  58446. ExpectTrue((fp = XFOPEN(der, "rb")) != XBADFILE);
  58447. ExpectNotNull(x509 = (X509 *)d2i_X509_fp(fp, (X509 **)NULL));
  58448. ExpectNotNull(x509);
  58449. X509_free(x509);
  58450. x509 = NULL;
  58451. if (fp != XBADFILE) {
  58452. XFCLOSE(fp);
  58453. fp = XBADFILE;
  58454. }
  58455. ExpectTrue((fp = XFOPEN(der, "rb")) != XBADFILE);
  58456. ExpectNotNull((X509 *)d2i_X509_fp(fp, (X509 **)&x509));
  58457. ExpectNotNull(x509);
  58458. X509_free(x509);
  58459. if (fp != XBADFILE)
  58460. XFCLOSE(fp);
  58461. /* X509_up_ref test */
  58462. ExpectIntEQ(X509_up_ref(NULL), 0);
  58463. ExpectNotNull(x509 = X509_new()); /* refCount = 1 */
  58464. ExpectIntEQ(X509_up_ref(x509), 1); /* refCount = 2 */
  58465. ExpectIntEQ(X509_up_ref(x509), 1); /* refCount = 3 */
  58466. X509_free(x509); /* refCount = 2 */
  58467. X509_free(x509); /* refCount = 1 */
  58468. X509_free(x509); /* refCount = 0, free */
  58469. #endif
  58470. return EXPECT_RESULT();
  58471. }
  58472. static int test_wolfSSL_X509_get_ext_count(void)
  58473. {
  58474. EXPECT_DECLS;
  58475. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  58476. !defined(NO_RSA)
  58477. int ret = 0;
  58478. WOLFSSL_X509* x509 = NULL;
  58479. const char ocspRootCaFile[] = "./certs/ocsp/root-ca-cert.pem";
  58480. XFILE f = XBADFILE;
  58481. /* NULL parameter check */
  58482. ExpectIntEQ(X509_get_ext_count(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  58483. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  58484. SSL_FILETYPE_PEM));
  58485. ExpectIntEQ(X509_get_ext_count(x509), 5);
  58486. wolfSSL_X509_free(x509);
  58487. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(ocspRootCaFile,
  58488. SSL_FILETYPE_PEM));
  58489. ExpectIntEQ(X509_get_ext_count(x509), 5);
  58490. wolfSSL_X509_free(x509);
  58491. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  58492. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  58493. if (f != XBADFILE)
  58494. XFCLOSE(f);
  58495. /* wolfSSL_X509_get_ext_count() valid input */
  58496. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(x509)), 5);
  58497. /* wolfSSL_X509_get_ext_count() NULL argument */
  58498. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(NULL)), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  58499. wolfSSL_X509_free(x509);
  58500. #endif
  58501. return EXPECT_RESULT();
  58502. }
  58503. static int test_wolfSSL_X509_sign2(void)
  58504. {
  58505. EXPECT_DECLS;
  58506. /* test requires WOLFSSL_AKID_NAME to match expected output */
  58507. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  58508. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_ALT_NAMES) && \
  58509. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_AKID_NAME) && \
  58510. (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  58511. defined(WOLFSSL_IP_ALT_NAME))
  58512. WOLFSSL_X509 *x509 = NULL;
  58513. WOLFSSL_X509 *ca = NULL;
  58514. const unsigned char *der = NULL;
  58515. const unsigned char *pt = NULL;
  58516. WOLFSSL_EVP_PKEY *priv = NULL;
  58517. WOLFSSL_X509_NAME *name = NULL;
  58518. int derSz;
  58519. #ifndef NO_ASN_TIME
  58520. WOLFSSL_ASN1_TIME *notBefore = NULL;
  58521. WOLFSSL_ASN1_TIME *notAfter = NULL;
  58522. const int year = 365*24*60*60;
  58523. const int day = 24*60*60;
  58524. const int hour = 60*60;
  58525. const int mini = 60;
  58526. time_t t;
  58527. #endif
  58528. const unsigned char expected[] = {
  58529. 0x30, 0x82, 0x05, 0x13, 0x30, 0x82, 0x03, 0xFB, 0xA0, 0x03, 0x02, 0x01,
  58530. 0x02, 0x02, 0x14, 0x08, 0xB0, 0x54, 0x7A, 0x03, 0x5A, 0xEC, 0x55, 0x8A,
  58531. 0x12, 0xE8, 0xF9, 0x8E, 0x34, 0xB6, 0x13, 0xD9, 0x59, 0xB8, 0xE8, 0x30,
  58532. 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B,
  58533. 0x05, 0x00, 0x30, 0x81, 0x94, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55,
  58534. 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03,
  58535. 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E, 0x74, 0x61, 0x6E, 0x61,
  58536. 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42,
  58537. 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x11, 0x30, 0x0F, 0x06, 0x03,
  58538. 0x55, 0x04, 0x0A, 0x0C, 0x08, 0x53, 0x61, 0x77, 0x74, 0x6F, 0x6F, 0x74,
  58539. 0x68, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x0A,
  58540. 0x43, 0x6F, 0x6E, 0x73, 0x75, 0x6C, 0x74, 0x69, 0x6E, 0x67, 0x31, 0x18,
  58541. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77,
  58542. 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D,
  58543. 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  58544. 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77, 0x6F,
  58545. 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x1E, 0x17,
  58546. 0x0D, 0x30, 0x30, 0x30, 0x32, 0x31, 0x35, 0x32, 0x30, 0x33, 0x30, 0x30,
  58547. 0x30, 0x5A, 0x17, 0x0D, 0x30, 0x31, 0x30, 0x32, 0x31, 0x34, 0x32, 0x30,
  58548. 0x33, 0x30, 0x30, 0x30, 0x5A, 0x30, 0x81, 0x9E, 0x31, 0x0B, 0x30, 0x09,
  58549. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30,
  58550. 0x0E, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E, 0x74,
  58551. 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07,
  58552. 0x0C, 0x07, 0x42, 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x15, 0x30,
  58553. 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0C, 0x77, 0x6F, 0x6C, 0x66,
  58554. 0x53, 0x53, 0x4C, 0x5F, 0x32, 0x30, 0x34, 0x38, 0x31, 0x19, 0x30, 0x17,
  58555. 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10, 0x50, 0x72, 0x6F, 0x67, 0x72,
  58556. 0x61, 0x6D, 0x6D, 0x69, 0x6E, 0x67, 0x2D, 0x32, 0x30, 0x34, 0x38, 0x31,
  58557. 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77,
  58558. 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F,
  58559. 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7,
  58560. 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77,
  58561. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x82,
  58562. 0x01, 0x22, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  58563. 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0F, 0x00, 0x30, 0x82,
  58564. 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC3, 0x03, 0xD1, 0x2B, 0xFE,
  58565. 0x39, 0xA4, 0x32, 0x45, 0x3B, 0x53, 0xC8, 0x84, 0x2B, 0x2A, 0x7C, 0x74,
  58566. 0x9A, 0xBD, 0xAA, 0x2A, 0x52, 0x07, 0x47, 0xD6, 0xA6, 0x36, 0xB2, 0x07,
  58567. 0x32, 0x8E, 0xD0, 0xBA, 0x69, 0x7B, 0xC6, 0xC3, 0x44, 0x9E, 0xD4, 0x81,
  58568. 0x48, 0xFD, 0x2D, 0x68, 0xA2, 0x8B, 0x67, 0xBB, 0xA1, 0x75, 0xC8, 0x36,
  58569. 0x2C, 0x4A, 0xD2, 0x1B, 0xF7, 0x8B, 0xBA, 0xCF, 0x0D, 0xF9, 0xEF, 0xEC,
  58570. 0xF1, 0x81, 0x1E, 0x7B, 0x9B, 0x03, 0x47, 0x9A, 0xBF, 0x65, 0xCC, 0x7F,
  58571. 0x65, 0x24, 0x69, 0xA6, 0xE8, 0x14, 0x89, 0x5B, 0xE4, 0x34, 0xF7, 0xC5,
  58572. 0xB0, 0x14, 0x93, 0xF5, 0x67, 0x7B, 0x3A, 0x7A, 0x78, 0xE1, 0x01, 0x56,
  58573. 0x56, 0x91, 0xA6, 0x13, 0x42, 0x8D, 0xD2, 0x3C, 0x40, 0x9C, 0x4C, 0xEF,
  58574. 0xD1, 0x86, 0xDF, 0x37, 0x51, 0x1B, 0x0C, 0xA1, 0x3B, 0xF5, 0xF1, 0xA3,
  58575. 0x4A, 0x35, 0xE4, 0xE1, 0xCE, 0x96, 0xDF, 0x1B, 0x7E, 0xBF, 0x4E, 0x97,
  58576. 0xD0, 0x10, 0xE8, 0xA8, 0x08, 0x30, 0x81, 0xAF, 0x20, 0x0B, 0x43, 0x14,
  58577. 0xC5, 0x74, 0x67, 0xB4, 0x32, 0x82, 0x6F, 0x8D, 0x86, 0xC2, 0x88, 0x40,
  58578. 0x99, 0x36, 0x83, 0xBA, 0x1E, 0x40, 0x72, 0x22, 0x17, 0xD7, 0x52, 0x65,
  58579. 0x24, 0x73, 0xB0, 0xCE, 0xEF, 0x19, 0xCD, 0xAE, 0xFF, 0x78, 0x6C, 0x7B,
  58580. 0xC0, 0x12, 0x03, 0xD4, 0x4E, 0x72, 0x0D, 0x50, 0x6D, 0x3B, 0xA3, 0x3B,
  58581. 0xA3, 0x99, 0x5E, 0x9D, 0xC8, 0xD9, 0x0C, 0x85, 0xB3, 0xD9, 0x8A, 0xD9,
  58582. 0x54, 0x26, 0xDB, 0x6D, 0xFA, 0xAC, 0xBB, 0xFF, 0x25, 0x4C, 0xC4, 0xD1,
  58583. 0x79, 0xF4, 0x71, 0xD3, 0x86, 0x40, 0x18, 0x13, 0xB0, 0x63, 0xB5, 0x72,
  58584. 0x4E, 0x30, 0xC4, 0x97, 0x84, 0x86, 0x2D, 0x56, 0x2F, 0xD7, 0x15, 0xF7,
  58585. 0x7F, 0xC0, 0xAE, 0xF5, 0xFC, 0x5B, 0xE5, 0xFB, 0xA1, 0xBA, 0xD3, 0x02,
  58586. 0x03, 0x01, 0x00, 0x01, 0xA3, 0x82, 0x01, 0x4F, 0x30, 0x82, 0x01, 0x4B,
  58587. 0x30, 0x0C, 0x06, 0x03, 0x55, 0x1D, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01,
  58588. 0x01, 0xFF, 0x30, 0x1C, 0x06, 0x03, 0x55, 0x1D, 0x11, 0x04, 0x15, 0x30,
  58589. 0x13, 0x82, 0x0B, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2E, 0x63,
  58590. 0x6F, 0x6D, 0x87, 0x04, 0x7F, 0x00, 0x00, 0x01, 0x30, 0x1D, 0x06, 0x03,
  58591. 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0x33, 0xD8, 0x45, 0x66, 0xD7,
  58592. 0x68, 0x87, 0x18, 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26, 0xD7,
  58593. 0x85, 0x65, 0xC0, 0x30, 0x81, 0xDE, 0x06, 0x03, 0x55, 0x1D, 0x23, 0x04,
  58594. 0x81, 0xD6, 0x30, 0x81, 0xD3, 0x80, 0x14, 0x33, 0xD8, 0x45, 0x66, 0xD7,
  58595. 0x68, 0x87, 0x18, 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26, 0xD7,
  58596. 0x85, 0x65, 0xC0, 0xA1, 0x81, 0xA4, 0xA4, 0x81, 0xA1, 0x30, 0x81, 0x9E,
  58597. 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  58598. 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x07,
  58599. 0x4D, 0x6F, 0x6E, 0x74, 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E, 0x06,
  58600. 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42, 0x6F, 0x7A, 0x65, 0x6D, 0x61,
  58601. 0x6E, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0C,
  58602. 0x77, 0x6F, 0x6C, 0x66, 0x53, 0x53, 0x4C, 0x5F, 0x32, 0x30, 0x34, 0x38,
  58603. 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10, 0x50,
  58604. 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x6D, 0x69, 0x6E, 0x67, 0x2D, 0x32,
  58605. 0x30, 0x34, 0x38, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03,
  58606. 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73,
  58607. 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A,
  58608. 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E,
  58609. 0x66, 0x6F, 0x40, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  58610. 0x6F, 0x6D, 0x82, 0x14, 0x08, 0xB0, 0x54, 0x7A, 0x03, 0x5A, 0xEC, 0x55,
  58611. 0x8A, 0x12, 0xE8, 0xF9, 0x8E, 0x34, 0xB6, 0x13, 0xD9, 0x59, 0xB8, 0xE8,
  58612. 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x25, 0x04, 0x16, 0x30, 0x14, 0x06,
  58613. 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2B,
  58614. 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x30, 0x0D, 0x06, 0x09, 0x2A,
  58615. 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x03, 0x82,
  58616. 0x01, 0x01, 0x00, 0x14, 0xFB, 0xD0, 0xCE, 0x31, 0x7F, 0xA5, 0x59, 0xFA,
  58617. 0x7C, 0x68, 0x26, 0xA7, 0xE8, 0x0D, 0x9F, 0x50, 0x57, 0xFA, 0x1C, 0x7C,
  58618. 0x5E, 0x43, 0xA4, 0x97, 0x47, 0xB6, 0x41, 0xAC, 0x63, 0xD3, 0x61, 0x8C,
  58619. 0x1F, 0x42, 0xEF, 0x53, 0xD0, 0xBA, 0x31, 0x4D, 0x99, 0x74, 0xA4, 0x60,
  58620. 0xDC, 0xC6, 0x6F, 0xCC, 0x1E, 0x25, 0x98, 0xE1, 0xA4, 0xA0, 0x67, 0x69,
  58621. 0x97, 0xE3, 0x97, 0x7C, 0x83, 0x28, 0xF1, 0xF4, 0x7D, 0x03, 0xA8, 0x31,
  58622. 0x77, 0xCC, 0xD1, 0x37, 0xEF, 0x7B, 0x4A, 0x71, 0x2D, 0x11, 0x7E, 0x92,
  58623. 0xF5, 0x67, 0xB7, 0x56, 0xBA, 0x28, 0xF8, 0xD6, 0xCE, 0x2A, 0x71, 0xE3,
  58624. 0x70, 0x6B, 0x09, 0x0F, 0x67, 0x6F, 0x7A, 0xE0, 0x89, 0xF6, 0x5E, 0x23,
  58625. 0x0C, 0x0A, 0x44, 0x4E, 0x65, 0x8E, 0x7B, 0x68, 0xD0, 0xAD, 0x76, 0x3E,
  58626. 0x2A, 0x0E, 0xA2, 0x05, 0x11, 0x74, 0x24, 0x08, 0x60, 0xED, 0x9F, 0x98,
  58627. 0x18, 0xE9, 0x91, 0x58, 0x36, 0xEC, 0xEC, 0x25, 0x6B, 0xBA, 0x9C, 0x87,
  58628. 0x38, 0x68, 0xDC, 0xDC, 0x15, 0x6F, 0x20, 0x68, 0xC4, 0xBF, 0x05, 0x5B,
  58629. 0x4A, 0x0C, 0x44, 0x2B, 0x92, 0x3F, 0x10, 0x99, 0xDC, 0xF6, 0x6C, 0x0E,
  58630. 0x34, 0x26, 0x6E, 0x6D, 0x4E, 0x12, 0xBC, 0x60, 0x8F, 0x27, 0x1D, 0x7A,
  58631. 0x00, 0x50, 0xBE, 0x23, 0xDE, 0x48, 0x47, 0x9F, 0xAD, 0x2F, 0x94, 0x3D,
  58632. 0x16, 0x73, 0x48, 0x6B, 0xC8, 0x97, 0xE6, 0xB4, 0xB3, 0x4B, 0xE1, 0x68,
  58633. 0x08, 0xC3, 0xE5, 0x34, 0x5F, 0x9B, 0xDA, 0xAB, 0xCA, 0x6D, 0x55, 0x32,
  58634. 0xEF, 0x6C, 0xEF, 0x9B, 0x8B, 0x5B, 0xC7, 0xF0, 0xC2, 0x0F, 0x8E, 0x93,
  58635. 0x09, 0x60, 0x3C, 0x0B, 0xDC, 0xBD, 0xDB, 0x4A, 0x2D, 0xD0, 0x98, 0xAA,
  58636. 0xAB, 0x6C, 0x6F, 0x6D, 0x6B, 0x6A, 0x5C, 0x33, 0xAC, 0xAD, 0xA8, 0x1B,
  58637. 0x38, 0x5D, 0x9F, 0xDA, 0xE7, 0x70, 0x07
  58638. };
  58639. pt = ca_key_der_2048;
  58640. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &pt,
  58641. sizeof_ca_key_der_2048));
  58642. pt = client_cert_der_2048;
  58643. ExpectNotNull(x509 = wolfSSL_d2i_X509(NULL, &pt,
  58644. sizeof_client_cert_der_2048));
  58645. pt = ca_cert_der_2048;
  58646. ExpectNotNull(ca = wolfSSL_d2i_X509(NULL, &pt, sizeof_ca_cert_der_2048));
  58647. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  58648. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  58649. #ifndef NO_ASN_TIME
  58650. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 7 * day;
  58651. ExpectNotNull(notBefore = wolfSSL_ASN1_TIME_adj(NULL, t, 0, 0));
  58652. ExpectNotNull(notAfter = wolfSSL_ASN1_TIME_adj(NULL, t, 365, 0));
  58653. ExpectIntEQ(notAfter->length, 13);
  58654. ExpectTrue(wolfSSL_X509_set_notBefore(x509, notBefore));
  58655. ExpectTrue(wolfSSL_X509_set_notAfter(x509, notAfter));
  58656. #endif
  58657. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  58658. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  58659. ExpectIntEQ(derSz, sizeof(expected));
  58660. #ifndef NO_ASN_TIME
  58661. ExpectIntEQ(XMEMCMP(der, expected, derSz), 0);
  58662. #endif
  58663. wolfSSL_X509_free(ca);
  58664. wolfSSL_X509_free(x509);
  58665. wolfSSL_EVP_PKEY_free(priv);
  58666. #ifndef NO_ASN_TIME
  58667. wolfSSL_ASN1_TIME_free(notBefore);
  58668. wolfSSL_ASN1_TIME_free(notAfter);
  58669. #endif
  58670. #endif
  58671. return EXPECT_RESULT();
  58672. }
  58673. static int test_wolfSSL_X509_sign(void)
  58674. {
  58675. EXPECT_DECLS;
  58676. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_ASN_TIME) && \
  58677. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA)
  58678. int ret = 0;
  58679. char *cn = NULL;
  58680. word32 cnSz = 0;
  58681. X509_NAME *name = NULL;
  58682. X509 *x509 = NULL;
  58683. X509 *ca = NULL;
  58684. DecodedCert dCert;
  58685. EVP_PKEY *pub = NULL;
  58686. EVP_PKEY *priv = NULL;
  58687. EVP_MD_CTX *mctx = NULL;
  58688. #if defined(USE_CERT_BUFFERS_1024)
  58689. const unsigned char* rsaPriv = client_key_der_1024;
  58690. const unsigned char* rsaPub = client_keypub_der_1024;
  58691. const unsigned char* certIssuer = client_cert_der_1024;
  58692. long clientKeySz = (long)sizeof_client_key_der_1024;
  58693. long clientPubKeySz = (long)sizeof_client_keypub_der_1024;
  58694. long certIssuerSz = (long)sizeof_client_cert_der_1024;
  58695. #elif defined(USE_CERT_BUFFERS_2048)
  58696. const unsigned char* rsaPriv = client_key_der_2048;
  58697. const unsigned char* rsaPub = client_keypub_der_2048;
  58698. const unsigned char* certIssuer = client_cert_der_2048;
  58699. long clientKeySz = (long)sizeof_client_key_der_2048;
  58700. long clientPubKeySz = (long)sizeof_client_keypub_der_2048;
  58701. long certIssuerSz = (long)sizeof_client_cert_der_2048;
  58702. #endif
  58703. byte sn[16];
  58704. int snSz = sizeof(sn);
  58705. /* Set X509_NAME fields */
  58706. ExpectNotNull(name = X509_NAME_new());
  58707. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  58708. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  58709. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  58710. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  58711. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  58712. (byte*)"support@wolfssl.com", 19, -1, 0), SSL_SUCCESS);
  58713. /* Get private and public keys */
  58714. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &rsaPriv,
  58715. clientKeySz));
  58716. ExpectNotNull(pub = wolfSSL_d2i_PUBKEY(NULL, &rsaPub, clientPubKeySz));
  58717. ExpectNotNull(x509 = X509_new());
  58718. /* Set version 3 */
  58719. ExpectIntNE(X509_set_version(x509, 2L), 0);
  58720. /* Set subject name, add pubkey, and sign certificate */
  58721. ExpectIntEQ(X509_set_subject_name(x509, name), SSL_SUCCESS);
  58722. X509_NAME_free(name);
  58723. name = NULL;
  58724. ExpectIntEQ(X509_set_pubkey(x509, pub), SSL_SUCCESS);
  58725. #ifdef WOLFSSL_ALT_NAMES
  58726. /* Add some subject alt names */
  58727. ExpectIntNE(wolfSSL_X509_add_altname(NULL,
  58728. "ipsum", ASN_DNS_TYPE), SSL_SUCCESS);
  58729. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  58730. NULL, ASN_DNS_TYPE), SSL_SUCCESS);
  58731. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  58732. "sphygmomanometer",
  58733. ASN_DNS_TYPE), SSL_SUCCESS);
  58734. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  58735. "supercalifragilisticexpialidocious",
  58736. ASN_DNS_TYPE), SSL_SUCCESS);
  58737. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  58738. "Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch",
  58739. ASN_DNS_TYPE), SSL_SUCCESS);
  58740. #ifdef WOLFSSL_IP_ALT_NAME
  58741. {
  58742. unsigned char ip4_type[] = {127,128,0,255};
  58743. unsigned char ip6_type[] = {0xdd, 0xcc, 0xba, 0xab,
  58744. 0xff, 0xee, 0x99, 0x88,
  58745. 0x77, 0x66, 0x55, 0x44,
  58746. 0x00, 0x33, 0x22, 0x11};
  58747. ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (char*)ip4_type,
  58748. sizeof(ip4_type), ASN_IP_TYPE), SSL_SUCCESS);
  58749. ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (char*)ip6_type,
  58750. sizeof(ip6_type), ASN_IP_TYPE), SSL_SUCCESS);
  58751. }
  58752. #endif
  58753. #endif /* WOLFSSL_ALT_NAMES */
  58754. {
  58755. ASN1_UTCTIME* infinite_past = NULL;
  58756. ExpectNotNull(infinite_past = ASN1_UTCTIME_set(NULL, 0));
  58757. ExpectIntEQ(X509_set1_notBefore(x509, infinite_past), 1);
  58758. ASN1_UTCTIME_free(infinite_past);
  58759. }
  58760. /* test valid sign case */
  58761. ExpectIntGT(ret = X509_sign(x509, priv, EVP_sha256()), 0);
  58762. /* test valid X509_sign_ctx case */
  58763. ExpectNotNull(mctx = EVP_MD_CTX_new());
  58764. ExpectIntEQ(EVP_DigestSignInit(mctx, NULL, EVP_sha256(), NULL, priv), 1);
  58765. ExpectIntGT(X509_sign_ctx(x509, mctx), 0);
  58766. #if defined(OPENSSL_ALL) && defined(WOLFSSL_ALT_NAMES)
  58767. ExpectIntEQ(X509_get_ext_count(x509), 1);
  58768. #endif
  58769. #if defined(WOLFSSL_ALT_NAMES) && defined(WOLFSSL_IP_ALT_NAME)
  58770. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "127.128.0.255", 0), 1);
  58771. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "DDCC:BAAB:FFEE:9988:7766:5544:0033:2211", 0), 1);
  58772. #endif
  58773. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, sn, &snSz),
  58774. WOLFSSL_SUCCESS);
  58775. DEBUG_WRITE_CERT_X509(x509, "signed.pem");
  58776. /* Variation in size depends on ASN.1 encoding when MSB is set.
  58777. * WOLFSSL_ASN_TEMPLATE code does not generate a serial number
  58778. * with the MSB set. See GenerateInteger in asn.c */
  58779. #ifndef USE_CERT_BUFFERS_1024
  58780. #ifndef WOLFSSL_ALT_NAMES
  58781. /* Valid case - size should be 781-786 with 16 byte serial number */
  58782. ExpectTrue((781 + snSz <= ret) && (ret <= 781 + 5 + snSz));
  58783. #elif defined(WOLFSSL_IP_ALT_NAME)
  58784. /* Valid case - size should be 955-960 with 16 byte serial number */
  58785. ExpectTrue((939 + snSz <= ret) && (ret <= 939 + 5 + snSz));
  58786. #else
  58787. /* Valid case - size should be 926-931 with 16 byte serial number */
  58788. ExpectTrue((910 + snSz <= ret) && (ret <= 910 + 5 + snSz));
  58789. #endif
  58790. #else
  58791. #ifndef WOLFSSL_ALT_NAMES
  58792. /* Valid case - size should be 537-542 with 16 byte serial number */
  58793. ExpectTrue((521 + snSz <= ret) && (ret <= 521 + 5 + snSz));
  58794. #elif defined(OPENSSL_ALL) || defined(WOLFSSL_IP_ALT_NAME)
  58795. /* Valid case - size should be 695-670 with 16 byte serial number */
  58796. ExpectTrue((679 + snSz <= ret) && (ret <= 679 + 5 + snSz));
  58797. #else
  58798. /* Valid case - size should be 666-671 with 16 byte serial number */
  58799. ExpectTrue((650 + snSz <= ret) && (ret <= 650 + 5 + snSz));
  58800. #endif
  58801. #endif
  58802. /* check that issuer name is as expected after signature */
  58803. InitDecodedCert(&dCert, certIssuer, (word32)certIssuerSz, 0);
  58804. ExpectIntEQ(ParseCert(&dCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  58805. ExpectNotNull(ca = d2i_X509(NULL, &certIssuer, (int)certIssuerSz));
  58806. ExpectNotNull(name = X509_get_subject_name(ca));
  58807. cnSz = X509_NAME_get_sz(name);
  58808. ExpectNotNull(cn = (char*)XMALLOC(cnSz, HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  58809. ExpectNotNull(cn = X509_NAME_oneline(name, cn, (int)cnSz));
  58810. ExpectIntEQ(0, XSTRNCMP(cn, dCert.subject, XSTRLEN(cn)));
  58811. XFREE(cn, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  58812. cn = NULL;
  58813. #ifdef WOLFSSL_MULTI_ATTRIB
  58814. /* test adding multiple OU's to the signer */
  58815. ExpectNotNull(name = X509_get_subject_name(ca));
  58816. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_UTF8,
  58817. (byte*)"OU1", 3, -1, 0), SSL_SUCCESS);
  58818. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_UTF8,
  58819. (byte*)"OU2", 3, -1, 0), SSL_SUCCESS);
  58820. ExpectIntGT(X509_sign(ca, priv, EVP_sha256()), 0);
  58821. #endif
  58822. ExpectNotNull(name = X509_get_subject_name(ca));
  58823. ExpectIntEQ(X509_set_issuer_name(x509, name), SSL_SUCCESS);
  58824. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  58825. ExpectNotNull(name = X509_get_issuer_name(x509));
  58826. cnSz = X509_NAME_get_sz(name);
  58827. ExpectNotNull(cn = (char*)XMALLOC(cnSz, HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  58828. ExpectNotNull(cn = X509_NAME_oneline(name, cn, (int)cnSz));
  58829. /* compare and don't include the multi-attrib "/OU=OU1/OU=OU2" above */
  58830. ExpectIntEQ(0, XSTRNCMP(cn, dCert.issuer, XSTRLEN(dCert.issuer)));
  58831. XFREE(cn, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  58832. cn = NULL;
  58833. FreeDecodedCert(&dCert);
  58834. /* Test invalid parameters */
  58835. ExpectIntEQ(X509_sign(NULL, priv, EVP_sha256()), 0);
  58836. ExpectIntEQ(X509_sign(x509, NULL, EVP_sha256()), 0);
  58837. ExpectIntEQ(X509_sign(x509, priv, NULL), 0);
  58838. ExpectIntEQ(X509_sign_ctx(NULL, mctx), 0);
  58839. EVP_MD_CTX_free(mctx);
  58840. mctx = NULL;
  58841. ExpectNotNull(mctx = EVP_MD_CTX_new());
  58842. ExpectIntEQ(X509_sign_ctx(x509, mctx), 0);
  58843. ExpectIntEQ(X509_sign_ctx(x509, NULL), 0);
  58844. /* test invalid version number */
  58845. #if defined(OPENSSL_ALL)
  58846. ExpectIntNE(X509_set_version(x509, 6L), 0);
  58847. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  58848. /* uses ParseCert which fails on bad version number */
  58849. ExpectIntEQ(X509_get_ext_count(x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  58850. #endif
  58851. EVP_MD_CTX_free(mctx);
  58852. EVP_PKEY_free(priv);
  58853. EVP_PKEY_free(pub);
  58854. X509_free(x509);
  58855. X509_free(ca);
  58856. #endif
  58857. return EXPECT_RESULT();
  58858. }
  58859. static int test_wolfSSL_X509_get0_tbs_sigalg(void)
  58860. {
  58861. EXPECT_DECLS;
  58862. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD))
  58863. X509* x509 = NULL;
  58864. const X509_ALGOR* alg;
  58865. ExpectNotNull(x509 = X509_new());
  58866. ExpectNull(alg = X509_get0_tbs_sigalg(NULL));
  58867. ExpectNotNull(alg = X509_get0_tbs_sigalg(x509));
  58868. X509_free(x509);
  58869. #endif
  58870. return EXPECT_RESULT();
  58871. }
  58872. static int test_wolfSSL_X509_ALGOR_get0(void)
  58873. {
  58874. EXPECT_DECLS;
  58875. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  58876. !defined(NO_SHA256) && !defined(NO_RSA)
  58877. X509* x509 = NULL;
  58878. const ASN1_OBJECT* obj = NULL;
  58879. const X509_ALGOR* alg = NULL;
  58880. X509_ALGOR* alg2 = NULL;
  58881. int pptype = 0;
  58882. const void *ppval = NULL;
  58883. byte* der = NULL;
  58884. const byte* tmp = NULL;
  58885. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  58886. SSL_FILETYPE_PEM));
  58887. ExpectNotNull(alg = X509_get0_tbs_sigalg(x509));
  58888. /* Invalid case */
  58889. X509_ALGOR_get0(&obj, NULL, NULL, NULL);
  58890. ExpectNull(obj);
  58891. /* Valid case */
  58892. X509_ALGOR_get0(&obj, &pptype, &ppval, alg);
  58893. ExpectNotNull(obj);
  58894. ExpectNull(ppval);
  58895. ExpectIntNE(pptype, 0);
  58896. /* Make sure NID of X509_ALGOR is Sha256 with RSA */
  58897. ExpectIntEQ(OBJ_obj2nid(obj), NID_sha256WithRSAEncryption);
  58898. ExpectIntEQ(i2d_X509_ALGOR(alg, &der), 15);
  58899. tmp = der;
  58900. ExpectNotNull(d2i_X509_ALGOR(&alg2, &tmp, 15));
  58901. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  58902. X509_free(x509);
  58903. X509_ALGOR_free(alg2);
  58904. #endif
  58905. return EXPECT_RESULT();
  58906. }
  58907. static int test_wolfSSL_X509_VERIFY_PARAM(void)
  58908. {
  58909. EXPECT_DECLS;
  58910. #if defined(OPENSSL_EXTRA)
  58911. X509_VERIFY_PARAM *paramTo = NULL;
  58912. X509_VERIFY_PARAM *paramFrom = NULL;
  58913. char testIPv4[] = "127.0.0.1";
  58914. char testIPv6[] = "0001:0000:0000:0000:0000:0000:0000:0000/32";
  58915. char testhostName1[] = "foo.hoge.com";
  58916. char testhostName2[] = "foobar.hoge.com";
  58917. ExpectNotNull(paramTo = X509_VERIFY_PARAM_new());
  58918. ExpectNotNull(XMEMSET(paramTo, 0, sizeof(X509_VERIFY_PARAM)));
  58919. ExpectNotNull(paramFrom = X509_VERIFY_PARAM_new());
  58920. ExpectNotNull(XMEMSET(paramFrom, 0, sizeof(X509_VERIFY_PARAM)));
  58921. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramFrom, testhostName1,
  58922. (int)XSTRLEN(testhostName1)), 1);
  58923. ExpectIntEQ(0, XSTRNCMP(paramFrom->hostName, testhostName1,
  58924. (int)XSTRLEN(testhostName1)));
  58925. X509_VERIFY_PARAM_set_hostflags(NULL, 0x00);
  58926. X509_VERIFY_PARAM_set_hostflags(paramFrom, 0x01);
  58927. ExpectIntEQ(0x01, paramFrom->hostFlags);
  58928. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(NULL, testIPv4), 0);
  58929. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, testIPv4), 1);
  58930. ExpectIntEQ(0, XSTRNCMP(paramFrom->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  58931. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, NULL), 1);
  58932. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, testIPv6), 1);
  58933. ExpectIntEQ(0, XSTRNCMP(paramFrom->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  58934. /* null pointer */
  58935. ExpectIntEQ(X509_VERIFY_PARAM_set1(NULL, paramFrom), 0);
  58936. /* in the case of "from" null, returns success */
  58937. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, NULL), 1);
  58938. ExpectIntEQ(X509_VERIFY_PARAM_set1(NULL, NULL), 0);
  58939. /* inherit flags test : VPARAM_DEFAULT */
  58940. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  58941. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  58942. (int)XSTRLEN(testhostName1)));
  58943. ExpectIntEQ(0x01, paramTo->hostFlags);
  58944. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  58945. /* inherit flags test : VPARAM OVERWRITE */
  58946. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  58947. (int)XSTRLEN(testhostName2)), 1);
  58948. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  58949. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x00);
  58950. if (paramTo != NULL) {
  58951. paramTo->inherit_flags = X509_VP_FLAG_OVERWRITE;
  58952. }
  58953. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  58954. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  58955. (int)XSTRLEN(testhostName1)));
  58956. ExpectIntEQ(0x01, paramTo->hostFlags);
  58957. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  58958. /* inherit flags test : VPARAM_RESET_FLAGS */
  58959. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  58960. (int)XSTRLEN(testhostName2)), 1);
  58961. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  58962. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x10);
  58963. if (paramTo != NULL) {
  58964. paramTo->inherit_flags = X509_VP_FLAG_RESET_FLAGS;
  58965. }
  58966. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  58967. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  58968. (int)XSTRLEN(testhostName1)));
  58969. ExpectIntEQ(0x01, paramTo->hostFlags);
  58970. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  58971. /* inherit flags test : VPARAM_LOCKED */
  58972. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  58973. (int)XSTRLEN(testhostName2)), 1);
  58974. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  58975. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x00);
  58976. if (paramTo != NULL) {
  58977. paramTo->inherit_flags = X509_VP_FLAG_LOCKED;
  58978. }
  58979. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  58980. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName2,
  58981. (int)XSTRLEN(testhostName2)));
  58982. ExpectIntEQ(0x00, paramTo->hostFlags);
  58983. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  58984. /* test for incorrect parameters */
  58985. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(NULL, X509_V_FLAG_CRL_CHECK_ALL),
  58986. 0);
  58987. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(NULL, 0), 0);
  58988. /* inherit flags test : VPARAM_ONCE, not testable yet */
  58989. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(paramTo, X509_V_FLAG_CRL_CHECK_ALL),
  58990. 1);
  58991. ExpectIntEQ(X509_VERIFY_PARAM_get_flags(paramTo),
  58992. X509_V_FLAG_CRL_CHECK_ALL);
  58993. ExpectIntEQ(X509_VERIFY_PARAM_clear_flags(paramTo,
  58994. X509_V_FLAG_CRL_CHECK_ALL), 1);
  58995. ExpectIntEQ(X509_VERIFY_PARAM_get_flags(paramTo), 0);
  58996. X509_VERIFY_PARAM_free(paramTo);
  58997. X509_VERIFY_PARAM_free(paramFrom);
  58998. X509_VERIFY_PARAM_free(NULL); /* to confirm NULL parameter gives no harm */
  58999. #endif
  59000. return EXPECT_RESULT();
  59001. }
  59002. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  59003. !defined(WOLFSSL_HOSTNAME_VERIFY_ALT_NAME_ONLY)
  59004. static int test_wolfSSL_check_domain_verify_count = 0;
  59005. static WC_INLINE int test_wolfSSL_check_domain_verify_cb(int preverify,
  59006. WOLFSSL_X509_STORE_CTX* store)
  59007. {
  59008. EXPECT_DECLS;
  59009. ExpectIntEQ(X509_STORE_CTX_get_error(store), 0);
  59010. ExpectIntEQ(preverify, 1);
  59011. ExpectIntGT(++test_wolfSSL_check_domain_verify_count, 0);
  59012. return EXPECT_SUCCESS();
  59013. }
  59014. static int test_wolfSSL_check_domain_client_cb(WOLFSSL* ssl)
  59015. {
  59016. EXPECT_DECLS;
  59017. X509_VERIFY_PARAM *param = NULL;
  59018. ExpectNotNull(param = SSL_get0_param(ssl));
  59019. /* Domain check should only be done on the leaf cert */
  59020. X509_VERIFY_PARAM_set_hostflags(param,
  59021. X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
  59022. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(param,
  59023. "wolfSSL Server Chain", 0), 1);
  59024. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER,
  59025. test_wolfSSL_check_domain_verify_cb);
  59026. return EXPECT_RESULT();
  59027. }
  59028. static int test_wolfSSL_check_domain_server_cb(WOLFSSL_CTX* ctx)
  59029. {
  59030. EXPECT_DECLS;
  59031. /* Use a cert with different domains in chain */
  59032. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx,
  59033. "certs/intermediate/server-chain.pem"), WOLFSSL_SUCCESS);
  59034. return EXPECT_RESULT();
  59035. }
  59036. static int test_wolfSSL_check_domain(void)
  59037. {
  59038. EXPECT_DECLS;
  59039. test_ssl_cbf func_cb_client;
  59040. test_ssl_cbf func_cb_server;
  59041. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  59042. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  59043. func_cb_client.ssl_ready = &test_wolfSSL_check_domain_client_cb;
  59044. func_cb_server.ctx_ready = &test_wolfSSL_check_domain_server_cb;
  59045. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  59046. &func_cb_server, NULL), TEST_SUCCESS);
  59047. /* Should have been called once for each cert in sent chain */
  59048. #ifdef WOLFSSL_VERIFY_CB_ALL_CERTS
  59049. ExpectIntEQ(test_wolfSSL_check_domain_verify_count, 3);
  59050. #else
  59051. ExpectIntEQ(test_wolfSSL_check_domain_verify_count, 1);
  59052. #endif
  59053. return EXPECT_RESULT();
  59054. }
  59055. #else
  59056. static int test_wolfSSL_check_domain(void)
  59057. {
  59058. EXPECT_DECLS;
  59059. return EXPECT_RESULT();
  59060. }
  59061. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  59062. static int test_wolfSSL_X509_get_X509_PUBKEY(void)
  59063. {
  59064. EXPECT_DECLS;
  59065. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD))
  59066. X509* x509 = NULL;
  59067. X509_PUBKEY* pubKey;
  59068. ExpectNotNull(x509 = X509_new());
  59069. ExpectNull(pubKey = wolfSSL_X509_get_X509_PUBKEY(NULL));
  59070. ExpectNotNull(pubKey = wolfSSL_X509_get_X509_PUBKEY(x509));
  59071. X509_free(x509);
  59072. #endif
  59073. return EXPECT_RESULT();
  59074. }
  59075. static int test_wolfSSL_X509_PUBKEY_RSA(void)
  59076. {
  59077. EXPECT_DECLS;
  59078. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  59079. !defined(NO_SHA256) && !defined(NO_RSA)
  59080. X509* x509 = NULL;
  59081. ASN1_OBJECT* obj = NULL;
  59082. const ASN1_OBJECT* pa_oid = NULL;
  59083. X509_PUBKEY* pubKey = NULL;
  59084. X509_PUBKEY* pubKey2 = NULL;
  59085. EVP_PKEY* evpKey = NULL;
  59086. const unsigned char *pk = NULL;
  59087. int ppklen;
  59088. int pptype;
  59089. X509_ALGOR *pa = NULL;
  59090. const void *pval;
  59091. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  59092. SSL_FILETYPE_PEM));
  59093. ExpectNotNull(pubKey = X509_get_X509_PUBKEY(x509));
  59094. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey), 1);
  59095. ExpectNotNull(pk);
  59096. ExpectNotNull(pa);
  59097. ExpectNotNull(pubKey);
  59098. ExpectIntGT(ppklen, 0);
  59099. ExpectIntEQ(OBJ_obj2nid(obj), NID_rsaEncryption);
  59100. ExpectNotNull(evpKey = X509_PUBKEY_get(pubKey));
  59101. ExpectNotNull(pubKey2 = X509_PUBKEY_new());
  59102. ExpectIntEQ(X509_PUBKEY_set(&pubKey2, evpKey), 1);
  59103. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey2), 1);
  59104. ExpectNotNull(pk);
  59105. ExpectNotNull(pa);
  59106. ExpectIntGT(ppklen, 0);
  59107. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  59108. ExpectNotNull(pa_oid);
  59109. ExpectNull(pval);
  59110. ExpectIntEQ(pptype, V_ASN1_NULL);
  59111. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_RSA);
  59112. X509_PUBKEY_free(pubKey2);
  59113. X509_free(x509);
  59114. EVP_PKEY_free(evpKey);
  59115. #endif
  59116. return EXPECT_RESULT();
  59117. }
  59118. static int test_wolfSSL_X509_PUBKEY_EC(void)
  59119. {
  59120. EXPECT_DECLS;
  59121. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && defined(HAVE_ECC)
  59122. X509* x509 = NULL;
  59123. ASN1_OBJECT* obj = NULL;
  59124. ASN1_OBJECT* poid = NULL;
  59125. const ASN1_OBJECT* pa_oid = NULL;
  59126. X509_PUBKEY* pubKey = NULL;
  59127. X509_PUBKEY* pubKey2 = NULL;
  59128. EVP_PKEY* evpKey = NULL;
  59129. const unsigned char *pk = NULL;
  59130. int ppklen;
  59131. int pptype;
  59132. X509_ALGOR *pa = NULL;
  59133. const void *pval;
  59134. char buf[50];
  59135. ExpectNotNull(x509 = X509_load_certificate_file(cliEccCertFile,
  59136. SSL_FILETYPE_PEM));
  59137. ExpectNotNull(pubKey = X509_get_X509_PUBKEY(x509));
  59138. ExpectNotNull(evpKey = X509_PUBKEY_get(pubKey));
  59139. ExpectNotNull(pubKey2 = X509_PUBKEY_new());
  59140. ExpectIntEQ(X509_PUBKEY_set(&pubKey2, evpKey), 1);
  59141. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey2), 1);
  59142. ExpectNotNull(pk);
  59143. ExpectNotNull(pa);
  59144. ExpectIntGT(ppklen, 0);
  59145. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  59146. ExpectNotNull(pa_oid);
  59147. ExpectNotNull(pval);
  59148. ExpectIntEQ(pptype, V_ASN1_OBJECT);
  59149. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_EC);
  59150. poid = (ASN1_OBJECT *)pval;
  59151. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), poid, 0), 0);
  59152. ExpectIntEQ(OBJ_txt2nid(buf), NID_X9_62_prime256v1);
  59153. X509_PUBKEY_free(pubKey2);
  59154. X509_free(x509);
  59155. EVP_PKEY_free(evpKey);
  59156. #endif
  59157. return EXPECT_RESULT();
  59158. }
  59159. static int test_wolfSSL_X509_PUBKEY_DSA(void)
  59160. {
  59161. EXPECT_DECLS;
  59162. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && !defined(NO_DSA)
  59163. word32 bytes;
  59164. #ifdef USE_CERT_BUFFERS_1024
  59165. byte tmp[ONEK_BUF];
  59166. #elif defined(USE_CERT_BUFFERS_2048)
  59167. byte tmp[TWOK_BUF];
  59168. #else
  59169. byte tmp[TWOK_BUF];
  59170. #endif /* END USE_CERT_BUFFERS_1024 */
  59171. const unsigned char* dsaKeyDer = tmp;
  59172. ASN1_OBJECT* obj = NULL;
  59173. ASN1_STRING* str;
  59174. const ASN1_OBJECT* pa_oid = NULL;
  59175. X509_PUBKEY* pubKey = NULL;
  59176. EVP_PKEY* evpKey = NULL;
  59177. const unsigned char *pk = NULL;
  59178. int ppklen, pptype;
  59179. X509_ALGOR *pa = NULL;
  59180. const void *pval;
  59181. #ifdef USE_CERT_BUFFERS_1024
  59182. XMEMSET(tmp, 0, sizeof(tmp));
  59183. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  59184. bytes = sizeof_dsa_key_der_1024;
  59185. #elif defined(USE_CERT_BUFFERS_2048)
  59186. XMEMSET(tmp, 0, sizeof(tmp));
  59187. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  59188. bytes = sizeof_dsa_key_der_2048;
  59189. #else
  59190. {
  59191. XFILE fp = XBADFILE;
  59192. XMEMSET(tmp, 0, sizeof(tmp));
  59193. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  59194. ExpectIntGT(bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  59195. if (fp != XBADFILE)
  59196. XFCLOSE(fp);
  59197. }
  59198. #endif
  59199. /* Initialize pkey with der format dsa key */
  59200. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_DSA, &evpKey, &dsaKeyDer, bytes));
  59201. ExpectNotNull(pubKey = X509_PUBKEY_new());
  59202. ExpectIntEQ(X509_PUBKEY_set(&pubKey, evpKey), 1);
  59203. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey), 1);
  59204. ExpectNotNull(pk);
  59205. ExpectNotNull(pa);
  59206. ExpectIntGT(ppklen, 0);
  59207. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  59208. ExpectNotNull(pa_oid);
  59209. ExpectNotNull(pval);
  59210. ExpectIntEQ(pptype, V_ASN1_SEQUENCE);
  59211. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_DSA);
  59212. str = (ASN1_STRING *)pval;
  59213. DEBUG_WRITE_DER(ASN1_STRING_data(str), ASN1_STRING_length(str), "str.der");
  59214. #ifdef USE_CERT_BUFFERS_1024
  59215. ExpectIntEQ(ASN1_STRING_length(str), 291);
  59216. #else
  59217. ExpectIntEQ(ASN1_STRING_length(str), 549);
  59218. #endif /* END USE_CERT_BUFFERS_1024 */
  59219. X509_PUBKEY_free(pubKey);
  59220. EVP_PKEY_free(evpKey);
  59221. #endif
  59222. return EXPECT_RESULT();
  59223. }
  59224. static int test_wolfSSL_BUF(void)
  59225. {
  59226. EXPECT_DECLS;
  59227. #if defined(OPENSSL_EXTRA)
  59228. BUF_MEM* buf = NULL;
  59229. ExpectNotNull(buf = BUF_MEM_new());
  59230. ExpectIntEQ(BUF_MEM_grow(buf, 10), 10);
  59231. ExpectIntEQ(BUF_MEM_grow(buf, -1), 0);
  59232. BUF_MEM_free(buf);
  59233. #endif
  59234. return EXPECT_RESULT();
  59235. }
  59236. #if defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_OPENSSL_RAND_CB)
  59237. static int stub_rand_seed(const void *buf, int num)
  59238. {
  59239. (void)buf;
  59240. (void)num;
  59241. return 123;
  59242. }
  59243. static int stub_rand_bytes(unsigned char *buf, int num)
  59244. {
  59245. (void)buf;
  59246. (void)num;
  59247. return 456;
  59248. }
  59249. static byte* was_stub_rand_cleanup_called(void)
  59250. {
  59251. static byte was_called = 0;
  59252. return &was_called;
  59253. }
  59254. static void stub_rand_cleanup(void)
  59255. {
  59256. byte* was_called = was_stub_rand_cleanup_called();
  59257. *was_called = 1;
  59258. return;
  59259. }
  59260. static byte* was_stub_rand_add_called(void)
  59261. {
  59262. static byte was_called = 0;
  59263. return &was_called;
  59264. }
  59265. static int stub_rand_add(const void *buf, int num, double entropy)
  59266. {
  59267. byte* was_called = was_stub_rand_add_called();
  59268. (void)buf;
  59269. (void)num;
  59270. (void)entropy;
  59271. *was_called = 1;
  59272. return 0;
  59273. }
  59274. static int stub_rand_pseudo_bytes(unsigned char *buf, int num)
  59275. {
  59276. (void)buf;
  59277. (void)num;
  59278. return 9876;
  59279. }
  59280. static int stub_rand_status(void)
  59281. {
  59282. return 5432;
  59283. }
  59284. #endif /* OPENSSL_EXTRA && !WOLFSSL_NO_OPENSSL_RAND_CB */
  59285. static int test_wolfSSL_RAND_set_rand_method(void)
  59286. {
  59287. EXPECT_DECLS;
  59288. #if defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_OPENSSL_RAND_CB)
  59289. RAND_METHOD rand_methods = {NULL, NULL, NULL, NULL, NULL, NULL};
  59290. unsigned char* buf = NULL;
  59291. int num = 0;
  59292. double entropy = 0;
  59293. int ret;
  59294. byte* was_cleanup_called = was_stub_rand_cleanup_called();
  59295. byte* was_add_called = was_stub_rand_add_called();
  59296. ExpectNotNull(buf = (byte*)XMALLOC(32 * sizeof(byte), NULL,
  59297. DYNAMIC_TYPE_TMP_BUFFER));
  59298. ExpectIntNE(wolfSSL_RAND_status(), 5432);
  59299. ExpectIntEQ(*was_cleanup_called, 0);
  59300. RAND_cleanup();
  59301. ExpectIntEQ(*was_cleanup_called, 0);
  59302. rand_methods.seed = &stub_rand_seed;
  59303. rand_methods.bytes = &stub_rand_bytes;
  59304. rand_methods.cleanup = &stub_rand_cleanup;
  59305. rand_methods.add = &stub_rand_add;
  59306. rand_methods.pseudorand = &stub_rand_pseudo_bytes;
  59307. rand_methods.status = &stub_rand_status;
  59308. ExpectIntEQ(RAND_set_rand_method(&rand_methods), WOLFSSL_SUCCESS);
  59309. ExpectIntEQ(RAND_seed(buf, num), 123);
  59310. ExpectIntEQ(RAND_bytes(buf, num), 456);
  59311. ExpectIntEQ(RAND_pseudo_bytes(buf, num), 9876);
  59312. ExpectIntEQ(RAND_status(), 5432);
  59313. ExpectIntEQ(*was_add_called, 0);
  59314. /* The function pointer for RAND_add returns int, but RAND_add itself
  59315. * returns void. */
  59316. RAND_add(buf, num, entropy);
  59317. ExpectIntEQ(*was_add_called, 1);
  59318. was_add_called = 0;
  59319. ExpectIntEQ(*was_cleanup_called, 0);
  59320. RAND_cleanup();
  59321. ExpectIntEQ(*was_cleanup_called, 1);
  59322. *was_cleanup_called = 0;
  59323. ret = RAND_set_rand_method(NULL);
  59324. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  59325. ExpectIntNE(RAND_status(), 5432);
  59326. ExpectIntEQ(*was_cleanup_called, 0);
  59327. RAND_cleanup();
  59328. ExpectIntEQ(*was_cleanup_called, 0);
  59329. RAND_set_rand_method(NULL);
  59330. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  59331. #endif /* OPENSSL_EXTRA && !WOLFSSL_NO_OPENSSL_RAND_CB */
  59332. return EXPECT_RESULT();
  59333. }
  59334. static int test_wolfSSL_RAND_bytes(void)
  59335. {
  59336. EXPECT_DECLS;
  59337. #if defined(OPENSSL_EXTRA)
  59338. const int size1 = RNG_MAX_BLOCK_LEN; /* in bytes */
  59339. const int size2 = RNG_MAX_BLOCK_LEN + 1; /* in bytes */
  59340. const int size3 = RNG_MAX_BLOCK_LEN * 2; /* in bytes */
  59341. const int size4 = RNG_MAX_BLOCK_LEN * 4; /* in bytes */
  59342. int max_bufsize;
  59343. byte *my_buf = NULL;
  59344. /* sanity check */
  59345. ExpectIntEQ(RAND_bytes(NULL, 16), 0);
  59346. ExpectIntEQ(RAND_bytes(NULL, 0), 0);
  59347. max_bufsize = size4;
  59348. ExpectNotNull(my_buf = (byte*)XMALLOC(max_bufsize * sizeof(byte), NULL,
  59349. DYNAMIC_TYPE_TMP_BUFFER));
  59350. ExpectIntEQ(RAND_bytes(my_buf, 0), 1);
  59351. ExpectIntEQ(RAND_bytes(my_buf, -1), 0);
  59352. ExpectNotNull(XMEMSET(my_buf, 0, max_bufsize));
  59353. ExpectIntEQ(RAND_bytes(my_buf, size1), 1);
  59354. ExpectIntEQ(RAND_bytes(my_buf, size2), 1);
  59355. ExpectIntEQ(RAND_bytes(my_buf, size3), 1);
  59356. ExpectIntEQ(RAND_bytes(my_buf, size4), 1);
  59357. XFREE(my_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  59358. #endif
  59359. return EXPECT_RESULT();
  59360. }
  59361. static int test_wolfSSL_RAND(void)
  59362. {
  59363. EXPECT_DECLS;
  59364. #if defined(OPENSSL_EXTRA)
  59365. byte seed[16];
  59366. XMEMSET(seed, 0, sizeof(seed));
  59367. /* No global methods set. */
  59368. ExpectIntEQ(RAND_seed(seed, sizeof(seed)), 1);
  59369. ExpectIntEQ(RAND_poll(), 1);
  59370. RAND_cleanup();
  59371. ExpectIntEQ(RAND_egd(NULL), -1);
  59372. #ifndef NO_FILESYSTEM
  59373. {
  59374. char fname[100];
  59375. ExpectNotNull(RAND_file_name(fname, (sizeof(fname) - 1)));
  59376. ExpectIntEQ(RAND_write_file(NULL), 0);
  59377. }
  59378. #endif
  59379. #endif
  59380. return EXPECT_RESULT();
  59381. }
  59382. static int test_wolfSSL_PKCS8_Compat(void)
  59383. {
  59384. EXPECT_DECLS;
  59385. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC) && \
  59386. !defined(NO_BIO)
  59387. PKCS8_PRIV_KEY_INFO* pt = NULL;
  59388. BIO* bio = NULL;
  59389. XFILE f = XBADFILE;
  59390. int bytes = 0;
  59391. char pkcs8_buffer[512];
  59392. #if defined(OPENSSL_ALL) || defined(WOLFSSL_WPAS_SMALL)
  59393. EVP_PKEY *pkey = NULL;
  59394. #endif
  59395. /* file from wolfssl/certs/ directory */
  59396. ExpectTrue((f = XFOPEN("./certs/ecc-keyPkcs8.pem", "rb")) != XBADFILE);
  59397. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer), f)),
  59398. 0);
  59399. if (f != XBADFILE)
  59400. XFCLOSE(f);
  59401. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  59402. ExpectNotNull(pt = d2i_PKCS8_PRIV_KEY_INFO_bio(bio, NULL));
  59403. #if defined(OPENSSL_ALL) || defined(WOLFSSL_WPAS_SMALL)
  59404. ExpectNotNull(pkey = EVP_PKCS82PKEY(pt));
  59405. ExpectIntEQ(EVP_PKEY_type(pkey->type), EVP_PKEY_EC);
  59406. /* gets PKCS8 pointer to pkey */
  59407. ExpectNotNull(EVP_PKEY2PKCS8(pkey));
  59408. EVP_PKEY_free(pkey);
  59409. #endif
  59410. BIO_free(bio);
  59411. PKCS8_PRIV_KEY_INFO_free(pt);
  59412. #endif
  59413. return EXPECT_RESULT();
  59414. }
  59415. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  59416. static int NoPasswordCallBack(char* passwd, int sz, int rw, void* userdata)
  59417. {
  59418. (void)passwd;
  59419. (void)sz;
  59420. (void)rw;
  59421. (void)userdata;
  59422. return -1;
  59423. }
  59424. #endif
  59425. static int test_wolfSSL_PKCS8_d2i(void)
  59426. {
  59427. EXPECT_DECLS;
  59428. #if !defined(HAVE_FIPS) && defined(OPENSSL_EXTRA)
  59429. /* This test ends up using HMAC as a part of PBKDF2, and HMAC
  59430. * requires a 12 byte password in FIPS mode. This test ends up
  59431. * trying to use an 8 byte password. */
  59432. #ifndef NO_FILESYSTEM
  59433. unsigned char pkcs8_buffer[2048];
  59434. const unsigned char* p = NULL;
  59435. int bytes = 0;
  59436. XFILE file = XBADFILE;
  59437. WOLFSSL_EVP_PKEY* pkey = NULL;
  59438. #ifndef NO_BIO
  59439. BIO* bio = NULL;
  59440. #if defined(OPENSSL_ALL) && \
  59441. ((!defined(NO_RSA) && !defined(NO_DES3)) || \
  59442. defined(HAVE_ECC)) && \
  59443. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  59444. WOLFSSL_EVP_PKEY* evpPkey = NULL;
  59445. #endif
  59446. #endif
  59447. #ifndef NO_RSA
  59448. const char rsaDerPkcs8File[] = "./certs/server-keyPkcs8.der";
  59449. const char rsaPemPkcs8File[] = "./certs/server-keyPkcs8.pem";
  59450. #ifndef NO_DES3
  59451. const char rsaDerPkcs8EncFile[] = "./certs/server-keyPkcs8Enc.der";
  59452. #endif
  59453. #endif /* NO_RSA */
  59454. #ifdef HAVE_ECC
  59455. const char ecDerPkcs8File[] = "certs/ecc-keyPkcs8.der";
  59456. const char ecPemPkcs8File[] = "certs/ecc-keyPkcs8.pem";
  59457. #ifndef NO_DES3
  59458. const char ecDerPkcs8EncFile[] = "certs/ecc-keyPkcs8Enc.der";
  59459. #endif
  59460. #endif /* HAVE_ECC */
  59461. #endif /* !NO_FILESYSTEM */
  59462. #if defined(OPENSSL_ALL) && (!defined(NO_RSA) || defined(HAVE_ECC))
  59463. #ifndef NO_RSA
  59464. #ifdef USE_CERT_BUFFERS_1024
  59465. const unsigned char* rsa = (unsigned char*)server_key_der_1024;
  59466. int rsaSz = sizeof_server_key_der_1024;
  59467. #else
  59468. const unsigned char* rsa = (unsigned char*)server_key_der_2048;
  59469. int rsaSz = sizeof_server_key_der_2048;
  59470. #endif
  59471. #endif
  59472. #ifdef HAVE_ECC
  59473. const unsigned char* ec = (unsigned char*)ecc_key_der_256;
  59474. int ecSz = sizeof_ecc_key_der_256;
  59475. #endif
  59476. #endif /* OPENSSL_ALL && (!NO_RSA || HAVE_ECC) */
  59477. #ifndef NO_FILESYSTEM
  59478. (void)pkcs8_buffer;
  59479. (void)p;
  59480. (void)bytes;
  59481. (void)file;
  59482. #ifndef NO_BIO
  59483. (void)bio;
  59484. #endif
  59485. #endif
  59486. #ifdef OPENSSL_ALL
  59487. #ifndef NO_RSA
  59488. /* Try to auto-detect normal RSA private key */
  59489. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &rsa, rsaSz));
  59490. EVP_PKEY_free(pkey);
  59491. pkey = NULL;
  59492. #endif
  59493. #ifdef HAVE_ECC
  59494. /* Try to auto-detect normal EC private key */
  59495. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &ec, ecSz));
  59496. EVP_PKEY_free(pkey);
  59497. pkey = NULL;
  59498. #endif
  59499. #endif /* OPENSSL_ALL */
  59500. #ifndef NO_FILESYSTEM
  59501. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  59502. ExpectIntEQ(PEM_write_PKCS8PrivateKey(XBADFILE, pkey, NULL, NULL, 0, NULL,
  59503. NULL), 0);
  59504. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, NULL, NULL, NULL, 0, NULL,
  59505. NULL), 0);
  59506. #endif
  59507. #ifndef NO_RSA
  59508. /* Get DER encoded RSA PKCS#8 data. */
  59509. ExpectTrue((file = XFOPEN(rsaDerPkcs8File, "rb")) != XBADFILE);
  59510. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  59511. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  59512. file)), 0);
  59513. if (file != XBADFILE) {
  59514. XFCLOSE(file);
  59515. file = XBADFILE;
  59516. }
  59517. p = pkcs8_buffer;
  59518. #ifdef OPENSSL_ALL
  59519. /* Try to decode - auto-detect key type. */
  59520. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &p, bytes));
  59521. #else
  59522. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &p, bytes));
  59523. #endif
  59524. /* Get PEM encoded RSA PKCS#8 data. */
  59525. ExpectTrue((file = XFOPEN(rsaPemPkcs8File, "rb")) != XBADFILE);
  59526. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  59527. file)), 0);
  59528. if (file != XBADFILE) {
  59529. XFCLOSE(file);
  59530. file = XBADFILE;
  59531. }
  59532. #if defined(OPENSSL_ALL) && \
  59533. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  59534. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  59535. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(NULL, pkey, NULL, NULL, 0, NULL,
  59536. NULL), 0);
  59537. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, NULL, NULL, NULL, 0, NULL,
  59538. NULL), 0);
  59539. /* Write PKCS#8 PEM to BIO. */
  59540. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  59541. NULL), bytes);
  59542. /* Write PKCS#8 PEM to stderr. */
  59543. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, NULL, NULL, 0, NULL,
  59544. NULL), bytes);
  59545. /* Compare file and written data */
  59546. ExpectIntEQ(BIO_get_mem_data(bio, &p), bytes);
  59547. ExpectIntEQ(XMEMCMP(p, pkcs8_buffer, bytes), 0);
  59548. BIO_free(bio);
  59549. bio = NULL;
  59550. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  59551. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_gcm(),
  59552. NULL, 0, PasswordCallBack, (void*)"yassl123"), 0);
  59553. #endif
  59554. #if !defined(NO_DES3) && !defined(NO_SHA)
  59555. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  59556. /* Write Encrypted PKCS#8 PEM to BIO. */
  59557. bytes = 1834;
  59558. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_des_ede3_cbc(),
  59559. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  59560. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_des_ede3_cbc(),
  59561. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  59562. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, PasswordCallBack,
  59563. (void*)"yassl123"));
  59564. EVP_PKEY_free(evpPkey);
  59565. evpPkey = NULL;
  59566. BIO_free(bio);
  59567. bio = NULL;
  59568. #endif /* !NO_DES3 && !NO_SHA */
  59569. #endif /* !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  59570. EVP_PKEY_free(pkey);
  59571. pkey = NULL;
  59572. /* PKCS#8 encrypted RSA key */
  59573. #ifndef NO_DES3
  59574. ExpectTrue((file = XFOPEN(rsaDerPkcs8EncFile, "rb")) != XBADFILE);
  59575. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  59576. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  59577. file)), 0);
  59578. if (file != XBADFILE) {
  59579. XFCLOSE(file);
  59580. file = XBADFILE;
  59581. }
  59582. #if defined(OPENSSL_ALL) && \
  59583. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  59584. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  59585. ExpectNotNull(pkey = d2i_PKCS8PrivateKey_bio(bio, NULL, PasswordCallBack,
  59586. (void*)"yassl123"));
  59587. EVP_PKEY_free(pkey);
  59588. pkey = NULL;
  59589. BIO_free(bio);
  59590. bio = NULL;
  59591. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  59592. #endif /* !NO_DES3 */
  59593. #endif /* NO_RSA */
  59594. #ifdef HAVE_ECC
  59595. /* PKCS#8 encode EC key */
  59596. ExpectTrue((file = XFOPEN(ecDerPkcs8File, "rb")) != XBADFILE);
  59597. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  59598. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  59599. file)), 0);
  59600. if (file != XBADFILE) {
  59601. XFCLOSE(file);
  59602. file = XBADFILE;
  59603. }
  59604. p = pkcs8_buffer;
  59605. #ifdef OPENSSL_ALL
  59606. /* Try to decode - auto-detect key type. */
  59607. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &p, bytes));
  59608. #else
  59609. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &p, bytes));
  59610. #endif
  59611. /* Get PEM encoded RSA PKCS#8 data. */
  59612. ExpectTrue((file = XFOPEN(ecPemPkcs8File, "rb")) != XBADFILE);
  59613. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  59614. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  59615. file)), 0);
  59616. if (file != XBADFILE) {
  59617. XFCLOSE(file);
  59618. file = XBADFILE;
  59619. }
  59620. #if defined(OPENSSL_ALL) && \
  59621. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8) && \
  59622. defined(HAVE_AES_CBC)
  59623. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  59624. /* Write PKCS#8 PEM to BIO. */
  59625. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  59626. NULL), bytes);
  59627. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, NULL, NULL, 0, NULL,
  59628. NULL), bytes);
  59629. /* Compare file and written data */
  59630. ExpectIntEQ(BIO_get_mem_data(bio, &p), bytes);
  59631. ExpectIntEQ(XMEMCMP(p, pkcs8_buffer, bytes), 0);
  59632. BIO_free(bio);
  59633. bio = NULL;
  59634. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  59635. /* Write Encrypted PKCS#8 PEM to BIO. */
  59636. bytes = 379;
  59637. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_aes_256_cbc(),
  59638. NULL, 0, NoPasswordCallBack, (void*)"yassl123"), 0);
  59639. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_aes_256_cbc(),
  59640. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  59641. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_cbc(),
  59642. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  59643. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_cbc(),
  59644. (char*)"yassl123", 8, PasswordCallBack, NULL), bytes);
  59645. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_256_cbc(),
  59646. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  59647. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, PasswordCallBack,
  59648. (void*)"yassl123"));
  59649. EVP_PKEY_free(evpPkey);
  59650. evpPkey = NULL;
  59651. BIO_free(bio);
  59652. bio = NULL;
  59653. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 && HAVE_AES_CBC */
  59654. EVP_PKEY_free(pkey);
  59655. pkey = NULL;
  59656. /* PKCS#8 encrypted EC key */
  59657. #ifndef NO_DES3
  59658. ExpectTrue((file = XFOPEN(ecDerPkcs8EncFile, "rb")) != XBADFILE);
  59659. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  59660. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  59661. file)), 0);
  59662. if (file != XBADFILE) {
  59663. XFCLOSE(file);
  59664. file = XBADFILE;
  59665. }
  59666. #if defined(OPENSSL_ALL) && \
  59667. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  59668. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  59669. ExpectNotNull(pkey = d2i_PKCS8PrivateKey_bio(bio, NULL, PasswordCallBack,
  59670. (void*)"yassl123"));
  59671. EVP_PKEY_free(pkey);
  59672. pkey = NULL;
  59673. BIO_free(bio);
  59674. bio = NULL;
  59675. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  59676. #endif /* !NO_DES3 */
  59677. #endif /* HAVE_ECC */
  59678. #endif /* !NO_FILESYSTEM */
  59679. #endif /* HAVE_FIPS && OPENSSL_EXTRA */
  59680. return EXPECT_RESULT();
  59681. }
  59682. #if !defined(SINGLE_THREADED) && defined(ERROR_QUEUE_PER_THREAD) && \
  59683. !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  59684. defined(DEBUG_WOLFSSL)
  59685. #define LOGGING_THREADS 5
  59686. #define ERROR_COUNT 10
  59687. /* copied from logging.c since this is not exposed otherwise */
  59688. #ifndef ERROR_QUEUE_MAX
  59689. #ifdef ERROR_QUEUE_PER_THREAD
  59690. #define ERROR_QUEUE_MAX 16
  59691. #else
  59692. /* this breaks from compat of unlimited error queue size */
  59693. #define ERROR_QUEUE_MAX 100
  59694. #endif
  59695. #endif
  59696. static volatile int loggingThreadsReady;
  59697. static THREAD_RETURN WOLFSSL_THREAD test_logging(void* args)
  59698. {
  59699. const char* file;
  59700. int line;
  59701. unsigned long err;
  59702. int errorCount = 0;
  59703. int i;
  59704. (void)args;
  59705. while (!loggingThreadsReady);
  59706. for (i = 0; i < ERROR_COUNT; i++)
  59707. ERR_put_error(ERR_LIB_PEM, SYS_F_ACCEPT, -990 - i, __FILE__, __LINE__);
  59708. while ((err = ERR_get_error_line(&file, &line))) {
  59709. AssertIntEQ(err, 990 + errorCount);
  59710. errorCount++;
  59711. }
  59712. AssertIntEQ(errorCount, ERROR_COUNT);
  59713. /* test max queue behavior, trying to add an arbitrary 3 errors over */
  59714. ERR_clear_error(); /* ERR_get_error_line() does not remove */
  59715. errorCount = 0;
  59716. for (i = 0; i < ERROR_QUEUE_MAX + 3; i++)
  59717. ERR_put_error(ERR_LIB_PEM, SYS_F_ACCEPT, -990 - i, __FILE__, __LINE__);
  59718. while ((err = ERR_get_error_line(&file, &line))) {
  59719. AssertIntEQ(err, 990 + errorCount);
  59720. errorCount++;
  59721. }
  59722. /* test that the 3 errors over the max were dropped */
  59723. AssertIntEQ(errorCount, ERROR_QUEUE_MAX);
  59724. WOLFSSL_RETURN_FROM_THREAD(0);
  59725. }
  59726. #endif
  59727. static int test_error_queue_per_thread(void)
  59728. {
  59729. int res = TEST_SKIPPED;
  59730. #if !defined(SINGLE_THREADED) && defined(ERROR_QUEUE_PER_THREAD) && \
  59731. !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  59732. defined(DEBUG_WOLFSSL)
  59733. THREAD_TYPE loggingThreads[LOGGING_THREADS];
  59734. int i;
  59735. ERR_clear_error(); /* clear out any error nodes */
  59736. loggingThreadsReady = 0;
  59737. for (i = 0; i < LOGGING_THREADS; i++)
  59738. start_thread(test_logging, NULL, &loggingThreads[i]);
  59739. loggingThreadsReady = 1;
  59740. for (i = 0; i < LOGGING_THREADS; i++)
  59741. join_thread(loggingThreads[i]);
  59742. res = TEST_SUCCESS;
  59743. #endif
  59744. return res;
  59745. }
  59746. static int test_wolfSSL_ERR_put_error(void)
  59747. {
  59748. EXPECT_DECLS;
  59749. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  59750. defined(DEBUG_WOLFSSL)
  59751. const char* file;
  59752. int line;
  59753. ERR_clear_error(); /* clear out any error nodes */
  59754. ERR_put_error(0,SYS_F_ACCEPT, 0, "this file", 0);
  59755. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  59756. ERR_put_error(0,SYS_F_BIND, 1, "this file", 1);
  59757. ExpectIntEQ(ERR_get_error_line(&file, &line), 1);
  59758. ERR_put_error(0,SYS_F_CONNECT, 2, "this file", 2);
  59759. ExpectIntEQ(ERR_get_error_line(&file, &line), 2);
  59760. ERR_put_error(0,SYS_F_FOPEN, 3, "this file", 3);
  59761. ExpectIntEQ(ERR_get_error_line(&file, &line), 3);
  59762. ERR_put_error(0,SYS_F_FREAD, 4, "this file", 4);
  59763. ExpectIntEQ(ERR_get_error_line(&file, &line), 4);
  59764. ERR_put_error(0,SYS_F_GETADDRINFO, 5, "this file", 5);
  59765. ExpectIntEQ(ERR_get_error_line(&file, &line), 5);
  59766. ERR_put_error(0,SYS_F_GETSOCKOPT, 6, "this file", 6);
  59767. ExpectIntEQ(ERR_get_error_line(&file, &line), 6);
  59768. ERR_put_error(0,SYS_F_GETSOCKNAME, 7, "this file", 7);
  59769. ExpectIntEQ(ERR_get_error_line(&file, &line), 7);
  59770. ERR_put_error(0,SYS_F_GETHOSTBYNAME, 8, "this file", 8);
  59771. ExpectIntEQ(ERR_get_error_line(&file, &line), 8);
  59772. ERR_put_error(0,SYS_F_GETNAMEINFO, 9, "this file", 9);
  59773. ExpectIntEQ(ERR_get_error_line(&file, &line), 9);
  59774. ERR_put_error(0,SYS_F_GETSERVBYNAME, 10, "this file", 10);
  59775. ExpectIntEQ(ERR_get_error_line(&file, &line), 10);
  59776. ERR_put_error(0,SYS_F_IOCTLSOCKET, 11, "this file", 11);
  59777. ExpectIntEQ(ERR_get_error_line(&file, &line), 11);
  59778. ERR_put_error(0,SYS_F_LISTEN, 12, "this file", 12);
  59779. ExpectIntEQ(ERR_get_error_line(&file, &line), 12);
  59780. ERR_put_error(0,SYS_F_OPENDIR, 13, "this file", 13);
  59781. ExpectIntEQ(ERR_get_error_line(&file, &line), 13);
  59782. ERR_put_error(0,SYS_F_SETSOCKOPT, 14, "this file", 14);
  59783. ExpectIntEQ(ERR_get_error_line(&file, &line), 14);
  59784. ERR_put_error(0,SYS_F_SOCKET, 15, "this file", 15);
  59785. ExpectIntEQ(ERR_get_error_line(&file, &line), 15);
  59786. #if defined(OPENSSL_ALL) && defined(WOLFSSL_PYTHON)
  59787. ERR_put_error(ERR_LIB_ASN1, SYS_F_ACCEPT, ASN1_R_HEADER_TOO_LONG,
  59788. "this file", 100);
  59789. ExpectIntEQ(wolfSSL_ERR_peek_last_error_line(&file, &line),
  59790. (ERR_LIB_ASN1 << 24) | ASN1_R_HEADER_TOO_LONG);
  59791. ExpectIntEQ(line, 100);
  59792. ExpectIntEQ(wolfSSL_ERR_peek_error(),
  59793. (ERR_LIB_ASN1 << 24) | ASN1_R_HEADER_TOO_LONG);
  59794. ExpectIntEQ(ERR_get_error_line(&file, &line), ASN1_R_HEADER_TOO_LONG);
  59795. #endif
  59796. /* try reading past end of error queue */
  59797. file = NULL;
  59798. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  59799. ExpectNull(file);
  59800. ExpectIntEQ(ERR_get_error_line_data(&file, &line, NULL, NULL), 0);
  59801. PEMerr(4,4);
  59802. ExpectIntEQ(ERR_get_error(), 4);
  59803. /* Empty and free up all error nodes */
  59804. ERR_clear_error();
  59805. /* Verify all nodes are cleared */
  59806. ERR_put_error(0,SYS_F_ACCEPT, 0, "this file", 0);
  59807. ERR_clear_error();
  59808. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  59809. #endif
  59810. return EXPECT_RESULT();
  59811. }
  59812. /*
  59813. * This is a regression test for a bug where the peek/get error functions were
  59814. * drawing from the end of the queue rather than the front.
  59815. */
  59816. static int test_wolfSSL_ERR_get_error_order(void)
  59817. {
  59818. EXPECT_DECLS;
  59819. #if defined(WOLFSSL_HAVE_ERROR_QUEUE) && defined(OPENSSL_EXTRA)
  59820. /* Empty the queue. */
  59821. wolfSSL_ERR_clear_error();
  59822. wolfSSL_ERR_put_error(0, 0, WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), "test", 0);
  59823. wolfSSL_ERR_put_error(0, 0, WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E), "test", 0);
  59824. ExpectIntEQ(wolfSSL_ERR_peek_error(), -WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  59825. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  59826. ExpectIntEQ(wolfSSL_ERR_peek_error(), -WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  59827. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  59828. #endif /* WOLFSSL_HAVE_ERROR_QUEUE && OPENSSL_EXTRA */
  59829. return EXPECT_RESULT();
  59830. }
  59831. #ifndef NO_BIO
  59832. static int test_wolfSSL_ERR_print_errors(void)
  59833. {
  59834. EXPECT_DECLS;
  59835. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  59836. defined(DEBUG_WOLFSSL) && !defined(NO_ERROR_STRINGS)
  59837. BIO* bio = NULL;
  59838. char buf[1024];
  59839. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  59840. ERR_clear_error(); /* clear out any error nodes */
  59841. ERR_put_error(0,SYS_F_ACCEPT, -173, "ssl.c", 0);
  59842. /* Choosing -600 as an unused errno. */
  59843. ERR_put_error(0,SYS_F_BIND, -600, "asn.c", 100);
  59844. ERR_print_errors(bio);
  59845. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 56);
  59846. ExpectIntEQ(XSTRNCMP(
  59847. "error:173:wolfSSL library:Bad function argument:ssl.c:0",
  59848. buf, 55), 0);
  59849. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 57);
  59850. ExpectIntEQ(XSTRNCMP(
  59851. "error:600:wolfSSL library:unknown error number:asn.c:100",
  59852. buf, 56), 0);
  59853. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 1);
  59854. ExpectIntEQ(buf[0], '\0');
  59855. ExpectIntEQ(ERR_get_error_line(NULL, NULL), 0);
  59856. BIO_free(bio);
  59857. #endif
  59858. return EXPECT_RESULT();
  59859. }
  59860. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  59861. defined(DEBUG_WOLFSSL)
  59862. static int test_wolfSSL_error_cb(const char *str, size_t len, void *u)
  59863. {
  59864. wolfSSL_BIO_write((BIO*)u, str, (int)len);
  59865. return 0;
  59866. }
  59867. #endif
  59868. static int test_wolfSSL_ERR_print_errors_cb(void)
  59869. {
  59870. EXPECT_DECLS;
  59871. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  59872. defined(DEBUG_WOLFSSL)
  59873. BIO* bio = NULL;
  59874. char buf[1024];
  59875. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  59876. ERR_clear_error(); /* clear out any error nodes */
  59877. ERR_put_error(0,SYS_F_ACCEPT, -173, "ssl.c", 0);
  59878. ERR_put_error(0,SYS_F_BIND, -275, "asn.c", 100);
  59879. ERR_print_errors_cb(test_wolfSSL_error_cb, bio);
  59880. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 108);
  59881. ExpectIntEQ(XSTRNCMP(
  59882. "wolfSSL error occurred, error = 173 line:0 file:ssl.c",
  59883. buf, 53), 0);
  59884. ExpectIntEQ(XSTRNCMP(
  59885. "wolfSSL error occurred, error = 275 line:100 file:asn.c",
  59886. buf + 53, 55), 0);
  59887. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 0);
  59888. BIO_free(bio);
  59889. #endif
  59890. return EXPECT_RESULT();
  59891. }
  59892. /*
  59893. * Testing WOLFSSL_ERROR_MSG
  59894. */
  59895. static int test_WOLFSSL_ERROR_MSG(void)
  59896. {
  59897. int res = TEST_SKIPPED;
  59898. #if defined(DEBUG_WOLFSSL) || defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) ||\
  59899. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA)
  59900. const char* msg = TEST_STRING;
  59901. WOLFSSL_ERROR_MSG(msg);
  59902. res = TEST_SUCCESS;
  59903. #endif
  59904. return res;
  59905. } /* End test_WOLFSSL_ERROR_MSG */
  59906. /*
  59907. * Testing wc_ERR_remove_state
  59908. */
  59909. static int test_wc_ERR_remove_state(void)
  59910. {
  59911. int res = TEST_SKIPPED;
  59912. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  59913. wc_ERR_remove_state();
  59914. res = TEST_SUCCESS;
  59915. #endif
  59916. return res;
  59917. } /* End test_wc_ERR_remove_state */
  59918. /*
  59919. * Testing wc_ERR_print_errors_fp
  59920. */
  59921. static int test_wc_ERR_print_errors_fp(void)
  59922. {
  59923. EXPECT_DECLS;
  59924. #if (defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)) && \
  59925. (!defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM))
  59926. long sz;
  59927. XFILE fp = XBADFILE;
  59928. WOLFSSL_ERROR(WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59929. ExpectTrue((fp = XFOPEN("./tests/test-log-dump-to-file.txt", "ar")) !=
  59930. XBADFILE);
  59931. wc_ERR_print_errors_fp(fp);
  59932. #if defined(DEBUG_WOLFSSL)
  59933. ExpectTrue(XFSEEK(fp, 0, XSEEK_END) == 0);
  59934. #ifdef NO_ERROR_QUEUE
  59935. ExpectIntEQ(sz = XFTELL(fp), 0);
  59936. #else
  59937. ExpectIntNE(sz = XFTELL(fp), 0);
  59938. #endif
  59939. #endif
  59940. if (fp != XBADFILE)
  59941. XFCLOSE(fp);
  59942. (void)sz;
  59943. #endif
  59944. return EXPECT_RESULT();
  59945. } /* End test_wc_ERR_print_errors_fp */
  59946. #ifdef DEBUG_WOLFSSL
  59947. static void Logging_cb(const int logLevel, const char *const logMessage)
  59948. {
  59949. (void)logLevel;
  59950. (void)logMessage;
  59951. }
  59952. #endif
  59953. /*
  59954. * Testing wolfSSL_GetLoggingCb
  59955. */
  59956. static int test_wolfSSL_GetLoggingCb(void)
  59957. {
  59958. EXPECT_DECLS;
  59959. #ifdef DEBUG_WOLFSSL
  59960. /* Testing without wolfSSL_SetLoggingCb() */
  59961. ExpectNull(wolfSSL_GetLoggingCb());
  59962. /* Testing with wolfSSL_SetLoggingCb() */
  59963. ExpectIntEQ(wolfSSL_SetLoggingCb(Logging_cb), 0);
  59964. ExpectNotNull(wolfSSL_GetLoggingCb());
  59965. ExpectIntEQ(wolfSSL_SetLoggingCb(NULL), 0);
  59966. #endif
  59967. ExpectNull(wolfSSL_GetLoggingCb());
  59968. return EXPECT_RESULT();
  59969. } /* End test_wolfSSL_GetLoggingCb */
  59970. #endif /* !NO_BIO */
  59971. static int test_wolfSSL_MD4(void)
  59972. {
  59973. EXPECT_DECLS;
  59974. #if defined(OPENSSL_EXTRA) && !defined(NO_MD4)
  59975. MD4_CTX md4;
  59976. unsigned char out[16]; /* MD4_DIGEST_SIZE */
  59977. const char* msg = "12345678901234567890123456789012345678901234567890123456"
  59978. "789012345678901234567890";
  59979. const char* test = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f"
  59980. "\xcc\x05\x36";
  59981. int msgSz = (int)XSTRLEN(msg);
  59982. XMEMSET(out, 0, sizeof(out));
  59983. MD4_Init(&md4);
  59984. MD4_Update(&md4, (const void*)msg, (word32)msgSz);
  59985. MD4_Final(out, &md4);
  59986. ExpectIntEQ(XMEMCMP(out, test, sizeof(out)), 0);
  59987. #endif
  59988. return EXPECT_RESULT();
  59989. }
  59990. static int test_wolfSSL_MD5(void)
  59991. {
  59992. EXPECT_DECLS;
  59993. #if defined(OPENSSL_EXTRA) && !defined(NO_MD5)
  59994. byte input1[] = "";
  59995. byte input2[] = "message digest";
  59996. byte hash[WC_MD5_DIGEST_SIZE];
  59997. unsigned char output1[] =
  59998. "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e";
  59999. unsigned char output2[] =
  60000. "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61\xd0";
  60001. WOLFSSL_MD5_CTX md5;
  60002. XMEMSET(&md5, 0, sizeof(md5));
  60003. /* Test cases for illegal parameters */
  60004. ExpectIntEQ(MD5_Init(NULL), 0);
  60005. ExpectIntEQ(MD5_Init(&md5), 1);
  60006. ExpectIntEQ(MD5_Update(NULL, input1, 0), 0);
  60007. ExpectIntEQ(MD5_Update(NULL, NULL, 0), 0);
  60008. ExpectIntEQ(MD5_Update(&md5, NULL, 1), 0);
  60009. ExpectIntEQ(MD5_Final(NULL, &md5), 0);
  60010. ExpectIntEQ(MD5_Final(hash, NULL), 0);
  60011. ExpectIntEQ(MD5_Final(NULL, NULL), 0);
  60012. /* Init MD5 CTX */
  60013. ExpectIntEQ(wolfSSL_MD5_Init(&md5), 1);
  60014. ExpectIntEQ(wolfSSL_MD5_Update(&md5, input1, XSTRLEN((const char*)&input1)),
  60015. 1);
  60016. ExpectIntEQ(wolfSSL_MD5_Final(hash, &md5), 1);
  60017. ExpectIntEQ(XMEMCMP(&hash, output1, WC_MD5_DIGEST_SIZE), 0);
  60018. /* Init MD5 CTX */
  60019. ExpectIntEQ(wolfSSL_MD5_Init(&md5), 1);
  60020. ExpectIntEQ(wolfSSL_MD5_Update(&md5, input2,
  60021. (int)XSTRLEN((const char*)input2)), 1);
  60022. ExpectIntEQ(wolfSSL_MD5_Final(hash, &md5), 1);
  60023. ExpectIntEQ(XMEMCMP(&hash, output2, WC_MD5_DIGEST_SIZE), 0);
  60024. #if !defined(NO_OLD_NAMES) && \
  60025. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  60026. ExpectPtrNE(MD5(NULL, 1, (byte*)&hash), &hash);
  60027. ExpectPtrEq(MD5(input1, 0, (byte*)&hash), &hash);
  60028. ExpectPtrNE(MD5(input1, 1, NULL), NULL);
  60029. ExpectPtrNE(MD5(NULL, 0, NULL), NULL);
  60030. ExpectPtrEq(MD5(input1, (int)XSTRLEN((const char*)&input1), (byte*)&hash),
  60031. &hash);
  60032. ExpectIntEQ(XMEMCMP(&hash, output1, WC_MD5_DIGEST_SIZE), 0);
  60033. ExpectPtrEq(MD5(input2, (int)XSTRLEN((const char*)&input2), (byte*)&hash),
  60034. &hash);
  60035. ExpectIntEQ(XMEMCMP(&hash, output2, WC_MD5_DIGEST_SIZE), 0);
  60036. {
  60037. byte data[] = "Data to be hashed.";
  60038. XMEMSET(hash, 0, WC_MD5_DIGEST_SIZE);
  60039. ExpectNotNull(MD5(data, sizeof(data), NULL));
  60040. ExpectNotNull(MD5(data, sizeof(data), hash));
  60041. ExpectNotNull(MD5(NULL, 0, hash));
  60042. ExpectNull(MD5(NULL, sizeof(data), hash));
  60043. }
  60044. #endif
  60045. #endif
  60046. return EXPECT_RESULT();
  60047. }
  60048. static int test_wolfSSL_MD5_Transform(void)
  60049. {
  60050. EXPECT_DECLS;
  60051. #if defined(OPENSSL_EXTRA) && !defined(NO_MD5)
  60052. byte input1[] = "";
  60053. byte input2[] = "abc";
  60054. byte local[WC_MD5_BLOCK_SIZE];
  60055. word32 sLen = 0;
  60056. #ifdef BIG_ENDIAN_ORDER
  60057. unsigned char output1[] =
  60058. "\x03\x1f\x1d\xac\x6e\xa5\x8e\xd0\x1f\xab\x67\xb7\x74\x31\x77\x91";
  60059. unsigned char output2[] =
  60060. "\xef\xd3\x79\x8d\x67\x17\x25\x90\xa4\x13\x79\xc7\xe3\xa7\x7b\xbc";
  60061. #else
  60062. unsigned char output1[] =
  60063. "\xac\x1d\x1f\x03\xd0\x8e\xa5\x6e\xb7\x67\xab\x1f\x91\x77\x31\x74";
  60064. unsigned char output2[] =
  60065. "\x8d\x79\xd3\xef\x90\x25\x17\x67\xc7\x79\x13\xa4\xbc\x7b\xa7\xe3";
  60066. #endif
  60067. union {
  60068. wc_Md5 native;
  60069. MD5_CTX compat;
  60070. } md5;
  60071. XMEMSET(&md5.compat, 0, sizeof(md5.compat));
  60072. XMEMSET(&local, 0, sizeof(local));
  60073. /* sanity check */
  60074. ExpectIntEQ(MD5_Transform(NULL, NULL), 0);
  60075. ExpectIntEQ(MD5_Transform(NULL, (const byte*)&input1), 0);
  60076. ExpectIntEQ(MD5_Transform(&md5.compat, NULL), 0);
  60077. ExpectIntEQ(wc_Md5Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60078. ExpectIntEQ(wc_Md5Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60079. ExpectIntEQ(wc_Md5Transform(&md5.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60080. /* Init MD5 CTX */
  60081. ExpectIntEQ(wolfSSL_MD5_Init(&md5.compat), 1);
  60082. /* Do Transform*/
  60083. sLen = (word32)XSTRLEN((char*)input1);
  60084. XMEMCPY(local, input1, sLen);
  60085. ExpectIntEQ(MD5_Transform(&md5.compat, (const byte*)&local[0]), 1);
  60086. ExpectIntEQ(XMEMCMP(md5.native.digest, output1, WC_MD5_DIGEST_SIZE), 0);
  60087. /* Init MD5 CTX */
  60088. ExpectIntEQ(MD5_Init(&md5.compat), 1);
  60089. sLen = (word32)XSTRLEN((char*)input2);
  60090. XMEMSET(local, 0, WC_MD5_BLOCK_SIZE);
  60091. XMEMCPY(local, input2, sLen);
  60092. ExpectIntEQ(MD5_Transform(&md5.compat, (const byte*)&local[0]), 1);
  60093. ExpectIntEQ(XMEMCMP(md5.native.digest, output2, WC_MD5_DIGEST_SIZE), 0);
  60094. #endif
  60095. return EXPECT_RESULT();
  60096. }
  60097. static int test_wolfSSL_SHA(void)
  60098. {
  60099. EXPECT_DECLS;
  60100. #if defined(OPENSSL_EXTRA) && !defined(HAVE_SELFTEST)
  60101. #if !defined(NO_SHA) && defined(NO_OLD_SHA_NAMES) && \
  60102. (!defined(HAVE_FIPS) || \
  60103. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2))
  60104. {
  60105. const unsigned char in[] = "abc";
  60106. unsigned char expected[] = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E"
  60107. "\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D";
  60108. unsigned char out[WC_SHA_DIGEST_SIZE];
  60109. unsigned char* p = NULL;
  60110. WOLFSSL_SHA_CTX sha;
  60111. XMEMSET(out, 0, WC_SHA_DIGEST_SIZE);
  60112. ExpectNotNull(SHA1(in, XSTRLEN((char*)in), out));
  60113. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  60114. /* SHA interface test */
  60115. XMEMSET(out, 0, WC_SHA_DIGEST_SIZE);
  60116. ExpectNull(SHA(NULL, XSTRLEN((char*)in), out));
  60117. ExpectNotNull(SHA(in, 0, out));
  60118. ExpectNotNull(SHA(in, XSTRLEN((char*)in), NULL));
  60119. ExpectNotNull(SHA(NULL, 0, out));
  60120. ExpectNotNull(SHA(NULL, 0, NULL));
  60121. ExpectNotNull(SHA(in, XSTRLEN((char*)in), out));
  60122. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  60123. ExpectNotNull(p = SHA(in, XSTRLEN((char*)in), NULL));
  60124. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA_DIGEST_SIZE), 0);
  60125. ExpectIntEQ(wolfSSL_SHA_Init(&sha), 1);
  60126. ExpectIntEQ(wolfSSL_SHA_Update(&sha, in, XSTRLEN((char*)in)), 1);
  60127. ExpectIntEQ(wolfSSL_SHA_Final(out, &sha), 1);
  60128. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  60129. ExpectIntEQ(wolfSSL_SHA1_Init(&sha), 1);
  60130. ExpectIntEQ(wolfSSL_SHA1_Update(&sha, in, XSTRLEN((char*)in)), 1);
  60131. ExpectIntEQ(wolfSSL_SHA1_Final(out, &sha), 1);
  60132. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  60133. }
  60134. #endif
  60135. #if !defined(NO_SHA256)
  60136. {
  60137. const unsigned char in[] = "abc";
  60138. unsigned char expected[] =
  60139. "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  60140. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  60141. "\x15\xAD";
  60142. unsigned char out[WC_SHA256_DIGEST_SIZE];
  60143. unsigned char* p = NULL;
  60144. XMEMSET(out, 0, WC_SHA256_DIGEST_SIZE);
  60145. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  60146. ExpectNotNull(SHA256(in, XSTRLEN((char*)in), out));
  60147. #else
  60148. ExpectNotNull(wolfSSL_SHA256(in, XSTRLEN((char*)in), out));
  60149. #endif
  60150. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA256_DIGEST_SIZE), 0);
  60151. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  60152. ExpectNotNull(p = SHA256(in, XSTRLEN((char*)in), NULL));
  60153. #else
  60154. ExpectNotNull(p = wolfSSL_SHA256(in, XSTRLEN((char*)in), NULL));
  60155. #endif
  60156. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA256_DIGEST_SIZE), 0);
  60157. }
  60158. #endif
  60159. #if defined(WOLFSSL_SHA384)
  60160. {
  60161. const unsigned char in[] = "abc";
  60162. unsigned char expected[] =
  60163. "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  60164. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  60165. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  60166. "\xc8\x25\xa7";
  60167. unsigned char out[WC_SHA384_DIGEST_SIZE];
  60168. unsigned char* p = NULL;
  60169. XMEMSET(out, 0, WC_SHA384_DIGEST_SIZE);
  60170. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  60171. ExpectNotNull(SHA384(in, XSTRLEN((char*)in), out));
  60172. #else
  60173. ExpectNotNull(wolfSSL_SHA384(in, XSTRLEN((char*)in), out));
  60174. #endif
  60175. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA384_DIGEST_SIZE), 0);
  60176. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  60177. ExpectNotNull(p = SHA384(in, XSTRLEN((char*)in), NULL));
  60178. #else
  60179. ExpectNotNull(p = wolfSSL_SHA384(in, XSTRLEN((char*)in), NULL));
  60180. #endif
  60181. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA384_DIGEST_SIZE), 0);
  60182. }
  60183. #endif
  60184. #if defined(WOLFSSL_SHA512)
  60185. {
  60186. const unsigned char in[] = "abc";
  60187. unsigned char expected[] =
  60188. "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  60189. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55"
  60190. "\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3"
  60191. "\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f"
  60192. "\xa5\x4c\xa4\x9f";
  60193. unsigned char out[WC_SHA512_DIGEST_SIZE];
  60194. unsigned char* p = NULL;
  60195. XMEMSET(out, 0, WC_SHA512_DIGEST_SIZE);
  60196. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  60197. ExpectNotNull(SHA512(in, XSTRLEN((char*)in), out));
  60198. #else
  60199. ExpectNotNull(wolfSSL_SHA512(in, XSTRLEN((char*)in), out));
  60200. #endif
  60201. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA512_DIGEST_SIZE), 0);
  60202. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  60203. ExpectNotNull(p = SHA512(in, XSTRLEN((char*)in), NULL));
  60204. #else
  60205. ExpectNotNull(p = wolfSSL_SHA512(in, XSTRLEN((char*)in), NULL));
  60206. #endif
  60207. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA512_DIGEST_SIZE), 0);
  60208. }
  60209. #endif
  60210. #endif
  60211. return EXPECT_RESULT();
  60212. }
  60213. static int test_wolfSSL_SHA_Transform(void)
  60214. {
  60215. EXPECT_DECLS;
  60216. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA)
  60217. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  60218. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  60219. byte input1[] = "";
  60220. byte input2[] = "abc";
  60221. byte local[WC_SHA_BLOCK_SIZE];
  60222. word32 sLen = 0;
  60223. #ifdef BIG_ENDIAN_ORDER
  60224. unsigned char output1[] =
  60225. "\x92\xb4\x04\xe5\x56\x58\x8c\xed\x6c\x1a\xcd\x4e\xbf\x05\x3f\x68"
  60226. "\x09\xf7\x3a\x93";
  60227. unsigned char output2[] =
  60228. "\x97\xb2\x74\x8b\x4f\x5b\xbc\xca\x5b\xc0\xe6\xea\x2d\x40\xb4\xa0"
  60229. "\x7c\x6e\x08\xb8";
  60230. #else
  60231. unsigned char output1[] =
  60232. "\xe5\x04\xb4\x92\xed\x8c\x58\x56\x4e\xcd\x1a\x6c\x68\x3f\x05\xbf"
  60233. "\x93\x3a\xf7\x09";
  60234. unsigned char output2[] =
  60235. "\x8b\x74\xb2\x97\xca\xbc\x5b\x4f\xea\xe6\xc0\x5b\xa0\xb4\x40\x2d"
  60236. "\xb8\x08\x6e\x7c";
  60237. #endif
  60238. union {
  60239. wc_Sha native;
  60240. SHA_CTX compat;
  60241. } sha;
  60242. union {
  60243. wc_Sha native;
  60244. SHA_CTX compat;
  60245. } sha1;
  60246. XMEMSET(&sha.compat, 0, sizeof(sha.compat));
  60247. XMEMSET(&local, 0, sizeof(local));
  60248. /* sanity check */
  60249. ExpectIntEQ(SHA_Transform(NULL, NULL), 0);
  60250. ExpectIntEQ(SHA_Transform(NULL, (const byte*)&input1), 0);
  60251. ExpectIntEQ(SHA_Transform(&sha.compat, NULL), 0);
  60252. ExpectIntEQ(SHA1_Transform(NULL, NULL), 0);
  60253. ExpectIntEQ(SHA1_Transform(NULL, (const byte*)&input1), 0);
  60254. ExpectIntEQ(SHA1_Transform(&sha.compat, NULL), 0);
  60255. ExpectIntEQ(wc_ShaTransform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60256. ExpectIntEQ(wc_ShaTransform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60257. ExpectIntEQ(wc_ShaTransform(&sha.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60258. /* Init SHA CTX */
  60259. ExpectIntEQ(SHA_Init(&sha.compat), 1);
  60260. /* Do Transform*/
  60261. sLen = (word32)XSTRLEN((char*)input1);
  60262. XMEMCPY(local, input1, sLen);
  60263. ExpectIntEQ(SHA_Transform(&sha.compat, (const byte*)&local[0]), 1);
  60264. ExpectIntEQ(XMEMCMP(sha.native.digest, output1, WC_SHA_DIGEST_SIZE), 0);
  60265. ExpectIntEQ(SHA_Final(local, &sha.compat), 1); /* frees resources */
  60266. /* Init SHA CTX */
  60267. ExpectIntEQ(SHA_Init(&sha.compat), 1);
  60268. sLen = (word32)XSTRLEN((char*)input2);
  60269. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  60270. XMEMCPY(local, input2, sLen);
  60271. ExpectIntEQ(SHA_Transform(&sha.compat, (const byte*)&local[0]), 1);
  60272. ExpectIntEQ(XMEMCMP(sha.native.digest, output2, WC_SHA_DIGEST_SIZE), 0);
  60273. ExpectIntEQ(SHA_Final(local, &sha.compat), 1); /* frees resources */
  60274. /* SHA1 */
  60275. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  60276. /* Init SHA CTX */
  60277. ExpectIntEQ(SHA1_Init(&sha1.compat), 1);
  60278. /* Do Transform*/
  60279. sLen = (word32)XSTRLEN((char*)input1);
  60280. XMEMCPY(local, input1, sLen);
  60281. ExpectIntEQ(SHA1_Transform(&sha1.compat, (const byte*)&local[0]), 1);
  60282. ExpectIntEQ(XMEMCMP(sha1.native.digest, output1, WC_SHA_DIGEST_SIZE), 0);
  60283. ExpectIntEQ(SHA1_Final(local, &sha1.compat), 1); /* frees resources */
  60284. /* Init SHA CTX */
  60285. ExpectIntEQ(SHA1_Init(&sha1.compat), 1);
  60286. sLen = (word32)XSTRLEN((char*)input2);
  60287. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  60288. XMEMCPY(local, input2, sLen);
  60289. ExpectIntEQ(SHA1_Transform(&sha1.compat, (const byte*)&local[0]), 1);
  60290. ExpectIntEQ(XMEMCMP(sha1.native.digest, output2, WC_SHA_DIGEST_SIZE), 0);
  60291. ExpectIntEQ(SHA_Final(local, &sha1.compat), 1); /* frees resources */
  60292. #endif
  60293. #endif
  60294. return EXPECT_RESULT();
  60295. }
  60296. static int test_wolfSSL_SHA224(void)
  60297. {
  60298. EXPECT_DECLS;
  60299. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA224) && \
  60300. !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  60301. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2))
  60302. unsigned char input[] =
  60303. "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  60304. unsigned char output[] =
  60305. "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01"
  60306. "\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25";
  60307. size_t inLen;
  60308. byte hash[WC_SHA224_DIGEST_SIZE];
  60309. unsigned char* p = NULL;
  60310. inLen = XSTRLEN((char*)input);
  60311. XMEMSET(hash, 0, WC_SHA224_DIGEST_SIZE);
  60312. ExpectNull(SHA224(NULL, inLen, hash));
  60313. ExpectNotNull(SHA224(input, 0, hash));
  60314. ExpectNotNull(SHA224(input, inLen, NULL));
  60315. ExpectNotNull(SHA224(NULL, 0, hash));
  60316. ExpectNotNull(SHA224(NULL, 0, NULL));
  60317. ExpectNotNull(SHA224(input, inLen, hash));
  60318. ExpectIntEQ(XMEMCMP(hash, output, WC_SHA224_DIGEST_SIZE), 0);
  60319. ExpectNotNull(p = SHA224(input, inLen, NULL));
  60320. ExpectIntEQ(XMEMCMP(p, output, WC_SHA224_DIGEST_SIZE), 0);
  60321. #endif
  60322. return EXPECT_RESULT();
  60323. }
  60324. static int test_wolfSSL_SHA256(void)
  60325. {
  60326. EXPECT_DECLS;
  60327. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && \
  60328. defined(NO_OLD_SHA_NAMES) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  60329. unsigned char input[] =
  60330. "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  60331. unsigned char output[] =
  60332. "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  60333. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  60334. "\x06\xC1";
  60335. size_t inLen;
  60336. byte hash[WC_SHA256_DIGEST_SIZE];
  60337. inLen = XSTRLEN((char*)input);
  60338. XMEMSET(hash, 0, WC_SHA256_DIGEST_SIZE);
  60339. ExpectNotNull(SHA256(input, inLen, hash));
  60340. ExpectIntEQ(XMEMCMP(hash, output, WC_SHA256_DIGEST_SIZE), 0);
  60341. #endif
  60342. return EXPECT_RESULT();
  60343. }
  60344. static int test_wolfSSL_SHA256_Transform(void)
  60345. {
  60346. EXPECT_DECLS;
  60347. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256)
  60348. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  60349. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  60350. !defined(WOLFSSL_DEVCRYPTO_HASH) && !defined(WOLFSSL_AFALG_HASH) && \
  60351. !defined(WOLFSSL_KCAPI_HASH)
  60352. byte input1[] = "";
  60353. byte input2[] = "abc";
  60354. byte local[WC_SHA256_BLOCK_SIZE];
  60355. word32 sLen = 0;
  60356. #ifdef BIG_ENDIAN_ORDER
  60357. unsigned char output1[] =
  60358. "\xda\x56\x98\xbe\x17\xb9\xb4\x69\x62\x33\x57\x99\x77\x9f\xbe\xca"
  60359. "\x8c\xe5\xd4\x91\xc0\xd2\x62\x43\xba\xfe\xf9\xea\x18\x37\xa9\xd8";
  60360. unsigned char output2[] =
  60361. "\x1d\x4e\xd4\x67\x67\x7c\x61\x67\x44\x10\x76\x26\x78\x10\xff\xb8"
  60362. "\x40\xc8\x9a\x39\x73\x16\x60\x8c\xa6\x61\xd6\x05\x91\xf2\x8c\x35";
  60363. #else
  60364. unsigned char output1[] =
  60365. "\xbe\x98\x56\xda\x69\xb4\xb9\x17\x99\x57\x33\x62\xca\xbe\x9f\x77"
  60366. "\x91\xd4\xe5\x8c\x43\x62\xd2\xc0\xea\xf9\xfe\xba\xd8\xa9\x37\x18";
  60367. unsigned char output2[] =
  60368. "\x67\xd4\x4e\x1d\x67\x61\x7c\x67\x26\x76\x10\x44\xb8\xff\x10\x78"
  60369. "\x39\x9a\xc8\x40\x8c\x60\x16\x73\x05\xd6\x61\xa6\x35\x8c\xf2\x91";
  60370. #endif
  60371. union {
  60372. wc_Sha256 native;
  60373. SHA256_CTX compat;
  60374. } sha256;
  60375. XMEMSET(&sha256.compat, 0, sizeof(sha256.compat));
  60376. XMEMSET(&local, 0, sizeof(local));
  60377. /* sanity check */
  60378. ExpectIntEQ(SHA256_Transform(NULL, NULL), 0);
  60379. ExpectIntEQ(SHA256_Transform(NULL, (const byte*)&input1), 0);
  60380. ExpectIntEQ(SHA256_Transform(&sha256.compat, NULL), 0);
  60381. ExpectIntEQ(wc_Sha256Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60382. ExpectIntEQ(wc_Sha256Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60383. ExpectIntEQ(wc_Sha256Transform(&sha256.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60384. /* Init SHA256 CTX */
  60385. ExpectIntEQ(SHA256_Init(&sha256.compat), 1);
  60386. /* Do Transform*/
  60387. sLen = (word32)XSTRLEN((char*)input1);
  60388. XMEMCPY(local, input1, sLen);
  60389. ExpectIntEQ(SHA256_Transform(&sha256.compat, (const byte*)&local[0]), 1);
  60390. ExpectIntEQ(XMEMCMP(sha256.native.digest, output1, WC_SHA256_DIGEST_SIZE),
  60391. 0);
  60392. ExpectIntEQ(SHA256_Final(local, &sha256.compat), 1); /* frees resources */
  60393. /* Init SHA256 CTX */
  60394. ExpectIntEQ(SHA256_Init(&sha256.compat), 1);
  60395. sLen = (word32)XSTRLEN((char*)input2);
  60396. XMEMSET(local, 0, WC_SHA256_BLOCK_SIZE);
  60397. XMEMCPY(local, input2, sLen);
  60398. ExpectIntEQ(SHA256_Transform(&sha256.compat, (const byte*)&local[0]), 1);
  60399. ExpectIntEQ(XMEMCMP(sha256.native.digest, output2, WC_SHA256_DIGEST_SIZE),
  60400. 0);
  60401. ExpectIntEQ(SHA256_Final(local, &sha256.compat), 1); /* frees resources */
  60402. #endif
  60403. #endif
  60404. return EXPECT_RESULT();
  60405. }
  60406. static int test_wolfSSL_SHA512_Transform(void)
  60407. {
  60408. EXPECT_DECLS;
  60409. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512)
  60410. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  60411. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  60412. !defined(WOLFSSL_KCAPI_HASH)
  60413. byte input1[] = "";
  60414. byte input2[] = "abc";
  60415. byte local[WC_SHA512_BLOCK_SIZE];
  60416. word32 sLen = 0;
  60417. #ifdef BIG_ENDIAN_ORDER
  60418. unsigned char output1[] =
  60419. "\xcf\x78\x81\xd5\x77\x4a\xcb\xe8\x53\x33\x62\xe0\xfb\xc7\x80\x70"
  60420. "\x02\x67\x63\x9d\x87\x46\x0e\xda\x30\x86\xcb\x40\xe8\x59\x31\xb0"
  60421. "\x71\x7d\xc9\x52\x88\xa0\x23\xa3\x96\xba\xb2\xc1\x4c\xe0\xb5\xe0"
  60422. "\x6f\xc4\xfe\x04\xea\xe3\x3e\x0b\x91\xf4\xd8\x0c\xbd\x66\x8b\xee";
  60423. unsigned char output2[] =
  60424. "\x11\x10\x93\x4e\xeb\xa0\xcc\x0d\xfd\x33\x43\x9c\xfb\x04\xc8\x21"
  60425. "\xa9\xb4\x26\x3d\xca\xab\x31\x41\xe2\xc6\xaa\xaf\xe1\x67\xd7\xab"
  60426. "\x31\x8f\x2e\x54\x2c\xba\x4e\x83\xbe\x88\xec\x9d\x8f\x2b\x38\x98"
  60427. "\x14\xd2\x4e\x9d\x53\x8b\x5e\x4d\xde\x68\x6c\x69\xaf\x20\x96\xf0";
  60428. #else
  60429. unsigned char output1[] =
  60430. "\xe8\xcb\x4a\x77\xd5\x81\x78\xcf\x70\x80\xc7\xfb\xe0\x62\x33\x53"
  60431. "\xda\x0e\x46\x87\x9d\x63\x67\x02\xb0\x31\x59\xe8\x40\xcb\x86\x30"
  60432. "\xa3\x23\xa0\x88\x52\xc9\x7d\x71\xe0\xb5\xe0\x4c\xc1\xb2\xba\x96"
  60433. "\x0b\x3e\xe3\xea\x04\xfe\xc4\x6f\xee\x8b\x66\xbd\x0c\xd8\xf4\x91";
  60434. unsigned char output2[] =
  60435. "\x0d\xcc\xa0\xeb\x4e\x93\x10\x11\x21\xc8\x04\xfb\x9c\x43\x33\xfd"
  60436. "\x41\x31\xab\xca\x3d\x26\xb4\xa9\xab\xd7\x67\xe1\xaf\xaa\xc6\xe2"
  60437. "\x83\x4e\xba\x2c\x54\x2e\x8f\x31\x98\x38\x2b\x8f\x9d\xec\x88\xbe"
  60438. "\x4d\x5e\x8b\x53\x9d\x4e\xd2\x14\xf0\x96\x20\xaf\x69\x6c\x68\xde";
  60439. #endif
  60440. union {
  60441. wc_Sha512 native;
  60442. SHA512_CTX compat;
  60443. } sha512;
  60444. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  60445. XMEMSET(&local, 0, sizeof(local));
  60446. /* sanity check */
  60447. ExpectIntEQ(SHA512_Transform(NULL, NULL), 0);
  60448. ExpectIntEQ(SHA512_Transform(NULL, (const byte*)&input1), 0);
  60449. ExpectIntEQ(SHA512_Transform(&sha512.compat, NULL), 0);
  60450. ExpectIntEQ(wc_Sha512Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60451. ExpectIntEQ(wc_Sha512Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60452. ExpectIntEQ(wc_Sha512Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60453. /* Init SHA512 CTX */
  60454. ExpectIntEQ(wolfSSL_SHA512_Init(&sha512.compat), 1);
  60455. /* Do Transform*/
  60456. sLen = (word32)XSTRLEN((char*)input1);
  60457. XMEMCPY(local, input1, sLen);
  60458. ExpectIntEQ(SHA512_Transform(&sha512.compat, (const byte*)&local[0]), 1);
  60459. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  60460. WC_SHA512_DIGEST_SIZE), 0);
  60461. ExpectIntEQ(SHA512_Final(local, &sha512.compat), 1); /* frees resources */
  60462. /* Init SHA512 CTX */
  60463. ExpectIntEQ(SHA512_Init(&sha512.compat), 1);
  60464. sLen = (word32)XSTRLEN((char*)input2);
  60465. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  60466. XMEMCPY(local, input2, sLen);
  60467. ExpectIntEQ(SHA512_Transform(&sha512.compat, (const byte*)&local[0]), 1);
  60468. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  60469. WC_SHA512_DIGEST_SIZE), 0);
  60470. ExpectIntEQ(SHA512_Final(local, &sha512.compat), 1); /* frees resources */
  60471. (void)input1;
  60472. #endif
  60473. #endif
  60474. return EXPECT_RESULT();
  60475. }
  60476. static int test_wolfSSL_SHA512_224_Transform(void)
  60477. {
  60478. EXPECT_DECLS;
  60479. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512) && \
  60480. !defined(WOLFSSL_NOSHA512_224)
  60481. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  60482. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  60483. !defined(WOLFSSL_KCAPI_HASH)
  60484. byte input1[] = "";
  60485. byte input2[] = "abc";
  60486. byte local[WC_SHA512_BLOCK_SIZE];
  60487. word32 sLen = 0;
  60488. unsigned char output1[] =
  60489. "\x94\x24\x66\xd4\x60\x3a\xeb\x23\x1d\xa8\x69\x31\x3c\xd2\xde\x11"
  60490. "\x48\x0f\x4a\x5a\xdf\x3a\x8d\x87\xcf\xcd\xbf\xa5\x03\x21\x50\xf1"
  60491. "\x8a\x0d\x0f\x0d\x3c\x07\xba\x52\xe0\xaa\x3c\xbb\xf1\xd3\x3f\xca"
  60492. "\x12\xa7\x61\xf8\x47\xda\x0d\x1b\x79\xc2\x65\x13\x92\xc1\x9c\xa5";
  60493. unsigned char output2[] =
  60494. "\x51\x28\xe7\x0b\xca\x1e\xbc\x5f\xd7\x34\x0b\x48\x30\xd7\xc2\x75"
  60495. "\x6d\x8d\x48\x2c\x1f\xc7\x9e\x2b\x20\x5e\xbb\x0f\x0e\x4d\xb7\x61"
  60496. "\x31\x76\x33\xa0\xb4\x3d\x5f\x93\xc1\x73\xac\xf7\x21\xff\x69\x17"
  60497. "\xce\x66\xe5\x1e\x31\xe7\xf3\x22\x0f\x0b\x34\xd7\x5a\x57\xeb\xbf";
  60498. union {
  60499. wc_Sha512 native;
  60500. SHA512_CTX compat;
  60501. } sha512;
  60502. #ifdef BIG_ENDIAN_ORDER
  60503. ByteReverseWords64((word64*)output1, (word64*)output1, sizeof(output1));
  60504. ByteReverseWords64((word64*)output2, (word64*)output2, sizeof(output2));
  60505. #endif
  60506. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  60507. XMEMSET(&local, 0, sizeof(local));
  60508. /* sanity check */
  60509. ExpectIntEQ(SHA512_224_Transform(NULL, NULL), 0);
  60510. ExpectIntEQ(SHA512_224_Transform(NULL, (const byte*)&input1), 0);
  60511. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, NULL), 0);
  60512. ExpectIntEQ(wc_Sha512_224Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60513. ExpectIntEQ(wc_Sha512_224Transform(NULL, (const byte*)&input1),
  60514. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60515. ExpectIntEQ(wc_Sha512_224Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60516. /* Init SHA512 CTX */
  60517. ExpectIntEQ(wolfSSL_SHA512_224_Init(&sha512.compat), 1);
  60518. /* Do Transform*/
  60519. sLen = (word32)XSTRLEN((char*)input1);
  60520. XMEMCPY(local, input1, sLen);
  60521. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, (const byte*)&local[0]),
  60522. 1);
  60523. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  60524. WC_SHA512_DIGEST_SIZE), 0);
  60525. /* frees resources */
  60526. ExpectIntEQ(SHA512_224_Final(local, &sha512.compat), 1);
  60527. /* Init SHA512 CTX */
  60528. ExpectIntEQ(SHA512_224_Init(&sha512.compat), 1);
  60529. sLen = (word32)XSTRLEN((char*)input2);
  60530. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  60531. XMEMCPY(local, input2, sLen);
  60532. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, (const byte*)&local[0]),
  60533. 1);
  60534. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  60535. WC_SHA512_DIGEST_SIZE), 0);
  60536. /* frees resources */
  60537. ExpectIntEQ(SHA512_224_Final(local, &sha512.compat), 1);
  60538. #endif
  60539. #endif
  60540. return EXPECT_RESULT();
  60541. }
  60542. static int test_wolfSSL_SHA512_256_Transform(void)
  60543. {
  60544. EXPECT_DECLS;
  60545. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512) && \
  60546. !defined(WOLFSSL_NOSHA512_256)
  60547. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  60548. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  60549. !defined(WOLFSSL_KCAPI_HASH)
  60550. byte input1[] = "";
  60551. byte input2[] = "abc";
  60552. byte local[WC_SHA512_BLOCK_SIZE];
  60553. word32 sLen = 0;
  60554. unsigned char output1[] =
  60555. "\xf8\x37\x37\x5a\xd7\x2e\x56\xec\xe2\x51\xa8\x31\x3a\xa0\x63\x2b"
  60556. "\x7e\x7c\x64\xcc\xd9\xff\x2b\x6b\xeb\xc3\xd4\x4d\x7f\x8a\x3a\xb5"
  60557. "\x61\x85\x0b\x37\x30\x9f\x3b\x08\x5e\x7b\xd3\xbc\x6d\x00\x61\xc0"
  60558. "\x65\x9a\xd7\x73\xda\x40\xbe\xc1\xe5\x2f\xc6\x5d\xb7\x9f\xbe\x60";
  60559. unsigned char output2[] =
  60560. "\x22\xad\xc0\x30\xee\xd4\x6a\xef\x13\xee\x5a\x95\x8b\x1f\xb7\xb6"
  60561. "\xb6\xba\xc0\x44\xb8\x18\x3b\xf0\xf6\x4b\x70\x9f\x03\xba\x64\xa1"
  60562. "\xe1\xe3\x45\x15\x91\x7d\xcb\x0b\x9a\xf0\xd2\x8e\x47\x8b\x37\x78"
  60563. "\x91\x41\xa6\xc4\xb0\x29\x8f\x8b\xdd\x78\x5c\xf2\x73\x3f\x21\x31";
  60564. union {
  60565. wc_Sha512 native;
  60566. SHA512_CTX compat;
  60567. } sha512;
  60568. #ifdef BIG_ENDIAN_ORDER
  60569. ByteReverseWords64((word64*)output1, (word64*)output1, sizeof(output1));
  60570. ByteReverseWords64((word64*)output2, (word64*)output2, sizeof(output2));
  60571. #endif
  60572. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  60573. XMEMSET(&local, 0, sizeof(local));
  60574. /* sanity check */
  60575. ExpectIntEQ(SHA512_256_Transform(NULL, NULL), 0);
  60576. ExpectIntEQ(SHA512_256_Transform(NULL, (const byte*)&input1), 0);
  60577. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, NULL), 0);
  60578. ExpectIntEQ(wc_Sha512_256Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60579. ExpectIntEQ(wc_Sha512_256Transform(NULL, (const byte*)&input1),
  60580. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60581. ExpectIntEQ(wc_Sha512_256Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60582. /* Init SHA512 CTX */
  60583. ExpectIntEQ(wolfSSL_SHA512_256_Init(&sha512.compat), 1);
  60584. /* Do Transform*/
  60585. sLen = (word32)XSTRLEN((char*)input1);
  60586. XMEMCPY(local, input1, sLen);
  60587. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, (const byte*)&local[0]),
  60588. 1);
  60589. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  60590. WC_SHA512_DIGEST_SIZE), 0);
  60591. /* frees resources */
  60592. ExpectIntEQ(SHA512_256_Final(local, &sha512.compat), 1);
  60593. /* Init SHA512 CTX */
  60594. ExpectIntEQ(SHA512_256_Init(&sha512.compat), 1);
  60595. sLen = (word32)XSTRLEN((char*)input2);
  60596. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  60597. XMEMCPY(local, input2, sLen);
  60598. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, (const byte*)&local[0]),
  60599. 1);
  60600. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  60601. WC_SHA512_DIGEST_SIZE), 0);
  60602. /* frees resources */
  60603. ExpectIntEQ(SHA512_256_Final(local, &sha512.compat), 1);
  60604. #endif
  60605. #endif
  60606. return EXPECT_RESULT();
  60607. }
  60608. #if defined(OPENSSL_EXTRA) && !defined(NO_HMAC)
  60609. /* helper function for test_wolfSSL_HMAC_CTX, digest size is expected to be a
  60610. * buffer of 64 bytes.
  60611. *
  60612. * returns the size of the digest buffer on success and a negative value on
  60613. * failure.
  60614. */
  60615. static int test_HMAC_CTX_helper(const EVP_MD* type, unsigned char* digest,
  60616. int* sz)
  60617. {
  60618. EXPECT_DECLS;
  60619. HMAC_CTX ctx1;
  60620. HMAC_CTX ctx2;
  60621. unsigned char key[] = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  60622. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  60623. unsigned char long_key[] =
  60624. "0123456789012345678901234567890123456789"
  60625. "0123456789012345678901234567890123456789"
  60626. "0123456789012345678901234567890123456789"
  60627. "0123456789012345678901234567890123456789";
  60628. unsigned char msg[] = "message to hash";
  60629. unsigned int digestSz = 64;
  60630. int keySz = sizeof(key);
  60631. int long_keySz = sizeof(long_key);
  60632. int msgSz = sizeof(msg);
  60633. unsigned char digest2[64];
  60634. unsigned int digestSz2 = 64;
  60635. HMAC_CTX_init(&ctx1);
  60636. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  60637. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60638. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  60639. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60640. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  60641. HMAC_CTX_cleanup(&ctx1);
  60642. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  60643. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz2), SSL_SUCCESS);
  60644. HMAC_CTX_cleanup(&ctx2);
  60645. ExpectIntEQ(digestSz, digestSz2);
  60646. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  60647. /* test HMAC_Init with NULL key */
  60648. /* init after copy */
  60649. HMAC_CTX_init(&ctx1);
  60650. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  60651. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60652. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  60653. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  60654. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60655. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60656. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  60657. HMAC_CTX_cleanup(&ctx1);
  60658. ExpectIntEQ(HMAC_Init(&ctx2, NULL, 0, NULL), SSL_SUCCESS);
  60659. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  60660. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  60661. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  60662. HMAC_CTX_cleanup(&ctx2);
  60663. ExpectIntEQ(digestSz, digestSz2);
  60664. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  60665. /* long key */
  60666. HMAC_CTX_init(&ctx1);
  60667. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)long_key, long_keySz, type),
  60668. SSL_SUCCESS);
  60669. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60670. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  60671. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  60672. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60673. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60674. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  60675. HMAC_CTX_cleanup(&ctx1);
  60676. ExpectIntEQ(HMAC_Init(&ctx2, NULL, 0, NULL), SSL_SUCCESS);
  60677. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  60678. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  60679. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  60680. HMAC_CTX_cleanup(&ctx2);
  60681. ExpectIntEQ(digestSz, digestSz2);
  60682. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  60683. /* init before copy */
  60684. HMAC_CTX_init(&ctx1);
  60685. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  60686. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60687. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  60688. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  60689. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60690. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60691. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  60692. HMAC_CTX_cleanup(&ctx1);
  60693. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  60694. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  60695. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  60696. HMAC_CTX_cleanup(&ctx2);
  60697. ExpectIntEQ(digestSz, digestSz2);
  60698. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  60699. *sz = (int)digestSz;
  60700. return EXPECT_RESULT();
  60701. }
  60702. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_HMAC) */
  60703. static int test_wolfSSL_HMAC_CTX(void)
  60704. {
  60705. EXPECT_DECLS;
  60706. #if defined(OPENSSL_EXTRA) && !defined(NO_HMAC)
  60707. unsigned char digest[64];
  60708. int digestSz;
  60709. WOLFSSL_HMAC_CTX* hmac_ctx = NULL;
  60710. WOLFSSL_HMAC_CTX ctx1;
  60711. WOLFSSL_HMAC_CTX ctx2;
  60712. ExpectNotNull(hmac_ctx = wolfSSL_HMAC_CTX_new());
  60713. ExpectIntEQ(wolfSSL_HMAC_CTX_Init(NULL), 1);
  60714. ExpectIntEQ(wolfSSL_HMAC_CTX_Init(hmac_ctx), 1);
  60715. wolfSSL_HMAC_CTX_free(NULL);
  60716. wolfSSL_HMAC_CTX_free(hmac_ctx);
  60717. XMEMSET(&ctx2, 0, sizeof(WOLFSSL_HMAC_CTX));
  60718. ExpectIntEQ(HMAC_CTX_init(NULL), 1);
  60719. ExpectIntEQ(HMAC_CTX_init(&ctx2), 1);
  60720. ExpectIntEQ(HMAC_CTX_copy(NULL, NULL), 0);
  60721. ExpectIntEQ(HMAC_CTX_copy(NULL, &ctx2), 0);
  60722. ExpectIntEQ(HMAC_CTX_copy(&ctx2, NULL), 0);
  60723. #if defined(HAVE_SELFTEST) || (defined(HAVE_FIPS) && \
  60724. ((! defined(HAVE_FIPS_VERSION)) || \
  60725. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION <= 2)))
  60726. /* Copy object that hasn't had a digest set - MD5. */
  60727. ExpectIntEQ(HMAC_CTX_copy(&ctx1, &ctx2), 1);
  60728. #else
  60729. /* Copy object that hasn't had a digest set. */
  60730. ExpectIntEQ(HMAC_CTX_copy(&ctx1, &ctx2), 0);
  60731. #endif
  60732. HMAC_CTX_cleanup(NULL);
  60733. HMAC_CTX_cleanup(&ctx2);
  60734. ExpectNull(HMAC_CTX_get_md(NULL));
  60735. #ifndef NO_SHA
  60736. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha1(), digest, &digestSz)),
  60737. TEST_SUCCESS);
  60738. ExpectIntEQ(digestSz, 20);
  60739. ExpectIntEQ(XMEMCMP("\xD9\x68\x77\x23\x70\xFB\x53\x70\x53\xBA\x0E\xDC\xDA"
  60740. "\xBF\x03\x98\x31\x19\xB2\xCC", digest, digestSz), 0);
  60741. #endif /* !NO_SHA */
  60742. #ifdef WOLFSSL_SHA224
  60743. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha224(), digest, &digestSz)),
  60744. TEST_SUCCESS);
  60745. ExpectIntEQ(digestSz, 28);
  60746. ExpectIntEQ(XMEMCMP("\x57\xFD\xF4\xE1\x2D\xB0\x79\xD7\x4B\x25\x7E\xB1\x95"
  60747. "\x9C\x11\xAC\x2D\x1E\x78\x94\x4F\x3A\x0F\xED\xF8\xAD"
  60748. "\x02\x0E", digest, digestSz), 0);
  60749. #endif /* WOLFSSL_SHA224 */
  60750. #ifndef NO_SHA256
  60751. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha256(), digest, &digestSz)),
  60752. TEST_SUCCESS);
  60753. ExpectIntEQ(digestSz, 32);
  60754. ExpectIntEQ(XMEMCMP("\x13\xAB\x76\x91\x0C\x37\x86\x8D\xB3\x7E\x30\x0C\xFC"
  60755. "\xB0\x2E\x8E\x4A\xD7\xD4\x25\xCC\x3A\xA9\x0F\xA2\xF2"
  60756. "\x47\x1E\x62\x6F\x5D\xF2", digest, digestSz), 0);
  60757. #endif /* !NO_SHA256 */
  60758. #ifdef WOLFSSL_SHA384
  60759. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha384(), digest, &digestSz)),
  60760. TEST_SUCCESS);
  60761. ExpectIntEQ(digestSz, 48);
  60762. ExpectIntEQ(XMEMCMP("\x9E\xCB\x07\x0C\x11\x76\x3F\x23\xC3\x25\x0E\xC4\xB7"
  60763. "\x28\x77\x95\x99\xD5\x9D\x7A\xBB\x1A\x9F\xB7\xFD\x25"
  60764. "\xC9\x72\x47\x9F\x8F\x86\x76\xD6\x20\x57\x87\xB7\xE7"
  60765. "\xCD\xFB\xC2\xCC\x9F\x2B\xC5\x41\xAB",
  60766. digest, digestSz), 0);
  60767. #endif /* WOLFSSL_SHA384 */
  60768. #ifdef WOLFSSL_SHA512
  60769. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha512(), digest, &digestSz)),
  60770. TEST_SUCCESS);
  60771. ExpectIntEQ(digestSz, 64);
  60772. ExpectIntEQ(XMEMCMP("\xD4\x21\x0C\x8B\x60\x6F\xF4\xBF\x07\x2F\x26\xCC\xAD"
  60773. "\xBC\x06\x0B\x34\x78\x8B\x4F\xD6\xC0\x42\xF1\x33\x10"
  60774. "\x6C\x4F\x1E\x55\x59\xDD\x2A\x9F\x15\x88\x62\xF8\x60"
  60775. "\xA3\x99\x91\xE2\x08\x7B\xF7\x95\x3A\xB0\x92\x48\x60"
  60776. "\x88\x8B\x5B\xB8\x5F\xE9\xB6\xB1\x96\xE3\xB5\xF0",
  60777. digest, digestSz), 0);
  60778. #endif /* WOLFSSL_SHA512 */
  60779. #ifdef WOLFSSL_SHA3
  60780. #ifndef WOLFSSL_NOSHA3_224
  60781. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_224(), digest, &digestSz)),
  60782. TEST_SUCCESS);
  60783. ExpectIntEQ(digestSz, 28);
  60784. ExpectIntEQ(XMEMCMP("\xdc\x53\x25\x3f\xc0\x9d\x2b\x0c\x7f\x59\x11\x17\x08"
  60785. "\x5c\xe8\x43\x31\x01\x5a\xb3\xe3\x08\x37\x71\x26\x0b"
  60786. "\x29\x0f", digest, digestSz), 0);
  60787. #endif
  60788. #ifndef WOLFSSL_NOSHA3_256
  60789. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_256(), digest, &digestSz)),
  60790. TEST_SUCCESS);
  60791. ExpectIntEQ(digestSz, 32);
  60792. ExpectIntEQ(XMEMCMP("\x0f\x00\x89\x82\x15\xce\xd6\x45\x01\x83\xce\xc8\x35"
  60793. "\xab\x71\x07\xc9\xfe\x61\x22\x38\xf9\x09\xad\x35\x65"
  60794. "\x43\x77\x24\xd4\x1e\xf4", digest, digestSz), 0);
  60795. #endif
  60796. #ifndef WOLFSSL_NOSHA3_384
  60797. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_384(), digest, &digestSz)),
  60798. TEST_SUCCESS);
  60799. ExpectIntEQ(digestSz, 48);
  60800. ExpectIntEQ(XMEMCMP("\x0f\x6a\xc0\xfb\xc3\xf2\x80\xb1\xb4\x04\xb6\xc8\x45"
  60801. "\x23\x3b\xb4\xbe\xc6\xea\x85\x07\xca\x8c\x71\xbb\x6e"
  60802. "\x79\xf6\xf9\x2b\x98\xf5\xef\x11\x39\xd4\x5d\xd3\xca"
  60803. "\xc0\xe6\x81\xf7\x73\xf9\x85\x5d\x4f",
  60804. digest, digestSz), 0);
  60805. #endif
  60806. #ifndef WOLFSSL_NOSHA3_512
  60807. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_512(), digest, &digestSz)),
  60808. TEST_SUCCESS);
  60809. ExpectIntEQ(digestSz, 64);
  60810. ExpectIntEQ(XMEMCMP("\x3e\x77\xe3\x59\x42\x89\xed\xc3\xa4\x26\x3d\xa4\x75"
  60811. "\xd2\x84\x8c\xb2\xf3\x25\x04\x47\x61\xce\x1c\x42\x86"
  60812. "\xcd\xf4\x56\xaa\x2f\x84\xb1\x3b\x18\xed\xe6\xd6\x48"
  60813. "\x15\xb0\x29\xc5\x9d\x32\xef\xdd\x3e\x09\xf6\xed\x9e"
  60814. "\x70\xbc\x1c\x63\xf7\x3b\x3e\xe1\xdc\x84\x9c\x1c",
  60815. digest, digestSz), 0);
  60816. #endif
  60817. #endif
  60818. #if !defined(NO_MD5) && (!defined(HAVE_FIPS_VERSION) || \
  60819. HAVE_FIPS_VERSION <= 2)
  60820. ExpectIntEQ((test_HMAC_CTX_helper(EVP_md5(), digest, &digestSz)),
  60821. TEST_SUCCESS);
  60822. ExpectIntEQ(digestSz, 16);
  60823. ExpectIntEQ(XMEMCMP("\xB7\x27\xC4\x41\xE5\x2E\x62\xBA\x54\xED\x72\x70\x9F"
  60824. "\xE4\x98\xDD", digest, digestSz), 0);
  60825. #endif /* !NO_MD5 */
  60826. #endif
  60827. return EXPECT_RESULT();
  60828. }
  60829. #if defined(OPENSSL_EXTRA) && (!defined(NO_SHA256) || \
  60830. defined(WOLFSSL_SHA224) || defined(WOLFSSL_SHA384) || \
  60831. defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA3))
  60832. static int test_openssl_hmac(const WOLFSSL_EVP_MD* md, int md_len)
  60833. {
  60834. EXPECT_DECLS;
  60835. static const unsigned char key[] = "simple test key";
  60836. HMAC_CTX* hmac = NULL;
  60837. ENGINE* e = NULL;
  60838. unsigned char hash[WC_MAX_DIGEST_SIZE];
  60839. unsigned int len;
  60840. ExpectNotNull(hmac = HMAC_CTX_new());
  60841. HMAC_CTX_init(hmac);
  60842. #if defined(HAVE_SELFTEST) || (defined(HAVE_FIPS) && \
  60843. ((! defined(HAVE_FIPS_VERSION)) || \
  60844. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION <= 2)))
  60845. /* Get size on object that hasn't had a digest set - MD5. */
  60846. ExpectIntEQ(HMAC_size(hmac), 16);
  60847. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, NULL), 1);
  60848. ExpectIntEQ(HMAC_Init(hmac, (void*)key, (int)sizeof(key), NULL), 1);
  60849. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, md), 1);
  60850. #else
  60851. ExpectIntEQ(HMAC_size(hmac), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60852. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, NULL), 0);
  60853. ExpectIntEQ(HMAC_Init(hmac, (void*)key, (int)sizeof(key), NULL), 0);
  60854. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, md), 0);
  60855. #endif
  60856. ExpectIntEQ(HMAC_Init_ex(NULL, (void*)key, (int)sizeof(key), md, e), 0);
  60857. ExpectIntEQ(HMAC_Init_ex(hmac, (void*)key, (int)sizeof(key), md, e), 1);
  60858. /* re-using test key as data to hash */
  60859. ExpectIntEQ(HMAC_Update(NULL, key, (int)sizeof(key)), 0);
  60860. ExpectIntEQ(HMAC_Update(hmac, key, (int)sizeof(key)), 1);
  60861. ExpectIntEQ(HMAC_Update(hmac, key, 0), 1);
  60862. ExpectIntEQ(HMAC_Update(hmac, NULL, 0), 1);
  60863. ExpectIntEQ(HMAC_Update(hmac, NULL, (int)sizeof(key)), 1);
  60864. ExpectIntEQ(HMAC_Final(NULL, NULL, &len), 0);
  60865. ExpectIntEQ(HMAC_Final(hmac, NULL, &len), 0);
  60866. ExpectIntEQ(HMAC_Final(NULL, hash, &len), 0);
  60867. ExpectIntEQ(HMAC_Final(hmac, hash, &len), 1);
  60868. ExpectIntEQ(HMAC_Final(hmac, hash, NULL), 1);
  60869. ExpectIntEQ(len, md_len);
  60870. ExpectIntEQ(HMAC_size(NULL), 0);
  60871. ExpectIntEQ(HMAC_size(hmac), md_len);
  60872. ExpectStrEQ(HMAC_CTX_get_md(hmac), md);
  60873. HMAC_cleanup(NULL);
  60874. HMAC_cleanup(hmac);
  60875. HMAC_CTX_free(hmac);
  60876. len = 0;
  60877. ExpectNull(HMAC(NULL, key, (int)sizeof(key), NULL, 0, hash, &len));
  60878. ExpectNull(HMAC(md, NULL, (int)sizeof(key), NULL, 0, hash, &len));
  60879. ExpectNull(HMAC(md, key, (int)sizeof(key), NULL, 0, NULL, &len));
  60880. ExpectNotNull(HMAC(md, key, (int)sizeof(key), NULL, 0, hash, &len));
  60881. ExpectIntEQ(len, md_len);
  60882. ExpectNotNull(HMAC(md, key, (int)sizeof(key), NULL, 0, hash, NULL));
  60883. /* With data. */
  60884. ExpectNotNull(HMAC(md, key, (int)sizeof(key), key, (int)sizeof(key), hash,
  60885. &len));
  60886. /* With NULL data. */
  60887. ExpectNull(HMAC(md, key, (int)sizeof(key), NULL, (int)sizeof(key), hash,
  60888. &len));
  60889. /* With zero length data. */
  60890. ExpectNotNull(HMAC(md, key, (int)sizeof(key), key, 0, hash, &len));
  60891. return EXPECT_RESULT();
  60892. }
  60893. #endif
  60894. static int test_wolfSSL_HMAC(void)
  60895. {
  60896. EXPECT_DECLS;
  60897. #if defined(OPENSSL_EXTRA) && (!defined(NO_SHA256) || \
  60898. defined(WOLFSSL_SHA224) || defined(WOLFSSL_SHA384) || \
  60899. defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA3))
  60900. #ifndef NO_SHA256
  60901. ExpectIntEQ(test_openssl_hmac(EVP_sha256(), (int)WC_SHA256_DIGEST_SIZE),
  60902. TEST_SUCCESS);
  60903. #endif
  60904. #ifdef WOLFSSL_SHA224
  60905. ExpectIntEQ(test_openssl_hmac(EVP_sha224(), (int)WC_SHA224_DIGEST_SIZE),
  60906. TEST_SUCCESS);
  60907. #endif
  60908. #ifdef WOLFSSL_SHA384
  60909. ExpectIntEQ(test_openssl_hmac(EVP_sha384(), (int)WC_SHA384_DIGEST_SIZE),
  60910. TEST_SUCCESS);
  60911. #endif
  60912. #ifdef WOLFSSL_SHA512
  60913. ExpectIntEQ(test_openssl_hmac(EVP_sha512(), (int)WC_SHA512_DIGEST_SIZE),
  60914. TEST_SUCCESS);
  60915. #endif
  60916. #ifdef WOLFSSL_SHA3
  60917. #ifndef WOLFSSL_NOSHA3_224
  60918. ExpectIntEQ(test_openssl_hmac(EVP_sha3_224(),
  60919. (int)WC_SHA3_224_DIGEST_SIZE), TEST_SUCCESS);
  60920. #endif
  60921. #ifndef WOLFSSL_NOSHA3_256
  60922. ExpectIntEQ(test_openssl_hmac(EVP_sha3_256(),
  60923. (int)WC_SHA3_256_DIGEST_SIZE), TEST_SUCCESS);
  60924. #endif
  60925. #ifndef WOLFSSL_NOSHA3_384
  60926. ExpectIntEQ(test_openssl_hmac(EVP_sha3_384(),
  60927. (int)WC_SHA3_384_DIGEST_SIZE), TEST_SUCCESS);
  60928. #endif
  60929. #ifndef WOLFSSL_NOSHA3_512
  60930. ExpectIntEQ(test_openssl_hmac(EVP_sha3_512(),
  60931. (int)WC_SHA3_512_DIGEST_SIZE), TEST_SUCCESS);
  60932. #endif
  60933. #endif
  60934. #ifndef NO_SHA
  60935. ExpectIntEQ(test_openssl_hmac(EVP_sha1(), (int)WC_SHA_DIGEST_SIZE),
  60936. TEST_SUCCESS);
  60937. #endif
  60938. #endif
  60939. return EXPECT_RESULT();
  60940. }
  60941. static int test_wolfSSL_CMAC(void)
  60942. {
  60943. EXPECT_DECLS;
  60944. #if defined(WOLFSSL_CMAC) && defined(OPENSSL_EXTRA) && \
  60945. defined(WOLFSSL_AES_DIRECT)
  60946. int i;
  60947. byte key[AES_256_KEY_SIZE];
  60948. CMAC_CTX* cmacCtx = NULL;
  60949. byte out[AES_BLOCK_SIZE];
  60950. size_t outLen = AES_BLOCK_SIZE;
  60951. for (i=0; i < AES_256_KEY_SIZE; ++i) {
  60952. key[i] = i;
  60953. }
  60954. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  60955. /* Check CMAC_CTX_get0_cipher_ctx; return value not used. */
  60956. ExpectNotNull(CMAC_CTX_get0_cipher_ctx(cmacCtx));
  60957. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  60958. NULL), 1);
  60959. /* re-using test key as data to hash */
  60960. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  60961. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, 0), 1);
  60962. ExpectIntEQ(CMAC_Final(cmacCtx, out, &outLen), 1);
  60963. ExpectIntEQ(outLen, AES_BLOCK_SIZE);
  60964. /* No Update works. */
  60965. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  60966. NULL), 1);
  60967. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  60968. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  60969. NULL), 1);
  60970. /* Test parameters with CMAC_Update. */
  60971. ExpectIntEQ(CMAC_Update(NULL, NULL, 0), 0);
  60972. ExpectIntEQ(CMAC_Update(NULL, key, 0), 0);
  60973. ExpectIntEQ(CMAC_Update(NULL, NULL, AES_128_KEY_SIZE), 0);
  60974. ExpectIntEQ(CMAC_Update(NULL, key, AES_128_KEY_SIZE), 0);
  60975. ExpectIntEQ(CMAC_Update(cmacCtx, key, 0), 1);
  60976. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, 0), 1);
  60977. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, AES_128_KEY_SIZE), 1);
  60978. /* Test parameters with CMAC_Final. */
  60979. ExpectIntEQ(CMAC_Final(NULL, NULL, NULL), 0);
  60980. ExpectIntEQ(CMAC_Final(NULL, out, NULL), 0);
  60981. ExpectIntEQ(CMAC_Final(NULL, NULL, &outLen), 0);
  60982. ExpectIntEQ(CMAC_Final(NULL, out, &outLen), 0);
  60983. ExpectIntEQ(CMAC_Final(cmacCtx, NULL, NULL), 1);
  60984. ExpectIntEQ(CMAC_Final(cmacCtx, NULL, &outLen), 1);
  60985. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  60986. CMAC_CTX_free(cmacCtx);
  60987. /* Test parameters with CMAC Init. */
  60988. cmacCtx = NULL;
  60989. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  60990. ExpectNotNull(CMAC_CTX_get0_cipher_ctx(cmacCtx));
  60991. ExpectIntEQ(CMAC_Init(NULL, NULL, 0, NULL, NULL), 0);
  60992. ExpectIntEQ(CMAC_Init(NULL, key, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  60993. NULL), 0);
  60994. ExpectIntEQ(CMAC_Init(cmacCtx, NULL, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  60995. NULL), 0);
  60996. /* give a key too small for the cipher, verify we get failure */
  60997. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_192_cbc(),
  60998. NULL), 0);
  60999. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_192_KEY_SIZE, NULL, NULL), 0);
  61000. #if defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128)
  61001. /* Only AES-CBC supported. */
  61002. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_gcm(),
  61003. NULL), 0);
  61004. #endif
  61005. CMAC_CTX_free(cmacCtx);
  61006. ExpectNull(CMAC_CTX_get0_cipher_ctx(NULL));
  61007. cmacCtx = NULL;
  61008. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  61009. /* No Init. */
  61010. ExpectIntEQ(CMAC_Final(cmacCtx, out, &outLen), 0);
  61011. CMAC_CTX_free(cmacCtx);
  61012. /* Test AES-256-CBC */
  61013. cmacCtx = NULL;
  61014. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  61015. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_256_KEY_SIZE, EVP_aes_256_cbc(),
  61016. NULL), 1);
  61017. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  61018. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  61019. CMAC_CTX_free(cmacCtx);
  61020. /* Test AES-192-CBC */
  61021. cmacCtx = NULL;
  61022. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  61023. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  61024. NULL), 1);
  61025. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  61026. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  61027. CMAC_CTX_free(cmacCtx);
  61028. cmacCtx = NULL;
  61029. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  61030. CMAC_CTX_free(cmacCtx);
  61031. #endif /* WOLFSSL_CMAC && OPENSSL_EXTRA && WOLFSSL_AES_DIRECT */
  61032. return EXPECT_RESULT();
  61033. }
  61034. static int test_wolfSSL_DES(void)
  61035. {
  61036. EXPECT_DECLS;
  61037. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  61038. const_DES_cblock myDes;
  61039. DES_cblock iv;
  61040. DES_key_schedule key;
  61041. word32 i = 0;
  61042. DES_LONG dl = 0;
  61043. unsigned char msg[] = "hello wolfssl";
  61044. unsigned char weakKey[][8] = {
  61045. { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
  61046. { 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE },
  61047. { 0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1 },
  61048. { 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E }
  61049. };
  61050. unsigned char semiWeakKey[][8] = {
  61051. { 0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E },
  61052. { 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01 },
  61053. { 0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1 },
  61054. { 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01 },
  61055. { 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE },
  61056. { 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01 },
  61057. { 0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1 },
  61058. { 0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E },
  61059. { 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE },
  61060. { 0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E },
  61061. { 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
  61062. { 0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1 }
  61063. };
  61064. DES_check_key(1);
  61065. DES_set_key(&myDes, &key);
  61066. /* check, check of odd parity */
  61067. XMEMSET(myDes, 4, sizeof(const_DES_cblock));
  61068. myDes[0] = 6; /* set even parity */
  61069. XMEMSET(key, 5, sizeof(DES_key_schedule));
  61070. ExpectIntEQ(DES_set_key_checked(&myDes, &key), -1);
  61071. ExpectIntNE(key[0], myDes[0]); /* should not have copied over key */
  61072. ExpectIntEQ(DES_set_key_checked(NULL, NULL), -2);
  61073. ExpectIntEQ(DES_set_key_checked(&myDes, NULL), -2);
  61074. ExpectIntEQ(DES_set_key_checked(NULL, &key), -2);
  61075. /* set odd parity for success case */
  61076. DES_set_odd_parity(&myDes);
  61077. ExpectIntEQ(DES_check_key_parity(&myDes), 1);
  61078. fprintf(stderr, "%02x %02x %02x %02x", myDes[0], myDes[1], myDes[2],
  61079. myDes[3]);
  61080. ExpectIntEQ(DES_set_key_checked(&myDes, &key), 0);
  61081. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  61082. ExpectIntEQ(key[i], myDes[i]);
  61083. }
  61084. ExpectIntEQ(DES_is_weak_key(&myDes), 0);
  61085. /* check weak key */
  61086. XMEMSET(myDes, 1, sizeof(const_DES_cblock));
  61087. XMEMSET(key, 5, sizeof(DES_key_schedule));
  61088. ExpectIntEQ(DES_set_key_checked(&myDes, &key), -2);
  61089. ExpectIntNE(key[0], myDes[0]); /* should not have copied over key */
  61090. DES_set_key_unchecked(NULL, NULL);
  61091. DES_set_key_unchecked(&myDes, NULL);
  61092. DES_set_key_unchecked(NULL, &key);
  61093. /* compare arrays, should be the same */
  61094. /* now do unchecked copy of a weak key over */
  61095. DES_set_key_unchecked(&myDes, &key);
  61096. /* compare arrays, should be the same */
  61097. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  61098. ExpectIntEQ(key[i], myDes[i]);
  61099. }
  61100. ExpectIntEQ(DES_is_weak_key(&myDes), 1);
  61101. myDes[7] = 2;
  61102. ExpectIntEQ(DES_set_key_checked(&myDes, &key), 0);
  61103. ExpectIntEQ(DES_is_weak_key(&myDes), 0);
  61104. ExpectIntEQ(DES_is_weak_key(NULL), 1);
  61105. /* Test all weak keys. */
  61106. for (i = 0; i < sizeof(weakKey) / sizeof(*weakKey); i++) {
  61107. ExpectIntEQ(DES_set_key_checked(&weakKey[i], &key), -2);
  61108. }
  61109. /* Test all semi-weak keys. */
  61110. for (i = 0; i < sizeof(semiWeakKey) / sizeof(*semiWeakKey); i++) {
  61111. ExpectIntEQ(DES_set_key_checked(&semiWeakKey[i], &key), -2);
  61112. }
  61113. /* check DES_key_sched API */
  61114. XMEMSET(key, 1, sizeof(DES_key_schedule));
  61115. ExpectIntEQ(DES_key_sched(&myDes, NULL), 0);
  61116. ExpectIntEQ(DES_key_sched(NULL, &key), 0);
  61117. ExpectIntEQ(DES_key_sched(&myDes, &key), 0);
  61118. /* compare arrays, should be the same */
  61119. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  61120. ExpectIntEQ(key[i], myDes[i]);
  61121. }
  61122. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, NULL, NULL)), 0);
  61123. ExpectIntEQ((DES_cbc_cksum(msg, NULL, 0, NULL, NULL)), 0);
  61124. ExpectIntEQ((DES_cbc_cksum(NULL, &key, 0, NULL, NULL)), 0);
  61125. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, &myDes, NULL)), 0);
  61126. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, NULL, &iv)), 0);
  61127. ExpectIntEQ((DES_cbc_cksum(NULL, &key, sizeof(msg), &myDes, &iv)), 0);
  61128. ExpectIntEQ((DES_cbc_cksum(msg, NULL, sizeof(msg), &myDes, &iv)), 0);
  61129. ExpectIntEQ((DES_cbc_cksum(msg, &key, sizeof(msg), NULL, &iv)), 0);
  61130. ExpectIntEQ((DES_cbc_cksum(msg, &key, sizeof(msg), &myDes, NULL)), 0);
  61131. /* DES_cbc_cksum should return the last 4 of the last 8 bytes after
  61132. * DES_cbc_encrypt on the input */
  61133. XMEMSET(iv, 0, sizeof(DES_cblock));
  61134. XMEMSET(myDes, 5, sizeof(DES_key_schedule));
  61135. ExpectIntGT((dl = DES_cbc_cksum(msg, &key, sizeof(msg), &myDes, &iv)), 0);
  61136. ExpectIntEQ(dl, 480052723);
  61137. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_DES3) */
  61138. return EXPECT_RESULT();
  61139. }
  61140. static int test_wolfSSL_DES_ncbc(void)
  61141. {
  61142. EXPECT_DECLS;
  61143. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  61144. const_DES_cblock myDes;
  61145. DES_cblock iv = {1};
  61146. DES_key_schedule key = {0};
  61147. unsigned char msg[] = "hello wolfssl";
  61148. unsigned char out[DES_BLOCK_SIZE * 2] = {0};
  61149. unsigned char pln[DES_BLOCK_SIZE * 2] = {0};
  61150. unsigned char exp[] = {0x31, 0x98, 0x2F, 0x3A, 0x55, 0xBF, 0xD8, 0xC4};
  61151. unsigned char exp2[] = {0xC7, 0x45, 0x8B, 0x28, 0x10, 0x53, 0xE0, 0x58};
  61152. /* partial block test */
  61153. DES_set_key(&key, &myDes);
  61154. DES_ncbc_encrypt(msg, out, 3, &myDes, &iv, DES_ENCRYPT);
  61155. ExpectIntEQ(XMEMCMP(exp, out, DES_BLOCK_SIZE), 0);
  61156. ExpectIntEQ(XMEMCMP(exp, iv, DES_BLOCK_SIZE), 0);
  61157. DES_set_key(&key, &myDes);
  61158. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  61159. *((byte*)&iv) = 1;
  61160. DES_ncbc_encrypt(out, pln, 3, &myDes, &iv, DES_DECRYPT);
  61161. ExpectIntEQ(XMEMCMP(msg, pln, 3), 0);
  61162. ExpectIntEQ(XMEMCMP(exp, iv, DES_BLOCK_SIZE), 0);
  61163. /* full block test */
  61164. DES_set_key(&key, &myDes);
  61165. XMEMSET(pln, 0, DES_BLOCK_SIZE);
  61166. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  61167. *((byte*)&iv) = 1;
  61168. DES_ncbc_encrypt(msg, out, 8, &myDes, &iv, DES_ENCRYPT);
  61169. ExpectIntEQ(XMEMCMP(exp2, out, DES_BLOCK_SIZE), 0);
  61170. ExpectIntEQ(XMEMCMP(exp2, iv, DES_BLOCK_SIZE), 0);
  61171. DES_set_key(&key, &myDes);
  61172. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  61173. *((byte*)&iv) = 1;
  61174. DES_ncbc_encrypt(out, pln, 8, &myDes, &iv, DES_DECRYPT);
  61175. ExpectIntEQ(XMEMCMP(msg, pln, 8), 0);
  61176. ExpectIntEQ(XMEMCMP(exp2, iv, DES_BLOCK_SIZE), 0);
  61177. #endif
  61178. return EXPECT_RESULT();
  61179. }
  61180. static int test_wolfSSL_DES_ecb_encrypt(void)
  61181. {
  61182. EXPECT_DECLS;
  61183. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3) && defined(WOLFSSL_DES_ECB)
  61184. WOLFSSL_DES_cblock input1, input2, output1, output2, back1, back2;
  61185. WOLFSSL_DES_key_schedule key;
  61186. XMEMCPY(key, "12345678", sizeof(WOLFSSL_DES_key_schedule));
  61187. XMEMCPY(input1, "Iamhuman", sizeof(WOLFSSL_DES_cblock));
  61188. XMEMCPY(input2, "Whoisit?", sizeof(WOLFSSL_DES_cblock));
  61189. XMEMSET(output1, 0, sizeof(WOLFSSL_DES_cblock));
  61190. XMEMSET(output2, 0, sizeof(WOLFSSL_DES_cblock));
  61191. XMEMSET(back1, 0, sizeof(WOLFSSL_DES_cblock));
  61192. XMEMSET(back2, 0, sizeof(WOLFSSL_DES_cblock));
  61193. wolfSSL_DES_ecb_encrypt(NULL, NULL, NULL, DES_ENCRYPT);
  61194. wolfSSL_DES_ecb_encrypt(&input1, NULL, NULL, DES_ENCRYPT);
  61195. wolfSSL_DES_ecb_encrypt(NULL, &output1, NULL, DES_ENCRYPT);
  61196. wolfSSL_DES_ecb_encrypt(NULL, NULL, &key, DES_ENCRYPT);
  61197. wolfSSL_DES_ecb_encrypt(&input1, &output1, NULL, DES_ENCRYPT);
  61198. wolfSSL_DES_ecb_encrypt(&input1, NULL, &key, DES_ENCRYPT);
  61199. wolfSSL_DES_ecb_encrypt(NULL, &output1, &key, DES_ENCRYPT);
  61200. /* Encrypt messages */
  61201. wolfSSL_DES_ecb_encrypt(&input1, &output1, &key, DES_ENCRYPT);
  61202. wolfSSL_DES_ecb_encrypt(&input2, &output2, &key, DES_ENCRYPT);
  61203. {
  61204. /* Decrypt messages */
  61205. int ret1 = 0;
  61206. int ret2 = 0;
  61207. wolfSSL_DES_ecb_encrypt(&output1, &back1, &key, DES_DECRYPT);
  61208. ExpectIntEQ(ret1 = XMEMCMP((unsigned char *)back1,
  61209. (unsigned char *)input1, sizeof(WOLFSSL_DES_cblock)), 0);
  61210. wolfSSL_DES_ecb_encrypt(&output2, &back2, &key, DES_DECRYPT);
  61211. ExpectIntEQ(ret2 = XMEMCMP((unsigned char *)back2,
  61212. (unsigned char *)input2, sizeof(WOLFSSL_DES_cblock)), 0);
  61213. }
  61214. #endif
  61215. return EXPECT_RESULT();
  61216. }
  61217. static int test_wolfSSL_DES_ede3_cbc_encrypt(void)
  61218. {
  61219. EXPECT_DECLS;
  61220. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  61221. unsigned char input1[8], input2[8];
  61222. unsigned char output1[8], output2[8];
  61223. unsigned char back1[8], back2[8];
  61224. WOLFSSL_DES_cblock iv1, iv2;
  61225. WOLFSSL_DES_key_schedule key1, key2, key3;
  61226. int i;
  61227. XMEMCPY(key1, "12345678", sizeof(WOLFSSL_DES_key_schedule));
  61228. XMEMCPY(key2, "23456781", sizeof(WOLFSSL_DES_key_schedule));
  61229. XMEMCPY(key3, "34567823", sizeof(WOLFSSL_DES_key_schedule));
  61230. XMEMCPY(input1, "Iamhuman", sizeof(input1));
  61231. XMEMCPY(input2, "Whoisit?", sizeof(input2));
  61232. XMEMSET(output1, 0, sizeof(output1));
  61233. XMEMSET(output2, 0, sizeof(output2));
  61234. XMEMSET(back1, 0, sizeof(back1));
  61235. XMEMSET(back2, 0, sizeof(back2));
  61236. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  61237. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  61238. /* Encrypt messages */
  61239. wolfSSL_DES_ede3_cbc_encrypt(input1, output1, 8, &key1, &key2, &key3, &iv1,
  61240. DES_ENCRYPT);
  61241. wolfSSL_DES_ede3_cbc_encrypt(input2, output2, 8, &key1, &key2, &key3, &iv2,
  61242. DES_ENCRYPT);
  61243. {
  61244. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  61245. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  61246. /* Decrypt messages */
  61247. wolfSSL_DES_ede3_cbc_encrypt(output1, back1, 8, &key1, &key2, &key3,
  61248. &iv1, DES_DECRYPT);
  61249. ExpectIntEQ(XMEMCMP(back1, input1, sizeof(input1)), 0);
  61250. wolfSSL_DES_ede3_cbc_encrypt(output2, back2, 8, &key1, &key2, &key3,
  61251. &iv2, DES_DECRYPT);
  61252. ExpectIntEQ(XMEMCMP(back2, input2, sizeof(input2)), 0);
  61253. }
  61254. for (i = 0; i < 8; i++) {
  61255. XMEMSET(output1, 0, sizeof(output1));
  61256. XMEMSET(output2, 0, sizeof(output2));
  61257. XMEMSET(back1, 0, sizeof(back1));
  61258. XMEMSET(back2, 0, sizeof(back2));
  61259. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  61260. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  61261. /* Encrypt partial messages */
  61262. wolfSSL_DES_ede3_cbc_encrypt(input1, output1, i, &key1, &key2, &key3,
  61263. &iv1, DES_ENCRYPT);
  61264. wolfSSL_DES_ede3_cbc_encrypt(input2, output2, i, &key1, &key2, &key3,
  61265. &iv2, DES_ENCRYPT);
  61266. {
  61267. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  61268. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  61269. /* Decrypt messages */
  61270. wolfSSL_DES_ede3_cbc_encrypt(output1, back1, i, &key1, &key2,
  61271. &key3, &iv1, DES_DECRYPT);
  61272. ExpectIntEQ(XMEMCMP(back1, input1, i), 0);
  61273. wolfSSL_DES_ede3_cbc_encrypt(output2, back2, i, &key1, &key2,
  61274. &key3, &iv2, DES_DECRYPT);
  61275. ExpectIntEQ(XMEMCMP(back2, input2, i), 0);
  61276. }
  61277. }
  61278. #endif
  61279. return EXPECT_RESULT();
  61280. }
  61281. static int test_wolfSSL_AES_encrypt(void)
  61282. {
  61283. EXPECT_DECLS;
  61284. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AES_ECB) \
  61285. && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  61286. AES_KEY enc;
  61287. AES_KEY dec;
  61288. const byte msg[] = {
  61289. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  61290. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a
  61291. };
  61292. const byte exp[] = {
  61293. 0xf3, 0xee, 0xd1, 0xbd, 0xb5, 0xd2, 0xa0, 0x3c,
  61294. 0x06, 0x4b, 0x5a, 0x7e, 0x3d, 0xb1, 0x81, 0xf8,
  61295. };
  61296. const byte key[] = {
  61297. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  61298. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  61299. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  61300. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  61301. };
  61302. byte eout[sizeof(msg)];
  61303. byte dout[sizeof(msg)];
  61304. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &enc), 0);
  61305. ExpectIntEQ(AES_set_decrypt_key(key, sizeof(key)*8, &dec), 0);
  61306. wolfSSL_AES_encrypt(NULL, NULL, NULL);
  61307. wolfSSL_AES_encrypt(msg, NULL, NULL);
  61308. wolfSSL_AES_encrypt(NULL, eout, NULL);
  61309. wolfSSL_AES_encrypt(NULL, NULL, &enc);
  61310. wolfSSL_AES_encrypt(msg, eout, NULL);
  61311. wolfSSL_AES_encrypt(msg, NULL, &enc);
  61312. wolfSSL_AES_encrypt(NULL, eout, &enc);
  61313. wolfSSL_AES_decrypt(NULL, NULL, NULL);
  61314. wolfSSL_AES_decrypt(eout, NULL, NULL);
  61315. wolfSSL_AES_decrypt(NULL, dout, NULL);
  61316. wolfSSL_AES_decrypt(NULL, NULL, &dec);
  61317. wolfSSL_AES_decrypt(eout, dout, NULL);
  61318. wolfSSL_AES_decrypt(eout, NULL, &dec);
  61319. wolfSSL_AES_decrypt(NULL, dout, &dec);
  61320. wolfSSL_AES_encrypt(msg, eout, &enc);
  61321. ExpectIntEQ(XMEMCMP(eout, exp, AES_BLOCK_SIZE), 0);
  61322. wolfSSL_AES_decrypt(eout, dout, &dec);
  61323. ExpectIntEQ(XMEMCMP(dout, msg, AES_BLOCK_SIZE), 0);
  61324. #endif
  61325. return EXPECT_RESULT();
  61326. }
  61327. static int test_wolfSSL_AES_ecb_encrypt(void)
  61328. {
  61329. EXPECT_DECLS;
  61330. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AES_ECB) \
  61331. && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  61332. AES_KEY aes;
  61333. const byte msg[] =
  61334. {
  61335. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  61336. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  61337. };
  61338. const byte verify[] =
  61339. {
  61340. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  61341. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  61342. };
  61343. const byte key[] =
  61344. {
  61345. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  61346. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  61347. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  61348. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  61349. };
  61350. byte out[AES_BLOCK_SIZE];
  61351. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aes), 0);
  61352. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61353. AES_ecb_encrypt(msg, out, &aes, AES_ENCRYPT);
  61354. ExpectIntEQ(XMEMCMP(out, verify, AES_BLOCK_SIZE), 0);
  61355. #ifdef HAVE_AES_DECRYPT
  61356. ExpectIntEQ(AES_set_decrypt_key(key, sizeof(key)*8, &aes), 0);
  61357. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61358. AES_ecb_encrypt(verify, out, &aes, AES_DECRYPT);
  61359. ExpectIntEQ(XMEMCMP(out, msg, AES_BLOCK_SIZE), 0);
  61360. #endif
  61361. /* test bad arguments */
  61362. AES_ecb_encrypt(NULL, out, &aes, AES_DECRYPT);
  61363. AES_ecb_encrypt(verify, NULL, &aes, AES_DECRYPT);
  61364. AES_ecb_encrypt(verify, out, NULL, AES_DECRYPT);
  61365. #endif
  61366. return EXPECT_RESULT();
  61367. }
  61368. static int test_wolfSSL_AES_cbc_encrypt(void)
  61369. {
  61370. EXPECT_DECLS;
  61371. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(OPENSSL_EXTRA) && \
  61372. !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  61373. AES_KEY aes;
  61374. AES_KEY* aesN = NULL;
  61375. size_t len = 0;
  61376. size_t lenB = 0;
  61377. int keySz0 = 0;
  61378. int keySzN = -1;
  61379. byte out[AES_BLOCK_SIZE] = {0};
  61380. byte* outN = NULL;
  61381. /* Test vectors retrieved from:
  61382. * <begin URL>
  61383. * https://csrc.nist.gov/
  61384. * CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/
  61385. * documents/aes/KAT_AES.zip
  61386. * </end URL>
  61387. */
  61388. const byte* pt128N = NULL;
  61389. byte* key128N = NULL;
  61390. byte* iv128N = NULL;
  61391. byte iv128tmp[AES_BLOCK_SIZE] = {0};
  61392. const byte pt128[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  61393. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
  61394. const byte ct128[] = { 0x87,0x85,0xb1,0xa7,0x5b,0x0f,0x3b,0xd9,
  61395. 0x58,0xdc,0xd0,0xe2,0x93,0x18,0xc5,0x21 };
  61396. const byte iv128[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  61397. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
  61398. byte key128[] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  61399. 0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x00 };
  61400. len = sizeof(pt128);
  61401. #define STRESS_T(a, b, c, d, e, f, g, h, i) \
  61402. wolfSSL_AES_cbc_encrypt(a, b, c, d, e, f); \
  61403. ExpectIntNE(XMEMCMP(b, g, h), i)
  61404. #define RESET_IV(x, y) XMEMCPY(x, y, AES_BLOCK_SIZE)
  61405. /* Stressing wolfSSL_AES_cbc_encrypt() */
  61406. STRESS_T(pt128N, out, len, &aes, iv128tmp, 1, ct128, AES_BLOCK_SIZE, 0);
  61407. STRESS_T(pt128, out, len, &aes, iv128N, 1, ct128, AES_BLOCK_SIZE, 0);
  61408. wolfSSL_AES_cbc_encrypt(pt128, outN, len, &aes, iv128tmp, AES_ENCRYPT);
  61409. ExpectIntNE(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  61410. wolfSSL_AES_cbc_encrypt(pt128, out, len, aesN, iv128tmp, AES_ENCRYPT);
  61411. ExpectIntNE(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  61412. STRESS_T(pt128, out, lenB, &aes, iv128tmp, 1, ct128, AES_BLOCK_SIZE, 0);
  61413. /* Stressing wolfSSL_AES_set_encrypt_key */
  61414. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128N, sizeof(key128)*8, &aes),0);
  61415. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, sizeof(key128)*8, aesN),0);
  61416. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, keySz0, &aes), 0);
  61417. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, keySzN, &aes), 0);
  61418. /* Stressing wolfSSL_AES_set_decrypt_key */
  61419. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128N, sizeof(key128)*8, &aes),0);
  61420. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128N, sizeof(key128)*8, aesN),0);
  61421. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128, keySz0, &aes), 0);
  61422. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128, keySzN, &aes), 0);
  61423. #ifdef WOLFSSL_AES_128
  61424. /* wolfSSL_AES_cbc_encrypt() 128-bit */
  61425. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61426. RESET_IV(iv128tmp, iv128);
  61427. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key128, sizeof(key128)*8, &aes), 0);
  61428. wolfSSL_AES_cbc_encrypt(pt128, out, len, &aes, iv128tmp, AES_ENCRYPT);
  61429. ExpectIntEQ(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  61430. wc_AesFree((Aes*)&aes);
  61431. #ifdef HAVE_AES_DECRYPT
  61432. /* wolfSSL_AES_cbc_encrypt() 128-bit in decrypt mode */
  61433. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61434. RESET_IV(iv128tmp, iv128);
  61435. len = sizeof(ct128);
  61436. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key128, sizeof(key128)*8, &aes), 0);
  61437. wolfSSL_AES_cbc_encrypt(ct128, out, len, &aes, iv128tmp, AES_DECRYPT);
  61438. ExpectIntEQ(XMEMCMP(out, pt128, AES_BLOCK_SIZE), 0);
  61439. wc_AesFree((Aes*)&aes);
  61440. #endif
  61441. #endif /* WOLFSSL_AES_128 */
  61442. #ifdef WOLFSSL_AES_192
  61443. {
  61444. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition
  61445. * Appendix F.2.3 */
  61446. byte iv192tmp[AES_BLOCK_SIZE] = {0};
  61447. const byte pt192[] = { 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  61448. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a };
  61449. const byte ct192[] = { 0x4f,0x02,0x1d,0xb2,0x43,0xbc,0x63,0x3d,
  61450. 0x71,0x78,0x18,0x3a,0x9f,0xa0,0x71,0xe8 };
  61451. const byte iv192[] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  61452. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F };
  61453. byte key192[] = { 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  61454. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  61455. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b };
  61456. len = sizeof(pt192);
  61457. /* wolfSSL_AES_cbc_encrypt() 192-bit */
  61458. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61459. RESET_IV(iv192tmp, iv192);
  61460. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key192, sizeof(key192)*8, &aes), 0);
  61461. wolfSSL_AES_cbc_encrypt(pt192, out, len, &aes, iv192tmp, AES_ENCRYPT);
  61462. ExpectIntEQ(XMEMCMP(out, ct192, AES_BLOCK_SIZE), 0);
  61463. wc_AesFree((Aes*)&aes);
  61464. #ifdef HAVE_AES_DECRYPT
  61465. /* wolfSSL_AES_cbc_encrypt() 192-bit in decrypt mode */
  61466. len = sizeof(ct192);
  61467. RESET_IV(iv192tmp, iv192);
  61468. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61469. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key192, sizeof(key192)*8, &aes), 0);
  61470. wolfSSL_AES_cbc_encrypt(ct192, out, len, &aes, iv192tmp, AES_DECRYPT);
  61471. ExpectIntEQ(XMEMCMP(out, pt192, AES_BLOCK_SIZE), 0);
  61472. wc_AesFree((Aes*)&aes);
  61473. #endif
  61474. }
  61475. #endif /* WOLFSSL_AES_192 */
  61476. #ifdef WOLFSSL_AES_256
  61477. {
  61478. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition,
  61479. * Appendix F.2.5 */
  61480. byte iv256tmp[AES_BLOCK_SIZE] = {0};
  61481. const byte pt256[] = { 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  61482. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a };
  61483. const byte ct256[] = { 0xf5,0x8c,0x4c,0x04,0xd6,0xe5,0xf1,0xba,
  61484. 0x77,0x9e,0xab,0xfb,0x5f,0x7b,0xfb,0xd6 };
  61485. const byte iv256[] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  61486. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F };
  61487. byte key256[] = { 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  61488. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  61489. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  61490. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4 };
  61491. len = sizeof(pt256);
  61492. /* wolfSSL_AES_cbc_encrypt() 256-bit */
  61493. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61494. RESET_IV(iv256tmp, iv256);
  61495. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  61496. wolfSSL_AES_cbc_encrypt(pt256, out, len, &aes, iv256tmp, AES_ENCRYPT);
  61497. ExpectIntEQ(XMEMCMP(out, ct256, AES_BLOCK_SIZE), 0);
  61498. wc_AesFree((Aes*)&aes);
  61499. #ifdef HAVE_AES_DECRYPT
  61500. /* wolfSSL_AES_cbc_encrypt() 256-bit in decrypt mode */
  61501. len = sizeof(ct256);
  61502. RESET_IV(iv256tmp, iv256);
  61503. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61504. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  61505. wolfSSL_AES_cbc_encrypt(ct256, out, len, &aes, iv256tmp, AES_DECRYPT);
  61506. ExpectIntEQ(XMEMCMP(out, pt256, AES_BLOCK_SIZE), 0);
  61507. wc_AesFree((Aes*)&aes);
  61508. #endif
  61509. #if defined(HAVE_AES_KEYWRAP) && !defined(HAVE_FIPS) && \
  61510. !defined(HAVE_SELFTEST)
  61511. {
  61512. byte wrapCipher[sizeof(key256) + KEYWRAP_BLOCK_SIZE] = { 0 };
  61513. byte wrapPlain[sizeof(key256)] = { 0 };
  61514. byte wrapIV[KEYWRAP_BLOCK_SIZE] = { 0 };
  61515. /* wolfSSL_AES_wrap_key() 256-bit NULL iv */
  61516. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  61517. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256,
  61518. 15), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61519. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256,
  61520. sizeof(key256)), sizeof(wrapCipher));
  61521. wc_AesFree((Aes*)&aes);
  61522. /* wolfSSL_AES_unwrap_key() 256-bit NULL iv */
  61523. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  61524. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher,
  61525. 23), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61526. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher,
  61527. sizeof(wrapCipher)), sizeof(wrapPlain));
  61528. ExpectIntEQ(XMEMCMP(wrapPlain, key256, sizeof(key256)), 0);
  61529. XMEMSET(wrapCipher, 0, sizeof(wrapCipher));
  61530. XMEMSET(wrapPlain, 0, sizeof(wrapPlain));
  61531. wc_AesFree((Aes*)&aes);
  61532. /* wolfSSL_AES_wrap_key() 256-bit custom iv */
  61533. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  61534. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapCipher, key256,
  61535. sizeof(key256)), sizeof(wrapCipher));
  61536. wc_AesFree((Aes*)&aes);
  61537. /* wolfSSL_AES_unwrap_key() 256-bit custom iv */
  61538. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  61539. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, wrapIV, wrapPlain, wrapCipher,
  61540. sizeof(wrapCipher)), sizeof(wrapPlain));
  61541. ExpectIntEQ(XMEMCMP(wrapPlain, key256, sizeof(key256)), 0);
  61542. wc_AesFree((Aes*)&aes);
  61543. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, NULL, NULL, 0), 0);
  61544. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, NULL, NULL, 0), 0);
  61545. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, wrapIV, NULL, NULL, 0), 0);
  61546. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, wrapCipher, NULL, 0), 0);
  61547. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, NULL, key256, 0), 0);
  61548. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, wrapIV, wrapCipher, key256, 0), 0);
  61549. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256, 0), 0);
  61550. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, NULL, key256, 0), 0);
  61551. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapCipher, NULL, 0), 0);
  61552. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, NULL, NULL, 0), 0);
  61553. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, NULL, NULL, 0), 0);
  61554. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, wrapIV, NULL, NULL, 0), 0);
  61555. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, wrapPlain, NULL, 0), 0);
  61556. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, NULL, wrapCipher, 0), 0);
  61557. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, wrapIV, wrapPlain, wrapCipher, 0),
  61558. 0);
  61559. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher, 0),
  61560. 0);
  61561. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, wrapIV, NULL, wrapCipher, 0), 0);
  61562. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapPlain, NULL, 0), 0);
  61563. }
  61564. #endif /* HAVE_AES_KEYWRAP */
  61565. }
  61566. #endif /* WOLFSSL_AES_256 */
  61567. #endif
  61568. return EXPECT_RESULT();
  61569. }
  61570. static int test_wolfSSL_AES_cfb128_encrypt(void)
  61571. {
  61572. EXPECT_DECLS;
  61573. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(WOLFSSL_AES_CFB) && \
  61574. !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  61575. AES_KEY aesEnc;
  61576. AES_KEY aesDec;
  61577. const byte msg[] = {
  61578. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  61579. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a
  61580. };
  61581. const byte exp[] = {
  61582. 0x16, 0xc9, 0x90, 0x6c, 0x04, 0x0c, 0xd1, 0x2f,
  61583. 0x84, 0x7b, 0x18, 0xed, 0xed, 0x6a, 0xb5, 0xfd
  61584. };
  61585. const byte key[] = {
  61586. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  61587. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  61588. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  61589. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  61590. };
  61591. const byte ivData[] = {
  61592. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  61593. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  61594. };
  61595. byte out[AES_BLOCK_SIZE];
  61596. byte iv[AES_BLOCK_SIZE];
  61597. word32 i;
  61598. int num;
  61599. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesEnc), 0);
  61600. XMEMCPY(iv, ivData, sizeof(iv));
  61601. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61602. AES_cfb128_encrypt(msg, out, sizeof(msg), &aesEnc, iv, NULL, AES_ENCRYPT);
  61603. ExpectIntEQ(XMEMCMP(out, exp, sizeof(msg)), 0);
  61604. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  61605. #ifdef HAVE_AES_DECRYPT
  61606. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesDec), 0);
  61607. XMEMCPY(iv, ivData, sizeof(iv));
  61608. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61609. AES_cfb128_encrypt(exp, out, sizeof(msg), &aesDec, iv, NULL, AES_DECRYPT);
  61610. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  61611. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  61612. #endif
  61613. for (i = 0; EXPECT_SUCCESS() && (i <= sizeof(msg)); i++) {
  61614. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesEnc), 0);
  61615. XMEMCPY(iv, ivData, sizeof(iv));
  61616. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61617. AES_cfb128_encrypt(msg, out, i, &aesEnc, iv, &num, AES_ENCRYPT);
  61618. ExpectIntEQ(num, i % AES_BLOCK_SIZE);
  61619. ExpectIntEQ(XMEMCMP(out, exp, i), 0);
  61620. if (i == 0) {
  61621. ExpectIntEQ(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  61622. }
  61623. else {
  61624. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  61625. }
  61626. #ifdef HAVE_AES_DECRYPT
  61627. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesDec), 0);
  61628. XMEMCPY(iv, ivData, sizeof(iv));
  61629. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61630. AES_cfb128_encrypt(exp, out, i, &aesDec, iv, &num, AES_DECRYPT);
  61631. ExpectIntEQ(num, i % AES_BLOCK_SIZE);
  61632. ExpectIntEQ(XMEMCMP(out, msg, i), 0);
  61633. if (i == 0) {
  61634. ExpectIntEQ(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  61635. }
  61636. else {
  61637. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  61638. }
  61639. #endif
  61640. }
  61641. if (EXPECT_SUCCESS()) {
  61642. /* test bad arguments */
  61643. AES_cfb128_encrypt(NULL, NULL, 0, NULL, NULL, NULL, AES_DECRYPT);
  61644. AES_cfb128_encrypt(msg, NULL, 0, NULL, NULL, NULL, AES_DECRYPT);
  61645. AES_cfb128_encrypt(NULL, out, 0, NULL, NULL, NULL, AES_DECRYPT);
  61646. AES_cfb128_encrypt(NULL, NULL, 0, &aesDec, NULL, NULL, AES_DECRYPT);
  61647. AES_cfb128_encrypt(NULL, NULL, 0, NULL, iv, NULL, AES_DECRYPT);
  61648. AES_cfb128_encrypt(NULL, out, 0, &aesDec, iv, NULL, AES_DECRYPT);
  61649. AES_cfb128_encrypt(msg, NULL, 0, &aesDec, iv, NULL, AES_DECRYPT);
  61650. AES_cfb128_encrypt(msg, out, 0, NULL, iv, NULL, AES_DECRYPT);
  61651. AES_cfb128_encrypt(msg, out, 0, &aesDec, NULL, NULL, AES_DECRYPT);
  61652. }
  61653. #endif
  61654. return EXPECT_RESULT();
  61655. }
  61656. static int test_wolfSSL_CRYPTO_cts128(void)
  61657. {
  61658. EXPECT_DECLS;
  61659. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(OPENSSL_EXTRA) && \
  61660. defined(HAVE_CTS) && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  61661. byte tmp[64]; /* Largest vector size */
  61662. /* Test vectors taken form RFC3962 Appendix B */
  61663. const testVector vects[] = {
  61664. {
  61665. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  61666. "\x20",
  61667. "\xc6\x35\x35\x68\xf2\xbf\x8c\xb4\xd8\xa5\x80\x36\x2d\xa7\xff\x7f"
  61668. "\x97",
  61669. 17, 17
  61670. },
  61671. {
  61672. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  61673. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20",
  61674. "\xfc\x00\x78\x3e\x0e\xfd\xb2\xc1\xd4\x45\xd4\xc8\xef\xf7\xed\x22"
  61675. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5",
  61676. 31, 31
  61677. },
  61678. {
  61679. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  61680. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43",
  61681. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
  61682. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84",
  61683. 32, 32
  61684. },
  61685. {
  61686. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  61687. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  61688. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c",
  61689. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  61690. "\xb3\xff\xfd\x94\x0c\x16\xa1\x8c\x1b\x55\x49\xd2\xf8\x38\x02\x9e"
  61691. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5",
  61692. 47, 47
  61693. },
  61694. {
  61695. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  61696. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  61697. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20",
  61698. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  61699. "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8"
  61700. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8",
  61701. 48, 48
  61702. },
  61703. {
  61704. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  61705. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  61706. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20"
  61707. "\x61\x6e\x64\x20\x77\x6f\x6e\x74\x6f\x6e\x20\x73\x6f\x75\x70\x2e",
  61708. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  61709. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
  61710. "\x48\x07\xef\xe8\x36\xee\x89\xa5\x26\x73\x0d\xbc\x2f\x7b\xc8\x40"
  61711. "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8",
  61712. 64, 64
  61713. }
  61714. };
  61715. byte keyBytes[AES_128_KEY_SIZE] = {
  61716. 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
  61717. 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69
  61718. };
  61719. size_t i;
  61720. AES_KEY encKey;
  61721. byte iv[AES_IV_SIZE]; /* All-zero IV for all cases */
  61722. XMEMSET(tmp, 0, sizeof(tmp));
  61723. for (i = 0; i < sizeof(vects)/sizeof(vects[0]); i++) {
  61724. AES_KEY decKey;
  61725. ExpectIntEQ(AES_set_encrypt_key(keyBytes, AES_128_KEY_SIZE * 8,
  61726. &encKey), 0);
  61727. ExpectIntEQ(AES_set_decrypt_key(keyBytes, AES_128_KEY_SIZE * 8,
  61728. &decKey), 0);
  61729. XMEMSET(iv, 0, sizeof(iv));
  61730. ExpectIntEQ(CRYPTO_cts128_encrypt((const unsigned char*)vects[i].input,
  61731. tmp, vects[i].inLen, &encKey, iv, (cbc128_f)AES_cbc_encrypt),
  61732. vects[i].outLen);
  61733. ExpectIntEQ(XMEMCMP(tmp, vects[i].output, vects[i].outLen), 0);
  61734. XMEMSET(iv, 0, sizeof(iv));
  61735. ExpectIntEQ(CRYPTO_cts128_decrypt((const unsigned char*)vects[i].output,
  61736. tmp, vects[i].outLen, &decKey, iv, (cbc128_f)AES_cbc_encrypt),
  61737. vects[i].inLen);
  61738. ExpectIntEQ(XMEMCMP(tmp, vects[i].input, vects[i].inLen), 0);
  61739. }
  61740. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, NULL, NULL), 0);
  61741. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, NULL, 17, NULL, NULL, NULL), 0);
  61742. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, tmp, 17, NULL, NULL, NULL), 0);
  61743. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, &encKey, NULL, NULL), 0);
  61744. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, iv, NULL), 0);
  61745. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, NULL,
  61746. (cbc128_f)AES_cbc_encrypt), 0);
  61747. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, tmp, 17, &encKey, iv,
  61748. (cbc128_f)AES_cbc_encrypt), 0);
  61749. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, NULL, 17, &encKey, iv,
  61750. (cbc128_f)AES_cbc_encrypt), 0);
  61751. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, NULL, iv,
  61752. (cbc128_f)AES_cbc_encrypt), 0);
  61753. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, &encKey, NULL,
  61754. (cbc128_f)AES_cbc_encrypt), 0);
  61755. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, &encKey, iv, NULL), 0);
  61756. /* Length too small. */
  61757. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 0, &encKey, iv,
  61758. (cbc128_f)AES_cbc_encrypt), 0);
  61759. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, NULL, NULL), 0);
  61760. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, NULL, 17, NULL, NULL, NULL), 0);
  61761. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, tmp, 17, NULL, NULL, NULL), 0);
  61762. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, &encKey, NULL, NULL), 0);
  61763. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, iv, NULL), 0);
  61764. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, NULL,
  61765. (cbc128_f)AES_cbc_encrypt), 0);
  61766. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, tmp, 17, &encKey, iv,
  61767. (cbc128_f)AES_cbc_encrypt), 0);
  61768. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, NULL, 17, &encKey, iv,
  61769. (cbc128_f)AES_cbc_encrypt), 0);
  61770. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, NULL, iv,
  61771. (cbc128_f)AES_cbc_encrypt), 0);
  61772. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, &encKey, NULL,
  61773. (cbc128_f)AES_cbc_encrypt), 0);
  61774. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, &encKey, iv, NULL), 0);
  61775. /* Length too small. */
  61776. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 0, &encKey, iv,
  61777. (cbc128_f)AES_cbc_encrypt), 0);
  61778. #endif /* !NO_AES && HAVE_AES_CBC && OPENSSL_EXTRA && HAVE_CTS */
  61779. return EXPECT_RESULT();
  61780. }
  61781. static int test_wolfSSL_RC4(void)
  61782. {
  61783. EXPECT_DECLS;
  61784. #if !defined(NO_RC4) && defined(OPENSSL_EXTRA)
  61785. WOLFSSL_RC4_KEY rc4Key;
  61786. unsigned char key[] = {
  61787. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  61788. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  61789. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  61790. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  61791. };
  61792. unsigned char data[] = {
  61793. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  61794. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  61795. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  61796. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  61797. };
  61798. unsigned char enc[sizeof(data)];
  61799. unsigned char dec[sizeof(data)];
  61800. word32 i;
  61801. word32 j;
  61802. wolfSSL_RC4_set_key(NULL, -1, NULL);
  61803. wolfSSL_RC4_set_key(&rc4Key, -1, NULL);
  61804. wolfSSL_RC4_set_key(NULL, 0, NULL);
  61805. wolfSSL_RC4_set_key(NULL, -1, key);
  61806. wolfSSL_RC4_set_key(&rc4Key, 0, NULL);
  61807. wolfSSL_RC4_set_key(&rc4Key, -1, key);
  61808. wolfSSL_RC4_set_key(NULL, 0, key);
  61809. wolfSSL_RC4(NULL, 0, NULL, NULL);
  61810. wolfSSL_RC4(&rc4Key, 0, NULL, NULL);
  61811. wolfSSL_RC4(NULL, 0, data, NULL);
  61812. wolfSSL_RC4(NULL, 0, NULL, enc);
  61813. wolfSSL_RC4(&rc4Key, 0, data, NULL);
  61814. wolfSSL_RC4(&rc4Key, 0, NULL, enc);
  61815. wolfSSL_RC4(NULL, 0, data, enc);
  61816. ExpectIntEQ(1, 1);
  61817. for (i = 0; EXPECT_SUCCESS() && (i <= sizeof(key)); i++) {
  61818. for (j = 0; EXPECT_SUCCESS() && (j <= sizeof(data)); j++) {
  61819. XMEMSET(enc, 0, sizeof(enc));
  61820. XMEMSET(dec, 0, sizeof(dec));
  61821. /* Encrypt */
  61822. wolfSSL_RC4_set_key(&rc4Key, (int)i, key);
  61823. wolfSSL_RC4(&rc4Key, j, data, enc);
  61824. /* Decrypt */
  61825. wolfSSL_RC4_set_key(&rc4Key, (int)i, key);
  61826. wolfSSL_RC4(&rc4Key, j, enc, dec);
  61827. ExpectIntEQ(XMEMCMP(dec, data, j), 0);
  61828. }
  61829. }
  61830. #endif
  61831. return EXPECT_RESULT();
  61832. }
  61833. static int test_wolfSSL_OBJ(void)
  61834. {
  61835. /* Password "wolfSSL test" is only 12 (96-bit) too short for testing in FIPS
  61836. * mode
  61837. */
  61838. EXPECT_DECLS;
  61839. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && !defined(NO_ASN) && \
  61840. !defined(HAVE_FIPS) && !defined(NO_SHA) && defined(WOLFSSL_CERT_EXT) && \
  61841. defined(WOLFSSL_CERT_GEN) && !defined(NO_BIO) && \
  61842. !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
  61843. ASN1_OBJECT *obj = NULL;
  61844. ASN1_OBJECT *obj2 = NULL;
  61845. char buf[50];
  61846. XFILE fp = XBADFILE;
  61847. X509 *x509 = NULL;
  61848. X509_NAME *x509Name = NULL;
  61849. X509_NAME_ENTRY *x509NameEntry = NULL;
  61850. ASN1_OBJECT *asn1Name = NULL;
  61851. int numNames = 0;
  61852. BIO *bio = NULL;
  61853. int nid;
  61854. int i, j;
  61855. const char *f[] = {
  61856. #ifndef NO_RSA
  61857. "./certs/ca-cert.der",
  61858. #endif
  61859. #ifdef HAVE_ECC
  61860. "./certs/ca-ecc-cert.der",
  61861. "./certs/ca-ecc384-cert.der",
  61862. #endif
  61863. NULL};
  61864. ASN1_OBJECT *field_name_obj = NULL;
  61865. int lastpos = -1;
  61866. int tmp = -1;
  61867. ASN1_STRING *asn1 = NULL;
  61868. unsigned char *buf_dyn = NULL;
  61869. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61870. ExpectNotNull(obj = OBJ_nid2obj(NID_any_policy));
  61871. ExpectIntEQ(OBJ_obj2nid(obj), NID_any_policy);
  61872. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), 11);
  61873. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0), 0);
  61874. ASN1_OBJECT_free(obj);
  61875. obj = NULL;
  61876. ExpectNotNull(obj = OBJ_nid2obj(NID_sha256));
  61877. ExpectIntEQ(OBJ_obj2nid(obj), NID_sha256);
  61878. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), 22);
  61879. #ifdef WOLFSSL_CERT_EXT
  61880. ExpectIntEQ(OBJ_txt2nid(buf), NID_sha256);
  61881. #endif
  61882. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0), 0);
  61883. ExpectNotNull(obj2 = OBJ_dup(obj));
  61884. ExpectIntEQ(OBJ_cmp(obj, obj2), 0);
  61885. ASN1_OBJECT_free(obj);
  61886. obj = NULL;
  61887. ASN1_OBJECT_free(obj2);
  61888. obj2 = NULL;
  61889. for (i = 0; f[i] != NULL; i++)
  61890. {
  61891. ExpectTrue((fp = XFOPEN(f[i], "rb")) != XBADFILE);
  61892. ExpectNotNull(x509 = d2i_X509_fp(fp, NULL));
  61893. if (fp != XBADFILE) {
  61894. XFCLOSE(fp);
  61895. fp = XBADFILE;
  61896. }
  61897. ExpectNotNull(x509Name = X509_get_issuer_name(x509));
  61898. ExpectIntNE((numNames = X509_NAME_entry_count(x509Name)), 0);
  61899. /* Get the Common Name by using OBJ_txt2obj */
  61900. ExpectNotNull(field_name_obj = OBJ_txt2obj("CN", 0));
  61901. do
  61902. {
  61903. lastpos = tmp;
  61904. tmp = X509_NAME_get_index_by_OBJ(x509Name, field_name_obj, lastpos);
  61905. } while (tmp > -1);
  61906. ExpectIntNE(lastpos, -1);
  61907. ASN1_OBJECT_free(field_name_obj);
  61908. field_name_obj = NULL;
  61909. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, lastpos));
  61910. ExpectNotNull(asn1 = X509_NAME_ENTRY_get_data(x509NameEntry));
  61911. ExpectIntGE(ASN1_STRING_to_UTF8(&buf_dyn, asn1), 0);
  61912. /*
  61913. * All Common Names should be www.wolfssl.com
  61914. * This makes testing easier as we can test for the expected value.
  61915. */
  61916. ExpectStrEQ((char*)buf_dyn, "www.wolfssl.com");
  61917. OPENSSL_free(buf_dyn);
  61918. buf_dyn = NULL;
  61919. bio = BIO_new(BIO_s_mem());
  61920. ExpectTrue(bio != NULL);
  61921. for (j = 0; j < numNames; j++)
  61922. {
  61923. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, j));
  61924. ExpectNotNull(asn1Name = X509_NAME_ENTRY_get_object(x509NameEntry));
  61925. ExpectTrue((nid = OBJ_obj2nid(asn1Name)) > 0);
  61926. }
  61927. BIO_free(bio);
  61928. bio = NULL;
  61929. X509_free(x509);
  61930. x509 = NULL;
  61931. }
  61932. #ifdef HAVE_PKCS12
  61933. {
  61934. PKCS12 *p12 = NULL;
  61935. int boolRet;
  61936. EVP_PKEY *pkey = NULL;
  61937. const char *p12_f[] = {
  61938. #if !defined(NO_DES3) && !defined(NO_RSA)
  61939. "./certs/test-servercert.p12",
  61940. #endif
  61941. NULL};
  61942. for (i = 0; p12_f[i] != NULL; i++)
  61943. {
  61944. ExpectTrue((fp = XFOPEN(p12_f[i], "rb")) != XBADFILE);
  61945. ExpectNotNull(p12 = d2i_PKCS12_fp(fp, NULL));
  61946. if (fp != XBADFILE) {
  61947. XFCLOSE(fp);
  61948. fp = XBADFILE;
  61949. }
  61950. ExpectTrue((boolRet = PKCS12_parse(p12, "wolfSSL test",
  61951. &pkey, &x509, NULL)) > 0);
  61952. wc_PKCS12_free(p12);
  61953. p12 = NULL;
  61954. EVP_PKEY_free(pkey);
  61955. x509Name = X509_get_issuer_name(x509);
  61956. ExpectNotNull(x509Name);
  61957. ExpectIntNE((numNames = X509_NAME_entry_count(x509Name)), 0);
  61958. ExpectTrue((bio = BIO_new(BIO_s_mem())) != NULL);
  61959. for (j = 0; j < numNames; j++)
  61960. {
  61961. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, j));
  61962. ExpectNotNull(asn1Name =
  61963. X509_NAME_ENTRY_get_object(x509NameEntry));
  61964. ExpectTrue((nid = OBJ_obj2nid(asn1Name)) > 0);
  61965. }
  61966. BIO_free(bio);
  61967. bio = NULL;
  61968. X509_free(x509);
  61969. x509 = NULL;
  61970. }
  61971. }
  61972. #endif /* HAVE_PKCS12 */
  61973. #endif
  61974. return EXPECT_RESULT();
  61975. }
  61976. static int test_wolfSSL_OBJ_cmp(void)
  61977. {
  61978. EXPECT_DECLS;
  61979. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256)
  61980. ASN1_OBJECT *obj = NULL;
  61981. ASN1_OBJECT *obj2 = NULL;
  61982. ExpectNotNull(obj = OBJ_nid2obj(NID_any_policy));
  61983. ExpectNotNull(obj2 = OBJ_nid2obj(NID_sha256));
  61984. ExpectIntEQ(OBJ_cmp(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  61985. ExpectIntEQ(OBJ_cmp(obj, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  61986. ExpectIntEQ(OBJ_cmp(NULL, obj2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  61987. ExpectIntEQ(OBJ_cmp(obj, obj2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  61988. ExpectIntEQ(OBJ_cmp(obj, obj), 0);
  61989. ExpectIntEQ(OBJ_cmp(obj2, obj2), 0);
  61990. ASN1_OBJECT_free(obj);
  61991. ASN1_OBJECT_free(obj2);
  61992. #endif
  61993. return EXPECT_RESULT();
  61994. }
  61995. static int test_wolfSSL_OBJ_txt2nid(void)
  61996. {
  61997. EXPECT_DECLS;
  61998. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  61999. defined(WOLFSSL_APACHE_HTTPD)
  62000. int i;
  62001. static const struct {
  62002. const char* sn;
  62003. const char* ln;
  62004. const char* oid;
  62005. int nid;
  62006. } testVals[] = {
  62007. #ifdef WOLFSSL_APACHE_HTTPD
  62008. { "tlsfeature", "TLS Feature", "1.3.6.1.5.5.7.1.24", NID_tlsfeature },
  62009. { "id-on-dnsSRV", "SRVName", "1.3.6.1.5.5.7.8.7",
  62010. NID_id_on_dnsSRV },
  62011. { "msUPN", "Microsoft User Principal Name",
  62012. "1.3.6.1.4.1.311.20.2.3", NID_ms_upn },
  62013. #endif
  62014. { NULL, NULL, NULL, NID_undef }
  62015. };
  62016. /* Invalid cases */
  62017. ExpectIntEQ(OBJ_txt2nid(NULL), NID_undef);
  62018. ExpectIntEQ(OBJ_txt2nid("Bad name"), NID_undef);
  62019. /* Valid cases */
  62020. for (i = 0; testVals[i].sn != NULL; i++) {
  62021. ExpectIntEQ(OBJ_txt2nid(testVals[i].sn), testVals[i].nid);
  62022. ExpectIntEQ(OBJ_txt2nid(testVals[i].ln), testVals[i].nid);
  62023. ExpectIntEQ(OBJ_txt2nid(testVals[i].oid), testVals[i].nid);
  62024. }
  62025. #endif
  62026. return EXPECT_RESULT();
  62027. }
  62028. static int test_wolfSSL_OBJ_txt2obj(void)
  62029. {
  62030. EXPECT_DECLS;
  62031. #if defined(WOLFSSL_APACHE_HTTPD) || (defined(OPENSSL_EXTRA) && \
  62032. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN))
  62033. int i;
  62034. char buf[50];
  62035. ASN1_OBJECT* obj = NULL;
  62036. static const struct {
  62037. const char* oidStr;
  62038. const char* sn;
  62039. const char* ln;
  62040. } objs_list[] = {
  62041. #if defined(WOLFSSL_APACHE_HTTPD)
  62042. { "1.3.6.1.5.5.7.1.24", "tlsfeature", "TLS Feature" },
  62043. { "1.3.6.1.5.5.7.8.7", "id-on-dnsSRV", "SRVName" },
  62044. #endif
  62045. { "2.5.29.19", "basicConstraints", "X509v3 Basic Constraints"},
  62046. { NULL, NULL, NULL }
  62047. };
  62048. static const struct {
  62049. const char* numeric;
  62050. const char* name;
  62051. } objs_named[] = {
  62052. /* In dictionary but not in normal list. */
  62053. { "1.3.6.1.5.5.7.3.8", "Time Stamping" },
  62054. /* Made up OID. */
  62055. { "1.3.5.7", "1.3.5.7" },
  62056. { NULL, NULL }
  62057. };
  62058. ExpectNull(obj = OBJ_txt2obj("Bad name", 0));
  62059. ASN1_OBJECT_free(obj);
  62060. obj = NULL;
  62061. ExpectNull(obj = OBJ_txt2obj(NULL, 0));
  62062. ASN1_OBJECT_free(obj);
  62063. obj = NULL;
  62064. for (i = 0; objs_list[i].oidStr != NULL; i++) {
  62065. /* Test numerical value of oid (oidStr) */
  62066. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].oidStr, 1));
  62067. /* Convert object back to text to confirm oid is correct */
  62068. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  62069. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  62070. ASN1_OBJECT_free(obj);
  62071. obj = NULL;
  62072. XMEMSET(buf, 0, sizeof(buf));
  62073. /* Test short name (sn) */
  62074. ExpectNull(obj = OBJ_txt2obj(objs_list[i].sn, 1));
  62075. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].sn, 0));
  62076. /* Convert object back to text to confirm oid is correct */
  62077. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  62078. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  62079. ASN1_OBJECT_free(obj);
  62080. obj = NULL;
  62081. XMEMSET(buf, 0, sizeof(buf));
  62082. /* Test long name (ln) - should fail when no_name = 1 */
  62083. ExpectNull(obj = OBJ_txt2obj(objs_list[i].ln, 1));
  62084. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].ln, 0));
  62085. /* Convert object back to text to confirm oid is correct */
  62086. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  62087. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  62088. ASN1_OBJECT_free(obj);
  62089. obj = NULL;
  62090. XMEMSET(buf, 0, sizeof(buf));
  62091. }
  62092. for (i = 0; objs_named[i].numeric != NULL; i++) {
  62093. ExpectNotNull(obj = OBJ_txt2obj(objs_named[i].numeric, 1));
  62094. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0);
  62095. ExpectIntEQ(XSTRNCMP(buf, objs_named[i].name, (int)XSTRLEN(buf)), 0);
  62096. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  62097. ExpectIntEQ(XSTRNCMP(buf, objs_named[i].numeric, (int)XSTRLEN(buf)), 0);
  62098. ASN1_OBJECT_free(obj);
  62099. obj = NULL;
  62100. }
  62101. #endif
  62102. return EXPECT_RESULT();
  62103. }
  62104. static int test_wolfSSL_PEM_write_bio_X509(void)
  62105. {
  62106. EXPECT_DECLS;
  62107. #if defined(OPENSSL_EXTRA) && defined(OPENSSL_ALL) && \
  62108. defined(WOLFSSL_AKID_NAME) && defined(WOLFSSL_CERT_EXT) && \
  62109. defined(WOLFSSL_CERT_GEN) && !defined(NO_BIO) && !defined(NO_RSA) && \
  62110. !defined(NO_FILESYSTEM)
  62111. /* This test contains the hard coded expected
  62112. * lengths. Update if necessary */
  62113. XFILE fp = XBADFILE;
  62114. WOLFSSL_EVP_PKEY *priv = NULL;
  62115. BIO* input = NULL;
  62116. BIO* output = NULL;
  62117. X509* x509a = NULL;
  62118. X509* x509b = NULL;
  62119. ASN1_TIME* notBeforeA = NULL;
  62120. ASN1_TIME* notAfterA = NULL;
  62121. #ifndef NO_ASN_TIME
  62122. ASN1_TIME* notBeforeB = NULL;
  62123. ASN1_TIME* notAfterB = NULL;
  62124. #endif
  62125. int expectedLen;
  62126. ExpectTrue((fp = XFOPEN("certs/server-key.pem", "rb")) != XBADFILE);
  62127. ExpectNotNull(priv = wolfSSL_PEM_read_PrivateKey(fp, NULL, NULL, NULL));
  62128. if (fp != XBADFILE) {
  62129. XFCLOSE(fp);
  62130. fp = XBADFILE;
  62131. }
  62132. ExpectNotNull(input = BIO_new_file("certs/test/cert-ext-multiple.pem",
  62133. "rb"));
  62134. ExpectIntEQ(wolfSSL_BIO_get_len(input), 2000);
  62135. /* read PEM into X509 struct, get notBefore / notAfter to verify against */
  62136. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  62137. ExpectNotNull(notBeforeA = X509_get_notBefore(x509a));
  62138. ExpectNotNull(notAfterA = X509_get_notAfter(x509a));
  62139. /* write X509 back to PEM BIO; no need to sign as nothing changed. */
  62140. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  62141. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  62142. /* compare length against expected */
  62143. expectedLen = 2000;
  62144. ExpectIntEQ(wolfSSL_BIO_get_len(output), expectedLen);
  62145. #ifndef NO_ASN_TIME
  62146. /* read exported X509 PEM back into struct, sanity check on export,
  62147. * make sure notBefore/notAfter are the same and certs are identical. */
  62148. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  62149. ExpectNotNull(notBeforeB = X509_get_notBefore(x509b));
  62150. ExpectNotNull(notAfterB = X509_get_notAfter(x509b));
  62151. ExpectIntEQ(ASN1_TIME_compare(notBeforeA, notBeforeB), 0);
  62152. ExpectIntEQ(ASN1_TIME_compare(notAfterA, notAfterB), 0);
  62153. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  62154. X509_free(x509b);
  62155. x509b = NULL;
  62156. #endif
  62157. /* Reset output buffer */
  62158. BIO_free(output);
  62159. output = NULL;
  62160. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  62161. /* Test forcing the AKID to be generated just from KeyIdentifier */
  62162. if (EXPECT_SUCCESS() && x509a->authKeyIdSrc != NULL) {
  62163. XMEMMOVE(x509a->authKeyIdSrc, x509a->authKeyId, x509a->authKeyIdSz);
  62164. x509a->authKeyId = x509a->authKeyIdSrc;
  62165. x509a->authKeyIdSrc = NULL;
  62166. x509a->authKeyIdSrcSz = 0;
  62167. }
  62168. /* Resign to re-generate the der */
  62169. ExpectIntGT(wolfSSL_X509_sign(x509a, priv, EVP_sha256()), 0);
  62170. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  62171. /* Check that we generate a smaller output since the AKID will
  62172. * only contain the KeyIdentifier without any additional
  62173. * information */
  62174. /* Here we copy the validity struct from the original */
  62175. expectedLen = 1688;
  62176. ExpectIntEQ(wolfSSL_BIO_get_len(output), expectedLen);
  62177. /* Reset buffers and x509 */
  62178. BIO_free(input);
  62179. input = NULL;
  62180. BIO_free(output);
  62181. output = NULL;
  62182. X509_free(x509a);
  62183. x509a = NULL;
  62184. /* test CA and basicConstSet values are encoded when
  62185. * the cert is a CA */
  62186. ExpectNotNull(input = BIO_new_file("certs/server-cert.pem", "rb"));
  62187. /* read PEM into X509 struct */
  62188. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  62189. /* write X509 back to PEM BIO; no need to sign as nothing changed */
  62190. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  62191. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  62192. /* read exported X509 PEM back into struct, ensure isCa and basicConstSet
  62193. * values are maintained and certs are identical.*/
  62194. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  62195. ExpectIntEQ(x509b->isCa, 1);
  62196. ExpectIntEQ(x509b->basicConstSet, 1);
  62197. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  62198. X509_free(x509a);
  62199. x509a = NULL;
  62200. X509_free(x509b);
  62201. x509b = NULL;
  62202. BIO_free(input);
  62203. input = NULL;
  62204. BIO_free(output);
  62205. output = NULL;
  62206. /* test CA and basicConstSet values are encoded when
  62207. * the cert is not CA */
  62208. ExpectNotNull(input = BIO_new_file("certs/client-uri-cert.pem", "rb"));
  62209. /* read PEM into X509 struct */
  62210. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  62211. /* write X509 back to PEM BIO; no need to sign as nothing changed */
  62212. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  62213. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  62214. /* read exported X509 PEM back into struct, ensure isCa and
  62215. * basicConstSet values are maintained and certs are identical */
  62216. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  62217. ExpectIntEQ(x509b->isCa, 0);
  62218. ExpectIntEQ(x509b->basicConstSet, 1);
  62219. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  62220. wolfSSL_EVP_PKEY_free(priv);
  62221. X509_free(x509a);
  62222. X509_free(x509b);
  62223. BIO_free(input);
  62224. BIO_free(output);
  62225. #endif
  62226. return EXPECT_RESULT();
  62227. }
  62228. static int test_wolfSSL_X509_NAME_ENTRY(void)
  62229. {
  62230. EXPECT_DECLS;
  62231. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  62232. !defined(NO_RSA) && defined(WOLFSSL_CERT_GEN)
  62233. X509* x509 = NULL;
  62234. #ifndef NO_BIO
  62235. BIO* bio = NULL;
  62236. #endif
  62237. X509_NAME* nm = NULL;
  62238. X509_NAME_ENTRY* entry = NULL;
  62239. unsigned char cn[] = "another name to add";
  62240. #ifdef OPENSSL_ALL
  62241. int i;
  62242. int names_len = 0;
  62243. #endif
  62244. ExpectNotNull(x509 =
  62245. wolfSSL_X509_load_certificate_file(cliCertFile, SSL_FILETYPE_PEM));
  62246. #ifndef NO_BIO
  62247. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62248. ExpectIntEQ(PEM_write_bio_X509_AUX(bio, x509), SSL_SUCCESS);
  62249. #endif
  62250. #ifdef WOLFSSL_CERT_REQ
  62251. {
  62252. X509_REQ* req = NULL;
  62253. #ifndef NO_BIO
  62254. BIO* bReq = NULL;
  62255. #endif
  62256. ExpectNotNull(req =
  62257. wolfSSL_X509_load_certificate_file(cliCertFile, SSL_FILETYPE_PEM));
  62258. #ifndef NO_BIO
  62259. ExpectNotNull(bReq = BIO_new(BIO_s_mem()));
  62260. ExpectIntEQ(PEM_write_bio_X509_REQ(bReq, req), SSL_SUCCESS);
  62261. BIO_free(bReq);
  62262. #endif
  62263. X509_free(req);
  62264. }
  62265. #endif
  62266. ExpectNotNull(nm = X509_get_subject_name(x509));
  62267. /* Test add entry */
  62268. ExpectNotNull(entry = X509_NAME_ENTRY_create_by_NID(NULL, NID_commonName,
  62269. 0x0c, cn, (int)sizeof(cn)));
  62270. ExpectIntEQ(X509_NAME_add_entry(nm, entry, -1, 0), SSL_SUCCESS);
  62271. #ifdef WOLFSSL_CERT_EXT
  62272. ExpectIntEQ(X509_NAME_add_entry_by_txt(nm, "emailAddress", MBSTRING_UTF8,
  62273. (byte*)"support@wolfssl.com", 19, -1,
  62274. 1), WOLFSSL_SUCCESS);
  62275. #endif
  62276. X509_NAME_ENTRY_free(entry);
  62277. entry = NULL;
  62278. #ifdef WOLFSSL_CERT_REQ
  62279. {
  62280. unsigned char srv_pkcs9p[] = "Server";
  62281. unsigned char fvrtDrnk[] = "tequila";
  62282. unsigned char* der = NULL;
  62283. char* subject = NULL;
  62284. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_pkcs9_contentType,
  62285. MBSTRING_ASC, srv_pkcs9p, -1, -1, 0), SSL_SUCCESS);
  62286. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_favouriteDrink,
  62287. MBSTRING_ASC, fvrtDrnk, -1, -1, 0), SSL_SUCCESS);
  62288. ExpectIntGT(wolfSSL_i2d_X509_NAME(nm, &der), 0);
  62289. ExpectNotNull(der);
  62290. ExpectNotNull(subject = X509_NAME_oneline(nm, 0, 0));
  62291. ExpectNotNull(XSTRSTR(subject, "favouriteDrink=tequila"));
  62292. ExpectNotNull(XSTRSTR(subject, "contentType=Server"));
  62293. #ifdef DEBUG_WOLFSSL
  62294. if (subject != NULL) {
  62295. fprintf(stderr, "\n\t%s\n", subject);
  62296. }
  62297. #endif
  62298. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  62299. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  62300. }
  62301. #endif
  62302. /* Test add entry by text */
  62303. ExpectNotNull(entry = X509_NAME_ENTRY_create_by_txt(NULL, "commonName",
  62304. 0x0c, cn, (int)sizeof(cn)));
  62305. #if defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) \
  62306. || defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_NGINX)
  62307. ExpectNull(X509_NAME_ENTRY_create_by_txt(&entry, "unknown",
  62308. V_ASN1_UTF8STRING, cn, (int)sizeof(cn)));
  62309. #endif
  62310. ExpectIntEQ(X509_NAME_add_entry(nm, entry, -1, 0), SSL_SUCCESS);
  62311. X509_NAME_ENTRY_free(entry);
  62312. entry = NULL;
  62313. /* Test add entry by NID */
  62314. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_commonName, MBSTRING_UTF8,
  62315. cn, -1, -1, 0), SSL_SUCCESS);
  62316. #ifdef OPENSSL_ALL
  62317. /* stack of name entry */
  62318. ExpectIntGT((names_len = sk_X509_NAME_ENTRY_num(nm->entries)), 0);
  62319. for (i = 0; i < names_len; i++) {
  62320. ExpectNotNull(entry = sk_X509_NAME_ENTRY_value(nm->entries, i));
  62321. }
  62322. #endif
  62323. #ifndef NO_BIO
  62324. BIO_free(bio);
  62325. #endif
  62326. X509_free(x509); /* free's nm */
  62327. #endif
  62328. return EXPECT_RESULT();
  62329. }
  62330. /* Note the lack of wolfSSL_ prefix...this is a compatibility layer test. */
  62331. static int test_GENERAL_NAME_set0_othername(void) {
  62332. EXPECT_DECLS;
  62333. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  62334. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  62335. defined(WOLFSSL_CUSTOM_OID) && defined(WOLFSSL_ALT_NAMES) && \
  62336. defined(WOLFSSL_CERT_EXT) && !defined(NO_FILESYSTEM) && \
  62337. defined(WOLFSSL_FPKI)
  62338. /* ./configure --enable-opensslall --enable-certgen --enable-certreq
  62339. * --enable-certext --enable-debug 'CPPFLAGS=-DWOLFSSL_CUSTOM_OID
  62340. * -DWOLFSSL_ALT_NAMES -DWOLFSSL_FPKI' */
  62341. const char * cert_fname = "./certs/server-cert.der";
  62342. const char * key_fname = "./certs/server-key.der";
  62343. X509* x509 = NULL;
  62344. GENERAL_NAME* gn = NULL;
  62345. GENERAL_NAMES* gns = NULL;
  62346. ASN1_OBJECT* upn_oid = NULL;
  62347. ASN1_UTF8STRING *utf8str = NULL;
  62348. ASN1_TYPE *value = NULL;
  62349. X509_EXTENSION * ext = NULL;
  62350. byte* pt = NULL;
  62351. byte der[4096];
  62352. int derSz = 0;
  62353. EVP_PKEY* priv = NULL;
  62354. XFILE f = XBADFILE;
  62355. ExpectTrue((f = XFOPEN(cert_fname, "rb")) != XBADFILE);
  62356. ExpectNotNull(x509 = d2i_X509_fp(f, NULL));
  62357. if (f != XBADFILE) {
  62358. XFCLOSE(f);
  62359. f = XBADFILE;
  62360. }
  62361. ExpectNotNull(gn = GENERAL_NAME_new());
  62362. ExpectNotNull(upn_oid = OBJ_txt2obj("1.3.6.1.4.1.311.20.2.3", 1));
  62363. ExpectNotNull(utf8str = ASN1_UTF8STRING_new());
  62364. ExpectIntEQ(ASN1_STRING_set(utf8str, "othername@wolfssl.com", -1), 1);
  62365. ExpectNotNull(value = ASN1_TYPE_new());
  62366. ASN1_TYPE_set(value, V_ASN1_UTF8STRING, utf8str);
  62367. if ((value == NULL) || (value->value.ptr != (char*)utf8str)) {
  62368. wolfSSL_ASN1_STRING_free(utf8str);
  62369. }
  62370. ExpectIntEQ(GENERAL_NAME_set0_othername(gn, upn_oid, value), 1);
  62371. if (EXPECT_FAIL()) {
  62372. ASN1_TYPE_free(value);
  62373. }
  62374. ExpectNotNull(gns = sk_GENERAL_NAME_new(NULL));
  62375. ExpectIntEQ(sk_GENERAL_NAME_push(gns, gn), 1);
  62376. if (EXPECT_FAIL()) {
  62377. GENERAL_NAME_free(gn);
  62378. gn = NULL;
  62379. }
  62380. ExpectNotNull(ext = X509V3_EXT_i2d(NID_subject_alt_name, 0, gns));
  62381. ExpectIntEQ(X509_add_ext(x509, ext, -1), 1);
  62382. ExpectTrue((f = XFOPEN(key_fname, "rb")) != XBADFILE);
  62383. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  62384. if (f != XBADFILE) {
  62385. XFCLOSE(f);
  62386. f = XBADFILE;
  62387. }
  62388. pt = der;
  62389. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  62390. (const unsigned char**)&pt, derSz));
  62391. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  62392. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  62393. gns = NULL;
  62394. ExpectNotNull(gns = (GENERAL_NAMES*)X509_get_ext_d2i(x509,
  62395. NID_subject_alt_name, NULL, NULL));
  62396. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 3);
  62397. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, 2));
  62398. ExpectIntEQ(gn->type, 0);
  62399. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  62400. ASN1_OBJECT_free(upn_oid);
  62401. X509_EXTENSION_free(ext);
  62402. X509_free(x509);
  62403. EVP_PKEY_free(priv);
  62404. #endif
  62405. return EXPECT_RESULT();
  62406. }
  62407. /* Note the lack of wolfSSL_ prefix...this is a compatibility layer test. */
  62408. static int test_othername_and_SID_ext(void) {
  62409. EXPECT_DECLS;
  62410. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  62411. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  62412. defined(WOLFSSL_CUSTOM_OID) && defined(WOLFSSL_ALT_NAMES) && \
  62413. defined(WOLFSSL_CERT_EXT) && !defined(NO_FILESYSTEM) && \
  62414. defined(WOLFSSL_FPKI) && defined(WOLFSSL_ASN_TEMPLATE)
  62415. /* ./configure --enable-opensslall --enable-certgen --enable-certreq
  62416. * --enable-certext --enable-debug 'CPPFLAGS=-DWOLFSSL_CUSTOM_OID
  62417. * -DWOLFSSL_ALT_NAMES -DWOLFSSL_FPKI' */
  62418. const char* csr_fname = "./certs/csr.signed.der";
  62419. const char* key_fname = "./certs/server-key.der";
  62420. byte der[4096];
  62421. int derSz = 0;
  62422. X509_REQ* x509 = NULL;
  62423. STACK_OF(X509_EXTENSION) *exts = NULL;
  62424. X509_EXTENSION * san_ext = NULL;
  62425. X509_EXTENSION * ext = NULL;
  62426. GENERAL_NAME* gn = NULL;
  62427. GENERAL_NAMES* gns = NULL;
  62428. ASN1_OBJECT* upn_oid = NULL;
  62429. ASN1_UTF8STRING *utf8str = NULL;
  62430. ASN1_TYPE *value = NULL;
  62431. ASN1_STRING *extval = NULL;
  62432. /* SID extension. SID data format explained here:
  62433. * https://blog.qdsecurity.se/2022/05/27/manually-injecting-a-sid-in-a-certificate/
  62434. */
  62435. byte SidExtension[] = {
  62436. 48, 64, 160, 62, 6, 10, 43, 6, 1, 4, 1, 130, 55, 25, 2, 1, 160,
  62437. 48, 4, 46, 83, 45, 49, 45, 53, 45, 50, 49, 45, 50, 56, 52, 51, 57,
  62438. 48, 55, 52, 49, 56, 45, 51, 57, 50, 54, 50, 55, 55, 52, 50, 49, 45,
  62439. 51, 56, 49, 53, 57, 57, 51, 57, 55, 50, 45, 52, 54, 48, 49};
  62440. byte expectedAltName[] = {
  62441. 0x30, 0x27, 0xA0, 0x25, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82,
  62442. 0x37, 0x14, 0x02, 0x03, 0xA0, 0x17, 0x0C, 0x15, 0x6F, 0x74, 0x68, 0x65,
  62443. 0x72, 0x6E, 0x61, 0x6D, 0x65, 0x40, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73,
  62444. 0x6C, 0x2E, 0x63, 0x6F, 0x6D};
  62445. X509_EXTENSION *sid_ext = NULL;
  62446. ASN1_OBJECT* sid_oid = NULL;
  62447. ASN1_OCTET_STRING *sid_data = NULL;
  62448. ASN1_OBJECT* alt_names_oid = NULL;
  62449. EVP_PKEY* priv = NULL;
  62450. XFILE f = XBADFILE;
  62451. byte* pt = NULL;
  62452. BIO* bio = NULL;
  62453. ExpectTrue((f = XFOPEN(csr_fname, "rb")) != XBADFILE);
  62454. ExpectNotNull(x509 = d2i_X509_REQ_fp(f, NULL));
  62455. if (f != XBADFILE) {
  62456. XFCLOSE(f);
  62457. f = XBADFILE;
  62458. }
  62459. ExpectIntEQ(X509_REQ_set_version(x509, 2), 1);
  62460. ExpectNotNull(gn = GENERAL_NAME_new());
  62461. ExpectNotNull(upn_oid = OBJ_txt2obj("1.3.6.1.4.1.311.20.2.3", 1));
  62462. ExpectNotNull(utf8str = ASN1_UTF8STRING_new());
  62463. ExpectIntEQ(ASN1_STRING_set(utf8str, "othername@wolfssl.com", -1), 1);
  62464. ExpectNotNull(value = ASN1_TYPE_new());
  62465. ASN1_TYPE_set(value, V_ASN1_UTF8STRING, utf8str);
  62466. if (EXPECT_FAIL()) {
  62467. ASN1_UTF8STRING_free(utf8str);
  62468. }
  62469. ExpectIntEQ(GENERAL_NAME_set0_othername(gn, upn_oid, value), 1);
  62470. if (EXPECT_FAIL()) {
  62471. ASN1_TYPE_free(value);
  62472. GENERAL_NAME_free(gn);
  62473. gn = NULL;
  62474. }
  62475. ExpectNotNull(gns = sk_GENERAL_NAME_new(NULL));
  62476. ExpectIntEQ(sk_GENERAL_NAME_push(gns, gn), 1);
  62477. if (EXPECT_FAIL()) {
  62478. GENERAL_NAME_free(gn);
  62479. }
  62480. ExpectNotNull(san_ext = X509V3_EXT_i2d(NID_subject_alt_name, 0, gns));
  62481. ExpectNotNull(sid_oid = OBJ_txt2obj("1.3.6.1.4.1.311.25.2", 1));
  62482. ExpectNotNull(sid_data = ASN1_OCTET_STRING_new());
  62483. ASN1_OCTET_STRING_set(sid_data, SidExtension, sizeof(SidExtension));
  62484. ExpectNotNull(sid_ext = X509_EXTENSION_create_by_OBJ(NULL, sid_oid, 0,
  62485. sid_data));
  62486. ExpectNotNull(exts = sk_X509_EXTENSION_new_null());
  62487. /* Ensure an empty stack doesn't raise an error. */
  62488. ExpectIntEQ(X509_REQ_add_extensions(x509, exts), 1);
  62489. ExpectIntEQ(sk_X509_EXTENSION_push(exts, san_ext), 1);
  62490. if (EXPECT_FAIL()) {
  62491. X509_EXTENSION_free(san_ext);
  62492. }
  62493. ExpectIntEQ(sk_X509_EXTENSION_push(exts, sid_ext), 2);
  62494. if (EXPECT_FAIL()) {
  62495. X509_EXTENSION_free(sid_ext);
  62496. }
  62497. ExpectIntEQ(X509_REQ_add_extensions(x509, exts), 1);
  62498. ExpectTrue((f = XFOPEN(key_fname, "rb")) != XBADFILE);
  62499. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  62500. if (f != XBADFILE)
  62501. XFCLOSE(f);
  62502. pt = der;
  62503. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  62504. (const unsigned char**)&pt, derSz));
  62505. ExpectIntGT(X509_REQ_sign(x509, priv, EVP_sha256()), 0);
  62506. pt = der;
  62507. ExpectIntGT(derSz = i2d_X509_REQ(x509, &pt), 0);
  62508. X509_REQ_free(x509);
  62509. x509 = NULL;
  62510. pt = der;
  62511. ExpectNotNull(d2i_X509_REQ_INFO(&x509, (const unsigned char**)&pt, derSz));
  62512. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  62513. gns = NULL;
  62514. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  62515. exts = NULL;
  62516. ASN1_OBJECT_free(upn_oid);
  62517. ASN1_OBJECT_free(sid_oid);
  62518. ASN1_OCTET_STRING_free(sid_data);
  62519. X509_REQ_free(x509);
  62520. EVP_PKEY_free(priv);
  62521. /* At this point everything used to generate what is in der is cleaned up.
  62522. * We now read back from der to confirm the extensions were inserted
  62523. * correctly. */
  62524. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  62525. ExpectNotNull(bio);
  62526. ExpectIntEQ(BIO_write(bio, der, derSz), derSz); /* d2i consumes BIO */
  62527. ExpectNotNull(d2i_X509_REQ_bio(bio, &x509));
  62528. ExpectNotNull(x509);
  62529. BIO_free(bio);
  62530. ExpectNotNull(exts = (STACK_OF(X509_EXTENSION)*)X509_REQ_get_extensions(
  62531. x509));
  62532. ExpectIntEQ(sk_X509_EXTENSION_num(exts), 2);
  62533. /* Check the SID extension. */
  62534. ExpectNotNull(sid_oid = OBJ_txt2obj("1.3.6.1.4.1.311.25.2", 1));
  62535. ExpectNotNull(ext = sk_X509_EXTENSION_value(exts,
  62536. X509_get_ext_by_OBJ(x509, sid_oid, -1)));
  62537. ExpectNotNull(extval = X509_EXTENSION_get_data(ext));
  62538. ExpectIntEQ(extval->length, sizeof(SidExtension));
  62539. ExpectIntEQ(XMEMCMP(SidExtension, extval->data, sizeof(SidExtension)), 0);
  62540. ASN1_OBJECT_free(sid_oid);
  62541. /* Check the AltNames extension. */
  62542. ExpectNotNull(alt_names_oid = OBJ_txt2obj("subjectAltName", 0));
  62543. ExpectNotNull(ext = sk_X509_EXTENSION_value(exts,
  62544. X509_get_ext_by_OBJ(x509, alt_names_oid, -1)));
  62545. ExpectNotNull(extval = X509_EXTENSION_get_data(ext));
  62546. ExpectIntEQ(extval->length, sizeof(expectedAltName));
  62547. ExpectIntEQ(XMEMCMP(expectedAltName, extval->data, sizeof(expectedAltName)),
  62548. 0);
  62549. ASN1_OBJECT_free(alt_names_oid);
  62550. /* Cleanup */
  62551. ExpectNotNull(gns = (GENERAL_NAMES*)X509_get_ext_d2i(x509,
  62552. NID_subject_alt_name, NULL, NULL));
  62553. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 1);
  62554. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, 0));
  62555. ExpectIntEQ(gn->type, 0);
  62556. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  62557. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  62558. X509_REQ_free(x509);
  62559. #endif
  62560. return EXPECT_RESULT();
  62561. }
  62562. static int test_wolfSSL_X509_set_name(void)
  62563. {
  62564. EXPECT_DECLS;
  62565. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  62566. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ)
  62567. X509* x509 = NULL;
  62568. X509_NAME* name = NULL;
  62569. ExpectNotNull(name = X509_NAME_new());
  62570. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  62571. (byte*)"wolfssl.com", 11, 0, 1),
  62572. WOLFSSL_SUCCESS);
  62573. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  62574. (byte*)"support@wolfssl.com", 19, -1,
  62575. 1), WOLFSSL_SUCCESS);
  62576. ExpectNotNull(x509 = X509_new());
  62577. ExpectIntEQ(X509_set_subject_name(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62578. ExpectIntEQ(X509_set_subject_name(x509, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62579. ExpectIntEQ(X509_set_subject_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62580. ExpectIntEQ(X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  62581. ExpectIntEQ(X509_set_issuer_name(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62582. ExpectIntEQ(X509_set_issuer_name(x509, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62583. ExpectIntEQ(X509_set_issuer_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62584. ExpectIntEQ(X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  62585. X509_free(x509);
  62586. X509_NAME_free(name);
  62587. #endif /* OPENSSL_ALL && !NO_CERTS */
  62588. return EXPECT_RESULT();
  62589. }
  62590. static int test_wolfSSL_X509_set_notAfter(void)
  62591. {
  62592. EXPECT_DECLS;
  62593. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) \
  62594. && !defined(NO_ASN_TIME) && !defined(USER_TIME) && \
  62595. !defined(TIME_OVERRIDES) && !defined(NO_CERTS) && \
  62596. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) &&\
  62597. !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT) && !defined(NO_BIO)
  62598. /* Generalized time will overflow time_t if not long */
  62599. X509* x = NULL;
  62600. BIO* bio = NULL;
  62601. ASN1_TIME *asn_time = NULL;
  62602. ASN1_TIME *time_check = NULL;
  62603. const int year = 365*24*60*60;
  62604. const int day = 24*60*60;
  62605. const int hour = 60*60;
  62606. const int mini = 60;
  62607. int offset_day;
  62608. unsigned char buf[25];
  62609. time_t t;
  62610. /*
  62611. * Setup asn_time. APACHE HTTPD uses time(NULL)
  62612. */
  62613. t = (time_t)107 * year + 31 * day + 34 * hour + 30 * mini + 7 * day;
  62614. offset_day = 7;
  62615. /*
  62616. * Free these.
  62617. */
  62618. asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day, 0);
  62619. ExpectNotNull(asn_time);
  62620. ExpectNotNull(x = X509_new());
  62621. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62622. /*
  62623. * Tests
  62624. */
  62625. ExpectTrue(wolfSSL_X509_set_notAfter(x, asn_time));
  62626. /* time_check is simply (ANS1_TIME*)x->notAfter */
  62627. ExpectNotNull(time_check = X509_get_notAfter(x));
  62628. /* ANS1_TIME_check validates by checking if argument can be parsed */
  62629. ExpectIntEQ(ASN1_TIME_check(time_check), WOLFSSL_SUCCESS);
  62630. /* Convert to human readable format and compare to intended date */
  62631. ExpectIntEQ(ASN1_TIME_print(bio, time_check), 1);
  62632. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  62633. ExpectIntEQ(XMEMCMP(buf, "Jan 20 10:30:00 2077 GMT", sizeof(buf) - 1), 0);
  62634. ExpectFalse(wolfSSL_X509_set_notAfter(NULL, NULL));
  62635. ExpectFalse(wolfSSL_X509_set_notAfter(x, NULL));
  62636. ExpectFalse(wolfSSL_X509_set_notAfter(NULL, asn_time));
  62637. /*
  62638. * Cleanup
  62639. */
  62640. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  62641. X509_free(x);
  62642. BIO_free(bio);
  62643. #endif
  62644. return EXPECT_RESULT();
  62645. }
  62646. static int test_wolfSSL_X509_set_notBefore(void)
  62647. {
  62648. EXPECT_DECLS;
  62649. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) \
  62650. && !defined(NO_ASN_TIME) && !defined(USER_TIME) && \
  62651. !defined(TIME_OVERRIDES) && !defined(NO_CERTS) && \
  62652. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_BIO)
  62653. X509* x = NULL;
  62654. BIO* bio = NULL;
  62655. ASN1_TIME *asn_time = NULL;
  62656. ASN1_TIME *time_check = NULL;
  62657. const int year = 365*24*60*60;
  62658. const int day = 24*60*60;
  62659. const int hour = 60*60;
  62660. const int mini = 60;
  62661. int offset_day;
  62662. unsigned char buf[25];
  62663. time_t t;
  62664. /*
  62665. * Setup asn_time. APACHE HTTPD uses time(NULL)
  62666. */
  62667. t = (time_t)49 * year + 125 * day + 20 * hour + 30 * mini + 7 * day;
  62668. offset_day = 7;
  62669. /*
  62670. * Free these.
  62671. */
  62672. asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day, 0);
  62673. ExpectNotNull(asn_time);
  62674. ExpectNotNull(x = X509_new());
  62675. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62676. ExpectIntEQ(ASN1_TIME_check(asn_time), WOLFSSL_SUCCESS);
  62677. /*
  62678. * Main Tests
  62679. */
  62680. ExpectTrue(wolfSSL_X509_set_notBefore(x, asn_time));
  62681. /* time_check == (ANS1_TIME*)x->notBefore */
  62682. ExpectNotNull(time_check = X509_get_notBefore(x));
  62683. /* ANS1_TIME_check validates by checking if argument can be parsed */
  62684. ExpectIntEQ(ASN1_TIME_check(time_check), WOLFSSL_SUCCESS);
  62685. /* Convert to human readable format and compare to intended date */
  62686. ExpectIntEQ(ASN1_TIME_print(bio, time_check), 1);
  62687. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  62688. ExpectIntEQ(XMEMCMP(buf, "May 8 20:30:00 2019 GMT", sizeof(buf) - 1), 0);
  62689. ExpectFalse(wolfSSL_X509_set_notBefore(NULL, NULL));
  62690. ExpectFalse(wolfSSL_X509_set_notBefore(x, NULL));
  62691. ExpectFalse(wolfSSL_X509_set_notBefore(NULL, asn_time));
  62692. /*
  62693. * Cleanup
  62694. */
  62695. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  62696. X509_free(x);
  62697. BIO_free(bio);
  62698. #endif
  62699. return EXPECT_RESULT();
  62700. }
  62701. static int test_wolfSSL_X509_set_version(void)
  62702. {
  62703. EXPECT_DECLS;
  62704. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  62705. !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ)
  62706. X509* x509 = NULL;
  62707. long v = 2L;
  62708. long maxInt = INT_MAX;
  62709. ExpectNotNull(x509 = X509_new());
  62710. /* These should pass. */
  62711. ExpectTrue(wolfSSL_X509_set_version(x509, v));
  62712. ExpectIntEQ(v, wolfSSL_X509_get_version(x509));
  62713. /* Fail Case: When v(long) is greater than x509->version(int). */
  62714. v = maxInt+1;
  62715. ExpectFalse(wolfSSL_X509_set_version(x509, v));
  62716. ExpectFalse(wolfSSL_X509_set_version(NULL, 2L));
  62717. ExpectFalse(wolfSSL_X509_set_version(NULL, maxInt+1));
  62718. /* Cleanup */
  62719. X509_free(x509);
  62720. #endif
  62721. return EXPECT_RESULT();
  62722. }
  62723. #ifndef NO_BIO
  62724. static int test_wolfSSL_BIO_gets(void)
  62725. {
  62726. EXPECT_DECLS;
  62727. #if defined(OPENSSL_EXTRA)
  62728. BIO* bio = NULL;
  62729. BIO* bio2 = NULL;
  62730. char msg[] = "\nhello wolfSSL\n security plus\t---...**adf\na...b.c";
  62731. char emp[] = "";
  62732. char bio_buffer[20];
  62733. int bufferSz = 20;
  62734. #ifdef OPENSSL_ALL
  62735. BUF_MEM* emp_bm = NULL;
  62736. BUF_MEM* msg_bm = NULL;
  62737. #endif
  62738. /* try with bad args */
  62739. ExpectNull(bio = BIO_new_mem_buf(NULL, sizeof(msg)));
  62740. #ifdef OPENSSL_ALL
  62741. ExpectIntEQ(BIO_set_mem_buf(bio, NULL, BIO_NOCLOSE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  62742. #endif
  62743. /* try with real msg */
  62744. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, -1));
  62745. XMEMSET(bio_buffer, 0, bufferSz);
  62746. ExpectNotNull(BIO_push(bio, BIO_new(BIO_s_bio())));
  62747. ExpectNull(bio2 = BIO_find_type(bio, BIO_TYPE_FILE));
  62748. ExpectNotNull(bio2 = BIO_find_type(bio, BIO_TYPE_BIO));
  62749. ExpectFalse(bio2 != BIO_next(bio));
  62750. /* make buffer filled with no terminating characters */
  62751. XMEMSET(bio_buffer, 1, bufferSz);
  62752. /* BIO_gets reads a line of data */
  62753. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  62754. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  62755. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  62756. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  62757. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  62758. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  62759. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  62760. #ifdef OPENSSL_ALL
  62761. /* test setting the mem_buf manually */
  62762. BIO_free(bio);
  62763. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, -1));
  62764. ExpectNotNull(emp_bm = BUF_MEM_new());
  62765. ExpectNotNull(msg_bm = BUF_MEM_new());
  62766. ExpectIntEQ(BUF_MEM_grow(msg_bm, sizeof(msg)), sizeof(msg));
  62767. if (EXPECT_SUCCESS()) {
  62768. XFREE(msg_bm->data, NULL, DYNAMIC_TYPE_OPENSSL);
  62769. msg_bm->data = NULL;
  62770. }
  62771. /* emp size is 1 for terminator */
  62772. ExpectIntEQ(BUF_MEM_grow(emp_bm, sizeof(emp)), sizeof(emp));
  62773. if (EXPECT_SUCCESS()) {
  62774. XFREE(emp_bm->data, NULL, DYNAMIC_TYPE_OPENSSL);
  62775. emp_bm->data = emp;
  62776. msg_bm->data = msg;
  62777. }
  62778. ExpectIntEQ(BIO_set_mem_buf(bio, emp_bm, BIO_CLOSE), WOLFSSL_SUCCESS);
  62779. /* check reading an empty string */
  62780. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1); /* just terminator */
  62781. ExpectStrEQ(emp, bio_buffer);
  62782. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  62783. /* BIO_gets reads a line of data */
  62784. ExpectIntEQ(BIO_set_mem_buf(bio, msg_bm, BIO_NOCLOSE), WOLFSSL_SUCCESS);
  62785. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  62786. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  62787. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  62788. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  62789. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  62790. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  62791. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  62792. if (EXPECT_SUCCESS())
  62793. emp_bm->data = NULL;
  62794. BUF_MEM_free(emp_bm);
  62795. if (EXPECT_SUCCESS())
  62796. msg_bm->data = NULL;
  62797. BUF_MEM_free(msg_bm);
  62798. #endif
  62799. /* check not null terminated string */
  62800. BIO_free(bio);
  62801. bio = NULL;
  62802. msg[0] = 0x33;
  62803. msg[1] = 0x33;
  62804. msg[2] = 0x33;
  62805. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, 3));
  62806. ExpectIntEQ(BIO_gets(bio, bio_buffer, 3), 2);
  62807. ExpectIntEQ(bio_buffer[0], msg[0]);
  62808. ExpectIntEQ(bio_buffer[1], msg[1]);
  62809. ExpectIntNE(bio_buffer[2], msg[2]);
  62810. BIO_free(bio);
  62811. bio = NULL;
  62812. msg[3] = 0x33;
  62813. bio_buffer[3] = 0x33;
  62814. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, 3));
  62815. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 3);
  62816. ExpectIntEQ(bio_buffer[0], msg[0]);
  62817. ExpectIntEQ(bio_buffer[1], msg[1]);
  62818. ExpectIntEQ(bio_buffer[2], msg[2]);
  62819. ExpectIntNE(bio_buffer[3], 0x33); /* make sure null terminator was set */
  62820. /* check reading an empty string */
  62821. BIO_free(bio);
  62822. bio = NULL;
  62823. ExpectNotNull(bio = BIO_new_mem_buf((void*)emp, sizeof(emp)));
  62824. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1); /* just terminator */
  62825. ExpectStrEQ(emp, bio_buffer);
  62826. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  62827. /* check error cases */
  62828. BIO_free(bio);
  62829. bio = NULL;
  62830. ExpectIntEQ(BIO_gets(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62831. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62832. ExpectIntEQ(BIO_gets(bio, bio_buffer, 2), 0); /* nothing to read */
  62833. #if !defined(NO_FILESYSTEM)
  62834. {
  62835. BIO* f_bio = NULL;
  62836. XFILE f = XBADFILE;
  62837. ExpectNotNull(f_bio = BIO_new(BIO_s_file()));
  62838. ExpectIntLE(BIO_gets(f_bio, bio_buffer, bufferSz), 0);
  62839. ExpectTrue((f = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  62840. ExpectIntEQ((int)BIO_set_fp(f_bio, f, BIO_CLOSE), SSL_SUCCESS);
  62841. if (EXPECT_FAIL() && (f != XBADFILE)) {
  62842. XFCLOSE(f);
  62843. }
  62844. ExpectIntGT(BIO_gets(f_bio, bio_buffer, bufferSz), 0);
  62845. BIO_free(f_bio);
  62846. f_bio = NULL;
  62847. }
  62848. #endif /* NO_FILESYSTEM */
  62849. BIO_free(bio);
  62850. bio = NULL;
  62851. BIO_free(bio2);
  62852. bio2 = NULL;
  62853. /* try with type BIO */
  62854. XMEMCPY(msg, "\nhello wolfSSL\n security plus\t---...**adf\na...b.c",
  62855. sizeof(msg));
  62856. ExpectNotNull(bio = BIO_new(BIO_s_bio()));
  62857. ExpectIntEQ(BIO_gets(bio, bio_buffer, 2), 0); /* nothing to read */
  62858. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  62859. ExpectIntEQ(BIO_set_write_buf_size(bio, 10), SSL_SUCCESS);
  62860. ExpectIntEQ(BIO_set_write_buf_size(bio2, sizeof(msg)), SSL_SUCCESS);
  62861. ExpectIntEQ(BIO_make_bio_pair(bio, bio2), SSL_SUCCESS);
  62862. ExpectIntEQ(BIO_write(bio2, msg, sizeof(msg)), sizeof(msg));
  62863. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  62864. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  62865. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  62866. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  62867. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  62868. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  62869. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  62870. BIO_free(bio);
  62871. bio = NULL;
  62872. BIO_free(bio2);
  62873. bio2 = NULL;
  62874. /* check reading an empty string */
  62875. ExpectNotNull(bio = BIO_new(BIO_s_bio()));
  62876. ExpectIntEQ(BIO_set_write_buf_size(bio, sizeof(emp)), SSL_SUCCESS);
  62877. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  62878. ExpectStrEQ(emp, bio_buffer);
  62879. BIO_free(bio);
  62880. bio = NULL;
  62881. #endif
  62882. return EXPECT_RESULT();
  62883. }
  62884. static int test_wolfSSL_BIO_puts(void)
  62885. {
  62886. EXPECT_DECLS;
  62887. #if defined(OPENSSL_EXTRA)
  62888. BIO* bio = NULL;
  62889. char input[] = "hello\0world\n.....ok\n\0";
  62890. char output[128];
  62891. XMEMSET(output, 0, sizeof(output));
  62892. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62893. ExpectIntEQ(BIO_puts(bio, input), 5);
  62894. ExpectIntEQ(BIO_pending(bio), 5);
  62895. ExpectIntEQ(BIO_puts(bio, input + 6), 14);
  62896. ExpectIntEQ(BIO_pending(bio), 19);
  62897. ExpectIntEQ(BIO_gets(bio, output, sizeof(output)), 11);
  62898. ExpectStrEQ(output, "helloworld\n");
  62899. ExpectIntEQ(BIO_pending(bio), 8);
  62900. ExpectIntEQ(BIO_gets(bio, output, sizeof(output)), 8);
  62901. ExpectStrEQ(output, ".....ok\n");
  62902. ExpectIntEQ(BIO_pending(bio), 0);
  62903. ExpectIntEQ(BIO_puts(bio, ""), -1);
  62904. BIO_free(bio);
  62905. #endif
  62906. return EXPECT_RESULT();
  62907. }
  62908. static int test_wolfSSL_BIO_dump(void)
  62909. {
  62910. EXPECT_DECLS;
  62911. #if defined(OPENSSL_EXTRA)
  62912. BIO* bio;
  62913. static const unsigned char data[] = {
  62914. 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE,
  62915. 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D,
  62916. 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x55, 0xBF, 0xF4,
  62917. 0x0F, 0x44, 0x50, 0x9A, 0x3D, 0xCE, 0x9B, 0xB7, 0xF0, 0xC5,
  62918. 0x4D, 0xF5, 0x70, 0x7B, 0xD4, 0xEC, 0x24, 0x8E, 0x19, 0x80,
  62919. 0xEC, 0x5A, 0x4C, 0xA2, 0x24, 0x03, 0x62, 0x2C, 0x9B, 0xDA,
  62920. 0xEF, 0xA2, 0x35, 0x12, 0x43, 0x84, 0x76, 0x16, 0xC6, 0x56,
  62921. 0x95, 0x06, 0xCC, 0x01, 0xA9, 0xBD, 0xF6, 0x75, 0x1A, 0x42,
  62922. 0xF7, 0xBD, 0xA9, 0xB2, 0x36, 0x22, 0x5F, 0xC7, 0x5D, 0x7F,
  62923. 0xB4
  62924. };
  62925. /* Generated with OpenSSL. */
  62926. static const char expected[] =
  62927. "0000 - 30 59 30 13 06 07 2a 86-48 ce 3d 02 01 06 08 2a 0Y0...*.H.=....*\n"
  62928. "0010 - 86 48 ce 3d 03 01 07 03-42 00 04 55 bf f4 0f 44 .H.=....B..U...D\n"
  62929. "0020 - 50 9a 3d ce 9b b7 f0 c5-4d f5 70 7b d4 ec 24 8e P.=.....M.p{..$.\n"
  62930. "0030 - 19 80 ec 5a 4c a2 24 03-62 2c 9b da ef a2 35 12 ...ZL.$.b,....5.\n"
  62931. "0040 - 43 84 76 16 c6 56 95 06-cc 01 a9 bd f6 75 1a 42 C.v..V.......u.B\n"
  62932. "0050 - f7 bd a9 b2 36 22 5f c7-5d 7f b4 ....6\"_.]..\n";
  62933. static const char expectedAll[] =
  62934. "0000 - 00 01 02 03 04 05 06 07-08 09 0a 0b 0c 0d 0e 0f ................\n"
  62935. "0010 - 10 11 12 13 14 15 16 17-18 19 1a 1b 1c 1d 1e 1f ................\n"
  62936. "0020 - 20 21 22 23 24 25 26 27-28 29 2a 2b 2c 2d 2e 2f !\"#$%&'()*+,-./\n"
  62937. "0030 - 30 31 32 33 34 35 36 37-38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>?\n"
  62938. "0040 - 40 41 42 43 44 45 46 47-48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO\n"
  62939. "0050 - 50 51 52 53 54 55 56 57-58 59 5a 5b 5c 5d 5e 5f PQRSTUVWXYZ[\\]^_\n"
  62940. "0060 - 60 61 62 63 64 65 66 67-68 69 6a 6b 6c 6d 6e 6f `abcdefghijklmno\n"
  62941. "0070 - 70 71 72 73 74 75 76 77-78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~.\n"
  62942. "0080 - 80 81 82 83 84 85 86 87-88 89 8a 8b 8c 8d 8e 8f ................\n"
  62943. "0090 - 90 91 92 93 94 95 96 97-98 99 9a 9b 9c 9d 9e 9f ................\n"
  62944. "00a0 - a0 a1 a2 a3 a4 a5 a6 a7-a8 a9 aa ab ac ad ae af ................\n"
  62945. "00b0 - b0 b1 b2 b3 b4 b5 b6 b7-b8 b9 ba bb bc bd be bf ................\n"
  62946. "00c0 - c0 c1 c2 c3 c4 c5 c6 c7-c8 c9 ca cb cc cd ce cf ................\n"
  62947. "00d0 - d0 d1 d2 d3 d4 d5 d6 d7-d8 d9 da db dc dd de df ................\n"
  62948. "00e0 - e0 e1 e2 e3 e4 e5 e6 e7-e8 e9 ea eb ec ed ee ef ................\n"
  62949. "00f0 - f0 f1 f2 f3 f4 f5 f6 f7-f8 f9 fa fb fc fd fe ff ................\n";
  62950. char output[16 * 80];
  62951. int i;
  62952. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62953. /* Example key dumped. */
  62954. ExpectIntEQ(BIO_dump(bio, (const char*)data, (int)sizeof(data)),
  62955. sizeof(expected) - 1);
  62956. ExpectIntEQ(BIO_read(bio, output, sizeof(output)), sizeof(expected) - 1);
  62957. ExpectIntEQ(XMEMCMP(output, expected, sizeof(expected) - 1), 0);
  62958. /* Try every possible value for a character. */
  62959. for (i = 0; i < 256; i++)
  62960. output[i] = i;
  62961. ExpectIntEQ(BIO_dump(bio, output, 256), sizeof(expectedAll) - 1);
  62962. ExpectIntEQ(BIO_read(bio, output, sizeof(output)), sizeof(expectedAll) - 1);
  62963. ExpectIntEQ(XMEMCMP(output, expectedAll, sizeof(expectedAll) - 1), 0);
  62964. BIO_free(bio);
  62965. #endif
  62966. return EXPECT_RESULT();
  62967. }
  62968. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  62969. !defined(NO_RSA) && defined(HAVE_EXT_CACHE) && \
  62970. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(USE_WOLFSSL_IO)
  62971. static int forceWantRead(WOLFSSL *ssl, char *buf, int sz, void *ctx)
  62972. {
  62973. (void)ssl;
  62974. (void)buf;
  62975. (void)sz;
  62976. (void)ctx;
  62977. return WOLFSSL_CBIO_ERR_WANT_READ;
  62978. }
  62979. #endif
  62980. static int test_wolfSSL_BIO_should_retry(void)
  62981. {
  62982. EXPECT_DECLS;
  62983. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  62984. !defined(NO_RSA) && defined(HAVE_EXT_CACHE) && \
  62985. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(USE_WOLFSSL_IO)
  62986. tcp_ready ready;
  62987. func_args server_args;
  62988. THREAD_TYPE serverThread;
  62989. SOCKET_T sockfd = 0;
  62990. WOLFSSL_CTX* ctx = NULL;
  62991. WOLFSSL* ssl = NULL;
  62992. char msg[64] = "hello wolfssl!";
  62993. char reply[1024];
  62994. int msgSz = (int)XSTRLEN(msg);
  62995. int ret;
  62996. BIO* bio = NULL;
  62997. XMEMSET(&server_args, 0, sizeof(func_args));
  62998. #ifdef WOLFSSL_TIRTOS
  62999. fdOpenSession(Task_self());
  63000. #endif
  63001. StartTCP();
  63002. InitTcpReady(&ready);
  63003. #if defined(USE_WINDOWS_API)
  63004. /* use RNG to get random port if using windows */
  63005. ready.port = GetRandomPort();
  63006. #endif
  63007. server_args.signal = &ready;
  63008. start_thread(test_server_nofail, &server_args, &serverThread);
  63009. wait_tcp_ready(&server_args);
  63010. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  63011. #ifdef OPENSSL_COMPATIBLE_DEFAULTS
  63012. ExpectIntEQ(wolfSSL_CTX_clear_mode(ctx, SSL_MODE_AUTO_RETRY), 0);
  63013. #endif
  63014. ExpectIntEQ(WOLFSSL_SUCCESS,
  63015. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  63016. ExpectIntEQ(WOLFSSL_SUCCESS,
  63017. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  63018. ExpectIntEQ(WOLFSSL_SUCCESS,
  63019. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  63020. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  63021. /* force retry */
  63022. ExpectNotNull(bio = wolfSSL_BIO_new_ssl(ctx, 1));
  63023. ExpectIntEQ(BIO_get_ssl(bio, &ssl), 1);
  63024. ExpectNotNull(ssl);
  63025. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  63026. wolfSSL_SSLSetIORecv(ssl, forceWantRead);
  63027. if (EXPECT_FAIL()) {
  63028. wolfSSL_free(ssl);
  63029. ssl = NULL;
  63030. }
  63031. ExpectIntLE(BIO_write(bio, msg, msgSz), 0);
  63032. ExpectIntNE(BIO_should_retry(bio), 0);
  63033. ExpectIntEQ(BIO_should_read(bio), 0);
  63034. ExpectIntEQ(BIO_should_write(bio), 0);
  63035. /* now perform successful connection */
  63036. wolfSSL_SSLSetIORecv(ssl, EmbedReceive);
  63037. ExpectIntEQ(BIO_write(bio, msg, msgSz), msgSz);
  63038. ExpectIntNE(BIO_read(bio, reply, sizeof(reply)), 0);
  63039. ret = wolfSSL_get_error(ssl, -1);
  63040. if (ret == WOLFSSL_ERROR_WANT_READ || ret == WOLFSSL_ERROR_WANT_WRITE) {
  63041. ExpectIntNE(BIO_should_retry(bio), 0);
  63042. if (ret == WOLFSSL_ERROR_WANT_READ)
  63043. ExpectIntEQ(BIO_should_read(bio), 1);
  63044. else
  63045. ExpectIntEQ(BIO_should_read(bio), 0);
  63046. if (ret == WOLFSSL_ERROR_WANT_WRITE)
  63047. ExpectIntEQ(BIO_should_write(bio), 1);
  63048. else
  63049. ExpectIntEQ(BIO_should_write(bio), 0);
  63050. }
  63051. else {
  63052. ExpectIntEQ(BIO_should_retry(bio), 0);
  63053. ExpectIntEQ(BIO_should_read(bio), 0);
  63054. ExpectIntEQ(BIO_should_write(bio), 0);
  63055. }
  63056. ExpectIntEQ(XMEMCMP(reply, "I hear you fa shizzle!",
  63057. XSTRLEN("I hear you fa shizzle!")), 0);
  63058. BIO_free(bio);
  63059. wolfSSL_CTX_free(ctx);
  63060. CloseSocket(sockfd);
  63061. join_thread(serverThread);
  63062. FreeTcpReady(&ready);
  63063. #ifdef WOLFSSL_TIRTOS
  63064. fdOpenSession(Task_self());
  63065. #endif
  63066. #endif
  63067. return EXPECT_RESULT();
  63068. }
  63069. static int test_wolfSSL_BIO_connect(void)
  63070. {
  63071. EXPECT_DECLS;
  63072. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  63073. defined(HAVE_HTTP_CLIENT) && !defined(NO_WOLFSSL_CLIENT)
  63074. tcp_ready ready;
  63075. func_args server_args;
  63076. THREAD_TYPE serverThread;
  63077. BIO *tcpBio = NULL;
  63078. BIO *sslBio = NULL;
  63079. SSL_CTX* ctx = NULL;
  63080. SSL *ssl = NULL;
  63081. SSL *sslPtr;
  63082. char msg[] = "hello wolfssl!";
  63083. char reply[30];
  63084. char buff[10] = {0};
  63085. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  63086. ExpectIntEQ(WOLFSSL_SUCCESS,
  63087. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  63088. ExpectIntEQ(WOLFSSL_SUCCESS,
  63089. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  63090. ExpectIntEQ(WOLFSSL_SUCCESS,
  63091. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  63092. /* Setup server */
  63093. XMEMSET(&server_args, 0, sizeof(func_args));
  63094. StartTCP();
  63095. InitTcpReady(&ready);
  63096. #if defined(USE_WINDOWS_API)
  63097. /* use RNG to get random port if using windows */
  63098. ready.port = GetRandomPort();
  63099. #endif
  63100. server_args.signal = &ready;
  63101. start_thread(test_server_nofail, &server_args, &serverThread);
  63102. wait_tcp_ready(&server_args);
  63103. ExpectIntGT(XSNPRINTF(buff, sizeof(buff), "%d", ready.port), 0);
  63104. /* Start the test proper */
  63105. /* Setup the TCP BIO */
  63106. ExpectNotNull(tcpBio = BIO_new_connect(wolfSSLIP));
  63107. ExpectIntEQ(BIO_set_conn_port(tcpBio, buff), 1);
  63108. /* Setup the SSL object */
  63109. ExpectNotNull(ssl = SSL_new(ctx));
  63110. SSL_set_connect_state(ssl);
  63111. /* Setup the SSL BIO */
  63112. ExpectNotNull(sslBio = BIO_new(BIO_f_ssl()));
  63113. ExpectIntEQ(BIO_set_ssl(sslBio, ssl, BIO_CLOSE), 1);
  63114. if (EXPECT_FAIL()) {
  63115. wolfSSL_free(ssl);
  63116. }
  63117. /* Verify that BIO_get_ssl works. */
  63118. ExpectIntEQ(BIO_get_ssl(sslBio, &sslPtr), 1);
  63119. ExpectPtrEq(ssl, sslPtr);
  63120. /* Link BIO's so that sslBio uses tcpBio for IO */
  63121. ExpectPtrEq(BIO_push(sslBio, tcpBio), sslBio);
  63122. /* Do TCP connect */
  63123. ExpectIntEQ(BIO_do_connect(sslBio), 1);
  63124. /* Do TLS handshake */
  63125. ExpectIntEQ(BIO_do_handshake(sslBio), 1);
  63126. /* Test writing */
  63127. ExpectIntEQ(BIO_write(sslBio, msg, sizeof(msg)), sizeof(msg));
  63128. /* Expect length of default wolfSSL reply */
  63129. ExpectIntEQ(BIO_read(sslBio, reply, sizeof(reply)), 23);
  63130. /* Clean it all up */
  63131. BIO_free_all(sslBio);
  63132. /* Server clean up */
  63133. join_thread(serverThread);
  63134. FreeTcpReady(&ready);
  63135. /* Run the same test, but use BIO_new_ssl_connect and set the IP and port
  63136. * after. */
  63137. XMEMSET(&server_args, 0, sizeof(func_args));
  63138. StartTCP();
  63139. InitTcpReady(&ready);
  63140. #if defined(USE_WINDOWS_API)
  63141. /* use RNG to get random port if using windows */
  63142. ready.port = GetRandomPort();
  63143. #endif
  63144. server_args.signal = &ready;
  63145. start_thread(test_server_nofail, &server_args, &serverThread);
  63146. wait_tcp_ready(&server_args);
  63147. ExpectIntGT(XSNPRINTF(buff, sizeof(buff), "%d", ready.port), 0);
  63148. ExpectNotNull(sslBio = BIO_new_ssl_connect(ctx));
  63149. ExpectIntEQ(BIO_set_conn_hostname(sslBio, (char*)wolfSSLIP), 1);
  63150. ExpectIntEQ(BIO_set_conn_port(sslBio, buff), 1);
  63151. ExpectIntEQ(BIO_do_connect(sslBio), 1);
  63152. ExpectIntEQ(BIO_do_handshake(sslBio), 1);
  63153. ExpectIntEQ(BIO_write(sslBio, msg, sizeof(msg)), sizeof(msg));
  63154. ExpectIntEQ(BIO_read(sslBio, reply, sizeof(reply)), 23);
  63155. /* Attempt to close the TLS connection gracefully. */
  63156. BIO_ssl_shutdown(sslBio);
  63157. BIO_free_all(sslBio);
  63158. join_thread(serverThread);
  63159. FreeTcpReady(&ready);
  63160. SSL_CTX_free(ctx);
  63161. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  63162. wc_ecc_fp_free(); /* free per thread cache */
  63163. #endif
  63164. #endif
  63165. return EXPECT_RESULT();
  63166. }
  63167. static int test_wolfSSL_BIO_tls(void)
  63168. {
  63169. EXPECT_DECLS;
  63170. #if !defined(NO_BIO) && defined(OPENSSL_EXTRA) && !defined(NO_WOLFSSL_CLIENT)
  63171. SSL_CTX* ctx = NULL;
  63172. SSL *ssl = NULL;
  63173. BIO *readBio = NULL;
  63174. BIO *writeBio = NULL;
  63175. int ret;
  63176. int err = 0;
  63177. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  63178. ExpectNotNull(ssl = SSL_new(ctx));
  63179. ExpectNotNull(readBio = BIO_new(BIO_s_mem()));
  63180. ExpectNotNull(writeBio = BIO_new(BIO_s_mem()));
  63181. /* Qt reads data from write-bio,
  63182. * then writes the read data into plain packet.
  63183. * Qt reads data from plain packet,
  63184. * then writes the read data into read-bio.
  63185. */
  63186. SSL_set_bio(ssl, readBio, writeBio);
  63187. do {
  63188. #ifdef WOLFSSL_ASYNC_CRYPT
  63189. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  63190. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  63191. if (ret < 0) { break; } else if (ret == 0) { continue; }
  63192. }
  63193. #endif
  63194. ret = SSL_connect(ssl);
  63195. err = SSL_get_error(ssl, 0);
  63196. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  63197. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  63198. /* in this use case, should return WANT READ
  63199. * so that Qt will read the data from plain packet for next state.
  63200. */
  63201. ExpectIntEQ(err, SSL_ERROR_WANT_READ);
  63202. SSL_free(ssl);
  63203. SSL_CTX_free(ctx);
  63204. #endif
  63205. return EXPECT_RESULT();
  63206. }
  63207. static int test_wolfSSL_BIO_datagram(void)
  63208. {
  63209. EXPECT_DECLS;
  63210. #if !defined(NO_BIO) && defined(WOLFSSL_DTLS) && defined(WOLFSSL_HAVE_BIO_ADDR) && defined(OPENSSL_EXTRA)
  63211. int ret;
  63212. SOCKET_T fd1 = SOCKET_INVALID, fd2 = SOCKET_INVALID;
  63213. WOLFSSL_BIO *bio1 = NULL, *bio2 = NULL;
  63214. WOLFSSL_BIO_ADDR *bio_addr1 = NULL, *bio_addr2 = NULL;
  63215. SOCKADDR_IN sin1, sin2;
  63216. socklen_t slen;
  63217. static const char test_msg[] = "I am a datagram, short and stout.";
  63218. char test_msg_recvd[sizeof(test_msg) + 10];
  63219. #ifdef USE_WINDOWS_API
  63220. static const DWORD timeout = 250; /* ms */
  63221. #else
  63222. static const struct timeval timeout = { 0, 250000 };
  63223. #endif
  63224. StartTCP();
  63225. if (EXPECT_SUCCESS()) {
  63226. fd1 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  63227. ExpectIntNE(fd1, SOCKET_INVALID);
  63228. }
  63229. if (EXPECT_SUCCESS()) {
  63230. fd2 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  63231. ExpectIntNE(fd2, SOCKET_INVALID);
  63232. }
  63233. if (EXPECT_SUCCESS()) {
  63234. bio1 = wolfSSL_BIO_new_dgram(fd1, 1 /* closeF */);
  63235. ExpectNotNull(bio1);
  63236. }
  63237. if (EXPECT_SUCCESS()) {
  63238. bio2 = wolfSSL_BIO_new_dgram(fd2, 1 /* closeF */);
  63239. ExpectNotNull(bio2);
  63240. }
  63241. if (EXPECT_SUCCESS()) {
  63242. sin1.sin_family = AF_INET;
  63243. sin1.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  63244. sin1.sin_port = 0;
  63245. slen = (socklen_t)sizeof(sin1);
  63246. ExpectIntEQ(bind(fd1, (const struct sockaddr *)&sin1, slen), 0);
  63247. ExpectIntEQ(setsockopt(fd1, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)), 0);
  63248. ExpectIntEQ(getsockname(fd1, (struct sockaddr *)&sin1, &slen), 0);
  63249. }
  63250. if (EXPECT_SUCCESS()) {
  63251. sin2.sin_family = AF_INET;
  63252. sin2.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  63253. sin2.sin_port = 0;
  63254. slen = (socklen_t)sizeof(sin2);
  63255. ExpectIntEQ(bind(fd2, (const struct sockaddr *)&sin2, slen), 0);
  63256. ExpectIntEQ(setsockopt(fd2, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)), 0);
  63257. ExpectIntEQ(getsockname(fd2, (struct sockaddr *)&sin2, &slen), 0);
  63258. }
  63259. if (EXPECT_SUCCESS()) {
  63260. bio_addr1 = wolfSSL_BIO_ADDR_new();
  63261. ExpectNotNull(bio_addr1);
  63262. }
  63263. if (EXPECT_SUCCESS()) {
  63264. bio_addr2 = wolfSSL_BIO_ADDR_new();
  63265. ExpectNotNull(bio_addr2);
  63266. }
  63267. if (EXPECT_SUCCESS()) {
  63268. /* for OpenSSL compatibility, direct copying of sockaddrs into BIO_ADDRs must work right. */
  63269. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  63270. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_PEER, 0, bio_addr2), WOLFSSL_SUCCESS);
  63271. wolfSSL_BIO_ADDR_clear(bio_addr2);
  63272. }
  63273. test_msg_recvd[0] = 0;
  63274. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  63275. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  63276. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  63277. #ifdef WOLFSSL_BIO_HAVE_FLOW_STATS
  63278. ExpectIntEQ(wolfSSL_BIO_number_written(bio1), sizeof(test_msg));
  63279. ExpectIntEQ(wolfSSL_BIO_number_read(bio2), sizeof(test_msg));
  63280. #endif
  63281. /* bio2 should now have bio1's addr stored as its peer_addr, because the
  63282. * BIOs aren't "connected" yet. use it to send a reply.
  63283. */
  63284. test_msg_recvd[0] = 0;
  63285. ExpectIntEQ(wolfSSL_BIO_write(bio2, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  63286. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  63287. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  63288. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), WOLFSSL_BIO_ERROR);
  63289. ExpectIntNE(BIO_should_retry(bio1), 0);
  63290. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), WOLFSSL_BIO_ERROR);
  63291. ExpectIntNE(BIO_should_retry(bio2), 0);
  63292. /* now "connect" the sockets. */
  63293. ExpectIntEQ(connect(fd1, (const struct sockaddr *)&sin2, (socklen_t)sizeof(sin2)), 0);
  63294. ExpectIntEQ(connect(fd2, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  63295. if (EXPECT_SUCCESS()) {
  63296. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  63297. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_CONNECTED, 0, bio_addr2), WOLFSSL_SUCCESS);
  63298. wolfSSL_BIO_ADDR_clear(bio_addr2);
  63299. }
  63300. if (EXPECT_SUCCESS()) {
  63301. XMEMCPY(&bio_addr1->sa_in, &sin1, sizeof(sin1));
  63302. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio2, BIO_CTRL_DGRAM_SET_CONNECTED, 0, bio_addr1), WOLFSSL_SUCCESS);
  63303. wolfSSL_BIO_ADDR_clear(bio_addr1);
  63304. }
  63305. test_msg_recvd[0] = 0;
  63306. ExpectIntEQ(wolfSSL_BIO_write(bio2, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  63307. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  63308. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  63309. test_msg_recvd[0] = 0;
  63310. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  63311. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  63312. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  63313. #ifdef __linux__
  63314. /* now "disconnect" the sockets and attempt transmits expected to fail. */
  63315. sin1.sin_family = AF_UNSPEC;
  63316. ExpectIntEQ(connect(fd1, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  63317. ExpectIntEQ(connect(fd2, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  63318. sin1.sin_family = AF_INET;
  63319. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_CONNECTED, 0, NULL), WOLFSSL_SUCCESS);
  63320. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio2, BIO_CTRL_DGRAM_SET_CONNECTED, 0, NULL), WOLFSSL_SUCCESS);
  63321. if (EXPECT_SUCCESS()) {
  63322. sin2.sin_addr.s_addr = htonl(0xc0a8c0a8); /* 192.168.192.168 -- invalid for loopback interface. */
  63323. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  63324. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_PEER, 0, bio_addr2), WOLFSSL_SUCCESS);
  63325. wolfSSL_BIO_ADDR_clear(bio_addr2);
  63326. }
  63327. test_msg_recvd[0] = 0;
  63328. errno = 0;
  63329. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), -1);
  63330. ExpectTrue((errno == EINVAL) || (errno == ENETUNREACH));
  63331. #endif /* __linux__ */
  63332. if (bio1) {
  63333. ret = wolfSSL_BIO_free(bio1);
  63334. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  63335. } else if (fd1 != SOCKET_INVALID)
  63336. CloseSocket(fd1);
  63337. if (bio2) {
  63338. ret = wolfSSL_BIO_free(bio2);
  63339. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  63340. } else if (fd2 != SOCKET_INVALID)
  63341. CloseSocket(fd2);
  63342. if (bio_addr1)
  63343. wolfSSL_BIO_ADDR_free(bio_addr1);
  63344. if (bio_addr2)
  63345. wolfSSL_BIO_ADDR_free(bio_addr2);
  63346. #endif /* !NO_BIO && WOLFSSL_DTLS && WOLFSSL_HAVE_BIO_ADDR && OPENSSL_EXTRA */
  63347. return EXPECT_RESULT();
  63348. }
  63349. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  63350. defined(HAVE_HTTP_CLIENT)
  63351. static THREAD_RETURN WOLFSSL_THREAD test_wolfSSL_BIO_accept_client(void* args)
  63352. {
  63353. BIO* clientBio;
  63354. SSL* sslClient;
  63355. SSL_CTX* ctx;
  63356. char connectAddr[20]; /* IP + port */;
  63357. (void)args;
  63358. AssertIntGT(snprintf(connectAddr, sizeof(connectAddr), "%s:%d", wolfSSLIP, wolfSSLPort), 0);
  63359. AssertNotNull(clientBio = BIO_new_connect(connectAddr));
  63360. AssertIntEQ(BIO_do_connect(clientBio), 1);
  63361. AssertNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  63362. AssertNotNull(sslClient = SSL_new(ctx));
  63363. AssertIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0), WOLFSSL_SUCCESS);
  63364. SSL_set_bio(sslClient, clientBio, clientBio);
  63365. AssertIntEQ(SSL_connect(sslClient), 1);
  63366. SSL_free(sslClient);
  63367. SSL_CTX_free(ctx);
  63368. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  63369. wc_ecc_fp_free(); /* free per thread cache */
  63370. #endif
  63371. WOLFSSL_RETURN_FROM_THREAD(0);
  63372. }
  63373. #endif
  63374. static int test_wolfSSL_BIO_accept(void)
  63375. {
  63376. EXPECT_DECLS;
  63377. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  63378. defined(HAVE_HTTP_CLIENT)
  63379. BIO* serverBindBio = NULL;
  63380. BIO* serverAcceptBio = NULL;
  63381. SSL* sslServer = NULL;
  63382. SSL_CTX* ctx = NULL;
  63383. func_args args;
  63384. THREAD_TYPE thread;
  63385. char port[10]; /* 10 bytes should be enough to store the string
  63386. * representation of the port */
  63387. ExpectIntGT(snprintf(port, sizeof(port), "%d", wolfSSLPort), 0);
  63388. ExpectNotNull(serverBindBio = BIO_new_accept(port));
  63389. /* First BIO_do_accept binds the port */
  63390. ExpectIntEQ(BIO_do_accept(serverBindBio), 1);
  63391. XMEMSET(&args, 0, sizeof(func_args));
  63392. start_thread(test_wolfSSL_BIO_accept_client, &args, &thread);
  63393. ExpectIntEQ(BIO_do_accept(serverBindBio), 1);
  63394. /* Let's plug it into SSL to test */
  63395. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  63396. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  63397. SSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  63398. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  63399. SSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  63400. ExpectNotNull(sslServer = SSL_new(ctx));
  63401. ExpectNotNull(serverAcceptBio = BIO_pop(serverBindBio));
  63402. SSL_set_bio(sslServer, serverAcceptBio, serverAcceptBio);
  63403. ExpectIntEQ(SSL_accept(sslServer), 1);
  63404. join_thread(thread);
  63405. BIO_free(serverBindBio);
  63406. SSL_free(sslServer);
  63407. SSL_CTX_free(ctx);
  63408. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  63409. wc_ecc_fp_free(); /* free per thread cache */
  63410. #endif
  63411. #endif
  63412. return EXPECT_RESULT();
  63413. }
  63414. static int test_wolfSSL_BIO_write(void)
  63415. {
  63416. EXPECT_DECLS;
  63417. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  63418. BIO* bio = NULL;
  63419. BIO* bio64 = NULL;
  63420. BIO* bio_mem = NULL;
  63421. BIO* ptr = NULL;
  63422. int sz;
  63423. char msg[] = "conversion test";
  63424. char out[40];
  63425. char expected[] = "Y29udmVyc2lvbiB0ZXN0AA==\n";
  63426. void* bufPtr = NULL;
  63427. BUF_MEM* buf = NULL;
  63428. ExpectNotNull(bio64 = BIO_new(BIO_f_base64()));
  63429. ExpectNotNull(bio = BIO_push(bio64, BIO_new(BIO_s_mem())));
  63430. if (EXPECT_FAIL()) {
  63431. BIO_free(bio64);
  63432. }
  63433. /* now should convert to base64 then write to memory */
  63434. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  63435. BIO_flush(bio);
  63436. /* test BIO chain */
  63437. ExpectIntEQ(SSL_SUCCESS, (int)BIO_get_mem_ptr(bio, &buf));
  63438. ExpectNotNull(buf);
  63439. ExpectIntEQ(buf->length, 25);
  63440. ExpectIntEQ(BIO_get_mem_data(bio, &bufPtr), 25);
  63441. ExpectPtrEq(buf->data, bufPtr);
  63442. ExpectNotNull(ptr = BIO_find_type(bio, BIO_TYPE_MEM));
  63443. sz = sizeof(out);
  63444. XMEMSET(out, 0, sz);
  63445. ExpectIntEQ((sz = BIO_read(ptr, out, sz)), 25);
  63446. ExpectIntEQ(XMEMCMP(out, expected, sz), 0);
  63447. /* write then read should return the same message */
  63448. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  63449. sz = sizeof(out);
  63450. XMEMSET(out, 0, sz);
  63451. ExpectIntEQ(BIO_read(bio, out, sz), 16);
  63452. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  63453. /* now try encoding with no line ending */
  63454. BIO_set_flags(bio64, BIO_FLAGS_BASE64_NO_NL);
  63455. #ifdef HAVE_EX_DATA
  63456. BIO_set_ex_data(bio64, 0, (void*) "data");
  63457. ExpectIntEQ(strcmp((const char*)BIO_get_ex_data(bio64, 0), "data"), 0);
  63458. #endif
  63459. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  63460. BIO_flush(bio);
  63461. sz = sizeof(out);
  63462. XMEMSET(out, 0, sz);
  63463. ExpectIntEQ((sz = BIO_read(ptr, out, sz)), 24);
  63464. ExpectIntEQ(XMEMCMP(out, expected, sz), 0);
  63465. BIO_free_all(bio); /* frees bio64 also */
  63466. bio = NULL;
  63467. /* test with more than one bio64 in list */
  63468. ExpectNotNull(bio64 = BIO_new(BIO_f_base64()));
  63469. ExpectNotNull(bio = BIO_push(BIO_new(BIO_f_base64()), bio64));
  63470. if (EXPECT_FAIL()) {
  63471. BIO_free(bio64);
  63472. bio64 = NULL;
  63473. }
  63474. ExpectNotNull(bio_mem = BIO_new(BIO_s_mem()));
  63475. ExpectNotNull(BIO_push(bio64, bio_mem));
  63476. if (EXPECT_FAIL()) {
  63477. BIO_free(bio_mem);
  63478. }
  63479. /* now should convert to base64 when stored and then decode with read */
  63480. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), 25);
  63481. BIO_flush(bio);
  63482. sz = sizeof(out);
  63483. XMEMSET(out, 0, sz);
  63484. ExpectIntEQ((sz = BIO_read(bio, out, sz)), 16);
  63485. ExpectIntEQ(XMEMCMP(out, msg, sz), 0);
  63486. BIO_clear_flags(bio64, ~0);
  63487. BIO_set_retry_read(bio);
  63488. BIO_free_all(bio); /* frees bio64s also */
  63489. bio = NULL;
  63490. ExpectNotNull(bio = BIO_new_mem_buf(out, 0));
  63491. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  63492. BIO_free(bio);
  63493. #endif
  63494. return EXPECT_RESULT();
  63495. }
  63496. static int test_wolfSSL_BIO_printf(void)
  63497. {
  63498. EXPECT_DECLS;
  63499. #if defined(OPENSSL_ALL)
  63500. BIO* bio = NULL;
  63501. int sz = 7;
  63502. char msg[] = "TLS 1.3 for the world";
  63503. char out[60];
  63504. char expected[] = "TLS 1.3 for the world : sz = 7";
  63505. XMEMSET(out, 0, sizeof(out));
  63506. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  63507. ExpectIntEQ(BIO_printf(bio, "%s : sz = %d", msg, sz), 30);
  63508. ExpectIntEQ(BIO_printf(NULL, ""), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  63509. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 30);
  63510. ExpectIntEQ(XSTRNCMP(out, expected, sizeof(expected)), 0);
  63511. BIO_free(bio);
  63512. #endif
  63513. return EXPECT_RESULT();
  63514. }
  63515. static int test_wolfSSL_BIO_f_md(void)
  63516. {
  63517. EXPECT_DECLS;
  63518. #if defined(OPENSSL_ALL) && !defined(NO_SHA256)
  63519. BIO* bio = NULL;
  63520. BIO* mem = NULL;
  63521. char msg[] = "message to hash";
  63522. char out[60];
  63523. EVP_MD_CTX* ctx = NULL;
  63524. const unsigned char testKey[] =
  63525. {
  63526. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  63527. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  63528. 0x0b, 0x0b, 0x0b, 0x0b
  63529. };
  63530. const char testData[] = "Hi There";
  63531. const unsigned char testResult[] =
  63532. {
  63533. 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
  63534. 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
  63535. 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
  63536. 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7
  63537. };
  63538. const unsigned char expectedHash[] =
  63539. {
  63540. 0x66, 0x49, 0x3C, 0xE8, 0x8A, 0x57, 0xB0, 0x60,
  63541. 0xDC, 0x55, 0x7D, 0xFC, 0x1F, 0xA5, 0xE5, 0x07,
  63542. 0x70, 0x5A, 0xF6, 0xD7, 0xC4, 0x1F, 0x1A, 0xE4,
  63543. 0x2D, 0xA6, 0xFD, 0xD1, 0x29, 0x7D, 0x60, 0x0D
  63544. };
  63545. const unsigned char emptyHash[] =
  63546. {
  63547. 0xE3, 0xB0, 0xC4, 0x42, 0x98, 0xFC, 0x1C, 0x14,
  63548. 0x9A, 0xFB, 0xF4, 0xC8, 0x99, 0x6F, 0xB9, 0x24,
  63549. 0x27, 0xAE, 0x41, 0xE4, 0x64, 0x9B, 0x93, 0x4C,
  63550. 0xA4, 0x95, 0x99, 0x1B, 0x78, 0x52, 0xB8, 0x55
  63551. };
  63552. unsigned char check[sizeof(testResult) + 1];
  63553. size_t checkSz = -1;
  63554. EVP_PKEY* key = NULL;
  63555. XMEMSET(out, 0, sizeof(out));
  63556. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  63557. ExpectNotNull(mem = BIO_new(BIO_s_mem()));
  63558. ExpectIntEQ(BIO_get_md_ctx(bio, &ctx), 1);
  63559. ExpectIntEQ(EVP_DigestInit(ctx, EVP_sha256()), 1);
  63560. /* should not be able to write/read yet since just digest wrapper and no
  63561. * data is passing through the bio */
  63562. ExpectIntEQ(BIO_write(bio, msg, 0), 0);
  63563. ExpectIntEQ(BIO_pending(bio), 0);
  63564. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 0);
  63565. ExpectIntEQ(BIO_gets(bio, out, 3), 0);
  63566. ExpectIntEQ(BIO_gets(bio, out, sizeof(out)), 32);
  63567. ExpectIntEQ(XMEMCMP(emptyHash, out, 32), 0);
  63568. BIO_reset(bio);
  63569. /* append BIO mem to bio in order to read/write */
  63570. ExpectNotNull(bio = BIO_push(bio, mem));
  63571. XMEMSET(out, 0, sizeof(out));
  63572. ExpectIntEQ(BIO_write(mem, msg, sizeof(msg)), 16);
  63573. ExpectIntEQ(BIO_pending(bio), 16);
  63574. /* this just reads the message and does not hash it (gets calls final) */
  63575. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 16);
  63576. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  63577. /* create a message digest using BIO */
  63578. XMEMSET(out, 0, sizeof(out));
  63579. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), 16);
  63580. ExpectIntEQ(BIO_pending(mem), 16);
  63581. ExpectIntEQ(BIO_pending(bio), 16);
  63582. ExpectIntEQ(BIO_gets(bio, out, sizeof(out)), 32);
  63583. ExpectIntEQ(XMEMCMP(expectedHash, out, 32), 0);
  63584. BIO_free(bio);
  63585. bio = NULL;
  63586. BIO_free(mem);
  63587. mem = NULL;
  63588. /* test with HMAC */
  63589. XMEMSET(out, 0, sizeof(out));
  63590. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  63591. ExpectNotNull(mem = BIO_new(BIO_s_mem()));
  63592. BIO_get_md_ctx(bio, &ctx);
  63593. ExpectNotNull(key = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, testKey,
  63594. (int)sizeof(testKey)));
  63595. EVP_DigestSignInit(ctx, NULL, EVP_sha256(), NULL, key);
  63596. ExpectNotNull(bio = BIO_push(bio, mem));
  63597. BIO_write(bio, testData, (int)strlen(testData));
  63598. ExpectIntEQ(EVP_DigestSignFinal(ctx, NULL, &checkSz), 1);
  63599. ExpectIntEQ(EVP_DigestSignFinal(ctx, check, &checkSz), 1);
  63600. ExpectIntEQ(XMEMCMP(check, testResult, sizeof(testResult)), 0);
  63601. EVP_PKEY_free(key);
  63602. BIO_free(bio);
  63603. BIO_free(mem);
  63604. #endif
  63605. return EXPECT_RESULT();
  63606. }
  63607. static int test_wolfSSL_BIO_up_ref(void)
  63608. {
  63609. EXPECT_DECLS;
  63610. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)
  63611. BIO* bio = NULL;
  63612. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  63613. ExpectIntEQ(BIO_up_ref(NULL), 0);
  63614. ExpectIntEQ(BIO_up_ref(bio), 1);
  63615. BIO_free(bio);
  63616. ExpectIntEQ(BIO_up_ref(bio), 1);
  63617. BIO_free(bio);
  63618. BIO_free(bio);
  63619. #endif
  63620. return EXPECT_RESULT();
  63621. }
  63622. static int test_wolfSSL_BIO_reset(void)
  63623. {
  63624. EXPECT_DECLS;
  63625. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)
  63626. BIO* bio = NULL;
  63627. byte buf[16];
  63628. ExpectNotNull(bio = BIO_new_mem_buf("secure your data",
  63629. (word32)XSTRLEN("secure your data")));
  63630. ExpectIntEQ(BIO_read(bio, buf, 6), 6);
  63631. ExpectIntEQ(XMEMCMP(buf, "secure", 6), 0);
  63632. XMEMSET(buf, 0, 16);
  63633. ExpectIntEQ(BIO_read(bio, buf, 16), 10);
  63634. ExpectIntEQ(XMEMCMP(buf, " your data", 10), 0);
  63635. /* You cannot write to MEM BIO with read-only mode. */
  63636. ExpectIntEQ(BIO_write(bio, "WriteToReadonly", 15), 0);
  63637. ExpectIntEQ(BIO_read(bio, buf, 16), -1);
  63638. XMEMSET(buf, 0, 16);
  63639. ExpectIntEQ(BIO_reset(bio), 1);
  63640. ExpectIntEQ(BIO_read(bio, buf, 16), 16);
  63641. ExpectIntEQ(XMEMCMP(buf, "secure your data", 16), 0);
  63642. BIO_free(bio);
  63643. #endif
  63644. return EXPECT_RESULT();
  63645. }
  63646. #endif /* !NO_BIO */
  63647. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  63648. /* test that the callback arg is correct */
  63649. static int certCbArg = 0;
  63650. static int certCb(WOLFSSL* ssl, void* arg)
  63651. {
  63652. if (ssl == NULL || arg != &certCbArg)
  63653. return 0;
  63654. if (wolfSSL_is_server(ssl)) {
  63655. if (wolfSSL_use_certificate_file(ssl, svrCertFile,
  63656. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  63657. return 0;
  63658. if (wolfSSL_use_PrivateKey_file(ssl, svrKeyFile,
  63659. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  63660. return 0;
  63661. }
  63662. else {
  63663. if (wolfSSL_use_certificate_file(ssl, cliCertFile,
  63664. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  63665. return 0;
  63666. if (wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  63667. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  63668. return 0;
  63669. }
  63670. return 1;
  63671. }
  63672. static int certSetupCb(WOLFSSL_CTX* ctx)
  63673. {
  63674. SSL_CTX_set_cert_cb(ctx, certCb, &certCbArg);
  63675. return TEST_SUCCESS;
  63676. }
  63677. /**
  63678. * This is only done because test_wolfSSL_client_server_nofail_memio has no way
  63679. * to stop certificate and key loading
  63680. */
  63681. static int certClearCb(WOLFSSL* ssl)
  63682. {
  63683. /* Clear the loaded certs to force the callbacks to set them up */
  63684. SSL_certs_clear(ssl);
  63685. return TEST_SUCCESS;
  63686. }
  63687. #endif
  63688. static int test_wolfSSL_cert_cb(void)
  63689. {
  63690. EXPECT_DECLS;
  63691. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  63692. test_ssl_cbf func_cb_client;
  63693. test_ssl_cbf func_cb_server;
  63694. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  63695. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  63696. func_cb_client.ctx_ready = certSetupCb;
  63697. func_cb_client.ssl_ready = certClearCb;
  63698. func_cb_server.ctx_ready = certSetupCb;
  63699. func_cb_server.ssl_ready = certClearCb;
  63700. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  63701. &func_cb_server, NULL), TEST_SUCCESS);
  63702. #endif
  63703. return EXPECT_RESULT();
  63704. }
  63705. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  63706. static const char* test_wolfSSL_cert_cb_dyn_ciphers_client_cipher = NULL;
  63707. static const char* test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs = NULL;
  63708. static int test_wolfSSL_cert_cb_dyn_ciphers_client_ctx_ready(WOLFSSL_CTX* ctx)
  63709. {
  63710. EXPECT_DECLS;
  63711. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx,
  63712. test_wolfSSL_cert_cb_dyn_ciphers_client_cipher), WOLFSSL_SUCCESS);
  63713. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  63714. test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs), WOLFSSL_SUCCESS);
  63715. return EXPECT_RESULT();
  63716. }
  63717. static int test_wolfSSL_cert_cb_dyn_ciphers_certCB(WOLFSSL* ssl, void* arg)
  63718. {
  63719. const byte* suites = NULL;
  63720. word16 suiteSz = 0;
  63721. const byte* hashSigAlgo = NULL;
  63722. word16 hashSigAlgoSz = 0;
  63723. word16 idx = 0;
  63724. int haveRSA = 0;
  63725. int haveECC = 0;
  63726. (void)arg;
  63727. if (wolfSSL_get_client_suites_sigalgs(ssl, &suites, &suiteSz, &hashSigAlgo,
  63728. &hashSigAlgoSz) != WOLFSSL_SUCCESS)
  63729. return 0;
  63730. if (suites == NULL || suiteSz == 0 || hashSigAlgo == NULL ||
  63731. hashSigAlgoSz == 0)
  63732. return 0;
  63733. for (idx = 0; idx < suiteSz; idx += 2) {
  63734. WOLFSSL_CIPHERSUITE_INFO info =
  63735. wolfSSL_get_ciphersuite_info(suites[idx], suites[idx+1]);
  63736. if (info.rsaAuth)
  63737. haveRSA = 1;
  63738. else if (info.eccAuth)
  63739. haveECC = 1;
  63740. }
  63741. if (hashSigAlgoSz > 0) {
  63742. /* sigalgs extension takes precedence over ciphersuites */
  63743. haveRSA = 0;
  63744. haveECC = 0;
  63745. }
  63746. for (idx = 0; idx < hashSigAlgoSz; idx += 2) {
  63747. int hashAlgo = 0;
  63748. int sigAlgo = 0;
  63749. if (wolfSSL_get_sigalg_info(hashSigAlgo[idx+0], hashSigAlgo[idx+1],
  63750. &hashAlgo, &sigAlgo) != 0)
  63751. return 0;
  63752. if (sigAlgo == RSAk || sigAlgo == RSAPSSk)
  63753. haveRSA = 1;
  63754. else if (sigAlgo == ECDSAk)
  63755. haveECC = 1;
  63756. }
  63757. if (haveRSA) {
  63758. if (wolfSSL_use_certificate_file(ssl, svrCertFile, WOLFSSL_FILETYPE_PEM)
  63759. != WOLFSSL_SUCCESS)
  63760. return 0;
  63761. if (wolfSSL_use_PrivateKey_file(ssl, svrKeyFile, WOLFSSL_FILETYPE_PEM)
  63762. != WOLFSSL_SUCCESS)
  63763. return 0;
  63764. }
  63765. else if (haveECC) {
  63766. if (wolfSSL_use_certificate_file(ssl, eccCertFile, WOLFSSL_FILETYPE_PEM)
  63767. != WOLFSSL_SUCCESS)
  63768. return 0;
  63769. if (wolfSSL_use_PrivateKey_file(ssl, eccKeyFile, WOLFSSL_FILETYPE_PEM)
  63770. != WOLFSSL_SUCCESS)
  63771. return 0;
  63772. }
  63773. return 1;
  63774. }
  63775. static int test_wolfSSL_cert_cb_dyn_ciphers_server_ctx_ready(WOLFSSL_CTX* ctx)
  63776. {
  63777. SSL_CTX_set_cert_cb(ctx, test_wolfSSL_cert_cb_dyn_ciphers_certCB, NULL);
  63778. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_NONE, NULL);
  63779. return TEST_SUCCESS;
  63780. }
  63781. #endif
  63782. /* Testing dynamic ciphers offered by client */
  63783. static int test_wolfSSL_cert_cb_dyn_ciphers(void)
  63784. {
  63785. EXPECT_DECLS;
  63786. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  63787. test_ssl_cbf func_cb_client;
  63788. test_ssl_cbf func_cb_server;
  63789. struct {
  63790. method_provider client_meth;
  63791. const char* client_ciphers;
  63792. const char* client_sigalgs;
  63793. const char* client_ca;
  63794. method_provider server_meth;
  63795. } test_params[] = {
  63796. #if !defined(NO_SHA256) && defined(HAVE_AESGCM)
  63797. #ifdef WOLFSSL_TLS13
  63798. #if !defined(NO_RSA) && defined(WC_RSA_PSS)
  63799. {wolfTLSv1_3_client_method,
  63800. "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256",
  63801. "RSA-PSS+SHA256", caCertFile, wolfTLSv1_3_server_method},
  63802. #endif
  63803. #ifdef HAVE_ECC
  63804. {wolfTLSv1_3_client_method,
  63805. "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256",
  63806. "ECDSA+SHA256", caEccCertFile, wolfTLSv1_3_server_method},
  63807. #endif
  63808. #endif
  63809. #ifndef WOLFSSL_NO_TLS12
  63810. #if !defined(NO_RSA) && defined(WC_RSA_PSS) && !defined(NO_DH)
  63811. {wolfTLSv1_2_client_method,
  63812. "DHE-RSA-AES128-GCM-SHA256",
  63813. "RSA-PSS+SHA256", caCertFile, wolfTLSv1_2_server_method},
  63814. #endif
  63815. #ifdef HAVE_ECC
  63816. {wolfTLSv1_2_client_method,
  63817. "ECDHE-ECDSA-AES128-GCM-SHA256",
  63818. "ECDSA+SHA256", caEccCertFile, wolfTLSv1_2_server_method},
  63819. #endif
  63820. #endif
  63821. #endif
  63822. };
  63823. size_t i;
  63824. size_t testCount = sizeof(test_params)/sizeof(*test_params);
  63825. if (testCount > 0) {
  63826. for (i = 0; i < testCount; i++) {
  63827. printf("\tTesting %s ciphers with %s sigalgs\n",
  63828. test_params[i].client_ciphers,
  63829. test_params[i].client_sigalgs);
  63830. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  63831. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  63832. test_wolfSSL_cert_cb_dyn_ciphers_client_cipher =
  63833. test_params[i].client_ciphers;
  63834. test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs =
  63835. test_params[i].client_sigalgs;
  63836. func_cb_client.method = test_params[i].client_meth;
  63837. func_cb_client.caPemFile = test_params[i].client_ca;
  63838. func_cb_client.ctx_ready =
  63839. test_wolfSSL_cert_cb_dyn_ciphers_client_ctx_ready;
  63840. func_cb_server.ctx_ready =
  63841. test_wolfSSL_cert_cb_dyn_ciphers_server_ctx_ready;
  63842. func_cb_server.ssl_ready = certClearCb; /* Reuse from prev test */
  63843. func_cb_server.method = test_params[i].server_meth;
  63844. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  63845. &func_cb_server, NULL), TEST_SUCCESS);
  63846. }
  63847. }
  63848. #endif
  63849. return EXPECT_RESULT();
  63850. }
  63851. static int test_wolfSSL_ciphersuite_auth(void)
  63852. {
  63853. EXPECT_DECLS;
  63854. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EXTRA)
  63855. WOLFSSL_CIPHERSUITE_INFO info;
  63856. (void)info;
  63857. #ifndef WOLFSSL_NO_TLS12
  63858. #ifdef HAVE_CHACHA
  63859. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  63860. TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256);
  63861. ExpectIntEQ(info.rsaAuth, 1);
  63862. ExpectIntEQ(info.eccAuth, 0);
  63863. ExpectIntEQ(info.eccStatic, 0);
  63864. ExpectIntEQ(info.psk, 0);
  63865. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  63866. TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256);
  63867. ExpectIntEQ(info.rsaAuth, 0);
  63868. ExpectIntEQ(info.eccAuth, 1);
  63869. ExpectIntEQ(info.eccStatic, 0);
  63870. ExpectIntEQ(info.psk, 0);
  63871. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  63872. TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256);
  63873. ExpectIntEQ(info.rsaAuth, 0);
  63874. ExpectIntEQ(info.eccAuth, 0);
  63875. ExpectIntEQ(info.eccStatic, 0);
  63876. ExpectIntEQ(info.psk, 1);
  63877. #endif
  63878. #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
  63879. #ifndef NO_RSA
  63880. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  63881. TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA);
  63882. ExpectIntEQ(info.rsaAuth, 1);
  63883. ExpectIntEQ(info.eccAuth, 0);
  63884. ExpectIntEQ(info.eccStatic, 0);
  63885. ExpectIntEQ(info.psk, 0);
  63886. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  63887. TLS_ECDH_RSA_WITH_AES_128_CBC_SHA);
  63888. ExpectIntEQ(info.rsaAuth, 1);
  63889. ExpectIntEQ(info.eccAuth, 0);
  63890. ExpectIntEQ(info.eccStatic, 1);
  63891. ExpectIntEQ(info.psk, 0);
  63892. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  63893. TLS_ECDH_RSA_WITH_AES_256_CBC_SHA);
  63894. ExpectIntEQ(info.rsaAuth, 1);
  63895. ExpectIntEQ(info.eccAuth, 0);
  63896. ExpectIntEQ(info.eccStatic, 1);
  63897. ExpectIntEQ(info.psk, 0);
  63898. #endif
  63899. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  63900. TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA);
  63901. ExpectIntEQ(info.rsaAuth, 0);
  63902. ExpectIntEQ(info.eccAuth, 1);
  63903. ExpectIntEQ(info.eccStatic, 0);
  63904. ExpectIntEQ(info.psk, 0);
  63905. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  63906. TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA);
  63907. ExpectIntEQ(info.rsaAuth, 0);
  63908. ExpectIntEQ(info.eccAuth, 1);
  63909. ExpectIntEQ(info.eccStatic, 1);
  63910. ExpectIntEQ(info.psk, 0);
  63911. info = wolfSSL_get_ciphersuite_info(ECDHE_PSK_BYTE,
  63912. TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256);
  63913. ExpectIntEQ(info.rsaAuth, 0);
  63914. ExpectIntEQ(info.eccAuth, 0);
  63915. ExpectIntEQ(info.eccStatic, 0);
  63916. ExpectIntEQ(info.psk, 1);
  63917. #endif
  63918. #endif
  63919. #ifdef WOLFSSL_TLS13
  63920. info = wolfSSL_get_ciphersuite_info(TLS13_BYTE,
  63921. TLS_AES_128_GCM_SHA256);
  63922. ExpectIntEQ(info.rsaAuth, 0);
  63923. ExpectIntEQ(info.eccAuth, 0);
  63924. ExpectIntEQ(info.eccStatic, 0);
  63925. ExpectIntEQ(info.psk, 0);
  63926. #endif
  63927. #endif
  63928. return EXPECT_RESULT();
  63929. }
  63930. static int test_wolfSSL_sigalg_info(void)
  63931. {
  63932. EXPECT_DECLS;
  63933. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EXTRA)
  63934. byte hashSigAlgo[WOLFSSL_MAX_SIGALGO];
  63935. word16 len = 0;
  63936. word16 idx = 0;
  63937. int allSigAlgs = SIG_ECDSA | SIG_RSA | SIG_SM2 | SIG_FALCON | SIG_DILITHIUM;
  63938. InitSuitesHashSigAlgo(hashSigAlgo, allSigAlgs, 1, 0xFFFFFFFF, &len);
  63939. for (idx = 0; idx < len; idx += 2) {
  63940. int hashAlgo = 0;
  63941. int sigAlgo = 0;
  63942. ExpectIntEQ(wolfSSL_get_sigalg_info(hashSigAlgo[idx+0],
  63943. hashSigAlgo[idx+1], &hashAlgo, &sigAlgo), 0);
  63944. ExpectIntNE(hashAlgo, 0);
  63945. ExpectIntNE(sigAlgo, 0);
  63946. }
  63947. InitSuitesHashSigAlgo(hashSigAlgo, allSigAlgs | SIG_ANON, 1,
  63948. 0xFFFFFFFF, &len);
  63949. for (idx = 0; idx < len; idx += 2) {
  63950. int hashAlgo = 0;
  63951. int sigAlgo = 0;
  63952. ExpectIntEQ(wolfSSL_get_sigalg_info(hashSigAlgo[idx+0],
  63953. hashSigAlgo[idx+1], &hashAlgo, &sigAlgo), 0);
  63954. ExpectIntNE(hashAlgo, 0);
  63955. }
  63956. #endif
  63957. return EXPECT_RESULT();
  63958. }
  63959. static int test_wolfSSL_SESSION(void)
  63960. {
  63961. EXPECT_DECLS;
  63962. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  63963. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  63964. !defined(NO_SESSION_CACHE)
  63965. WOLFSSL* ssl = NULL;
  63966. WOLFSSL_CTX* ctx = NULL;
  63967. WOLFSSL_SESSION* sess = NULL;
  63968. WOLFSSL_SESSION* sess_copy = NULL;
  63969. #ifdef OPENSSL_EXTRA
  63970. #ifdef HAVE_EXT_CACHE
  63971. unsigned char* sessDer = NULL;
  63972. unsigned char* ptr = NULL;
  63973. int sz = 0;
  63974. #endif
  63975. const unsigned char context[] = "user app context";
  63976. unsigned int contextSz = (unsigned int)sizeof(context);
  63977. #endif
  63978. int ret = 0, err = 0;
  63979. SOCKET_T sockfd;
  63980. tcp_ready ready;
  63981. func_args server_args;
  63982. THREAD_TYPE serverThread;
  63983. char msg[80];
  63984. const char* sendGET = "GET";
  63985. /* TLS v1.3 requires session tickets */
  63986. /* CHACHA and POLY1305 required for myTicketEncCb */
  63987. #if !defined(WOLFSSL_NO_TLS12) && (!defined(WOLFSSL_TLS13) || \
  63988. !(defined(HAVE_SESSION_TICKET) && ((defined(HAVE_CHACHA) && \
  63989. defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))))
  63990. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  63991. #else
  63992. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  63993. #endif
  63994. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  63995. WOLFSSL_FILETYPE_PEM));
  63996. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  63997. WOLFSSL_FILETYPE_PEM));
  63998. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0),
  63999. WOLFSSL_SUCCESS);
  64000. #ifdef WOLFSSL_ENCRYPTED_KEYS
  64001. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  64002. #endif
  64003. #ifdef HAVE_SESSION_TICKET
  64004. /* Use session tickets, for ticket tests below */
  64005. ExpectIntEQ(wolfSSL_CTX_UseSessionTicket(ctx), WOLFSSL_SUCCESS);
  64006. #endif
  64007. XMEMSET(&server_args, 0, sizeof(func_args));
  64008. #ifdef WOLFSSL_TIRTOS
  64009. fdOpenSession(Task_self());
  64010. #endif
  64011. StartTCP();
  64012. InitTcpReady(&ready);
  64013. #if defined(USE_WINDOWS_API)
  64014. /* use RNG to get random port if using windows */
  64015. ready.port = GetRandomPort();
  64016. #endif
  64017. server_args.signal = &ready;
  64018. start_thread(test_server_nofail, &server_args, &serverThread);
  64019. wait_tcp_ready(&server_args);
  64020. /* client connection */
  64021. ExpectNotNull(ssl = wolfSSL_new(ctx));
  64022. tcp_connect(&sockfd, wolfSSLIP, ready.port, 0, 0, ssl);
  64023. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  64024. #ifdef WOLFSSL_ASYNC_CRYPT
  64025. err = 0; /* Reset error */
  64026. #endif
  64027. do {
  64028. #ifdef WOLFSSL_ASYNC_CRYPT
  64029. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  64030. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  64031. if (ret < 0) { break; } else if (ret == 0) { continue; }
  64032. }
  64033. #endif
  64034. ret = wolfSSL_connect(ssl);
  64035. err = wolfSSL_get_error(ssl, 0);
  64036. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  64037. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  64038. #ifdef WOLFSSL_ASYNC_CRYPT
  64039. err = 0; /* Reset error */
  64040. #endif
  64041. do {
  64042. #ifdef WOLFSSL_ASYNC_CRYPT
  64043. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  64044. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  64045. if (ret < 0) { break; } else if (ret == 0) { continue; }
  64046. }
  64047. #endif
  64048. ret = wolfSSL_write(ssl, sendGET, (int)XSTRLEN(sendGET));
  64049. err = wolfSSL_get_error(ssl, 0);
  64050. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  64051. ExpectIntEQ(ret, (int)XSTRLEN(sendGET));
  64052. #ifdef WOLFSSL_ASYNC_CRYPT
  64053. err = 0; /* Reset error */
  64054. #endif
  64055. do {
  64056. #ifdef WOLFSSL_ASYNC_CRYPT
  64057. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  64058. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  64059. if (ret < 0) { break; } else if (ret == 0) { continue; }
  64060. }
  64061. #endif
  64062. ret = wolfSSL_read(ssl, msg, sizeof(msg));
  64063. err = wolfSSL_get_error(ssl, 0);
  64064. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  64065. ExpectIntEQ(ret, 23);
  64066. ExpectPtrNE((sess = wolfSSL_get1_session(ssl)), NULL); /* ref count 1 */
  64067. ExpectPtrNE((sess_copy = wolfSSL_get1_session(ssl)), NULL); /* ref count 2 */
  64068. ExpectIntEQ(wolfSSL_SessionIsSetup(sess), 1);
  64069. #ifdef HAVE_EXT_CACHE
  64070. ExpectPtrEq(sess, sess_copy); /* they should be the same pointer but without
  64071. * HAVE_EXT_CACHE we get new objects each time */
  64072. #endif
  64073. wolfSSL_SESSION_free(sess_copy); sess_copy = NULL;
  64074. wolfSSL_SESSION_free(sess); sess = NULL; /* free session ref */
  64075. sess = wolfSSL_get_session(ssl);
  64076. #ifdef OPENSSL_EXTRA
  64077. ExpectIntEQ(SSL_SESSION_is_resumable(NULL), 0);
  64078. ExpectIntEQ(SSL_SESSION_is_resumable(sess), 1);
  64079. ExpectIntEQ(wolfSSL_SESSION_has_ticket(NULL), 0);
  64080. ExpectIntEQ(wolfSSL_SESSION_get_ticket_lifetime_hint(NULL), 0);
  64081. #ifdef HAVE_SESSION_TICKET
  64082. ExpectIntEQ(wolfSSL_SESSION_has_ticket(sess), 1);
  64083. ExpectIntEQ(wolfSSL_SESSION_get_ticket_lifetime_hint(sess),
  64084. SESSION_TICKET_HINT_DEFAULT);
  64085. #else
  64086. ExpectIntEQ(wolfSSL_SESSION_has_ticket(sess), 0);
  64087. #endif
  64088. #else
  64089. (void)sess;
  64090. #endif /* OPENSSL_EXTRA */
  64091. /* Retain copy of the session for later testing */
  64092. ExpectNotNull(sess = wolfSSL_get1_session(ssl));
  64093. wolfSSL_shutdown(ssl);
  64094. wolfSSL_free(ssl); ssl = NULL;
  64095. CloseSocket(sockfd);
  64096. join_thread(serverThread);
  64097. FreeTcpReady(&ready);
  64098. #ifdef WOLFSSL_TIRTOS
  64099. fdOpenSession(Task_self());
  64100. #endif
  64101. #if defined(SESSION_CERTS) && defined(OPENSSL_EXTRA)
  64102. {
  64103. X509 *x509 = NULL;
  64104. char buf[30];
  64105. int bufSz = 0;
  64106. ExpectNotNull(x509 = SSL_SESSION_get0_peer(sess));
  64107. ExpectIntGT((bufSz = X509_NAME_get_text_by_NID(
  64108. X509_get_subject_name(x509), NID_organizationalUnitName, buf,
  64109. sizeof(buf))), 0);
  64110. ExpectIntNE((bufSz == 7 || bufSz == 16), 0); /* should be one of these*/
  64111. if (bufSz == 7) {
  64112. ExpectIntEQ(XMEMCMP(buf, "Support", bufSz), 0);
  64113. }
  64114. if (bufSz == 16) {
  64115. ExpectIntEQ(XMEMCMP(buf, "Programming-2048", bufSz), 0);
  64116. }
  64117. }
  64118. #endif
  64119. #ifdef HAVE_EXT_CACHE
  64120. ExpectNotNull(sess_copy = wolfSSL_SESSION_dup(sess));
  64121. wolfSSL_SESSION_free(sess_copy); sess_copy = NULL;
  64122. sess_copy = NULL;
  64123. #endif
  64124. #if defined(OPENSSL_EXTRA) && defined(HAVE_EXT_CACHE)
  64125. /* get session from DER and update the timeout */
  64126. ExpectIntEQ(wolfSSL_i2d_SSL_SESSION(NULL, &sessDer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  64127. ExpectIntGT((sz = wolfSSL_i2d_SSL_SESSION(sess, &sessDer)), 0);
  64128. wolfSSL_SESSION_free(sess); sess = NULL;
  64129. sess = NULL;
  64130. ptr = sessDer;
  64131. ExpectNull(sess = wolfSSL_d2i_SSL_SESSION(NULL, NULL, sz));
  64132. ExpectNotNull(sess = wolfSSL_d2i_SSL_SESSION(NULL,
  64133. (const unsigned char**)&ptr, sz));
  64134. XFREE(sessDer, NULL, DYNAMIC_TYPE_OPENSSL);
  64135. sessDer = NULL;
  64136. ExpectIntGT(wolfSSL_SESSION_get_time(sess), 0);
  64137. ExpectIntEQ(wolfSSL_SSL_SESSION_set_timeout(sess, 500), SSL_SUCCESS);
  64138. #endif
  64139. /* successful set session test */
  64140. ExpectNotNull(ssl = wolfSSL_new(ctx));
  64141. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WOLFSSL_SUCCESS);
  64142. #ifdef HAVE_SESSION_TICKET
  64143. /* Test set/get session ticket */
  64144. {
  64145. const char* ticket = "This is a session ticket";
  64146. char buf[64] = {0};
  64147. word32 bufSz = (word32)sizeof(buf);
  64148. ExpectIntEQ(SSL_SUCCESS,
  64149. wolfSSL_set_SessionTicket(ssl, (byte *)ticket,
  64150. (word32)XSTRLEN(ticket)));
  64151. ExpectIntEQ(SSL_SUCCESS,
  64152. wolfSSL_get_SessionTicket(ssl, (byte *)buf, &bufSz));
  64153. ExpectStrEQ(ticket, buf);
  64154. }
  64155. #endif
  64156. #ifdef OPENSSL_EXTRA
  64157. /* session timeout case */
  64158. /* make the session to be expired */
  64159. ExpectIntEQ(SSL_SESSION_set_timeout(sess,1), SSL_SUCCESS);
  64160. XSLEEP_MS(1200);
  64161. /* SSL_set_session should reject specified session but return success
  64162. * if WOLFSSL_ERROR_CODE_OPENSSL macro is defined for OpenSSL compatibility.
  64163. */
  64164. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  64165. ExpectIntEQ(wolfSSL_set_session(ssl,sess), SSL_SUCCESS);
  64166. #else
  64167. ExpectIntEQ(wolfSSL_set_session(ssl,sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64168. #endif
  64169. ExpectIntEQ(wolfSSL_SSL_SESSION_set_timeout(sess, 500), SSL_SUCCESS);
  64170. #ifdef WOLFSSL_SESSION_ID_CTX
  64171. /* fail case with miss match session context IDs (use compatibility API) */
  64172. ExpectIntEQ(SSL_set_session_id_context(ssl, context, contextSz),
  64173. SSL_SUCCESS);
  64174. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64175. wolfSSL_free(ssl); ssl = NULL;
  64176. ExpectIntEQ(SSL_CTX_set_session_id_context(NULL, context, contextSz),
  64177. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64178. ExpectIntEQ(SSL_CTX_set_session_id_context(ctx, context, contextSz),
  64179. SSL_SUCCESS);
  64180. ExpectNotNull(ssl = wolfSSL_new(ctx));
  64181. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64182. #endif
  64183. #endif /* OPENSSL_EXTRA */
  64184. wolfSSL_free(ssl);
  64185. wolfSSL_SESSION_free(sess);
  64186. wolfSSL_CTX_free(ctx);
  64187. #endif
  64188. return EXPECT_RESULT();
  64189. }
  64190. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  64191. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  64192. !defined(NO_SESSION_CACHE) && defined(OPENSSL_EXTRA) && \
  64193. !defined(WOLFSSL_NO_TLS12)
  64194. static WOLFSSL_SESSION* test_wolfSSL_SESSION_expire_sess = NULL;
  64195. static void test_wolfSSL_SESSION_expire_downgrade_ctx_ready(WOLFSSL_CTX* ctx)
  64196. {
  64197. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  64198. /* returns previous timeout value */
  64199. AssertIntEQ(wolfSSL_CTX_set_timeout(ctx, 1), 500);
  64200. #else
  64201. AssertIntEQ(wolfSSL_CTX_set_timeout(ctx, 1), WOLFSSL_SUCCESS);
  64202. #endif
  64203. }
  64204. /* set the session to timeout in a second */
  64205. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready(WOLFSSL* ssl)
  64206. {
  64207. AssertIntEQ(wolfSSL_set_timeout(ssl, 2), 1);
  64208. }
  64209. /* store the client side session from the first successful connection */
  64210. static void test_wolfSSL_SESSION_expire_downgrade_ssl_result(WOLFSSL* ssl)
  64211. {
  64212. AssertPtrNE((test_wolfSSL_SESSION_expire_sess = wolfSSL_get1_session(ssl)),
  64213. NULL); /* ref count 1 */
  64214. }
  64215. /* wait till session is expired then set it in the WOLFSSL struct for use */
  64216. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready_wait(WOLFSSL* ssl)
  64217. {
  64218. AssertIntEQ(wolfSSL_set_timeout(ssl, 1), 1);
  64219. AssertIntEQ(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  64220. WOLFSSL_SUCCESS);
  64221. XSLEEP_MS(2000); /* wait 2 seconds for session to expire */
  64222. }
  64223. /* set expired session in the WOLFSSL struct for use */
  64224. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready_set(WOLFSSL* ssl)
  64225. {
  64226. XSLEEP_MS(1200); /* wait a second for session to expire */
  64227. /* set the expired session, call to set session fails but continuing on
  64228. after failure should be handled here */
  64229. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL)
  64230. AssertIntEQ(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  64231. WOLFSSL_SUCCESS);
  64232. #else
  64233. AssertIntNE(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  64234. WOLFSSL_SUCCESS);
  64235. #endif
  64236. }
  64237. /* check that the expired session was not reused */
  64238. static void test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse(WOLFSSL* ssl)
  64239. {
  64240. /* since the session has expired it should not have been reused */
  64241. AssertIntEQ(wolfSSL_session_reused(ssl), 0);
  64242. }
  64243. #endif
  64244. static int test_wolfSSL_SESSION_expire_downgrade(void)
  64245. {
  64246. EXPECT_DECLS;
  64247. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  64248. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  64249. !defined(NO_SESSION_CACHE) && defined(OPENSSL_EXTRA) && \
  64250. !defined(WOLFSSL_NO_TLS12)
  64251. WOLFSSL_CTX* ctx = NULL;
  64252. callback_functions server_cbf, client_cbf;
  64253. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  64254. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  64255. /* force server side to use TLS 1.2 */
  64256. server_cbf.ctx = ctx;
  64257. server_cbf.method = wolfTLSv1_2_server_method;
  64258. client_cbf.method = wolfSSLv23_client_method;
  64259. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  64260. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready;
  64261. client_cbf.on_result = test_wolfSSL_SESSION_expire_downgrade_ssl_result;
  64262. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  64263. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  64264. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  64265. /* set the previously created session and wait till expired */
  64266. server_cbf.ctx = ctx;
  64267. client_cbf.method = wolfSSLv23_client_method;
  64268. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  64269. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready_wait;
  64270. client_cbf.on_result =
  64271. test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse;
  64272. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  64273. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  64274. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  64275. /* set the previously created expired session */
  64276. server_cbf.ctx = ctx;
  64277. client_cbf.method = wolfSSLv23_client_method;
  64278. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  64279. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready_set;
  64280. client_cbf.on_result =
  64281. test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse;
  64282. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  64283. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  64284. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  64285. wolfSSL_SESSION_free(test_wolfSSL_SESSION_expire_sess);
  64286. wolfSSL_CTX_free(ctx);
  64287. #endif
  64288. return EXPECT_RESULT();
  64289. }
  64290. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  64291. defined(HAVE_EX_DATA) && !defined(NO_SESSION_CACHE)
  64292. #ifdef WOLFSSL_ATOMIC_OPS
  64293. typedef wolfSSL_Atomic_Int SessRemCounter_t;
  64294. #else
  64295. typedef int SessRemCounter_t;
  64296. #endif
  64297. static SessRemCounter_t clientSessRemCountMalloc;
  64298. static SessRemCounter_t serverSessRemCountMalloc;
  64299. static SessRemCounter_t clientSessRemCountFree;
  64300. static SessRemCounter_t serverSessRemCountFree;
  64301. static WOLFSSL_CTX* serverSessCtx = NULL;
  64302. static WOLFSSL_SESSION* serverSess = NULL;
  64303. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  64304. !defined(NO_SESSION_CACHE_REF)
  64305. static WOLFSSL_CTX* clientSessCtx = NULL;
  64306. static WOLFSSL_SESSION* clientSess = NULL;
  64307. #endif
  64308. static int serverSessRemIdx = 3;
  64309. static int sessRemCtx_Server = WOLFSSL_SERVER_END;
  64310. static int sessRemCtx_Client = WOLFSSL_CLIENT_END;
  64311. static void SessRemCtxCb(WOLFSSL_CTX *ctx, WOLFSSL_SESSION *sess)
  64312. {
  64313. int* side;
  64314. (void)ctx;
  64315. side = (int*)SSL_SESSION_get_ex_data(sess, serverSessRemIdx);
  64316. if (side != NULL) {
  64317. if (*side == WOLFSSL_CLIENT_END)
  64318. (void)wolfSSL_Atomic_Int_FetchAdd(&clientSessRemCountFree, 1);
  64319. else
  64320. (void)wolfSSL_Atomic_Int_FetchAdd(&serverSessRemCountFree, 1);
  64321. SSL_SESSION_set_ex_data(sess, serverSessRemIdx, NULL);
  64322. }
  64323. }
  64324. static int SessRemCtxSetupCb(WOLFSSL_CTX* ctx)
  64325. {
  64326. SSL_CTX_sess_set_remove_cb(ctx, SessRemCtxCb);
  64327. #if defined(WOLFSSL_TLS13) && !defined(HAVE_SESSION_TICKET) && \
  64328. !defined(NO_SESSION_CACHE_REF)
  64329. {
  64330. EXPECT_DECLS;
  64331. /* Allow downgrade, set min version, and disable TLS 1.3.
  64332. * Do this because without NO_SESSION_CACHE_REF we will want to return a
  64333. * reference to the session cache. But with WOLFSSL_TLS13 and without
  64334. * HAVE_SESSION_TICKET we won't have a session ID to be able to place
  64335. * the session in the cache. In this case we need to downgrade to
  64336. * previous versions to just use the legacy session ID field. */
  64337. ExpectIntEQ(SSL_CTX_set_min_proto_version(ctx, SSL3_VERSION),
  64338. SSL_SUCCESS);
  64339. ExpectIntEQ(SSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION),
  64340. SSL_SUCCESS);
  64341. return EXPECT_RESULT();
  64342. }
  64343. #else
  64344. return TEST_SUCCESS;
  64345. #endif
  64346. }
  64347. static int SessRemSslSetupCb(WOLFSSL* ssl)
  64348. {
  64349. EXPECT_DECLS;
  64350. int* side;
  64351. if (SSL_is_server(ssl)) {
  64352. side = &sessRemCtx_Server;
  64353. (void)wolfSSL_Atomic_Int_FetchAdd(&serverSessRemCountMalloc, 1);
  64354. ExpectNotNull(serverSess = SSL_get1_session(ssl));
  64355. ExpectIntEQ(SSL_CTX_up_ref(serverSessCtx = SSL_get_SSL_CTX(ssl)),
  64356. SSL_SUCCESS);
  64357. }
  64358. else {
  64359. side = &sessRemCtx_Client;
  64360. (void)wolfSSL_Atomic_Int_FetchAdd(&clientSessRemCountMalloc, 1);
  64361. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  64362. !defined(NO_SESSION_CACHE_REF)
  64363. ExpectNotNull(clientSess = SSL_get1_session(ssl));
  64364. ExpectIntEQ(SSL_CTX_up_ref(clientSessCtx = SSL_get_SSL_CTX(ssl)),
  64365. SSL_SUCCESS);
  64366. #endif
  64367. }
  64368. ExpectIntEQ(SSL_SESSION_set_ex_data(SSL_get_session(ssl),
  64369. serverSessRemIdx, side), SSL_SUCCESS);
  64370. return EXPECT_RESULT();
  64371. }
  64372. #endif
  64373. static int test_wolfSSL_CTX_sess_set_remove_cb(void)
  64374. {
  64375. EXPECT_DECLS;
  64376. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  64377. defined(HAVE_EX_DATA) && !defined(NO_SESSION_CACHE)
  64378. /* Check that the remove callback gets called for external data in a
  64379. * session object */
  64380. test_ssl_cbf func_cb;
  64381. wolfSSL_Atomic_Int_Init(&clientSessRemCountMalloc, 0);
  64382. wolfSSL_Atomic_Int_Init(&serverSessRemCountMalloc, 0);
  64383. wolfSSL_Atomic_Int_Init(&clientSessRemCountFree, 0);
  64384. wolfSSL_Atomic_Int_Init(&serverSessRemCountFree, 0);
  64385. XMEMSET(&func_cb, 0, sizeof(func_cb));
  64386. func_cb.ctx_ready = SessRemCtxSetupCb;
  64387. func_cb.on_result = SessRemSslSetupCb;
  64388. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb, &func_cb,
  64389. NULL), TEST_SUCCESS);
  64390. /* Both should have been allocated */
  64391. ExpectIntEQ(clientSessRemCountMalloc, 1);
  64392. ExpectIntEQ(serverSessRemCountMalloc, 1);
  64393. /* This should not be called yet. Session wasn't evicted from cache yet. */
  64394. ExpectIntEQ(clientSessRemCountFree, 0);
  64395. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  64396. !defined(NO_SESSION_CACHE_REF)
  64397. /* Force a cache lookup */
  64398. ExpectNotNull(SSL_SESSION_get_ex_data(clientSess, serverSessRemIdx));
  64399. /* Force a cache update */
  64400. ExpectNotNull(SSL_SESSION_set_ex_data(clientSess, serverSessRemIdx - 1, 0));
  64401. /* This should set the timeout to 0 and call the remove callback from within
  64402. * the session cache. */
  64403. ExpectIntEQ(SSL_CTX_remove_session(clientSessCtx, clientSess), 0);
  64404. ExpectNull(SSL_SESSION_get_ex_data(clientSess, serverSessRemIdx));
  64405. ExpectIntEQ(clientSessRemCountFree, 1);
  64406. #endif
  64407. /* Server session is in the cache so ex_data isn't free'd with the SSL
  64408. * object */
  64409. ExpectIntEQ(serverSessRemCountFree, 0);
  64410. /* Force a cache lookup */
  64411. ExpectNotNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx));
  64412. /* Force a cache update */
  64413. ExpectNotNull(SSL_SESSION_set_ex_data(serverSess, serverSessRemIdx - 1, 0));
  64414. /* This should set the timeout to 0 and call the remove callback from within
  64415. * the session cache. */
  64416. ExpectIntEQ(SSL_CTX_remove_session(serverSessCtx, serverSess), 0);
  64417. ExpectNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx));
  64418. ExpectIntEQ(serverSessRemCountFree, 1);
  64419. /* Need to free the references that we kept */
  64420. SSL_CTX_free(serverSessCtx);
  64421. SSL_SESSION_free(serverSess);
  64422. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  64423. !defined(NO_SESSION_CACHE_REF)
  64424. SSL_CTX_free(clientSessCtx);
  64425. SSL_SESSION_free(clientSess);
  64426. #endif
  64427. #endif
  64428. return EXPECT_RESULT();
  64429. }
  64430. static int test_wolfSSL_ticket_keys(void)
  64431. {
  64432. EXPECT_DECLS;
  64433. #if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  64434. !defined(NO_WOLFSSL_SERVER)
  64435. WOLFSSL_CTX* ctx = NULL;
  64436. byte keys[WOLFSSL_TICKET_KEYS_SZ];
  64437. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  64438. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, NULL, 0),
  64439. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64440. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, NULL, 0),
  64441. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64442. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, keys, 0),
  64443. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64444. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, keys, 0),
  64445. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64446. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, NULL, sizeof(keys)),
  64447. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64448. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, NULL, sizeof(keys)),
  64449. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64450. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, keys, sizeof(keys)),
  64451. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64452. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, NULL, 0),
  64453. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64454. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, NULL, 0),
  64455. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64456. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, keys, 0),
  64457. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64458. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, keys, 0),
  64459. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64460. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, NULL, sizeof(keys)),
  64461. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64462. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, NULL, sizeof(keys)),
  64463. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64464. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, keys, sizeof(keys)),
  64465. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64466. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, keys, sizeof(keys)),
  64467. WOLFSSL_SUCCESS);
  64468. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, keys, sizeof(keys)),
  64469. WOLFSSL_SUCCESS);
  64470. wolfSSL_CTX_free(ctx);
  64471. #endif
  64472. return EXPECT_RESULT();
  64473. }
  64474. #ifndef NO_BIO
  64475. static int test_wolfSSL_d2i_PUBKEY(void)
  64476. {
  64477. EXPECT_DECLS;
  64478. #if defined(OPENSSL_EXTRA)
  64479. BIO* bio = NULL;
  64480. EVP_PKEY* pkey = NULL;
  64481. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  64482. ExpectNull(d2i_PUBKEY_bio(NULL, NULL));
  64483. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA)
  64484. /* RSA PUBKEY test */
  64485. ExpectIntGT(BIO_write(bio, client_keypub_der_2048,
  64486. sizeof_client_keypub_der_2048), 0);
  64487. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  64488. EVP_PKEY_free(pkey);
  64489. pkey = NULL;
  64490. #endif
  64491. #if defined(USE_CERT_BUFFERS_256) && defined(HAVE_ECC)
  64492. /* ECC PUBKEY test */
  64493. ExpectIntGT(BIO_write(bio, ecc_clikeypub_der_256,
  64494. sizeof_ecc_clikeypub_der_256), 0);
  64495. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  64496. EVP_PKEY_free(pkey);
  64497. pkey = NULL;
  64498. #endif
  64499. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DSA)
  64500. /* DSA PUBKEY test */
  64501. ExpectIntGT(BIO_write(bio, dsa_pub_key_der_2048,
  64502. sizeof_dsa_pub_key_der_2048), 0);
  64503. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  64504. EVP_PKEY_free(pkey);
  64505. pkey = NULL;
  64506. #endif
  64507. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DH) && \
  64508. defined(OPENSSL_EXTRA) && defined(WOLFSSL_DH_EXTRA)
  64509. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  64510. (HAVE_FIPS_VERSION > 2))
  64511. /* DH PUBKEY test */
  64512. ExpectIntGT(BIO_write(bio, dh_pub_key_der_2048,
  64513. sizeof_dh_pub_key_der_2048), 0);
  64514. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  64515. EVP_PKEY_free(pkey);
  64516. pkey = NULL;
  64517. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  64518. #endif /* USE_CERT_BUFFERS_2048 && !NO_DH && && OPENSSL_EXTRA */
  64519. BIO_free(bio);
  64520. (void)pkey;
  64521. #endif
  64522. return EXPECT_RESULT();
  64523. }
  64524. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  64525. static int test_wolfSSL_d2i_PrivateKeys_bio(void)
  64526. {
  64527. EXPECT_DECLS;
  64528. BIO* bio = NULL;
  64529. EVP_PKEY* pkey = NULL;
  64530. WOLFSSL_CTX* ctx = NULL;
  64531. #if defined(WOLFSSL_KEY_GEN)
  64532. unsigned char buff[4096];
  64533. unsigned char* bufPtr = buff;
  64534. #endif
  64535. /* test creating new EVP_PKEY with bad arg */
  64536. ExpectNull((pkey = d2i_PrivateKey_bio(NULL, NULL)));
  64537. /* test loading RSA key using BIO */
  64538. #if !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  64539. {
  64540. XFILE file = XBADFILE;
  64541. const char* fname = "./certs/server-key.der";
  64542. size_t sz = 0;
  64543. byte* buf = NULL;
  64544. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  64545. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  64546. ExpectTrue((sz = XFTELL(file)) != 0);
  64547. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  64548. ExpectNotNull(buf = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_FILE));
  64549. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  64550. if (file != XBADFILE) {
  64551. XFCLOSE(file);
  64552. }
  64553. /* Test using BIO new mem and loading DER private key */
  64554. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  64555. ExpectNotNull((pkey = d2i_PrivateKey_bio(bio, NULL)));
  64556. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  64557. BIO_free(bio);
  64558. bio = NULL;
  64559. EVP_PKEY_free(pkey);
  64560. pkey = NULL;
  64561. }
  64562. #endif
  64563. /* test loading ECC key using BIO */
  64564. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  64565. {
  64566. XFILE file = XBADFILE;
  64567. const char* fname = "./certs/ecc-key.der";
  64568. size_t sz = 0;
  64569. byte* buf = NULL;
  64570. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  64571. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  64572. ExpectTrue((sz = XFTELL(file)) != 0);
  64573. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  64574. ExpectNotNull(buf = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_FILE));
  64575. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  64576. if (file != XBADFILE)
  64577. XFCLOSE(file);
  64578. /* Test using BIO new mem and loading DER private key */
  64579. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  64580. ExpectNotNull((pkey = d2i_PrivateKey_bio(bio, NULL)));
  64581. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  64582. BIO_free(bio);
  64583. bio = NULL;
  64584. EVP_PKEY_free(pkey);
  64585. pkey = NULL;
  64586. }
  64587. #endif
  64588. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  64589. #ifndef NO_WOLFSSL_SERVER
  64590. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  64591. #else
  64592. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  64593. #endif
  64594. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  64595. {
  64596. RSA* rsa = NULL;
  64597. /* Tests bad parameters */
  64598. ExpectNull(d2i_RSAPrivateKey_bio(NULL, NULL));
  64599. /* RSA not set yet, expecting to fail*/
  64600. rsa = wolfSSL_RSA_new();
  64601. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64602. wolfSSL_RSA_free(rsa);
  64603. rsa = NULL;
  64604. #if defined(USE_CERT_BUFFERS_2048) && defined(WOLFSSL_KEY_GEN)
  64605. /* set RSA using bio*/
  64606. ExpectIntGT(BIO_write(bio, client_key_der_2048,
  64607. sizeof_client_key_der_2048), 0);
  64608. ExpectNotNull(d2i_RSAPrivateKey_bio(bio, &rsa));
  64609. ExpectNotNull(rsa);
  64610. /* Tests bad parameters */
  64611. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  64612. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  64613. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(NULL, rsa), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  64614. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), WOLFSSL_SUCCESS);
  64615. /* i2d RSAprivate key tests */
  64616. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  64617. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, NULL), 1192);
  64618. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr),
  64619. sizeof_client_key_der_2048);
  64620. bufPtr -= sizeof_client_key_der_2048;
  64621. ExpectIntEQ(XMEMCMP(bufPtr, client_key_der_2048,
  64622. sizeof_client_key_der_2048), 0);
  64623. bufPtr = NULL;
  64624. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr),
  64625. sizeof_client_key_der_2048);
  64626. ExpectNotNull(bufPtr);
  64627. ExpectIntEQ(XMEMCMP(bufPtr, client_key_der_2048,
  64628. sizeof_client_key_der_2048), 0);
  64629. XFREE(bufPtr, NULL, DYNAMIC_TYPE_OPENSSL);
  64630. RSA_free(rsa);
  64631. rsa = NULL;
  64632. ExpectIntGT(BIO_write(bio, client_key_der_2048,
  64633. sizeof_client_key_der_2048), 0);
  64634. ExpectNotNull(d2i_RSA_PUBKEY_bio(bio, &rsa));
  64635. (void)BIO_reset(bio);
  64636. RSA_free(rsa);
  64637. rsa = RSA_new();
  64638. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, NULL), 0);
  64639. #endif /* USE_CERT_BUFFERS_2048 WOLFSSL_KEY_GEN */
  64640. RSA_free(rsa);
  64641. }
  64642. #endif /* WOLFSSL_KEY_GEN && !NO_RSA */
  64643. SSL_CTX_free(ctx);
  64644. ctx = NULL;
  64645. BIO_free(bio);
  64646. bio = NULL;
  64647. return EXPECT_RESULT();
  64648. }
  64649. #endif /* OPENSSL_ALL || (WOLFSSL_ASIO && !NO_RSA) */
  64650. #endif /* !NO_BIO */
  64651. static int test_wolfSSL_sk_GENERAL_NAME(void)
  64652. {
  64653. EXPECT_DECLS;
  64654. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  64655. !defined(NO_RSA)
  64656. X509* x509 = NULL;
  64657. GENERAL_NAME* gn = NULL;
  64658. unsigned char buf[4096];
  64659. const unsigned char* bufPt = NULL;
  64660. int bytes = 0;
  64661. int i;
  64662. int j;
  64663. XFILE f = XBADFILE;
  64664. STACK_OF(GENERAL_NAME)* sk = NULL;
  64665. ExpectTrue((f = XFOPEN(cliCertDerFileExt, "rb")) != XBADFILE);
  64666. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  64667. if (f != XBADFILE)
  64668. XFCLOSE(f);
  64669. for (j = 0; j < 2; ++j) {
  64670. bufPt = buf;
  64671. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  64672. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  64673. NID_subject_alt_name, NULL, NULL));
  64674. ExpectIntEQ(sk_GENERAL_NAME_num(sk), 1);
  64675. for (i = 0; i < sk_GENERAL_NAME_num(sk); i++) {
  64676. ExpectNotNull(gn = sk_GENERAL_NAME_value(sk, i));
  64677. if (gn != NULL) {
  64678. switch (gn->type) {
  64679. case GEN_DNS:
  64680. fprintf(stderr, "found type GEN_DNS\n");
  64681. break;
  64682. case GEN_EMAIL:
  64683. fprintf(stderr, "found type GEN_EMAIL\n");
  64684. break;
  64685. case GEN_URI:
  64686. fprintf(stderr, "found type GEN_URI\n");
  64687. break;
  64688. }
  64689. }
  64690. }
  64691. X509_free(x509);
  64692. x509 = NULL;
  64693. if (j == 0) {
  64694. sk_GENERAL_NAME_pop_free(sk, GENERAL_NAME_free);
  64695. }
  64696. else {
  64697. /*
  64698. * We had a bug where GENERAL_NAMES_free didn't free all the memory
  64699. * it was supposed to. This is a regression test for that bug.
  64700. */
  64701. GENERAL_NAMES_free(sk);
  64702. }
  64703. sk = NULL;
  64704. }
  64705. #endif
  64706. return EXPECT_RESULT();
  64707. }
  64708. static int test_wolfSSL_GENERAL_NAME_print(void)
  64709. {
  64710. EXPECT_DECLS;
  64711. #if defined(OPENSSL_ALL) && !defined(NO_BIO) && !defined(NO_RSA)
  64712. X509* x509 = NULL;
  64713. GENERAL_NAME* gn = NULL;
  64714. unsigned char buf[4096];
  64715. const unsigned char* bufPt = NULL;
  64716. int bytes = 0;
  64717. XFILE f = XBADFILE;
  64718. STACK_OF(GENERAL_NAME)* sk = NULL;
  64719. BIO* out = NULL;
  64720. unsigned char outbuf[128];
  64721. X509_EXTENSION* ext = NULL;
  64722. AUTHORITY_INFO_ACCESS* aia = NULL;
  64723. ACCESS_DESCRIPTION* ad = NULL;
  64724. ASN1_IA5STRING *dnsname = NULL;
  64725. const unsigned char v4Addr[] = {192,168,53,1};
  64726. const unsigned char v6Addr[] =
  64727. {0x20, 0x21, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
  64728. 0x00, 0x00, 0xff, 0x00, 0x00, 0x42, 0x77, 0x77};
  64729. const unsigned char email[] =
  64730. {'i', 'n', 'f', 'o', '@', 'w', 'o', 'l',
  64731. 'f', 's', 's', 'l', '.', 'c', 'o', 'm'};
  64732. const char* dnsStr = "DNS:example.com";
  64733. const char* uriStr = "URI:http://127.0.0.1:22220";
  64734. const char* v4addStr = "IP Address:192.168.53.1";
  64735. const char* v6addStr = "IP Address:2021:DB8:0:0:0:FF00:42:7777";
  64736. const char* emailStr = "email:info@wolfssl.com";
  64737. const char* othrStr = "othername:<unsupported>";
  64738. const char* x400Str = "X400Name:<unsupported>";
  64739. const char* ediStr = "EdiPartyName:<unsupported>";
  64740. /* BIO to output */
  64741. ExpectNotNull(out = BIO_new(BIO_s_mem()));
  64742. /* test for NULL param */
  64743. gn = NULL;
  64744. ExpectIntEQ(GENERAL_NAME_print(NULL, NULL), 0);
  64745. ExpectIntEQ(GENERAL_NAME_print(NULL, gn), 0);
  64746. ExpectIntEQ(GENERAL_NAME_print(out, NULL), 0);
  64747. /* test for GEN_DNS */
  64748. ExpectTrue((f = XFOPEN(cliCertDerFileExt, "rb")) != XBADFILE);
  64749. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  64750. if (f != XBADFILE) {
  64751. XFCLOSE(f);
  64752. f = XBADFILE;
  64753. }
  64754. bufPt = buf;
  64755. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  64756. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  64757. NID_subject_alt_name, NULL, NULL));
  64758. ExpectNotNull(gn = sk_GENERAL_NAME_value(sk, 0));
  64759. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64760. XMEMSET(outbuf, 0, sizeof(outbuf));
  64761. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64762. ExpectIntEQ(XSTRNCMP((const char*)outbuf, dnsStr, XSTRLEN(dnsStr)), 0);
  64763. sk_GENERAL_NAME_pop_free(sk, GENERAL_NAME_free);
  64764. gn = NULL;
  64765. sk = NULL;
  64766. X509_free(x509);
  64767. x509 = NULL;
  64768. /* Lets test for setting as well. */
  64769. ExpectNotNull(gn = GENERAL_NAME_new());
  64770. ExpectNotNull(dnsname = ASN1_IA5STRING_new());
  64771. ExpectIntEQ(ASN1_STRING_set(dnsname, "example.com", -1), 1);
  64772. GENERAL_NAME_set0_value(gn, GEN_DNS, dnsname);
  64773. dnsname = NULL;
  64774. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64775. XMEMSET(outbuf, 0, sizeof(outbuf));
  64776. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64777. ExpectIntEQ(XSTRNCMP((const char*)outbuf, dnsStr, XSTRLEN(dnsStr)), 0);
  64778. GENERAL_NAME_free(gn);
  64779. /* test for GEN_URI */
  64780. ExpectTrue((f = XFOPEN("./certs/ocsp/root-ca-cert.pem", "rb")) != XBADFILE);
  64781. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  64782. if (f != XBADFILE) {
  64783. XFCLOSE(f);
  64784. f = XBADFILE;
  64785. }
  64786. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 4));
  64787. ExpectNotNull(aia = (WOLFSSL_AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(
  64788. ext));
  64789. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION *)wolfSSL_sk_value(aia, 0));
  64790. if (ad != NULL) {
  64791. gn = ad->location;
  64792. }
  64793. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64794. gn = NULL;
  64795. XMEMSET(outbuf,0,sizeof(outbuf));
  64796. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64797. ExpectIntEQ(XSTRNCMP((const char*)outbuf, uriStr, XSTRLEN(uriStr)), 0);
  64798. wolfSSL_sk_ACCESS_DESCRIPTION_pop_free(aia, NULL);
  64799. aia = NULL;
  64800. aia = (AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(ext);
  64801. ExpectNotNull(aia);
  64802. AUTHORITY_INFO_ACCESS_pop_free(aia, NULL);
  64803. aia = NULL;
  64804. X509_free(x509);
  64805. x509 = NULL;
  64806. /* test for GEN_IPADD */
  64807. /* ip v4 address */
  64808. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64809. if (gn != NULL) {
  64810. gn->type = GEN_IPADD;
  64811. if (gn->d.iPAddress != NULL) {
  64812. gn->d.iPAddress->length = sizeof(v4Addr);
  64813. }
  64814. }
  64815. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.iPAddress, v4Addr,
  64816. sizeof(v4Addr)), 1);
  64817. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64818. XMEMSET(outbuf,0,sizeof(outbuf));
  64819. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64820. ExpectIntEQ(XSTRNCMP((const char*)outbuf, v4addStr, XSTRLEN(v4addStr)), 0);
  64821. GENERAL_NAME_free(gn);
  64822. gn = NULL;
  64823. /* ip v6 address */
  64824. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64825. if (gn != NULL) {
  64826. gn->type = GEN_IPADD;
  64827. if (gn->d.iPAddress != NULL) {
  64828. gn->d.iPAddress->length = sizeof(v6Addr);
  64829. }
  64830. }
  64831. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.iPAddress, v6Addr,
  64832. sizeof(v6Addr)), 1);
  64833. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64834. XMEMSET(outbuf,0,sizeof(outbuf));
  64835. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64836. ExpectIntEQ(XSTRNCMP((const char*)outbuf, v6addStr, XSTRLEN(v6addStr)), 0);
  64837. GENERAL_NAME_free(gn);
  64838. gn = NULL;
  64839. /* test for GEN_EMAIL */
  64840. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64841. if (gn != NULL) {
  64842. gn->type = GEN_EMAIL;
  64843. if (gn->d.rfc822Name != NULL) {
  64844. gn->d.rfc822Name->length = sizeof(email);
  64845. }
  64846. }
  64847. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.rfc822Name, email, sizeof(email)),
  64848. 1);
  64849. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64850. XMEMSET(outbuf,0,sizeof(outbuf));
  64851. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64852. ExpectIntEQ(XSTRNCMP((const char*)outbuf, emailStr, XSTRLEN(emailStr)), 0);
  64853. GENERAL_NAME_free(gn);
  64854. gn = NULL;
  64855. /* test for GEN_OTHERNAME */
  64856. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64857. if (gn != NULL) {
  64858. gn->type = GEN_OTHERNAME;
  64859. }
  64860. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64861. XMEMSET(outbuf,0,sizeof(outbuf));
  64862. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64863. ExpectIntEQ(XSTRNCMP((const char*)outbuf, othrStr, XSTRLEN(othrStr)), 0);
  64864. GENERAL_NAME_free(gn);
  64865. gn = NULL;
  64866. /* test for GEN_X400 */
  64867. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64868. if (gn != NULL) {
  64869. gn->type = GEN_X400;
  64870. }
  64871. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64872. XMEMSET(outbuf,0,sizeof(outbuf));
  64873. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64874. ExpectIntEQ(XSTRNCMP((const char*)outbuf, x400Str, XSTRLEN(x400Str)), 0);
  64875. /* Restore to GEN_IA5 (default) to avoid memory leak. */
  64876. if (gn != NULL) {
  64877. gn->type = GEN_IA5;
  64878. }
  64879. GENERAL_NAME_free(gn);
  64880. gn = NULL;
  64881. /* test for GEN_EDIPARTY */
  64882. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64883. if (gn != NULL) {
  64884. gn->type = GEN_EDIPARTY;
  64885. }
  64886. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64887. XMEMSET(outbuf,0,sizeof(outbuf));
  64888. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64889. ExpectIntEQ(XSTRNCMP((const char*)outbuf, ediStr, XSTRLEN(ediStr)), 0);
  64890. /* Restore to GEN_IA5 (default) to avoid memory leak. */
  64891. if (gn != NULL) {
  64892. gn->type = GEN_IA5;
  64893. }
  64894. GENERAL_NAME_free(gn);
  64895. gn = NULL;
  64896. BIO_free(out);
  64897. #endif /* OPENSSL_ALL */
  64898. return EXPECT_RESULT();
  64899. }
  64900. static int test_wolfSSL_sk_DIST_POINT(void)
  64901. {
  64902. EXPECT_DECLS;
  64903. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  64904. !defined(NO_RSA)
  64905. X509* x509 = NULL;
  64906. unsigned char buf[4096];
  64907. const unsigned char* bufPt;
  64908. int bytes = 0;
  64909. int i = 0;
  64910. int j = 0;
  64911. XFILE f = XBADFILE;
  64912. DIST_POINT* dp = NULL;
  64913. DIST_POINT_NAME* dpn = NULL;
  64914. GENERAL_NAME* gn = NULL;
  64915. ASN1_IA5STRING* uri = NULL;
  64916. STACK_OF(DIST_POINT)* dps = NULL;
  64917. STACK_OF(GENERAL_NAME)* gns = NULL;
  64918. const char cliCertDerCrlDistPoint[] = "./certs/client-crl-dist.der";
  64919. ExpectTrue((f = XFOPEN(cliCertDerCrlDistPoint, "rb")) != XBADFILE);
  64920. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  64921. if (f != XBADFILE)
  64922. XFCLOSE(f);
  64923. bufPt = buf;
  64924. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  64925. ExpectNotNull(dps = (STACK_OF(DIST_POINT)*)X509_get_ext_d2i(x509,
  64926. NID_crl_distribution_points, NULL, NULL));
  64927. ExpectIntEQ(sk_DIST_POINT_num(dps), 1);
  64928. for (i = 0; i < sk_DIST_POINT_num(dps); i++) {
  64929. ExpectNotNull(dp = sk_DIST_POINT_value(dps, i));
  64930. ExpectNotNull(dpn = dp->distpoint);
  64931. /* this should be type 0, fullname */
  64932. ExpectIntEQ(dpn->type, 0);
  64933. ExpectNotNull(gns = dp->distpoint->name.fullname);
  64934. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 1);
  64935. for (j = 0; j < sk_GENERAL_NAME_num(gns); j++) {
  64936. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, j));
  64937. ExpectIntEQ(gn->type, GEN_URI);
  64938. ExpectNotNull(uri = gn->d.uniformResourceIdentifier);
  64939. ExpectNotNull(uri->data);
  64940. ExpectIntGT(uri->length, 0);
  64941. }
  64942. }
  64943. X509_free(x509);
  64944. CRL_DIST_POINTS_free(dps);
  64945. #endif
  64946. return EXPECT_RESULT();
  64947. }
  64948. static int test_wolfSSL_verify_mode(void)
  64949. {
  64950. EXPECT_DECLS;
  64951. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  64952. WOLFSSL* ssl = NULL;
  64953. WOLFSSL_CTX* ctx = NULL;
  64954. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  64955. ExpectNotNull(ssl = SSL_new(ctx));
  64956. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  64957. SSL_free(ssl);
  64958. ssl = NULL;
  64959. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  64960. ExpectNotNull(ssl = SSL_new(ctx));
  64961. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  64962. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_PEER);
  64963. wolfSSL_set_verify(ssl, SSL_VERIFY_NONE, 0);
  64964. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx), SSL_VERIFY_PEER);
  64965. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_NONE);
  64966. SSL_free(ssl);
  64967. ssl = NULL;
  64968. wolfSSL_CTX_set_verify(ctx,
  64969. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  64970. ExpectNotNull(ssl = SSL_new(ctx));
  64971. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  64972. ExpectIntEQ(SSL_get_verify_mode(ssl),
  64973. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  64974. wolfSSL_set_verify(ssl, SSL_VERIFY_PEER, 0);
  64975. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx),
  64976. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  64977. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_PEER);
  64978. wolfSSL_set_verify(ssl, SSL_VERIFY_NONE, 0);
  64979. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_NONE);
  64980. wolfSSL_set_verify(ssl, SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  64981. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  64982. wolfSSL_set_verify(ssl, SSL_VERIFY_FAIL_EXCEPT_PSK, 0);
  64983. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_FAIL_EXCEPT_PSK);
  64984. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  64985. wolfSSL_set_verify(ssl, SSL_VERIFY_POST_HANDSHAKE, 0);
  64986. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_POST_HANDSHAKE);
  64987. #endif
  64988. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx),
  64989. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  64990. SSL_free(ssl);
  64991. SSL_CTX_free(ctx);
  64992. #endif
  64993. return EXPECT_RESULT();
  64994. }
  64995. static int test_wolfSSL_verify_depth(void)
  64996. {
  64997. EXPECT_DECLS;
  64998. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  64999. WOLFSSL* ssl = NULL;
  65000. WOLFSSL_CTX* ctx = NULL;
  65001. long depth = 0;
  65002. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  65003. ExpectIntGT((depth = SSL_CTX_get_verify_depth(ctx)), 0);
  65004. ExpectNotNull(ssl = SSL_new(ctx));
  65005. ExpectIntEQ(SSL_get_verify_depth(ssl), SSL_CTX_get_verify_depth(ctx));
  65006. SSL_free(ssl);
  65007. ssl = NULL;
  65008. SSL_CTX_set_verify_depth(ctx, -1);
  65009. ExpectIntEQ(depth, SSL_CTX_get_verify_depth(ctx));
  65010. SSL_CTX_set_verify_depth(ctx, 2);
  65011. ExpectIntEQ(2, SSL_CTX_get_verify_depth(ctx));
  65012. ExpectNotNull(ssl = SSL_new(ctx));
  65013. ExpectIntEQ(2, SSL_get_verify_depth(ssl));
  65014. SSL_free(ssl);
  65015. SSL_CTX_free(ctx);
  65016. #endif
  65017. return EXPECT_RESULT();
  65018. }
  65019. static int test_wolfSSL_verify_result(void)
  65020. {
  65021. EXPECT_DECLS;
  65022. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  65023. defined(OPENSSL_ALL)) && !defined(NO_WOLFSSL_CLIENT)
  65024. WOLFSSL* ssl = NULL;
  65025. WOLFSSL_CTX* ctx = NULL;
  65026. long result = 0xDEADBEEF;
  65027. ExpectIntEQ(WC_NO_ERR_TRACE(WOLFSSL_FAILURE), wolfSSL_get_verify_result(ssl));
  65028. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  65029. ExpectNotNull(ssl = SSL_new(ctx));
  65030. wolfSSL_set_verify_result(ssl, result);
  65031. ExpectIntEQ(result, wolfSSL_get_verify_result(ssl));
  65032. SSL_free(ssl);
  65033. SSL_CTX_free(ctx);
  65034. #endif
  65035. return EXPECT_RESULT();
  65036. }
  65037. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  65038. static void sslMsgCb(int w, int version, int type, const void* buf,
  65039. size_t sz, SSL* ssl, void* arg)
  65040. {
  65041. int i;
  65042. unsigned char* pt = (unsigned char*)buf;
  65043. fprintf(stderr, "%s %d bytes of version %d , type %d : ",
  65044. (w)?"Writing":"Reading", (int)sz, version, type);
  65045. for (i = 0; i < (int)sz; i++) fprintf(stderr, "%02X", pt[i]);
  65046. fprintf(stderr, "\n");
  65047. (void)ssl;
  65048. (void)arg;
  65049. }
  65050. #endif /* OPENSSL_EXTRA */
  65051. static int test_wolfSSL_msg_callback(void)
  65052. {
  65053. EXPECT_DECLS;
  65054. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  65055. WOLFSSL* ssl = NULL;
  65056. WOLFSSL_CTX* ctx = NULL;
  65057. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  65058. ExpectNotNull(ssl = SSL_new(ctx));
  65059. ExpectIntEQ(SSL_set_msg_callback(ssl, NULL), SSL_SUCCESS);
  65060. ExpectIntEQ(SSL_set_msg_callback(ssl, &sslMsgCb), SSL_SUCCESS);
  65061. ExpectIntEQ(SSL_set_msg_callback(NULL, &sslMsgCb), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65062. SSL_free(ssl);
  65063. SSL_CTX_free(ctx);
  65064. #endif
  65065. return EXPECT_RESULT();
  65066. }
  65067. /* test_EVP_Cipher_extra, Extra-test on EVP_CipherUpdate/Final. see also test.c */
  65068. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) &&\
  65069. (!defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128))
  65070. static void binary_dump(void *ptr, int size)
  65071. {
  65072. #ifdef WOLFSSL_EVP_PRINT
  65073. int i = 0;
  65074. unsigned char *p = (unsigned char *) ptr;
  65075. fprintf(stderr, "{");
  65076. while ((p != NULL) && (i < size)) {
  65077. if ((i % 8) == 0) {
  65078. fprintf(stderr, "\n");
  65079. fprintf(stderr, " ");
  65080. }
  65081. fprintf(stderr, "0x%02x, ", p[i]);
  65082. i++;
  65083. }
  65084. fprintf(stderr, "\n};\n");
  65085. #else
  65086. (void) ptr;
  65087. (void) size;
  65088. #endif
  65089. }
  65090. static int last_val = 0x0f;
  65091. static int check_result(unsigned char *data, int len)
  65092. {
  65093. int i;
  65094. for ( ; len; ) {
  65095. last_val = (last_val + 1) % 16;
  65096. for (i = 0; i < 16; len--, i++, data++)
  65097. if (*data != last_val) {
  65098. return -1;
  65099. }
  65100. }
  65101. return 0;
  65102. }
  65103. static int r_offset;
  65104. static int w_offset;
  65105. static void init_offset(void)
  65106. {
  65107. r_offset = 0;
  65108. w_offset = 0;
  65109. }
  65110. static void get_record(unsigned char *data, unsigned char *buf, int len)
  65111. {
  65112. XMEMCPY(buf, data+r_offset, len);
  65113. r_offset += len;
  65114. }
  65115. static void set_record(unsigned char *data, unsigned char *buf, int len)
  65116. {
  65117. XMEMCPY(data+w_offset, buf, len);
  65118. w_offset += len;
  65119. }
  65120. static void set_plain(unsigned char *plain, int rec)
  65121. {
  65122. int i, j;
  65123. unsigned char *p = plain;
  65124. #define BLOCKSZ 16
  65125. for (i=0; i<(rec/BLOCKSZ); i++) {
  65126. for (j=0; j<BLOCKSZ; j++)
  65127. *p++ = (i % 16);
  65128. }
  65129. }
  65130. #endif
  65131. static int test_wolfSSL_EVP_Cipher_extra(void)
  65132. {
  65133. EXPECT_DECLS;
  65134. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) &&\
  65135. (!defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128))
  65136. /* aes128-cbc, keylen=16, ivlen=16 */
  65137. byte aes128_cbc_key[] = {
  65138. 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
  65139. 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
  65140. };
  65141. byte aes128_cbc_iv[] = {
  65142. 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
  65143. 0x99, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
  65144. };
  65145. /* teset data size table */
  65146. int test_drive1[] = {8, 3, 5, 512, 8, 3, 8, 512, 0};
  65147. int test_drive2[] = {8, 3, 8, 512, 0};
  65148. int test_drive3[] = {512, 512, 504, 512, 512, 8, 512, 0};
  65149. int *test_drive[] = {test_drive1, test_drive2, test_drive3, NULL};
  65150. int test_drive_len[100];
  65151. int ret = 0;
  65152. EVP_CIPHER_CTX *evp = NULL;
  65153. int ilen = 0;
  65154. int klen = 0;
  65155. int i, j;
  65156. const EVP_CIPHER *type;
  65157. byte *iv;
  65158. byte *key;
  65159. int ivlen;
  65160. int keylen;
  65161. #define RECORDS 16
  65162. #define BUFFSZ 512
  65163. byte plain [BUFFSZ * RECORDS];
  65164. byte cipher[BUFFSZ * RECORDS];
  65165. byte inb[BUFFSZ];
  65166. byte outb[BUFFSZ+16];
  65167. int outl = 0;
  65168. int inl;
  65169. iv = aes128_cbc_iv;
  65170. ivlen = sizeof(aes128_cbc_iv);
  65171. key = aes128_cbc_key;
  65172. keylen = sizeof(aes128_cbc_key);
  65173. type = EVP_aes_128_cbc();
  65174. set_plain(plain, BUFFSZ * RECORDS);
  65175. SSL_library_init();
  65176. ExpectNotNull(evp = EVP_CIPHER_CTX_new());
  65177. ExpectIntNE((ret = EVP_CipherInit(evp, type, NULL, iv, 0)), 0);
  65178. ExpectIntEQ(EVP_CIPHER_CTX_nid(evp), NID_aes_128_cbc);
  65179. klen = EVP_CIPHER_CTX_key_length(evp);
  65180. if (klen > 0 && keylen != klen) {
  65181. ExpectIntNE(EVP_CIPHER_CTX_set_key_length(evp, keylen), 0);
  65182. }
  65183. ilen = EVP_CIPHER_CTX_iv_length(evp);
  65184. if (ilen > 0 && ivlen != ilen) {
  65185. ExpectIntNE(EVP_CIPHER_CTX_set_iv_length(evp, ivlen), 0);
  65186. }
  65187. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  65188. for (j = 0; j<RECORDS; j++)
  65189. {
  65190. inl = BUFFSZ;
  65191. get_record(plain, inb, inl);
  65192. ExpectIntNE((ret = EVP_CipherUpdate(evp, outb, &outl, inb, inl)), 0);
  65193. set_record(cipher, outb, outl);
  65194. }
  65195. for (i = 0; test_drive[i]; i++) {
  65196. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  65197. init_offset();
  65198. test_drive_len[i] = 0;
  65199. for (j = 0; test_drive[i][j]; j++)
  65200. {
  65201. inl = test_drive[i][j];
  65202. test_drive_len[i] += inl;
  65203. get_record(plain, inb, inl);
  65204. ExpectIntNE((ret = EVP_EncryptUpdate(evp, outb, &outl, inb, inl)),
  65205. 0);
  65206. /* output to cipher buffer, so that following Dec test can detect
  65207. if any error */
  65208. set_record(cipher, outb, outl);
  65209. }
  65210. EVP_CipherFinal(evp, outb, &outl);
  65211. if (outl > 0)
  65212. set_record(cipher, outb, outl);
  65213. }
  65214. for (i = 0; test_drive[i]; i++) {
  65215. last_val = 0x0f;
  65216. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 0)), 0);
  65217. init_offset();
  65218. for (j = 0; test_drive[i][j]; j++) {
  65219. inl = test_drive[i][j];
  65220. get_record(cipher, inb, inl);
  65221. ExpectIntNE((ret = EVP_DecryptUpdate(evp, outb, &outl, inb, inl)),
  65222. 0);
  65223. binary_dump(outb, outl);
  65224. ExpectIntEQ((ret = check_result(outb, outl)), 0);
  65225. ExpectFalse(outl > ((inl/16+1)*16) && outl > 16);
  65226. }
  65227. ret = EVP_CipherFinal(evp, outb, &outl);
  65228. binary_dump(outb, outl);
  65229. ret = (((test_drive_len[i] % 16) != 0) && (ret == 0)) ||
  65230. (((test_drive_len[i] % 16) == 0) && (ret == 1));
  65231. ExpectTrue(ret);
  65232. }
  65233. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(evp), WOLFSSL_SUCCESS);
  65234. EVP_CIPHER_CTX_free(evp);
  65235. evp = NULL;
  65236. /* Do an extra test to verify correct behavior with empty input. */
  65237. ExpectNotNull(evp = EVP_CIPHER_CTX_new());
  65238. ExpectIntNE((ret = EVP_CipherInit(evp, type, NULL, iv, 0)), 0);
  65239. ExpectIntEQ(EVP_CIPHER_CTX_nid(evp), NID_aes_128_cbc);
  65240. klen = EVP_CIPHER_CTX_key_length(evp);
  65241. if (klen > 0 && keylen != klen) {
  65242. ExpectIntNE(EVP_CIPHER_CTX_set_key_length(evp, keylen), 0);
  65243. }
  65244. ilen = EVP_CIPHER_CTX_iv_length(evp);
  65245. if (ilen > 0 && ivlen != ilen) {
  65246. ExpectIntNE(EVP_CIPHER_CTX_set_iv_length(evp, ivlen), 0);
  65247. }
  65248. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  65249. /* outl should be set to 0 after passing NULL, 0 for input args. */
  65250. outl = -1;
  65251. ExpectIntNE((ret = EVP_CipherUpdate(evp, outb, &outl, NULL, 0)), 0);
  65252. ExpectIntEQ(outl, 0);
  65253. EVP_CIPHER_CTX_free(evp);
  65254. #endif /* test_EVP_Cipher */
  65255. return EXPECT_RESULT();
  65256. }
  65257. static int test_wolfSSL_PEM_read_DHparams(void)
  65258. {
  65259. EXPECT_DECLS;
  65260. #if defined(OPENSSL_ALL) && !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && \
  65261. !defined(NO_FILESYSTEM)
  65262. DH* dh = NULL;
  65263. XFILE fp = XBADFILE;
  65264. unsigned char derOut[300];
  65265. unsigned char* derOutBuf = derOut;
  65266. int derOutSz = 0;
  65267. unsigned char derExpected[300];
  65268. int derExpectedSz = 0;
  65269. XMEMSET(derOut, 0, sizeof(derOut));
  65270. XMEMSET(derExpected, 0, sizeof(derExpected));
  65271. /* open DH param file, read into DH struct */
  65272. ExpectTrue((fp = XFOPEN(dhParamFile, "rb")) != XBADFILE);
  65273. /* bad args */
  65274. ExpectNull(dh = PEM_read_DHparams(NULL, &dh, NULL, NULL));
  65275. ExpectNull(dh = PEM_read_DHparams(NULL, NULL, NULL, NULL));
  65276. /* good args */
  65277. ExpectNotNull(dh = PEM_read_DHparams(fp, &dh, NULL, NULL));
  65278. if (fp != XBADFILE) {
  65279. XFCLOSE(fp);
  65280. fp = XBADFILE;
  65281. }
  65282. /* read in certs/dh2048.der for comparison against exported params */
  65283. ExpectTrue((fp = XFOPEN("./certs/dh2048.der", "rb")) != XBADFILE);
  65284. ExpectIntGT(derExpectedSz = (int)XFREAD(derExpected, 1, sizeof(derExpected),
  65285. fp), 0);
  65286. if (fp != XBADFILE) {
  65287. XFCLOSE(fp);
  65288. fp = XBADFILE;
  65289. }
  65290. /* export DH back to DER and compare */
  65291. derOutSz = wolfSSL_i2d_DHparams(dh, &derOutBuf);
  65292. ExpectIntEQ(derOutSz, derExpectedSz);
  65293. ExpectIntEQ(XMEMCMP(derOut, derExpected, derOutSz), 0);
  65294. DH_free(dh);
  65295. dh = NULL;
  65296. /* Test parsing with X9.42 header */
  65297. ExpectTrue((fp = XFOPEN("./certs/x942dh2048.pem", "rb")) != XBADFILE);
  65298. ExpectNotNull(dh = PEM_read_DHparams(fp, &dh, NULL, NULL));
  65299. if (fp != XBADFILE)
  65300. XFCLOSE(fp);
  65301. DH_free(dh);
  65302. dh = NULL;
  65303. #endif
  65304. return EXPECT_RESULT();
  65305. }
  65306. static int test_wolfSSL_X509_get_serialNumber(void)
  65307. {
  65308. EXPECT_DECLS;
  65309. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  65310. ASN1_INTEGER* a = NULL;
  65311. BIGNUM* bn = NULL;
  65312. X509* x509 = NULL;
  65313. char *serialHex = NULL;
  65314. byte serial[3];
  65315. int serialSz;
  65316. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  65317. SSL_FILETYPE_PEM));
  65318. ExpectNotNull(a = X509_get_serialNumber(x509));
  65319. /* check on value of ASN1 Integer */
  65320. ExpectNotNull(bn = ASN1_INTEGER_to_BN(a, NULL));
  65321. a = NULL;
  65322. /* test setting serial number and then retrieving it */
  65323. ExpectNotNull(a = ASN1_INTEGER_new());
  65324. ExpectIntEQ(ASN1_INTEGER_set(a, 3), 1);
  65325. ExpectIntEQ(X509_set_serialNumber(x509, a), WOLFSSL_SUCCESS);
  65326. serialSz = sizeof(serial);
  65327. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, serial, &serialSz),
  65328. WOLFSSL_SUCCESS);
  65329. ExpectIntEQ(serialSz, 1);
  65330. ExpectIntEQ(serial[0], 3);
  65331. ASN1_INTEGER_free(a);
  65332. a = NULL;
  65333. /* test setting serial number with 0's in it */
  65334. serial[0] = 0x01;
  65335. serial[1] = 0x00;
  65336. serial[2] = 0x02;
  65337. ExpectNotNull(a = wolfSSL_ASN1_INTEGER_new());
  65338. if (a != NULL) {
  65339. a->data[0] = ASN_INTEGER;
  65340. a->data[1] = sizeof(serial);
  65341. XMEMCPY(&a->data[2], serial, sizeof(serial));
  65342. a->length = sizeof(serial) + 2;
  65343. }
  65344. ExpectIntEQ(X509_set_serialNumber(x509, a), WOLFSSL_SUCCESS);
  65345. XMEMSET(serial, 0, sizeof(serial));
  65346. serialSz = sizeof(serial);
  65347. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, serial, &serialSz),
  65348. WOLFSSL_SUCCESS);
  65349. ExpectIntEQ(serialSz, 3);
  65350. ExpectIntEQ(serial[0], 0x01);
  65351. ExpectIntEQ(serial[1], 0x00);
  65352. ExpectIntEQ(serial[2], 0x02);
  65353. ASN1_INTEGER_free(a);
  65354. a = NULL;
  65355. X509_free(x509); /* free's a */
  65356. ExpectNotNull(serialHex = BN_bn2hex(bn));
  65357. #ifndef WC_DISABLE_RADIX_ZERO_PAD
  65358. ExpectStrEQ(serialHex, "01");
  65359. #else
  65360. ExpectStrEQ(serialHex, "1");
  65361. #endif
  65362. OPENSSL_free(serialHex);
  65363. ExpectIntEQ(BN_get_word(bn), 1);
  65364. BN_free(bn);
  65365. /* hard test free'ing with dynamic buffer to make sure there is no leaks */
  65366. ExpectNotNull(a = ASN1_INTEGER_new());
  65367. if (a != NULL) {
  65368. ExpectNotNull(a->data = (unsigned char*)XMALLOC(100, NULL,
  65369. DYNAMIC_TYPE_OPENSSL));
  65370. a->isDynamic = 1;
  65371. ASN1_INTEGER_free(a);
  65372. }
  65373. #endif
  65374. return EXPECT_RESULT();
  65375. }
  65376. static int test_wolfSSL_OpenSSL_add_all_algorithms(void)
  65377. {
  65378. EXPECT_DECLS;
  65379. #if defined(OPENSSL_EXTRA)
  65380. ExpectIntEQ(wolfSSL_add_all_algorithms(), WOLFSSL_SUCCESS);
  65381. ExpectIntEQ(wolfSSL_OpenSSL_add_all_algorithms_noconf(), WOLFSSL_SUCCESS);
  65382. ExpectIntEQ(wolfSSL_OpenSSL_add_all_algorithms_conf(), WOLFSSL_SUCCESS);
  65383. #endif
  65384. return EXPECT_RESULT();
  65385. }
  65386. static int test_wolfSSL_OPENSSL_hexstr2buf(void)
  65387. {
  65388. EXPECT_DECLS;
  65389. #if defined(OPENSSL_EXTRA)
  65390. #define MAX_HEXSTR_BUFSZ 9
  65391. #define NUM_CASES 5
  65392. struct Output {
  65393. const unsigned char buffer[MAX_HEXSTR_BUFSZ];
  65394. long ret;
  65395. };
  65396. int i;
  65397. int j;
  65398. const char* inputs[NUM_CASES] = {
  65399. "aabcd1357e",
  65400. "01:12:23:34:a5:b6:c7:d8:e9",
  65401. ":01:02",
  65402. "012",
  65403. ":ab:ac:d"
  65404. };
  65405. struct Output expectedOutputs[NUM_CASES] = {
  65406. {{0xaa, 0xbc, 0xd1, 0x35, 0x7e}, 5},
  65407. {{0x01, 0x12, 0x23, 0x34, 0xa5, 0xb6, 0xc7, 0xd8, 0xe9}, 9},
  65408. {{0x01, 0x02}, 2},
  65409. {{0x00}, 0},
  65410. {{0x00}, 0}
  65411. };
  65412. long len = 0;
  65413. unsigned char* returnedBuf = NULL;
  65414. for (i = 0; i < NUM_CASES && !EXPECT_FAIL(); ++i) {
  65415. returnedBuf = wolfSSL_OPENSSL_hexstr2buf(inputs[i], &len);
  65416. if (returnedBuf == NULL) {
  65417. ExpectIntEQ(expectedOutputs[i].ret, 0);
  65418. continue;
  65419. }
  65420. ExpectIntEQ(expectedOutputs[i].ret, len);
  65421. for (j = 0; j < len; ++j) {
  65422. ExpectIntEQ(expectedOutputs[i].buffer[j], returnedBuf[j]);
  65423. }
  65424. OPENSSL_free(returnedBuf);
  65425. returnedBuf = NULL;
  65426. }
  65427. #endif
  65428. return EXPECT_RESULT();
  65429. }
  65430. static int test_wolfSSL_X509_CA_num(void)
  65431. {
  65432. EXPECT_DECLS;
  65433. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  65434. defined(HAVE_ECC) && !defined(NO_RSA)
  65435. WOLFSSL_X509_STORE *store = NULL;
  65436. WOLFSSL_X509 *x509_1 = NULL;
  65437. WOLFSSL_X509 *x509_2 = NULL;
  65438. int ca_num = 0;
  65439. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  65440. ExpectNotNull(x509_1 = wolfSSL_X509_load_certificate_file(svrCertFile,
  65441. WOLFSSL_FILETYPE_PEM));
  65442. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, x509_1), 1);
  65443. ExpectIntEQ(ca_num = wolfSSL_X509_CA_num(store), 1);
  65444. ExpectNotNull(x509_2 = wolfSSL_X509_load_certificate_file(eccCertFile,
  65445. WOLFSSL_FILETYPE_PEM));
  65446. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, x509_2), 1);
  65447. ExpectIntEQ(ca_num = wolfSSL_X509_CA_num(store), 2);
  65448. wolfSSL_X509_free(x509_1);
  65449. wolfSSL_X509_free(x509_2);
  65450. wolfSSL_X509_STORE_free(store);
  65451. #endif
  65452. return EXPECT_RESULT();
  65453. }
  65454. static int test_wolfSSL_X509_check_ca(void)
  65455. {
  65456. EXPECT_DECLS;
  65457. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  65458. WOLFSSL_X509 *x509 = NULL;
  65459. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  65460. WOLFSSL_FILETYPE_PEM));
  65461. ExpectIntEQ(wolfSSL_X509_check_ca(x509), 1);
  65462. wolfSSL_X509_free(x509);
  65463. #endif
  65464. return EXPECT_RESULT();
  65465. }
  65466. static int test_wolfSSL_X509_check_ip_asc(void)
  65467. {
  65468. EXPECT_DECLS;
  65469. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  65470. WOLFSSL_X509 *x509 = NULL;
  65471. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  65472. WOLFSSL_FILETYPE_PEM));
  65473. #if 0
  65474. /* TODO: add cert gen for testing positive case */
  65475. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "127.0.0.1", 0), 1);
  65476. #endif
  65477. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "0.0.0.0", 0), 0);
  65478. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, NULL, 0), 0);
  65479. wolfSSL_X509_free(x509);
  65480. #endif
  65481. return EXPECT_RESULT();
  65482. }
  65483. static int test_wolfSSL_make_cert(void)
  65484. {
  65485. EXPECT_DECLS;
  65486. #if !defined(NO_RSA) && !defined(NO_ASN_TIME) && defined(WOLFSSL_CERT_GEN) && \
  65487. defined(WOLFSSL_CERT_EXT)
  65488. int ret = 0;
  65489. Cert cert;
  65490. CertName name;
  65491. RsaKey key;
  65492. WC_RNG rng;
  65493. byte der[FOURK_BUF];
  65494. word32 idx = 0;
  65495. const byte mySerial[8] = {1,2,3,4,5,6,7,8};
  65496. #ifdef OPENSSL_EXTRA
  65497. const unsigned char* pt = NULL;
  65498. int certSz = 0;
  65499. X509* x509 = NULL;
  65500. X509_NAME* x509name = NULL;
  65501. X509_NAME_ENTRY* entry = NULL;
  65502. ASN1_STRING* entryValue = NULL;
  65503. #endif
  65504. XMEMSET(&name, 0, sizeof(CertName));
  65505. /* set up cert name */
  65506. XMEMCPY(name.country, "US", sizeof("US"));
  65507. name.countryEnc = CTC_PRINTABLE;
  65508. XMEMCPY(name.state, "Oregon", sizeof("Oregon"));
  65509. name.stateEnc = CTC_UTF8;
  65510. XMEMCPY(name.locality, "Portland", sizeof("Portland"));
  65511. name.localityEnc = CTC_UTF8;
  65512. XMEMCPY(name.sur, "Test", sizeof("Test"));
  65513. name.surEnc = CTC_UTF8;
  65514. XMEMCPY(name.org, "wolfSSL", sizeof("wolfSSL"));
  65515. name.orgEnc = CTC_UTF8;
  65516. XMEMCPY(name.unit, "Development", sizeof("Development"));
  65517. name.unitEnc = CTC_UTF8;
  65518. XMEMCPY(name.commonName, "www.wolfssl.com", sizeof("www.wolfssl.com"));
  65519. name.commonNameEnc = CTC_UTF8;
  65520. XMEMCPY(name.serialDev, "wolfSSL12345", sizeof("wolfSSL12345"));
  65521. name.serialDevEnc = CTC_PRINTABLE;
  65522. XMEMCPY(name.userId, "TestUserID", sizeof("TestUserID"));
  65523. name.userIdEnc = CTC_PRINTABLE;
  65524. #ifdef WOLFSSL_MULTI_ATTRIB
  65525. #if CTC_MAX_ATTRIB > 2
  65526. {
  65527. NameAttrib* n;
  65528. n = &name.name[0];
  65529. n->id = ASN_DOMAIN_COMPONENT;
  65530. n->type = CTC_UTF8;
  65531. n->sz = sizeof("com");
  65532. XMEMCPY(n->value, "com", sizeof("com"));
  65533. n = &name.name[1];
  65534. n->id = ASN_DOMAIN_COMPONENT;
  65535. n->type = CTC_UTF8;
  65536. n->sz = sizeof("wolfssl");
  65537. XMEMCPY(n->value, "wolfssl", sizeof("wolfssl"));
  65538. }
  65539. #endif
  65540. #endif /* WOLFSSL_MULTI_ATTRIB */
  65541. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  65542. #ifndef HAVE_FIPS
  65543. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  65544. #else
  65545. ExpectIntEQ(wc_InitRng(&rng), 0);
  65546. #endif
  65547. /* load test RSA key */
  65548. idx = 0;
  65549. #if defined(USE_CERT_BUFFERS_1024)
  65550. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_1024, &idx, &key,
  65551. sizeof_server_key_der_1024), 0);
  65552. #elif defined(USE_CERT_BUFFERS_2048)
  65553. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &key,
  65554. sizeof_server_key_der_2048), 0);
  65555. #else
  65556. /* error case, no RSA key loaded, happens later */
  65557. (void)idx;
  65558. #endif
  65559. XMEMSET(&cert, 0 , sizeof(Cert));
  65560. ExpectIntEQ(wc_InitCert(&cert), 0);
  65561. XMEMCPY(&cert.subject, &name, sizeof(CertName));
  65562. XMEMCPY(cert.serial, mySerial, sizeof(mySerial));
  65563. cert.serialSz = (int)sizeof(mySerial);
  65564. cert.isCA = 1;
  65565. #ifndef NO_SHA256
  65566. cert.sigType = CTC_SHA256wRSA;
  65567. #else
  65568. cert.sigType = CTC_SHAwRSA;
  65569. #endif
  65570. /* add SKID from the Public Key */
  65571. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey(&cert, &key, NULL), 0);
  65572. /* add AKID from the Public Key */
  65573. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey(&cert, &key, NULL), 0);
  65574. ret = 0;
  65575. do {
  65576. #if defined(WOLFSSL_ASYNC_CRYPT)
  65577. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  65578. #endif
  65579. if (ret >= 0) {
  65580. ret = wc_MakeSelfCert(&cert, der, FOURK_BUF, &key, &rng);
  65581. }
  65582. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  65583. ExpectIntGT(ret, 0);
  65584. #ifdef OPENSSL_EXTRA
  65585. /* der holds a certificate with DC's now check X509 parsing of it */
  65586. certSz = ret;
  65587. pt = der;
  65588. ExpectNotNull(x509 = d2i_X509(NULL, &pt, certSz));
  65589. ExpectNotNull(x509name = X509_get_subject_name(x509));
  65590. #ifdef WOLFSSL_MULTI_ATTRIB
  65591. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  65592. -1)), 5);
  65593. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  65594. (int)idx)), 6);
  65595. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  65596. (int)idx)), -1);
  65597. #endif /* WOLFSSL_MULTI_ATTRIB */
  65598. /* compare DN at index 0 */
  65599. ExpectNotNull(entry = X509_NAME_get_entry(x509name, 0));
  65600. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  65601. ExpectIntEQ(ASN1_STRING_length(entryValue), 2);
  65602. ExpectStrEQ((const char*)ASN1_STRING_data(entryValue), "US");
  65603. #ifndef WOLFSSL_MULTI_ATTRIB
  65604. /* compare Serial Number */
  65605. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_serialNumber,
  65606. -1)), 7);
  65607. ExpectNotNull(entry = X509_NAME_get_entry(x509name, idx));
  65608. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  65609. ExpectIntEQ(ASN1_STRING_length(entryValue), XSTRLEN("wolfSSL12345"));
  65610. ExpectStrEQ((const char*)ASN1_STRING_data(entryValue), "wolfSSL12345");
  65611. #endif
  65612. #ifdef WOLFSSL_MULTI_ATTRIB
  65613. /* get first and second DC and compare result */
  65614. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  65615. -1)), 5);
  65616. ExpectNotNull(entry = X509_NAME_get_entry(x509name, (int)idx));
  65617. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  65618. ExpectStrEQ((const char *)ASN1_STRING_data(entryValue), "com");
  65619. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  65620. (int)idx)), 6);
  65621. ExpectNotNull(entry = X509_NAME_get_entry(x509name, (int)idx));
  65622. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  65623. ExpectStrEQ((const char *)ASN1_STRING_data(entryValue), "wolfssl");
  65624. #endif /* WOLFSSL_MULTI_ATTRIB */
  65625. /* try invalid index locations for regression test and sanity check */
  65626. ExpectNull(entry = X509_NAME_get_entry(x509name, 11));
  65627. ExpectNull(entry = X509_NAME_get_entry(x509name, 20));
  65628. X509_free(x509);
  65629. #endif /* OPENSSL_EXTRA */
  65630. wc_FreeRsaKey(&key);
  65631. wc_FreeRng(&rng);
  65632. #endif
  65633. return EXPECT_RESULT();
  65634. }
  65635. static int test_x509_get_key_id(void)
  65636. {
  65637. EXPECT_DECLS;
  65638. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  65639. X509 *x509 = NULL;
  65640. const ASN1_STRING* str = NULL;
  65641. byte* keyId = NULL;
  65642. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  65643. WOLFSSL_FILETYPE_PEM));
  65644. ExpectNotNull(str = X509_get0_subject_key_id(x509));
  65645. ExpectNotNull(keyId = wolfSSL_X509_get_subjectKeyID(x509, NULL, NULL));
  65646. ExpectBufEQ(keyId, ASN1_STRING_data((ASN1_STRING*)str),
  65647. ASN1_STRING_length(str));
  65648. X509_free(x509);
  65649. #endif
  65650. return EXPECT_RESULT();
  65651. }
  65652. static int test_wolfSSL_X509_get_version(void)
  65653. {
  65654. EXPECT_DECLS;
  65655. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  65656. WOLFSSL_X509 *x509 = NULL;
  65657. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  65658. WOLFSSL_FILETYPE_PEM));
  65659. ExpectIntEQ((int)wolfSSL_X509_get_version(x509), 2);
  65660. wolfSSL_X509_free(x509);
  65661. #endif
  65662. return EXPECT_RESULT();
  65663. }
  65664. #if defined(OPENSSL_ALL)
  65665. static int test_wolfSSL_sk_CIPHER_description(void)
  65666. {
  65667. EXPECT_DECLS;
  65668. #if !defined(NO_RSA)
  65669. const long flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_COMPRESSION;
  65670. int i;
  65671. int numCiphers = 0;
  65672. const SSL_METHOD *method = NULL;
  65673. const SSL_CIPHER *cipher = NULL;
  65674. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  65675. SSL_CTX *ctx = NULL;
  65676. SSL *ssl = NULL;
  65677. char buf[256];
  65678. char test_str[9] = "0000000";
  65679. const char badStr[] = "unknown";
  65680. const char certPath[] = "./certs/client-cert.pem";
  65681. XMEMSET(buf, 0, sizeof(buf));
  65682. ExpectNotNull(method = TLSv1_2_client_method());
  65683. ExpectNotNull(ctx = SSL_CTX_new(method));
  65684. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  65685. SSL_CTX_set_verify_depth(ctx, 4);
  65686. SSL_CTX_set_options(ctx, flags);
  65687. ExpectIntEQ(SSL_CTX_load_verify_locations(ctx, certPath, NULL),
  65688. WOLFSSL_SUCCESS);
  65689. ExpectNotNull(ssl = SSL_new(ctx));
  65690. /* SSL_get_ciphers returns a stack of all configured ciphers
  65691. * A flag, getCipherAtOffset, is set to later have SSL_CIPHER_description
  65692. */
  65693. ExpectNotNull(supportedCiphers = SSL_get_ciphers(ssl));
  65694. /* loop through the amount of supportedCiphers */
  65695. numCiphers = sk_num(supportedCiphers);
  65696. for (i = 0; i < numCiphers; ++i) {
  65697. int j;
  65698. /* sk_value increments "sk->data.cipher->cipherOffset".
  65699. * wolfSSL_sk_CIPHER_description sets the description for
  65700. * the cipher based on the provided offset.
  65701. */
  65702. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  65703. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  65704. }
  65705. /* Search cipher description string for "unknown" descriptor */
  65706. for (j = 0; j < (int)XSTRLEN(buf); j++) {
  65707. int k = 0;
  65708. while ((k < (int)XSTRLEN(badStr)) && (buf[j] == badStr[k])) {
  65709. test_str[k] = badStr[k];
  65710. j++;
  65711. k++;
  65712. }
  65713. }
  65714. /* Fail if test_str == badStr == "unknown" */
  65715. ExpectStrNE(test_str,badStr);
  65716. }
  65717. SSL_free(ssl);
  65718. SSL_CTX_free(ctx);
  65719. #endif
  65720. return EXPECT_RESULT();
  65721. }
  65722. static int test_wolfSSL_get_ciphers_compat(void)
  65723. {
  65724. EXPECT_DECLS;
  65725. #if !defined(NO_RSA)
  65726. const SSL_METHOD *method = NULL;
  65727. const char certPath[] = "./certs/client-cert.pem";
  65728. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  65729. SSL_CTX *ctx = NULL;
  65730. WOLFSSL *ssl = NULL;
  65731. const long flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_COMPRESSION;
  65732. ExpectNotNull(method = SSLv23_client_method());
  65733. ExpectNotNull(ctx = SSL_CTX_new(method));
  65734. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  65735. SSL_CTX_set_verify_depth(ctx, 4);
  65736. SSL_CTX_set_options(ctx, flags);
  65737. ExpectIntEQ(SSL_CTX_load_verify_locations(ctx, certPath, NULL),
  65738. WOLFSSL_SUCCESS);
  65739. ExpectNotNull(ssl = SSL_new(ctx));
  65740. /* Test Bad NULL input */
  65741. ExpectNull(supportedCiphers = SSL_get_ciphers(NULL));
  65742. /* Test for Good input */
  65743. ExpectNotNull(supportedCiphers = SSL_get_ciphers(ssl));
  65744. /* Further usage of SSL_get_ciphers/wolfSSL_get_ciphers_compat is
  65745. * tested in test_wolfSSL_sk_CIPHER_description according to Qt usage */
  65746. SSL_free(ssl);
  65747. SSL_CTX_free(ctx);
  65748. #endif
  65749. return EXPECT_RESULT();
  65750. }
  65751. static int test_wolfSSL_X509_PUBKEY_get(void)
  65752. {
  65753. EXPECT_DECLS;
  65754. WOLFSSL_X509_PUBKEY pubkey;
  65755. WOLFSSL_X509_PUBKEY* key;
  65756. WOLFSSL_EVP_PKEY evpkey ;
  65757. WOLFSSL_EVP_PKEY* evpPkey;
  65758. WOLFSSL_EVP_PKEY* retEvpPkey;
  65759. XMEMSET(&pubkey, 0, sizeof(WOLFSSL_X509_PUBKEY));
  65760. XMEMSET(&evpkey, 0, sizeof(WOLFSSL_EVP_PKEY));
  65761. key = &pubkey;
  65762. evpPkey = &evpkey;
  65763. evpPkey->type = WOLFSSL_SUCCESS;
  65764. key->pkey = evpPkey;
  65765. ExpectNotNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(key));
  65766. ExpectIntEQ(retEvpPkey->type, WOLFSSL_SUCCESS);
  65767. ExpectNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(NULL));
  65768. key->pkey = NULL;
  65769. ExpectNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(key));
  65770. return EXPECT_RESULT();
  65771. }
  65772. static int test_wolfSSL_EVP_PKEY_set1_get1_DSA(void)
  65773. {
  65774. EXPECT_DECLS;
  65775. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  65776. DSA *dsa = NULL;
  65777. DSA *setDsa = NULL;
  65778. EVP_PKEY *pkey = NULL;
  65779. EVP_PKEY *set1Pkey = NULL;
  65780. SHA_CTX sha;
  65781. byte signature[DSA_SIG_SIZE];
  65782. byte hash[WC_SHA_DIGEST_SIZE];
  65783. word32 bytes;
  65784. int answer;
  65785. #ifdef USE_CERT_BUFFERS_1024
  65786. const unsigned char* dsaKeyDer = dsa_key_der_1024;
  65787. int dsaKeySz = sizeof_dsa_key_der_1024;
  65788. byte tmp[ONEK_BUF];
  65789. XMEMSET(tmp, 0, sizeof(tmp));
  65790. XMEMCPY(tmp, dsaKeyDer , dsaKeySz);
  65791. bytes = dsaKeySz;
  65792. #elif defined(USE_CERT_BUFFERS_2048)
  65793. const unsigned char* dsaKeyDer = dsa_key_der_2048;
  65794. int dsaKeySz = sizeof_dsa_key_der_2048;
  65795. byte tmp[TWOK_BUF];
  65796. XMEMSET(tmp, 0, sizeof(tmp));
  65797. XMEMCPY(tmp, dsaKeyDer , dsaKeySz);
  65798. bytes = (word32)dsaKeySz;
  65799. #else
  65800. byte tmp[TWOK_BUF];
  65801. const unsigned char* dsaKeyDer = (const unsigned char*)tmp;
  65802. int dsaKeySz;
  65803. XFILE fp = XBADFILE;
  65804. XMEMSET(tmp, 0, sizeof(tmp));
  65805. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  65806. ExpectIntGT(dsaKeySz = bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  65807. if (fp != XBADFILE)
  65808. XFCLOSE(fp);
  65809. #endif /* END USE_CERT_BUFFERS_1024 */
  65810. /* Create hash to later Sign and Verify */
  65811. ExpectIntEQ(SHA1_Init(&sha), WOLFSSL_SUCCESS);
  65812. ExpectIntEQ(SHA1_Update(&sha, tmp, bytes), WOLFSSL_SUCCESS);
  65813. ExpectIntEQ(SHA1_Final(hash,&sha), WOLFSSL_SUCCESS);
  65814. /* Initialize pkey with der format dsa key */
  65815. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_DSA, &pkey, &dsaKeyDer,
  65816. (long)dsaKeySz));
  65817. /* Test wolfSSL_EVP_PKEY_get1_DSA */
  65818. /* Should Fail: NULL argument */
  65819. ExpectNull(dsa = EVP_PKEY_get0_DSA(NULL));
  65820. ExpectNull(dsa = EVP_PKEY_get1_DSA(NULL));
  65821. /* Should Pass: Initialized pkey argument */
  65822. ExpectNotNull(dsa = EVP_PKEY_get0_DSA(pkey));
  65823. ExpectNotNull(dsa = EVP_PKEY_get1_DSA(pkey));
  65824. #ifdef USE_CERT_BUFFERS_1024
  65825. ExpectIntEQ(DSA_bits(dsa), 1024);
  65826. #else
  65827. ExpectIntEQ(DSA_bits(dsa), 2048);
  65828. #endif
  65829. /* Sign */
  65830. ExpectIntEQ(wolfSSL_DSA_do_sign(hash, signature, dsa), WOLFSSL_SUCCESS);
  65831. /* Verify. */
  65832. ExpectIntEQ(wolfSSL_DSA_do_verify(hash, signature, dsa, &answer),
  65833. WOLFSSL_SUCCESS);
  65834. /* Test wolfSSL_EVP_PKEY_set1_DSA */
  65835. /* Should Fail: set1Pkey not initialized */
  65836. ExpectIntNE(EVP_PKEY_set1_DSA(set1Pkey, dsa), WOLFSSL_SUCCESS);
  65837. /* Initialize set1Pkey */
  65838. set1Pkey = EVP_PKEY_new();
  65839. /* Should Fail Verify: setDsa not initialized from set1Pkey */
  65840. ExpectIntNE(wolfSSL_DSA_do_verify(hash,signature,setDsa,&answer),
  65841. WOLFSSL_SUCCESS);
  65842. /* Should Pass: set dsa into set1Pkey */
  65843. ExpectIntEQ(EVP_PKEY_set1_DSA(set1Pkey, dsa), WOLFSSL_SUCCESS);
  65844. DSA_free(dsa);
  65845. DSA_free(setDsa);
  65846. EVP_PKEY_free(pkey);
  65847. EVP_PKEY_free(set1Pkey);
  65848. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  65849. return EXPECT_RESULT();
  65850. } /* END test_EVP_PKEY_set1_get1_DSA */
  65851. static int test_wolfSSL_DSA_generate_parameters(void)
  65852. {
  65853. EXPECT_DECLS;
  65854. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN) && \
  65855. !defined(HAVE_FIPS)
  65856. DSA *dsa = NULL;
  65857. ExpectNotNull(dsa = DSA_generate_parameters(2048, NULL, 0, NULL, NULL, NULL,
  65858. NULL));
  65859. DSA_free(dsa);
  65860. #endif
  65861. return EXPECT_RESULT();
  65862. }
  65863. static int test_wolfSSL_DSA_SIG(void)
  65864. {
  65865. EXPECT_DECLS;
  65866. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN) && \
  65867. !defined(HAVE_FIPS)
  65868. DSA *dsa = NULL;
  65869. DSA *dsa2 = NULL;
  65870. DSA_SIG *sig = NULL;
  65871. const BIGNUM *p = NULL;
  65872. const BIGNUM *q = NULL;
  65873. const BIGNUM *g = NULL;
  65874. const BIGNUM *pub = NULL;
  65875. const BIGNUM *priv = NULL;
  65876. BIGNUM *dup_p = NULL;
  65877. BIGNUM *dup_q = NULL;
  65878. BIGNUM *dup_g = NULL;
  65879. BIGNUM *dup_pub = NULL;
  65880. BIGNUM *dup_priv = NULL;
  65881. const byte digest[WC_SHA_DIGEST_SIZE] = {0};
  65882. ExpectNotNull(dsa = DSA_new());
  65883. ExpectIntEQ(DSA_generate_parameters_ex(dsa, 2048, NULL, 0, NULL, NULL,
  65884. NULL), 1);
  65885. ExpectIntEQ(DSA_generate_key(dsa), 1);
  65886. DSA_get0_pqg(dsa, &p, &q, &g);
  65887. DSA_get0_key(dsa, &pub, &priv);
  65888. ExpectNotNull(dup_p = BN_dup(p));
  65889. ExpectNotNull(dup_q = BN_dup(q));
  65890. ExpectNotNull(dup_g = BN_dup(g));
  65891. ExpectNotNull(dup_pub = BN_dup(pub));
  65892. ExpectNotNull(dup_priv = BN_dup(priv));
  65893. ExpectNotNull(sig = DSA_do_sign(digest, sizeof(digest), dsa));
  65894. ExpectNotNull(dsa2 = DSA_new());
  65895. ExpectIntEQ(DSA_set0_pqg(dsa2, dup_p, dup_q, dup_g), 1);
  65896. if (EXPECT_FAIL()) {
  65897. BN_free(dup_p);
  65898. BN_free(dup_q);
  65899. BN_free(dup_g);
  65900. }
  65901. ExpectIntEQ(DSA_set0_key(dsa2, dup_pub, dup_priv), 1);
  65902. if (EXPECT_FAIL()) {
  65903. BN_free(dup_pub);
  65904. BN_free(dup_priv);
  65905. }
  65906. ExpectIntEQ(DSA_do_verify(digest, sizeof(digest), sig, dsa2), 1);
  65907. DSA_free(dsa);
  65908. DSA_free(dsa2);
  65909. DSA_SIG_free(sig);
  65910. #endif
  65911. return EXPECT_RESULT();
  65912. }
  65913. static int test_wolfSSL_EVP_PKEY_set1_get1_EC_KEY (void)
  65914. {
  65915. EXPECT_DECLS;
  65916. #ifdef HAVE_ECC
  65917. WOLFSSL_EC_KEY* ecKey = NULL;
  65918. WOLFSSL_EC_KEY* ecGet1 = NULL;
  65919. EVP_PKEY* pkey = NULL;
  65920. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  65921. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65922. /* Test wolfSSL_EVP_PKEY_set1_EC_KEY */
  65923. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(NULL, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65924. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65925. /* Should fail since ecKey is empty */
  65926. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65927. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  65928. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  65929. /* Test wolfSSL_EVP_PKEY_get1_EC_KEY */
  65930. ExpectNull(wolfSSL_EVP_PKEY_get1_EC_KEY(NULL));
  65931. ExpectNotNull(ecGet1 = wolfSSL_EVP_PKEY_get1_EC_KEY(pkey));
  65932. wolfSSL_EC_KEY_free(ecKey);
  65933. wolfSSL_EC_KEY_free(ecGet1);
  65934. EVP_PKEY_free(pkey);
  65935. #endif /* HAVE_ECC */
  65936. return EXPECT_RESULT();
  65937. } /* END test_EVP_PKEY_set1_get1_EC_KEY */
  65938. static int test_wolfSSL_EVP_PKEY_set1_get1_DH (void)
  65939. {
  65940. EXPECT_DECLS;
  65941. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || defined(WOLFSSL_OPENSSH)
  65942. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  65943. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  65944. DH *dh = NULL;
  65945. DH *setDh = NULL;
  65946. EVP_PKEY *pkey = NULL;
  65947. XFILE f = XBADFILE;
  65948. unsigned char buf[4096];
  65949. const unsigned char* pt = buf;
  65950. const char* dh2048 = "./certs/dh2048.der";
  65951. long len = 0;
  65952. int code = -1;
  65953. XMEMSET(buf, 0, sizeof(buf));
  65954. ExpectTrue((f = XFOPEN(dh2048, "rb")) != XBADFILE);
  65955. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  65956. if (f != XBADFILE)
  65957. XFCLOSE(f);
  65958. /* Load dh2048.der into DH with internal format */
  65959. ExpectNotNull(setDh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  65960. ExpectIntEQ(wolfSSL_DH_check(setDh, &code), WOLFSSL_SUCCESS);
  65961. ExpectIntEQ(code, 0);
  65962. code = -1;
  65963. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65964. /* Set DH into PKEY */
  65965. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_DH(pkey, setDh), WOLFSSL_SUCCESS);
  65966. /* Get DH from PKEY */
  65967. ExpectNotNull(dh = wolfSSL_EVP_PKEY_get1_DH(pkey));
  65968. ExpectIntEQ(wolfSSL_DH_check(dh, &code), WOLFSSL_SUCCESS);
  65969. ExpectIntEQ(code, 0);
  65970. EVP_PKEY_free(pkey);
  65971. DH_free(setDh);
  65972. setDh = NULL;
  65973. DH_free(dh);
  65974. dh = NULL;
  65975. #endif /* !NO_DH && WOLFSSL_DH_EXTRA && !NO_FILESYSTEM */
  65976. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  65977. #endif /* OPENSSL_ALL || WOLFSSL_QT || WOLFSSL_OPENSSH */
  65978. return EXPECT_RESULT();
  65979. } /* END test_EVP_PKEY_set1_get1_DH */
  65980. static int test_wolfSSL_CTX_ctrl(void)
  65981. {
  65982. EXPECT_DECLS;
  65983. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  65984. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  65985. char caFile[] = "./certs/client-ca.pem";
  65986. char clientFile[] = "./certs/client-cert.pem";
  65987. SSL_CTX* ctx = NULL;
  65988. X509* x509 = NULL;
  65989. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  65990. byte buf[6000];
  65991. char file[] = "./certs/dsaparams.pem";
  65992. XFILE f = XBADFILE;
  65993. int bytes = 0;
  65994. BIO* bio = NULL;
  65995. DSA* dsa = NULL;
  65996. DH* dh = NULL;
  65997. #endif
  65998. #ifdef HAVE_ECC
  65999. WOLFSSL_EC_KEY* ecKey = NULL;
  66000. #endif
  66001. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  66002. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caFile,
  66003. WOLFSSL_FILETYPE_PEM));
  66004. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WOLFSSL_SUCCESS);
  66005. if (EXPECT_FAIL()) {
  66006. wolfSSL_X509_free(x509);
  66007. }
  66008. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(clientFile,
  66009. WOLFSSL_FILETYPE_PEM));
  66010. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  66011. /* Initialize DH */
  66012. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  66013. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  66014. if (f != XBADFILE)
  66015. XFCLOSE(f);
  66016. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  66017. ExpectNotNull(dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL));
  66018. ExpectNotNull(dh = wolfSSL_DSA_dup_DH(dsa));
  66019. #endif
  66020. #ifdef HAVE_ECC
  66021. /* Initialize WOLFSSL_EC_KEY */
  66022. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  66023. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  66024. #endif
  66025. /* additional test of getting EVP_PKEY key size from X509
  66026. * Do not run with user RSA because wolfSSL_RSA_size is not currently
  66027. * allowed with user RSA */
  66028. {
  66029. EVP_PKEY* pkey = NULL;
  66030. #if defined(HAVE_ECC)
  66031. X509* ecX509 = NULL;
  66032. #endif /* HAVE_ECC */
  66033. ExpectNotNull(pkey = X509_get_pubkey(x509));
  66034. /* current RSA key is 2048 bit (256 bytes) */
  66035. ExpectIntEQ(EVP_PKEY_size(pkey), 256);
  66036. EVP_PKEY_free(pkey);
  66037. pkey = NULL;
  66038. #if defined(HAVE_ECC)
  66039. #if defined(USE_CERT_BUFFERS_256)
  66040. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_buffer(
  66041. cliecc_cert_der_256, sizeof_cliecc_cert_der_256,
  66042. SSL_FILETYPE_ASN1));
  66043. #else
  66044. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_file(
  66045. cliEccCertFile, SSL_FILETYPE_PEM));
  66046. #endif
  66047. ExpectNotNull(pkey = X509_get_pubkey(ecX509));
  66048. /* current ECC key is 256 bit (32 bytes) */
  66049. ExpectIntEQ(EVP_PKEY_size(pkey), 32);
  66050. X509_free(ecX509);
  66051. EVP_PKEY_free(pkey);
  66052. #endif /* HAVE_ECC */
  66053. }
  66054. /* Tests should fail with passed in NULL pointer */
  66055. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0, NULL),
  66056. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66057. #if !defined(NO_DH) && !defined(NO_DSA)
  66058. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_DH, 0, NULL),
  66059. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66060. #endif
  66061. #ifdef HAVE_ECC
  66062. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_ECDH, 0, NULL),
  66063. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66064. #endif
  66065. /* Test with SSL_CTRL_EXTRA_CHAIN_CERT
  66066. * wolfSSL_CTX_ctrl should succesffuly call SSL_CTX_add_extra_chain_cert
  66067. */
  66068. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0, x509),
  66069. SSL_SUCCESS);
  66070. if (EXPECT_FAIL()) {
  66071. wolfSSL_X509_free(x509);
  66072. }
  66073. /* Test with SSL_CTRL_OPTIONS
  66074. * wolfSSL_CTX_ctrl should succesffuly call SSL_CTX_set_options
  66075. */
  66076. ExpectTrue(wolfSSL_CTX_ctrl(ctx, SSL_CTRL_OPTIONS, SSL_OP_NO_TLSv1,
  66077. NULL) == SSL_OP_NO_TLSv1);
  66078. ExpectTrue(SSL_CTX_get_options(ctx) == SSL_OP_NO_TLSv1);
  66079. /* Test with SSL_CTRL_SET_TMP_DH
  66080. * wolfSSL_CTX_ctrl should succesffuly call wolfSSL_SSL_CTX_set_tmp_dh
  66081. */
  66082. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  66083. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_DH, 0, dh),
  66084. SSL_SUCCESS);
  66085. #endif
  66086. /* Test with SSL_CTRL_SET_TMP_ECDH
  66087. * wolfSSL_CTX_ctrl should succesffuly call wolfSSL_SSL_CTX_set_tmp_ecdh
  66088. */
  66089. #ifdef HAVE_ECC
  66090. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_ECDH, 0, ecKey),
  66091. SSL_SUCCESS);
  66092. #endif
  66093. #ifdef WOLFSSL_ENCRYPTED_KEYS
  66094. ExpectNull(SSL_CTX_get_default_passwd_cb(ctx));
  66095. ExpectNull(SSL_CTX_get_default_passwd_cb_userdata(ctx));
  66096. #endif
  66097. /* Test for min/max proto */
  66098. #ifndef WOLFSSL_NO_TLS12
  66099. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION,
  66100. 0, NULL), SSL_SUCCESS);
  66101. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION,
  66102. TLS1_2_VERSION, NULL), SSL_SUCCESS);
  66103. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_2_VERSION);
  66104. #endif
  66105. #ifdef WOLFSSL_TLS13
  66106. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  66107. 0, NULL), SSL_SUCCESS);
  66108. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  66109. TLS1_3_VERSION, NULL), SSL_SUCCESS);
  66110. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx), TLS1_3_VERSION);
  66111. #ifndef WOLFSSL_NO_TLS12
  66112. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  66113. TLS1_2_VERSION, NULL), SSL_SUCCESS);
  66114. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx), TLS1_2_VERSION);
  66115. #endif
  66116. #endif
  66117. /* Cleanup and Pass */
  66118. #if !defined(NO_DH) && !defined(NO_DSA)
  66119. #ifndef NO_BIO
  66120. BIO_free(bio);
  66121. DSA_free(dsa);
  66122. DH_free(dh);
  66123. dh = NULL;
  66124. #endif
  66125. #endif
  66126. #ifdef HAVE_ECC
  66127. wolfSSL_EC_KEY_free(ecKey);
  66128. #endif
  66129. SSL_CTX_free(ctx);
  66130. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  66131. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  66132. return EXPECT_RESULT();
  66133. }
  66134. static int test_wolfSSL_EVP_PKEY_assign(void)
  66135. {
  66136. EXPECT_DECLS;
  66137. #if !defined(NO_RSA) || !defined(NO_DSA) || defined(HAVE_ECC)
  66138. int type;
  66139. WOLFSSL_EVP_PKEY* pkey = NULL;
  66140. #ifndef NO_RSA
  66141. WOLFSSL_RSA* rsa = NULL;
  66142. #endif
  66143. #ifndef NO_DSA
  66144. WOLFSSL_DSA* dsa = NULL;
  66145. #endif
  66146. #ifdef HAVE_ECC
  66147. WOLFSSL_EC_KEY* ecKey = NULL;
  66148. #endif
  66149. #ifndef NO_RSA
  66150. type = EVP_PKEY_RSA;
  66151. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66152. ExpectNotNull(rsa = wolfSSL_RSA_new());
  66153. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66154. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66155. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66156. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, rsa), WOLFSSL_SUCCESS);
  66157. if (EXPECT_FAIL()) {
  66158. wolfSSL_RSA_free(rsa);
  66159. }
  66160. wolfSSL_EVP_PKEY_free(pkey);
  66161. pkey = NULL;
  66162. #endif /* NO_RSA */
  66163. #ifndef NO_DSA
  66164. type = EVP_PKEY_DSA;
  66165. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66166. ExpectNotNull(dsa = wolfSSL_DSA_new());
  66167. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, dsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66168. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66169. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, dsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66170. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, dsa), WOLFSSL_SUCCESS);
  66171. if (EXPECT_FAIL()) {
  66172. wolfSSL_DSA_free(dsa);
  66173. }
  66174. wolfSSL_EVP_PKEY_free(pkey);
  66175. pkey = NULL;
  66176. #endif /* NO_DSA */
  66177. #ifdef HAVE_ECC
  66178. type = EVP_PKEY_EC;
  66179. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66180. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  66181. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66182. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66183. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66184. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66185. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  66186. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, ecKey), WOLFSSL_SUCCESS);
  66187. if (EXPECT_FAIL()) {
  66188. wolfSSL_EC_KEY_free(ecKey);
  66189. }
  66190. wolfSSL_EVP_PKEY_free(pkey);
  66191. pkey = NULL;
  66192. #endif /* HAVE_ECC */
  66193. #endif /* !NO_RSA || !NO_DSA || HAVE_ECC */
  66194. return EXPECT_RESULT();
  66195. }
  66196. static int test_wolfSSL_EVP_PKEY_assign_DH(void)
  66197. {
  66198. EXPECT_DECLS;
  66199. #if !defined(NO_DH) && \
  66200. !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  66201. XFILE f = XBADFILE;
  66202. unsigned char buf[4096];
  66203. const unsigned char* pt = buf;
  66204. const char* params1 = "./certs/dh2048.der";
  66205. long len = 0;
  66206. WOLFSSL_DH* dh = NULL;
  66207. WOLFSSL_EVP_PKEY* pkey = NULL;
  66208. XMEMSET(buf, 0, sizeof(buf));
  66209. /* Load DH parameters DER. */
  66210. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  66211. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  66212. if (f != XBADFILE)
  66213. XFCLOSE(f);
  66214. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  66215. ExpectIntEQ(DH_generate_key(dh), WOLFSSL_SUCCESS);
  66216. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66217. /* Bad cases */
  66218. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(NULL, dh), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66219. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66220. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66221. /* Good case */
  66222. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(pkey, dh), WOLFSSL_SUCCESS);
  66223. if (EXPECT_FAIL()) {
  66224. wolfSSL_DH_free(dh);
  66225. }
  66226. EVP_PKEY_free(pkey);
  66227. #endif
  66228. return EXPECT_RESULT();
  66229. }
  66230. static int test_wolfSSL_EVP_PKEY_base_id(void)
  66231. {
  66232. EXPECT_DECLS;
  66233. WOLFSSL_EVP_PKEY* pkey = NULL;
  66234. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66235. ExpectIntEQ(wolfSSL_EVP_PKEY_base_id(NULL), NID_undef);
  66236. ExpectIntEQ(wolfSSL_EVP_PKEY_base_id(pkey), EVP_PKEY_RSA);
  66237. EVP_PKEY_free(pkey);
  66238. return EXPECT_RESULT();
  66239. }
  66240. static int test_wolfSSL_EVP_PKEY_id(void)
  66241. {
  66242. EXPECT_DECLS;
  66243. WOLFSSL_EVP_PKEY* pkey = NULL;
  66244. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66245. ExpectIntEQ(wolfSSL_EVP_PKEY_id(NULL), 0);
  66246. ExpectIntEQ(wolfSSL_EVP_PKEY_id(pkey), EVP_PKEY_RSA);
  66247. EVP_PKEY_free(pkey);
  66248. return EXPECT_RESULT();
  66249. }
  66250. static int test_wolfSSL_EVP_PKEY_paramgen(void)
  66251. {
  66252. EXPECT_DECLS;
  66253. /* ECC check taken from ecc.c. It is the condition that defines ECC256 */
  66254. #if defined(OPENSSL_ALL) && !defined(NO_ECC_SECP) && \
  66255. ((!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  66256. ECC_MIN_KEY_SZ <= 256)
  66257. EVP_PKEY_CTX* ctx = NULL;
  66258. EVP_PKEY* pkey = NULL;
  66259. /* Test error conditions. */
  66260. ExpectIntEQ(EVP_PKEY_paramgen(NULL, &pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66261. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL));
  66262. ExpectIntEQ(EVP_PKEY_paramgen(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66263. #ifndef NO_RSA
  66264. EVP_PKEY_CTX_free(ctx);
  66265. /* Parameter generation for RSA not supported yet. */
  66266. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL));
  66267. ExpectIntEQ(EVP_PKEY_paramgen(ctx, &pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66268. #endif
  66269. #ifdef HAVE_ECC
  66270. EVP_PKEY_CTX_free(ctx);
  66271. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL));
  66272. ExpectIntEQ(EVP_PKEY_paramgen_init(ctx), WOLFSSL_SUCCESS);
  66273. ExpectIntEQ(EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx,
  66274. NID_X9_62_prime256v1), WOLFSSL_SUCCESS);
  66275. ExpectIntEQ(EVP_PKEY_paramgen(ctx, &pkey), WOLFSSL_SUCCESS);
  66276. ExpectIntEQ(EVP_PKEY_CTX_set_ec_param_enc(ctx, OPENSSL_EC_NAMED_CURVE),
  66277. WOLFSSL_SUCCESS);
  66278. ExpectIntEQ(EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  66279. ExpectIntEQ(EVP_PKEY_keygen(ctx, &pkey), WOLFSSL_SUCCESS);
  66280. #endif
  66281. EVP_PKEY_CTX_free(ctx);
  66282. EVP_PKEY_free(pkey);
  66283. #endif
  66284. return EXPECT_RESULT();
  66285. }
  66286. static int test_wolfSSL_EVP_PKEY_keygen(void)
  66287. {
  66288. EXPECT_DECLS;
  66289. WOLFSSL_EVP_PKEY* pkey = NULL;
  66290. EVP_PKEY_CTX* ctx = NULL;
  66291. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  66292. WOLFSSL_EVP_PKEY* params = NULL;
  66293. DH* dh = NULL;
  66294. const BIGNUM* pubkey = NULL;
  66295. const BIGNUM* privkey = NULL;
  66296. ASN1_INTEGER* asn1int = NULL;
  66297. unsigned int length = 0;
  66298. byte* derBuffer = NULL;
  66299. #endif
  66300. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66301. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  66302. /* Bad cases */
  66303. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(NULL, &pkey), 0);
  66304. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(ctx, NULL), 0);
  66305. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(NULL, NULL), 0);
  66306. /* Good case */
  66307. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(ctx, &pkey), 0);
  66308. EVP_PKEY_CTX_free(ctx);
  66309. ctx = NULL;
  66310. EVP_PKEY_free(pkey);
  66311. pkey = NULL;
  66312. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  66313. /* Test DH keygen */
  66314. {
  66315. ExpectNotNull(params = wolfSSL_EVP_PKEY_new());
  66316. ExpectNotNull(dh = DH_get_2048_256());
  66317. ExpectIntEQ(EVP_PKEY_set1_DH(params, dh), WOLFSSL_SUCCESS);
  66318. ExpectNotNull(ctx = EVP_PKEY_CTX_new(params, NULL));
  66319. ExpectIntEQ(EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  66320. ExpectIntEQ(EVP_PKEY_keygen(ctx, &pkey), WOLFSSL_SUCCESS);
  66321. DH_free(dh);
  66322. dh = NULL;
  66323. EVP_PKEY_CTX_free(ctx);
  66324. EVP_PKEY_free(params);
  66325. /* try exporting generated key to DER, to verify */
  66326. ExpectNotNull(dh = EVP_PKEY_get1_DH(pkey));
  66327. DH_get0_key(dh, &pubkey, &privkey);
  66328. ExpectNotNull(pubkey);
  66329. ExpectNotNull(privkey);
  66330. ExpectNotNull(asn1int = BN_to_ASN1_INTEGER(pubkey, NULL));
  66331. ExpectIntGT((length = i2d_ASN1_INTEGER(asn1int, &derBuffer)), 0);
  66332. ASN1_INTEGER_free(asn1int);
  66333. DH_free(dh);
  66334. dh = NULL;
  66335. XFREE(derBuffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66336. EVP_PKEY_free(pkey);
  66337. }
  66338. #endif
  66339. return EXPECT_RESULT();
  66340. }
  66341. static int test_wolfSSL_EVP_PKEY_keygen_init(void)
  66342. {
  66343. EXPECT_DECLS;
  66344. WOLFSSL_EVP_PKEY* pkey = NULL;
  66345. EVP_PKEY_CTX *ctx = NULL;
  66346. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66347. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  66348. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  66349. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen_init(NULL), WOLFSSL_SUCCESS);
  66350. EVP_PKEY_CTX_free(ctx);
  66351. EVP_PKEY_free(pkey);
  66352. return EXPECT_RESULT();
  66353. }
  66354. static int test_wolfSSL_EVP_PKEY_missing_parameters(void)
  66355. {
  66356. EXPECT_DECLS;
  66357. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_STUB)
  66358. WOLFSSL_EVP_PKEY* pkey = NULL;
  66359. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66360. ExpectIntEQ(wolfSSL_EVP_PKEY_missing_parameters(pkey), 0);
  66361. ExpectIntEQ(wolfSSL_EVP_PKEY_missing_parameters(NULL), 0);
  66362. EVP_PKEY_free(pkey);
  66363. #endif
  66364. return EXPECT_RESULT();
  66365. }
  66366. static int test_wolfSSL_EVP_PKEY_copy_parameters(void)
  66367. {
  66368. EXPECT_DECLS;
  66369. #if defined(OPENSSL_EXTRA) && !defined(NO_DH) && defined(WOLFSSL_KEY_GEN) && \
  66370. !defined(HAVE_SELFTEST) && (defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || \
  66371. defined(WOLFSSL_OPENSSH)) && defined(WOLFSSL_DH_EXTRA) && \
  66372. !defined(NO_FILESYSTEM)
  66373. WOLFSSL_EVP_PKEY* params = NULL;
  66374. WOLFSSL_EVP_PKEY* copy = NULL;
  66375. DH* dh = NULL;
  66376. BIGNUM* p1;
  66377. BIGNUM* g1;
  66378. BIGNUM* q1;
  66379. BIGNUM* p2;
  66380. BIGNUM* g2;
  66381. BIGNUM* q2;
  66382. /* create DH with DH_get_2048_256 params */
  66383. ExpectNotNull(params = wolfSSL_EVP_PKEY_new());
  66384. ExpectNotNull(dh = DH_get_2048_256());
  66385. ExpectIntEQ(EVP_PKEY_set1_DH(params, dh), WOLFSSL_SUCCESS);
  66386. DH_get0_pqg(dh, (const BIGNUM**)&p1,
  66387. (const BIGNUM**)&q1,
  66388. (const BIGNUM**)&g1);
  66389. DH_free(dh);
  66390. dh = NULL;
  66391. /* create DH with random generated DH params */
  66392. ExpectNotNull(copy = wolfSSL_EVP_PKEY_new());
  66393. ExpectNotNull(dh = DH_generate_parameters(2048, 2, NULL, NULL));
  66394. ExpectIntEQ(EVP_PKEY_set1_DH(copy, dh), WOLFSSL_SUCCESS);
  66395. DH_free(dh);
  66396. dh = NULL;
  66397. ExpectIntEQ(EVP_PKEY_copy_parameters(copy, params), WOLFSSL_SUCCESS);
  66398. ExpectNotNull(dh = EVP_PKEY_get1_DH(copy));
  66399. ExpectNotNull(dh->p);
  66400. ExpectNotNull(dh->g);
  66401. ExpectNotNull(dh->q);
  66402. DH_get0_pqg(dh, (const BIGNUM**)&p2,
  66403. (const BIGNUM**)&q2,
  66404. (const BIGNUM**)&g2);
  66405. ExpectIntEQ(BN_cmp(p1, p2), 0);
  66406. ExpectIntEQ(BN_cmp(q1, q2), 0);
  66407. ExpectIntEQ(BN_cmp(g1, g2), 0);
  66408. DH_free(dh);
  66409. dh = NULL;
  66410. EVP_PKEY_free(copy);
  66411. EVP_PKEY_free(params);
  66412. #endif
  66413. return EXPECT_RESULT();
  66414. }
  66415. static int test_wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits(void)
  66416. {
  66417. EXPECT_DECLS;
  66418. WOLFSSL_EVP_PKEY* pkey = NULL;
  66419. EVP_PKEY_CTX* ctx = NULL;
  66420. int bits = 2048;
  66421. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66422. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  66423. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits),
  66424. WOLFSSL_SUCCESS);
  66425. EVP_PKEY_CTX_free(ctx);
  66426. EVP_PKEY_free(pkey);
  66427. return EXPECT_RESULT();
  66428. }
  66429. static int test_wolfSSL_EVP_CIPHER_CTX_iv_length(void)
  66430. {
  66431. EXPECT_DECLS;
  66432. /* This is large enough to be used for all key sizes */
  66433. byte key[AES_256_KEY_SIZE] = {0};
  66434. byte iv[AES_BLOCK_SIZE] = {0};
  66435. int i;
  66436. int nids[] = {
  66437. #ifdef HAVE_AES_CBC
  66438. NID_aes_128_cbc,
  66439. #endif
  66440. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  66441. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  66442. #ifdef HAVE_AESGCM
  66443. NID_aes_128_gcm,
  66444. #endif
  66445. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  66446. #ifdef WOLFSSL_AES_COUNTER
  66447. NID_aes_128_ctr,
  66448. #endif
  66449. #ifndef NO_DES3
  66450. NID_des_cbc,
  66451. NID_des_ede3_cbc,
  66452. #endif
  66453. };
  66454. int iv_lengths[] = {
  66455. #ifdef HAVE_AES_CBC
  66456. AES_BLOCK_SIZE,
  66457. #endif
  66458. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  66459. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  66460. #ifdef HAVE_AESGCM
  66461. GCM_NONCE_MID_SZ,
  66462. #endif
  66463. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  66464. #ifdef WOLFSSL_AES_COUNTER
  66465. AES_BLOCK_SIZE,
  66466. #endif
  66467. #ifndef NO_DES3
  66468. DES_BLOCK_SIZE,
  66469. DES_BLOCK_SIZE,
  66470. #endif
  66471. };
  66472. int nidsLen = (sizeof(nids)/sizeof(int));
  66473. for (i = 0; i < nidsLen; i++) {
  66474. const EVP_CIPHER* init = wolfSSL_EVP_get_cipherbynid(nids[i]);
  66475. EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
  66476. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  66477. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  66478. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_iv_length(ctx), iv_lengths[i]);
  66479. EVP_CIPHER_CTX_free(ctx);
  66480. }
  66481. return EXPECT_RESULT();
  66482. }
  66483. static int test_wolfSSL_EVP_CIPHER_CTX_key_length(void)
  66484. {
  66485. EXPECT_DECLS;
  66486. byte key[AES_256_KEY_SIZE] = {0};
  66487. byte iv[AES_BLOCK_SIZE] = {0};
  66488. int i;
  66489. int nids[] = {
  66490. #ifdef HAVE_AES_CBC
  66491. NID_aes_128_cbc,
  66492. NID_aes_256_cbc,
  66493. #endif
  66494. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  66495. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  66496. #ifdef HAVE_AESGCM
  66497. NID_aes_128_gcm,
  66498. NID_aes_256_gcm,
  66499. #endif
  66500. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  66501. #ifdef WOLFSSL_AES_COUNTER
  66502. NID_aes_128_ctr,
  66503. NID_aes_256_ctr,
  66504. #endif
  66505. #ifndef NO_DES3
  66506. NID_des_cbc,
  66507. NID_des_ede3_cbc,
  66508. #endif
  66509. };
  66510. int key_lengths[] = {
  66511. #ifdef HAVE_AES_CBC
  66512. AES_128_KEY_SIZE,
  66513. AES_256_KEY_SIZE,
  66514. #endif
  66515. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  66516. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  66517. #ifdef HAVE_AESGCM
  66518. AES_128_KEY_SIZE,
  66519. AES_256_KEY_SIZE,
  66520. #endif
  66521. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  66522. #ifdef WOLFSSL_AES_COUNTER
  66523. AES_128_KEY_SIZE,
  66524. AES_256_KEY_SIZE,
  66525. #endif
  66526. #ifndef NO_DES3
  66527. DES_KEY_SIZE,
  66528. DES3_KEY_SIZE,
  66529. #endif
  66530. };
  66531. int nidsLen = (sizeof(nids)/sizeof(int));
  66532. for (i = 0; i < nidsLen; i++) {
  66533. const EVP_CIPHER *init = wolfSSL_EVP_get_cipherbynid(nids[i]);
  66534. EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
  66535. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  66536. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  66537. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_key_length(ctx), key_lengths[i]);
  66538. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_key_length(ctx, key_lengths[i]),
  66539. WOLFSSL_SUCCESS);
  66540. EVP_CIPHER_CTX_free(ctx);
  66541. }
  66542. return EXPECT_RESULT();
  66543. }
  66544. static int test_wolfSSL_EVP_CIPHER_CTX_set_iv(void)
  66545. {
  66546. EXPECT_DECLS;
  66547. #if defined(HAVE_AESGCM) && !defined(NO_DES3)
  66548. int ivLen, keyLen;
  66549. EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
  66550. #ifdef HAVE_AESGCM
  66551. byte key[AES_128_KEY_SIZE] = {0};
  66552. byte iv[AES_BLOCK_SIZE] = {0};
  66553. const EVP_CIPHER *init = EVP_aes_128_gcm();
  66554. #else
  66555. byte key[DES3_KEY_SIZE] = {0};
  66556. byte iv[DES_BLOCK_SIZE] = {0};
  66557. const EVP_CIPHER *init = EVP_des_ede3_cbc();
  66558. #endif
  66559. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  66560. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  66561. ivLen = wolfSSL_EVP_CIPHER_CTX_iv_length(ctx);
  66562. keyLen = wolfSSL_EVP_CIPHER_CTX_key_length(ctx);
  66563. /* Bad cases */
  66564. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(NULL, iv, ivLen),
  66565. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66566. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, NULL, ivLen),
  66567. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66568. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66569. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66570. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, keyLen),
  66571. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66572. /* Good case */
  66573. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, ivLen), 1);
  66574. EVP_CIPHER_CTX_free(ctx);
  66575. #endif
  66576. return EXPECT_RESULT();
  66577. }
  66578. static int test_wolfSSL_EVP_PKEY_CTX_new_id(void)
  66579. {
  66580. EXPECT_DECLS;
  66581. WOLFSSL_ENGINE* e = NULL;
  66582. int id = 0;
  66583. EVP_PKEY_CTX *ctx = NULL;
  66584. ExpectNotNull(ctx = wolfSSL_EVP_PKEY_CTX_new_id(id, e));
  66585. EVP_PKEY_CTX_free(ctx);
  66586. return EXPECT_RESULT();
  66587. }
  66588. static int test_wolfSSL_EVP_rc4(void)
  66589. {
  66590. EXPECT_DECLS;
  66591. #if !defined(NO_RC4)
  66592. ExpectNotNull(wolfSSL_EVP_rc4());
  66593. #endif
  66594. return EXPECT_RESULT();
  66595. }
  66596. static int test_wolfSSL_EVP_enc_null(void)
  66597. {
  66598. EXPECT_DECLS;
  66599. ExpectNotNull(wolfSSL_EVP_enc_null());
  66600. return EXPECT_RESULT();
  66601. }
  66602. static int test_wolfSSL_EVP_rc2_cbc(void)
  66603. {
  66604. EXPECT_DECLS;
  66605. #if defined(WOLFSSL_QT) && !defined(NO_WOLFSSL_STUB)
  66606. ExpectNull(wolfSSL_EVP_rc2_cbc());
  66607. #endif
  66608. return EXPECT_RESULT();
  66609. }
  66610. static int test_wolfSSL_EVP_mdc2(void)
  66611. {
  66612. EXPECT_DECLS;
  66613. #if !defined(NO_WOLFSSL_STUB)
  66614. ExpectNull(wolfSSL_EVP_mdc2());
  66615. #endif
  66616. return EXPECT_RESULT();
  66617. }
  66618. static int test_wolfSSL_EVP_md4(void)
  66619. {
  66620. EXPECT_DECLS;
  66621. #if !defined(NO_MD4)
  66622. ExpectNotNull(wolfSSL_EVP_md4());
  66623. #endif
  66624. return EXPECT_RESULT();
  66625. }
  66626. static int test_wolfSSL_EVP_aes_256_gcm(void)
  66627. {
  66628. EXPECT_DECLS;
  66629. #ifdef HAVE_AESGCM
  66630. ExpectNotNull(wolfSSL_EVP_aes_256_gcm());
  66631. #endif
  66632. return EXPECT_RESULT();
  66633. }
  66634. static int test_wolfSSL_EVP_aes_192_gcm(void)
  66635. {
  66636. EXPECT_DECLS;
  66637. #ifdef HAVE_AESGCM
  66638. ExpectNotNull(wolfSSL_EVP_aes_192_gcm());
  66639. #endif
  66640. return EXPECT_RESULT();
  66641. }
  66642. static int test_wolfSSL_EVP_aes_256_ccm(void)
  66643. {
  66644. EXPECT_DECLS;
  66645. #ifdef HAVE_AESCCM
  66646. ExpectNotNull(wolfSSL_EVP_aes_256_ccm());
  66647. #endif
  66648. return EXPECT_RESULT();
  66649. }
  66650. static int test_wolfSSL_EVP_aes_192_ccm(void)
  66651. {
  66652. EXPECT_DECLS;
  66653. #ifdef HAVE_AESCCM
  66654. ExpectNotNull(wolfSSL_EVP_aes_192_ccm());
  66655. #endif
  66656. return EXPECT_RESULT();
  66657. }
  66658. static int test_wolfSSL_EVP_aes_128_ccm(void)
  66659. {
  66660. EXPECT_DECLS;
  66661. #ifdef HAVE_AESCCM
  66662. ExpectNotNull(wolfSSL_EVP_aes_128_ccm());
  66663. #endif
  66664. return EXPECT_RESULT();
  66665. }
  66666. static int test_wolfSSL_EVP_ripemd160(void)
  66667. {
  66668. EXPECT_DECLS;
  66669. #if !defined(NO_WOLFSSL_STUB)
  66670. ExpectNull(wolfSSL_EVP_ripemd160());
  66671. #endif
  66672. return EXPECT_RESULT();
  66673. }
  66674. static int test_wolfSSL_EVP_get_digestbynid(void)
  66675. {
  66676. EXPECT_DECLS;
  66677. #ifndef NO_MD5
  66678. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_md5));
  66679. #endif
  66680. #ifndef NO_SHA
  66681. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_sha1));
  66682. #endif
  66683. #ifndef NO_SHA256
  66684. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_sha256));
  66685. #endif
  66686. ExpectNull(wolfSSL_EVP_get_digestbynid(0));
  66687. return EXPECT_RESULT();
  66688. }
  66689. static int test_wolfSSL_EVP_MD_nid(void)
  66690. {
  66691. EXPECT_DECLS;
  66692. #ifndef NO_MD5
  66693. ExpectIntEQ(EVP_MD_nid(EVP_md5()), NID_md5);
  66694. #endif
  66695. #ifndef NO_SHA
  66696. ExpectIntEQ(EVP_MD_nid(EVP_sha1()), NID_sha1);
  66697. #endif
  66698. #ifndef NO_SHA256
  66699. ExpectIntEQ(EVP_MD_nid(EVP_sha256()), NID_sha256);
  66700. #endif
  66701. ExpectIntEQ(EVP_MD_nid(NULL), NID_undef);
  66702. return EXPECT_RESULT();
  66703. }
  66704. static int test_wolfSSL_EVP_PKEY_get0_EC_KEY(void)
  66705. {
  66706. EXPECT_DECLS;
  66707. #if defined(HAVE_ECC)
  66708. WOLFSSL_EVP_PKEY* pkey = NULL;
  66709. ExpectNull(EVP_PKEY_get0_EC_KEY(NULL));
  66710. ExpectNotNull(pkey = EVP_PKEY_new());
  66711. ExpectNull(EVP_PKEY_get0_EC_KEY(pkey));
  66712. EVP_PKEY_free(pkey);
  66713. #endif
  66714. return EXPECT_RESULT();
  66715. }
  66716. static int test_wolfSSL_EVP_X_STATE(void)
  66717. {
  66718. EXPECT_DECLS;
  66719. #if !defined(NO_DES3) && !defined(NO_RC4)
  66720. byte key[DES3_KEY_SIZE] = {0};
  66721. byte iv[DES_IV_SIZE] = {0};
  66722. EVP_CIPHER_CTX *ctx = NULL;
  66723. const EVP_CIPHER *init = NULL;
  66724. /* Bad test cases */
  66725. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  66726. ExpectNotNull(init = EVP_des_ede3_cbc());
  66727. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  66728. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  66729. ExpectNull(wolfSSL_EVP_X_STATE(NULL));
  66730. ExpectNull(wolfSSL_EVP_X_STATE(ctx));
  66731. EVP_CIPHER_CTX_free(ctx);
  66732. ctx = NULL;
  66733. /* Good test case */
  66734. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  66735. ExpectNotNull(init = wolfSSL_EVP_rc4());
  66736. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  66737. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  66738. ExpectNotNull(wolfSSL_EVP_X_STATE(ctx));
  66739. EVP_CIPHER_CTX_free(ctx);
  66740. #endif
  66741. return EXPECT_RESULT();
  66742. }
  66743. static int test_wolfSSL_EVP_X_STATE_LEN(void)
  66744. {
  66745. EXPECT_DECLS;
  66746. #if !defined(NO_DES3) && !defined(NO_RC4)
  66747. byte key[DES3_KEY_SIZE] = {0};
  66748. byte iv[DES_IV_SIZE] = {0};
  66749. EVP_CIPHER_CTX *ctx = NULL;
  66750. const EVP_CIPHER *init = NULL;
  66751. /* Bad test cases */
  66752. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  66753. ExpectNotNull(init = EVP_des_ede3_cbc());
  66754. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  66755. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  66756. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(NULL), 0);
  66757. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(ctx), 0);
  66758. EVP_CIPHER_CTX_free(ctx);
  66759. ctx = NULL;
  66760. /* Good test case */
  66761. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  66762. ExpectNotNull(init = wolfSSL_EVP_rc4());
  66763. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  66764. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  66765. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(ctx), sizeof(Arc4));
  66766. EVP_CIPHER_CTX_free(ctx);
  66767. #endif
  66768. return EXPECT_RESULT();
  66769. }
  66770. static int test_wolfSSL_EVP_CIPHER_block_size(void)
  66771. {
  66772. EXPECT_DECLS;
  66773. #if defined(HAVE_AES_CBC) || defined(HAVE_AESGCM) || \
  66774. defined(WOLFSSL_AES_COUNTER) || defined(HAVE_AES_ECB) || \
  66775. defined(WOLFSSL_AES_OFB) || !defined(NO_RC4) || \
  66776. (defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
  66777. #ifdef HAVE_AES_CBC
  66778. #ifdef WOLFSSL_AES_128
  66779. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_cbc()), AES_BLOCK_SIZE);
  66780. #endif
  66781. #ifdef WOLFSSL_AES_192
  66782. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_cbc()), AES_BLOCK_SIZE);
  66783. #endif
  66784. #ifdef WOLFSSL_AES_256
  66785. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_cbc()), AES_BLOCK_SIZE);
  66786. #endif
  66787. #endif
  66788. #ifdef HAVE_AESGCM
  66789. #ifdef WOLFSSL_AES_128
  66790. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_gcm()), 1);
  66791. #endif
  66792. #ifdef WOLFSSL_AES_192
  66793. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_gcm()), 1);
  66794. #endif
  66795. #ifdef WOLFSSL_AES_256
  66796. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_gcm()), 1);
  66797. #endif
  66798. #endif
  66799. #ifdef HAVE_AESCCM
  66800. #ifdef WOLFSSL_AES_128
  66801. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ccm()), 1);
  66802. #endif
  66803. #ifdef WOLFSSL_AES_192
  66804. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ccm()), 1);
  66805. #endif
  66806. #ifdef WOLFSSL_AES_256
  66807. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ccm()), 1);
  66808. #endif
  66809. #endif
  66810. #ifdef WOLFSSL_AES_COUNTER
  66811. #ifdef WOLFSSL_AES_128
  66812. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ctr()), 1);
  66813. #endif
  66814. #ifdef WOLFSSL_AES_192
  66815. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ctr()), 1);
  66816. #endif
  66817. #ifdef WOLFSSL_AES_256
  66818. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ctr()), 1);
  66819. #endif
  66820. #endif
  66821. #ifdef HAVE_AES_ECB
  66822. #ifdef WOLFSSL_AES_128
  66823. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ecb()), AES_BLOCK_SIZE);
  66824. #endif
  66825. #ifdef WOLFSSL_AES_192
  66826. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ecb()), AES_BLOCK_SIZE);
  66827. #endif
  66828. #ifdef WOLFSSL_AES_256
  66829. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ecb()), AES_BLOCK_SIZE);
  66830. #endif
  66831. #endif
  66832. #ifdef WOLFSSL_AES_OFB
  66833. #ifdef WOLFSSL_AES_128
  66834. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ofb()), 1);
  66835. #endif
  66836. #ifdef WOLFSSL_AES_192
  66837. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ofb()), 1);
  66838. #endif
  66839. #ifdef WOLFSSL_AES_256
  66840. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ofb()), 1);
  66841. #endif
  66842. #endif
  66843. #ifndef NO_RC4
  66844. ExpectIntEQ(EVP_CIPHER_block_size(wolfSSL_EVP_rc4()), 1);
  66845. #endif
  66846. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  66847. ExpectIntEQ(EVP_CIPHER_block_size(wolfSSL_EVP_chacha20_poly1305()), 1);
  66848. #endif
  66849. #endif
  66850. #ifdef WOLFSSL_SM4_ECB
  66851. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ecb()), SM4_BLOCK_SIZE);
  66852. #endif
  66853. #ifdef WOLFSSL_SM4_CBC
  66854. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_cbc()), SM4_BLOCK_SIZE);
  66855. #endif
  66856. #ifdef WOLFSSL_SM4_CTR
  66857. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ctr()), 1);
  66858. #endif
  66859. #ifdef WOLFSSL_SM4_GCM
  66860. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_gcm()), 1);
  66861. #endif
  66862. #ifdef WOLFSSL_SM4_CCM
  66863. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ccm()), 1);
  66864. #endif
  66865. return EXPECT_RESULT();
  66866. }
  66867. static int test_wolfSSL_EVP_CIPHER_iv_length(void)
  66868. {
  66869. EXPECT_DECLS;
  66870. int nids[] = {
  66871. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)
  66872. #ifdef WOLFSSL_AES_128
  66873. NID_aes_128_cbc,
  66874. #endif
  66875. #ifdef WOLFSSL_AES_192
  66876. NID_aes_192_cbc,
  66877. #endif
  66878. #ifdef WOLFSSL_AES_256
  66879. NID_aes_256_cbc,
  66880. #endif
  66881. #endif /* HAVE_AES_CBC || WOLFSSL_AES_DIRECT */
  66882. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  66883. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  66884. #ifdef HAVE_AESGCM
  66885. #ifdef WOLFSSL_AES_128
  66886. NID_aes_128_gcm,
  66887. #endif
  66888. #ifdef WOLFSSL_AES_192
  66889. NID_aes_192_gcm,
  66890. #endif
  66891. #ifdef WOLFSSL_AES_256
  66892. NID_aes_256_gcm,
  66893. #endif
  66894. #endif /* HAVE_AESGCM */
  66895. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  66896. #ifdef WOLFSSL_AES_COUNTER
  66897. #ifdef WOLFSSL_AES_128
  66898. NID_aes_128_ctr,
  66899. #endif
  66900. #ifdef WOLFSSL_AES_192
  66901. NID_aes_192_ctr,
  66902. #endif
  66903. #ifdef WOLFSSL_AES_256
  66904. NID_aes_256_ctr,
  66905. #endif
  66906. #endif
  66907. #ifndef NO_DES3
  66908. NID_des_cbc,
  66909. NID_des_ede3_cbc,
  66910. #endif
  66911. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  66912. NID_chacha20_poly1305,
  66913. #endif
  66914. };
  66915. int iv_lengths[] = {
  66916. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)
  66917. #ifdef WOLFSSL_AES_128
  66918. AES_BLOCK_SIZE,
  66919. #endif
  66920. #ifdef WOLFSSL_AES_192
  66921. AES_BLOCK_SIZE,
  66922. #endif
  66923. #ifdef WOLFSSL_AES_256
  66924. AES_BLOCK_SIZE,
  66925. #endif
  66926. #endif /* HAVE_AES_CBC || WOLFSSL_AES_DIRECT */
  66927. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  66928. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  66929. #ifdef HAVE_AESGCM
  66930. #ifdef WOLFSSL_AES_128
  66931. GCM_NONCE_MID_SZ,
  66932. #endif
  66933. #ifdef WOLFSSL_AES_192
  66934. GCM_NONCE_MID_SZ,
  66935. #endif
  66936. #ifdef WOLFSSL_AES_256
  66937. GCM_NONCE_MID_SZ,
  66938. #endif
  66939. #endif /* HAVE_AESGCM */
  66940. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  66941. #ifdef WOLFSSL_AES_COUNTER
  66942. #ifdef WOLFSSL_AES_128
  66943. AES_BLOCK_SIZE,
  66944. #endif
  66945. #ifdef WOLFSSL_AES_192
  66946. AES_BLOCK_SIZE,
  66947. #endif
  66948. #ifdef WOLFSSL_AES_256
  66949. AES_BLOCK_SIZE,
  66950. #endif
  66951. #endif
  66952. #ifndef NO_DES3
  66953. DES_BLOCK_SIZE,
  66954. DES_BLOCK_SIZE,
  66955. #endif
  66956. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  66957. CHACHA20_POLY1305_AEAD_IV_SIZE,
  66958. #endif
  66959. };
  66960. int i;
  66961. int nidsLen = (sizeof(nids)/sizeof(int));
  66962. for (i = 0; i < nidsLen; i++) {
  66963. const EVP_CIPHER *c = EVP_get_cipherbynid(nids[i]);
  66964. ExpectIntEQ(EVP_CIPHER_iv_length(c), iv_lengths[i]);
  66965. }
  66966. return EXPECT_RESULT();
  66967. }
  66968. static int test_wolfSSL_EVP_SignInit_ex(void)
  66969. {
  66970. EXPECT_DECLS;
  66971. WOLFSSL_EVP_MD_CTX mdCtx;
  66972. WOLFSSL_ENGINE* e = 0;
  66973. const EVP_MD* md = EVP_sha256();
  66974. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  66975. ExpectIntEQ(wolfSSL_EVP_SignInit_ex(&mdCtx, md, e), WOLFSSL_SUCCESS);
  66976. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  66977. return EXPECT_RESULT();
  66978. }
  66979. static int test_wolfSSL_EVP_DigestFinal_ex(void)
  66980. {
  66981. EXPECT_DECLS;
  66982. #if !defined(NO_SHA256)
  66983. WOLFSSL_EVP_MD_CTX mdCtx;
  66984. unsigned int s = 0;
  66985. unsigned char md[WC_SHA256_DIGEST_SIZE];
  66986. unsigned char md2[WC_SHA256_DIGEST_SIZE];
  66987. /* Bad Case */
  66988. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  66989. (HAVE_FIPS_VERSION > 2))
  66990. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  66991. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md, &s), 0);
  66992. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  66993. #else
  66994. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  66995. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md, &s), WOLFSSL_SUCCESS);
  66996. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);
  66997. #endif
  66998. /* Good Case */
  66999. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  67000. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, EVP_sha256()), WOLFSSL_SUCCESS);
  67001. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md2, &s), WOLFSSL_SUCCESS);
  67002. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);
  67003. #endif
  67004. return EXPECT_RESULT();
  67005. }
  67006. static int test_wolfSSL_QT_EVP_PKEY_CTX_free(void)
  67007. {
  67008. EXPECT_DECLS;
  67009. #if defined(OPENSSL_EXTRA)
  67010. EVP_PKEY* pkey = NULL;
  67011. EVP_PKEY_CTX* ctx = NULL;
  67012. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  67013. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  67014. #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  67015. /* void */
  67016. EVP_PKEY_CTX_free(ctx);
  67017. #else
  67018. /* int */
  67019. ExpectIntEQ(EVP_PKEY_CTX_free(ctx), WOLFSSL_SUCCESS);
  67020. #endif
  67021. EVP_PKEY_free(pkey);
  67022. #endif
  67023. return EXPECT_RESULT();
  67024. }
  67025. static int test_wolfSSL_EVP_PKEY_param_check(void)
  67026. {
  67027. EXPECT_DECLS;
  67028. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  67029. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  67030. DH *dh = NULL;
  67031. DH *setDh = NULL;
  67032. EVP_PKEY *pkey = NULL;
  67033. EVP_PKEY_CTX* ctx = NULL;
  67034. FILE* f = NULL;
  67035. unsigned char buf[512];
  67036. const unsigned char* pt = buf;
  67037. const char* dh2048 = "./certs/dh2048.der";
  67038. long len = 0;
  67039. int code = -1;
  67040. XMEMSET(buf, 0, sizeof(buf));
  67041. ExpectTrue((f = XFOPEN(dh2048, "rb")) != XBADFILE);
  67042. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  67043. if (f != XBADFILE)
  67044. XFCLOSE(f);
  67045. /* Load dh2048.der into DH with internal format */
  67046. ExpectNotNull(setDh = d2i_DHparams(NULL, &pt, len));
  67047. ExpectIntEQ(DH_check(setDh, &code), WOLFSSL_SUCCESS);
  67048. ExpectIntEQ(code, 0);
  67049. code = -1;
  67050. pkey = wolfSSL_EVP_PKEY_new();
  67051. /* Set DH into PKEY */
  67052. ExpectIntEQ(EVP_PKEY_set1_DH(pkey, setDh), WOLFSSL_SUCCESS);
  67053. /* create ctx from pkey */
  67054. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  67055. ExpectIntEQ(EVP_PKEY_param_check(ctx), 1/* valid */);
  67056. /* TODO: more invalid cases */
  67057. ExpectIntEQ(EVP_PKEY_param_check(NULL), 0);
  67058. EVP_PKEY_CTX_free(ctx);
  67059. EVP_PKEY_free(pkey);
  67060. DH_free(setDh);
  67061. setDh = NULL;
  67062. DH_free(dh);
  67063. dh = NULL;
  67064. #endif
  67065. #endif
  67066. return EXPECT_RESULT();
  67067. }
  67068. static int test_wolfSSL_EVP_BytesToKey(void)
  67069. {
  67070. EXPECT_DECLS;
  67071. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  67072. byte key[AES_BLOCK_SIZE] = {0};
  67073. byte iv[AES_BLOCK_SIZE] = {0};
  67074. int count = 0;
  67075. const EVP_MD* md = EVP_sha256();
  67076. const EVP_CIPHER *type;
  67077. const unsigned char *salt = (unsigned char *)"salt1234";
  67078. int sz = 5;
  67079. const byte data[] = {
  67080. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  67081. 0x72,0x6c,0x64
  67082. };
  67083. type = wolfSSL_EVP_get_cipherbynid(NID_aes_128_cbc);
  67084. /* Bad cases */
  67085. ExpectIntEQ(EVP_BytesToKey(NULL, md, salt, data, sz, count, key, iv),
  67086. 0);
  67087. ExpectIntEQ(EVP_BytesToKey(type, md, salt, NULL, sz, count, key, iv),
  67088. 16);
  67089. md = "2";
  67090. ExpectIntEQ(EVP_BytesToKey(type, md, salt, data, sz, count, key, iv),
  67091. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  67092. /* Good case */
  67093. md = EVP_sha256();
  67094. ExpectIntEQ(EVP_BytesToKey(type, md, salt, data, sz, count, key, iv),
  67095. 16);
  67096. #endif
  67097. return EXPECT_RESULT();
  67098. }
  67099. static int test_evp_cipher_aes_gcm(void)
  67100. {
  67101. EXPECT_DECLS;
  67102. #if defined(HAVE_AESGCM) && ((!defined(HAVE_FIPS) && \
  67103. !defined(HAVE_SELFTEST)) || (defined(HAVE_FIPS_VERSION) && \
  67104. (HAVE_FIPS_VERSION >= 2)))
  67105. /*
  67106. * This test checks data at various points in the encrypt/decrypt process
  67107. * against known values produced using the same test with OpenSSL. This
  67108. * interop testing is critical for verifying the correctness of our
  67109. * EVP_Cipher implementation with AES-GCM. Specifically, this test exercises
  67110. * a flow supported by OpenSSL that uses the control command
  67111. * EVP_CTRL_GCM_IV_GEN to increment the IV between cipher operations without
  67112. * the need to call EVP_CipherInit. OpenSSH uses this flow, for example. We
  67113. * had a bug with OpenSSH where wolfSSL OpenSSH servers could only talk to
  67114. * wolfSSL OpenSSH clients because there was a bug in this flow that
  67115. * happened to "cancel out" if both sides of the connection had the bug.
  67116. */
  67117. enum {
  67118. NUM_ENCRYPTIONS = 3,
  67119. AAD_SIZE = 4
  67120. };
  67121. byte plainText1[] = {
  67122. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  67123. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  67124. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23
  67125. };
  67126. byte plainText2[] = {
  67127. 0x42, 0x49, 0x3b, 0x27, 0x03, 0x35, 0x59, 0x14, 0x41, 0x47, 0x37, 0x14,
  67128. 0x0e, 0x34, 0x0d, 0x28, 0x63, 0x09, 0x0a, 0x5b, 0x22, 0x57, 0x42, 0x22,
  67129. 0x0f, 0x5c, 0x1e, 0x53, 0x45, 0x15, 0x62, 0x08, 0x60, 0x43, 0x50, 0x2c
  67130. };
  67131. byte plainText3[] = {
  67132. 0x36, 0x0d, 0x2b, 0x09, 0x4a, 0x56, 0x3b, 0x4c, 0x21, 0x22, 0x58, 0x0e,
  67133. 0x5b, 0x57, 0x10
  67134. };
  67135. byte* plainTexts[NUM_ENCRYPTIONS] = {
  67136. plainText1,
  67137. plainText2,
  67138. plainText3
  67139. };
  67140. const int plainTextSzs[NUM_ENCRYPTIONS] = {
  67141. sizeof(plainText1),
  67142. sizeof(plainText2),
  67143. sizeof(plainText3)
  67144. };
  67145. byte aad1[AAD_SIZE] = {
  67146. 0x00, 0x00, 0x00, 0x01
  67147. };
  67148. byte aad2[AAD_SIZE] = {
  67149. 0x00, 0x00, 0x00, 0x10
  67150. };
  67151. byte aad3[AAD_SIZE] = {
  67152. 0x00, 0x00, 0x01, 0x00
  67153. };
  67154. byte* aads[NUM_ENCRYPTIONS] = {
  67155. aad1,
  67156. aad2,
  67157. aad3
  67158. };
  67159. const byte iv[GCM_NONCE_MID_SZ] = {
  67160. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  67161. };
  67162. byte currentIv[GCM_NONCE_MID_SZ];
  67163. const byte key[] = {
  67164. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
  67165. 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  67166. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
  67167. };
  67168. const byte expIvs[NUM_ENCRYPTIONS][GCM_NONCE_MID_SZ] = {
  67169. {
  67170. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  67171. 0xEF
  67172. },
  67173. {
  67174. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  67175. 0xF0
  67176. },
  67177. {
  67178. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  67179. 0xF1
  67180. }
  67181. };
  67182. const byte expTags[NUM_ENCRYPTIONS][AES_BLOCK_SIZE] = {
  67183. {
  67184. 0x65, 0x4F, 0xF7, 0xA0, 0xBB, 0x7B, 0x90, 0xB7, 0x9C, 0xC8, 0x14,
  67185. 0x3D, 0x32, 0x18, 0x34, 0xA9
  67186. },
  67187. {
  67188. 0x50, 0x3A, 0x13, 0x8D, 0x91, 0x1D, 0xEC, 0xBB, 0xBA, 0x5B, 0x57,
  67189. 0xA2, 0xFD, 0x2D, 0x6B, 0x7F
  67190. },
  67191. {
  67192. 0x3B, 0xED, 0x18, 0x9C, 0xB3, 0xE3, 0x61, 0x1E, 0x11, 0xEB, 0x13,
  67193. 0x5B, 0xEC, 0x52, 0x49, 0x32,
  67194. }
  67195. };
  67196. const byte expCipherText1[] = {
  67197. 0xCB, 0x93, 0x4F, 0xC8, 0x22, 0xE2, 0xC0, 0x35, 0xAA, 0x6B, 0x41, 0x15,
  67198. 0x17, 0x30, 0x2F, 0x97, 0x20, 0x74, 0x39, 0x28, 0xF8, 0xEB, 0xC5, 0x51,
  67199. 0x7B, 0xD9, 0x8A, 0x36, 0xB8, 0xDA, 0x24, 0x80, 0xE7, 0x9E, 0x09, 0xDE
  67200. };
  67201. const byte expCipherText2[] = {
  67202. 0xF9, 0x32, 0xE1, 0x87, 0x37, 0x0F, 0x04, 0xC1, 0xB5, 0x59, 0xF0, 0x45,
  67203. 0x3A, 0x0D, 0xA0, 0x26, 0xFF, 0xA6, 0x8D, 0x38, 0xFE, 0xB8, 0xE5, 0xC2,
  67204. 0x2A, 0x98, 0x4A, 0x54, 0x8F, 0x1F, 0xD6, 0x13, 0x03, 0xB2, 0x1B, 0xC0
  67205. };
  67206. const byte expCipherText3[] = {
  67207. 0xD0, 0x37, 0x59, 0x1C, 0x2F, 0x85, 0x39, 0x4D, 0xED, 0xC2, 0x32, 0x5B,
  67208. 0x80, 0x5E, 0x6B,
  67209. };
  67210. const byte* expCipherTexts[NUM_ENCRYPTIONS] = {
  67211. expCipherText1,
  67212. expCipherText2,
  67213. expCipherText3
  67214. };
  67215. byte* cipherText = NULL;
  67216. byte* calcPlainText = NULL;
  67217. byte tag[AES_BLOCK_SIZE];
  67218. EVP_CIPHER_CTX* encCtx = NULL;
  67219. EVP_CIPHER_CTX* decCtx = NULL;
  67220. int i, j, outl;
  67221. /****************************************************/
  67222. for (i = 0; i < 3; ++i) {
  67223. ExpectNotNull(encCtx = EVP_CIPHER_CTX_new());
  67224. ExpectNotNull(decCtx = EVP_CIPHER_CTX_new());
  67225. /* First iteration, set key before IV. */
  67226. if (i == 0) {
  67227. ExpectIntEQ(EVP_CipherInit(encCtx, EVP_aes_256_gcm(), key, NULL, 1),
  67228. SSL_SUCCESS);
  67229. /*
  67230. * The call to EVP_CipherInit below (with NULL key) should clear the
  67231. * authIvGenEnable flag set by EVP_CTRL_GCM_SET_IV_FIXED. As such, a
  67232. * subsequent EVP_CTRL_GCM_IV_GEN should fail. This matches OpenSSL
  67233. * behavior.
  67234. */
  67235. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  67236. (void*)iv), SSL_SUCCESS);
  67237. ExpectIntEQ(EVP_CipherInit(encCtx, NULL, NULL, iv, 1),
  67238. SSL_SUCCESS);
  67239. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  67240. currentIv), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  67241. ExpectIntEQ(EVP_CipherInit(decCtx, EVP_aes_256_gcm(), key, NULL, 0),
  67242. SSL_SUCCESS);
  67243. ExpectIntEQ(EVP_CipherInit(decCtx, NULL, NULL, iv, 0),
  67244. SSL_SUCCESS);
  67245. }
  67246. /* Second iteration, IV before key. */
  67247. else {
  67248. ExpectIntEQ(EVP_CipherInit(encCtx, EVP_aes_256_gcm(), NULL, iv, 1),
  67249. SSL_SUCCESS);
  67250. ExpectIntEQ(EVP_CipherInit(encCtx, NULL, key, NULL, 1),
  67251. SSL_SUCCESS);
  67252. ExpectIntEQ(EVP_CipherInit(decCtx, EVP_aes_256_gcm(), NULL, iv, 0),
  67253. SSL_SUCCESS);
  67254. ExpectIntEQ(EVP_CipherInit(decCtx, NULL, key, NULL, 0),
  67255. SSL_SUCCESS);
  67256. }
  67257. /*
  67258. * EVP_CTRL_GCM_IV_GEN should fail if EVP_CTRL_GCM_SET_IV_FIXED hasn't
  67259. * been issued first.
  67260. */
  67261. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  67262. currentIv), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  67263. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  67264. (void*)iv), SSL_SUCCESS);
  67265. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  67266. (void*)iv), SSL_SUCCESS);
  67267. for (j = 0; j < NUM_ENCRYPTIONS; ++j) {
  67268. /*************** Encrypt ***************/
  67269. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  67270. currentIv), SSL_SUCCESS);
  67271. /* Check current IV against expected. */
  67272. ExpectIntEQ(XMEMCMP(currentIv, expIvs[j], GCM_NONCE_MID_SZ), 0);
  67273. /* Add AAD. */
  67274. if (i == 2) {
  67275. /* Test streaming API. */
  67276. ExpectIntEQ(EVP_CipherUpdate(encCtx, NULL, &outl, aads[j],
  67277. AAD_SIZE), SSL_SUCCESS);
  67278. }
  67279. else {
  67280. ExpectIntEQ(EVP_Cipher(encCtx, NULL, aads[j], AAD_SIZE),
  67281. AAD_SIZE);
  67282. }
  67283. ExpectNotNull(cipherText = (byte*)XMALLOC(plainTextSzs[j], NULL,
  67284. DYNAMIC_TYPE_TMP_BUFFER));
  67285. /* Encrypt plaintext. */
  67286. if (i == 2) {
  67287. ExpectIntEQ(EVP_CipherUpdate(encCtx, cipherText, &outl,
  67288. plainTexts[j], plainTextSzs[j]),
  67289. SSL_SUCCESS);
  67290. }
  67291. else {
  67292. ExpectIntEQ(EVP_Cipher(encCtx, cipherText, plainTexts[j],
  67293. plainTextSzs[j]), plainTextSzs[j]);
  67294. }
  67295. if (i == 2) {
  67296. ExpectIntEQ(EVP_CipherFinal(encCtx, cipherText, &outl),
  67297. SSL_SUCCESS);
  67298. }
  67299. else {
  67300. /*
  67301. * Calling EVP_Cipher with NULL input and output for AES-GCM is
  67302. * akin to calling EVP_CipherFinal.
  67303. */
  67304. ExpectIntGE(EVP_Cipher(encCtx, NULL, NULL, 0), 0);
  67305. }
  67306. /* Check ciphertext against expected. */
  67307. ExpectIntEQ(XMEMCMP(cipherText, expCipherTexts[j], plainTextSzs[j]),
  67308. 0);
  67309. /* Get and check tag against expected. */
  67310. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_GET_TAG,
  67311. sizeof(tag), tag), SSL_SUCCESS);
  67312. ExpectIntEQ(XMEMCMP(tag, expTags[j], sizeof(tag)), 0);
  67313. /*************** Decrypt ***************/
  67314. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_IV_GEN, -1,
  67315. currentIv), SSL_SUCCESS);
  67316. /* Check current IV against expected. */
  67317. ExpectIntEQ(XMEMCMP(currentIv, expIvs[j], GCM_NONCE_MID_SZ), 0);
  67318. /* Add AAD. */
  67319. if (i == 2) {
  67320. /* Test streaming API. */
  67321. ExpectIntEQ(EVP_CipherUpdate(decCtx, NULL, &outl, aads[j],
  67322. AAD_SIZE), SSL_SUCCESS);
  67323. }
  67324. else {
  67325. ExpectIntEQ(EVP_Cipher(decCtx, NULL, aads[j], AAD_SIZE),
  67326. AAD_SIZE);
  67327. }
  67328. /* Set expected tag. */
  67329. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_SET_TAG,
  67330. sizeof(tag), tag), SSL_SUCCESS);
  67331. /* Decrypt ciphertext. */
  67332. ExpectNotNull(calcPlainText = (byte*)XMALLOC(plainTextSzs[j], NULL,
  67333. DYNAMIC_TYPE_TMP_BUFFER));
  67334. if (i == 2) {
  67335. ExpectIntEQ(EVP_CipherUpdate(decCtx, calcPlainText, &outl,
  67336. cipherText, plainTextSzs[j]),
  67337. SSL_SUCCESS);
  67338. }
  67339. else {
  67340. /* This first EVP_Cipher call will check the tag, too. */
  67341. ExpectIntEQ(EVP_Cipher(decCtx, calcPlainText, cipherText,
  67342. plainTextSzs[j]), plainTextSzs[j]);
  67343. }
  67344. if (i == 2) {
  67345. ExpectIntEQ(EVP_CipherFinal(decCtx, calcPlainText, &outl),
  67346. SSL_SUCCESS);
  67347. }
  67348. else {
  67349. ExpectIntGE(EVP_Cipher(decCtx, NULL, NULL, 0), 0);
  67350. }
  67351. /* Check plaintext against expected. */
  67352. ExpectIntEQ(XMEMCMP(calcPlainText, plainTexts[j], plainTextSzs[j]),
  67353. 0);
  67354. XFREE(cipherText, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  67355. cipherText = NULL;
  67356. XFREE(calcPlainText, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  67357. calcPlainText = NULL;
  67358. }
  67359. EVP_CIPHER_CTX_free(encCtx);
  67360. encCtx = NULL;
  67361. EVP_CIPHER_CTX_free(decCtx);
  67362. decCtx = NULL;
  67363. }
  67364. #endif
  67365. return EXPECT_RESULT();
  67366. }
  67367. static int test_wolfSSL_OBJ_ln(void)
  67368. {
  67369. EXPECT_DECLS;
  67370. const int nid_set[] = {
  67371. NID_commonName,
  67372. NID_serialNumber,
  67373. NID_countryName,
  67374. NID_localityName,
  67375. NID_stateOrProvinceName,
  67376. NID_organizationName,
  67377. NID_organizationalUnitName,
  67378. NID_domainComponent,
  67379. NID_businessCategory,
  67380. NID_jurisdictionCountryName,
  67381. NID_jurisdictionStateOrProvinceName,
  67382. NID_emailAddress
  67383. };
  67384. const char* ln_set[] = {
  67385. "commonName",
  67386. "serialNumber",
  67387. "countryName",
  67388. "localityName",
  67389. "stateOrProvinceName",
  67390. "organizationName",
  67391. "organizationalUnitName",
  67392. "domainComponent",
  67393. "businessCategory",
  67394. "jurisdictionCountryName",
  67395. "jurisdictionStateOrProvinceName",
  67396. "emailAddress",
  67397. };
  67398. size_t i = 0, maxIdx = sizeof(ln_set)/sizeof(char*);
  67399. ExpectIntEQ(OBJ_ln2nid(NULL), NID_undef);
  67400. #ifdef HAVE_ECC
  67401. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  67402. {
  67403. EC_builtin_curve r[27];
  67404. size_t nCurves = sizeof(r) / sizeof(r[0]);
  67405. nCurves = EC_get_builtin_curves(r, nCurves);
  67406. for (i = 0; i < nCurves; i++) {
  67407. /* skip ECC_CURVE_INVALID */
  67408. if (r[i].nid != ECC_CURVE_INVALID) {
  67409. ExpectIntEQ(OBJ_ln2nid(r[i].comment), r[i].nid);
  67410. ExpectStrEQ(OBJ_nid2ln(r[i].nid), r[i].comment);
  67411. }
  67412. }
  67413. }
  67414. #endif
  67415. #endif
  67416. for (i = 0; i < maxIdx; i++) {
  67417. ExpectIntEQ(OBJ_ln2nid(ln_set[i]), nid_set[i]);
  67418. ExpectStrEQ(OBJ_nid2ln(nid_set[i]), ln_set[i]);
  67419. }
  67420. return EXPECT_RESULT();
  67421. }
  67422. static int test_wolfSSL_OBJ_sn(void)
  67423. {
  67424. EXPECT_DECLS;
  67425. int i = 0, maxIdx = 7;
  67426. const int nid_set[] = {NID_commonName,NID_countryName,NID_localityName,
  67427. NID_stateOrProvinceName,NID_organizationName,
  67428. NID_organizationalUnitName,NID_emailAddress};
  67429. const char* sn_open_set[] = {"CN","C","L","ST","O","OU","emailAddress"};
  67430. const char* sn_wolf_set[] = {WOLFSSL_COMMON_NAME,WOLFSSL_COUNTRY_NAME,
  67431. WOLFSSL_LOCALITY_NAME, WOLFSSL_STATE_NAME,
  67432. WOLFSSL_ORG_NAME, WOLFSSL_ORGUNIT_NAME,
  67433. WOLFSSL_EMAIL_ADDR};
  67434. ExpectIntEQ(wolfSSL_OBJ_sn2nid(NULL), NID_undef);
  67435. for (i = 0; i < maxIdx; i++) {
  67436. ExpectIntEQ(wolfSSL_OBJ_sn2nid(sn_wolf_set[i]), nid_set[i]);
  67437. ExpectStrEQ(wolfSSL_OBJ_nid2sn(nid_set[i]), sn_open_set[i]);
  67438. }
  67439. return EXPECT_RESULT();
  67440. }
  67441. #if !defined(NO_BIO)
  67442. static word32 TXT_DB_hash(const WOLFSSL_STRING *s)
  67443. {
  67444. return (word32)lh_strhash(s[3]);
  67445. }
  67446. static int TXT_DB_cmp(const WOLFSSL_STRING *a, const WOLFSSL_STRING *b)
  67447. {
  67448. return XSTRCMP(a[3], b[3]);
  67449. }
  67450. #endif
  67451. static int test_wolfSSL_TXT_DB(void)
  67452. {
  67453. EXPECT_DECLS;
  67454. #if !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  67455. BIO *bio = NULL;
  67456. TXT_DB *db = NULL;
  67457. const int columns = 6;
  67458. const char *fields[6] = {
  67459. "V",
  67460. "320926161116Z",
  67461. "",
  67462. "12BD",
  67463. "unknown",
  67464. "/CN=rsa doe",
  67465. };
  67466. char** fields_copy = NULL;
  67467. /* Test read */
  67468. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  67469. ExpectIntGT(BIO_read_filename(bio, "./tests/TXT_DB.txt"), 0);
  67470. ExpectNotNull(db = TXT_DB_read(bio, columns));
  67471. ExpectNotNull(fields_copy = (char**)XMALLOC(sizeof(fields), NULL,
  67472. DYNAMIC_TYPE_OPENSSL));
  67473. if (fields_copy != NULL) {
  67474. XMEMCPY(fields_copy, fields, sizeof(fields));
  67475. }
  67476. ExpectIntEQ(TXT_DB_insert(db, fields_copy), 1);
  67477. if (EXPECT_FAIL()) {
  67478. XFREE(fields_copy, NULL, DYNAMIC_TYPE_OPENSSL);
  67479. }
  67480. BIO_free(bio);
  67481. bio = NULL;
  67482. /* Test write */
  67483. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  67484. ExpectIntEQ(TXT_DB_write(bio, db), 1484);
  67485. BIO_free(bio);
  67486. /* Test index */
  67487. ExpectIntEQ(TXT_DB_create_index(db, 3, NULL,
  67488. (wolf_sk_hash_cb)(long unsigned int)TXT_DB_hash,
  67489. (wolf_lh_compare_cb)TXT_DB_cmp), 1);
  67490. ExpectNotNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  67491. fields[3] = "12DA";
  67492. ExpectNotNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  67493. fields[3] = "FFFF";
  67494. ExpectNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  67495. fields[3] = "";
  67496. ExpectNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  67497. TXT_DB_free(db);
  67498. #endif
  67499. return EXPECT_RESULT();
  67500. }
  67501. static int test_wolfSSL_NCONF(void)
  67502. {
  67503. EXPECT_DECLS;
  67504. #if !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  67505. const char* confFile = "./tests/NCONF_test.cnf";
  67506. CONF* conf = NULL;
  67507. long eline = 0;
  67508. long num = 0;
  67509. ExpectNotNull(conf = NCONF_new(NULL));
  67510. ExpectIntEQ(NCONF_load(conf, confFile, &eline), 1);
  67511. ExpectIntEQ(NCONF_get_number(conf, NULL, "port", &num), 1);
  67512. ExpectIntEQ(num, 1234);
  67513. ExpectIntEQ(NCONF_get_number(conf, "section2", "port", &num), 1);
  67514. ExpectIntEQ(num, 4321);
  67515. ExpectStrEQ(NCONF_get_string(conf, NULL, "dir"), "./test-dir");
  67516. ExpectStrEQ(NCONF_get_string(conf, "section1", "file1_copy"),
  67517. "./test-dir/file1");
  67518. ExpectStrEQ(NCONF_get_string(conf, "section2", "file_list"),
  67519. "./test-dir/file1:./test-dir/file2:./section1:file2");
  67520. NCONF_free(conf);
  67521. #endif
  67522. return EXPECT_RESULT();
  67523. }
  67524. #endif /* OPENSSL_ALL */
  67525. static int test_wolfSSL_X509V3_EXT_get(void) {
  67526. EXPECT_DECLS;
  67527. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  67528. XFILE f = XBADFILE;
  67529. int numOfExt =0;
  67530. int extNid = 0;
  67531. int i = 0;
  67532. WOLFSSL_X509* x509 = NULL;
  67533. WOLFSSL_X509_EXTENSION* ext = NULL;
  67534. const WOLFSSL_v3_ext_method* method = NULL;
  67535. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67536. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  67537. if (f != XBADFILE)
  67538. XFCLOSE(f);
  67539. /* wolfSSL_X509V3_EXT_get() return struct and nid test */
  67540. ExpectIntEQ((numOfExt = wolfSSL_X509_get_ext_count(x509)), 5);
  67541. for (i = 0; i < numOfExt; i++) {
  67542. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  67543. ExpectIntNE((extNid = ext->obj->nid), NID_undef);
  67544. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  67545. ExpectIntEQ(method->ext_nid, extNid);
  67546. }
  67547. /* wolfSSL_X509V3_EXT_get() NULL argument test */
  67548. ExpectNull(method = wolfSSL_X509V3_EXT_get(NULL));
  67549. wolfSSL_X509_free(x509);
  67550. #endif
  67551. return EXPECT_RESULT();
  67552. }
  67553. static int test_wolfSSL_X509V3_EXT_nconf(void)
  67554. {
  67555. EXPECT_DECLS;
  67556. #ifdef OPENSSL_ALL
  67557. const char *ext_names[] = {
  67558. "subjectKeyIdentifier",
  67559. "authorityKeyIdentifier",
  67560. "subjectAltName",
  67561. "keyUsage",
  67562. "extendedKeyUsage",
  67563. };
  67564. size_t ext_names_count = sizeof(ext_names)/sizeof(*ext_names);
  67565. int ext_nids[] = {
  67566. NID_subject_key_identifier,
  67567. NID_authority_key_identifier,
  67568. NID_subject_alt_name,
  67569. NID_key_usage,
  67570. NID_ext_key_usage,
  67571. };
  67572. size_t ext_nids_count = sizeof(ext_nids)/sizeof(*ext_nids);
  67573. const char *ext_values[] = {
  67574. "hash",
  67575. "hash",
  67576. "DNS:example.com, IP:127.0.0.1",
  67577. "digitalSignature,nonRepudiation,keyEncipherment,dataEncipherment,"
  67578. "keyAgreement,keyCertSign,cRLSign,encipherOnly,decipherOnly",
  67579. "serverAuth,clientAuth,codeSigning,emailProtection,timeStamping,"
  67580. "OCSPSigning",
  67581. };
  67582. size_t i;
  67583. X509_EXTENSION* ext = NULL;
  67584. X509* x509 = NULL;
  67585. unsigned int keyUsageFlags;
  67586. unsigned int extKeyUsageFlags;
  67587. ExpectNotNull(x509 = X509_new());
  67588. /* keyUsage / extKeyUsage should match string above */
  67589. keyUsageFlags = KU_DIGITAL_SIGNATURE
  67590. | KU_NON_REPUDIATION
  67591. | KU_KEY_ENCIPHERMENT
  67592. | KU_DATA_ENCIPHERMENT
  67593. | KU_KEY_AGREEMENT
  67594. | KU_KEY_CERT_SIGN
  67595. | KU_CRL_SIGN
  67596. | KU_ENCIPHER_ONLY
  67597. | KU_DECIPHER_ONLY;
  67598. extKeyUsageFlags = XKU_SSL_CLIENT
  67599. | XKU_SSL_SERVER
  67600. | XKU_CODE_SIGN
  67601. | XKU_SMIME
  67602. | XKU_TIMESTAMP
  67603. | XKU_OCSP_SIGN;
  67604. for (i = 0; i < ext_names_count; i++) {
  67605. ExpectNotNull(ext = X509V3_EXT_nconf(NULL, NULL, ext_names[i],
  67606. ext_values[i]));
  67607. X509_EXTENSION_free(ext);
  67608. ext = NULL;
  67609. }
  67610. for (i = 0; i < ext_nids_count; i++) {
  67611. ExpectNotNull(ext = X509V3_EXT_nconf_nid(NULL, NULL, ext_nids[i],
  67612. ext_values[i]));
  67613. X509_EXTENSION_free(ext);
  67614. ext = NULL;
  67615. }
  67616. /* Test adding extension to X509 */
  67617. for (i = 0; i < ext_nids_count; i++) {
  67618. ExpectNotNull(ext = X509V3_EXT_nconf(NULL, NULL, ext_names[i],
  67619. ext_values[i]));
  67620. ExpectIntEQ(X509_add_ext(x509, ext, -1), WOLFSSL_SUCCESS);
  67621. if (ext_nids[i] == NID_key_usage) {
  67622. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  67623. }
  67624. else if (ext_nids[i] == NID_ext_key_usage) {
  67625. ExpectIntEQ(X509_get_extended_key_usage(x509), extKeyUsageFlags);
  67626. }
  67627. X509_EXTENSION_free(ext);
  67628. ext = NULL;
  67629. }
  67630. X509_free(x509);
  67631. #endif
  67632. return EXPECT_RESULT();
  67633. }
  67634. static int test_wolfSSL_X509V3_EXT(void) {
  67635. EXPECT_DECLS;
  67636. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  67637. XFILE f = XBADFILE;
  67638. int numOfExt = 0, nid = 0, i = 0, expected, actual = 0;
  67639. char* str = NULL;
  67640. unsigned char* data = NULL;
  67641. const WOLFSSL_v3_ext_method* method = NULL;
  67642. WOLFSSL_X509* x509 = NULL;
  67643. WOLFSSL_X509_EXTENSION* ext = NULL;
  67644. WOLFSSL_X509_EXTENSION* ext2 = NULL;
  67645. WOLFSSL_ASN1_OBJECT *obj = NULL;
  67646. WOLFSSL_ASN1_OBJECT *adObj = NULL;
  67647. WOLFSSL_ASN1_STRING* asn1str = NULL;
  67648. WOLFSSL_AUTHORITY_KEYID* aKeyId = NULL;
  67649. WOLFSSL_AUTHORITY_INFO_ACCESS* aia = NULL;
  67650. WOLFSSL_BASIC_CONSTRAINTS* bc = NULL;
  67651. WOLFSSL_ACCESS_DESCRIPTION* ad = NULL;
  67652. WOLFSSL_GENERAL_NAME* gn = NULL;
  67653. /* Check NULL argument */
  67654. ExpectNull(wolfSSL_X509V3_EXT_d2i(NULL));
  67655. /* Using OCSP cert with X509V3 extensions */
  67656. ExpectTrue((f = XFOPEN("./certs/ocsp/root-ca-cert.pem", "rb")) != XBADFILE);
  67657. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  67658. if (f != XBADFILE)
  67659. XFCLOSE(f);
  67660. ExpectIntEQ((numOfExt = wolfSSL_X509_get_ext_count(x509)), 5);
  67661. /* Basic Constraints */
  67662. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  67663. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  67664. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_basic_constraints);
  67665. ExpectNotNull(bc = (WOLFSSL_BASIC_CONSTRAINTS*)wolfSSL_X509V3_EXT_d2i(ext));
  67666. ExpectIntEQ(bc->ca, 1);
  67667. ExpectNull(bc->pathlen);
  67668. wolfSSL_BASIC_CONSTRAINTS_free(bc);
  67669. bc = NULL;
  67670. i++;
  67671. /* Subject Key Identifier */
  67672. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  67673. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  67674. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_subject_key_identifier);
  67675. ExpectNotNull(asn1str = (WOLFSSL_ASN1_STRING*)wolfSSL_X509V3_EXT_d2i(ext));
  67676. ExpectNotNull(ext2 = wolfSSL_X509V3_EXT_i2d(NID_subject_key_identifier, 0,
  67677. asn1str));
  67678. X509_EXTENSION_free(ext2);
  67679. ext2 = NULL;
  67680. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  67681. ExpectNotNull(method->i2s);
  67682. ExpectNotNull(str = method->i2s((WOLFSSL_v3_ext_method*)method, asn1str));
  67683. wolfSSL_ASN1_STRING_free(asn1str);
  67684. asn1str = NULL;
  67685. if (str != NULL) {
  67686. actual = strcmp(str,
  67687. "73:B0:1C:A4:2F:82:CB:CF:47:A5:38:D7:B0:04:82:3A:7E:72:15:21");
  67688. }
  67689. ExpectIntEQ(actual, 0);
  67690. XFREE(str, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  67691. str = NULL;
  67692. i++;
  67693. /* Authority Key Identifier */
  67694. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  67695. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  67696. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_authority_key_identifier);
  67697. ExpectNotNull(aKeyId = (WOLFSSL_AUTHORITY_KEYID*)wolfSSL_X509V3_EXT_d2i(
  67698. ext));
  67699. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  67700. ExpectNotNull(asn1str = aKeyId->keyid);
  67701. ExpectNotNull(str = wolfSSL_i2s_ASN1_STRING((WOLFSSL_v3_ext_method*)method,
  67702. asn1str));
  67703. asn1str = NULL;
  67704. if (str != NULL) {
  67705. actual = strcmp(str,
  67706. "73:B0:1C:A4:2F:82:CB:CF:47:A5:38:D7:B0:04:82:3A:7E:72:15:21");
  67707. }
  67708. ExpectIntEQ(actual, 0);
  67709. XFREE(str, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  67710. str = NULL;
  67711. wolfSSL_AUTHORITY_KEYID_free(aKeyId);
  67712. aKeyId = NULL;
  67713. i++;
  67714. /* Key Usage */
  67715. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  67716. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  67717. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_key_usage);
  67718. ExpectNotNull(asn1str = (WOLFSSL_ASN1_STRING*)wolfSSL_X509V3_EXT_d2i(ext));
  67719. #if defined(WOLFSSL_QT)
  67720. ExpectNotNull(data = (unsigned char*)ASN1_STRING_get0_data(asn1str));
  67721. #else
  67722. ExpectNotNull(data = wolfSSL_ASN1_STRING_data(asn1str));
  67723. #endif
  67724. expected = KEYUSE_KEY_CERT_SIGN | KEYUSE_CRL_SIGN;
  67725. if (data != NULL) {
  67726. #ifdef BIG_ENDIAN_ORDER
  67727. actual = data[1];
  67728. #else
  67729. actual = data[0];
  67730. #endif
  67731. }
  67732. ExpectIntEQ(actual, expected);
  67733. wolfSSL_ASN1_STRING_free(asn1str);
  67734. asn1str = NULL;
  67735. #if 1
  67736. i++;
  67737. /* Authority Info Access */
  67738. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  67739. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  67740. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_info_access);
  67741. ExpectNotNull(aia = (WOLFSSL_AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(
  67742. ext));
  67743. #if defined(WOLFSSL_QT)
  67744. ExpectIntEQ(OPENSSL_sk_num(aia), 1); /* Only one URI entry for this cert */
  67745. #else
  67746. ExpectIntEQ(wolfSSL_sk_num(aia), 1); /* Only one URI entry for this cert */
  67747. #endif
  67748. /* URI entry is an ACCESS_DESCRIPTION type */
  67749. #if defined(WOLFSSL_QT)
  67750. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION*)wolfSSL_sk_value(aia, 0));
  67751. #else
  67752. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION*)OPENSSL_sk_value(aia, 0));
  67753. #endif
  67754. ExpectNotNull(adObj = ad->method);
  67755. /* Make sure nid is OCSP */
  67756. ExpectIntEQ(wolfSSL_OBJ_obj2nid(adObj), NID_ad_OCSP);
  67757. /* GENERAL_NAME stores URI as an ASN1_STRING */
  67758. ExpectNotNull(gn = ad->location);
  67759. ExpectIntEQ(gn->type, GEN_URI); /* Type should always be GEN_URI */
  67760. ExpectNotNull(asn1str = gn->d.uniformResourceIdentifier);
  67761. ExpectIntEQ(wolfSSL_ASN1_STRING_length(asn1str), 22);
  67762. #if defined(WOLFSSL_QT)
  67763. ExpectNotNull(str = (char*)ASN1_STRING_get0_data(asn1str));
  67764. #else
  67765. ExpectNotNull(str = (char*)wolfSSL_ASN1_STRING_data(asn1str));
  67766. #endif
  67767. if (str != NULL) {
  67768. actual = strcmp(str, "http://127.0.0.1:22220");
  67769. }
  67770. ExpectIntEQ(actual, 0);
  67771. wolfSSL_sk_ACCESS_DESCRIPTION_pop_free(aia, NULL);
  67772. aia = NULL;
  67773. #else
  67774. (void) aia; (void) ad; (void) adObj; (void) gn;
  67775. #endif
  67776. wolfSSL_X509_free(x509);
  67777. #endif
  67778. return EXPECT_RESULT();
  67779. }
  67780. static int test_wolfSSL_X509_get_extension_flags(void)
  67781. {
  67782. EXPECT_DECLS;
  67783. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  67784. XFILE f = XBADFILE;
  67785. X509* x509 = NULL;
  67786. unsigned int extFlags;
  67787. unsigned int keyUsageFlags;
  67788. unsigned int extKeyUsageFlags;
  67789. /* client-int-cert.pem has the following extension flags. */
  67790. extFlags = EXFLAG_KUSAGE | EXFLAG_XKUSAGE;
  67791. /* and the following key usage flags. */
  67792. keyUsageFlags = KU_DIGITAL_SIGNATURE
  67793. | KU_NON_REPUDIATION
  67794. | KU_KEY_ENCIPHERMENT;
  67795. /* and the following extended key usage flags. */
  67796. extKeyUsageFlags = XKU_SSL_CLIENT | XKU_SMIME;
  67797. ExpectTrue((f = XFOPEN("./certs/intermediate/client-int-cert.pem", "rb")) !=
  67798. XBADFILE);
  67799. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  67800. if (f != XBADFILE) {
  67801. XFCLOSE(f);
  67802. f = XBADFILE;
  67803. }
  67804. ExpectIntEQ(X509_get_extension_flags(x509), extFlags);
  67805. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  67806. ExpectIntEQ(X509_get_extended_key_usage(x509), extKeyUsageFlags);
  67807. X509_free(x509);
  67808. x509 = NULL;
  67809. /* client-cert-ext.pem has the following extension flags. */
  67810. extFlags = EXFLAG_KUSAGE;
  67811. /* and the following key usage flags. */
  67812. keyUsageFlags = KU_DIGITAL_SIGNATURE
  67813. | KU_KEY_CERT_SIGN
  67814. | KU_CRL_SIGN;
  67815. ExpectTrue((f = fopen("./certs/client-cert-ext.pem", "rb")) != XBADFILE);
  67816. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  67817. if (f != XBADFILE)
  67818. XFCLOSE(f);
  67819. ExpectIntEQ(X509_get_extension_flags(x509), extFlags);
  67820. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  67821. X509_free(x509);
  67822. #endif /* OPENSSL_ALL */
  67823. return EXPECT_RESULT();
  67824. }
  67825. static int test_wolfSSL_X509_get_ext(void)
  67826. {
  67827. EXPECT_DECLS;
  67828. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  67829. int ret = 0;
  67830. XFILE f = XBADFILE;
  67831. WOLFSSL_X509* x509 = NULL;
  67832. WOLFSSL_X509_EXTENSION* foundExtension;
  67833. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67834. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  67835. if (f != XBADFILE)
  67836. XFCLOSE(f);
  67837. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(x509)), 5);
  67838. /* wolfSSL_X509_get_ext() valid input */
  67839. ExpectNotNull(foundExtension = wolfSSL_X509_get_ext(x509, 0));
  67840. /* wolfSSL_X509_get_ext() valid x509, idx out of bounds */
  67841. ExpectNull(foundExtension = wolfSSL_X509_get_ext(x509, -1));
  67842. ExpectNull(foundExtension = wolfSSL_X509_get_ext(x509, 100));
  67843. /* wolfSSL_X509_get_ext() NULL x509, idx out of bounds */
  67844. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, -1));
  67845. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, 100));
  67846. /* wolfSSL_X509_get_ext() NULL x509, valid idx */
  67847. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, 0));
  67848. wolfSSL_X509_free(x509);
  67849. #endif
  67850. return EXPECT_RESULT();
  67851. }
  67852. static int test_wolfSSL_X509_get_ext_by_NID(void)
  67853. {
  67854. EXPECT_DECLS;
  67855. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  67856. int rc = 0;
  67857. XFILE f = XBADFILE;
  67858. WOLFSSL_X509* x509 = NULL;
  67859. ASN1_OBJECT* obj = NULL;
  67860. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67861. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  67862. if (f != XBADFILE)
  67863. XFCLOSE(f);
  67864. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  67865. -1), 0);
  67866. /* Start search from last location (should fail) */
  67867. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  67868. rc), -1);
  67869. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  67870. -2), -1);
  67871. ExpectIntEQ(rc = wolfSSL_X509_get_ext_by_NID(NULL, NID_basic_constraints,
  67872. -1), -1);
  67873. ExpectIntEQ(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_undef, -1), -1);
  67874. /* NID_ext_key_usage, check also its nid and oid */
  67875. ExpectIntGT(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_ext_key_usage, -1),
  67876. -1);
  67877. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(wolfSSL_X509_get_ext(
  67878. x509, rc)));
  67879. ExpectIntEQ(obj->nid, NID_ext_key_usage);
  67880. ExpectIntEQ(obj->type, EXT_KEY_USAGE_OID);
  67881. wolfSSL_X509_free(x509);
  67882. #endif
  67883. return EXPECT_RESULT();
  67884. }
  67885. static int test_wolfSSL_X509_get_ext_subj_alt_name(void)
  67886. {
  67887. EXPECT_DECLS;
  67888. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  67889. int rc = 0;
  67890. XFILE f = XBADFILE;
  67891. WOLFSSL_X509* x509 = NULL;
  67892. WOLFSSL_X509_EXTENSION* ext = NULL;
  67893. WOLFSSL_ASN1_STRING* sanString = NULL;
  67894. byte* sanDer = NULL;
  67895. const byte expectedDer[] = {
  67896. 0x30, 0x13, 0x82, 0x0b, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e,
  67897. 0x63, 0x6f, 0x6d, 0x87, 0x04, 0x7f, 0x00, 0x00, 0x01};
  67898. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67899. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  67900. if (f != XBADFILE)
  67901. XFCLOSE(f);
  67902. ExpectIntNE(rc = X509_get_ext_by_NID(x509, NID_subject_alt_name, -1), -1);
  67903. ExpectNotNull(ext = X509_get_ext(x509, rc));
  67904. ExpectNotNull(sanString = X509_EXTENSION_get_data(ext));
  67905. ExpectIntEQ(ASN1_STRING_length(sanString), sizeof(expectedDer));
  67906. ExpectNotNull(sanDer = ASN1_STRING_data(sanString));
  67907. ExpectIntEQ(XMEMCMP(sanDer, expectedDer, sizeof(expectedDer)), 0);
  67908. X509_free(x509);
  67909. #endif
  67910. return EXPECT_RESULT();
  67911. }
  67912. static int test_wolfSSL_X509_EXTENSION_new(void)
  67913. {
  67914. EXPECT_DECLS;
  67915. #if defined (OPENSSL_ALL)
  67916. WOLFSSL_X509_EXTENSION* ext = NULL;
  67917. ExpectNotNull(ext = wolfSSL_X509_EXTENSION_new());
  67918. ExpectNotNull(ext->obj = wolfSSL_ASN1_OBJECT_new());
  67919. wolfSSL_X509_EXTENSION_free(ext);
  67920. #endif
  67921. return EXPECT_RESULT();
  67922. }
  67923. static int test_wolfSSL_X509_EXTENSION_get_object(void)
  67924. {
  67925. EXPECT_DECLS;
  67926. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  67927. WOLFSSL_X509* x509 = NULL;
  67928. WOLFSSL_X509_EXTENSION* ext = NULL;
  67929. WOLFSSL_ASN1_OBJECT* o = NULL;
  67930. XFILE file = XBADFILE;
  67931. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67932. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  67933. if (file != XBADFILE)
  67934. XFCLOSE(file);
  67935. /* wolfSSL_X509_EXTENSION_get_object() testing ext idx 0 */
  67936. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  67937. ExpectNull(wolfSSL_X509_EXTENSION_get_object(NULL));
  67938. ExpectNotNull(o = wolfSSL_X509_EXTENSION_get_object(ext));
  67939. ExpectIntEQ(o->nid, 128);
  67940. /* wolfSSL_X509_EXTENSION_get_object() NULL argument */
  67941. ExpectNull(o = wolfSSL_X509_EXTENSION_get_object(NULL));
  67942. wolfSSL_X509_free(x509);
  67943. #endif
  67944. return EXPECT_RESULT();
  67945. }
  67946. static int test_wolfSSL_X509_EXTENSION_get_data(void)
  67947. {
  67948. EXPECT_DECLS;
  67949. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  67950. WOLFSSL_X509* x509 = NULL;
  67951. WOLFSSL_X509_EXTENSION* ext = NULL;
  67952. WOLFSSL_ASN1_STRING* str = NULL;
  67953. XFILE file = XBADFILE;
  67954. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67955. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  67956. if (file != XBADFILE)
  67957. XFCLOSE(file);
  67958. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  67959. ExpectNull(str = wolfSSL_X509_EXTENSION_get_data(NULL));
  67960. ExpectNotNull(str = wolfSSL_X509_EXTENSION_get_data(ext));
  67961. wolfSSL_X509_free(x509);
  67962. #endif
  67963. return EXPECT_RESULT();
  67964. }
  67965. static int test_wolfSSL_X509_EXTENSION_get_critical(void)
  67966. {
  67967. EXPECT_DECLS;
  67968. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  67969. WOLFSSL_X509* x509 = NULL;
  67970. WOLFSSL_X509_EXTENSION* ext = NULL;
  67971. XFILE file = XBADFILE;
  67972. int crit = 0;
  67973. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67974. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  67975. if (file != XBADFILE)
  67976. XFCLOSE(file);
  67977. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  67978. ExpectIntEQ(crit = wolfSSL_X509_EXTENSION_get_critical(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  67979. ExpectIntEQ(crit = wolfSSL_X509_EXTENSION_get_critical(ext), 0);
  67980. wolfSSL_X509_free(x509);
  67981. #endif
  67982. return EXPECT_RESULT();
  67983. }
  67984. static int test_wolfSSL_X509V3_EXT_print(void)
  67985. {
  67986. EXPECT_DECLS;
  67987. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_BIO) && \
  67988. !defined(NO_RSA)
  67989. {
  67990. XFILE f = XBADFILE;
  67991. WOLFSSL_X509* x509 = NULL;
  67992. X509_EXTENSION * ext = NULL;
  67993. int loc = 0;
  67994. BIO *bio = NULL;
  67995. ExpectTrue((f = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  67996. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  67997. if (f != XBADFILE)
  67998. fclose(f);
  67999. ExpectNotNull(bio = wolfSSL_BIO_new(BIO_s_mem()));
  68000. ExpectIntGT(loc = wolfSSL_X509_get_ext_by_NID(x509,
  68001. NID_basic_constraints, -1), -1);
  68002. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, loc));
  68003. ExpectIntEQ(wolfSSL_X509V3_EXT_print(bio, ext, 0, 0), WOLFSSL_SUCCESS);
  68004. ExpectIntGT(loc = wolfSSL_X509_get_ext_by_NID(x509,
  68005. NID_subject_key_identifier, -1), -1);
  68006. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, loc));
  68007. ExpectIntEQ(wolfSSL_X509V3_EXT_print(bio, ext, 0, 0), WOLFSSL_SUCCESS);
  68008. ExpectIntGT(loc = wolfSSL_X509_get_ext_by_NID(x509,
  68009. NID_authority_key_identifier, -1), -1);
  68010. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, loc));
  68011. ExpectIntEQ(wolfSSL_X509V3_EXT_print(bio, ext, 0, 0), WOLFSSL_SUCCESS);
  68012. wolfSSL_BIO_free(bio);
  68013. wolfSSL_X509_free(x509);
  68014. }
  68015. {
  68016. X509 *x509 = NULL;
  68017. BIO *bio = NULL;
  68018. X509_EXTENSION *ext = NULL;
  68019. unsigned int i = 0;
  68020. unsigned int idx = 0;
  68021. /* Some NIDs to test with */
  68022. int nids[] = {
  68023. /* NID_key_usage, currently X509_get_ext returns this as a bit
  68024. * string, which messes up X509V3_EXT_print */
  68025. /* NID_ext_key_usage, */
  68026. NID_subject_alt_name,
  68027. };
  68028. int* n = NULL;
  68029. ExpectNotNull(bio = BIO_new_fp(stderr, BIO_NOCLOSE));
  68030. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFileExt,
  68031. WOLFSSL_FILETYPE_PEM));
  68032. ExpectIntGT(fprintf(stderr, "\nPrinting extension values:\n"), 0);
  68033. for (i = 0, n = nids; i<(sizeof(nids)/sizeof(int)); i++, n++) {
  68034. /* X509_get_ext_by_NID should return 3 for now. If that changes then
  68035. * update the index */
  68036. ExpectIntEQ((idx = X509_get_ext_by_NID(x509, *n, -1)), 3);
  68037. ExpectNotNull(ext = X509_get_ext(x509, (int)idx));
  68038. ExpectIntEQ(X509V3_EXT_print(bio, ext, 0, 0), 1);
  68039. ExpectIntGT(fprintf(stderr, "\n"), 0);
  68040. }
  68041. BIO_free(bio);
  68042. X509_free(x509);
  68043. }
  68044. #endif
  68045. return EXPECT_RESULT();
  68046. }
  68047. static int test_wolfSSL_X509_cmp(void)
  68048. {
  68049. EXPECT_DECLS;
  68050. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  68051. XFILE file1 = XBADFILE;
  68052. XFILE file2 = XBADFILE;
  68053. WOLFSSL_X509* cert1 = NULL;
  68054. WOLFSSL_X509* cert2 = NULL;
  68055. ExpectTrue((file1 = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  68056. ExpectTrue((file2 = XFOPEN("./certs/3072/client-cert.pem", "rb")) !=
  68057. XBADFILE);
  68058. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  68059. ExpectNotNull(cert2 = wolfSSL_PEM_read_X509(file2, NULL, NULL, NULL));
  68060. if (file1 != XBADFILE)
  68061. fclose(file1);
  68062. if (file2 != XBADFILE)
  68063. fclose(file2);
  68064. /* wolfSSL_X509_cmp() testing matching certs */
  68065. ExpectIntEQ(0, wolfSSL_X509_cmp(cert1, cert1));
  68066. /* wolfSSL_X509_cmp() testing mismatched certs */
  68067. ExpectIntEQ(-1, wolfSSL_X509_cmp(cert1, cert2));
  68068. /* wolfSSL_X509_cmp() testing NULL, valid args */
  68069. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(NULL, cert2));
  68070. /* wolfSSL_X509_cmp() testing valid, NULL args */
  68071. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(cert1, NULL));
  68072. /* wolfSSL_X509_cmp() testing NULL, NULL args */
  68073. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(NULL, NULL));
  68074. wolfSSL_X509_free(cert1);
  68075. wolfSSL_X509_free(cert2);
  68076. #endif
  68077. return EXPECT_RESULT();
  68078. }
  68079. static int test_wolfSSL_EVP_PKEY_up_ref(void)
  68080. {
  68081. EXPECT_DECLS;
  68082. #if defined(OPENSSL_ALL)
  68083. EVP_PKEY* pkey;
  68084. pkey = EVP_PKEY_new();
  68085. ExpectNotNull(pkey);
  68086. ExpectIntEQ(EVP_PKEY_up_ref(NULL), 0);
  68087. ExpectIntEQ(EVP_PKEY_up_ref(pkey), 1);
  68088. EVP_PKEY_free(pkey);
  68089. ExpectIntEQ(EVP_PKEY_up_ref(pkey), 1);
  68090. EVP_PKEY_free(pkey);
  68091. EVP_PKEY_free(pkey);
  68092. #endif
  68093. return EXPECT_RESULT();
  68094. }
  68095. static int test_wolfSSL_d2i_and_i2d_PublicKey(void)
  68096. {
  68097. EXPECT_DECLS;
  68098. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  68099. EVP_PKEY* pkey = NULL;
  68100. const unsigned char* p;
  68101. unsigned char *der = NULL;
  68102. unsigned char *tmp = NULL;
  68103. int derLen;
  68104. p = client_keypub_der_2048;
  68105. /* Check that key can be successfully decoded. */
  68106. ExpectNotNull(pkey = wolfSSL_d2i_PublicKey(EVP_PKEY_RSA, NULL, &p,
  68107. sizeof_client_keypub_der_2048));
  68108. /* Check that key can be successfully encoded. */
  68109. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &der)), 0);
  68110. /* Ensure that the encoded version matches the original. */
  68111. ExpectIntEQ(derLen, sizeof_client_keypub_der_2048);
  68112. ExpectIntEQ(XMEMCMP(der, client_keypub_der_2048, derLen), 0);
  68113. /* Do same test except with pre-allocated buffer to ensure the der pointer
  68114. * is advanced. */
  68115. tmp = der;
  68116. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &tmp)), 0);
  68117. ExpectIntEQ(derLen, sizeof_client_keypub_der_2048);
  68118. ExpectIntEQ(XMEMCMP(der, client_keypub_der_2048, derLen), 0);
  68119. ExpectTrue(der + derLen == tmp);
  68120. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  68121. EVP_PKEY_free(pkey);
  68122. #endif
  68123. return EXPECT_RESULT();
  68124. }
  68125. static int test_wolfSSL_d2i_and_i2d_PublicKey_ecc(void)
  68126. {
  68127. EXPECT_DECLS;
  68128. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && !defined(NO_CERTS) && \
  68129. !defined(NO_ASN) && !defined(NO_PWDBASED)
  68130. EVP_PKEY* pkey = NULL;
  68131. const unsigned char* p;
  68132. unsigned char *der = NULL;
  68133. unsigned char *tmp = NULL;
  68134. int derLen;
  68135. unsigned char pub_buf[65];
  68136. const int pub_len = 65;
  68137. BN_CTX* ctx;
  68138. EC_GROUP* curve = NULL;
  68139. EC_KEY* ephemeral_key = NULL;
  68140. const EC_POINT* h = NULL;
  68141. /* Generate an x963 key pair and get public part into pub_buf */
  68142. ExpectNotNull(ctx = BN_CTX_new());
  68143. ExpectNotNull(curve = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  68144. ExpectNotNull(ephemeral_key = EC_KEY_new_by_curve_name(
  68145. NID_X9_62_prime256v1));
  68146. ExpectIntEQ(EC_KEY_generate_key(ephemeral_key), 1);
  68147. ExpectNotNull(h = EC_KEY_get0_public_key(ephemeral_key));
  68148. ExpectIntEQ(pub_len, EC_POINT_point2oct(curve, h,
  68149. POINT_CONVERSION_UNCOMPRESSED, pub_buf, pub_len, ctx));
  68150. /* Prepare the EVP_PKEY */
  68151. ExpectNotNull(pkey = EVP_PKEY_new());
  68152. p = pub_buf;
  68153. /* Check that key can be successfully decoded. */
  68154. ExpectNotNull(wolfSSL_d2i_PublicKey(EVP_PKEY_EC, &pkey, &p,
  68155. pub_len));
  68156. /* Check that key can be successfully encoded. */
  68157. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &der)), 0);
  68158. /* Ensure that the encoded version matches the original. */
  68159. ExpectIntEQ(derLen, pub_len);
  68160. ExpectIntEQ(XMEMCMP(der, pub_buf, derLen), 0);
  68161. /* Do same test except with pre-allocated buffer to ensure the der pointer
  68162. * is advanced. */
  68163. tmp = der;
  68164. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &tmp)), 0);
  68165. ExpectIntEQ(derLen, pub_len);
  68166. ExpectIntEQ(XMEMCMP(der, pub_buf, derLen), 0);
  68167. ExpectTrue(der + derLen == tmp);
  68168. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  68169. EVP_PKEY_free(pkey);
  68170. EC_KEY_free(ephemeral_key);
  68171. EC_GROUP_free(curve);
  68172. #endif
  68173. return EXPECT_RESULT();
  68174. }
  68175. static int test_wolfSSL_d2i_and_i2d_DSAparams(void)
  68176. {
  68177. EXPECT_DECLS;
  68178. #if defined(OPENSSL_EXTRA) && !defined(NO_DSA)
  68179. DSA* dsa = NULL;
  68180. byte derIn[] = {
  68181. 0x30, 0x82, 0x01, 0x1f, 0x02, 0x81, 0x81, 0x00,
  68182. 0xcd, 0xde, 0x25, 0x68, 0x80, 0x53, 0x0d, 0xe5,
  68183. 0x77, 0xd6, 0xd2, 0x90, 0x39, 0x3f, 0x90, 0xa2,
  68184. 0x3f, 0x33, 0x94, 0x6e, 0xe8, 0x4f, 0x2b, 0x63,
  68185. 0xab, 0x30, 0xab, 0x15, 0xba, 0x11, 0xea, 0x8a,
  68186. 0x5d, 0x8d, 0xcc, 0xb8, 0xd4, 0xa1, 0xd5, 0xc1,
  68187. 0x47, 0x9d, 0x5a, 0x73, 0x6a, 0x62, 0x49, 0xd1,
  68188. 0x06, 0x07, 0x67, 0xf6, 0x2f, 0xa3, 0x39, 0xbd,
  68189. 0x4e, 0x0d, 0xb4, 0xd3, 0x22, 0x23, 0x84, 0xec,
  68190. 0x93, 0x26, 0x5a, 0x49, 0xee, 0x7c, 0x89, 0x48,
  68191. 0x66, 0x4d, 0xe8, 0xe8, 0xd8, 0x50, 0xfb, 0xa5,
  68192. 0x71, 0x9f, 0x22, 0x18, 0xe5, 0xe6, 0x0b, 0x46,
  68193. 0x87, 0x66, 0xee, 0x52, 0x8f, 0x46, 0x4f, 0xb5,
  68194. 0x03, 0xce, 0xed, 0xe3, 0xbe, 0xe5, 0xb5, 0x81,
  68195. 0xd2, 0x59, 0xe9, 0xc0, 0xad, 0x4d, 0xd0, 0x4d,
  68196. 0x26, 0xf7, 0xba, 0x50, 0xe8, 0xc9, 0x8f, 0xfe,
  68197. 0x24, 0x19, 0x3d, 0x2e, 0xa7, 0x52, 0x3c, 0x6d,
  68198. 0x02, 0x15, 0x00, 0xfb, 0x47, 0xfb, 0xec, 0x81,
  68199. 0x20, 0xc8, 0x1c, 0xe9, 0x4a, 0xba, 0x04, 0x6f,
  68200. 0x19, 0x9b, 0x94, 0xee, 0x82, 0x67, 0xd3, 0x02,
  68201. 0x81, 0x81, 0x00, 0x9b, 0x95, 0xbb, 0x85, 0xc5,
  68202. 0x58, 0x4a, 0x32, 0x9c, 0xaa, 0x44, 0x85, 0xd6,
  68203. 0x68, 0xdc, 0x3e, 0x14, 0xf4, 0xce, 0x6d, 0xa3,
  68204. 0x49, 0x38, 0xea, 0xd6, 0x61, 0x48, 0x92, 0x5a,
  68205. 0x40, 0x95, 0x49, 0x38, 0xaa, 0xe1, 0x39, 0x29,
  68206. 0x68, 0x58, 0x47, 0x8a, 0x4b, 0x01, 0xe1, 0x2e,
  68207. 0x8e, 0x6c, 0x63, 0x6f, 0x40, 0xca, 0x50, 0x3f,
  68208. 0x8c, 0x0b, 0x99, 0xe4, 0x72, 0x42, 0xb8, 0xb1,
  68209. 0xc2, 0x26, 0x48, 0xf1, 0x9c, 0x83, 0xc6, 0x37,
  68210. 0x2e, 0x5a, 0xae, 0x11, 0x09, 0xd9, 0xf3, 0xad,
  68211. 0x1f, 0x6f, 0xad, 0xad, 0x50, 0xe3, 0x78, 0x32,
  68212. 0xe6, 0xde, 0x8e, 0xaa, 0xbf, 0xd1, 0x00, 0x9f,
  68213. 0xb3, 0x02, 0x12, 0x19, 0xa2, 0x15, 0xec, 0x14,
  68214. 0x18, 0x5c, 0x0e, 0x26, 0xce, 0xf9, 0xae, 0xcc,
  68215. 0x7b, 0xb5, 0xd1, 0x26, 0xfc, 0x85, 0xfe, 0x14,
  68216. 0x93, 0xb6, 0x9d, 0x7d, 0x76, 0xe3, 0x35, 0x97,
  68217. 0x1e, 0xde, 0xc4
  68218. };
  68219. int derInLen = sizeof(derIn);
  68220. byte* derOut = NULL;
  68221. int derOutLen;
  68222. byte* p = derIn;
  68223. /* Check that params can be successfully decoded. */
  68224. ExpectNotNull(dsa = d2i_DSAparams(NULL, (const byte**)&p, derInLen));
  68225. /* Check that params can be successfully encoded. */
  68226. ExpectIntGE((derOutLen = i2d_DSAparams(dsa, &derOut)), 0);
  68227. /* Ensure that the encoded version matches the original. */
  68228. ExpectIntEQ(derInLen, derOutLen);
  68229. ExpectIntEQ(XMEMCMP(derIn, derOut, derInLen), 0);
  68230. XFREE(derOut, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  68231. DSA_free(dsa);
  68232. #endif
  68233. return EXPECT_RESULT();
  68234. }
  68235. static int test_wolfSSL_i2d_PrivateKey(void)
  68236. {
  68237. EXPECT_DECLS;
  68238. #if (!defined(NO_RSA) || defined(HAVE_ECC)) && defined(OPENSSL_EXTRA) && \
  68239. !defined(NO_ASN) && !defined(NO_PWDBASED)
  68240. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  68241. {
  68242. EVP_PKEY* pkey = NULL;
  68243. const unsigned char* server_key =
  68244. (const unsigned char*)server_key_der_2048;
  68245. unsigned char buf[FOURK_BUF];
  68246. unsigned char* pt = NULL;
  68247. int bufSz = 0;
  68248. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &server_key,
  68249. (long)sizeof_server_key_der_2048));
  68250. ExpectIntEQ(i2d_PrivateKey(pkey, NULL), 1193);
  68251. pt = buf;
  68252. ExpectIntEQ((bufSz = i2d_PrivateKey(pkey, &pt)), 1193);
  68253. ExpectIntNE((pt - buf), 0);
  68254. ExpectIntEQ(XMEMCMP(buf, server_key_der_2048, bufSz), 0);
  68255. EVP_PKEY_free(pkey);
  68256. }
  68257. #endif
  68258. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  68259. {
  68260. EVP_PKEY* pkey = NULL;
  68261. const unsigned char* client_key =
  68262. (const unsigned char*)ecc_clikey_der_256;
  68263. unsigned char buf[FOURK_BUF];
  68264. unsigned char* pt = NULL;
  68265. int bufSz = 0;
  68266. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &client_key,
  68267. (long)sizeof_ecc_clikey_der_256)));
  68268. ExpectIntEQ(i2d_PrivateKey(pkey, NULL), 121);
  68269. pt = buf;
  68270. ExpectIntEQ((bufSz = i2d_PrivateKey(pkey, &pt)), 121);
  68271. ExpectIntNE((pt - buf), 0);
  68272. ExpectIntEQ(XMEMCMP(buf, ecc_clikey_der_256, bufSz), 0);
  68273. EVP_PKEY_free(pkey);
  68274. }
  68275. #endif
  68276. #endif
  68277. return EXPECT_RESULT();
  68278. }
  68279. static int test_wolfSSL_OCSP_id_get0_info(void)
  68280. {
  68281. EXPECT_DECLS;
  68282. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && \
  68283. defined(HAVE_OCSP) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  68284. X509* cert = NULL;
  68285. X509* issuer = NULL;
  68286. OCSP_CERTID* id = NULL;
  68287. OCSP_CERTID* id2 = NULL;
  68288. ASN1_STRING* name = NULL;
  68289. ASN1_OBJECT* pmd = NULL;
  68290. ASN1_STRING* keyHash = NULL;
  68291. ASN1_INTEGER* serial = NULL;
  68292. ASN1_INTEGER* x509Int = NULL;
  68293. ExpectNotNull(cert = wolfSSL_X509_load_certificate_file(svrCertFile,
  68294. SSL_FILETYPE_PEM));
  68295. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caCertFile,
  68296. SSL_FILETYPE_PEM));
  68297. ExpectNotNull(id = OCSP_cert_to_id(NULL, cert, issuer));
  68298. ExpectNotNull(id2 = OCSP_cert_to_id(NULL, cert, issuer));
  68299. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, NULL, NULL), 0);
  68300. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, NULL, id), 1);
  68301. /* name, pmd, keyHash not supported yet, expect failure if not NULL */
  68302. ExpectIntEQ(OCSP_id_get0_info(&name, NULL, NULL, NULL, id), 0);
  68303. ExpectIntEQ(OCSP_id_get0_info(NULL, &pmd, NULL, NULL, id), 0);
  68304. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, &keyHash, NULL, id), 0);
  68305. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, &serial, id), 1);
  68306. ExpectNotNull(serial);
  68307. /* compare serial number to one in cert, should be equal */
  68308. ExpectNotNull(x509Int = X509_get_serialNumber(cert));
  68309. ExpectIntEQ(x509Int->length, serial->length);
  68310. ExpectIntEQ(XMEMCMP(x509Int->data, serial->data, serial->length), 0);
  68311. /* test OCSP_id_cmp */
  68312. ExpectIntNE(OCSP_id_cmp(NULL, NULL), 0);
  68313. ExpectIntNE(OCSP_id_cmp(id, NULL), 0);
  68314. ExpectIntNE(OCSP_id_cmp(NULL, id2), 0);
  68315. ExpectIntEQ(OCSP_id_cmp(id, id2), 0);
  68316. if (id != NULL) {
  68317. id->issuerHash[0] = ~id->issuerHash[0];
  68318. }
  68319. ExpectIntNE(OCSP_id_cmp(id, id2), 0);
  68320. OCSP_CERTID_free(id);
  68321. OCSP_CERTID_free(id2);
  68322. X509_free(cert); /* free's x509Int */
  68323. X509_free(issuer);
  68324. #endif
  68325. return EXPECT_RESULT();
  68326. }
  68327. static int test_wolfSSL_i2d_OCSP_CERTID(void)
  68328. {
  68329. EXPECT_DECLS;
  68330. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && defined(HAVE_OCSP)
  68331. WOLFSSL_OCSP_CERTID certId;
  68332. byte* targetBuffer = NULL;
  68333. byte* p;
  68334. /* OCSP CertID bytes taken from PCAP */
  68335. byte rawCertId[] = {
  68336. 0x30, 0x49, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
  68337. 0x00, 0x04, 0x14, 0x80, 0x51, 0x06, 0x01, 0x32, 0xad, 0x9a, 0xc2, 0x7d,
  68338. 0x51, 0x87, 0xa0, 0xe8, 0x87, 0xfb, 0x01, 0x62, 0x01, 0x55, 0xee, 0x04,
  68339. 0x14, 0x03, 0xde, 0x50, 0x35, 0x56, 0xd1, 0x4c, 0xbb, 0x66, 0xf0, 0xa3,
  68340. 0xe2, 0x1b, 0x1b, 0xc3, 0x97, 0xb2, 0x3d, 0xd1, 0x55, 0x02, 0x10, 0x01,
  68341. 0xfd, 0xa3, 0xeb, 0x6e, 0xca, 0x75, 0xc8, 0x88, 0x43, 0x8b, 0x72, 0x4b,
  68342. 0xcf, 0xbc, 0x91
  68343. };
  68344. int ret = 0;
  68345. int i;
  68346. XMEMSET(&certId, 0, sizeof(WOLFSSL_OCSP_CERTID));
  68347. certId.rawCertId = rawCertId;
  68348. certId.rawCertIdSize = sizeof(rawCertId);
  68349. ExpectNotNull(targetBuffer = (byte*)XMALLOC(sizeof(rawCertId), NULL,
  68350. DYNAMIC_TYPE_TMP_BUFFER));
  68351. p = targetBuffer;
  68352. /* Function returns the size of the encoded data. */
  68353. ExpectIntEQ(ret = wolfSSL_i2d_OCSP_CERTID(&certId, &p), sizeof(rawCertId));
  68354. /* If target buffer is not null, function increments targetBuffer to point
  68355. * just past the end of the encoded data. */
  68356. ExpectPtrEq(p, (targetBuffer + sizeof(rawCertId)));
  68357. for (i = 0; EXPECT_SUCCESS() && i < ret; ++i) {
  68358. ExpectIntEQ(targetBuffer[i], rawCertId[i]);
  68359. }
  68360. XFREE(targetBuffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  68361. targetBuffer = NULL;
  68362. /* If target buffer is null, function allocates memory for a buffer and
  68363. * copies the encoded data into it. targetBuffer then points to the start of
  68364. * this newly allocate buffer. */
  68365. ExpectIntEQ(ret = wolfSSL_i2d_OCSP_CERTID(&certId, &targetBuffer),
  68366. sizeof(rawCertId));
  68367. for (i = 0; EXPECT_SUCCESS() && i < ret; ++i) {
  68368. ExpectIntEQ(targetBuffer[i], rawCertId[i]);
  68369. }
  68370. XFREE(targetBuffer, NULL, DYNAMIC_TYPE_OPENSSL);
  68371. #endif
  68372. return EXPECT_RESULT();
  68373. }
  68374. static int test_wolfSSL_d2i_OCSP_CERTID(void)
  68375. {
  68376. EXPECT_DECLS;
  68377. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && defined(HAVE_OCSP)
  68378. WOLFSSL_OCSP_CERTID* certId;
  68379. WOLFSSL_OCSP_CERTID* certIdGood;
  68380. WOLFSSL_OCSP_CERTID* certIdBad;
  68381. const unsigned char* rawCertIdPtr;
  68382. const unsigned char rawCertId[] = {
  68383. 0x30, 0x49, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
  68384. 0x00, 0x04, 0x14, 0x80, 0x51, 0x06, 0x01, 0x32, 0xad, 0x9a, 0xc2, 0x7d,
  68385. 0x51, 0x87, 0xa0, 0xe8, 0x87, 0xfb, 0x01, 0x62, 0x01, 0x55, 0xee, 0x04,
  68386. 0x14, 0x03, 0xde, 0x50, 0x35, 0x56, 0xd1, 0x4c, 0xbb, 0x66, 0xf0, 0xa3,
  68387. 0xe2, 0x1b, 0x1b, 0xc3, 0x97, 0xb2, 0x3d, 0xd1, 0x55, 0x02, 0x10, 0x01,
  68388. 0xfd, 0xa3, 0xeb, 0x6e, 0xca, 0x75, 0xc8, 0x88, 0x43, 0x8b, 0x72, 0x4b,
  68389. 0xcf, 0xbc, 0x91
  68390. };
  68391. rawCertIdPtr = &rawCertId[0];
  68392. /* If the cert ID is NULL the function should allocate it and copy the
  68393. * data to it. */
  68394. certId = NULL;
  68395. ExpectNotNull(certId = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr,
  68396. sizeof(rawCertId)));
  68397. ExpectIntEQ(certId->rawCertIdSize, sizeof(rawCertId));
  68398. if (certId != NULL) {
  68399. XFREE(certId->rawCertId, NULL, DYNAMIC_TYPE_OPENSSL);
  68400. XFREE(certId, NULL, DYNAMIC_TYPE_OPENSSL);
  68401. }
  68402. /* If the cert ID is not NULL the function will just copy the data to it. */
  68403. ExpectNotNull(certId = (WOLFSSL_OCSP_CERTID*)XMALLOC(sizeof(*certId), NULL,
  68404. DYNAMIC_TYPE_TMP_BUFFER));
  68405. ExpectNotNull(certId);
  68406. ExpectNotNull(XMEMSET(certId, 0, sizeof(*certId)));
  68407. /* Reset rawCertIdPtr since it was push forward in the previous call. */
  68408. rawCertIdPtr = &rawCertId[0];
  68409. ExpectNotNull(certIdGood = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr,
  68410. sizeof(rawCertId)));
  68411. ExpectPtrEq(certIdGood, certId);
  68412. ExpectIntEQ(certId->rawCertIdSize, sizeof(rawCertId));
  68413. if (certId != NULL) {
  68414. XFREE(certId->rawCertId, NULL, DYNAMIC_TYPE_OPENSSL);
  68415. XFREE(certId, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  68416. certId = NULL;
  68417. }
  68418. /* The below tests should fail when passed bad parameters. NULL should
  68419. * always be returned. */
  68420. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(NULL, &rawCertIdPtr,
  68421. sizeof(rawCertId)));
  68422. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(&certId, NULL,
  68423. sizeof(rawCertId)));
  68424. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr, 0));
  68425. #endif
  68426. return EXPECT_RESULT();
  68427. }
  68428. static int test_wolfSSL_OCSP_id_cmp(void)
  68429. {
  68430. EXPECT_DECLS;
  68431. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP)
  68432. OCSP_CERTID id1;
  68433. OCSP_CERTID id2;
  68434. XMEMSET(&id1, 0, sizeof(id1));
  68435. XMEMSET(&id2, 0, sizeof(id2));
  68436. ExpectIntEQ(OCSP_id_cmp(&id1, &id2), 0);
  68437. ExpectIntNE(OCSP_id_cmp(NULL, NULL), 0);
  68438. ExpectIntNE(OCSP_id_cmp(&id1, NULL), 0);
  68439. ExpectIntNE(OCSP_id_cmp(NULL, &id2), 0);
  68440. #endif
  68441. return EXPECT_RESULT();
  68442. }
  68443. static int test_wolfSSL_OCSP_SINGLERESP_get0_id(void)
  68444. {
  68445. EXPECT_DECLS;
  68446. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  68447. WOLFSSL_OCSP_SINGLERESP single;
  68448. const WOLFSSL_OCSP_CERTID* certId;
  68449. XMEMSET(&single, 0, sizeof(single));
  68450. certId = wolfSSL_OCSP_SINGLERESP_get0_id(&single);
  68451. ExpectPtrEq(&single, certId);
  68452. ExpectNull(wolfSSL_OCSP_SINGLERESP_get0_id(NULL));
  68453. #endif
  68454. return EXPECT_RESULT();
  68455. }
  68456. static int test_wolfSSL_OCSP_single_get0_status(void)
  68457. {
  68458. EXPECT_DECLS;
  68459. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA) && \
  68460. defined(WOLFSSL_OCSP_PARSE_STATUS)
  68461. WOLFSSL_OCSP_SINGLERESP single;
  68462. CertStatus certStatus;
  68463. WOLFSSL_ASN1_TIME* thisDate;
  68464. WOLFSSL_ASN1_TIME* nextDate;
  68465. int ret, i;
  68466. XMEMSET(&single, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  68467. XMEMSET(&certStatus, 0, sizeof(CertStatus));
  68468. /* Fill the date fields with some dummy data. */
  68469. for (i = 0; i < CTC_DATE_SIZE; ++i) {
  68470. certStatus.thisDateParsed.data[i] = i;
  68471. certStatus.nextDateParsed.data[i] = i;
  68472. }
  68473. certStatus.status = CERT_GOOD;
  68474. single.status = &certStatus;
  68475. ret = wolfSSL_OCSP_single_get0_status(&single, NULL, NULL, &thisDate,
  68476. &nextDate);
  68477. ExpectIntEQ(ret, CERT_GOOD);
  68478. ExpectPtrEq(thisDate, &certStatus.thisDateParsed);
  68479. ExpectPtrEq(nextDate, &certStatus.nextDateParsed);
  68480. ExpectIntEQ(wolfSSL_OCSP_single_get0_status(NULL, NULL, NULL, NULL, NULL),
  68481. CERT_GOOD);
  68482. ExpectIntEQ(wolfSSL_OCSP_single_get0_status(&single, NULL, NULL, NULL,
  68483. NULL), CERT_GOOD);
  68484. #endif
  68485. return EXPECT_RESULT();
  68486. }
  68487. static int test_wolfSSL_OCSP_resp_count(void)
  68488. {
  68489. EXPECT_DECLS;
  68490. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  68491. WOLFSSL_OCSP_BASICRESP basicResp;
  68492. WOLFSSL_OCSP_SINGLERESP singleRespOne;
  68493. WOLFSSL_OCSP_SINGLERESP singleRespTwo;
  68494. XMEMSET(&basicResp, 0, sizeof(WOLFSSL_OCSP_BASICRESP));
  68495. XMEMSET(&singleRespOne, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  68496. XMEMSET(&singleRespTwo, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  68497. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 0);
  68498. basicResp.single = &singleRespOne;
  68499. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 1);
  68500. singleRespOne.next = &singleRespTwo;
  68501. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 2);
  68502. #endif
  68503. return EXPECT_RESULT();
  68504. }
  68505. static int test_wolfSSL_OCSP_resp_get0(void)
  68506. {
  68507. EXPECT_DECLS;
  68508. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  68509. WOLFSSL_OCSP_BASICRESP basicResp;
  68510. WOLFSSL_OCSP_SINGLERESP singleRespOne;
  68511. WOLFSSL_OCSP_SINGLERESP singleRespTwo;
  68512. XMEMSET(&basicResp, 0, sizeof(WOLFSSL_OCSP_BASICRESP));
  68513. XMEMSET(&singleRespOne, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  68514. XMEMSET(&singleRespTwo, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  68515. basicResp.single = &singleRespOne;
  68516. singleRespOne.next = &singleRespTwo;
  68517. ExpectPtrEq(wolfSSL_OCSP_resp_get0(&basicResp, 0), &singleRespOne);
  68518. ExpectPtrEq(wolfSSL_OCSP_resp_get0(&basicResp, 1), &singleRespTwo);
  68519. #endif
  68520. return EXPECT_RESULT();
  68521. }
  68522. static int test_wolfSSL_OCSP_parse_url(void)
  68523. {
  68524. EXPECT_DECLS;
  68525. #if defined(OPENSSL_EXTRA) && defined(HAVE_OCSP)
  68526. #define CK_OPU_OK(u, h, po, pa, s) do { \
  68527. char* host = NULL; \
  68528. char* port = NULL; \
  68529. char* path = NULL; \
  68530. int isSsl = 0; \
  68531. ExpectIntEQ(OCSP_parse_url(u, &host, &port, &path, &isSsl), 1); \
  68532. ExpectStrEQ(host, h); \
  68533. ExpectStrEQ(port, po); \
  68534. ExpectStrEQ(path, pa); \
  68535. ExpectIntEQ(isSsl, s); \
  68536. XFREE(host, NULL, DYNAMIC_TYPE_OPENSSL); \
  68537. XFREE(port, NULL, DYNAMIC_TYPE_OPENSSL); \
  68538. XFREE(path, NULL, DYNAMIC_TYPE_OPENSSL); \
  68539. } while(0)
  68540. #define CK_OPU_FAIL(u) do { \
  68541. char* host = NULL; \
  68542. char* port = NULL; \
  68543. char* path = NULL; \
  68544. int isSsl = 0; \
  68545. ExpectIntEQ(OCSP_parse_url(u, &host, &port, &path, &isSsl), 0); \
  68546. XFREE(host, NULL, DYNAMIC_TYPE_OPENSSL); \
  68547. XFREE(port, NULL, DYNAMIC_TYPE_OPENSSL); \
  68548. XFREE(path, NULL, DYNAMIC_TYPE_OPENSSL); \
  68549. } while(0)
  68550. CK_OPU_OK("http://localhost", "localhost", "80", "/", 0);
  68551. CK_OPU_OK("https://wolfssl.com", "wolfssl.com", "443", "/", 1);
  68552. CK_OPU_OK("https://www.wolfssl.com/fips-140-3-announcement-to-the-world/",
  68553. "www.wolfssl.com", "443", "/fips-140-3-announcement-to-the-world/", 1);
  68554. CK_OPU_OK("http://localhost:1234", "localhost", "1234", "/", 0);
  68555. CK_OPU_OK("https://localhost:1234", "localhost", "1234", "/", 1);
  68556. CK_OPU_FAIL("ftp://localhost");
  68557. /* two strings to cppcheck doesn't mark it as a c++ style comment */
  68558. CK_OPU_FAIL("http/""/localhost");
  68559. CK_OPU_FAIL("http:/localhost");
  68560. CK_OPU_FAIL("https://localhost/path:1234");
  68561. #undef CK_OPU_OK
  68562. #undef CK_OPU_FAIL
  68563. #endif
  68564. return EXPECT_RESULT();
  68565. }
  68566. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP) && \
  68567. defined(WOLFSSL_SIGNER_DER_CERT) && !defined(NO_FILESYSTEM)
  68568. static time_t test_wolfSSL_OCSP_REQ_CTX_time_cb(time_t* t)
  68569. {
  68570. if (t != NULL) {
  68571. *t = 1722006780;
  68572. }
  68573. return 1722006780;
  68574. }
  68575. #endif
  68576. static int test_wolfSSL_OCSP_REQ_CTX(void)
  68577. {
  68578. EXPECT_DECLS;
  68579. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP) && \
  68580. defined(WOLFSSL_SIGNER_DER_CERT) && !defined(NO_FILESYSTEM)
  68581. /* This buffer was taken from the ocsp-stapling.test test case 1. The ocsp
  68582. * response was captured in wireshark. It contains both the http and binary
  68583. * parts. The time test_wolfSSL_OCSP_REQ_CTX_time_cb is set exactly so that
  68584. * the time check passes. */
  68585. unsigned char ocspRespBin[] = {
  68586. 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30,
  68587. 0x20, 0x4f, 0x4b, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
  68588. 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69,
  68589. 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6f, 0x63, 0x73, 0x70, 0x2d,
  68590. 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x0d, 0x0a, 0x43, 0x6f,
  68591. 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68,
  68592. 0x3a, 0x20, 0x31, 0x38, 0x32, 0x31, 0x0d, 0x0a, 0x0d, 0x0a, 0x30, 0x82,
  68593. 0x07, 0x19, 0x0a, 0x01, 0x00, 0xa0, 0x82, 0x07, 0x12, 0x30, 0x82, 0x07,
  68594. 0x0e, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x01,
  68595. 0x04, 0x82, 0x06, 0xff, 0x30, 0x82, 0x06, 0xfb, 0x30, 0x82, 0x01, 0x19,
  68596. 0xa1, 0x81, 0xa1, 0x30, 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03,
  68597. 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06,
  68598. 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e,
  68599. 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04,
  68600. 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10,
  68601. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c,
  68602. 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04,
  68603. 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69,
  68604. 0x6e, 0x67, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
  68605. 0x16, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, 0x43, 0x53,
  68606. 0x50, 0x20, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31,
  68607. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
  68608. 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c,
  68609. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x18, 0x0f, 0x32, 0x30,
  68610. 0x32, 0x34, 0x30, 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x35,
  68611. 0x5a, 0x30, 0x62, 0x30, 0x60, 0x30, 0x38, 0x30, 0x07, 0x06, 0x05, 0x2b,
  68612. 0x0e, 0x03, 0x02, 0x1a, 0x04, 0x14, 0x71, 0x4d, 0x82, 0x23, 0x40, 0x59,
  68613. 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, 0xba, 0xb1, 0x43, 0x18,
  68614. 0xda, 0x04, 0x04, 0x14, 0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02,
  68615. 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, 0x64, 0x44, 0xda, 0x0e,
  68616. 0x02, 0x01, 0x05, 0x80, 0x00, 0x18, 0x0f, 0x32, 0x30, 0x32, 0x34, 0x30,
  68617. 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x35, 0x5a, 0xa0, 0x11,
  68618. 0x18, 0x0f, 0x32, 0x30, 0x32, 0x34, 0x30, 0x37, 0x32, 0x36, 0x31, 0x35,
  68619. 0x31, 0x33, 0x30, 0x35, 0x5a, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  68620. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01,
  68621. 0x00, 0x89, 0x7a, 0xe9, 0x6b, 0x66, 0x47, 0x8e, 0x52, 0x16, 0xf9, 0x8a,
  68622. 0x5a, 0x1e, 0x7a, 0x35, 0xbb, 0x1d, 0x6c, 0xd8, 0x31, 0xbb, 0x24, 0xd2,
  68623. 0xd7, 0xa4, 0x30, 0x27, 0x06, 0x17, 0x66, 0xd1, 0xf9, 0x8d, 0x24, 0xb0,
  68624. 0x49, 0x37, 0x62, 0x13, 0x78, 0x5e, 0xa6, 0x6d, 0xea, 0xe3, 0xd0, 0x30,
  68625. 0x82, 0x7d, 0xb6, 0xf6, 0x55, 0x82, 0x11, 0xdc, 0xe7, 0x0f, 0xd6, 0x24,
  68626. 0xb4, 0x80, 0x23, 0x4f, 0xfd, 0xa7, 0x9a, 0x4b, 0xac, 0xf2, 0xd3, 0xde,
  68627. 0x42, 0x10, 0xfb, 0x4b, 0x29, 0x06, 0x02, 0x7b, 0x47, 0x36, 0x70, 0x75,
  68628. 0x45, 0x38, 0x8d, 0x3e, 0x55, 0x9c, 0xce, 0x78, 0xd8, 0x18, 0x45, 0x47,
  68629. 0x2d, 0x2a, 0x46, 0x65, 0x13, 0x93, 0x1a, 0x98, 0x90, 0xc6, 0x2d, 0xd5,
  68630. 0x05, 0x2a, 0xfc, 0xcb, 0xac, 0x53, 0x73, 0x93, 0x42, 0x4e, 0xdb, 0x17,
  68631. 0x91, 0xcb, 0xe1, 0x08, 0x03, 0xd1, 0x33, 0x57, 0x4b, 0x1d, 0xb8, 0x71,
  68632. 0x84, 0x01, 0x04, 0x47, 0x6f, 0x06, 0xfa, 0x76, 0x7d, 0xd9, 0x37, 0x64,
  68633. 0x57, 0x37, 0x3a, 0x8f, 0x4d, 0x88, 0x11, 0xa5, 0xd4, 0xaa, 0xcb, 0x49,
  68634. 0x47, 0x86, 0xdd, 0xcf, 0x46, 0xa6, 0xfa, 0x8e, 0xf2, 0x62, 0x0f, 0xc9,
  68635. 0x25, 0xf2, 0x39, 0x62, 0x3e, 0x2d, 0x35, 0xc4, 0x76, 0x7b, 0xae, 0xd5,
  68636. 0xe8, 0x85, 0xa1, 0xa6, 0x2d, 0x41, 0xd6, 0x8e, 0x3c, 0xfa, 0xdc, 0x6c,
  68637. 0x66, 0xe2, 0x61, 0xe7, 0xe5, 0x90, 0xa1, 0xfd, 0x7f, 0xdb, 0x18, 0xd0,
  68638. 0xeb, 0x6d, 0x73, 0x08, 0x5f, 0x6a, 0x65, 0x44, 0x50, 0xad, 0x38, 0x9d,
  68639. 0xb6, 0xfb, 0xbf, 0x28, 0x55, 0x84, 0x65, 0xfa, 0x0e, 0x34, 0xfc, 0x43,
  68640. 0x19, 0x80, 0x5c, 0x7d, 0x2d, 0x5b, 0xd8, 0x60, 0xec, 0x0e, 0xf9, 0x1e,
  68641. 0x6e, 0x32, 0x3f, 0x35, 0xf7, 0xec, 0x7e, 0x47, 0xba, 0xb5, 0xd2, 0xaa,
  68642. 0x5a, 0x9d, 0x07, 0x2c, 0xc5, 0xa0, 0x82, 0x04, 0xc6, 0x30, 0x82, 0x04,
  68643. 0xc2, 0x30, 0x82, 0x04, 0xbe, 0x30, 0x82, 0x03, 0xa6, 0xa0, 0x03, 0x02,
  68644. 0x01, 0x02, 0x02, 0x01, 0x04, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  68645. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x81, 0x97, 0x31,
  68646. 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53,
  68647. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57,
  68648. 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30,
  68649. 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74,
  68650. 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a,
  68651. 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30,
  68652. 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69,
  68653. 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16, 0x06,
  68654. 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53,
  68655. 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f, 0x30,
  68656. 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01,
  68657. 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73,
  68658. 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34,
  68659. 0x30, 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x34, 0x5a, 0x17,
  68660. 0x0d, 0x32, 0x37, 0x30, 0x34, 0x32, 0x32, 0x31, 0x35, 0x31, 0x32, 0x30,
  68661. 0x34, 0x5a, 0x30, 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
  68662. 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03,
  68663. 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67,
  68664. 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07,
  68665. 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30,
  68666. 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66,
  68667. 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  68668. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  68669. 0x67, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16,
  68670. 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, 0x43, 0x53, 0x50,
  68671. 0x20, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, 0x1f,
  68672. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09,
  68673. 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66,
  68674. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x82, 0x01, 0x22, 0x30,
  68675. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  68676. 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02,
  68677. 0x82, 0x01, 0x01, 0x00, 0xb8, 0xba, 0x23, 0xb4, 0xf6, 0xc3, 0x7b, 0x14,
  68678. 0xc3, 0xa4, 0xf5, 0x1d, 0x61, 0xa1, 0xf5, 0x1e, 0x63, 0xb9, 0x85, 0x23,
  68679. 0x34, 0x50, 0x6d, 0xf8, 0x7c, 0xa2, 0x8a, 0x04, 0x8b, 0xd5, 0x75, 0x5c,
  68680. 0x2d, 0xf7, 0x63, 0x88, 0xd1, 0x07, 0x7a, 0xea, 0x0b, 0x45, 0x35, 0x2b,
  68681. 0xeb, 0x1f, 0xb1, 0x22, 0xb4, 0x94, 0x41, 0x38, 0xe2, 0x9d, 0x74, 0xd6,
  68682. 0x8b, 0x30, 0x22, 0x10, 0x51, 0xc5, 0xdb, 0xca, 0x3f, 0x46, 0x2b, 0xfe,
  68683. 0xe5, 0x5a, 0x3f, 0x41, 0x74, 0x67, 0x75, 0x95, 0xa9, 0x94, 0xd5, 0xc3,
  68684. 0xee, 0x42, 0xf8, 0x8d, 0xeb, 0x92, 0x95, 0xe1, 0xd9, 0x65, 0xb7, 0x43,
  68685. 0xc4, 0x18, 0xde, 0x16, 0x80, 0x90, 0xce, 0x24, 0x35, 0x21, 0xc4, 0x55,
  68686. 0xac, 0x5a, 0x51, 0xe0, 0x2e, 0x2d, 0xb3, 0x0a, 0x5a, 0x4f, 0x4a, 0x73,
  68687. 0x31, 0x50, 0xee, 0x4a, 0x16, 0xbd, 0x39, 0x8b, 0xad, 0x05, 0x48, 0x87,
  68688. 0xb1, 0x99, 0xe2, 0x10, 0xa7, 0x06, 0x72, 0x67, 0xca, 0x5c, 0xd1, 0x97,
  68689. 0xbd, 0xc8, 0xf1, 0x76, 0xf8, 0xe0, 0x4a, 0xec, 0xbc, 0x93, 0xf4, 0x66,
  68690. 0x4c, 0x28, 0x71, 0xd1, 0xd8, 0x66, 0x03, 0xb4, 0x90, 0x30, 0xbb, 0x17,
  68691. 0xb0, 0xfe, 0x97, 0xf5, 0x1e, 0xe8, 0xc7, 0x5d, 0x9b, 0x8b, 0x11, 0x19,
  68692. 0x12, 0x3c, 0xab, 0x82, 0x71, 0x78, 0xff, 0xae, 0x3f, 0x32, 0xb2, 0x08,
  68693. 0x71, 0xb2, 0x1b, 0x8c, 0x27, 0xac, 0x11, 0xb8, 0xd8, 0x43, 0x49, 0xcf,
  68694. 0xb0, 0x70, 0xb1, 0xf0, 0x8c, 0xae, 0xda, 0x24, 0x87, 0x17, 0x3b, 0xd8,
  68695. 0x04, 0x65, 0x6c, 0x00, 0x76, 0x50, 0xef, 0x15, 0x08, 0xd7, 0xb4, 0x73,
  68696. 0x68, 0x26, 0x14, 0x87, 0x95, 0xc3, 0x5f, 0x6e, 0x61, 0xb8, 0x87, 0x84,
  68697. 0xfa, 0x80, 0x1a, 0x0a, 0x8b, 0x98, 0xf3, 0xe3, 0xff, 0x4e, 0x44, 0x1c,
  68698. 0x65, 0x74, 0x7c, 0x71, 0x54, 0x65, 0xe5, 0x39, 0x02, 0x03, 0x01, 0x00,
  68699. 0x01, 0xa3, 0x82, 0x01, 0x0a, 0x30, 0x82, 0x01, 0x06, 0x30, 0x09, 0x06,
  68700. 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03,
  68701. 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x32, 0x67, 0xe1, 0xb1, 0x79,
  68702. 0xd2, 0x81, 0xfc, 0x9f, 0x23, 0x0c, 0x70, 0x40, 0x50, 0xb5, 0x46, 0x56,
  68703. 0xb8, 0x30, 0x36, 0x30, 0x81, 0xc4, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04,
  68704. 0x81, 0xbc, 0x30, 0x81, 0xb9, 0x80, 0x14, 0x73, 0xb0, 0x1c, 0xa4, 0x2f,
  68705. 0x82, 0xcb, 0xcf, 0x47, 0xa5, 0x38, 0xd7, 0xb0, 0x04, 0x82, 0x3a, 0x7e,
  68706. 0x72, 0x15, 0x21, 0xa1, 0x81, 0x9d, 0xa4, 0x81, 0x9a, 0x30, 0x81, 0x97,
  68707. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  68708. 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a,
  68709. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10,
  68710. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61,
  68711. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04,
  68712. 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14,
  68713. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67,
  68714. 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16,
  68715. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, 0x53,
  68716. 0x53, 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f,
  68717. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09,
  68718. 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66,
  68719. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x01, 0x63, 0x30, 0x13,
  68720. 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x0c, 0x30, 0x0a, 0x06, 0x08, 0x2b,
  68721. 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x09, 0x30, 0x0d, 0x06, 0x09, 0x2a,
  68722. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82,
  68723. 0x01, 0x01, 0x00, 0x37, 0xb9, 0x66, 0xd3, 0xa1, 0x08, 0xfc, 0x37, 0x58,
  68724. 0x4e, 0xe0, 0x8c, 0xd3, 0x7f, 0xa6, 0x0f, 0x59, 0xd3, 0x14, 0xf7, 0x4b,
  68725. 0x36, 0xf7, 0x2e, 0x98, 0xeb, 0x7c, 0x03, 0x3f, 0x3a, 0xd6, 0x9c, 0xcd,
  68726. 0xb4, 0x9e, 0x8d, 0x5f, 0x92, 0xa6, 0x6f, 0x63, 0x87, 0x34, 0xe8, 0x83,
  68727. 0xfd, 0x6d, 0x34, 0x64, 0xb5, 0xf0, 0x9c, 0x71, 0x02, 0xb8, 0xf6, 0x2f,
  68728. 0x10, 0xa0, 0x92, 0x8f, 0x3f, 0x86, 0x3e, 0xe2, 0x01, 0x5a, 0x56, 0x39,
  68729. 0x0a, 0x8d, 0xb1, 0xbe, 0x03, 0xf7, 0xf8, 0xa7, 0x88, 0x46, 0xef, 0x81,
  68730. 0xa0, 0xad, 0x86, 0xc9, 0xe6, 0x23, 0x89, 0x1d, 0xa6, 0x24, 0x45, 0xf2,
  68731. 0x6a, 0x83, 0x2d, 0x8e, 0x92, 0x17, 0x1e, 0x44, 0x19, 0xfa, 0x0f, 0x47,
  68732. 0x6b, 0x8f, 0x4a, 0xa2, 0xda, 0xab, 0xd5, 0x2b, 0xcd, 0xcb, 0x14, 0xf0,
  68733. 0xb5, 0xcf, 0x7c, 0x76, 0x42, 0x32, 0x90, 0x21, 0xdc, 0xdd, 0x52, 0xfc,
  68734. 0x53, 0x7e, 0xff, 0x7f, 0xd9, 0x58, 0x6b, 0x1f, 0x73, 0xee, 0x83, 0xf4,
  68735. 0x67, 0xfa, 0x4a, 0x4f, 0x24, 0xe4, 0x2b, 0x10, 0x74, 0x89, 0x52, 0x9a,
  68736. 0xf7, 0xa4, 0xe0, 0xaf, 0xf5, 0x63, 0xd7, 0xfa, 0x0b, 0x2c, 0xc9, 0x39,
  68737. 0x5d, 0xbd, 0x44, 0x93, 0x69, 0xa4, 0x1d, 0x01, 0xe2, 0x66, 0xe7, 0xc1,
  68738. 0x11, 0x44, 0x7d, 0x0a, 0x7e, 0x5d, 0x1d, 0x26, 0xc5, 0x4a, 0x26, 0x2e,
  68739. 0xa3, 0x58, 0xc4, 0xf7, 0x10, 0xcb, 0xba, 0xe6, 0x27, 0xfc, 0xdb, 0x54,
  68740. 0xe2, 0x60, 0x08, 0xc2, 0x0e, 0x4b, 0xd4, 0xaa, 0x22, 0x23, 0x93, 0x9f,
  68741. 0xe1, 0xcb, 0x85, 0xa4, 0x41, 0x6f, 0x26, 0xa7, 0x77, 0x8a, 0xef, 0x66,
  68742. 0xd0, 0xf8, 0x33, 0xf6, 0xfd, 0x6d, 0x37, 0x7a, 0x89, 0xcc, 0x88, 0x3b,
  68743. 0x82, 0xd0, 0xa9, 0xdf, 0xf1, 0x3d, 0xdc, 0xb0, 0x06, 0x1c, 0xe4, 0x4b,
  68744. 0x57, 0xb4, 0x0c, 0x65, 0xb9, 0xb4, 0x6c
  68745. };
  68746. OCSP_REQ_CTX *ctx = NULL;
  68747. OCSP_REQUEST *req = NULL;
  68748. OCSP_CERTID *cid = NULL;
  68749. OCSP_RESPONSE *rsp = NULL;
  68750. BIO* bio1 = NULL;
  68751. BIO* bio2 = NULL;
  68752. X509* cert = NULL;
  68753. X509 *issuer = NULL;
  68754. X509_LOOKUP *lookup = NULL;
  68755. X509_STORE *store = NULL;
  68756. STACK_OF(X509_OBJECT) *str_objs = NULL;
  68757. X509_OBJECT *x509_obj = NULL;
  68758. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  68759. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  68760. ExpectIntEQ(BIO_make_bio_pair(bio1, bio2), WOLFSSL_SUCCESS);
  68761. /* Load the leaf cert */
  68762. ExpectNotNull(cert = wolfSSL_X509_load_certificate_file(
  68763. "certs/ocsp/server1-cert.pem", WOLFSSL_FILETYPE_PEM));
  68764. ExpectNotNull(store = X509_STORE_new());
  68765. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  68766. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ocsp/server1-cert.pem",
  68767. X509_FILETYPE_PEM), 1);
  68768. ExpectNotNull(str_objs = X509_STORE_get0_objects(store));
  68769. ExpectNotNull(x509_obj = X509_OBJECT_retrieve_by_subject(str_objs,
  68770. X509_LU_X509, X509_get_issuer_name(cert)));
  68771. ExpectNotNull(issuer = X509_OBJECT_get0_X509(x509_obj));
  68772. ExpectNotNull(req = OCSP_REQUEST_new());
  68773. ExpectNotNull(cid = OCSP_cert_to_id(EVP_sha1(), cert, issuer));
  68774. ExpectNotNull(OCSP_request_add0_id(req, cid));
  68775. ExpectIntEQ(OCSP_request_add1_nonce(req, NULL, -1), 1);
  68776. ExpectNotNull(ctx = OCSP_sendreq_new(bio1, "/", NULL, -1));
  68777. ExpectIntEQ(OCSP_REQ_CTX_add1_header(ctx, "Host", "127.0.0.1"), 1);
  68778. ExpectIntEQ(OCSP_REQ_CTX_set1_req(ctx, req), 1);
  68779. ExpectIntEQ(OCSP_sendreq_nbio(&rsp, ctx), -1);
  68780. ExpectIntEQ(BIO_write(bio2, ocspRespBin, sizeof(ocspRespBin)),
  68781. sizeof(ocspRespBin));
  68782. ExpectIntEQ(wc_SetTimeCb(test_wolfSSL_OCSP_REQ_CTX_time_cb), 0);
  68783. ExpectIntEQ(OCSP_sendreq_nbio(&rsp, ctx), 1);
  68784. ExpectIntEQ(wc_SetTimeCb(NULL), 0);
  68785. ExpectNotNull(rsp);
  68786. OCSP_REQ_CTX_free(ctx);
  68787. OCSP_REQUEST_free(req);
  68788. OCSP_RESPONSE_free(rsp);
  68789. BIO_free(bio1);
  68790. BIO_free(bio2);
  68791. X509_free(cert);
  68792. X509_STORE_free(store);
  68793. #endif
  68794. return EXPECT_RESULT();
  68795. }
  68796. static int test_wolfSSL_EVP_PKEY_derive(void)
  68797. {
  68798. EXPECT_DECLS;
  68799. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || defined(WOLFSSL_OPENSSH)
  68800. #if (!defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)) || defined(HAVE_ECC)
  68801. EVP_PKEY_CTX *ctx = NULL;
  68802. unsigned char *skey = NULL;
  68803. size_t skeylen;
  68804. EVP_PKEY *pkey = NULL;
  68805. EVP_PKEY *peerkey = NULL;
  68806. const unsigned char* key;
  68807. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)
  68808. /* DH */
  68809. key = dh_key_der_2048;
  68810. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &key,
  68811. sizeof_dh_key_der_2048)));
  68812. ExpectIntEQ(DH_generate_key(EVP_PKEY_get0_DH(pkey)), 1);
  68813. key = dh_key_der_2048;
  68814. ExpectNotNull((peerkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &key,
  68815. sizeof_dh_key_der_2048)));
  68816. ExpectIntEQ(DH_generate_key(EVP_PKEY_get0_DH(peerkey)), 1);
  68817. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  68818. ExpectIntEQ(EVP_PKEY_derive_init(ctx), 1);
  68819. ExpectIntEQ(EVP_PKEY_derive_set_peer(ctx, peerkey), 1);
  68820. ExpectIntEQ(EVP_PKEY_derive(ctx, NULL, &skeylen), 1);
  68821. ExpectNotNull(skey = (unsigned char*)XMALLOC(skeylen, NULL,
  68822. DYNAMIC_TYPE_OPENSSL));
  68823. ExpectIntEQ(EVP_PKEY_derive(ctx, skey, &skeylen), 1);
  68824. EVP_PKEY_CTX_free(ctx);
  68825. ctx = NULL;
  68826. EVP_PKEY_free(peerkey);
  68827. peerkey = NULL;
  68828. EVP_PKEY_free(pkey);
  68829. pkey = NULL;
  68830. XFREE(skey, NULL, DYNAMIC_TYPE_OPENSSL);
  68831. skey = NULL;
  68832. #endif
  68833. #ifdef HAVE_ECC
  68834. /* ECDH */
  68835. key = ecc_clikey_der_256;
  68836. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &key,
  68837. sizeof_ecc_clikey_der_256)));
  68838. key = ecc_clikeypub_der_256;
  68839. ExpectNotNull((peerkey = d2i_PUBKEY(NULL, &key,
  68840. sizeof_ecc_clikeypub_der_256)));
  68841. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  68842. ExpectIntEQ(EVP_PKEY_derive_init(ctx), 1);
  68843. ExpectIntEQ(EVP_PKEY_derive_set_peer(ctx, peerkey), 1);
  68844. ExpectIntEQ(EVP_PKEY_derive(ctx, NULL, &skeylen), 1);
  68845. ExpectNotNull(skey = (unsigned char*)XMALLOC(skeylen, NULL,
  68846. DYNAMIC_TYPE_OPENSSL));
  68847. ExpectIntEQ(EVP_PKEY_derive(ctx, skey, &skeylen), 1);
  68848. EVP_PKEY_CTX_free(ctx);
  68849. EVP_PKEY_free(peerkey);
  68850. EVP_PKEY_free(pkey);
  68851. XFREE(skey, NULL, DYNAMIC_TYPE_OPENSSL);
  68852. #endif /* HAVE_ECC */
  68853. #endif /* (!NO_DH && WOLFSSL_DH_EXTRA) || HAVE_ECC */
  68854. #endif /* OPENSSL_ALL || WOLFSSL_QT || WOLFSSL_OPENSSH */
  68855. return EXPECT_RESULT();
  68856. }
  68857. static int test_wolfSSL_EVP_PBE_scrypt(void)
  68858. {
  68859. EXPECT_DECLS;
  68860. #if defined(OPENSSL_EXTRA) && defined(HAVE_SCRYPT) && defined(HAVE_PBKDF2) && \
  68861. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 5))
  68862. #if !defined(NO_PWDBASED) && !defined(NO_SHA256)
  68863. int ret;
  68864. const char pwd[] = {'p','a','s','s','w','o','r','d'};
  68865. int pwdlen = sizeof(pwd);
  68866. const byte salt[] = {'N','a','C','l'};
  68867. int saltlen = sizeof(salt);
  68868. byte key[80];
  68869. word64 numOvr32 = (word64)INT32_MAX + 1;
  68870. /* expected derived key for N:16, r:1, p:1 */
  68871. const byte expectedKey[] = {
  68872. 0xAE, 0xC6, 0xB7, 0x48, 0x3E, 0xD2, 0x6E, 0x08, 0x80, 0x2B,
  68873. 0x41, 0xF4, 0x03, 0x20, 0x86, 0xA0, 0xE8, 0x86, 0xBE, 0x7A,
  68874. 0xC4, 0x8F, 0xCF, 0xD9, 0x2F, 0xF0, 0xCE, 0xF8, 0x10, 0x97,
  68875. 0x52, 0xF4, 0xAC, 0x74, 0xB0, 0x77, 0x26, 0x32, 0x56, 0xA6,
  68876. 0x5A, 0x99, 0x70, 0x1B, 0x7A, 0x30, 0x4D, 0x46, 0x61, 0x1C,
  68877. 0x8A, 0xA3, 0x91, 0xE7, 0x99, 0xCE, 0x10, 0xA2, 0x77, 0x53,
  68878. 0xE7, 0xE9, 0xC0, 0x9A};
  68879. /* N r p mx key keylen */
  68880. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 0, 1, 1, 0, key, 64);
  68881. ExpectIntEQ(ret, 0); /* N must be greater than 1 */
  68882. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 3, 1, 1, 0, key, 64);
  68883. ExpectIntEQ(ret, 0); /* N must be power of 2 */
  68884. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 0, 1, 0, key, 64);
  68885. ExpectIntEQ(ret, 0); /* r must be greater than 0 */
  68886. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 0, 0, key, 64);
  68887. ExpectIntEQ(ret, 0); /* p must be greater than 0 */
  68888. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, key, 0);
  68889. ExpectIntEQ(ret, 0); /* keylen must be greater than 0 */
  68890. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 9, 1, 0, key, 64);
  68891. ExpectIntEQ(ret, 0); /* r must be smaller than 9 */
  68892. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, NULL, 64);
  68893. ExpectIntEQ(ret, 1); /* should succeed if key is NULL */
  68894. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, key, 64);
  68895. ExpectIntEQ(ret, 1); /* should succeed */
  68896. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, numOvr32, 1, 0,
  68897. key, 64);
  68898. ExpectIntEQ(ret, 0); /* should fail since r is greater than INT32_MAC */
  68899. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, numOvr32, 0,
  68900. key, 64);
  68901. ExpectIntEQ(ret, 0); /* should fail since p is greater than INT32_MAC */
  68902. ret = EVP_PBE_scrypt(pwd, pwdlen, NULL, 0, 2, 1, 1, 0, key, 64);
  68903. ExpectIntEQ(ret, 1); /* should succeed even if salt is NULL */
  68904. ret = EVP_PBE_scrypt(pwd, pwdlen, NULL, 4, 2, 1, 1, 0, key, 64);
  68905. ExpectIntEQ(ret, 0); /* if salt is NULL, saltlen must be 0, otherwise fail*/
  68906. ret = EVP_PBE_scrypt(NULL, 0, salt, saltlen, 2, 1, 1, 0, key, 64);
  68907. ExpectIntEQ(ret, 1); /* should succeed if pwd is NULL and pwdlen is 0*/
  68908. ret = EVP_PBE_scrypt(NULL, 4, salt, saltlen, 2, 1, 1, 0, key, 64);
  68909. ExpectIntEQ(ret, 0); /* if pwd is NULL, pwdlen must be 0 */
  68910. ret = EVP_PBE_scrypt(NULL, 0, NULL, 0, 2, 1, 1, 0, key, 64);
  68911. ExpectIntEQ(ret, 1); /* should succeed even both pwd and salt are NULL */
  68912. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 16, 1, 1, 0, key, 64);
  68913. ExpectIntEQ(ret, 1);
  68914. ret = XMEMCMP(expectedKey, key, sizeof(expectedKey));
  68915. ExpectIntEQ(ret, 0); /* derived key must be the same as expected-key */
  68916. #endif /* !NO_PWDBASED && !NO_SHA256 */
  68917. #endif /* OPENSSL_EXTRA && HAVE_SCRYPT && HAVE_PBKDF2 */
  68918. return EXPECT_RESULT();
  68919. }
  68920. static int test_no_op_functions(void)
  68921. {
  68922. EXPECT_DECLS;
  68923. #if defined(OPENSSL_EXTRA)
  68924. /* this makes sure wolfSSL can compile and run these no-op functions */
  68925. SSL_load_error_strings();
  68926. ENGINE_load_builtin_engines();
  68927. OpenSSL_add_all_ciphers();
  68928. ExpectIntEQ(CRYPTO_malloc_init(), 0);
  68929. #endif
  68930. return EXPECT_RESULT();
  68931. }
  68932. static int test_wolfSSL_CRYPTO_memcmp(void)
  68933. {
  68934. EXPECT_DECLS;
  68935. #ifdef OPENSSL_EXTRA
  68936. char a[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  68937. "implementation of TLS/SSL for embedded devices to the cloud.";
  68938. char b[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  68939. "implementation of TLS/SSL for embedded devices to the cloud.";
  68940. char c[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  68941. "implementation of TLS/SSL for embedded devices to the cloud!";
  68942. ExpectIntEQ(CRYPTO_memcmp(a, b, sizeof(a)), 0);
  68943. ExpectIntNE(CRYPTO_memcmp(a, c, sizeof(a)), 0);
  68944. #endif
  68945. return EXPECT_RESULT();
  68946. }
  68947. /*----------------------------------------------------------------------------*
  68948. | wolfCrypt ASN
  68949. *----------------------------------------------------------------------------*/
  68950. static int test_wc_CreateEncryptedPKCS8Key(void)
  68951. {
  68952. EXPECT_DECLS;
  68953. #if defined(HAVE_PKCS8) && !defined(NO_PWDBASED) && defined(WOLFSSL_AES_256) \
  68954. && !defined(NO_AES_CBC) && !defined(NO_RSA) && !defined(NO_SHA) && \
  68955. !defined(NO_ASN_CRYPT)
  68956. WC_RNG rng;
  68957. byte* encKey = NULL;
  68958. word32 encKeySz = 0;
  68959. word32 decKeySz = 0;
  68960. const char password[] = "Lorem ipsum dolor sit amet";
  68961. word32 passwordSz = (word32)XSTRLEN(password);
  68962. word32 tradIdx = 0;
  68963. XMEMSET(&rng, 0, sizeof(WC_RNG));
  68964. ExpectIntEQ(wc_InitRng(&rng), 0);
  68965. PRIVATE_KEY_UNLOCK();
  68966. /* Call with NULL for out buffer to get necessary length. */
  68967. ExpectIntEQ(wc_CreateEncryptedPKCS8Key((byte*)server_key_der_2048,
  68968. sizeof_server_key_der_2048, NULL, &encKeySz, password, (int)passwordSz,
  68969. PKCS5, PBES2, AES256CBCb, NULL, 0, WC_PKCS12_ITT_DEFAULT, &rng, NULL),
  68970. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  68971. ExpectNotNull(encKey = (byte*)XMALLOC(encKeySz, HEAP_HINT,
  68972. DYNAMIC_TYPE_TMP_BUFFER));
  68973. /* Call with the allocated out buffer. */
  68974. ExpectIntGT(wc_CreateEncryptedPKCS8Key((byte*)server_key_der_2048,
  68975. sizeof_server_key_der_2048, encKey, &encKeySz, password, (int)passwordSz,
  68976. PKCS5, PBES2, AES256CBCb, NULL, 0, WC_PKCS12_ITT_DEFAULT, &rng, NULL),
  68977. 0);
  68978. /* Decrypt the encrypted PKCS8 key we just made. */
  68979. ExpectIntGT((decKeySz = (word32)wc_DecryptPKCS8Key(encKey, encKeySz, password,
  68980. (int)passwordSz)), 0);
  68981. /* encKey now holds the decrypted key (decrypted in place). */
  68982. ExpectIntGT(wc_GetPkcs8TraditionalOffset(encKey, &tradIdx, decKeySz), 0);
  68983. /* Check that the decrypted key matches the key prior to encryption. */
  68984. ExpectIntEQ(XMEMCMP(encKey + tradIdx, server_key_der_2048,
  68985. sizeof_server_key_der_2048), 0);
  68986. PRIVATE_KEY_LOCK();
  68987. XFREE(encKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68988. wc_FreeRng(&rng);
  68989. #endif
  68990. return EXPECT_RESULT();
  68991. }
  68992. static int test_wc_GetPkcs8TraditionalOffset(void)
  68993. {
  68994. EXPECT_DECLS;
  68995. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(HAVE_PKCS8)
  68996. int length;
  68997. int derSz = 0;
  68998. word32 inOutIdx;
  68999. const char* path = "./certs/server-keyPkcs8.der";
  69000. const char* pathAttributes = "./certs/ca-key-pkcs8-attribute.der";
  69001. XFILE file = XBADFILE;
  69002. byte der[2048];
  69003. ExpectTrue((file = XFOPEN(path, "rb")) != XBADFILE);
  69004. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), file), 0);
  69005. if (file != XBADFILE)
  69006. XFCLOSE(file);
  69007. file = XBADFILE; /* reset file to avoid warning of use after close */
  69008. /* valid case */
  69009. inOutIdx = 0;
  69010. ExpectIntGT(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  69011. 0);
  69012. /* inOutIdx > sz */
  69013. inOutIdx = 4000;
  69014. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  69015. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  69016. /* null input */
  69017. inOutIdx = 0;
  69018. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(NULL, &inOutIdx, 0),
  69019. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  69020. /* invalid input, fill buffer with 1's */
  69021. XMEMSET(der, 1, sizeof(der));
  69022. inOutIdx = 0;
  69023. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  69024. WC_NO_ERR_TRACE(ASN_PARSE_E));
  69025. /* test parsing with attributes */
  69026. ExpectTrue((file = XFOPEN(pathAttributes, "rb")) != XBADFILE);
  69027. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), file), 0);
  69028. if (file != XBADFILE)
  69029. XFCLOSE(file);
  69030. inOutIdx = 0;
  69031. ExpectIntGT(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx,
  69032. (word32)derSz), 0);
  69033. #endif /* NO_ASN */
  69034. return EXPECT_RESULT();
  69035. }
  69036. static int test_wc_SetSubjectRaw(void)
  69037. {
  69038. EXPECT_DECLS;
  69039. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  69040. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  69041. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  69042. WOLFSSL_X509* x509 = NULL;
  69043. int peerCertSz;
  69044. const byte* peerCertBuf = NULL;
  69045. Cert forgedCert;
  69046. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  69047. WOLFSSL_FILETYPE_ASN1));
  69048. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  69049. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  69050. ExpectIntEQ(0, wc_SetSubjectRaw(&forgedCert, peerCertBuf, peerCertSz));
  69051. wolfSSL_FreeX509(x509);
  69052. #endif
  69053. return EXPECT_RESULT();
  69054. }
  69055. static int test_wc_GetSubjectRaw(void)
  69056. {
  69057. EXPECT_DECLS;
  69058. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  69059. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT)
  69060. Cert cert;
  69061. byte *subjectRaw;
  69062. ExpectIntEQ(0, wc_InitCert(&cert));
  69063. ExpectIntEQ(0, wc_GetSubjectRaw(&subjectRaw, &cert));
  69064. #endif
  69065. return EXPECT_RESULT();
  69066. }
  69067. static int test_wc_SetIssuerRaw(void)
  69068. {
  69069. EXPECT_DECLS;
  69070. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  69071. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  69072. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  69073. WOLFSSL_X509* x509 = NULL;
  69074. int peerCertSz;
  69075. const byte* peerCertBuf = NULL;
  69076. Cert forgedCert;
  69077. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  69078. WOLFSSL_FILETYPE_ASN1));
  69079. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  69080. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  69081. ExpectIntEQ(0, wc_SetIssuerRaw(&forgedCert, peerCertBuf, peerCertSz));
  69082. wolfSSL_FreeX509(x509);
  69083. #endif
  69084. return EXPECT_RESULT();
  69085. }
  69086. static int test_wc_SetIssueBuffer(void)
  69087. {
  69088. EXPECT_DECLS;
  69089. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  69090. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  69091. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  69092. WOLFSSL_X509* x509 = NULL;
  69093. int peerCertSz;
  69094. const byte* peerCertBuf = NULL;
  69095. Cert forgedCert;
  69096. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  69097. WOLFSSL_FILETYPE_ASN1));
  69098. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  69099. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  69100. ExpectIntEQ(0, wc_SetIssuerBuffer(&forgedCert, peerCertBuf, peerCertSz));
  69101. wolfSSL_FreeX509(x509);
  69102. #endif
  69103. return EXPECT_RESULT();
  69104. }
  69105. /*
  69106. * Testing wc_SetSubjectKeyId
  69107. */
  69108. static int test_wc_SetSubjectKeyId(void)
  69109. {
  69110. EXPECT_DECLS;
  69111. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  69112. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && defined(HAVE_ECC)
  69113. Cert cert;
  69114. const char* file = "certs/ecc-client-keyPub.pem";
  69115. ExpectIntEQ(0, wc_InitCert(&cert));
  69116. ExpectIntEQ(0, wc_SetSubjectKeyId(&cert, file));
  69117. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SetSubjectKeyId(NULL, file));
  69118. ExpectIntGT(0, wc_SetSubjectKeyId(&cert, "badfile.name"));
  69119. #endif
  69120. return EXPECT_RESULT();
  69121. } /* END test_wc_SetSubjectKeyId */
  69122. /*
  69123. * Testing wc_SetSubject
  69124. */
  69125. static int test_wc_SetSubject(void)
  69126. {
  69127. EXPECT_DECLS;
  69128. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  69129. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && defined(HAVE_ECC)
  69130. Cert cert;
  69131. const char* file = "./certs/ca-ecc-cert.pem";
  69132. ExpectIntEQ(0, wc_InitCert(&cert));
  69133. ExpectIntEQ(0, wc_SetSubject(&cert, file));
  69134. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SetSubject(NULL, file));
  69135. ExpectIntGT(0, wc_SetSubject(&cert, "badfile.name"));
  69136. #endif
  69137. return EXPECT_RESULT();
  69138. } /* END test_wc_SetSubject */
  69139. static int test_CheckCertSignature(void)
  69140. {
  69141. EXPECT_DECLS;
  69142. #if !defined(NO_CERTS) && defined(WOLFSSL_SMALL_CERT_VERIFY)
  69143. WOLFSSL_CERT_MANAGER* cm = NULL;
  69144. #if !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || defined(HAVE_ECC))
  69145. XFILE fp = XBADFILE;
  69146. byte cert[4096];
  69147. int certSz;
  69148. #endif
  69149. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_CheckCertSignature(NULL, 0, NULL, NULL));
  69150. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  69151. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_CheckCertSignature(NULL, 0, NULL, cm));
  69152. #ifndef NO_RSA
  69153. #ifdef USE_CERT_BUFFERS_1024
  69154. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(server_cert_der_1024,
  69155. sizeof_server_cert_der_1024, NULL, cm));
  69156. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  69157. ca_cert_der_1024, sizeof_ca_cert_der_1024,
  69158. WOLFSSL_FILETYPE_ASN1));
  69159. ExpectIntEQ(0, wc_CheckCertSignature(server_cert_der_1024,
  69160. sizeof_server_cert_der_1024, NULL, cm));
  69161. #elif defined(USE_CERT_BUFFERS_2048)
  69162. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(server_cert_der_2048,
  69163. sizeof_server_cert_der_2048, NULL, cm));
  69164. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  69165. ca_cert_der_2048, sizeof_ca_cert_der_2048,
  69166. WOLFSSL_FILETYPE_ASN1));
  69167. ExpectIntEQ(0, wc_CheckCertSignature(server_cert_der_2048,
  69168. sizeof_server_cert_der_2048, NULL, cm));
  69169. #endif
  69170. #endif
  69171. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  69172. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(serv_ecc_der_256,
  69173. sizeof_serv_ecc_der_256, NULL, cm));
  69174. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  69175. ca_ecc_cert_der_256, sizeof_ca_ecc_cert_der_256,
  69176. WOLFSSL_FILETYPE_ASN1));
  69177. ExpectIntEQ(0, wc_CheckCertSignature(serv_ecc_der_256, sizeof_serv_ecc_der_256,
  69178. NULL, cm));
  69179. #endif
  69180. #if !defined(NO_FILESYSTEM)
  69181. wolfSSL_CertManagerFree(cm);
  69182. cm = NULL;
  69183. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  69184. #ifndef NO_RSA
  69185. ExpectTrue((fp = XFOPEN("./certs/server-cert.der", "rb")) != XBADFILE);
  69186. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), fp)), 0);
  69187. if (fp != XBADFILE) {
  69188. XFCLOSE(fp);
  69189. fp = XBADFILE;
  69190. }
  69191. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(cert, certSz, NULL, cm));
  69192. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  69193. "./certs/ca-cert.pem", NULL));
  69194. ExpectIntEQ(0, wc_CheckCertSignature(cert, certSz, NULL, cm));
  69195. #endif
  69196. #ifdef HAVE_ECC
  69197. ExpectTrue((fp = XFOPEN("./certs/server-ecc.der", "rb")) != XBADFILE);
  69198. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), fp)), 0);
  69199. if (fp != XBADFILE) {
  69200. XFCLOSE(fp);
  69201. fp = XBADFILE;
  69202. }
  69203. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(cert, certSz, NULL, cm));
  69204. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  69205. "./certs/ca-ecc-cert.pem", NULL));
  69206. ExpectIntEQ(0, wc_CheckCertSignature(cert, certSz, NULL, cm));
  69207. #endif
  69208. #endif
  69209. #if !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || defined(HAVE_ECC))
  69210. (void)fp;
  69211. (void)cert;
  69212. (void)certSz;
  69213. #endif
  69214. wolfSSL_CertManagerFree(cm);
  69215. #endif
  69216. return EXPECT_RESULT();
  69217. }
  69218. static int test_wc_ParseCert(void)
  69219. {
  69220. EXPECT_DECLS;
  69221. #if !defined(NO_CERTS) && !defined(NO_RSA)
  69222. DecodedCert decodedCert;
  69223. const byte* rawCert = client_cert_der_2048;
  69224. const int rawCertSize = sizeof_client_cert_der_2048;
  69225. wc_InitDecodedCert(&decodedCert, rawCert, rawCertSize, NULL);
  69226. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  69227. #ifndef IGNORE_NAME_CONSTRAINTS
  69228. /* check that the subjects emailAddress was not put in the alt name list */
  69229. ExpectNotNull(decodedCert.subjectEmail);
  69230. ExpectNull(decodedCert.altEmailNames);
  69231. #endif
  69232. wc_FreeDecodedCert(&decodedCert);
  69233. #endif
  69234. return EXPECT_RESULT();
  69235. }
  69236. /* Test wc_ParseCert decoding of various encodings and scenarios ensuring that
  69237. * the API safely errors out on badly-formed ASN input.
  69238. * NOTE: Test not compatible with released FIPS implementations!
  69239. */
  69240. static int test_wc_ParseCert_Error(void)
  69241. {
  69242. EXPECT_DECLS;
  69243. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(HAVE_SELFTEST) && \
  69244. (!defined(HAVE_FIPS) || \
  69245. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  69246. DecodedCert decodedCert;
  69247. int i;
  69248. /* Certificate data */
  69249. const byte c0[] = { 0x30, 0x04, 0x30, 0x02, 0x02, 0x80, 0x00, 0x00};
  69250. const byte c1[] = { 0x30, 0x04, 0x30, 0x04, 0x02, 0x80, 0x00, 0x00};
  69251. const byte c2[] = { 0x30, 0x06, 0x30, 0x04, 0x02, 0x80, 0x00, 0x00};
  69252. const byte c3[] = { 0x30, 0x07, 0x30, 0x05, 0x02, 0x80, 0x10, 0x00, 0x00};
  69253. const byte c4[] = { 0x02, 0x80, 0x10, 0x00, 0x00};
  69254. /* Test data */
  69255. const struct testStruct {
  69256. const byte* c;
  69257. word32 cSz;
  69258. const int expRet;
  69259. } t[] = {
  69260. {c0, sizeof(c0), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid bit-string length */
  69261. {c1, sizeof(c1), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid bit-string length */
  69262. {c2, sizeof(c2), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid integer length (zero) */
  69263. {c3, sizeof(c3), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Valid INTEGER, but buffer too short */
  69264. {c4, sizeof(c4), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Valid INTEGER, but not in bit-string */
  69265. };
  69266. const int tSz = (int)(sizeof(t) / sizeof(struct testStruct));
  69267. for (i = 0; i < tSz; i++) {
  69268. WOLFSSL_MSG_EX("i == %d", i);
  69269. wc_InitDecodedCert(&decodedCert, t[i].c, t[i].cSz, NULL);
  69270. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), t[i].expRet);
  69271. wc_FreeDecodedCert(&decodedCert);
  69272. }
  69273. #endif
  69274. return EXPECT_RESULT();
  69275. }
  69276. static int test_MakeCertWithPathLen(void)
  69277. {
  69278. EXPECT_DECLS;
  69279. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME) && \
  69280. defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC)
  69281. const byte expectedPathLen = 7;
  69282. Cert cert;
  69283. DecodedCert decodedCert;
  69284. byte der[FOURK_BUF];
  69285. int derSize = 0;
  69286. WC_RNG rng;
  69287. ecc_key key;
  69288. int ret;
  69289. XMEMSET(&rng, 0, sizeof(WC_RNG));
  69290. XMEMSET(&key, 0, sizeof(ecc_key));
  69291. XMEMSET(&cert, 0, sizeof(Cert));
  69292. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  69293. ExpectIntEQ(wc_InitRng(&rng), 0);
  69294. ExpectIntEQ(wc_ecc_init(&key), 0);
  69295. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  69296. ExpectIntEQ(wc_InitCert(&cert), 0);
  69297. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  69298. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  69299. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  69300. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  69301. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  69302. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  69303. CTC_NAME_SIZE);
  69304. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  69305. CTC_NAME_SIZE);
  69306. cert.selfSigned = 1;
  69307. cert.isCA = 1;
  69308. cert.pathLen = expectedPathLen;
  69309. cert.pathLenSet = 1;
  69310. cert.sigType = CTC_SHA256wECDSA;
  69311. #ifdef WOLFSSL_CERT_EXT
  69312. cert.keyUsage |= KEYUSE_KEY_CERT_SIGN;
  69313. #endif
  69314. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  69315. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  69316. FOURK_BUF, NULL, &key, &rng), 0);
  69317. wc_InitDecodedCert(&decodedCert, der, (word32)derSize, NULL);
  69318. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  69319. ExpectIntEQ(decodedCert.pathLength, expectedPathLen);
  69320. wc_FreeDecodedCert(&decodedCert);
  69321. ret = wc_ecc_free(&key);
  69322. ExpectIntEQ(ret, 0);
  69323. ret = wc_FreeRng(&rng);
  69324. ExpectIntEQ(ret, 0);
  69325. #endif
  69326. return EXPECT_RESULT();
  69327. }
  69328. static int test_MakeCertWith0Ser(void)
  69329. {
  69330. EXPECT_DECLS;
  69331. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME) && \
  69332. defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC) && \
  69333. defined(WOLFSSL_ASN_TEMPLATE)
  69334. Cert cert;
  69335. DecodedCert decodedCert;
  69336. byte der[FOURK_BUF];
  69337. int derSize = 0;
  69338. WC_RNG rng;
  69339. ecc_key key;
  69340. int ret;
  69341. XMEMSET(&rng, 0, sizeof(WC_RNG));
  69342. XMEMSET(&key, 0, sizeof(ecc_key));
  69343. XMEMSET(&cert, 0, sizeof(Cert));
  69344. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  69345. ExpectIntEQ(wc_InitRng(&rng), 0);
  69346. ExpectIntEQ(wc_ecc_init(&key), 0);
  69347. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  69348. ExpectIntEQ(wc_InitCert(&cert), 0);
  69349. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  69350. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  69351. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  69352. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  69353. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  69354. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  69355. CTC_NAME_SIZE);
  69356. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  69357. CTC_NAME_SIZE);
  69358. cert.selfSigned = 1;
  69359. cert.isCA = 1;
  69360. cert.sigType = CTC_SHA256wECDSA;
  69361. #ifdef WOLFSSL_CERT_EXT
  69362. cert.keyUsage |= KEYUSE_KEY_CERT_SIGN;
  69363. #endif
  69364. /* set serial number to 0 */
  69365. cert.serialSz = 1;
  69366. cert.serial[0] = 0;
  69367. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  69368. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  69369. FOURK_BUF, NULL, &key, &rng), 0);
  69370. wc_InitDecodedCert(&decodedCert, der, (word32)derSize, NULL);
  69371. #if !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_PYTHON)
  69372. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL),
  69373. WC_NO_ERR_TRACE(ASN_PARSE_E));
  69374. #else
  69375. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  69376. #endif
  69377. wc_FreeDecodedCert(&decodedCert);
  69378. ret = wc_ecc_free(&key);
  69379. ExpectIntEQ(ret, 0);
  69380. ret = wc_FreeRng(&rng);
  69381. ExpectIntEQ(ret, 0);
  69382. #endif
  69383. return EXPECT_RESULT();
  69384. }
  69385. static int test_MakeCertWithCaFalse(void)
  69386. {
  69387. EXPECT_DECLS;
  69388. #if defined(WOLFSSL_ALLOW_ENCODING_CA_FALSE) && defined(WOLFSSL_CERT_REQ) && \
  69389. !defined(NO_ASN_TIME) && defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC)
  69390. const byte expectedIsCa = 0;
  69391. Cert cert;
  69392. DecodedCert decodedCert;
  69393. byte der[FOURK_BUF];
  69394. int derSize = 0;
  69395. WC_RNG rng;
  69396. ecc_key key;
  69397. int ret;
  69398. XMEMSET(&rng, 0, sizeof(WC_RNG));
  69399. XMEMSET(&key, 0, sizeof(ecc_key));
  69400. XMEMSET(&cert, 0, sizeof(Cert));
  69401. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  69402. ExpectIntEQ(wc_InitRng(&rng), 0);
  69403. ExpectIntEQ(wc_ecc_init(&key), 0);
  69404. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  69405. ExpectIntEQ(wc_InitCert(&cert), 0);
  69406. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  69407. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  69408. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  69409. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  69410. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  69411. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  69412. CTC_NAME_SIZE);
  69413. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  69414. CTC_NAME_SIZE);
  69415. cert.selfSigned = 1;
  69416. cert.isCA = expectedIsCa;
  69417. cert.isCaSet = 1;
  69418. cert.sigType = CTC_SHA256wECDSA;
  69419. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  69420. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  69421. FOURK_BUF, NULL, &key, &rng), 0);
  69422. wc_InitDecodedCert(&decodedCert, der, derSize, NULL);
  69423. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  69424. ExpectIntEQ(decodedCert.isCA, expectedIsCa);
  69425. wc_FreeDecodedCert(&decodedCert);
  69426. ret = wc_ecc_free(&key);
  69427. ExpectIntEQ(ret, 0);
  69428. ret = wc_FreeRng(&rng);
  69429. ExpectIntEQ(ret, 0);
  69430. #endif
  69431. return EXPECT_RESULT();
  69432. }
  69433. /*----------------------------------------------------------------------------*
  69434. | wolfCrypt ECC
  69435. *----------------------------------------------------------------------------*/
  69436. static int test_wc_ecc_get_curve_size_from_name(void)
  69437. {
  69438. EXPECT_DECLS;
  69439. #ifdef HAVE_ECC
  69440. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  69441. ExpectIntEQ(wc_ecc_get_curve_size_from_name("SECP256R1"), 32);
  69442. #endif
  69443. /* invalid case */
  69444. ExpectIntEQ(wc_ecc_get_curve_size_from_name("BADCURVE"), -1);
  69445. /* NULL input */
  69446. ExpectIntEQ(wc_ecc_get_curve_size_from_name(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  69447. #endif /* HAVE_ECC */
  69448. return EXPECT_RESULT();
  69449. }
  69450. static int test_wc_ecc_get_curve_id_from_name(void)
  69451. {
  69452. EXPECT_DECLS;
  69453. #ifdef HAVE_ECC
  69454. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  69455. ExpectIntEQ(wc_ecc_get_curve_id_from_name("SECP256R1"),
  69456. ECC_SECP256R1);
  69457. #endif
  69458. /* invalid case */
  69459. ExpectIntEQ(wc_ecc_get_curve_id_from_name("BADCURVE"), -1);
  69460. /* NULL input */
  69461. ExpectIntEQ(wc_ecc_get_curve_id_from_name(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  69462. #endif /* HAVE_ECC */
  69463. return EXPECT_RESULT();
  69464. }
  69465. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && \
  69466. !defined(HAVE_SELFTEST) && \
  69467. !(defined(HAVE_FIPS) || defined(HAVE_FIPS_VERSION))
  69468. static int test_wc_ecc_get_curve_id_from_dp_params(void)
  69469. {
  69470. EXPECT_DECLS;
  69471. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  69472. ecc_key* key;
  69473. const ecc_set_type* params = NULL;
  69474. int ret;
  69475. #endif
  69476. WOLFSSL_EC_KEY *ecKey = NULL;
  69477. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  69478. ExpectIntEQ(wc_ecc_get_curve_id_from_name("SECP256R1"), ECC_SECP256R1);
  69479. ExpectNotNull(ecKey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  69480. if (EXPECT_SUCCESS()) {
  69481. ret = EC_KEY_generate_key(ecKey);
  69482. } else
  69483. ret = 0;
  69484. if (ret == 1) {
  69485. /* normal test */
  69486. key = (ecc_key*)ecKey->internal;
  69487. if (key != NULL) {
  69488. params = key->dp;
  69489. }
  69490. ExpectIntEQ(wc_ecc_get_curve_id_from_dp_params(params),
  69491. ECC_SECP256R1);
  69492. }
  69493. #endif
  69494. /* invalid case, NULL input*/
  69495. ExpectIntEQ(wc_ecc_get_curve_id_from_dp_params(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  69496. wolfSSL_EC_KEY_free(ecKey);
  69497. return EXPECT_RESULT();
  69498. }
  69499. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_ECC) */
  69500. static int test_wc_ecc_get_curve_id_from_params(void)
  69501. {
  69502. EXPECT_DECLS;
  69503. #ifdef HAVE_ECC
  69504. const byte prime[] =
  69505. {
  69506. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  69507. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  69508. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  69509. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  69510. };
  69511. const byte primeInvalid[] =
  69512. {
  69513. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  69514. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  69515. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  69516. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x01
  69517. };
  69518. const byte Af[] =
  69519. {
  69520. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  69521. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  69522. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  69523. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC
  69524. };
  69525. const byte Bf[] =
  69526. {
  69527. 0x5A,0xC6,0x35,0xD8,0xAA,0x3A,0x93,0xE7,
  69528. 0xB3,0xEB,0xBD,0x55,0x76,0x98,0x86,0xBC,
  69529. 0x65,0x1D,0x06,0xB0,0xCC,0x53,0xB0,0xF6,
  69530. 0x3B,0xCE,0x3C,0x3E,0x27,0xD2,0x60,0x4B
  69531. };
  69532. const byte order[] =
  69533. {
  69534. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,
  69535. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  69536. 0xBC,0xE6,0xFA,0xAD,0xA7,0x17,0x9E,0x84,
  69537. 0xF3,0xB9,0xCA,0xC2,0xFC,0x63,0x25,0x51
  69538. };
  69539. const byte Gx[] =
  69540. {
  69541. 0x6B,0x17,0xD1,0xF2,0xE1,0x2C,0x42,0x47,
  69542. 0xF8,0xBC,0xE6,0xE5,0x63,0xA4,0x40,0xF2,
  69543. 0x77,0x03,0x7D,0x81,0x2D,0xEB,0x33,0xA0,
  69544. 0xF4,0xA1,0x39,0x45,0xD8,0x98,0xC2,0x96
  69545. };
  69546. const byte Gy[] =
  69547. {
  69548. 0x4F,0xE3,0x42,0xE2,0xFE,0x1A,0x7F,0x9B,
  69549. 0x8E,0xE7,0xEB,0x4A,0x7C,0x0F,0x9E,0x16,
  69550. 0x2B,0xCE,0x33,0x57,0x6B,0x31,0x5E,0xCE,
  69551. 0xCB,0xB6,0x40,0x68,0x37,0xBF,0x51,0xF5
  69552. };
  69553. int cofactor = 1;
  69554. int fieldSize = 256;
  69555. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  69556. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize,
  69557. prime, sizeof(prime), Af, sizeof(Af), Bf, sizeof(Bf),
  69558. order, sizeof(order), Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor),
  69559. ECC_SECP256R1);
  69560. #endif
  69561. /* invalid case, fieldSize = 0 */
  69562. ExpectIntEQ(wc_ecc_get_curve_id_from_params(0, prime, sizeof(prime),
  69563. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  69564. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), ECC_CURVE_INVALID);
  69565. /* invalid case, NULL prime */
  69566. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize, NULL, sizeof(prime),
  69567. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  69568. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  69569. /* invalid case, invalid prime */
  69570. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize,
  69571. primeInvalid, sizeof(primeInvalid),
  69572. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  69573. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), ECC_CURVE_INVALID);
  69574. #endif
  69575. return EXPECT_RESULT();
  69576. }
  69577. static int test_wolfSSL_EVP_PKEY_encrypt(void)
  69578. {
  69579. EXPECT_DECLS;
  69580. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  69581. WOLFSSL_RSA* rsa = NULL;
  69582. WOLFSSL_EVP_PKEY* pkey = NULL;
  69583. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  69584. const char* in = "What is easy to do is easy not to do.";
  69585. size_t inlen = XSTRLEN(in);
  69586. size_t outEncLen = 0;
  69587. byte* outEnc = NULL;
  69588. byte* outDec = NULL;
  69589. size_t outDecLen = 0;
  69590. size_t rsaKeySz = 2048/8; /* Bytes */
  69591. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  69592. byte* inTmp = NULL;
  69593. byte* outEncTmp = NULL;
  69594. byte* outDecTmp = NULL;
  69595. #endif
  69596. ExpectNotNull(outEnc = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  69597. DYNAMIC_TYPE_TMP_BUFFER));
  69598. if (outEnc != NULL) {
  69599. XMEMSET(outEnc, 0, rsaKeySz);
  69600. }
  69601. ExpectNotNull(outDec = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  69602. DYNAMIC_TYPE_TMP_BUFFER));
  69603. if (outDec != NULL) {
  69604. XMEMSET(outDec, 0, rsaKeySz);
  69605. }
  69606. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  69607. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  69608. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  69609. if (EXPECT_FAIL()) {
  69610. RSA_free(rsa);
  69611. }
  69612. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  69613. ExpectIntEQ(EVP_PKEY_encrypt_init(ctx), WOLFSSL_SUCCESS);
  69614. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  69615. WOLFSSL_SUCCESS);
  69616. /* Test pkey references count is decremented. pkey shouldn't be destroyed
  69617. since ctx uses it.*/
  69618. ExpectIntEQ(pkey->ref.count, 2);
  69619. EVP_PKEY_free(pkey);
  69620. ExpectIntEQ(pkey->ref.count, 1);
  69621. /* Encrypt data */
  69622. /* Check that we can get the required output buffer length by passing in a
  69623. * NULL output buffer. */
  69624. ExpectIntEQ(EVP_PKEY_encrypt(ctx, NULL, &outEncLen,
  69625. (const unsigned char*)in, inlen), WOLFSSL_SUCCESS);
  69626. ExpectIntEQ(rsaKeySz, outEncLen);
  69627. /* Now do the actual encryption. */
  69628. ExpectIntEQ(EVP_PKEY_encrypt(ctx, outEnc, &outEncLen,
  69629. (const unsigned char*)in, inlen), WOLFSSL_SUCCESS);
  69630. /* Decrypt data */
  69631. ExpectIntEQ(EVP_PKEY_decrypt_init(ctx), WOLFSSL_SUCCESS);
  69632. /* Check that we can get the required output buffer length by passing in a
  69633. * NULL output buffer. */
  69634. ExpectIntEQ(EVP_PKEY_decrypt(ctx, NULL, &outDecLen, outEnc, outEncLen),
  69635. WOLFSSL_SUCCESS);
  69636. ExpectIntEQ(rsaKeySz, outDecLen);
  69637. /* Now do the actual decryption. */
  69638. ExpectIntEQ(EVP_PKEY_decrypt(ctx, outDec, &outDecLen, outEnc, outEncLen),
  69639. WOLFSSL_SUCCESS);
  69640. ExpectIntEQ(XMEMCMP(in, outDec, outDecLen), 0);
  69641. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  69642. /* The input length must be the same size as the RSA key.*/
  69643. ExpectNotNull(inTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  69644. DYNAMIC_TYPE_TMP_BUFFER));
  69645. if (inTmp != NULL) {
  69646. XMEMSET(inTmp, 9, rsaKeySz);
  69647. }
  69648. ExpectNotNull(outEncTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  69649. DYNAMIC_TYPE_TMP_BUFFER));
  69650. if (outEncTmp != NULL) {
  69651. XMEMSET(outEncTmp, 0, rsaKeySz);
  69652. }
  69653. ExpectNotNull(outDecTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  69654. DYNAMIC_TYPE_TMP_BUFFER));
  69655. if (outDecTmp != NULL) {
  69656. XMEMSET(outDecTmp, 0, rsaKeySz);
  69657. }
  69658. ExpectIntEQ(EVP_PKEY_encrypt_init(ctx), WOLFSSL_SUCCESS);
  69659. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_NO_PADDING),
  69660. WOLFSSL_SUCCESS);
  69661. ExpectIntEQ(EVP_PKEY_encrypt(ctx, outEncTmp, &outEncLen, inTmp, rsaKeySz),
  69662. WOLFSSL_SUCCESS);
  69663. ExpectIntEQ(EVP_PKEY_decrypt_init(ctx), WOLFSSL_SUCCESS);
  69664. ExpectIntEQ(EVP_PKEY_decrypt(ctx, outDecTmp, &outDecLen, outEncTmp,
  69665. outEncLen), WOLFSSL_SUCCESS);
  69666. ExpectIntEQ(XMEMCMP(inTmp, outDecTmp, outDecLen), 0);
  69667. #endif
  69668. EVP_PKEY_CTX_free(ctx);
  69669. XFREE(outEnc, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  69670. XFREE(outDec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  69671. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  69672. XFREE(inTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  69673. XFREE(outEncTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  69674. XFREE(outDecTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  69675. #endif
  69676. #endif
  69677. return EXPECT_RESULT();
  69678. }
  69679. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  69680. !defined(HAVE_SELFTEST)
  69681. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69682. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  69683. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  69684. #endif
  69685. #endif
  69686. #endif
  69687. #if defined(OPENSSL_EXTRA)
  69688. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  69689. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  69690. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  69691. #endif
  69692. #endif
  69693. #endif
  69694. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  69695. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69696. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  69697. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  69698. #endif
  69699. #endif
  69700. #endif
  69701. #ifdef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  69702. static int test_wolfSSL_EVP_PKEY_sign_verify(int keyType)
  69703. {
  69704. EXPECT_DECLS;
  69705. #if defined(OPENSSL_EXTRA)
  69706. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  69707. !defined(HAVE_SELFTEST)
  69708. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69709. WOLFSSL_RSA* rsa = NULL;
  69710. #endif
  69711. #endif
  69712. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  69713. WOLFSSL_DSA* dsa = NULL;
  69714. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  69715. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  69716. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69717. WOLFSSL_EC_KEY* ecKey = NULL;
  69718. #endif
  69719. #endif
  69720. WOLFSSL_EVP_PKEY* pkey = NULL;
  69721. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  69722. WOLFSSL_EVP_PKEY_CTX* ctx_verify = NULL;
  69723. const char* in = "What is easy to do is easy not to do.";
  69724. size_t inlen = XSTRLEN(in);
  69725. byte hash[SHA256_DIGEST_LENGTH] = {0};
  69726. byte zero[SHA256_DIGEST_LENGTH] = {0};
  69727. SHA256_CTX c;
  69728. byte* sig = NULL;
  69729. byte* sigVerify = NULL;
  69730. size_t siglen;
  69731. size_t siglenOnlyLen;
  69732. size_t keySz = 2048/8; /* Bytes */
  69733. ExpectNotNull(sig =
  69734. (byte*)XMALLOC(keySz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  69735. ExpectNotNull(sigVerify =
  69736. (byte*)XMALLOC(keySz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  69737. siglen = keySz;
  69738. ExpectNotNull(XMEMSET(sig, 0, keySz));
  69739. ExpectNotNull(XMEMSET(sigVerify, 0, keySz));
  69740. /* Generate hash */
  69741. SHA256_Init(&c);
  69742. SHA256_Update(&c, in, inlen);
  69743. SHA256_Final(hash, &c);
  69744. #ifdef WOLFSSL_SMALL_STACK_CACHE
  69745. /* workaround for small stack cache case */
  69746. wc_Sha256Free((wc_Sha256*)&c);
  69747. #endif
  69748. /* Generate key */
  69749. ExpectNotNull(pkey = EVP_PKEY_new());
  69750. switch (keyType) {
  69751. case EVP_PKEY_RSA:
  69752. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  69753. !defined(HAVE_SELFTEST)
  69754. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69755. {
  69756. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  69757. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  69758. }
  69759. #endif
  69760. #endif
  69761. break;
  69762. case EVP_PKEY_DSA:
  69763. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  69764. ExpectNotNull(dsa = DSA_new());
  69765. ExpectIntEQ(DSA_generate_parameters_ex(dsa, 2048,
  69766. NULL, 0, NULL, NULL, NULL), 1);
  69767. ExpectIntEQ(DSA_generate_key(dsa), 1);
  69768. ExpectIntEQ(EVP_PKEY_set1_DSA(pkey, dsa), WOLFSSL_SUCCESS);
  69769. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  69770. break;
  69771. case EVP_PKEY_EC:
  69772. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  69773. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69774. {
  69775. ExpectNotNull(ecKey = EC_KEY_new());
  69776. ExpectIntEQ(EC_KEY_generate_key(ecKey), 1);
  69777. ExpectIntEQ(
  69778. EVP_PKEY_assign_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  69779. if (EXPECT_FAIL()) {
  69780. EC_KEY_free(ecKey);
  69781. }
  69782. }
  69783. #endif
  69784. #endif
  69785. break;
  69786. }
  69787. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  69788. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  69789. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  69790. !defined(HAVE_SELFTEST)
  69791. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69792. if (keyType == EVP_PKEY_RSA)
  69793. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  69794. WOLFSSL_SUCCESS);
  69795. #endif
  69796. #endif
  69797. /* Check returning only length */
  69798. ExpectIntEQ(EVP_PKEY_sign(ctx, NULL, &siglenOnlyLen, hash,
  69799. SHA256_DIGEST_LENGTH), WOLFSSL_SUCCESS);
  69800. ExpectIntGT(siglenOnlyLen, 0);
  69801. /* Sign data */
  69802. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &siglen, hash,
  69803. SHA256_DIGEST_LENGTH), WOLFSSL_SUCCESS);
  69804. ExpectIntGE(siglenOnlyLen, siglen);
  69805. /* Verify signature */
  69806. ExpectNotNull(ctx_verify = EVP_PKEY_CTX_new(pkey, NULL));
  69807. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  69808. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  69809. !defined(HAVE_SELFTEST)
  69810. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69811. if (keyType == EVP_PKEY_RSA)
  69812. ExpectIntEQ(
  69813. EVP_PKEY_CTX_set_rsa_padding(ctx_verify, RSA_PKCS1_PADDING),
  69814. WOLFSSL_SUCCESS);
  69815. #endif
  69816. #endif
  69817. ExpectIntEQ(EVP_PKEY_verify(
  69818. ctx_verify, sig, siglen, hash, SHA256_DIGEST_LENGTH),
  69819. WOLFSSL_SUCCESS);
  69820. ExpectIntEQ(EVP_PKEY_verify(
  69821. ctx_verify, sig, siglen, zero, SHA256_DIGEST_LENGTH),
  69822. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69823. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  69824. !defined(HAVE_SELFTEST)
  69825. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69826. if (keyType == EVP_PKEY_RSA) {
  69827. #if defined(WC_RSA_NO_PADDING) || defined(WC_RSA_DIRECT)
  69828. /* Try RSA sign/verify with no padding. */
  69829. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  69830. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_NO_PADDING),
  69831. WOLFSSL_SUCCESS);
  69832. ExpectIntEQ(EVP_PKEY_sign(ctx, sigVerify, &siglen, sig,
  69833. siglen), WOLFSSL_SUCCESS);
  69834. ExpectIntGE(siglenOnlyLen, siglen);
  69835. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  69836. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  69837. RSA_NO_PADDING), WOLFSSL_SUCCESS);
  69838. ExpectIntEQ(EVP_PKEY_verify(ctx_verify, sigVerify, siglen, sig,
  69839. siglen), WOLFSSL_SUCCESS);
  69840. #endif
  69841. /* Wrong padding schemes. */
  69842. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  69843. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx,
  69844. RSA_PKCS1_OAEP_PADDING), WOLFSSL_SUCCESS);
  69845. ExpectIntNE(EVP_PKEY_sign(ctx, sigVerify, &siglen, sig,
  69846. siglen), WOLFSSL_SUCCESS);
  69847. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  69848. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  69849. RSA_PKCS1_OAEP_PADDING), WOLFSSL_SUCCESS);
  69850. ExpectIntNE(EVP_PKEY_verify(ctx_verify, sigVerify, siglen, sig,
  69851. siglen), WOLFSSL_SUCCESS);
  69852. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  69853. WOLFSSL_SUCCESS);
  69854. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  69855. RSA_PKCS1_PADDING), WOLFSSL_SUCCESS);
  69856. }
  69857. #endif
  69858. #endif
  69859. /* error cases */
  69860. siglen = keySz; /* Reset because sig size may vary slightly */
  69861. ExpectIntNE(EVP_PKEY_sign_init(NULL), WOLFSSL_SUCCESS);
  69862. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  69863. ExpectIntNE(EVP_PKEY_sign(NULL, sig, &siglen, (byte*)in, inlen),
  69864. WOLFSSL_SUCCESS);
  69865. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &siglen, (byte*)in, inlen),
  69866. WOLFSSL_SUCCESS);
  69867. EVP_PKEY_free(pkey);
  69868. pkey = NULL;
  69869. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  69870. DSA_free(dsa);
  69871. dsa = NULL;
  69872. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  69873. EVP_PKEY_CTX_free(ctx_verify);
  69874. ctx_verify = NULL;
  69875. EVP_PKEY_CTX_free(ctx);
  69876. ctx = NULL;
  69877. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  69878. XFREE(sigVerify, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  69879. #endif /* OPENSSL_EXTRA */
  69880. return EXPECT_RESULT();
  69881. }
  69882. #endif
  69883. static int test_wolfSSL_EVP_PKEY_sign_verify_rsa(void)
  69884. {
  69885. EXPECT_DECLS;
  69886. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  69887. !defined(HAVE_SELFTEST)
  69888. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69889. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_RSA), TEST_SUCCESS);
  69890. #endif
  69891. #endif
  69892. return EXPECT_RESULT();
  69893. }
  69894. static int test_wolfSSL_EVP_PKEY_sign_verify_dsa(void)
  69895. {
  69896. EXPECT_DECLS;
  69897. #if defined(OPENSSL_EXTRA)
  69898. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  69899. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_DSA), TEST_SUCCESS);
  69900. #endif
  69901. #endif
  69902. return EXPECT_RESULT();
  69903. }
  69904. static int test_wolfSSL_EVP_PKEY_sign_verify_ec(void)
  69905. {
  69906. EXPECT_DECLS;
  69907. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  69908. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69909. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_EC), TEST_SUCCESS);
  69910. #endif
  69911. #endif
  69912. return EXPECT_RESULT();
  69913. }
  69914. static int test_EVP_PKEY_rsa(void)
  69915. {
  69916. EXPECT_DECLS;
  69917. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  69918. WOLFSSL_RSA* rsa = NULL;
  69919. WOLFSSL_EVP_PKEY* pkey = NULL;
  69920. ExpectNotNull(rsa = wolfSSL_RSA_new());
  69921. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  69922. ExpectIntEQ(EVP_PKEY_assign_RSA(NULL, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69923. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69924. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  69925. if (EXPECT_FAIL()) {
  69926. wolfSSL_RSA_free(rsa);
  69927. }
  69928. ExpectPtrEq(EVP_PKEY_get0_RSA(pkey), rsa);
  69929. wolfSSL_EVP_PKEY_free(pkey);
  69930. #endif
  69931. return EXPECT_RESULT();
  69932. }
  69933. static int test_EVP_PKEY_ec(void)
  69934. {
  69935. EXPECT_DECLS;
  69936. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  69937. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69938. WOLFSSL_EC_KEY* ecKey = NULL;
  69939. WOLFSSL_EVP_PKEY* pkey = NULL;
  69940. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  69941. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  69942. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(NULL, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69943. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69944. /* Should fail since ecKey is empty */
  69945. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69946. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  69947. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  69948. if (EXPECT_FAIL()) {
  69949. wolfSSL_EC_KEY_free(ecKey);
  69950. }
  69951. wolfSSL_EVP_PKEY_free(pkey);
  69952. #endif
  69953. #endif
  69954. return EXPECT_RESULT();
  69955. }
  69956. static int test_EVP_PKEY_cmp(void)
  69957. {
  69958. EXPECT_DECLS;
  69959. #if defined(OPENSSL_EXTRA)
  69960. EVP_PKEY *a = NULL;
  69961. EVP_PKEY *b = NULL;
  69962. const unsigned char *in;
  69963. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  69964. in = client_key_der_2048;
  69965. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  69966. &in, (long)sizeof_client_key_der_2048));
  69967. in = client_key_der_2048;
  69968. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  69969. &in, (long)sizeof_client_key_der_2048));
  69970. /* Test success case RSA */
  69971. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  69972. ExpectIntEQ(EVP_PKEY_cmp(a, b), 1);
  69973. #else
  69974. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  69975. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  69976. EVP_PKEY_free(b);
  69977. b = NULL;
  69978. EVP_PKEY_free(a);
  69979. a = NULL;
  69980. #endif
  69981. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  69982. in = ecc_clikey_der_256;
  69983. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  69984. &in, (long)sizeof_ecc_clikey_der_256));
  69985. in = ecc_clikey_der_256;
  69986. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  69987. &in, (long)sizeof_ecc_clikey_der_256));
  69988. /* Test success case ECC */
  69989. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  69990. ExpectIntEQ(EVP_PKEY_cmp(a, b), 1);
  69991. #else
  69992. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  69993. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  69994. EVP_PKEY_free(b);
  69995. b = NULL;
  69996. EVP_PKEY_free(a);
  69997. a = NULL;
  69998. #endif
  69999. /* Test failure cases */
  70000. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048) && \
  70001. defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  70002. in = client_key_der_2048;
  70003. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  70004. &in, (long)sizeof_client_key_der_2048));
  70005. in = ecc_clikey_der_256;
  70006. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  70007. &in, (long)sizeof_ecc_clikey_der_256));
  70008. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  70009. ExpectIntEQ(EVP_PKEY_cmp(a, b), -1);
  70010. #else
  70011. ExpectIntNE(EVP_PKEY_cmp(a, b), 0);
  70012. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  70013. EVP_PKEY_free(b);
  70014. b = NULL;
  70015. EVP_PKEY_free(a);
  70016. a = NULL;
  70017. #endif
  70018. /* invalid or empty failure cases */
  70019. a = EVP_PKEY_new();
  70020. b = EVP_PKEY_new();
  70021. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  70022. ExpectIntEQ(EVP_PKEY_cmp(NULL, NULL), 0);
  70023. ExpectIntEQ(EVP_PKEY_cmp(a, NULL), 0);
  70024. ExpectIntEQ(EVP_PKEY_cmp(NULL, b), 0);
  70025. #ifdef NO_RSA
  70026. /* Type check will fail since RSA is the default EVP key type */
  70027. ExpectIntEQ(EVP_PKEY_cmp(a, b), -2);
  70028. #else
  70029. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  70030. #endif
  70031. #else
  70032. ExpectIntNE(EVP_PKEY_cmp(NULL, NULL), 0);
  70033. ExpectIntNE(EVP_PKEY_cmp(a, NULL), 0);
  70034. ExpectIntNE(EVP_PKEY_cmp(NULL, b), 0);
  70035. ExpectIntNE(EVP_PKEY_cmp(a, b), 0);
  70036. #endif
  70037. EVP_PKEY_free(b);
  70038. EVP_PKEY_free(a);
  70039. (void)in;
  70040. #endif
  70041. return EXPECT_RESULT();
  70042. }
  70043. static int test_ERR_load_crypto_strings(void)
  70044. {
  70045. #if defined(OPENSSL_ALL)
  70046. ERR_load_crypto_strings();
  70047. return TEST_SUCCESS;
  70048. #else
  70049. return TEST_SKIPPED;
  70050. #endif
  70051. }
  70052. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  70053. static void free_x509(X509* x)
  70054. {
  70055. AssertIntEQ((x == (X509*)1 || x == (X509*)2), 1);
  70056. }
  70057. #endif
  70058. static int test_sk_X509(void)
  70059. {
  70060. EXPECT_DECLS;
  70061. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  70062. {
  70063. STACK_OF(X509)* s = NULL;
  70064. ExpectNotNull(s = sk_X509_new_null());
  70065. ExpectIntEQ(sk_X509_num(s), 0);
  70066. sk_X509_pop_free(s, NULL);
  70067. ExpectNotNull(s = sk_X509_new_null());
  70068. ExpectIntEQ(sk_X509_num(s), 0);
  70069. sk_X509_pop_free(s, NULL);
  70070. ExpectNotNull(s = sk_X509_new_null());
  70071. sk_X509_push(s, (X509*)1);
  70072. ExpectIntEQ(sk_X509_num(s), 1);
  70073. ExpectIntEQ((sk_X509_value(s, 0) == (X509*)1), 1);
  70074. sk_X509_push(s, (X509*)2);
  70075. ExpectIntEQ(sk_X509_num(s), 2);
  70076. ExpectIntEQ((sk_X509_value(s, 0) == (X509*)2), 1);
  70077. ExpectIntEQ((sk_X509_value(s, 1) == (X509*)1), 1);
  70078. sk_X509_push(s, (X509*)2);
  70079. sk_X509_pop_free(s, free_x509);
  70080. }
  70081. {
  70082. /* Push a list of 10 X509s onto stack, then verify that
  70083. * value(), push(), shift(), and pop() behave as expected. */
  70084. STACK_OF(X509)* s = NULL;
  70085. X509* xList[10];
  70086. int i = 0;
  70087. const int len = (sizeof(xList) / sizeof(xList[0]));
  70088. for (i = 0; i < len; ++i) {
  70089. xList[i] = NULL;
  70090. ExpectNotNull(xList[i] = X509_new());
  70091. }
  70092. /* test push, pop, and free */
  70093. ExpectNotNull(s = sk_X509_new_null());
  70094. for (i = 0; i < len; ++i) {
  70095. sk_X509_push(s, xList[i]);
  70096. ExpectIntEQ(sk_X509_num(s), i + 1);
  70097. ExpectIntEQ((sk_X509_value(s, 0) == xList[i]), 1);
  70098. ExpectIntEQ((sk_X509_value(s, i) == xList[0]), 1);
  70099. }
  70100. /* pop returns and removes last pushed on stack, which is index 0
  70101. * in sk_x509_value */
  70102. for (i = 0; i < len; ++i) {
  70103. X509 * x = sk_X509_value(s, 0);
  70104. X509 * y = sk_X509_pop(s);
  70105. X509 * z = xList[len - 1 - i];
  70106. ExpectIntEQ((x == y), 1);
  70107. ExpectIntEQ((x == z), 1);
  70108. ExpectIntEQ(sk_X509_num(s), len - 1 - i);
  70109. }
  70110. sk_free(s);
  70111. s = NULL;
  70112. /* test push, shift, and free */
  70113. ExpectNotNull(s = sk_X509_new_null());
  70114. for (i = 0; i < len; ++i) {
  70115. sk_X509_push(s, xList[i]);
  70116. ExpectIntEQ(sk_X509_num(s), i + 1);
  70117. ExpectIntEQ((sk_X509_value(s, 0) == xList[i]), 1);
  70118. ExpectIntEQ((sk_X509_value(s, i) == xList[0]), 1);
  70119. }
  70120. /* shift returns and removes first pushed on stack, which is index i
  70121. * in sk_x509_value() */
  70122. for (i = 0; i < len; ++i) {
  70123. X509 * x = sk_X509_value(s, len - 1 - i);
  70124. X509 * y = sk_X509_shift(s);
  70125. X509 * z = xList[i];
  70126. ExpectIntEQ((x == y), 1);
  70127. ExpectIntEQ((x == z), 1);
  70128. ExpectIntEQ(sk_X509_num(s), len - 1 - i);
  70129. }
  70130. sk_free(s);
  70131. for (i = 0; i < len; ++i)
  70132. X509_free(xList[i]);
  70133. }
  70134. #endif
  70135. return EXPECT_RESULT();
  70136. }
  70137. static int test_sk_X509_CRL(void)
  70138. {
  70139. EXPECT_DECLS;
  70140. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && defined(HAVE_CRL)
  70141. X509_CRL* crl = NULL;
  70142. XFILE fp = XBADFILE;
  70143. STACK_OF(X509_CRL)* s = NULL;
  70144. ExpectTrue((fp = XFOPEN("./certs/crl/crl.pem", "rb")) != XBADFILE);
  70145. ExpectNotNull(crl = (X509_CRL*)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  70146. NULL, NULL));
  70147. if (fp != XBADFILE)
  70148. XFCLOSE(fp);
  70149. ExpectNotNull(s = sk_X509_CRL_new());
  70150. ExpectIntEQ(sk_X509_CRL_num(s), 0);
  70151. ExpectIntEQ(sk_X509_CRL_push(s, crl), 1);
  70152. if (EXPECT_FAIL()) {
  70153. X509_CRL_free(crl);
  70154. }
  70155. ExpectIntEQ(sk_X509_CRL_num(s), 1);
  70156. ExpectPtrEq(sk_X509_CRL_value(s, 0), crl);
  70157. sk_X509_CRL_free(s);
  70158. #endif
  70159. return EXPECT_RESULT();
  70160. }
  70161. static int test_X509_get_signature_nid(void)
  70162. {
  70163. EXPECT_DECLS;
  70164. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  70165. X509* x509 = NULL;
  70166. ExpectIntEQ(X509_get_signature_nid(NULL), 0);
  70167. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  70168. SSL_FILETYPE_PEM));
  70169. ExpectIntEQ(X509_get_signature_nid(x509), NID_sha256WithRSAEncryption);
  70170. X509_free(x509);
  70171. #endif
  70172. return EXPECT_RESULT();
  70173. }
  70174. static int test_X509_REQ(void)
  70175. {
  70176. EXPECT_DECLS;
  70177. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  70178. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_BIO)
  70179. X509_NAME* name = NULL;
  70180. #ifndef NO_RSA
  70181. X509_NAME* subject = NULL;
  70182. #endif
  70183. #if !defined(NO_RSA) || defined(HAVE_ECC)
  70184. X509_REQ* req = NULL;
  70185. EVP_PKEY* priv = NULL;
  70186. EVP_PKEY* pub = NULL;
  70187. unsigned char* der = NULL;
  70188. int len;
  70189. #endif
  70190. #ifndef NO_RSA
  70191. EVP_MD_CTX *mctx = NULL;
  70192. EVP_PKEY_CTX *pkctx = NULL;
  70193. #ifdef USE_CERT_BUFFERS_1024
  70194. const unsigned char* rsaPriv = (const unsigned char*)client_key_der_1024;
  70195. const unsigned char* rsaPub = (unsigned char*)client_keypub_der_1024;
  70196. #elif defined(USE_CERT_BUFFERS_2048)
  70197. const unsigned char* rsaPriv = (const unsigned char*)client_key_der_2048;
  70198. const unsigned char* rsaPub = (unsigned char*)client_keypub_der_2048;
  70199. #endif
  70200. #endif
  70201. #ifdef HAVE_ECC
  70202. const unsigned char* ecPriv = (const unsigned char*)ecc_clikey_der_256;
  70203. const unsigned char* ecPub = (unsigned char*)ecc_clikeypub_der_256;
  70204. #endif
  70205. ExpectNotNull(name = X509_NAME_new());
  70206. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  70207. (byte*)"wolfssl.com", 11, 0, 1), WOLFSSL_SUCCESS);
  70208. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  70209. (byte*)"support@wolfssl.com", 19, -1, 1), WOLFSSL_SUCCESS);
  70210. #ifndef NO_RSA
  70211. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &rsaPriv,
  70212. (long)sizeof_client_key_der_2048));
  70213. ExpectNotNull(pub = d2i_PUBKEY(NULL, &rsaPub,
  70214. (long)sizeof_client_keypub_der_2048));
  70215. ExpectNotNull(req = X509_REQ_new());
  70216. ExpectIntEQ(X509_REQ_set_subject_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70217. ExpectIntEQ(X509_REQ_set_subject_name(req, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70218. ExpectIntEQ(X509_REQ_set_subject_name(req, name), WOLFSSL_SUCCESS);
  70219. ExpectIntEQ(X509_REQ_set_pubkey(NULL, pub), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70220. ExpectIntEQ(X509_REQ_set_pubkey(req, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70221. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  70222. ExpectIntEQ(X509_REQ_sign(NULL, priv, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70223. ExpectIntEQ(X509_REQ_sign(req, NULL, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70224. ExpectIntEQ(X509_REQ_sign(req, priv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70225. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  70226. len = i2d_X509_REQ(req, &der);
  70227. DEBUG_WRITE_DER(der, len, "req.der");
  70228. #ifdef USE_CERT_BUFFERS_1024
  70229. ExpectIntEQ(len, 381);
  70230. #else
  70231. ExpectIntEQ(len, 643);
  70232. #endif
  70233. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  70234. der = NULL;
  70235. mctx = EVP_MD_CTX_new();
  70236. ExpectIntEQ(EVP_DigestSignInit(mctx, &pkctx, EVP_sha256(), NULL, priv),
  70237. WOLFSSL_SUCCESS);
  70238. ExpectIntEQ(X509_REQ_sign_ctx(req, mctx), WOLFSSL_SUCCESS);
  70239. EVP_MD_CTX_free(mctx);
  70240. mctx = NULL;
  70241. X509_REQ_free(NULL);
  70242. X509_REQ_free(req);
  70243. req = NULL;
  70244. /* Test getting the subject from a newly created X509_REQ */
  70245. ExpectNotNull(req = X509_REQ_new());
  70246. ExpectNotNull(subject = X509_REQ_get_subject_name(req));
  70247. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_commonName,
  70248. MBSTRING_UTF8, (unsigned char*)"www.wolfssl.com", -1, -1, 0), 1);
  70249. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_countryName,
  70250. MBSTRING_UTF8, (unsigned char*)"US", -1, -1, 0), 1);
  70251. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_localityName,
  70252. MBSTRING_UTF8, (unsigned char*)"Bozeman", -1, -1, 0), 1);
  70253. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_stateOrProvinceName,
  70254. MBSTRING_UTF8, (unsigned char*)"Montana", -1, -1, 0), 1);
  70255. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_organizationName,
  70256. MBSTRING_UTF8, (unsigned char*)"wolfSSL", -1, -1, 0), 1);
  70257. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_organizationalUnitName,
  70258. MBSTRING_UTF8, (unsigned char*)"Testing", -1, -1, 0), 1);
  70259. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  70260. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  70261. len = i2d_X509_REQ(req, &der);
  70262. DEBUG_WRITE_DER(der, len, "req2.der");
  70263. #ifdef USE_CERT_BUFFERS_1024
  70264. ExpectIntEQ(len, 435);
  70265. #else
  70266. ExpectIntEQ(len, 696);
  70267. #endif
  70268. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  70269. der = NULL;
  70270. EVP_PKEY_free(pub);
  70271. pub = NULL;
  70272. EVP_PKEY_free(priv);
  70273. priv = NULL;
  70274. X509_REQ_free(req);
  70275. req = NULL;
  70276. #endif
  70277. #ifdef HAVE_ECC
  70278. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL, &ecPriv,
  70279. sizeof_ecc_clikey_der_256));
  70280. ExpectNotNull(pub = wolfSSL_d2i_PUBKEY(NULL, &ecPub,
  70281. sizeof_ecc_clikeypub_der_256));
  70282. ExpectNotNull(req = X509_REQ_new());
  70283. ExpectIntEQ(X509_REQ_set_subject_name(req, name), WOLFSSL_SUCCESS);
  70284. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  70285. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  70286. /* Signature is random and may be shorter or longer. */
  70287. ExpectIntGE((len = i2d_X509_REQ(req, &der)), 245);
  70288. ExpectIntLE(len, 253);
  70289. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  70290. X509_REQ_free(req);
  70291. EVP_PKEY_free(pub);
  70292. EVP_PKEY_free(priv);
  70293. #ifdef FP_ECC
  70294. wc_ecc_fp_free();
  70295. #endif
  70296. #endif /* HAVE_ECC */
  70297. X509_NAME_free(name);
  70298. #endif
  70299. return EXPECT_RESULT();
  70300. }
  70301. static int test_wolfssl_PKCS7(void)
  70302. {
  70303. EXPECT_DECLS;
  70304. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_BIO) && \
  70305. !defined(NO_RSA)
  70306. PKCS7* pkcs7 = NULL;
  70307. byte data[FOURK_BUF];
  70308. word32 len = sizeof(data);
  70309. const byte* p = data;
  70310. byte content[] = "Test data to encode.";
  70311. #if !defined(NO_RSA) & defined(USE_CERT_BUFFERS_2048)
  70312. BIO* bio = NULL;
  70313. byte key[sizeof(client_key_der_2048)];
  70314. word32 keySz = (word32)sizeof(key);
  70315. byte* out = NULL;
  70316. #endif
  70317. ExpectIntGT((len = (word32)CreatePKCS7SignedData(data, (int)len, content,
  70318. (word32)sizeof(content), 0, 0, 0, RSA_TYPE)), 0);
  70319. ExpectNull(pkcs7 = d2i_PKCS7(NULL, NULL, (int)len));
  70320. ExpectNull(pkcs7 = d2i_PKCS7(NULL, &p, 0));
  70321. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  70322. ExpectIntEQ(wolfSSL_PKCS7_verify(NULL, NULL, NULL, NULL, NULL,
  70323. PKCS7_NOVERIFY), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70324. PKCS7_free(pkcs7);
  70325. pkcs7 = NULL;
  70326. /* fail case, without PKCS7_NOVERIFY */
  70327. p = data;
  70328. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  70329. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, NULL, NULL,
  70330. 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70331. PKCS7_free(pkcs7);
  70332. pkcs7 = NULL;
  70333. /* success case, with PKCS7_NOVERIFY */
  70334. p = data;
  70335. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  70336. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, NULL, NULL,
  70337. PKCS7_NOVERIFY), WOLFSSL_SUCCESS);
  70338. #if !defined(NO_RSA) & defined(USE_CERT_BUFFERS_2048)
  70339. /* test i2d */
  70340. XMEMCPY(key, client_key_der_2048, keySz);
  70341. if (pkcs7 != NULL) {
  70342. pkcs7->privateKey = key;
  70343. pkcs7->privateKeySz = (word32)sizeof(key);
  70344. pkcs7->encryptOID = RSAk;
  70345. #ifdef NO_SHA
  70346. pkcs7->hashOID = SHA256h;
  70347. #else
  70348. pkcs7->hashOID = SHAh;
  70349. #endif
  70350. }
  70351. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  70352. ExpectIntEQ(i2d_PKCS7_bio(bio, pkcs7), 1);
  70353. #ifndef NO_ASN_TIME
  70354. ExpectIntEQ(i2d_PKCS7(pkcs7, &out), 655);
  70355. #else
  70356. ExpectIntEQ(i2d_PKCS7(pkcs7, &out), 625);
  70357. #endif
  70358. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  70359. BIO_free(bio);
  70360. #endif
  70361. PKCS7_free(NULL);
  70362. PKCS7_free(pkcs7);
  70363. #endif
  70364. return EXPECT_RESULT();
  70365. }
  70366. static int test_wolfSSL_PKCS7_sign(void)
  70367. {
  70368. EXPECT_DECLS;
  70369. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_BIO) && \
  70370. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  70371. PKCS7* p7 = NULL;
  70372. PKCS7* p7Ver = NULL;
  70373. byte* out = NULL;
  70374. byte* tmpPtr = NULL;
  70375. int outLen = 0;
  70376. int flags = 0;
  70377. byte data[] = "Test data to encode.";
  70378. const char* cert = "./certs/server-cert.pem";
  70379. const char* key = "./certs/server-key.pem";
  70380. const char* ca = "./certs/ca-cert.pem";
  70381. WOLFSSL_BIO* certBio = NULL;
  70382. WOLFSSL_BIO* keyBio = NULL;
  70383. WOLFSSL_BIO* caBio = NULL;
  70384. WOLFSSL_BIO* inBio = NULL;
  70385. X509* signCert = NULL;
  70386. EVP_PKEY* signKey = NULL;
  70387. X509* caCert = NULL;
  70388. X509_STORE* store = NULL;
  70389. #ifndef NO_PKCS7_STREAM
  70390. int z;
  70391. int ret;
  70392. #endif /* !NO_PKCS7_STREAM */
  70393. /* read signer cert/key into BIO */
  70394. ExpectNotNull(certBio = BIO_new_file(cert, "r"));
  70395. ExpectNotNull(keyBio = BIO_new_file(key, "r"));
  70396. ExpectNotNull(signCert = PEM_read_bio_X509(certBio, NULL, 0, NULL));
  70397. ExpectNotNull(signKey = PEM_read_bio_PrivateKey(keyBio, NULL, 0, NULL));
  70398. /* read CA cert into store (for verify) */
  70399. ExpectNotNull(caBio = BIO_new_file(ca, "r"));
  70400. ExpectNotNull(caCert = PEM_read_bio_X509(caBio, NULL, 0, NULL));
  70401. ExpectNotNull(store = X509_STORE_new());
  70402. ExpectIntEQ(X509_STORE_add_cert(store, caCert), 1);
  70403. /* data to be signed into BIO */
  70404. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70405. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70406. /* PKCS7_sign, bad args: signer NULL */
  70407. ExpectNull(p7 = PKCS7_sign(NULL, signKey, NULL, inBio, 0));
  70408. /* PKCS7_sign, bad args: signer key NULL */
  70409. ExpectNull(p7 = PKCS7_sign(signCert, NULL, NULL, inBio, 0));
  70410. /* PKCS7_sign, bad args: in data NULL without PKCS7_STREAM */
  70411. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, NULL, 0));
  70412. /* PKCS7_sign, bad args: PKCS7_NOCERTS flag not supported */
  70413. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, PKCS7_NOCERTS));
  70414. /* PKCS7_sign, bad args: PKCS7_PARTIAL flag not supported */
  70415. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, PKCS7_PARTIAL));
  70416. /* TEST SUCCESS: Not detached, not streaming, not MIME */
  70417. {
  70418. flags = PKCS7_BINARY;
  70419. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70420. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  70421. /* verify with d2i_PKCS7 */
  70422. tmpPtr = out;
  70423. ExpectNotNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  70424. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  70425. PKCS7_free(p7Ver);
  70426. p7Ver = NULL;
  70427. /* verify with wc_PKCS7_VerifySignedData */
  70428. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  70429. ExpectIntEQ(wc_PKCS7_Init(p7Ver, HEAP_HINT, INVALID_DEVID), 0);
  70430. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  70431. #ifndef NO_PKCS7_STREAM
  70432. /* verify with wc_PKCS7_VerifySignedData streaming */
  70433. wc_PKCS7_Free(p7Ver);
  70434. p7Ver = NULL;
  70435. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  70436. ExpectIntEQ(wc_PKCS7_Init(p7Ver, HEAP_HINT, INVALID_DEVID), 0);
  70437. /* test for streaming */
  70438. ret = -1;
  70439. for (z = 0; z < outLen && ret != 0; z++) {
  70440. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  70441. if (ret < 0){
  70442. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  70443. }
  70444. }
  70445. ExpectIntEQ(ret, 0);
  70446. #endif /* !NO_PKCS7_STREAM */
  70447. /* compare the signer found to expected signer */
  70448. ExpectIntNE(p7Ver->verifyCertSz, 0);
  70449. tmpPtr = NULL;
  70450. ExpectIntEQ(i2d_X509(signCert, &tmpPtr), p7Ver->verifyCertSz);
  70451. ExpectIntEQ(XMEMCMP(tmpPtr, p7Ver->verifyCert, p7Ver->verifyCertSz), 0);
  70452. XFREE(tmpPtr, NULL, DYNAMIC_TYPE_OPENSSL);
  70453. tmpPtr = NULL;
  70454. wc_PKCS7_Free(p7Ver);
  70455. p7Ver = NULL;
  70456. ExpectNotNull(out);
  70457. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  70458. out = NULL;
  70459. PKCS7_free(p7);
  70460. p7 = NULL;
  70461. }
  70462. /* TEST SUCCESS: Not detached, streaming, not MIME. Also bad arg
  70463. * tests for PKCS7_final() while we have a PKCS7 pointer to use */
  70464. {
  70465. /* re-populate input BIO, may have been consumed */
  70466. BIO_free(inBio);
  70467. inBio = NULL;
  70468. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70469. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70470. flags = PKCS7_BINARY | PKCS7_STREAM;
  70471. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70472. ExpectIntEQ(PKCS7_final(p7, inBio, flags), 1);
  70473. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  70474. /* PKCS7_final, bad args: PKCS7 null */
  70475. ExpectIntEQ(PKCS7_final(NULL, inBio, 0), 0);
  70476. /* PKCS7_final, bad args: PKCS7 null */
  70477. ExpectIntEQ(PKCS7_final(p7, NULL, 0), 0);
  70478. tmpPtr = out;
  70479. ExpectNotNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  70480. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  70481. PKCS7_free(p7Ver);
  70482. p7Ver = NULL;
  70483. ExpectNotNull(out);
  70484. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  70485. out = NULL;
  70486. PKCS7_free(p7);
  70487. p7 = NULL;
  70488. }
  70489. /* TEST SUCCESS: Detached, not streaming, not MIME */
  70490. {
  70491. /* re-populate input BIO, may have been consumed */
  70492. BIO_free(inBio);
  70493. inBio = NULL;
  70494. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70495. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70496. flags = PKCS7_BINARY | PKCS7_DETACHED;
  70497. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70498. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  70499. /* verify with wolfCrypt, d2i_PKCS7 does not support detached content */
  70500. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  70501. if (p7Ver != NULL) {
  70502. p7Ver->content = data;
  70503. p7Ver->contentSz = sizeof(data);
  70504. }
  70505. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  70506. wc_PKCS7_Free(p7Ver);
  70507. p7Ver = NULL;
  70508. #ifndef NO_PKCS7_STREAM
  70509. /* verify with wc_PKCS7_VerifySignedData streaming */
  70510. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  70511. if (p7Ver != NULL) {
  70512. p7Ver->content = data;
  70513. p7Ver->contentSz = sizeof(data);
  70514. }
  70515. /* test for streaming */
  70516. ret = -1;
  70517. for (z = 0; z < outLen && ret != 0; z++) {
  70518. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  70519. if (ret < 0){
  70520. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  70521. }
  70522. }
  70523. ExpectIntEQ(ret, 0);
  70524. wc_PKCS7_Free(p7Ver);
  70525. p7Ver = NULL;
  70526. #endif /* !NO_PKCS7_STREAM */
  70527. /* verify expected failure (NULL return) from d2i_PKCS7, it does not
  70528. * yet support detached content */
  70529. tmpPtr = out;
  70530. ExpectNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  70531. PKCS7_free(p7Ver);
  70532. p7Ver = NULL;
  70533. ExpectNotNull(out);
  70534. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  70535. out = NULL;
  70536. PKCS7_free(p7);
  70537. p7 = NULL;
  70538. }
  70539. /* TEST SUCCESS: Detached, streaming, not MIME */
  70540. {
  70541. /* re-populate input BIO, may have been consumed */
  70542. BIO_free(inBio);
  70543. inBio = NULL;
  70544. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70545. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70546. flags = PKCS7_BINARY | PKCS7_DETACHED | PKCS7_STREAM;
  70547. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70548. ExpectIntEQ(PKCS7_final(p7, inBio, flags), 1);
  70549. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  70550. /* verify with wolfCrypt, d2i_PKCS7 does not support detached content */
  70551. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  70552. if (p7Ver != NULL) {
  70553. p7Ver->content = data;
  70554. p7Ver->contentSz = sizeof(data);
  70555. }
  70556. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  70557. wc_PKCS7_Free(p7Ver);
  70558. p7Ver = NULL;
  70559. ExpectNotNull(out);
  70560. #ifndef NO_PKCS7_STREAM
  70561. /* verify with wc_PKCS7_VerifySignedData streaming */
  70562. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  70563. if (p7Ver != NULL) {
  70564. p7Ver->content = data;
  70565. p7Ver->contentSz = sizeof(data);
  70566. }
  70567. /* test for streaming */
  70568. ret = -1;
  70569. for (z = 0; z < outLen && ret != 0; z++) {
  70570. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  70571. if (ret < 0){
  70572. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  70573. }
  70574. }
  70575. ExpectIntEQ(ret, 0);
  70576. ExpectNotNull(out);
  70577. wc_PKCS7_Free(p7Ver);
  70578. p7Ver = NULL;
  70579. #endif /* !NO_PKCS7_STREAM */
  70580. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  70581. PKCS7_free(p7);
  70582. p7 = NULL;
  70583. }
  70584. X509_STORE_free(store);
  70585. X509_free(caCert);
  70586. X509_free(signCert);
  70587. EVP_PKEY_free(signKey);
  70588. BIO_free(inBio);
  70589. BIO_free(keyBio);
  70590. BIO_free(certBio);
  70591. BIO_free(caBio);
  70592. #endif
  70593. return EXPECT_RESULT();
  70594. }
  70595. static int test_wolfSSL_PKCS7_SIGNED_new(void)
  70596. {
  70597. EXPECT_DECLS;
  70598. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7)
  70599. PKCS7_SIGNED* pkcs7 = NULL;
  70600. ExpectNotNull(pkcs7 = PKCS7_SIGNED_new());
  70601. ExpectIntEQ(pkcs7->contentOID, SIGNED_DATA);
  70602. PKCS7_SIGNED_free(pkcs7);
  70603. #endif
  70604. return EXPECT_RESULT();
  70605. }
  70606. #ifndef NO_BIO
  70607. static int test_wolfSSL_PEM_write_bio_PKCS7(void)
  70608. {
  70609. EXPECT_DECLS;
  70610. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  70611. PKCS7* pkcs7 = NULL;
  70612. BIO* bio = NULL;
  70613. const byte* cert_buf = NULL;
  70614. int ret = 0;
  70615. WC_RNG rng;
  70616. const byte data[] = { /* Hello World */
  70617. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  70618. 0x72,0x6c,0x64
  70619. };
  70620. #ifndef NO_RSA
  70621. #if defined(USE_CERT_BUFFERS_2048)
  70622. byte key[sizeof(client_key_der_2048)];
  70623. byte cert[sizeof(client_cert_der_2048)];
  70624. word32 keySz = (word32)sizeof(key);
  70625. word32 certSz = (word32)sizeof(cert);
  70626. XMEMSET(key, 0, keySz);
  70627. XMEMSET(cert, 0, certSz);
  70628. XMEMCPY(key, client_key_der_2048, keySz);
  70629. XMEMCPY(cert, client_cert_der_2048, certSz);
  70630. #elif defined(USE_CERT_BUFFERS_1024)
  70631. byte key[sizeof_client_key_der_1024];
  70632. byte cert[sizeof(sizeof_client_cert_der_1024)];
  70633. word32 keySz = (word32)sizeof(key);
  70634. word32 certSz = (word32)sizeof(cert);
  70635. XMEMSET(key, 0, keySz);
  70636. XMEMSET(cert, 0, certSz);
  70637. XMEMCPY(key, client_key_der_1024, keySz);
  70638. XMEMCPY(cert, client_cert_der_1024, certSz);
  70639. #else
  70640. unsigned char cert[ONEK_BUF];
  70641. unsigned char key[ONEK_BUF];
  70642. XFILE fp = XBADFILE;
  70643. int certSz;
  70644. int keySz;
  70645. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  70646. XBADFILE);
  70647. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  70648. fp), 0);
  70649. if (fp != XBADFILE) {
  70650. XFCLOSE(fp);
  70651. fp = XBADFILE;
  70652. }
  70653. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  70654. XBADFILE);
  70655. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  70656. 0);
  70657. if (fp != XBADFILE) {
  70658. XFCLOSE(fp);
  70659. fp = XBADFILE;
  70660. }
  70661. #endif
  70662. #elif defined(HAVE_ECC)
  70663. #if defined(USE_CERT_BUFFERS_256)
  70664. unsigned char cert[sizeof(cliecc_cert_der_256)];
  70665. unsigned char key[sizeof(ecc_clikey_der_256)];
  70666. int certSz = (int)sizeof(cert);
  70667. int keySz = (int)sizeof(key);
  70668. XMEMSET(cert, 0, certSz);
  70669. XMEMSET(key, 0, keySz);
  70670. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  70671. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  70672. #else
  70673. unsigned char cert[ONEK_BUF];
  70674. unsigned char key[ONEK_BUF];
  70675. XFILE fp = XBADFILE;
  70676. int certSz, keySz;
  70677. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  70678. XBADFILE);
  70679. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  70680. fp), 0);
  70681. if (fp != XBADFILE) {
  70682. XFCLOSE(fp);
  70683. fp = XBADFILE;
  70684. }
  70685. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  70686. XBADFILE);
  70687. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  70688. 0);
  70689. if (fp != XBADFILE) {
  70690. XFCLOSE(fp);
  70691. fp = XBADFILE;
  70692. }
  70693. #endif
  70694. #else
  70695. #error PKCS7 requires ECC or RSA
  70696. #endif
  70697. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  70698. /* initialize with DER encoded cert */
  70699. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz), 0);
  70700. /* init rng */
  70701. XMEMSET(&rng, 0, sizeof(WC_RNG));
  70702. ExpectIntEQ(wc_InitRng(&rng), 0);
  70703. if (pkcs7 != NULL) {
  70704. pkcs7->rng = &rng;
  70705. pkcs7->content = (byte*)data; /* not used for ex */
  70706. pkcs7->contentSz = (word32)sizeof(data);
  70707. pkcs7->contentOID = SIGNED_DATA;
  70708. pkcs7->privateKey = key;
  70709. pkcs7->privateKeySz = (word32)sizeof(key);
  70710. pkcs7->encryptOID = RSAk;
  70711. #ifdef NO_SHA
  70712. pkcs7->hashOID = SHA256h;
  70713. #else
  70714. pkcs7->hashOID = SHAh;
  70715. #endif
  70716. pkcs7->signedAttribs = NULL;
  70717. pkcs7->signedAttribsSz = 0;
  70718. }
  70719. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  70720. /* Write PKCS#7 PEM to BIO, the function converts the DER to PEM cert*/
  70721. ExpectIntEQ(PEM_write_bio_PKCS7(bio, pkcs7), WOLFSSL_SUCCESS);
  70722. /* Read PKCS#7 PEM from BIO */
  70723. ret = wolfSSL_BIO_get_mem_data(bio, &cert_buf);
  70724. ExpectIntGE(ret, 0);
  70725. BIO_free(bio);
  70726. wc_PKCS7_Free(pkcs7);
  70727. wc_FreeRng(&rng);
  70728. #endif
  70729. return EXPECT_RESULT();
  70730. }
  70731. #ifdef HAVE_SMIME
  70732. /* // NOLINTBEGIN(clang-analyzer-unix.Stream) */
  70733. static int test_wolfSSL_SMIME_read_PKCS7(void)
  70734. {
  70735. EXPECT_DECLS;
  70736. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  70737. !defined(NO_RSA)
  70738. PKCS7* pkcs7 = NULL;
  70739. BIO* bio = NULL;
  70740. BIO* bcont = NULL;
  70741. BIO* out = NULL;
  70742. const byte* outBuf = NULL;
  70743. int outBufLen = 0;
  70744. static const char contTypeText[] = "Content-Type: text/plain\r\n\r\n";
  70745. XFILE smimeTestFile = XBADFILE;
  70746. ExpectTrue((smimeTestFile = XFOPEN("./certs/test/smime-test.p7s", "r")) !=
  70747. XBADFILE);
  70748. /* smime-test.p7s */
  70749. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  70750. ExpectNotNull(bio);
  70751. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  70752. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  70753. ExpectNotNull(pkcs7);
  70754. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  70755. PKCS7_NOVERIFY), SSL_SUCCESS);
  70756. if (smimeTestFile != XBADFILE) {
  70757. XFCLOSE(smimeTestFile);
  70758. smimeTestFile = XBADFILE;
  70759. }
  70760. if (bcont) BIO_free(bcont);
  70761. bcont = NULL;
  70762. wolfSSL_PKCS7_free(pkcs7);
  70763. pkcs7 = NULL;
  70764. /* smime-test-multipart.p7s */
  70765. smimeTestFile = XFOPEN("./certs/test/smime-test-multipart.p7s", "r");
  70766. ExpectFalse(smimeTestFile == XBADFILE);
  70767. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  70768. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  70769. ExpectNotNull(pkcs7);
  70770. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  70771. PKCS7_NOVERIFY), SSL_SUCCESS);
  70772. if (smimeTestFile != XBADFILE) {
  70773. XFCLOSE(smimeTestFile);
  70774. smimeTestFile = XBADFILE;
  70775. }
  70776. if (bcont) BIO_free(bcont);
  70777. bcont = NULL;
  70778. wolfSSL_PKCS7_free(pkcs7);
  70779. pkcs7 = NULL;
  70780. /* smime-test-multipart-badsig.p7s */
  70781. smimeTestFile = XFOPEN("./certs/test/smime-test-multipart-badsig.p7s", "r");
  70782. ExpectFalse(smimeTestFile == XBADFILE);
  70783. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  70784. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  70785. ExpectNotNull(pkcs7); /* can read in the unverified smime bundle */
  70786. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  70787. PKCS7_NOVERIFY), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70788. if (smimeTestFile != XBADFILE) {
  70789. XFCLOSE(smimeTestFile);
  70790. smimeTestFile = XBADFILE;
  70791. }
  70792. if (bcont) BIO_free(bcont);
  70793. bcont = NULL;
  70794. wolfSSL_PKCS7_free(pkcs7);
  70795. pkcs7 = NULL;
  70796. /* smime-test-canon.p7s */
  70797. smimeTestFile = XFOPEN("./certs/test/smime-test-canon.p7s", "r");
  70798. ExpectFalse(smimeTestFile == XBADFILE);
  70799. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  70800. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  70801. ExpectNotNull(pkcs7);
  70802. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  70803. PKCS7_NOVERIFY), SSL_SUCCESS);
  70804. if (smimeTestFile != XBADFILE) {
  70805. XFCLOSE(smimeTestFile);
  70806. smimeTestFile = XBADFILE;
  70807. }
  70808. if (bcont) BIO_free(bcont);
  70809. bcont = NULL;
  70810. wolfSSL_PKCS7_free(pkcs7);
  70811. pkcs7 = NULL;
  70812. /* Test PKCS7_TEXT, PKCS7_verify() should remove Content-Type: text/plain */
  70813. smimeTestFile = XFOPEN("./certs/test/smime-test-canon.p7s", "r");
  70814. ExpectFalse(smimeTestFile == XBADFILE);
  70815. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  70816. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  70817. ExpectNotNull(pkcs7);
  70818. out = wolfSSL_BIO_new(BIO_s_mem());
  70819. ExpectNotNull(out);
  70820. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, out,
  70821. PKCS7_NOVERIFY | PKCS7_TEXT), SSL_SUCCESS);
  70822. ExpectIntGT((outBufLen = BIO_get_mem_data(out, &outBuf)), 0);
  70823. /* Content-Type should not show up at beginning of output buffer */
  70824. ExpectIntGT(outBufLen, XSTRLEN(contTypeText));
  70825. ExpectIntGT(XMEMCMP(outBuf, contTypeText, XSTRLEN(contTypeText)), 0);
  70826. BIO_free(out);
  70827. BIO_free(bio);
  70828. if (bcont) BIO_free(bcont);
  70829. wolfSSL_PKCS7_free(pkcs7);
  70830. #endif
  70831. return EXPECT_RESULT();
  70832. }
  70833. /* // NOLINTEND(clang-analyzer-unix.Stream) */
  70834. static int test_wolfSSL_SMIME_write_PKCS7(void)
  70835. {
  70836. EXPECT_DECLS;
  70837. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_RSA)
  70838. PKCS7* p7 = NULL;
  70839. PKCS7* p7Ver = NULL;
  70840. int flags = 0;
  70841. byte data[] = "Test data to encode.";
  70842. const char* cert = "./certs/server-cert.pem";
  70843. const char* key = "./certs/server-key.pem";
  70844. const char* ca = "./certs/ca-cert.pem";
  70845. WOLFSSL_BIO* certBio = NULL;
  70846. WOLFSSL_BIO* keyBio = NULL;
  70847. WOLFSSL_BIO* caBio = NULL;
  70848. WOLFSSL_BIO* inBio = NULL;
  70849. WOLFSSL_BIO* outBio = NULL;
  70850. WOLFSSL_BIO* content = NULL;
  70851. X509* signCert = NULL;
  70852. EVP_PKEY* signKey = NULL;
  70853. X509* caCert = NULL;
  70854. X509_STORE* store = NULL;
  70855. /* read signer cert/key into BIO */
  70856. ExpectNotNull(certBio = BIO_new_file(cert, "r"));
  70857. ExpectNotNull(keyBio = BIO_new_file(key, "r"));
  70858. ExpectNotNull(signCert = PEM_read_bio_X509(certBio, NULL, 0, NULL));
  70859. ExpectNotNull(signKey = PEM_read_bio_PrivateKey(keyBio, NULL, 0, NULL));
  70860. /* read CA cert into store (for verify) */
  70861. ExpectNotNull(caBio = BIO_new_file(ca, "r"));
  70862. ExpectNotNull(caCert = PEM_read_bio_X509(caBio, NULL, 0, NULL));
  70863. ExpectNotNull(store = X509_STORE_new());
  70864. ExpectIntEQ(X509_STORE_add_cert(store, caCert), 1);
  70865. /* generate and verify SMIME: not detached */
  70866. {
  70867. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70868. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70869. flags = PKCS7_STREAM;
  70870. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70871. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  70872. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  70873. /* bad arg: out NULL */
  70874. ExpectIntEQ(SMIME_write_PKCS7(NULL, p7, inBio, flags), 0);
  70875. /* bad arg: pkcs7 NULL */
  70876. ExpectIntEQ(SMIME_write_PKCS7(outBio, NULL, inBio, flags), 0);
  70877. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  70878. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  70879. BIO_free(content);
  70880. content = NULL;
  70881. BIO_free(inBio);
  70882. inBio = NULL;
  70883. BIO_free(outBio);
  70884. outBio = NULL;
  70885. PKCS7_free(p7Ver);
  70886. p7Ver = NULL;
  70887. PKCS7_free(p7);
  70888. p7 = NULL;
  70889. }
  70890. /* generate and verify SMIME: not detached, add Content-Type */
  70891. {
  70892. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70893. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70894. flags = PKCS7_STREAM | PKCS7_TEXT;
  70895. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70896. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  70897. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  70898. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  70899. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  70900. BIO_free(content);
  70901. content = NULL;
  70902. BIO_free(inBio);
  70903. inBio = NULL;
  70904. BIO_free(outBio);
  70905. outBio = NULL;
  70906. PKCS7_free(p7Ver);
  70907. p7Ver = NULL;
  70908. PKCS7_free(p7);
  70909. p7 = NULL;
  70910. }
  70911. /* generate and verify SMIME: detached */
  70912. {
  70913. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70914. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70915. flags = PKCS7_DETACHED | PKCS7_STREAM;
  70916. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70917. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  70918. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  70919. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  70920. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, content, NULL, flags), 1);
  70921. BIO_free(content);
  70922. content = NULL;
  70923. BIO_free(inBio);
  70924. inBio = NULL;
  70925. BIO_free(outBio);
  70926. outBio = NULL;
  70927. PKCS7_free(p7Ver);
  70928. p7Ver = NULL;
  70929. PKCS7_free(p7);
  70930. p7 = NULL;
  70931. }
  70932. /* generate and verify SMIME: PKCS7_TEXT to add Content-Type header */
  70933. {
  70934. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70935. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70936. flags = PKCS7_STREAM | PKCS7_DETACHED | PKCS7_TEXT;
  70937. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70938. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  70939. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  70940. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  70941. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, content, NULL, flags), 1);
  70942. BIO_free(content);
  70943. content = NULL;
  70944. BIO_free(inBio);
  70945. inBio = NULL;
  70946. BIO_free(outBio);
  70947. outBio = NULL;
  70948. PKCS7_free(p7Ver);
  70949. p7Ver = NULL;
  70950. PKCS7_free(p7);
  70951. p7 = NULL;
  70952. }
  70953. X509_STORE_free(store);
  70954. X509_free(caCert);
  70955. X509_free(signCert);
  70956. EVP_PKEY_free(signKey);
  70957. BIO_free(keyBio);
  70958. BIO_free(certBio);
  70959. BIO_free(caBio);
  70960. #endif
  70961. return EXPECT_RESULT();
  70962. }
  70963. #endif /* HAVE_SMIME */
  70964. #endif /* !NO_BIO */
  70965. /* Test of X509 store use outside of SSL context w/ CRL lookup (ALWAYS
  70966. * returns 0) */
  70967. static int test_X509_STORE_No_SSL_CTX(void)
  70968. {
  70969. EXPECT_DECLS;
  70970. #if defined(OPENSSL_ALL) && defined(WOLFSSL_CERT_GEN) && \
  70971. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && \
  70972. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && \
  70973. (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)) && \
  70974. defined(HAVE_CRL) && !defined(NO_RSA)
  70975. X509_STORE * store = NULL;
  70976. X509_STORE_CTX * storeCtx = NULL;
  70977. X509_CRL * crl = NULL;
  70978. X509 * ca = NULL;
  70979. X509 * cert = NULL;
  70980. const char cliCrlPem[] = "./certs/crl/cliCrl.pem";
  70981. const char srvCert[] = "./certs/server-cert.pem";
  70982. const char caCert[] = "./certs/ca-cert.pem";
  70983. const char caDir[] = "./certs/crl/hash_pem";
  70984. XFILE fp = XBADFILE;
  70985. X509_LOOKUP * lookup = NULL;
  70986. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  70987. /* Set up store with CA */
  70988. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  70989. SSL_FILETYPE_PEM)));
  70990. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  70991. /* Add CRL lookup directory to store
  70992. * NOTE: test uses ./certs/crl/hash_pem/0fdb2da4.r0, which is a copy
  70993. * of crl.pem */
  70994. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  70995. X509_LOOKUP_hash_dir())));
  70996. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, caDir,
  70997. X509_FILETYPE_PEM, NULL), SSL_SUCCESS);
  70998. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  70999. SSL_SUCCESS);
  71000. /* Add CRL to store NOT containing the verified certificate, which
  71001. * forces use of the CRL lookup directory */
  71002. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  71003. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  71004. NULL, NULL));
  71005. if (fp != XBADFILE)
  71006. XFCLOSE(fp);
  71007. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  71008. /* Create verification context outside of an SSL session */
  71009. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  71010. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  71011. SSL_FILETYPE_PEM)));
  71012. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  71013. /* Perform verification, which should NOT indicate CRL missing due to the
  71014. * store CM's X509 store pointer being NULL */
  71015. ExpectIntNE(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(CRL_MISSING));
  71016. X509_CRL_free(crl);
  71017. X509_STORE_free(store);
  71018. X509_STORE_CTX_free(storeCtx);
  71019. X509_free(cert);
  71020. X509_free(ca);
  71021. #endif
  71022. return EXPECT_RESULT();
  71023. }
  71024. /* Test of X509 store use outside of SSL context w/ CRL lookup, but
  71025. * with X509_LOOKUP_add_dir and X509_FILETYPE_ASN1. */
  71026. static int test_X509_LOOKUP_add_dir(void)
  71027. {
  71028. EXPECT_DECLS;
  71029. #if defined(OPENSSL_ALL) && defined(WOLFSSL_CERT_GEN) && \
  71030. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && \
  71031. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && \
  71032. (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)) && \
  71033. defined(HAVE_CRL) && !defined(NO_RSA)
  71034. X509_STORE * store = NULL;
  71035. X509_STORE_CTX * storeCtx = NULL;
  71036. X509_CRL * crl = NULL;
  71037. X509 * ca = NULL;
  71038. X509 * cert = NULL;
  71039. const char cliCrlPem[] = "./certs/crl/cliCrl.pem";
  71040. const char srvCert[] = "./certs/server-cert.pem";
  71041. const char caCert[] = "./certs/ca-cert.pem";
  71042. const char caDir[] = "./certs/crl/hash_der";
  71043. XFILE fp = XBADFILE;
  71044. X509_LOOKUP * lookup = NULL;
  71045. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  71046. /* Set up store with CA */
  71047. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  71048. SSL_FILETYPE_PEM)));
  71049. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  71050. /* Add CRL lookup directory to store.
  71051. * Test uses ./certs/crl/hash_der/0fdb2da4.r0, which is a copy
  71052. * of crl.der */
  71053. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  71054. X509_LOOKUP_hash_dir())));
  71055. ExpectIntEQ(X509_LOOKUP_add_dir(lookup, caDir, X509_FILETYPE_ASN1),
  71056. SSL_SUCCESS);
  71057. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  71058. SSL_SUCCESS);
  71059. /* Add CRL to store NOT containing the verified certificate, which
  71060. * forces use of the CRL lookup directory */
  71061. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  71062. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  71063. NULL, NULL));
  71064. if (fp != XBADFILE) {
  71065. XFCLOSE(fp);
  71066. fp = XBADFILE;
  71067. }
  71068. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  71069. /* Create verification context outside of an SSL session */
  71070. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  71071. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  71072. SSL_FILETYPE_PEM)));
  71073. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  71074. /* Perform verification, which should NOT return CRL missing */
  71075. ExpectIntNE(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(CRL_MISSING));
  71076. X509_CRL_free(crl);
  71077. crl = NULL;
  71078. X509_STORE_free(store);
  71079. store = NULL;
  71080. X509_STORE_CTX_free(storeCtx);
  71081. storeCtx = NULL;
  71082. X509_free(cert);
  71083. cert = NULL;
  71084. X509_free(ca);
  71085. ca = NULL;
  71086. /* Now repeat the same, but look for X509_FILETYPE_PEM.
  71087. * We should get CRL_MISSING at the end, because the lookup
  71088. * dir has only ASN1 CRLs. */
  71089. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  71090. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  71091. SSL_FILETYPE_PEM)));
  71092. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  71093. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  71094. X509_LOOKUP_hash_dir())));
  71095. ExpectIntEQ(X509_LOOKUP_add_dir(lookup, caDir, X509_FILETYPE_PEM),
  71096. SSL_SUCCESS);
  71097. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  71098. SSL_SUCCESS);
  71099. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  71100. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  71101. NULL, NULL));
  71102. if (fp != XBADFILE) {
  71103. XFCLOSE(fp);
  71104. fp = XBADFILE;
  71105. }
  71106. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  71107. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  71108. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  71109. SSL_FILETYPE_PEM)));
  71110. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  71111. /* Now we SHOULD get CRL_MISSING, because we looked for PEM
  71112. * in dir containing only ASN1/DER. */
  71113. ExpectIntEQ(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71114. ExpectIntEQ(X509_STORE_CTX_get_error(storeCtx),
  71115. X509_V_ERR_UNABLE_TO_GET_CRL);
  71116. X509_CRL_free(crl);
  71117. X509_STORE_free(store);
  71118. X509_STORE_CTX_free(storeCtx);
  71119. X509_free(cert);
  71120. X509_free(ca);
  71121. #endif
  71122. return EXPECT_RESULT();
  71123. }
  71124. /*----------------------------------------------------------------------------*
  71125. | Certificate Failure Checks
  71126. *----------------------------------------------------------------------------*/
  71127. #if !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \
  71128. !defined(WOLFSSL_NO_CLIENT_AUTH)) && !defined(NO_FILESYSTEM)
  71129. #if !defined(NO_RSA) || defined(HAVE_ECC)
  71130. /* Use the Cert Manager(CM) API to generate the error ASN_SIG_CONFIRM_E */
  71131. static int verify_sig_cm(const char* ca, byte* cert_buf, size_t cert_sz,
  71132. int type)
  71133. {
  71134. int ret;
  71135. WOLFSSL_CERT_MANAGER* cm = NULL;
  71136. switch (type) {
  71137. case TESTING_RSA:
  71138. #ifdef NO_RSA
  71139. fprintf(stderr, "RSA disabled, skipping test\n");
  71140. return ASN_SIG_CONFIRM_E;
  71141. #else
  71142. break;
  71143. #endif
  71144. case TESTING_ECC:
  71145. #ifndef HAVE_ECC
  71146. fprintf(stderr, "ECC disabled, skipping test\n");
  71147. return ASN_SIG_CONFIRM_E;
  71148. #else
  71149. break;
  71150. #endif
  71151. default:
  71152. fprintf(stderr, "Bad function argument\n");
  71153. return BAD_FUNC_ARG;
  71154. }
  71155. cm = wolfSSL_CertManagerNew();
  71156. if (cm == NULL) {
  71157. fprintf(stderr, "wolfSSL_CertManagerNew failed\n");
  71158. return -1;
  71159. }
  71160. #ifndef NO_FILESYSTEM
  71161. ret = wolfSSL_CertManagerLoadCA(cm, ca, 0);
  71162. if (ret != WOLFSSL_SUCCESS) {
  71163. fprintf(stderr, "wolfSSL_CertManagerLoadCA failed\n");
  71164. wolfSSL_CertManagerFree(cm);
  71165. return ret;
  71166. }
  71167. #else
  71168. (void)ca;
  71169. #endif
  71170. ret = wolfSSL_CertManagerVerifyBuffer(cm, cert_buf, (long int)cert_sz,
  71171. WOLFSSL_FILETYPE_ASN1);
  71172. /* Let ExpectIntEQ handle return code */
  71173. wolfSSL_CertManagerFree(cm);
  71174. return ret;
  71175. }
  71176. #endif
  71177. #if !defined(NO_FILESYSTEM)
  71178. static int test_RsaSigFailure_cm(void)
  71179. {
  71180. EXPECT_DECLS;
  71181. #ifndef NO_RSA
  71182. const char* ca_cert = "./certs/ca-cert.pem";
  71183. const char* server_cert = "./certs/server-cert.der";
  71184. byte* cert_buf = NULL;
  71185. size_t cert_sz = 0;
  71186. ExpectIntEQ(load_file(server_cert, &cert_buf, &cert_sz), 0);
  71187. if ((cert_buf != NULL) && (cert_sz > 0)) {
  71188. /* corrupt DER - invert last byte, which is signature */
  71189. cert_buf[cert_sz-1] = ~cert_buf[cert_sz-1];
  71190. /* test bad cert */
  71191. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  71192. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  71193. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  71194. #elif defined(NO_ASN_CRYPT)
  71195. /* RSA verify is not called when ASN crypt support is disabled */
  71196. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  71197. WOLFSSL_SUCCESS);
  71198. #else
  71199. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  71200. WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E));
  71201. #endif
  71202. }
  71203. /* load_file() uses malloc. */
  71204. if (cert_buf != NULL) {
  71205. free(cert_buf);
  71206. }
  71207. #endif /* !NO_RSA */
  71208. return EXPECT_RESULT();
  71209. }
  71210. static int test_EccSigFailure_cm(void)
  71211. {
  71212. EXPECT_DECLS;
  71213. #ifdef HAVE_ECC
  71214. /* self-signed ECC cert, so use server cert as CA */
  71215. const char* ca_cert = "./certs/ca-ecc-cert.pem";
  71216. const char* server_cert = "./certs/server-ecc.der";
  71217. byte* cert_buf = NULL;
  71218. size_t cert_sz = 0;
  71219. ExpectIntEQ(load_file(server_cert, &cert_buf, &cert_sz), 0);
  71220. if (cert_buf != NULL && cert_sz > 0) {
  71221. /* corrupt DER - invert last byte, which is signature */
  71222. cert_buf[cert_sz-1] = ~cert_buf[cert_sz-1];
  71223. /* test bad cert */
  71224. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  71225. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  71226. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  71227. #elif defined(NO_ASN_CRYPT)
  71228. /* ECC verify is not called when ASN crypt support is disabled */
  71229. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  71230. WOLFSSL_SUCCESS);
  71231. #else
  71232. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  71233. WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E));
  71234. #endif
  71235. }
  71236. /* load_file() uses malloc. */
  71237. if (cert_buf != NULL) {
  71238. free(cert_buf);
  71239. }
  71240. #ifdef FP_ECC
  71241. wc_ecc_fp_free();
  71242. #endif
  71243. #endif /* HAVE_ECC */
  71244. return EXPECT_RESULT();
  71245. }
  71246. #endif /* !NO_FILESYSTEM */
  71247. #endif /* NO_CERTS */
  71248. #ifdef WOLFSSL_TLS13
  71249. #if defined(WOLFSSL_SEND_HRR_COOKIE) && !defined(NO_WOLFSSL_SERVER)
  71250. #ifdef WC_SHA384_DIGEST_SIZE
  71251. static byte fixedKey[WC_SHA384_DIGEST_SIZE] = { 0, };
  71252. #else
  71253. static byte fixedKey[WC_SHA256_DIGEST_SIZE] = { 0, };
  71254. #endif
  71255. #endif
  71256. #ifdef WOLFSSL_EARLY_DATA
  71257. static const char earlyData[] = "Early Data";
  71258. static char earlyDataBuffer[1];
  71259. #endif
  71260. static int test_tls13_apis(void)
  71261. {
  71262. EXPECT_DECLS;
  71263. int ret;
  71264. #ifndef WOLFSSL_NO_TLS12
  71265. #ifndef NO_WOLFSSL_CLIENT
  71266. WOLFSSL_CTX* clientTls12Ctx = NULL;
  71267. WOLFSSL* clientTls12Ssl = NULL;
  71268. #endif
  71269. #ifndef NO_WOLFSSL_SERVER
  71270. WOLFSSL_CTX* serverTls12Ctx = NULL;
  71271. WOLFSSL* serverTls12Ssl = NULL;
  71272. #endif
  71273. #endif
  71274. #ifndef NO_WOLFSSL_CLIENT
  71275. WOLFSSL_CTX* clientCtx = NULL;
  71276. WOLFSSL* clientSsl = NULL;
  71277. #endif
  71278. #ifndef NO_WOLFSSL_SERVER
  71279. WOLFSSL_CTX* serverCtx = NULL;
  71280. WOLFSSL* serverSsl = NULL;
  71281. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  71282. const char* ourCert = svrCertFile;
  71283. const char* ourKey = svrKeyFile;
  71284. #endif
  71285. #endif
  71286. int required;
  71287. #ifdef WOLFSSL_EARLY_DATA
  71288. int outSz;
  71289. #endif
  71290. #if defined(HAVE_ECC) && defined(HAVE_SUPPORTED_CURVES)
  71291. int groups[2] = { WOLFSSL_ECC_SECP256R1,
  71292. #ifdef WOLFSSL_HAVE_KYBER
  71293. #ifndef WOLFSSL_NO_KYBER512
  71294. WOLFSSL_KYBER_LEVEL1
  71295. #elif !defined(WOLFSSL_NO_KYBER768)
  71296. WOLFSSL_KYBER_LEVEL3
  71297. #else
  71298. WOLFSSL_KYBER_LEVEL5
  71299. #endif
  71300. #else
  71301. WOLFSSL_ECC_SECP256R1
  71302. #endif
  71303. };
  71304. #if !defined(NO_WOLFSSL_SERVER) || !defined(NO_WOLFSSL_CLIENT)
  71305. int bad_groups[2] = { 0xDEAD, 0xBEEF };
  71306. #endif /* !NO_WOLFSSL_SERVER || !NO_WOLFSSL_CLIENT */
  71307. int numGroups = 2;
  71308. #endif
  71309. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  71310. char groupList[] =
  71311. #ifdef HAVE_CURVE25519
  71312. "X25519:"
  71313. #endif
  71314. #ifdef HAVE_CURVE448
  71315. "X448:"
  71316. #endif
  71317. #ifndef NO_ECC_SECP
  71318. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  71319. "P-521:secp521r1:"
  71320. #endif
  71321. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  71322. "P-384:secp384r1:"
  71323. #endif
  71324. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  71325. "P-256:secp256r1"
  71326. #if defined(WOLFSSL_HAVE_KYBER)
  71327. #ifndef WOLFSSL_NO_KYBER512
  71328. ":P256_KYBER_LEVEL1"
  71329. #elif !defined(WOLFSSL_NO_KYBER768)
  71330. ":P256_KYBER_LEVEL3"
  71331. #else
  71332. ":P256_KYBER_LEVEL5"
  71333. #endif
  71334. #endif
  71335. #endif
  71336. #endif /* !defined(NO_ECC_SECP) */
  71337. #if defined(WOLFSSL_HAVE_KYBER)
  71338. #ifndef WOLFSSL_NO_KYBER512
  71339. ":KYBER_LEVEL1"
  71340. #elif !defined(WOLFSSL_NO_KYBER768)
  71341. ":KYBER_LEVEL3"
  71342. #else
  71343. ":KYBER_LEVEL5"
  71344. #endif
  71345. #endif
  71346. "";
  71347. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_ECC) */
  71348. #if defined(WOLFSSL_HAVE_KYBER)
  71349. int kyberLevel;
  71350. #endif
  71351. (void)ret;
  71352. #ifndef WOLFSSL_NO_TLS12
  71353. #ifndef NO_WOLFSSL_CLIENT
  71354. clientTls12Ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
  71355. clientTls12Ssl = wolfSSL_new(clientTls12Ctx);
  71356. #endif
  71357. #ifndef NO_WOLFSSL_SERVER
  71358. serverTls12Ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method());
  71359. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  71360. wolfSSL_CTX_use_certificate_chain_file(serverTls12Ctx, ourCert);
  71361. wolfSSL_CTX_use_PrivateKey_file(serverTls12Ctx, ourKey,
  71362. WOLFSSL_FILETYPE_PEM);
  71363. #endif
  71364. serverTls12Ssl = wolfSSL_new(serverTls12Ctx);
  71365. #endif
  71366. #endif
  71367. #ifndef NO_WOLFSSL_CLIENT
  71368. clientCtx = wolfSSL_CTX_new(wolfTLSv1_3_client_method());
  71369. clientSsl = wolfSSL_new(clientCtx);
  71370. #endif
  71371. #ifndef NO_WOLFSSL_SERVER
  71372. serverCtx = wolfSSL_CTX_new(wolfTLSv1_3_server_method());
  71373. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  71374. wolfSSL_CTX_use_certificate_chain_file(serverCtx, ourCert);
  71375. wolfSSL_CTX_use_PrivateKey_file(serverCtx, ourKey, WOLFSSL_FILETYPE_PEM);
  71376. #endif
  71377. serverSsl = wolfSSL_new(serverCtx);
  71378. ExpectNotNull(serverSsl);
  71379. #endif
  71380. #ifdef WOLFSSL_SEND_HRR_COOKIE
  71381. ExpectIntEQ(wolfSSL_send_hrr_cookie(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71382. #ifndef NO_WOLFSSL_CLIENT
  71383. ExpectIntEQ(wolfSSL_send_hrr_cookie(clientSsl, NULL, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  71384. #endif
  71385. #ifndef NO_WOLFSSL_SERVER
  71386. #ifndef WOLFSSL_NO_TLS12
  71387. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverTls12Ssl, NULL, 0),
  71388. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71389. #endif
  71390. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverSsl, NULL, 0), WOLFSSL_SUCCESS);
  71391. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverSsl, fixedKey, sizeof(fixedKey)),
  71392. WOLFSSL_SUCCESS);
  71393. #endif
  71394. #endif
  71395. #ifdef HAVE_SUPPORTED_CURVES
  71396. #ifdef HAVE_ECC
  71397. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_SECP256R1),
  71398. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71399. #ifndef NO_WOLFSSL_SERVER
  71400. do {
  71401. ret = wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_SECP256R1);
  71402. #ifdef WOLFSSL_ASYNC_CRYPT
  71403. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  71404. wolfSSL_AsyncPoll(serverSsl, WOLF_POLL_FLAG_CHECK_HW);
  71405. #endif
  71406. }
  71407. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  71408. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  71409. #endif
  71410. #ifndef NO_WOLFSSL_CLIENT
  71411. #ifndef WOLFSSL_NO_TLS12
  71412. do {
  71413. ret = wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_SECP256R1);
  71414. #ifdef WOLFSSL_ASYNC_CRYPT
  71415. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  71416. wolfSSL_AsyncPoll(clientTls12Ssl, WOLF_POLL_FLAG_CHECK_HW);
  71417. #endif
  71418. }
  71419. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  71420. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  71421. #endif
  71422. do {
  71423. ret = wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_SECP256R1);
  71424. #ifdef WOLFSSL_ASYNC_CRYPT
  71425. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  71426. wolfSSL_AsyncPoll(clientSsl, WOLF_POLL_FLAG_CHECK_HW);
  71427. #endif
  71428. }
  71429. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  71430. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  71431. #endif
  71432. #elif defined(HAVE_CURVE25519)
  71433. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_X25519), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71434. #ifndef NO_WOLFSSL_SERVER
  71435. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_X25519),
  71436. WOLFSSL_SUCCESS);
  71437. #endif
  71438. #ifndef NO_WOLFSSL_CLIENT
  71439. #ifndef WOLFSSL_NO_TLS12
  71440. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_X25519),
  71441. WOLFSSL_SUCCESS);
  71442. #endif
  71443. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_X25519),
  71444. WOLFSSL_SUCCESS);
  71445. #endif
  71446. #elif defined(HAVE_CURVE448)
  71447. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_X448), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71448. #ifndef NO_WOLFSSL_SERVER
  71449. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_X448),
  71450. WOLFSSL_SUCCESS);
  71451. #endif
  71452. #ifndef NO_WOLFSSL_CLIENT
  71453. #ifndef WOLFSSL_NO_TLS12
  71454. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_X448),
  71455. WOLFSSL_SUCCESS);
  71456. #endif
  71457. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_X448),
  71458. WOLFSSL_SUCCESS);
  71459. #endif
  71460. #else
  71461. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_SECP256R1),
  71462. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71463. #ifndef NO_WOLFSSL_CLIENT
  71464. #ifndef WOLFSSL_NO_TLS12
  71465. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_SECP256R1),
  71466. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  71467. #endif
  71468. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_SECP256R1),
  71469. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  71470. #endif
  71471. #endif
  71472. #if defined(WOLFSSL_HAVE_KYBER)
  71473. #ifndef WOLFSSL_NO_KYBER768
  71474. kyberLevel = WOLFSSL_KYBER_LEVEL3;
  71475. #elif !defined(WOLFSSL_NO_KYBER1024)
  71476. kyberLevel = WOLFSSL_KYBER_LEVEL5;
  71477. #else
  71478. kyberLevel = WOLFSSL_KYBER_LEVEL1;
  71479. #endif
  71480. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, kyberLevel), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71481. #ifndef NO_WOLFSSL_SERVER
  71482. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, kyberLevel),
  71483. WOLFSSL_SUCCESS);
  71484. #endif
  71485. #ifndef NO_WOLFSSL_CLIENT
  71486. #ifndef WOLFSSL_NO_TLS12
  71487. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, kyberLevel),
  71488. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71489. #endif
  71490. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, kyberLevel),
  71491. WOLFSSL_SUCCESS);
  71492. #endif
  71493. #endif
  71494. ExpectIntEQ(wolfSSL_NoKeyShares(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71495. #ifndef NO_WOLFSSL_SERVER
  71496. ExpectIntEQ(wolfSSL_NoKeyShares(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  71497. #endif
  71498. #ifndef NO_WOLFSSL_CLIENT
  71499. #ifndef WOLFSSL_NO_TLS12
  71500. ExpectIntEQ(wolfSSL_NoKeyShares(clientTls12Ssl), WOLFSSL_SUCCESS);
  71501. #endif
  71502. ExpectIntEQ(wolfSSL_NoKeyShares(clientSsl), WOLFSSL_SUCCESS);
  71503. #endif
  71504. #endif /* HAVE_SUPPORTED_CURVES */
  71505. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71506. #ifndef NO_WOLFSSL_CLIENT
  71507. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  71508. #endif
  71509. #ifndef NO_WOLFSSL_SERVER
  71510. #ifndef WOLFSSL_NO_TLS12
  71511. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71512. #endif
  71513. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(serverCtx), 0);
  71514. #endif
  71515. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71516. #ifndef NO_WOLFSSL_CLIENT
  71517. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(clientSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  71518. #endif
  71519. #ifndef NO_WOLFSSL_SERVER
  71520. #ifndef WOLFSSL_NO_TLS12
  71521. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71522. #endif
  71523. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(serverSsl), 0);
  71524. #endif
  71525. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71526. #ifndef NO_WOLFSSL_CLIENT
  71527. #ifndef WOLFSSL_NO_TLS12
  71528. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(clientTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71529. #endif
  71530. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(clientCtx), 0);
  71531. #endif
  71532. #ifndef NO_WOLFSSL_SERVER
  71533. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(serverCtx), 0);
  71534. #endif
  71535. ExpectIntEQ(wolfSSL_no_dhe_psk(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71536. #ifndef NO_WOLFSSL_CLIENT
  71537. #ifndef WOLFSSL_NO_TLS12
  71538. ExpectIntEQ(wolfSSL_no_dhe_psk(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71539. #endif
  71540. ExpectIntEQ(wolfSSL_no_dhe_psk(clientSsl), 0);
  71541. #endif
  71542. #ifndef NO_WOLFSSL_SERVER
  71543. ExpectIntEQ(wolfSSL_no_dhe_psk(serverSsl), 0);
  71544. #endif
  71545. ExpectIntEQ(wolfSSL_update_keys(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71546. #ifndef NO_WOLFSSL_CLIENT
  71547. #ifndef WOLFSSL_NO_TLS12
  71548. ExpectIntEQ(wolfSSL_update_keys(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71549. #endif
  71550. ExpectIntEQ(wolfSSL_update_keys(clientSsl), WC_NO_ERR_TRACE(BUILD_MSG_ERROR));
  71551. #endif
  71552. #ifndef NO_WOLFSSL_SERVER
  71553. ExpectIntEQ(wolfSSL_update_keys(serverSsl), WC_NO_ERR_TRACE(BUILD_MSG_ERROR));
  71554. #endif
  71555. ExpectIntEQ(wolfSSL_key_update_response(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71556. ExpectIntEQ(wolfSSL_key_update_response(NULL, &required), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71557. #ifndef NO_WOLFSSL_CLIENT
  71558. #ifndef WOLFSSL_NO_TLS12
  71559. ExpectIntEQ(wolfSSL_key_update_response(clientTls12Ssl, &required),
  71560. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71561. #endif
  71562. ExpectIntEQ(wolfSSL_key_update_response(clientSsl, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71563. #endif
  71564. #ifndef NO_WOLFSSL_SERVER
  71565. ExpectIntEQ(wolfSSL_key_update_response(serverSsl, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71566. #endif
  71567. #if !defined(NO_CERTS) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  71568. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71569. #ifndef NO_WOLFSSL_SERVER
  71570. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(serverCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  71571. #endif
  71572. #ifndef NO_WOLFSSL_CLIENT
  71573. #ifndef WOLFSSL_NO_TLS12
  71574. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(clientTls12Ctx),
  71575. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71576. #endif
  71577. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(clientCtx), 0);
  71578. #endif
  71579. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71580. #ifndef NO_WOLFSSL_SERVER
  71581. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  71582. #endif
  71583. #ifndef NO_WOLFSSL_CLIENT
  71584. #ifndef WOLFSSL_NO_TLS12
  71585. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(clientTls12Ssl),
  71586. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71587. #endif
  71588. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(clientSsl), 0);
  71589. #endif
  71590. ExpectIntEQ(wolfSSL_request_certificate(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71591. #ifndef NO_WOLFSSL_CLIENT
  71592. ExpectIntEQ(wolfSSL_request_certificate(clientSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  71593. #endif
  71594. #ifndef NO_WOLFSSL_SERVER
  71595. #ifndef WOLFSSL_NO_TLS12
  71596. ExpectIntEQ(wolfSSL_request_certificate(serverTls12Ssl),
  71597. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71598. #endif
  71599. ExpectIntEQ(wolfSSL_request_certificate(serverSsl), WC_NO_ERR_TRACE(NOT_READY_ERROR));
  71600. #endif
  71601. #endif
  71602. #ifdef HAVE_ECC
  71603. #ifndef WOLFSSL_NO_SERVER_GROUPS_EXT
  71604. ExpectIntEQ(wolfSSL_preferred_group(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71605. #ifndef NO_WOLFSSL_SERVER
  71606. ExpectIntEQ(wolfSSL_preferred_group(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  71607. #endif
  71608. #ifndef NO_WOLFSSL_CLIENT
  71609. #ifndef WOLFSSL_NO_TLS12
  71610. ExpectIntEQ(wolfSSL_preferred_group(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71611. #endif
  71612. ExpectIntEQ(wolfSSL_preferred_group(clientSsl), WC_NO_ERR_TRACE(NOT_READY_ERROR));
  71613. #endif
  71614. #endif
  71615. #ifdef HAVE_SUPPORTED_CURVES
  71616. ExpectIntEQ(wolfSSL_CTX_set_groups(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71617. #ifndef NO_WOLFSSL_CLIENT
  71618. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71619. #endif
  71620. ExpectIntEQ(wolfSSL_CTX_set_groups(NULL, groups, numGroups), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71621. #ifndef NO_WOLFSSL_CLIENT
  71622. #ifndef WOLFSSL_NO_TLS12
  71623. ExpectIntEQ(wolfSSL_CTX_set_groups(clientTls12Ctx, groups, numGroups),
  71624. WOLFSSL_SUCCESS);
  71625. #endif
  71626. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, groups,
  71627. WOLFSSL_MAX_GROUP_COUNT + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71628. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, groups, numGroups),
  71629. WOLFSSL_SUCCESS);
  71630. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, bad_groups, numGroups),
  71631. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71632. #endif
  71633. #ifndef NO_WOLFSSL_SERVER
  71634. ExpectIntEQ(wolfSSL_CTX_set_groups(serverCtx, groups, numGroups),
  71635. WOLFSSL_SUCCESS);
  71636. ExpectIntEQ(wolfSSL_CTX_set_groups(serverCtx, bad_groups, numGroups),
  71637. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71638. #endif
  71639. ExpectIntEQ(wolfSSL_set_groups(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71640. #ifndef NO_WOLFSSL_CLIENT
  71641. ExpectIntEQ(wolfSSL_set_groups(clientSsl, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71642. #endif
  71643. ExpectIntEQ(wolfSSL_set_groups(NULL, groups, numGroups), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71644. #ifndef NO_WOLFSSL_CLIENT
  71645. #ifndef WOLFSSL_NO_TLS12
  71646. ExpectIntEQ(wolfSSL_set_groups(clientTls12Ssl, groups, numGroups),
  71647. WOLFSSL_SUCCESS);
  71648. #endif
  71649. ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups,
  71650. WOLFSSL_MAX_GROUP_COUNT + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71651. ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups, numGroups),
  71652. WOLFSSL_SUCCESS);
  71653. ExpectIntEQ(wolfSSL_set_groups(clientSsl, bad_groups, numGroups),
  71654. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71655. #endif
  71656. #ifndef NO_WOLFSSL_SERVER
  71657. ExpectIntEQ(wolfSSL_set_groups(serverSsl, groups, numGroups),
  71658. WOLFSSL_SUCCESS);
  71659. ExpectIntEQ(wolfSSL_set_groups(serverSsl, bad_groups, numGroups),
  71660. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71661. #endif
  71662. #ifdef OPENSSL_EXTRA
  71663. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71664. #ifndef NO_WOLFSSL_CLIENT
  71665. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientCtx, NULL),
  71666. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71667. #endif
  71668. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(NULL, groupList),
  71669. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71670. #ifndef NO_WOLFSSL_CLIENT
  71671. #ifndef WOLFSSL_NO_TLS12
  71672. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientTls12Ctx, groupList),
  71673. WOLFSSL_SUCCESS);
  71674. #endif
  71675. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientCtx, groupList),
  71676. WOLFSSL_SUCCESS);
  71677. #endif
  71678. #ifndef NO_WOLFSSL_SERVER
  71679. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(serverCtx, groupList),
  71680. WOLFSSL_SUCCESS);
  71681. #endif
  71682. ExpectIntEQ(wolfSSL_set1_groups_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71683. #ifndef NO_WOLFSSL_CLIENT
  71684. ExpectIntEQ(wolfSSL_set1_groups_list(clientSsl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71685. #endif
  71686. ExpectIntEQ(wolfSSL_set1_groups_list(NULL, groupList), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71687. #ifndef NO_WOLFSSL_CLIENT
  71688. #ifndef WOLFSSL_NO_TLS12
  71689. ExpectIntEQ(wolfSSL_set1_groups_list(clientTls12Ssl, groupList),
  71690. WOLFSSL_SUCCESS);
  71691. #endif
  71692. ExpectIntEQ(wolfSSL_set1_groups_list(clientSsl, groupList),
  71693. WOLFSSL_SUCCESS);
  71694. #endif
  71695. #ifndef NO_WOLFSSL_SERVER
  71696. ExpectIntEQ(wolfSSL_set1_groups_list(serverSsl, groupList),
  71697. WOLFSSL_SUCCESS);
  71698. #endif
  71699. #endif /* OPENSSL_EXTRA */
  71700. #endif /* HAVE_SUPPORTED_CURVES */
  71701. #endif /* HAVE_ECC */
  71702. #ifdef WOLFSSL_EARLY_DATA
  71703. #ifndef OPENSSL_EXTRA
  71704. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71705. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71706. #else
  71707. ExpectIntEQ(SSL_CTX_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71708. ExpectIntEQ(SSL_CTX_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71709. #endif
  71710. #ifndef NO_WOLFSSL_CLIENT
  71711. #ifndef OPENSSL_EXTRA
  71712. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(clientCtx, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  71713. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  71714. #else
  71715. ExpectIntEQ(SSL_CTX_set_max_early_data(clientCtx, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  71716. ExpectIntEQ(SSL_CTX_get_max_early_data(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  71717. #endif
  71718. #endif
  71719. #ifndef NO_WOLFSSL_SERVER
  71720. #ifndef WOLFSSL_NO_TLS12
  71721. #ifndef OPENSSL_EXTRA
  71722. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverTls12Ctx, 0),
  71723. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71724. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71725. #else
  71726. ExpectIntEQ(SSL_CTX_set_max_early_data(serverTls12Ctx, 0),
  71727. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71728. ExpectIntEQ(SSL_CTX_get_max_early_data(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71729. #endif
  71730. #endif
  71731. #ifndef OPENSSL_EXTRA
  71732. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  71733. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverCtx, 32),
  71734. WOLFSSL_SUCCESS);
  71735. #else
  71736. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverCtx, 32), 0);
  71737. #endif
  71738. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(serverCtx), 32);
  71739. #else
  71740. ExpectIntEQ(SSL_CTX_set_max_early_data(serverCtx, 32), 1);
  71741. ExpectIntEQ(SSL_CTX_get_max_early_data(serverCtx), 32);
  71742. #endif
  71743. #endif
  71744. #ifndef OPENSSL_EXTRA
  71745. ExpectIntEQ(wolfSSL_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71746. ExpectIntEQ(wolfSSL_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71747. #else
  71748. ExpectIntEQ(SSL_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71749. ExpectIntEQ(SSL_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71750. #endif
  71751. #ifndef NO_WOLFSSL_CLIENT
  71752. #ifndef OPENSSL_EXTRA
  71753. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  71754. ExpectIntEQ(wolfSSL_set_max_early_data(clientSsl, 17), WOLFSSL_SUCCESS);
  71755. #else
  71756. ExpectIntEQ(wolfSSL_set_max_early_data(clientSsl, 17), 0);
  71757. #endif
  71758. ExpectIntEQ(wolfSSL_get_max_early_data(clientSsl), 17);
  71759. #else
  71760. ExpectIntEQ(SSL_set_max_early_data(clientSsl, 17), WOLFSSL_SUCCESS);
  71761. ExpectIntEQ(SSL_get_max_early_data(clientSsl), 17);
  71762. #endif
  71763. #endif
  71764. #ifndef NO_WOLFSSL_SERVER
  71765. #ifndef WOLFSSL_NO_TLS12
  71766. #ifndef OPENSSL_EXTRA
  71767. ExpectIntEQ(wolfSSL_set_max_early_data(serverTls12Ssl, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71768. ExpectIntEQ(wolfSSL_get_max_early_data(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71769. #else
  71770. ExpectIntEQ(SSL_set_max_early_data(serverTls12Ssl, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71771. ExpectIntEQ(SSL_get_max_early_data(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71772. #endif
  71773. #endif
  71774. #ifndef OPENSSL_EXTRA
  71775. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  71776. ExpectIntEQ(wolfSSL_set_max_early_data(serverSsl, 16), WOLFSSL_SUCCESS);
  71777. #else
  71778. ExpectIntEQ(wolfSSL_set_max_early_data(serverSsl, 16), 0);
  71779. #endif
  71780. ExpectIntEQ(wolfSSL_get_max_early_data(serverSsl), 16);
  71781. #else
  71782. ExpectIntEQ(SSL_set_max_early_data(serverSsl, 16), 1);
  71783. ExpectIntEQ(SSL_get_max_early_data(serverSsl), 16);
  71784. #endif
  71785. #endif
  71786. ExpectIntEQ(wolfSSL_write_early_data(NULL, earlyData, sizeof(earlyData),
  71787. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71788. #ifndef NO_WOLFSSL_CLIENT
  71789. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, NULL, sizeof(earlyData),
  71790. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71791. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData, -1, &outSz),
  71792. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71793. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData,
  71794. sizeof(earlyData), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71795. #endif
  71796. #ifndef NO_WOLFSSL_SERVER
  71797. ExpectIntEQ(wolfSSL_write_early_data(serverSsl, earlyData,
  71798. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(SIDE_ERROR));
  71799. #endif
  71800. #ifndef NO_WOLFSSL_CLIENT
  71801. #ifndef WOLFSSL_NO_TLS12
  71802. ExpectIntEQ(wolfSSL_write_early_data(clientTls12Ssl, earlyData,
  71803. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71804. #endif
  71805. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData,
  71806. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  71807. #endif
  71808. ExpectIntEQ(wolfSSL_read_early_data(NULL, earlyDataBuffer,
  71809. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71810. #ifndef NO_WOLFSSL_SERVER
  71811. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, NULL,
  71812. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71813. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer, -1,
  71814. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71815. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer,
  71816. sizeof(earlyDataBuffer), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71817. #endif
  71818. #ifndef NO_WOLFSSL_CLIENT
  71819. ExpectIntEQ(wolfSSL_read_early_data(clientSsl, earlyDataBuffer,
  71820. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(SIDE_ERROR));
  71821. #endif
  71822. #ifndef NO_WOLFSSL_SERVER
  71823. #ifndef WOLFSSL_NO_TLS12
  71824. ExpectIntEQ(wolfSSL_read_early_data(serverTls12Ssl, earlyDataBuffer,
  71825. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71826. #endif
  71827. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer,
  71828. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  71829. #endif
  71830. #endif
  71831. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_EARLY_DATA)
  71832. ExpectIntLT(SSL_get_early_data_status(NULL), 0);
  71833. #endif
  71834. #ifndef NO_WOLFSSL_SERVER
  71835. wolfSSL_free(serverSsl);
  71836. wolfSSL_CTX_free(serverCtx);
  71837. #endif
  71838. #ifndef NO_WOLFSSL_CLIENT
  71839. wolfSSL_free(clientSsl);
  71840. wolfSSL_CTX_free(clientCtx);
  71841. #endif
  71842. #ifndef WOLFSSL_NO_TLS12
  71843. #ifndef NO_WOLFSSL_SERVER
  71844. wolfSSL_free(serverTls12Ssl);
  71845. wolfSSL_CTX_free(serverTls12Ctx);
  71846. #endif
  71847. #ifndef NO_WOLFSSL_CLIENT
  71848. wolfSSL_free(clientTls12Ssl);
  71849. wolfSSL_CTX_free(clientTls12Ctx);
  71850. #endif
  71851. #endif
  71852. return EXPECT_RESULT();
  71853. }
  71854. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && \
  71855. defined(HAVE_ECC) && defined(BUILD_TLS_AES_128_GCM_SHA256) && \
  71856. defined(BUILD_TLS_AES_256_GCM_SHA384)
  71857. /* Called when writing. */
  71858. static int CsSend(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  71859. {
  71860. (void)ssl;
  71861. (void)buf;
  71862. (void)sz;
  71863. (void)ctx;
  71864. /* Force error return from wolfSSL_accept_TLSv13(). */
  71865. return WANT_WRITE;
  71866. }
  71867. /* Called when reading. */
  71868. static int CsRecv(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  71869. {
  71870. WOLFSSL_BUFFER_INFO* msg = (WOLFSSL_BUFFER_INFO*)ctx;
  71871. int len = (int)msg->length;
  71872. (void)ssl;
  71873. (void)sz;
  71874. /* Pass back as much of message as will fit in buffer. */
  71875. if (len > sz)
  71876. len = sz;
  71877. XMEMCPY(buf, msg->buffer, len);
  71878. /* Move over returned data. */
  71879. msg->buffer += len;
  71880. msg->length -= len;
  71881. /* Amount actually copied. */
  71882. return len;
  71883. }
  71884. #endif
  71885. static int test_tls13_cipher_suites(void)
  71886. {
  71887. EXPECT_DECLS;
  71888. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && \
  71889. defined(HAVE_ECC) && defined(BUILD_TLS_AES_128_GCM_SHA256) && \
  71890. defined(BUILD_TLS_AES_256_GCM_SHA384)
  71891. WOLFSSL_CTX* ctx = NULL;
  71892. WOLFSSL *ssl = NULL;
  71893. int i;
  71894. byte clientHello[] = {
  71895. 0x16, 0x03, 0x03, 0x01, 0x9b, 0x01, 0x00, 0x01,
  71896. 0x97, 0x03, 0x03, 0xf4, 0x65, 0xbd, 0x22, 0xfe,
  71897. 0x6e, 0xab, 0x66, 0xdd, 0xcf, 0xe9, 0x65, 0x55,
  71898. 0xe8, 0xdf, 0xc3, 0x8e, 0x4b, 0x00, 0xbc, 0xf8,
  71899. 0x23, 0x57, 0x1b, 0xa0, 0xc8, 0xa9, 0xe2, 0x8c,
  71900. 0x91, 0x6e, 0xf9, 0x20, 0xf7, 0x5c, 0xc5, 0x5b,
  71901. 0x75, 0x8c, 0x47, 0x0a, 0x0e, 0xc4, 0x1a, 0xda,
  71902. 0xef, 0x75, 0xe5, 0x21, 0x00, 0x00, 0x00, 0x00,
  71903. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  71904. 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
  71905. /* Cipher suites: 0x13, 0x01 = TLS13-AES128-GCM-SHA256, twice. */
  71906. 0x13, 0x01,
  71907. 0x13, 0x01, 0x01, 0x00, 0x01, 0x4a, 0x00, 0x2d,
  71908. 0x00, 0x03, 0x02, 0x00, 0x01, 0x00, 0x33, 0x00,
  71909. 0x47, 0x00, 0x45, 0x00, 0x17, 0x00, 0x41, 0x04,
  71910. 0x90, 0xfc, 0xe2, 0x97, 0x05, 0x7c, 0xb5, 0x23,
  71911. 0x5d, 0x5f, 0x5b, 0xcd, 0x0c, 0x1e, 0xe0, 0xe9,
  71912. 0xab, 0x38, 0x6b, 0x1e, 0x20, 0x5c, 0x1c, 0x90,
  71913. 0x2a, 0x9e, 0x68, 0x8e, 0x70, 0x05, 0x10, 0xa8,
  71914. 0x02, 0x1b, 0xf9, 0x5c, 0xef, 0xc9, 0xaf, 0xca,
  71915. 0x1a, 0x3b, 0x16, 0x8b, 0xe4, 0x1b, 0x3c, 0x15,
  71916. 0xb8, 0x0d, 0xbd, 0xaf, 0x62, 0x8d, 0xa7, 0x13,
  71917. 0xa0, 0x7c, 0xe0, 0x59, 0x0c, 0x4f, 0x8a, 0x6d,
  71918. 0x00, 0x2b, 0x00, 0x03, 0x02, 0x03, 0x04, 0x00,
  71919. 0x0d, 0x00, 0x20, 0x00, 0x1e, 0x06, 0x03, 0x05,
  71920. 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06, 0x08,
  71921. 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08,
  71922. 0x09, 0x06, 0x01, 0x05, 0x01, 0x04, 0x01, 0x03,
  71923. 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x04, 0x00,
  71924. 0x02, 0x00, 0x17, 0x00, 0x16, 0x00, 0x00, 0x00,
  71925. 0x23, 0x00, 0x00, 0x00, 0x29, 0x00, 0xb9, 0x00,
  71926. 0x94, 0x00, 0x8e, 0x0f, 0x12, 0xfa, 0x84, 0x1f,
  71927. 0x76, 0x94, 0xd7, 0x09, 0x5e, 0xad, 0x08, 0x51,
  71928. 0xb6, 0x80, 0x28, 0x31, 0x8b, 0xfd, 0xc6, 0xbd,
  71929. 0x9e, 0xf5, 0x3b, 0x4d, 0x02, 0xbe, 0x1d, 0x73,
  71930. 0xea, 0x13, 0x68, 0x00, 0x4c, 0xfd, 0x3d, 0x48,
  71931. 0x51, 0xf9, 0x06, 0xbb, 0x92, 0xed, 0x42, 0x9f,
  71932. 0x7f, 0x2c, 0x73, 0x9f, 0xd9, 0xb4, 0xef, 0x05,
  71933. 0x26, 0x5b, 0x60, 0x5c, 0x0a, 0xfc, 0xa3, 0xbd,
  71934. 0x2d, 0x2d, 0x8b, 0xf9, 0xaa, 0x5c, 0x96, 0x3a,
  71935. 0xf2, 0xec, 0xfa, 0xe5, 0x57, 0x2e, 0x87, 0xbe,
  71936. 0x27, 0xc5, 0x3d, 0x4f, 0x5d, 0xdd, 0xde, 0x1c,
  71937. 0x1b, 0xb3, 0xcc, 0x27, 0x27, 0x57, 0x5a, 0xd9,
  71938. 0xea, 0x99, 0x27, 0x23, 0xa6, 0x0e, 0xea, 0x9c,
  71939. 0x0d, 0x85, 0xcb, 0x72, 0xeb, 0xd7, 0x93, 0xe3,
  71940. 0xfe, 0xf7, 0x5c, 0xc5, 0x5b, 0x75, 0x8c, 0x47,
  71941. 0x0a, 0x0e, 0xc4, 0x1a, 0xda, 0xef, 0x75, 0xe5,
  71942. 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  71943. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  71944. 0x00, 0xfb, 0x92, 0xce, 0xaa, 0x00, 0x21, 0x20,
  71945. 0xcb, 0x73, 0x25, 0x80, 0x46, 0x78, 0x4f, 0xe5,
  71946. 0x34, 0xf6, 0x91, 0x13, 0x7f, 0xc8, 0x8d, 0xdc,
  71947. 0x81, 0x04, 0xb7, 0x0d, 0x49, 0x85, 0x2e, 0x12,
  71948. 0x7a, 0x07, 0x23, 0xe9, 0x13, 0xa4, 0x6d, 0x8c
  71949. };
  71950. WOLFSSL_BUFFER_INFO msg;
  71951. /* Offset into ClientHello message data of first cipher suite. */
  71952. const int csOff = 78;
  71953. /* Server cipher list. */
  71954. const char* serverCs = "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256";
  71955. /* Suite list with duplicates. */
  71956. const char* dupCs = "TLS13-AES128-GCM-SHA256:"
  71957. "TLS13-AES128-GCM-SHA256:"
  71958. "TLS13-AES256-GCM-SHA384:"
  71959. "TLS13-AES256-GCM-SHA384:"
  71960. "TLS13-AES128-GCM-SHA256";
  71961. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)
  71962. const byte dupCsBytes[] = { TLS13_BYTE, TLS_AES_256_GCM_SHA384,
  71963. TLS13_BYTE, TLS_AES_256_GCM_SHA384,
  71964. TLS13_BYTE, TLS_AES_128_GCM_SHA256,
  71965. TLS13_BYTE, TLS_AES_128_GCM_SHA256,
  71966. TLS13_BYTE, TLS_AES_256_GCM_SHA384 };
  71967. #endif
  71968. /* Set up wolfSSL context. */
  71969. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  71970. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  71971. WOLFSSL_FILETYPE_PEM));
  71972. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  71973. WOLFSSL_FILETYPE_PEM));
  71974. /* Read from 'msg'. */
  71975. wolfSSL_SetIORecv(ctx, CsRecv);
  71976. /* No where to send to - dummy sender. */
  71977. wolfSSL_SetIOSend(ctx, CsSend);
  71978. /* Test cipher suite list with many copies of a cipher suite. */
  71979. ExpectNotNull(ssl = wolfSSL_new(ctx));
  71980. msg.buffer = clientHello;
  71981. msg.length = (unsigned int)sizeof(clientHello);
  71982. wolfSSL_SetIOReadCtx(ssl, &msg);
  71983. /* Force server to have as many occurrences of same cipher suite as
  71984. * possible. */
  71985. if (ssl != NULL) {
  71986. Suites* suites = (Suites*)WOLFSSL_SUITES(ssl);
  71987. suites->suiteSz = WOLFSSL_MAX_SUITE_SZ;
  71988. for (i = 0; i < suites->suiteSz; i += 2) {
  71989. suites->suites[i + 0] = TLS13_BYTE;
  71990. suites->suites[i + 1] = TLS_AES_128_GCM_SHA256;
  71991. }
  71992. }
  71993. /* Test multiple occurrences of same cipher suite. */
  71994. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  71995. wolfSSL_free(ssl);
  71996. ssl = NULL;
  71997. /* Set client order opposite to server order:
  71998. * TLS13-AES128-GCM-SHA256:TLS13-AES256-GCM-SHA384 */
  71999. clientHello[csOff + 0] = TLS13_BYTE;
  72000. clientHello[csOff + 1] = TLS_AES_128_GCM_SHA256;
  72001. clientHello[csOff + 2] = TLS13_BYTE;
  72002. clientHello[csOff + 3] = TLS_AES_256_GCM_SHA384;
  72003. /* Test server order negotiation. */
  72004. ExpectNotNull(ssl = wolfSSL_new(ctx));
  72005. msg.buffer = clientHello;
  72006. msg.length = (unsigned int)sizeof(clientHello);
  72007. wolfSSL_SetIOReadCtx(ssl, &msg);
  72008. /* Server order: TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256 */
  72009. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, serverCs), WOLFSSL_SUCCESS);
  72010. /* Negotiate cipher suites in server order: TLS13-AES256-GCM-SHA384 */
  72011. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  72012. /* Check refined order - server order. */
  72013. ExpectIntEQ(ssl->suites->suiteSz, 4);
  72014. ExpectIntEQ(ssl->suites->suites[0], TLS13_BYTE);
  72015. ExpectIntEQ(ssl->suites->suites[1], TLS_AES_256_GCM_SHA384);
  72016. ExpectIntEQ(ssl->suites->suites[2], TLS13_BYTE);
  72017. ExpectIntEQ(ssl->suites->suites[3], TLS_AES_128_GCM_SHA256);
  72018. wolfSSL_free(ssl);
  72019. ssl = NULL;
  72020. /* Test client order negotiation. */
  72021. ExpectNotNull(ssl = wolfSSL_new(ctx));
  72022. msg.buffer = clientHello;
  72023. msg.length = (unsigned int)sizeof(clientHello);
  72024. wolfSSL_SetIOReadCtx(ssl, &msg);
  72025. /* Server order: TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256 */
  72026. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, serverCs), WOLFSSL_SUCCESS);
  72027. ExpectIntEQ(wolfSSL_UseClientSuites(ssl), 0);
  72028. /* Negotiate cipher suites in client order: TLS13-AES128-GCM-SHA256 */
  72029. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  72030. /* Check refined order - client order. */
  72031. ExpectIntEQ(ssl->suites->suiteSz, 4);
  72032. ExpectIntEQ(ssl->suites->suites[0], TLS13_BYTE);
  72033. ExpectIntEQ(ssl->suites->suites[1], TLS_AES_128_GCM_SHA256);
  72034. ExpectIntEQ(ssl->suites->suites[2], TLS13_BYTE);
  72035. ExpectIntEQ(ssl->suites->suites[3], TLS_AES_256_GCM_SHA384);
  72036. wolfSSL_free(ssl);
  72037. ssl = NULL;
  72038. /* Check duplicate detection is working. */
  72039. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, dupCs), WOLFSSL_SUCCESS);
  72040. ExpectIntEQ(ctx->suites->suiteSz, 4);
  72041. ExpectIntEQ(ctx->suites->suites[0], TLS13_BYTE);
  72042. ExpectIntEQ(ctx->suites->suites[1], TLS_AES_128_GCM_SHA256);
  72043. ExpectIntEQ(ctx->suites->suites[2], TLS13_BYTE);
  72044. ExpectIntEQ(ctx->suites->suites[3], TLS_AES_256_GCM_SHA384);
  72045. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)
  72046. ExpectIntEQ(wolfSSL_CTX_set_cipher_list_bytes(ctx, dupCsBytes,
  72047. sizeof(dupCsBytes)), WOLFSSL_SUCCESS);
  72048. ExpectIntEQ(ctx->suites->suiteSz, 4);
  72049. ExpectIntEQ(ctx->suites->suites[0], TLS13_BYTE);
  72050. ExpectIntEQ(ctx->suites->suites[1], TLS_AES_256_GCM_SHA384);
  72051. ExpectIntEQ(ctx->suites->suites[2], TLS13_BYTE);
  72052. ExpectIntEQ(ctx->suites->suites[3], TLS_AES_128_GCM_SHA256);
  72053. #endif
  72054. wolfSSL_CTX_free(ctx);
  72055. #endif
  72056. return EXPECT_RESULT();
  72057. }
  72058. #endif
  72059. #if defined(HAVE_PK_CALLBACKS) && !defined(WOLFSSL_NO_TLS12)
  72060. #if !defined(NO_FILESYSTEM) && !defined(NO_DH) && \
  72061. !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  72062. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  72063. static int my_DhCallback(WOLFSSL* ssl, struct DhKey* key,
  72064. const unsigned char* priv, unsigned int privSz,
  72065. const unsigned char* pubKeyDer, unsigned int pubKeySz,
  72066. unsigned char* out, unsigned int* outlen,
  72067. void* ctx)
  72068. {
  72069. int result;
  72070. /* Test fail when context associated with WOLFSSL is NULL */
  72071. if (ctx == NULL) {
  72072. return -1;
  72073. }
  72074. (void)ssl;
  72075. /* return 0 on success */
  72076. PRIVATE_KEY_UNLOCK();
  72077. result = wc_DhAgree(key, out, outlen, priv, privSz, pubKeyDer, pubKeySz);
  72078. PRIVATE_KEY_LOCK();
  72079. return result;
  72080. }
  72081. static int test_dh_ctx_setup(WOLFSSL_CTX* ctx) {
  72082. EXPECT_DECLS;
  72083. wolfSSL_CTX_SetDhAgreeCb(ctx, my_DhCallback);
  72084. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  72085. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, "DHE-RSA-AES128-SHA256"),
  72086. WOLFSSL_SUCCESS);
  72087. #endif
  72088. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  72089. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, "DHE-RSA-AES256-SHA256"),
  72090. WOLFSSL_SUCCESS);
  72091. #endif
  72092. return EXPECT_RESULT();
  72093. }
  72094. static int test_dh_ssl_setup(WOLFSSL* ssl)
  72095. {
  72096. EXPECT_DECLS;
  72097. static int dh_test_ctx = 1;
  72098. int ret;
  72099. wolfSSL_SetDhAgreeCtx(ssl, &dh_test_ctx);
  72100. ExpectIntEQ(*((int*)wolfSSL_GetDhAgreeCtx(ssl)), dh_test_ctx);
  72101. ret = wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  72102. if (ret != WOLFSSL_SUCCESS && ret != WC_NO_ERR_TRACE(SIDE_ERROR)) {
  72103. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  72104. }
  72105. return EXPECT_RESULT();
  72106. }
  72107. static int test_dh_ssl_setup_fail(WOLFSSL* ssl)
  72108. {
  72109. EXPECT_DECLS;
  72110. int ret;
  72111. wolfSSL_SetDhAgreeCtx(ssl, NULL);
  72112. ExpectNull(wolfSSL_GetDhAgreeCtx(ssl));
  72113. ret = wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  72114. if (ret != WOLFSSL_SUCCESS && ret != WC_NO_ERR_TRACE(SIDE_ERROR)) {
  72115. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  72116. }
  72117. return EXPECT_RESULT();
  72118. }
  72119. #endif
  72120. static int test_DhCallbacks(void)
  72121. {
  72122. EXPECT_DECLS;
  72123. #if !defined(NO_FILESYSTEM) && !defined(NO_DH) && \
  72124. !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  72125. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  72126. WOLFSSL_CTX *ctx = NULL;
  72127. WOLFSSL *ssl = NULL;
  72128. int test;
  72129. test_ssl_cbf func_cb_client;
  72130. test_ssl_cbf func_cb_server;
  72131. /* Test that DH callback APIs work. */
  72132. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  72133. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(NULL, "NONE"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72134. wolfSSL_CTX_SetDhAgreeCb(ctx, &my_DhCallback);
  72135. /* load client ca cert */
  72136. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0),
  72137. WOLFSSL_SUCCESS);
  72138. /* test with NULL arguments */
  72139. wolfSSL_SetDhAgreeCtx(NULL, &test);
  72140. ExpectNull(wolfSSL_GetDhAgreeCtx(NULL));
  72141. /* test success case */
  72142. test = 1;
  72143. ExpectNotNull(ssl = wolfSSL_new(ctx));
  72144. wolfSSL_SetDhAgreeCtx(ssl, &test);
  72145. ExpectIntEQ(*((int*)wolfSSL_GetDhAgreeCtx(ssl)), test);
  72146. wolfSSL_free(ssl);
  72147. wolfSSL_CTX_free(ctx);
  72148. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  72149. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  72150. /* set callbacks to use DH functions */
  72151. func_cb_client.ctx_ready = &test_dh_ctx_setup;
  72152. func_cb_client.ssl_ready = &test_dh_ssl_setup;
  72153. func_cb_client.method = wolfTLSv1_2_client_method;
  72154. func_cb_server.ctx_ready = &test_dh_ctx_setup;
  72155. func_cb_server.ssl_ready = &test_dh_ssl_setup;
  72156. func_cb_server.method = wolfTLSv1_2_server_method;
  72157. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  72158. &func_cb_server, NULL), TEST_SUCCESS);
  72159. /* Test fail */
  72160. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  72161. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  72162. /* set callbacks to use DH functions */
  72163. func_cb_client.ctx_ready = &test_dh_ctx_setup;
  72164. func_cb_client.ssl_ready = &test_dh_ssl_setup_fail;
  72165. func_cb_client.method = wolfTLSv1_2_client_method;
  72166. func_cb_server.ctx_ready = &test_dh_ctx_setup;
  72167. func_cb_server.ssl_ready = &test_dh_ssl_setup_fail;
  72168. func_cb_server.method = wolfTLSv1_2_server_method;
  72169. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  72170. &func_cb_server, NULL), -1001);
  72171. #endif
  72172. return EXPECT_RESULT();
  72173. }
  72174. #endif /* HAVE_PK_CALLBACKS */
  72175. #ifdef HAVE_HASHDRBG
  72176. #ifdef TEST_RESEED_INTERVAL
  72177. static int test_wc_RNG_GenerateBlock_Reseed(void)
  72178. {
  72179. EXPECT_DECLS;
  72180. int i;
  72181. WC_RNG rng;
  72182. byte key[32];
  72183. XMEMSET(&rng, 0, sizeof(WC_RNG));
  72184. ExpectIntEQ(wc_InitRng(&rng), 0);
  72185. for (i = 0; i < WC_RESEED_INTERVAL + 10; i++) {
  72186. ExpectIntEQ(wc_RNG_GenerateBlock(&rng, key, sizeof(key)), 0);
  72187. }
  72188. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  72189. return EXPECT_RESULT();
  72190. }
  72191. #endif /* TEST_RESEED_INTERVAL */
  72192. static int test_wc_RNG_GenerateBlock(void)
  72193. {
  72194. EXPECT_DECLS;
  72195. int i;
  72196. WC_RNG rng;
  72197. byte key[32];
  72198. XMEMSET(&rng, 0, sizeof(WC_RNG));
  72199. ExpectIntEQ(wc_InitRng(&rng), 0);
  72200. for (i = 0; i < 10; i++) {
  72201. ExpectIntEQ(wc_RNG_GenerateBlock(&rng, key, sizeof(key)), 0);
  72202. }
  72203. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  72204. return EXPECT_RESULT();
  72205. }
  72206. #endif /* HAVE_HASHDRBG */
  72207. /*
  72208. * Testing get_rand_digit
  72209. */
  72210. static int test_get_rand_digit(void)
  72211. {
  72212. EXPECT_DECLS;
  72213. #if !defined(WC_NO_RNG) && defined(WOLFSSL_PUBLIC_MP)
  72214. WC_RNG rng;
  72215. mp_digit d;
  72216. XMEMSET(&rng, 0, sizeof(WC_RNG));
  72217. ExpectIntEQ(wc_InitRng(&rng), 0);
  72218. ExpectIntEQ(get_rand_digit(&rng, &d), 0);
  72219. ExpectIntEQ(get_rand_digit(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72220. ExpectIntEQ(get_rand_digit(NULL, &d), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72221. ExpectIntEQ(get_rand_digit(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72222. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  72223. #endif
  72224. return EXPECT_RESULT();
  72225. } /* End test_get_rand_digit*/
  72226. /*
  72227. * Testing get_digit_count
  72228. */
  72229. static int test_get_digit_count(void)
  72230. {
  72231. EXPECT_DECLS;
  72232. #if !defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_PUBLIC_MP)
  72233. mp_int a;
  72234. XMEMSET(&a, 0, sizeof(mp_int));
  72235. ExpectIntEQ(mp_init(&a), 0);
  72236. ExpectIntEQ(get_digit_count(NULL), 0);
  72237. ExpectIntEQ(get_digit_count(&a), 0);
  72238. mp_clear(&a);
  72239. #endif
  72240. return EXPECT_RESULT();
  72241. } /* End test_get_digit_count*/
  72242. /*
  72243. * Testing mp_cond_copy
  72244. */
  72245. static int test_mp_cond_copy(void)
  72246. {
  72247. EXPECT_DECLS;
  72248. #if (defined(HAVE_ECC) || defined(WOLFSSL_MP_COND_COPY)) && \
  72249. defined(WOLFSSL_PUBLIC_MP)
  72250. mp_int a;
  72251. mp_int b;
  72252. int copy = 0;
  72253. XMEMSET(&a, 0, sizeof(mp_int));
  72254. XMEMSET(&b, 0, sizeof(mp_int));
  72255. ExpectIntEQ(mp_init(&a), MP_OKAY);
  72256. ExpectIntEQ(mp_init(&b), MP_OKAY);
  72257. ExpectIntEQ(mp_cond_copy(NULL, copy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72258. ExpectIntEQ(mp_cond_copy(NULL, copy, &b), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72259. ExpectIntEQ(mp_cond_copy(&a, copy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72260. ExpectIntEQ(mp_cond_copy(&a, copy, &b), 0);
  72261. mp_clear(&a);
  72262. mp_clear(&b);
  72263. #endif
  72264. return EXPECT_RESULT();
  72265. } /* End test_mp_cond_copy*/
  72266. /*
  72267. * Testing mp_rand
  72268. */
  72269. static int test_mp_rand(void)
  72270. {
  72271. EXPECT_DECLS;
  72272. #if defined(WC_RSA_BLINDING) && defined(WOLFSSL_PUBLIC_MP)
  72273. mp_int a;
  72274. WC_RNG rng;
  72275. int digits = 1;
  72276. XMEMSET(&a, 0, sizeof(mp_int));
  72277. XMEMSET(&rng, 0, sizeof(WC_RNG));
  72278. ExpectIntEQ(mp_init(&a), MP_OKAY);
  72279. ExpectIntEQ(wc_InitRng(&rng), 0);
  72280. ExpectIntEQ(mp_rand(&a, digits, NULL), WC_NO_ERR_TRACE(MISSING_RNG_E));
  72281. ExpectIntEQ(mp_rand(NULL, digits, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72282. ExpectIntEQ(mp_rand(&a, 0, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72283. ExpectIntEQ(mp_rand(&a, digits, &rng), 0);
  72284. mp_clear(&a);
  72285. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  72286. #endif
  72287. return EXPECT_RESULT();
  72288. } /* End test_mp_rand*/
  72289. /*
  72290. * Testing get_digit
  72291. */
  72292. static int test_get_digit(void)
  72293. {
  72294. EXPECT_DECLS;
  72295. #if defined(WOLFSSL_PUBLIC_MP)
  72296. mp_int a;
  72297. int n = 0;
  72298. XMEMSET(&a, 0, sizeof(mp_int));
  72299. ExpectIntEQ(mp_init(&a), MP_OKAY);
  72300. ExpectIntEQ(get_digit(NULL, n), 0);
  72301. ExpectIntEQ(get_digit(&a, n), 0);
  72302. mp_clear(&a);
  72303. #endif
  72304. return EXPECT_RESULT();
  72305. } /* End test_get_digit*/
  72306. /*
  72307. * Testing wc_export_int
  72308. */
  72309. static int test_wc_export_int(void)
  72310. {
  72311. EXPECT_DECLS;
  72312. #if (defined(HAVE_ECC) || defined(WOLFSSL_EXPORT_INT)) && \
  72313. defined(WOLFSSL_PUBLIC_MP)
  72314. mp_int mp;
  72315. byte buf[32];
  72316. word32 keySz = (word32)sizeof(buf);
  72317. word32 len = (word32)sizeof(buf);
  72318. XMEMSET(&mp, 0, sizeof(mp_int));
  72319. ExpectIntEQ(mp_init(&mp), MP_OKAY);
  72320. ExpectIntEQ(mp_set(&mp, 1234), 0);
  72321. ExpectIntEQ(wc_export_int(NULL, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN),
  72322. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72323. len = sizeof(buf)-1;
  72324. ExpectIntEQ(wc_export_int(&mp, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN),
  72325. WC_NO_ERR_TRACE(BUFFER_E));
  72326. len = sizeof(buf);
  72327. ExpectIntEQ(wc_export_int(&mp, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN), 0);
  72328. len = 4; /* test input too small */
  72329. ExpectIntEQ(wc_export_int(&mp, buf, &len, 0, WC_TYPE_HEX_STR), WC_NO_ERR_TRACE(BUFFER_E));
  72330. len = sizeof(buf);
  72331. ExpectIntEQ(wc_export_int(&mp, buf, &len, 0, WC_TYPE_HEX_STR), 0);
  72332. /* hex version of 1234 is 04D2 and should be 4 digits + 1 null */
  72333. ExpectIntEQ(len, 5);
  72334. mp_clear(&mp);
  72335. #endif
  72336. return EXPECT_RESULT();
  72337. } /* End test_wc_export_int*/
  72338. static int test_wc_InitRngNonce(void)
  72339. {
  72340. EXPECT_DECLS;
  72341. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  72342. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  72343. HAVE_FIPS_VERSION >= 2))
  72344. WC_RNG rng;
  72345. byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"
  72346. "\x45\xAC\x13\x7A\xE1\x48\xAF\x16";
  72347. word32 nonceSz = sizeof(nonce);
  72348. ExpectIntEQ(wc_InitRngNonce(&rng, nonce, nonceSz), 0);
  72349. ExpectIntEQ(wc_FreeRng(&rng), 0);
  72350. #endif
  72351. return EXPECT_RESULT();
  72352. } /* End test_wc_InitRngNonce*/
  72353. /*
  72354. * Testing wc_InitRngNonce_ex
  72355. */
  72356. static int test_wc_InitRngNonce_ex(void)
  72357. {
  72358. EXPECT_DECLS;
  72359. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  72360. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  72361. HAVE_FIPS_VERSION >= 2))
  72362. WC_RNG rng;
  72363. byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"
  72364. "\x45\xAC\x13\x7A\xE1\x48\xAF\x16";
  72365. word32 nonceSz = sizeof(nonce);
  72366. ExpectIntEQ(wc_InitRngNonce_ex(&rng, nonce, nonceSz, HEAP_HINT, testDevId),
  72367. 0);
  72368. ExpectIntEQ(wc_FreeRng(&rng), 0);
  72369. #endif
  72370. return EXPECT_RESULT();
  72371. } /* End test_wc_InitRngNonce_ex */
  72372. static int test_wolfSSL_X509_CRL(void)
  72373. {
  72374. EXPECT_DECLS;
  72375. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL)
  72376. X509_CRL *crl = NULL;
  72377. char pem[][100] = {
  72378. "./certs/crl/crl.pem",
  72379. "./certs/crl/crl2.pem",
  72380. "./certs/crl/caEccCrl.pem",
  72381. "./certs/crl/eccCliCRL.pem",
  72382. "./certs/crl/eccSrvCRL.pem",
  72383. ""
  72384. };
  72385. #ifndef NO_BIO
  72386. BIO *bio = NULL;
  72387. #endif
  72388. #ifdef HAVE_TEST_d2i_X509_CRL_fp
  72389. char der[][100] = {
  72390. "./certs/crl/crl.der",
  72391. "./certs/crl/crl2.der",
  72392. ""};
  72393. #endif
  72394. XFILE fp = XBADFILE;
  72395. int i;
  72396. for (i = 0; pem[i][0] != '\0'; i++)
  72397. {
  72398. ExpectTrue((fp = XFOPEN(pem[i], "rb")) != XBADFILE);
  72399. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  72400. NULL, NULL));
  72401. ExpectNotNull(crl);
  72402. X509_CRL_free(crl);
  72403. if (fp != XBADFILE) {
  72404. XFCLOSE(fp);
  72405. fp = XBADFILE;
  72406. }
  72407. ExpectTrue((fp = XFOPEN(pem[i], "rb")) != XBADFILE);
  72408. ExpectNotNull((X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)&crl, NULL,
  72409. NULL));
  72410. if (EXPECT_FAIL()) {
  72411. crl = NULL;
  72412. }
  72413. ExpectNotNull(crl);
  72414. X509_CRL_free(crl);
  72415. crl = NULL;
  72416. if (fp != XBADFILE) {
  72417. XFCLOSE(fp);
  72418. fp = XBADFILE;
  72419. }
  72420. }
  72421. #ifndef NO_BIO
  72422. for (i = 0; pem[i][0] != '\0'; i++)
  72423. {
  72424. ExpectNotNull(bio = BIO_new_file(pem[i], "rb"));
  72425. ExpectNotNull(crl = PEM_read_bio_X509_CRL(bio, NULL, NULL, NULL));
  72426. X509_CRL_free(crl);
  72427. crl = NULL;
  72428. BIO_free(bio);
  72429. bio = NULL;
  72430. }
  72431. #endif
  72432. #ifdef HAVE_TEST_d2i_X509_CRL_fp
  72433. for (i = 0; der[i][0] != '\0'; i++) {
  72434. ExpectTrue((fp = XFOPEN(der[i], "rb")) != XBADFILE);
  72435. ExpectTrue((fp != XBADFILE));
  72436. ExpectNotNull(crl = (X509_CRL *)d2i_X509_CRL_fp((fp, X509_CRL **)NULL));
  72437. ExpectNotNull(crl);
  72438. X509_CRL_free(crl);
  72439. if (fp != XBADFILE) {
  72440. XFCLOSE(fp);
  72441. fp = XBADFILE;
  72442. }
  72443. fp = XFOPEN(der[i], "rb");
  72444. ExpectTrue((fp != XBADFILE));
  72445. ExpectNotNull((X509_CRL *)d2i_X509_CRL_fp(fp, (X509_CRL **)&crl));
  72446. if (EXPECT_FAIL()) {
  72447. crl = NULL;
  72448. }
  72449. ExpectNotNull(crl);
  72450. X509_CRL_free(crl);
  72451. crl = NULL;
  72452. if (fp != XBADFILE) {
  72453. XFCLOSE(fp);
  72454. fp = XBADFILE;
  72455. }
  72456. }
  72457. #endif
  72458. #endif
  72459. return EXPECT_RESULT();
  72460. }
  72461. static int test_wolfSSL_X509_load_crl_file(void)
  72462. {
  72463. EXPECT_DECLS;
  72464. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && !defined(NO_FILESYSTEM) && \
  72465. !defined(NO_STDIO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_BIO) && \
  72466. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  72467. int i;
  72468. char pem[][100] = {
  72469. "./certs/crl/crl.pem",
  72470. "./certs/crl/crl2.pem",
  72471. "./certs/crl/caEccCrl.pem",
  72472. "./certs/crl/eccCliCRL.pem",
  72473. "./certs/crl/eccSrvCRL.pem",
  72474. #ifdef WC_RSA_PSS
  72475. "./certs/crl/crl_rsapss.pem",
  72476. #endif
  72477. ""
  72478. };
  72479. char der[][100] = {
  72480. "./certs/crl/crl.der",
  72481. "./certs/crl/crl2.der",
  72482. ""
  72483. };
  72484. WOLFSSL_X509_STORE* store = NULL;
  72485. WOLFSSL_X509_LOOKUP* lookup = NULL;
  72486. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  72487. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  72488. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  72489. X509_FILETYPE_PEM), 1);
  72490. #ifdef WC_RSA_PSS
  72491. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/rsapss/ca-rsapss.pem",
  72492. X509_FILETYPE_PEM), 1);
  72493. #endif
  72494. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/server-revoked-cert.pem",
  72495. X509_FILETYPE_PEM), 1);
  72496. if (store) {
  72497. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  72498. WOLFSSL_FILETYPE_PEM), 1);
  72499. /* since store hasn't yet known the revoked cert*/
  72500. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  72501. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM), 1);
  72502. }
  72503. for (i = 0; pem[i][0] != '\0'; i++) {
  72504. ExpectIntEQ(X509_load_crl_file(lookup, pem[i], WOLFSSL_FILETYPE_PEM),
  72505. 1);
  72506. }
  72507. if (store) {
  72508. /* since store knows crl list */
  72509. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  72510. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM),
  72511. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  72512. #ifdef WC_RSA_PSS
  72513. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  72514. "certs/rsapss/server-rsapss-cert.pem", WOLFSSL_FILETYPE_PEM),
  72515. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  72516. #endif
  72517. }
  72518. /* once feeing store */
  72519. X509_STORE_free(store);
  72520. store = NULL;
  72521. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  72522. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  72523. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  72524. X509_FILETYPE_PEM), 1);
  72525. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/server-revoked-cert.pem",
  72526. X509_FILETYPE_PEM), 1);
  72527. if (store) {
  72528. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  72529. WOLFSSL_FILETYPE_PEM), 1);
  72530. /* since store hasn't yet known the revoked cert*/
  72531. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  72532. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM), 1);
  72533. }
  72534. for (i = 0; der[i][0] != '\0'; i++) {
  72535. ExpectIntEQ(X509_load_crl_file(lookup, der[i], WOLFSSL_FILETYPE_ASN1),
  72536. 1);
  72537. }
  72538. if (store) {
  72539. /* since store knows crl list */
  72540. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  72541. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM),
  72542. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  72543. }
  72544. /* test for incorrect parameter */
  72545. ExpectIntEQ(X509_load_crl_file(NULL, pem[0], 0), 0);
  72546. ExpectIntEQ(X509_load_crl_file(lookup, NULL, 0), 0);
  72547. ExpectIntEQ(X509_load_crl_file(NULL, NULL, 0), 0);
  72548. X509_STORE_free(store);
  72549. store = NULL;
  72550. #endif
  72551. return EXPECT_RESULT();
  72552. }
  72553. static int test_wolfSSL_i2d_X509(void)
  72554. {
  72555. EXPECT_DECLS;
  72556. #if defined(OPENSSL_EXTRA) && defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA)
  72557. const unsigned char* cert_buf = server_cert_der_2048;
  72558. unsigned char* out = NULL;
  72559. unsigned char* tmp = NULL;
  72560. X509* cert = NULL;
  72561. ExpectNotNull(d2i_X509(&cert, &cert_buf, sizeof_server_cert_der_2048));
  72562. /* Pointer should be advanced */
  72563. ExpectPtrGT(cert_buf, server_cert_der_2048);
  72564. ExpectIntGT(i2d_X509(cert, &out), 0);
  72565. ExpectNotNull(out);
  72566. tmp = out;
  72567. ExpectIntGT(i2d_X509(cert, &tmp), 0);
  72568. ExpectPtrGT(tmp, out);
  72569. if (out != NULL)
  72570. XFREE(out, NULL, DYNAMIC_TYPE_OPENSSL);
  72571. X509_free(cert);
  72572. #endif
  72573. return EXPECT_RESULT();
  72574. }
  72575. static int test_wolfSSL_d2i_X509_REQ(void)
  72576. {
  72577. EXPECT_DECLS;
  72578. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA) && !defined(NO_BIO) && \
  72579. (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)) && \
  72580. !defined(WOLFSSL_SP_MATH)
  72581. /* ./certs/csr.signed.der, ./certs/csr.ext.der, and ./certs/csr.attr.der
  72582. * were generated by libest
  72583. * ./certs/csr.attr.der contains sample attributes
  72584. * ./certs/csr.ext.der contains sample extensions */
  72585. const char* csrFile = "./certs/csr.signed.der";
  72586. const char* csrPopFile = "./certs/csr.attr.der";
  72587. const char* csrExtFile = "./certs/csr.ext.der";
  72588. /* ./certs/csr.dsa.pem is generated using
  72589. * openssl req -newkey dsa:certs/dsaparams.pem \
  72590. * -keyout certs/csr.dsa.key.pem -keyform PEM -out certs/csr.dsa.pem \
  72591. * -outform PEM
  72592. * with the passphrase "wolfSSL"
  72593. */
  72594. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST)
  72595. const char* csrDsaFile = "./certs/csr.dsa.pem";
  72596. XFILE f = XBADFILE;
  72597. #endif
  72598. BIO* bio = NULL;
  72599. X509* req = NULL;
  72600. EVP_PKEY *pub_key = NULL;
  72601. {
  72602. ExpectNotNull(bio = BIO_new_file(csrFile, "rb"));
  72603. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  72604. /*
  72605. * Extract the public key from the CSR
  72606. */
  72607. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  72608. /*
  72609. * Verify the signature in the CSR
  72610. */
  72611. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  72612. X509_free(req);
  72613. req = NULL;
  72614. BIO_free(bio);
  72615. bio = NULL;
  72616. EVP_PKEY_free(pub_key);
  72617. pub_key = NULL;
  72618. }
  72619. {
  72620. #ifdef OPENSSL_ALL
  72621. X509_ATTRIBUTE* attr = NULL;
  72622. ASN1_TYPE *at = NULL;
  72623. #endif
  72624. ExpectNotNull(bio = BIO_new_file(csrPopFile, "rb"));
  72625. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  72626. /*
  72627. * Extract the public key from the CSR
  72628. */
  72629. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  72630. /*
  72631. * Verify the signature in the CSR
  72632. */
  72633. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  72634. #ifdef OPENSSL_ALL
  72635. /*
  72636. * Obtain the challenge password from the CSR
  72637. */
  72638. ExpectIntEQ(X509_REQ_get_attr_by_NID(req, NID_pkcs9_challengePassword,
  72639. -1), 1);
  72640. ExpectNotNull(attr = X509_REQ_get_attr(req, 1));
  72641. ExpectNotNull(at = X509_ATTRIBUTE_get0_type(attr, 0));
  72642. ExpectNotNull(at->value.asn1_string);
  72643. ExpectStrEQ((char*)ASN1_STRING_data(at->value.asn1_string),
  72644. "2xIE+qqp/rhyTXP+");
  72645. ExpectIntEQ(X509_get_ext_by_NID(req, NID_subject_alt_name, -1), -1);
  72646. #endif
  72647. X509_free(req);
  72648. req = NULL;
  72649. BIO_free(bio);
  72650. bio = NULL;
  72651. EVP_PKEY_free(pub_key);
  72652. pub_key = NULL;
  72653. }
  72654. {
  72655. #ifdef OPENSSL_ALL
  72656. X509_ATTRIBUTE* attr = NULL;
  72657. ASN1_TYPE *at = NULL;
  72658. STACK_OF(X509_EXTENSION) *exts = NULL;
  72659. #endif
  72660. ExpectNotNull(bio = BIO_new_file(csrExtFile, "rb"));
  72661. /* This CSR contains an Extension Request attribute so
  72662. * we test extension parsing in a CSR attribute here. */
  72663. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  72664. /*
  72665. * Extract the public key from the CSR
  72666. */
  72667. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  72668. /*
  72669. * Verify the signature in the CSR
  72670. */
  72671. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  72672. #ifdef OPENSSL_ALL
  72673. ExpectNotNull(exts = (STACK_OF(X509_EXTENSION)*)X509_REQ_get_extensions(
  72674. req));
  72675. ExpectIntEQ(sk_X509_EXTENSION_num(exts), 2);
  72676. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  72677. /*
  72678. * Obtain the challenge password from the CSR
  72679. */
  72680. ExpectIntEQ(X509_REQ_get_attr_by_NID(req, NID_pkcs9_challengePassword,
  72681. -1), 0);
  72682. ExpectNotNull(attr = X509_REQ_get_attr(req, 0));
  72683. ExpectNotNull(at = X509_ATTRIBUTE_get0_type(attr, 0));
  72684. ExpectNotNull(at->value.asn1_string);
  72685. ExpectStrEQ((char*)ASN1_STRING_data(at->value.asn1_string), "IGCu/xNL4/0/wOgo");
  72686. ExpectIntGE(X509_get_ext_by_NID(req, NID_key_usage, -1), 0);
  72687. ExpectIntGE(X509_get_ext_by_NID(req, NID_subject_alt_name, -1), 0);
  72688. #endif
  72689. X509_free(req);
  72690. req = NULL;
  72691. BIO_free(bio);
  72692. bio = NULL;
  72693. EVP_PKEY_free(pub_key);
  72694. pub_key = NULL;
  72695. }
  72696. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST)
  72697. {
  72698. ExpectNotNull(bio = BIO_new_file(csrDsaFile, "rb"));
  72699. ExpectNotNull(PEM_read_bio_X509_REQ(bio, &req, NULL, NULL));
  72700. /*
  72701. * Extract the public key from the CSR
  72702. */
  72703. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  72704. /*
  72705. * Verify the signature in the CSR
  72706. */
  72707. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  72708. X509_free(req);
  72709. req = NULL;
  72710. BIO_free(bio);
  72711. /* Run the same test, but with a file pointer instead of a BIO.
  72712. * (PEM_read_X509_REQ)*/
  72713. ExpectTrue((f = XFOPEN(csrDsaFile, "rb")) != XBADFILE);
  72714. ExpectNotNull(PEM_read_X509_REQ(f, &req, NULL, NULL));
  72715. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  72716. X509_free(req);
  72717. EVP_PKEY_free(pub_key);
  72718. }
  72719. #endif /* !NO_DSA && !HAVE_SELFTEST */
  72720. #endif /* WOLFSSL_CERT_REQ && (OPENSSL_ALL || OPENSSL_EXTRA) */
  72721. return EXPECT_RESULT();
  72722. }
  72723. static int test_wolfSSL_PEM_read_X509(void)
  72724. {
  72725. EXPECT_DECLS;
  72726. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && !defined(NO_FILESYSTEM) && \
  72727. !defined(NO_RSA)
  72728. X509 *x509 = NULL;
  72729. XFILE fp = XBADFILE;
  72730. ExpectTrue((fp = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  72731. ExpectNotNull(x509 = (X509 *)PEM_read_X509(fp, (X509 **)NULL, NULL, NULL));
  72732. X509_free(x509);
  72733. if (fp != XBADFILE)
  72734. XFCLOSE(fp);
  72735. #endif
  72736. return EXPECT_RESULT();
  72737. }
  72738. static int test_wolfSSL_PEM_read(void)
  72739. {
  72740. EXPECT_DECLS;
  72741. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  72742. const char* filename = "./certs/server-keyEnc.pem";
  72743. XFILE fp = XBADFILE;
  72744. char* name = NULL;
  72745. char* header = NULL;
  72746. byte* data = NULL;
  72747. long len;
  72748. EVP_CIPHER_INFO cipher;
  72749. WOLFSSL_BIO* bio = NULL;
  72750. byte* fileData = NULL;
  72751. size_t fileDataSz = 0;
  72752. byte* out;
  72753. ExpectNotNull(bio = BIO_new_file(filename, "rb"));
  72754. ExpectIntEQ(PEM_read_bio(bio, NULL, &header, &data, &len), 0);
  72755. ExpectIntEQ(PEM_read_bio(bio, &name, NULL, &data, &len), 0);
  72756. ExpectIntEQ(PEM_read_bio(bio, &name, &header, NULL, &len), 0);
  72757. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, NULL), 0);
  72758. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, &len), 1);
  72759. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  72760. ExpectIntGT(XSTRLEN(header), 0);
  72761. ExpectIntGT(len, 0);
  72762. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72763. name = NULL;
  72764. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72765. header = NULL;
  72766. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72767. data = NULL;
  72768. BIO_free(bio);
  72769. bio = NULL;
  72770. ExpectTrue((fp = XFOPEN(filename, "rb")) != XBADFILE);
  72771. /* Fail cases. */
  72772. ExpectIntEQ(PEM_read(fp, NULL, &header, &data, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72773. ExpectIntEQ(PEM_read(fp, &name, NULL, &data, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72774. ExpectIntEQ(PEM_read(fp, &name, &header, NULL, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72775. ExpectIntEQ(PEM_read(fp, &name, &header, &data, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72776. ExpectIntEQ(PEM_read(fp, &name, &header, &data, &len), WOLFSSL_SUCCESS);
  72777. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  72778. ExpectIntGT(XSTRLEN(header), 0);
  72779. ExpectIntGT(len, 0);
  72780. ExpectIntEQ(XFSEEK(fp, 0, SEEK_END), 0);
  72781. ExpectIntGT((fileDataSz = XFTELL(fp)), 0);
  72782. ExpectIntEQ(XFSEEK(fp, 0, SEEK_SET), 0);
  72783. ExpectNotNull(fileData = (unsigned char*)XMALLOC(fileDataSz, NULL,
  72784. DYNAMIC_TYPE_TMP_BUFFER));
  72785. ExpectIntEQ(XFREAD(fileData, 1, fileDataSz, fp), fileDataSz);
  72786. if (fp != XBADFILE) {
  72787. XFCLOSE(fp);
  72788. fp = XBADFILE;
  72789. }
  72790. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  72791. /* Fail cases. */
  72792. ExpectIntEQ(PEM_write_bio(NULL, name, header, data, len), 0);
  72793. ExpectIntEQ(PEM_write_bio(bio, NULL, header, data, len), 0);
  72794. ExpectIntEQ(PEM_write_bio(bio, name, NULL, data, len), 0);
  72795. ExpectIntEQ(PEM_write_bio(bio, name, header, NULL, len), 0);
  72796. ExpectIntEQ(PEM_write_bio(bio, name, header, data, len), fileDataSz);
  72797. ExpectIntEQ(wolfSSL_BIO_get_mem_data(bio, &out), fileDataSz);
  72798. ExpectIntEQ(XMEMCMP(out, fileData, fileDataSz), 0);
  72799. /* Fail cases. */
  72800. ExpectIntEQ(PEM_write(XBADFILE, name, header, data, len), 0);
  72801. ExpectIntEQ(PEM_write(stderr, NULL, header, data, len), 0);
  72802. ExpectIntEQ(PEM_write(stderr, name, NULL, data, len), 0);
  72803. ExpectIntEQ(PEM_write(stderr, name, header, NULL, len), 0);
  72804. /* Pass case */
  72805. ExpectIntEQ(PEM_write(stderr, name, header, data, len), fileDataSz);
  72806. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72807. name = NULL;
  72808. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72809. header = NULL;
  72810. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72811. data = NULL;
  72812. /* Read out of a fixed buffer BIO - forces malloc in PEM_read_bio. */
  72813. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, &len), 1);
  72814. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  72815. ExpectIntGT(XSTRLEN(header), 0);
  72816. ExpectIntGT(len, 0);
  72817. /* Fail cases. */
  72818. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(NULL, &cipher), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72819. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(header, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72820. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO((char*)"", &cipher), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72821. #ifndef NO_DES3
  72822. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(header, &cipher), WOLFSSL_SUCCESS);
  72823. #endif
  72824. /* Fail cases. */
  72825. ExpectIntEQ(PEM_do_header(NULL, data, &len, PasswordCallBack,
  72826. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72827. ExpectIntEQ(PEM_do_header(&cipher, NULL, &len, PasswordCallBack,
  72828. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72829. ExpectIntEQ(PEM_do_header(&cipher, data, NULL, PasswordCallBack,
  72830. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72831. ExpectIntEQ(PEM_do_header(&cipher, data, &len, NULL,
  72832. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72833. ExpectIntEQ(PEM_do_header(&cipher, data, &len, NoPasswordCallBack,
  72834. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72835. #if !defined(NO_DES3) && !defined(NO_MD5)
  72836. ExpectIntEQ(PEM_do_header(&cipher, data, &len, PasswordCallBack,
  72837. (void*)"yassl123"), WOLFSSL_SUCCESS);
  72838. #else
  72839. ExpectIntEQ(PEM_do_header(&cipher, data, &len, PasswordCallBack,
  72840. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72841. #endif
  72842. BIO_free(bio);
  72843. bio = NULL;
  72844. XFREE(fileData, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72845. fileData = NULL;
  72846. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72847. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72848. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72849. name = NULL;
  72850. header = NULL;
  72851. data = NULL;
  72852. ExpectTrue((fp = XFOPEN(svrKeyFile, "rb")) != XBADFILE);
  72853. ExpectIntEQ(PEM_read(fp, &name, &header, &data, &len), WOLFSSL_SUCCESS);
  72854. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  72855. ExpectIntEQ(XSTRLEN(header), 0);
  72856. ExpectIntGT(len, 0);
  72857. ExpectIntEQ(XFSEEK(fp, 0, SEEK_END), 0);
  72858. ExpectIntGT((fileDataSz = XFTELL(fp)), 0);
  72859. ExpectIntEQ(XFSEEK(fp, 0, SEEK_SET), 0);
  72860. ExpectNotNull(fileData = (unsigned char*)XMALLOC(fileDataSz, NULL,
  72861. DYNAMIC_TYPE_TMP_BUFFER));
  72862. ExpectIntEQ(XFREAD(fileData, 1, fileDataSz, fp), fileDataSz);
  72863. if (fp != XBADFILE)
  72864. XFCLOSE(fp);
  72865. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  72866. ExpectIntEQ(PEM_write_bio(bio, name, header, data, len), fileDataSz);
  72867. ExpectIntEQ(wolfSSL_BIO_get_mem_data(bio, &out), fileDataSz);
  72868. ExpectIntEQ(XMEMCMP(out, fileData, fileDataSz), 0);
  72869. BIO_free(bio);
  72870. XFREE(fileData, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72871. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72872. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72873. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72874. #endif
  72875. return EXPECT_RESULT();
  72876. }
  72877. static int test_wolfssl_EVP_aes_gcm_AAD_2_parts(void)
  72878. {
  72879. EXPECT_DECLS;
  72880. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  72881. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72882. const byte iv[12] = { 0 };
  72883. const byte key[16] = { 0 };
  72884. const byte cleartext[16] = { 0 };
  72885. const byte aad[] = {
  72886. 0x01, 0x10, 0x00, 0x2a, 0x08, 0x00, 0x04, 0x00,
  72887. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  72888. 0x00, 0x00, 0xdc, 0x4d, 0xad, 0x6b, 0x06, 0x93,
  72889. 0x4f
  72890. };
  72891. byte out1Part[16];
  72892. byte outTag1Part[16];
  72893. byte out2Part[16];
  72894. byte outTag2Part[16];
  72895. byte decryptBuf[16];
  72896. int len = 0;
  72897. int tlen;
  72898. EVP_CIPHER_CTX* ctx = NULL;
  72899. /* ENCRYPT */
  72900. /* Send AAD and data in 1 part */
  72901. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  72902. tlen = 0;
  72903. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  72904. 1);
  72905. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  72906. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad, sizeof(aad)), 1);
  72907. ExpectIntEQ(EVP_EncryptUpdate(ctx, out1Part, &len, cleartext,
  72908. sizeof(cleartext)), 1);
  72909. tlen += len;
  72910. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, out1Part, &len), 1);
  72911. tlen += len;
  72912. ExpectIntEQ(tlen, sizeof(cleartext));
  72913. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, 16,
  72914. outTag1Part), 1);
  72915. EVP_CIPHER_CTX_free(ctx);
  72916. ctx = NULL;
  72917. /* DECRYPT */
  72918. /* Send AAD and data in 1 part */
  72919. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  72920. tlen = 0;
  72921. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  72922. 1);
  72923. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  72924. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad, sizeof(aad)), 1);
  72925. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf, &len, out1Part,
  72926. sizeof(cleartext)), 1);
  72927. tlen += len;
  72928. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16,
  72929. outTag1Part), 1);
  72930. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptBuf, &len), 1);
  72931. tlen += len;
  72932. ExpectIntEQ(tlen, sizeof(cleartext));
  72933. EVP_CIPHER_CTX_free(ctx);
  72934. ctx = NULL;
  72935. ExpectIntEQ(XMEMCMP(decryptBuf, cleartext, len), 0);
  72936. /* ENCRYPT */
  72937. /* Send AAD and data in 2 parts */
  72938. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  72939. tlen = 0;
  72940. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  72941. 1);
  72942. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  72943. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad, 1), 1);
  72944. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad + 1, sizeof(aad) - 1),
  72945. 1);
  72946. ExpectIntEQ(EVP_EncryptUpdate(ctx, out2Part, &len, cleartext, 1), 1);
  72947. tlen += len;
  72948. ExpectIntEQ(EVP_EncryptUpdate(ctx, out2Part + tlen, &len, cleartext + 1,
  72949. sizeof(cleartext) - 1), 1);
  72950. tlen += len;
  72951. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, out2Part + tlen, &len), 1);
  72952. tlen += len;
  72953. ExpectIntEQ(tlen, sizeof(cleartext));
  72954. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, 16,
  72955. outTag2Part), 1);
  72956. ExpectIntEQ(XMEMCMP(out1Part, out2Part, sizeof(out1Part)), 0);
  72957. ExpectIntEQ(XMEMCMP(outTag1Part, outTag2Part, sizeof(outTag1Part)), 0);
  72958. EVP_CIPHER_CTX_free(ctx);
  72959. ctx = NULL;
  72960. /* DECRYPT */
  72961. /* Send AAD and data in 2 parts */
  72962. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  72963. tlen = 0;
  72964. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  72965. 1);
  72966. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  72967. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad, 1), 1);
  72968. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad + 1, sizeof(aad) - 1),
  72969. 1);
  72970. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf, &len, out1Part, 1), 1);
  72971. tlen += len;
  72972. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf + tlen, &len, out1Part + 1,
  72973. sizeof(cleartext) - 1), 1);
  72974. tlen += len;
  72975. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16,
  72976. outTag1Part), 1);
  72977. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptBuf + tlen, &len), 1);
  72978. tlen += len;
  72979. ExpectIntEQ(tlen, sizeof(cleartext));
  72980. ExpectIntEQ(XMEMCMP(decryptBuf, cleartext, len), 0);
  72981. /* Test AAD reuse */
  72982. EVP_CIPHER_CTX_free(ctx);
  72983. #endif
  72984. return EXPECT_RESULT();
  72985. }
  72986. static int test_wolfssl_EVP_aes_gcm_zeroLen(void)
  72987. {
  72988. EXPECT_DECLS;
  72989. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  72990. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72991. /* Zero length plain text */
  72992. byte key[] = {
  72993. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72994. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72995. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72996. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72997. }; /* align */
  72998. byte iv[] = {
  72999. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73000. }; /* align */
  73001. byte plaintxt[1];
  73002. int ivSz = 12;
  73003. int plaintxtSz = 0;
  73004. unsigned char tag[16];
  73005. unsigned char tag_kat[] = {
  73006. 0x53,0x0f,0x8a,0xfb,0xc7,0x45,0x36,0xb9,
  73007. 0xa9,0x63,0xb4,0xf1,0xc4,0xcb,0x73,0x8b
  73008. };
  73009. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  73010. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  73011. int ciphertxtSz = 0;
  73012. int decryptedtxtSz = 0;
  73013. int len = 0;
  73014. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  73015. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  73016. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_aes_256_gcm(), NULL, key, iv));
  73017. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73018. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  73019. plaintxtSz));
  73020. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  73021. ciphertxtSz += len;
  73022. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_GET_TAG, 16, tag));
  73023. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  73024. ExpectIntEQ(0, ciphertxtSz);
  73025. ExpectIntEQ(0, XMEMCMP(tag, tag_kat, sizeof(tag)));
  73026. EVP_CIPHER_CTX_init(de);
  73027. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_aes_256_gcm(), NULL, key, iv));
  73028. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73029. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  73030. decryptedtxtSz = len;
  73031. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_TAG, 16, tag));
  73032. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  73033. decryptedtxtSz += len;
  73034. ExpectIntEQ(0, decryptedtxtSz);
  73035. EVP_CIPHER_CTX_free(en);
  73036. EVP_CIPHER_CTX_free(de);
  73037. #endif
  73038. return EXPECT_RESULT();
  73039. }
  73040. static int test_wolfssl_EVP_aes_gcm(void)
  73041. {
  73042. EXPECT_DECLS;
  73043. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  73044. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  73045. /* A 256 bit key, AES_128 will use the first 128 bit*/
  73046. byte *key = (byte*)"01234567890123456789012345678901";
  73047. /* A 128 bit IV */
  73048. byte *iv = (byte*)"0123456789012345";
  73049. int ivSz = AES_BLOCK_SIZE;
  73050. /* Message to be encrypted */
  73051. byte *plaintxt = (byte*)"for things to change you have to change";
  73052. /* Additional non-confidential data */
  73053. byte *aad = (byte*)"Don't spend major time on minor things.";
  73054. unsigned char tag[AES_BLOCK_SIZE] = {0};
  73055. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  73056. int aadSz = (int)XSTRLEN((char*)aad);
  73057. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  73058. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  73059. int ciphertxtSz = 0;
  73060. int decryptedtxtSz = 0;
  73061. int len = 0;
  73062. int i = 0;
  73063. EVP_CIPHER_CTX en[2];
  73064. EVP_CIPHER_CTX de[2];
  73065. for (i = 0; i < 2; i++) {
  73066. EVP_CIPHER_CTX_init(&en[i]);
  73067. if (i == 0) {
  73068. /* Default uses 96-bits IV length */
  73069. #ifdef WOLFSSL_AES_128
  73070. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_gcm(), NULL,
  73071. key, iv));
  73072. #elif defined(WOLFSSL_AES_192)
  73073. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_gcm(), NULL,
  73074. key, iv));
  73075. #elif defined(WOLFSSL_AES_256)
  73076. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_gcm(), NULL,
  73077. key, iv));
  73078. #endif
  73079. }
  73080. else {
  73081. #ifdef WOLFSSL_AES_128
  73082. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_gcm(), NULL,
  73083. NULL, NULL));
  73084. #elif defined(WOLFSSL_AES_192)
  73085. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_gcm(), NULL,
  73086. NULL, NULL));
  73087. #elif defined(WOLFSSL_AES_256)
  73088. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_gcm(), NULL,
  73089. NULL, NULL));
  73090. #endif
  73091. /* non-default must to set the IV length first */
  73092. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN,
  73093. ivSz, NULL));
  73094. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  73095. }
  73096. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  73097. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  73098. plaintxtSz));
  73099. ciphertxtSz = len;
  73100. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  73101. ciphertxtSz += len;
  73102. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG,
  73103. AES_BLOCK_SIZE, tag));
  73104. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  73105. EVP_CIPHER_CTX_init(&de[i]);
  73106. if (i == 0) {
  73107. /* Default uses 96-bits IV length */
  73108. #ifdef WOLFSSL_AES_128
  73109. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  73110. key, iv));
  73111. #elif defined(WOLFSSL_AES_192)
  73112. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  73113. key, iv));
  73114. #elif defined(WOLFSSL_AES_256)
  73115. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  73116. key, iv));
  73117. #endif
  73118. }
  73119. else {
  73120. #ifdef WOLFSSL_AES_128
  73121. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  73122. NULL, NULL));
  73123. #elif defined(WOLFSSL_AES_192)
  73124. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  73125. NULL, NULL));
  73126. #elif defined(WOLFSSL_AES_256)
  73127. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  73128. NULL, NULL));
  73129. #endif
  73130. /* non-default must to set the IV length first */
  73131. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  73132. ivSz, NULL));
  73133. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  73134. }
  73135. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73136. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73137. ciphertxtSz));
  73138. decryptedtxtSz = len;
  73139. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  73140. AES_BLOCK_SIZE, tag));
  73141. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73142. decryptedtxtSz += len;
  73143. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  73144. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  73145. /* modify tag*/
  73146. if (i == 0) {
  73147. /* Default uses 96-bits IV length */
  73148. #ifdef WOLFSSL_AES_128
  73149. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  73150. key, iv));
  73151. #elif defined(WOLFSSL_AES_192)
  73152. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  73153. key, iv));
  73154. #elif defined(WOLFSSL_AES_256)
  73155. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  73156. key, iv));
  73157. #endif
  73158. }
  73159. else {
  73160. #ifdef WOLFSSL_AES_128
  73161. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  73162. NULL, NULL));
  73163. #elif defined(WOLFSSL_AES_192)
  73164. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  73165. NULL, NULL));
  73166. #elif defined(WOLFSSL_AES_256)
  73167. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  73168. NULL, NULL));
  73169. #endif
  73170. /* non-default must to set the IV length first */
  73171. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  73172. ivSz, NULL));
  73173. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  73174. }
  73175. tag[AES_BLOCK_SIZE-1]+=0xBB;
  73176. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73177. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  73178. AES_BLOCK_SIZE, tag));
  73179. /* fail due to wrong tag */
  73180. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73181. ciphertxtSz));
  73182. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73183. ExpectIntEQ(0, len);
  73184. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  73185. }
  73186. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESGCM */
  73187. return EXPECT_RESULT();
  73188. }
  73189. static int test_wolfssl_EVP_aria_gcm(void)
  73190. {
  73191. int res = TEST_SKIPPED;
  73192. #if defined(OPENSSL_EXTRA) && defined(HAVE_ARIA) && \
  73193. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  73194. /* A 256 bit key, AES_128 will use the first 128 bit*/
  73195. byte *key = (byte*)"01234567890123456789012345678901";
  73196. /* A 128 bit IV */
  73197. byte *iv = (byte*)"0123456789012345";
  73198. int ivSz = ARIA_BLOCK_SIZE;
  73199. /* Message to be encrypted */
  73200. const int plaintxtSz = 40;
  73201. byte plaintxt[WC_ARIA_GCM_GET_CIPHERTEXT_SIZE(plaintxtSz)];
  73202. XMEMCPY(plaintxt,"for things to change you have to change",plaintxtSz);
  73203. /* Additional non-confidential data */
  73204. byte *aad = (byte*)"Don't spend major time on minor things.";
  73205. unsigned char tag[ARIA_BLOCK_SIZE] = {0};
  73206. int aadSz = (int)XSTRLEN((char*)aad);
  73207. byte ciphertxt[WC_ARIA_GCM_GET_CIPHERTEXT_SIZE(plaintxtSz)];
  73208. byte decryptedtxt[plaintxtSz];
  73209. int ciphertxtSz = 0;
  73210. int decryptedtxtSz = 0;
  73211. int len = 0;
  73212. int i = 0;
  73213. #define TEST_ARIA_GCM_COUNT 6
  73214. EVP_CIPHER_CTX en[TEST_ARIA_GCM_COUNT];
  73215. EVP_CIPHER_CTX de[TEST_ARIA_GCM_COUNT];
  73216. for (i = 0; i < TEST_ARIA_GCM_COUNT; i++) {
  73217. EVP_CIPHER_CTX_init(&en[i]);
  73218. switch (i) {
  73219. case 0:
  73220. /* Default uses 96-bits IV length */
  73221. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_128_gcm(), NULL, key, iv));
  73222. break;
  73223. case 1:
  73224. /* Default uses 96-bits IV length */
  73225. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_192_gcm(), NULL, key, iv));
  73226. break;
  73227. case 2:
  73228. /* Default uses 96-bits IV length */
  73229. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_256_gcm(), NULL, key, iv));
  73230. break;
  73231. case 3:
  73232. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_128_gcm(), NULL, NULL, NULL));
  73233. /* non-default must to set the IV length first */
  73234. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73235. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  73236. break;
  73237. case 4:
  73238. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_192_gcm(), NULL, NULL, NULL));
  73239. /* non-default must to set the IV length first */
  73240. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73241. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  73242. break;
  73243. case 5:
  73244. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_256_gcm(), NULL, NULL, NULL));
  73245. /* non-default must to set the IV length first */
  73246. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73247. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  73248. break;
  73249. }
  73250. XMEMSET(ciphertxt,0,sizeof(ciphertxt));
  73251. AssertIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  73252. AssertIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt, plaintxtSz));
  73253. ciphertxtSz = len;
  73254. AssertIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  73255. AssertIntNE(0, XMEMCMP(plaintxt, ciphertxt, plaintxtSz));
  73256. ciphertxtSz += len;
  73257. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG, ARIA_BLOCK_SIZE, tag));
  73258. AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  73259. EVP_CIPHER_CTX_init(&de[i]);
  73260. switch (i) {
  73261. case 0:
  73262. /* Default uses 96-bits IV length */
  73263. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_128_gcm(), NULL, key, iv));
  73264. break;
  73265. case 1:
  73266. /* Default uses 96-bits IV length */
  73267. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_192_gcm(), NULL, key, iv));
  73268. break;
  73269. case 2:
  73270. /* Default uses 96-bits IV length */
  73271. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_256_gcm(), NULL, key, iv));
  73272. break;
  73273. case 3:
  73274. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_128_gcm(), NULL, NULL, NULL));
  73275. /* non-default must to set the IV length first */
  73276. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73277. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  73278. break;
  73279. case 4:
  73280. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_192_gcm(), NULL, NULL, NULL));
  73281. /* non-default must to set the IV length first */
  73282. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73283. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  73284. break;
  73285. case 5:
  73286. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_256_gcm(), NULL, NULL, NULL));
  73287. /* non-default must to set the IV length first */
  73288. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73289. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  73290. break;
  73291. }
  73292. XMEMSET(decryptedtxt,0,sizeof(decryptedtxt));
  73293. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73294. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt, ciphertxtSz));
  73295. decryptedtxtSz = len;
  73296. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG, ARIA_BLOCK_SIZE, tag));
  73297. AssertIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73298. decryptedtxtSz += len;
  73299. AssertIntEQ(plaintxtSz, decryptedtxtSz);
  73300. AssertIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  73301. XMEMSET(decryptedtxt,0,sizeof(decryptedtxt));
  73302. /* modify tag*/
  73303. tag[AES_BLOCK_SIZE-1]+=0xBB;
  73304. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73305. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG, ARIA_BLOCK_SIZE, tag));
  73306. /* fail due to wrong tag */
  73307. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt, ciphertxtSz));
  73308. AssertIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73309. AssertIntEQ(0, len);
  73310. AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  73311. }
  73312. res = TEST_RES_CHECK(1);
  73313. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESGCM */
  73314. return res;
  73315. }
  73316. static int test_wolfssl_EVP_aes_ccm_zeroLen(void)
  73317. {
  73318. EXPECT_DECLS;
  73319. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESCCM) && \
  73320. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  73321. /* Zero length plain text */
  73322. byte key[] = {
  73323. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73324. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73325. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73326. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73327. }; /* align */
  73328. byte iv[] = {
  73329. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73330. }; /* align */
  73331. byte plaintxt[1];
  73332. int ivSz = 12;
  73333. int plaintxtSz = 0;
  73334. unsigned char tag[16];
  73335. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  73336. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  73337. int ciphertxtSz = 0;
  73338. int decryptedtxtSz = 0;
  73339. int len = 0;
  73340. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  73341. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  73342. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_aes_256_ccm(), NULL, key, iv));
  73343. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  73344. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  73345. plaintxtSz));
  73346. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  73347. ciphertxtSz += len;
  73348. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_GET_TAG, 16, tag));
  73349. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  73350. ExpectIntEQ(0, ciphertxtSz);
  73351. EVP_CIPHER_CTX_init(de);
  73352. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_aes_256_ccm(), NULL, key, iv));
  73353. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  73354. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  73355. decryptedtxtSz = len;
  73356. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_TAG, 16, tag));
  73357. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  73358. decryptedtxtSz += len;
  73359. ExpectIntEQ(0, decryptedtxtSz);
  73360. EVP_CIPHER_CTX_free(en);
  73361. EVP_CIPHER_CTX_free(de);
  73362. #endif
  73363. return EXPECT_RESULT();
  73364. }
  73365. static int test_wolfssl_EVP_aes_ccm(void)
  73366. {
  73367. EXPECT_DECLS;
  73368. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESCCM) && \
  73369. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  73370. /* A 256 bit key, AES_128 will use the first 128 bit*/
  73371. byte *key = (byte*)"01234567890123456789012345678901";
  73372. /* A 128 bit IV */
  73373. byte *iv = (byte*)"0123456789012";
  73374. int ivSz = (int)XSTRLEN((char*)iv);
  73375. /* Message to be encrypted */
  73376. byte *plaintxt = (byte*)"for things to change you have to change";
  73377. /* Additional non-confidential data */
  73378. byte *aad = (byte*)"Don't spend major time on minor things.";
  73379. unsigned char tag[AES_BLOCK_SIZE] = {0};
  73380. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  73381. int aadSz = (int)XSTRLEN((char*)aad);
  73382. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  73383. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  73384. int ciphertxtSz = 0;
  73385. int decryptedtxtSz = 0;
  73386. int len = 0;
  73387. int i = 0;
  73388. int ret;
  73389. EVP_CIPHER_CTX en[2];
  73390. EVP_CIPHER_CTX de[2];
  73391. for (i = 0; i < 2; i++) {
  73392. EVP_CIPHER_CTX_init(&en[i]);
  73393. if (i == 0) {
  73394. /* Default uses 96-bits IV length */
  73395. #ifdef WOLFSSL_AES_128
  73396. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_ccm(), NULL,
  73397. key, iv));
  73398. #elif defined(WOLFSSL_AES_192)
  73399. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_ccm(), NULL,
  73400. key, iv));
  73401. #elif defined(WOLFSSL_AES_256)
  73402. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_ccm(), NULL,
  73403. key, iv));
  73404. #endif
  73405. }
  73406. else {
  73407. #ifdef WOLFSSL_AES_128
  73408. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_ccm(), NULL,
  73409. NULL, NULL));
  73410. #elif defined(WOLFSSL_AES_192)
  73411. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_ccm(), NULL,
  73412. NULL, NULL));
  73413. #elif defined(WOLFSSL_AES_256)
  73414. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_ccm(), NULL,
  73415. NULL, NULL));
  73416. #endif
  73417. /* non-default must to set the IV length first */
  73418. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_SET_IVLEN,
  73419. ivSz, NULL));
  73420. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  73421. }
  73422. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  73423. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  73424. plaintxtSz));
  73425. ciphertxtSz = len;
  73426. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  73427. ciphertxtSz += len;
  73428. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_GET_TAG,
  73429. AES_BLOCK_SIZE, tag));
  73430. ret = wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]);
  73431. ExpectIntEQ(ret, 1);
  73432. EVP_CIPHER_CTX_init(&de[i]);
  73433. if (i == 0) {
  73434. /* Default uses 96-bits IV length */
  73435. #ifdef WOLFSSL_AES_128
  73436. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_ccm(), NULL,
  73437. key, iv));
  73438. #elif defined(WOLFSSL_AES_192)
  73439. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_ccm(), NULL,
  73440. key, iv));
  73441. #elif defined(WOLFSSL_AES_256)
  73442. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_ccm(), NULL,
  73443. key, iv));
  73444. #endif
  73445. }
  73446. else {
  73447. #ifdef WOLFSSL_AES_128
  73448. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_ccm(), NULL,
  73449. NULL, NULL));
  73450. #elif defined(WOLFSSL_AES_192)
  73451. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_ccm(), NULL,
  73452. NULL, NULL));
  73453. #elif defined(WOLFSSL_AES_256)
  73454. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_ccm(), NULL,
  73455. NULL, NULL));
  73456. #endif
  73457. /* non-default must to set the IV length first */
  73458. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_IVLEN,
  73459. ivSz, NULL));
  73460. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  73461. }
  73462. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73463. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73464. ciphertxtSz));
  73465. decryptedtxtSz = len;
  73466. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  73467. AES_BLOCK_SIZE, tag));
  73468. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73469. decryptedtxtSz += len;
  73470. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  73471. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  73472. /* modify tag*/
  73473. tag[AES_BLOCK_SIZE-1]+=0xBB;
  73474. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73475. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  73476. AES_BLOCK_SIZE, tag));
  73477. /* fail due to wrong tag */
  73478. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73479. ciphertxtSz));
  73480. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73481. ExpectIntEQ(0, len);
  73482. ret = wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]);
  73483. ExpectIntEQ(ret, 1);
  73484. }
  73485. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESCCM */
  73486. return EXPECT_RESULT();
  73487. }
  73488. static int test_wolfssl_EVP_chacha20_poly1305(void)
  73489. {
  73490. EXPECT_DECLS;
  73491. #if defined(OPENSSL_EXTRA) && defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  73492. byte key[CHACHA20_POLY1305_AEAD_KEYSIZE];
  73493. byte iv [CHACHA20_POLY1305_AEAD_IV_SIZE];
  73494. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  73495. byte aad[] = {0xAA, 0XBB, 0xCC, 0xDD, 0xEE, 0xFF};
  73496. byte cipherText[sizeof(plainText)];
  73497. byte decryptedText[sizeof(plainText)];
  73498. byte tag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  73499. EVP_CIPHER_CTX* ctx = NULL;
  73500. int outSz;
  73501. XMEMSET(key, 0, sizeof(key));
  73502. XMEMSET(iv, 0, sizeof(iv));
  73503. /* Encrypt. */
  73504. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73505. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, NULL,
  73506. NULL), WOLFSSL_SUCCESS);
  73507. /* Invalid IV length. */
  73508. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  73509. CHACHA20_POLY1305_AEAD_IV_SIZE-1, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73510. /* Valid IV length. */
  73511. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  73512. CHACHA20_POLY1305_AEAD_IV_SIZE, NULL), WOLFSSL_SUCCESS);
  73513. /* Invalid tag length. */
  73514. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  73515. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE-1, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73516. /* Valid tag length. */
  73517. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  73518. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, NULL), WOLFSSL_SUCCESS);
  73519. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  73520. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &outSz, aad, sizeof(aad)),
  73521. WOLFSSL_SUCCESS);
  73522. ExpectIntEQ(outSz, sizeof(aad));
  73523. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  73524. sizeof(plainText)), WOLFSSL_SUCCESS);
  73525. ExpectIntEQ(outSz, sizeof(plainText));
  73526. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  73527. ExpectIntEQ(outSz, 0);
  73528. /* Invalid tag length. */
  73529. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG,
  73530. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE-1, tag), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73531. /* Valid tag length. */
  73532. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG,
  73533. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, tag), WOLFSSL_SUCCESS);
  73534. EVP_CIPHER_CTX_free(ctx);
  73535. ctx = NULL;
  73536. /* Decrypt. */
  73537. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73538. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, NULL,
  73539. NULL), WOLFSSL_SUCCESS);
  73540. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  73541. CHACHA20_POLY1305_AEAD_IV_SIZE, NULL), WOLFSSL_SUCCESS);
  73542. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  73543. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, tag), WOLFSSL_SUCCESS);
  73544. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  73545. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &outSz, aad, sizeof(aad)),
  73546. WOLFSSL_SUCCESS);
  73547. ExpectIntEQ(outSz, sizeof(aad));
  73548. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73549. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73550. ExpectIntEQ(outSz, sizeof(cipherText));
  73551. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  73552. WOLFSSL_SUCCESS);
  73553. ExpectIntEQ(outSz, 0);
  73554. EVP_CIPHER_CTX_free(ctx);
  73555. ctx = NULL;
  73556. /* Test partial Inits. CipherInit() allow setting of key and iv
  73557. * in separate calls. */
  73558. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73559. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_chacha20_poly1305(),
  73560. key, NULL, 1), WOLFSSL_SUCCESS);
  73561. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  73562. WOLFSSL_SUCCESS);
  73563. ExpectIntEQ(wolfSSL_EVP_CipherUpdate(ctx, NULL, &outSz,
  73564. aad, sizeof(aad)), WOLFSSL_SUCCESS);
  73565. ExpectIntEQ(outSz, sizeof(aad));
  73566. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73567. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73568. ExpectIntEQ(outSz, sizeof(cipherText));
  73569. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  73570. WOLFSSL_SUCCESS);
  73571. ExpectIntEQ(outSz, 0);
  73572. EVP_CIPHER_CTX_free(ctx);
  73573. #endif
  73574. return EXPECT_RESULT();
  73575. }
  73576. static int test_wolfssl_EVP_chacha20(void)
  73577. {
  73578. EXPECT_DECLS;
  73579. #if defined(OPENSSL_EXTRA) && defined(HAVE_CHACHA)
  73580. byte key[CHACHA_MAX_KEY_SZ];
  73581. byte iv [WOLFSSL_EVP_CHACHA_IV_BYTES];
  73582. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  73583. byte cipherText[sizeof(plainText)];
  73584. byte decryptedText[sizeof(plainText)];
  73585. EVP_CIPHER_CTX* ctx = NULL;
  73586. int outSz;
  73587. XMEMSET(key, 0, sizeof(key));
  73588. XMEMSET(iv, 0, sizeof(iv));
  73589. /* Encrypt. */
  73590. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73591. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_chacha20(), NULL, NULL,
  73592. NULL), WOLFSSL_SUCCESS);
  73593. /* Any tag length must fail - not an AEAD cipher. */
  73594. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  73595. 16, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73596. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  73597. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  73598. sizeof(plainText)), WOLFSSL_SUCCESS);
  73599. ExpectIntEQ(outSz, sizeof(plainText));
  73600. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  73601. ExpectIntEQ(outSz, 0);
  73602. EVP_CIPHER_CTX_free(ctx);
  73603. ctx = NULL;
  73604. /* Decrypt. */
  73605. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73606. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_chacha20(), NULL, NULL,
  73607. NULL), WOLFSSL_SUCCESS);
  73608. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  73609. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73610. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73611. ExpectIntEQ(outSz, sizeof(cipherText));
  73612. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  73613. WOLFSSL_SUCCESS);
  73614. ExpectIntEQ(outSz, 0);
  73615. EVP_CIPHER_CTX_free(ctx);
  73616. ctx = NULL;
  73617. /* Test partial Inits. CipherInit() allow setting of key and iv
  73618. * in separate calls. */
  73619. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73620. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_chacha20(),
  73621. key, NULL, 1), WOLFSSL_SUCCESS);
  73622. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  73623. WOLFSSL_SUCCESS);
  73624. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73625. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73626. ExpectIntEQ(outSz, sizeof(cipherText));
  73627. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  73628. WOLFSSL_SUCCESS);
  73629. ExpectIntEQ(outSz, 0);
  73630. EVP_CIPHER_CTX_free(ctx);
  73631. #endif
  73632. return EXPECT_RESULT();
  73633. }
  73634. static int test_wolfssl_EVP_sm4_ecb(void)
  73635. {
  73636. int res = TEST_SKIPPED;
  73637. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_ECB)
  73638. EXPECT_DECLS;
  73639. byte key[SM4_KEY_SIZE];
  73640. byte plainText[SM4_BLOCK_SIZE] = {
  73641. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
  73642. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  73643. };
  73644. byte cipherText[sizeof(plainText) + SM4_BLOCK_SIZE];
  73645. byte decryptedText[sizeof(plainText) + SM4_BLOCK_SIZE];
  73646. EVP_CIPHER_CTX* ctx;
  73647. int outSz;
  73648. XMEMSET(key, 0, sizeof(key));
  73649. /* Encrypt. */
  73650. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73651. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_ecb(), NULL, NULL, NULL),
  73652. WOLFSSL_SUCCESS);
  73653. /* Any tag length must fail - not an AEAD cipher. */
  73654. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  73655. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73656. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL),
  73657. WOLFSSL_SUCCESS);
  73658. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  73659. sizeof(plainText)), WOLFSSL_SUCCESS);
  73660. ExpectIntEQ(outSz, sizeof(plainText));
  73661. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText + outSz, &outSz),
  73662. WOLFSSL_SUCCESS);
  73663. ExpectIntEQ(outSz, SM4_BLOCK_SIZE);
  73664. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  73665. EVP_CIPHER_CTX_free(ctx);
  73666. /* Decrypt. */
  73667. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73668. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_ecb(), NULL, NULL, NULL),
  73669. WOLFSSL_SUCCESS);
  73670. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, NULL),
  73671. WOLFSSL_SUCCESS);
  73672. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73673. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73674. ExpectIntEQ(outSz, sizeof(plainText));
  73675. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  73676. WOLFSSL_SUCCESS);
  73677. ExpectIntEQ(outSz, 0);
  73678. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  73679. EVP_CIPHER_CTX_free(ctx);
  73680. res = EXPECT_RESULT();
  73681. #endif
  73682. return res;
  73683. }
  73684. static int test_wolfssl_EVP_sm4_cbc(void)
  73685. {
  73686. int res = TEST_SKIPPED;
  73687. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CBC)
  73688. EXPECT_DECLS;
  73689. byte key[SM4_KEY_SIZE];
  73690. byte iv[SM4_BLOCK_SIZE];
  73691. byte plainText[SM4_BLOCK_SIZE] = {
  73692. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
  73693. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  73694. };
  73695. byte cipherText[sizeof(plainText) + SM4_BLOCK_SIZE];
  73696. byte decryptedText[sizeof(plainText) + SM4_BLOCK_SIZE];
  73697. EVP_CIPHER_CTX* ctx;
  73698. int outSz;
  73699. XMEMSET(key, 0, sizeof(key));
  73700. XMEMSET(iv, 0, sizeof(iv));
  73701. /* Encrypt. */
  73702. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73703. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_cbc(), NULL, NULL, NULL),
  73704. WOLFSSL_SUCCESS);
  73705. /* Any tag length must fail - not an AEAD cipher. */
  73706. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  73707. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73708. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  73709. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  73710. sizeof(plainText)), WOLFSSL_SUCCESS);
  73711. ExpectIntEQ(outSz, sizeof(plainText));
  73712. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText + outSz, &outSz),
  73713. WOLFSSL_SUCCESS);
  73714. ExpectIntEQ(outSz, SM4_BLOCK_SIZE);
  73715. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  73716. EVP_CIPHER_CTX_free(ctx);
  73717. /* Decrypt. */
  73718. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73719. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_cbc(), NULL, NULL, NULL),
  73720. WOLFSSL_SUCCESS);
  73721. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  73722. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73723. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73724. ExpectIntEQ(outSz, sizeof(plainText));
  73725. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  73726. WOLFSSL_SUCCESS);
  73727. ExpectIntEQ(outSz, 0);
  73728. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  73729. EVP_CIPHER_CTX_free(ctx);
  73730. /* Test partial Inits. CipherInit() allow setting of key and iv
  73731. * in separate calls. */
  73732. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73733. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_sm4_cbc(), key, NULL, 0),
  73734. WOLFSSL_SUCCESS);
  73735. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 0),
  73736. WOLFSSL_SUCCESS);
  73737. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73738. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73739. ExpectIntEQ(outSz, sizeof(plainText));
  73740. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  73741. WOLFSSL_SUCCESS);
  73742. ExpectIntEQ(outSz, 0);
  73743. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  73744. EVP_CIPHER_CTX_free(ctx);
  73745. res = EXPECT_RESULT();
  73746. #endif
  73747. return res;
  73748. }
  73749. static int test_wolfssl_EVP_sm4_ctr(void)
  73750. {
  73751. int res = TEST_SKIPPED;
  73752. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CTR)
  73753. EXPECT_DECLS;
  73754. byte key[SM4_KEY_SIZE];
  73755. byte iv[SM4_BLOCK_SIZE];
  73756. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  73757. byte cipherText[sizeof(plainText)];
  73758. byte decryptedText[sizeof(plainText)];
  73759. EVP_CIPHER_CTX* ctx;
  73760. int outSz;
  73761. XMEMSET(key, 0, sizeof(key));
  73762. XMEMSET(iv, 0, sizeof(iv));
  73763. /* Encrypt. */
  73764. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73765. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_ctr(), NULL, NULL, NULL),
  73766. WOLFSSL_SUCCESS);
  73767. /* Any tag length must fail - not an AEAD cipher. */
  73768. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  73769. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73770. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  73771. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  73772. sizeof(plainText)), WOLFSSL_SUCCESS);
  73773. ExpectIntEQ(outSz, sizeof(plainText));
  73774. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  73775. ExpectIntEQ(outSz, 0);
  73776. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  73777. EVP_CIPHER_CTX_free(ctx);
  73778. /* Decrypt. */
  73779. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73780. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_ctr(), NULL, NULL, NULL),
  73781. WOLFSSL_SUCCESS);
  73782. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  73783. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73784. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73785. ExpectIntEQ(outSz, sizeof(cipherText));
  73786. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  73787. WOLFSSL_SUCCESS);
  73788. ExpectIntEQ(outSz, 0);
  73789. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  73790. EVP_CIPHER_CTX_free(ctx);
  73791. /* Test partial Inits. CipherInit() allow setting of key and iv
  73792. * in separate calls. */
  73793. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73794. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_sm4_ctr(), key, NULL, 1),
  73795. WOLFSSL_SUCCESS);
  73796. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  73797. WOLFSSL_SUCCESS);
  73798. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73799. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73800. ExpectIntEQ(outSz, sizeof(cipherText));
  73801. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  73802. WOLFSSL_SUCCESS);
  73803. ExpectIntEQ(outSz, 0);
  73804. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  73805. EVP_CIPHER_CTX_free(ctx);
  73806. res = EXPECT_RESULT();
  73807. #endif
  73808. return res;
  73809. }
  73810. static int test_wolfssl_EVP_sm4_gcm_zeroLen(void)
  73811. {
  73812. int res = TEST_SKIPPED;
  73813. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_GCM)
  73814. /* Zero length plain text */
  73815. EXPECT_DECLS;
  73816. byte key[] = {
  73817. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73818. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73819. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73820. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73821. }; /* align */
  73822. byte iv[] = {
  73823. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73824. }; /* align */
  73825. byte plaintxt[1];
  73826. int ivSz = 12;
  73827. int plaintxtSz = 0;
  73828. unsigned char tag[16];
  73829. unsigned char tag_kat[16] = {
  73830. 0x23,0x2f,0x0c,0xfe,0x30,0x8b,0x49,0xea,
  73831. 0x6f,0xc8,0x82,0x29,0xb5,0xdc,0x85,0x8d
  73832. };
  73833. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  73834. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  73835. int ciphertxtSz = 0;
  73836. int decryptedtxtSz = 0;
  73837. int len = 0;
  73838. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  73839. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  73840. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_sm4_gcm(), NULL, key, iv));
  73841. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73842. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  73843. plaintxtSz));
  73844. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  73845. ciphertxtSz += len;
  73846. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_GET_TAG, 16, tag));
  73847. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  73848. ExpectIntEQ(0, ciphertxtSz);
  73849. ExpectIntEQ(0, XMEMCMP(tag, tag_kat, sizeof(tag)));
  73850. EVP_CIPHER_CTX_init(de);
  73851. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_sm4_gcm(), NULL, key, iv));
  73852. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73853. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  73854. decryptedtxtSz = len;
  73855. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_TAG, 16, tag));
  73856. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  73857. decryptedtxtSz += len;
  73858. ExpectIntEQ(0, decryptedtxtSz);
  73859. EVP_CIPHER_CTX_free(en);
  73860. EVP_CIPHER_CTX_free(de);
  73861. res = EXPECT_RESULT();
  73862. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_GCM */
  73863. return res;
  73864. }
  73865. static int test_wolfssl_EVP_sm4_gcm(void)
  73866. {
  73867. int res = TEST_SKIPPED;
  73868. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_GCM)
  73869. EXPECT_DECLS;
  73870. byte *key = (byte*)"0123456789012345";
  73871. /* A 128 bit IV */
  73872. byte *iv = (byte*)"0123456789012345";
  73873. int ivSz = SM4_BLOCK_SIZE;
  73874. /* Message to be encrypted */
  73875. byte *plaintxt = (byte*)"for things to change you have to change";
  73876. /* Additional non-confidential data */
  73877. byte *aad = (byte*)"Don't spend major time on minor things.";
  73878. unsigned char tag[SM4_BLOCK_SIZE] = {0};
  73879. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  73880. int aadSz = (int)XSTRLEN((char*)aad);
  73881. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  73882. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  73883. int ciphertxtSz = 0;
  73884. int decryptedtxtSz = 0;
  73885. int len = 0;
  73886. int i = 0;
  73887. EVP_CIPHER_CTX en[2];
  73888. EVP_CIPHER_CTX de[2];
  73889. for (i = 0; i < 2; i++) {
  73890. EVP_CIPHER_CTX_init(&en[i]);
  73891. if (i == 0) {
  73892. /* Default uses 96-bits IV length */
  73893. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_gcm(), NULL, key,
  73894. iv));
  73895. }
  73896. else {
  73897. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_gcm(), NULL, NULL,
  73898. NULL));
  73899. /* non-default must to set the IV length first */
  73900. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN,
  73901. ivSz, NULL));
  73902. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  73903. }
  73904. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  73905. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  73906. plaintxtSz));
  73907. ciphertxtSz = len;
  73908. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  73909. ciphertxtSz += len;
  73910. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG,
  73911. SM4_BLOCK_SIZE, tag));
  73912. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  73913. EVP_CIPHER_CTX_init(&de[i]);
  73914. if (i == 0) {
  73915. /* Default uses 96-bits IV length */
  73916. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_gcm(), NULL, key,
  73917. iv));
  73918. }
  73919. else {
  73920. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_gcm(), NULL, NULL,
  73921. NULL));
  73922. /* non-default must to set the IV length first */
  73923. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  73924. ivSz, NULL));
  73925. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  73926. }
  73927. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73928. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73929. ciphertxtSz));
  73930. decryptedtxtSz = len;
  73931. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  73932. SM4_BLOCK_SIZE, tag));
  73933. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73934. decryptedtxtSz += len;
  73935. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  73936. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  73937. /* modify tag*/
  73938. tag[SM4_BLOCK_SIZE-1]+=0xBB;
  73939. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73940. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  73941. SM4_BLOCK_SIZE, tag));
  73942. /* fail due to wrong tag */
  73943. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73944. ciphertxtSz));
  73945. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73946. ExpectIntEQ(0, len);
  73947. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  73948. }
  73949. res = EXPECT_RESULT();
  73950. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_GCM */
  73951. return res;
  73952. }
  73953. static int test_wolfssl_EVP_sm4_ccm_zeroLen(void)
  73954. {
  73955. int res = TEST_SKIPPED;
  73956. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CCM)
  73957. /* Zero length plain text */
  73958. EXPECT_DECLS;
  73959. byte key[] = {
  73960. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73961. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73962. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73963. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73964. }; /* align */
  73965. byte iv[] = {
  73966. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73967. }; /* align */
  73968. byte plaintxt[1];
  73969. int ivSz = 12;
  73970. int plaintxtSz = 0;
  73971. unsigned char tag[16];
  73972. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  73973. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  73974. int ciphertxtSz = 0;
  73975. int decryptedtxtSz = 0;
  73976. int len = 0;
  73977. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  73978. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  73979. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_sm4_ccm(), NULL, key, iv));
  73980. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  73981. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  73982. plaintxtSz));
  73983. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  73984. ciphertxtSz += len;
  73985. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_GET_TAG, 16, tag));
  73986. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  73987. ExpectIntEQ(0, ciphertxtSz);
  73988. EVP_CIPHER_CTX_init(de);
  73989. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_sm4_ccm(), NULL, key, iv));
  73990. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  73991. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  73992. decryptedtxtSz = len;
  73993. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_TAG, 16, tag));
  73994. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  73995. decryptedtxtSz += len;
  73996. ExpectIntEQ(0, decryptedtxtSz);
  73997. EVP_CIPHER_CTX_free(en);
  73998. EVP_CIPHER_CTX_free(de);
  73999. res = EXPECT_RESULT();
  74000. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_CCM */
  74001. return res;
  74002. }
  74003. static int test_wolfssl_EVP_sm4_ccm(void)
  74004. {
  74005. int res = TEST_SKIPPED;
  74006. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CCM)
  74007. EXPECT_DECLS;
  74008. byte *key = (byte*)"0123456789012345";
  74009. byte *iv = (byte*)"0123456789012";
  74010. int ivSz = (int)XSTRLEN((char*)iv);
  74011. /* Message to be encrypted */
  74012. byte *plaintxt = (byte*)"for things to change you have to change";
  74013. /* Additional non-confidential data */
  74014. byte *aad = (byte*)"Don't spend major time on minor things.";
  74015. unsigned char tag[SM4_BLOCK_SIZE] = {0};
  74016. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  74017. int aadSz = (int)XSTRLEN((char*)aad);
  74018. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  74019. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  74020. int ciphertxtSz = 0;
  74021. int decryptedtxtSz = 0;
  74022. int len = 0;
  74023. int i = 0;
  74024. EVP_CIPHER_CTX en[2];
  74025. EVP_CIPHER_CTX de[2];
  74026. for (i = 0; i < 2; i++) {
  74027. EVP_CIPHER_CTX_init(&en[i]);
  74028. if (i == 0) {
  74029. /* Default uses 96-bits IV length */
  74030. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_ccm(), NULL, key,
  74031. iv));
  74032. }
  74033. else {
  74034. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_ccm(), NULL, NULL,
  74035. NULL));
  74036. /* non-default must to set the IV length first */
  74037. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_SET_IVLEN,
  74038. ivSz, NULL));
  74039. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  74040. }
  74041. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  74042. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  74043. plaintxtSz));
  74044. ciphertxtSz = len;
  74045. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  74046. ciphertxtSz += len;
  74047. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_GET_TAG,
  74048. SM4_BLOCK_SIZE, tag));
  74049. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  74050. EVP_CIPHER_CTX_init(&de[i]);
  74051. if (i == 0) {
  74052. /* Default uses 96-bits IV length */
  74053. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_ccm(), NULL, key,
  74054. iv));
  74055. }
  74056. else {
  74057. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_ccm(), NULL, NULL,
  74058. NULL));
  74059. /* non-default must to set the IV length first */
  74060. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_IVLEN,
  74061. ivSz, NULL));
  74062. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  74063. }
  74064. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  74065. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  74066. ciphertxtSz));
  74067. decryptedtxtSz = len;
  74068. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  74069. SM4_BLOCK_SIZE, tag));
  74070. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  74071. decryptedtxtSz += len;
  74072. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  74073. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  74074. /* modify tag*/
  74075. tag[SM4_BLOCK_SIZE-1]+=0xBB;
  74076. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  74077. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  74078. SM4_BLOCK_SIZE, tag));
  74079. /* fail due to wrong tag */
  74080. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  74081. ciphertxtSz));
  74082. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  74083. ExpectIntEQ(0, len);
  74084. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  74085. }
  74086. res = EXPECT_RESULT();
  74087. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_CCM */
  74088. return res;
  74089. }
  74090. static int test_wolfSSL_EVP_PKEY_hkdf(void)
  74091. {
  74092. EXPECT_DECLS;
  74093. #if defined(OPENSSL_EXTRA) && defined(HAVE_HKDF)
  74094. EVP_PKEY_CTX* ctx = NULL;
  74095. byte salt[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  74096. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
  74097. byte key[] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  74098. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  74099. byte info[] = {0X01, 0x02, 0x03, 0x04, 0x05};
  74100. byte info2[] = {0X06, 0x07, 0x08, 0x09, 0x0A};
  74101. byte outKey[34];
  74102. size_t outKeySz = sizeof(outKey);
  74103. /* These expected outputs were gathered by running the same test below using
  74104. * OpenSSL. */
  74105. const byte extractAndExpand[] = {
  74106. 0x8B, 0xEB, 0x90, 0xA9, 0x04, 0xFF, 0x05, 0x10, 0xE4, 0xB5, 0xB1, 0x10,
  74107. 0x31, 0x34, 0xFF, 0x07, 0x5B, 0xE3, 0xC6, 0x93, 0xD4, 0xF8, 0xC7, 0xEE,
  74108. 0x96, 0xDA, 0x78, 0x7A, 0xE2, 0x9A, 0x2D, 0x05, 0x4B, 0xF6
  74109. };
  74110. const byte extractOnly[] = {
  74111. 0xE7, 0x6B, 0x9E, 0x0F, 0xE4, 0x02, 0x1D, 0x62, 0xEA, 0x97, 0x74, 0x5E,
  74112. 0xF4, 0x3C, 0x65, 0x4D, 0xC1, 0x46, 0x98, 0xAA, 0x79, 0x9A, 0xCB, 0x9C,
  74113. 0xCC, 0x3E, 0x7F, 0x2A, 0x2B, 0x41, 0xA1, 0x9E
  74114. };
  74115. const byte expandOnly[] = {
  74116. 0xFF, 0x29, 0x29, 0x56, 0x9E, 0xA7, 0x66, 0x02, 0xDB, 0x4F, 0xDB, 0x53,
  74117. 0x7D, 0x21, 0x67, 0x52, 0xC3, 0x0E, 0xF3, 0xFC, 0x71, 0xCE, 0x67, 0x2B,
  74118. 0xEA, 0x3B, 0xE9, 0xFC, 0xDD, 0xC8, 0xCC, 0xB7, 0x42, 0x74
  74119. };
  74120. const byte extractAndExpandAddInfo[] = {
  74121. 0x5A, 0x74, 0x79, 0x83, 0xA3, 0xA4, 0x2E, 0xB7, 0xD4, 0x08, 0xC2, 0x6A,
  74122. 0x2F, 0xA5, 0xE3, 0x4E, 0xF1, 0xF4, 0x87, 0x3E, 0xA6, 0xC7, 0x88, 0x45,
  74123. 0xD7, 0xE2, 0x15, 0xBC, 0xB8, 0x10, 0xEF, 0x6C, 0x4D, 0x7A
  74124. };
  74125. ExpectNotNull((ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL)));
  74126. ExpectIntEQ(EVP_PKEY_derive_init(ctx), WOLFSSL_SUCCESS);
  74127. /* NULL ctx. */
  74128. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(NULL, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74129. /* NULL md. */
  74130. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74131. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(ctx, EVP_sha256()), WOLFSSL_SUCCESS);
  74132. /* NULL ctx. */
  74133. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(NULL, salt, sizeof(salt)),
  74134. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74135. /* NULL salt is ok. */
  74136. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, NULL, sizeof(salt)),
  74137. WOLFSSL_SUCCESS);
  74138. /* Salt length <= 0. */
  74139. /* Length 0 salt is ok. */
  74140. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, 0), WOLFSSL_SUCCESS);
  74141. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74142. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, sizeof(salt)),
  74143. WOLFSSL_SUCCESS);
  74144. /* NULL ctx. */
  74145. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(NULL, key, sizeof(key)),
  74146. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74147. /* NULL key. */
  74148. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, NULL, sizeof(key)),
  74149. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74150. /* Key length <= 0 */
  74151. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74152. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74153. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, sizeof(key)),
  74154. WOLFSSL_SUCCESS);
  74155. /* NULL ctx. */
  74156. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(NULL, info, sizeof(info)),
  74157. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74158. /* NULL info is ok. */
  74159. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, NULL, sizeof(info)),
  74160. WOLFSSL_SUCCESS);
  74161. /* Info length <= 0 */
  74162. /* Length 0 info is ok. */
  74163. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, 0), WOLFSSL_SUCCESS);
  74164. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74165. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, sizeof(info)),
  74166. WOLFSSL_SUCCESS);
  74167. /* NULL ctx. */
  74168. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(NULL, EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY),
  74169. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74170. /* Extract and expand (default). */
  74171. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  74172. ExpectIntEQ(outKeySz, sizeof(extractAndExpand));
  74173. ExpectIntEQ(XMEMCMP(outKey, extractAndExpand, outKeySz), 0);
  74174. /* Extract only. */
  74175. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx, EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY),
  74176. WOLFSSL_SUCCESS);
  74177. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  74178. ExpectIntEQ(outKeySz, sizeof(extractOnly));
  74179. ExpectIntEQ(XMEMCMP(outKey, extractOnly, outKeySz), 0);
  74180. outKeySz = sizeof(outKey);
  74181. /* Expand only. */
  74182. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx, EVP_PKEY_HKDEF_MODE_EXPAND_ONLY),
  74183. WOLFSSL_SUCCESS);
  74184. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  74185. ExpectIntEQ(outKeySz, sizeof(expandOnly));
  74186. ExpectIntEQ(XMEMCMP(outKey, expandOnly, outKeySz), 0);
  74187. outKeySz = sizeof(outKey);
  74188. /* Extract and expand with appended additional info. */
  74189. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info2, sizeof(info2)),
  74190. WOLFSSL_SUCCESS);
  74191. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx,
  74192. EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND), WOLFSSL_SUCCESS);
  74193. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  74194. ExpectIntEQ(outKeySz, sizeof(extractAndExpandAddInfo));
  74195. ExpectIntEQ(XMEMCMP(outKey, extractAndExpandAddInfo, outKeySz), 0);
  74196. EVP_PKEY_CTX_free(ctx);
  74197. #endif /* OPENSSL_EXTRA && HAVE_HKDF */
  74198. return EXPECT_RESULT();
  74199. }
  74200. #ifndef NO_BIO
  74201. static int test_wolfSSL_PEM_X509_INFO_read_bio(void)
  74202. {
  74203. EXPECT_DECLS;
  74204. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  74205. BIO* bio = NULL;
  74206. X509_INFO* info = NULL;
  74207. STACK_OF(X509_INFO)* sk = NULL;
  74208. char* subject = NULL;
  74209. char exp1[] = "/C=US/ST=Montana/L=Bozeman/O=Sawtooth/OU=Consulting/"
  74210. "CN=www.wolfssl.com/emailAddress=info@wolfssl.com";
  74211. char exp2[] = "/C=US/ST=Montana/L=Bozeman/O=wolfSSL/OU=Support/"
  74212. "CN=www.wolfssl.com/emailAddress=info@wolfssl.com";
  74213. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  74214. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  74215. ExpectNotNull(sk = PEM_X509_INFO_read_bio(bio, NULL, NULL, NULL));
  74216. ExpectIntEQ(sk_X509_INFO_num(sk), 2);
  74217. /* using dereference to maintain testing for Apache port*/
  74218. ExpectNotNull(info = sk_X509_INFO_pop(sk));
  74219. ExpectNotNull(subject = X509_NAME_oneline(X509_get_subject_name(info->x509),
  74220. 0, 0));
  74221. ExpectIntEQ(0, XSTRNCMP(subject, exp1, sizeof(exp1)));
  74222. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  74223. X509_INFO_free(info);
  74224. info = NULL;
  74225. ExpectNotNull(info = sk_X509_INFO_pop(sk));
  74226. ExpectNotNull(subject = X509_NAME_oneline(X509_get_subject_name(info->x509),
  74227. 0, 0));
  74228. ExpectIntEQ(0, XSTRNCMP(subject, exp2, sizeof(exp2)));
  74229. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  74230. X509_INFO_free(info);
  74231. ExpectNull(info = sk_X509_INFO_pop(sk));
  74232. sk_X509_INFO_pop_free(sk, X509_INFO_free);
  74233. BIO_free(bio);
  74234. #endif
  74235. return EXPECT_RESULT();
  74236. }
  74237. #endif /* !NO_BIO */
  74238. static int test_wolfSSL_X509_NAME_ENTRY_get_object(void)
  74239. {
  74240. EXPECT_DECLS;
  74241. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  74242. X509 *x509 = NULL;
  74243. X509_NAME* name = NULL;
  74244. int idx = 0;
  74245. X509_NAME_ENTRY *ne = NULL;
  74246. ASN1_OBJECT *object = NULL;
  74247. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  74248. WOLFSSL_FILETYPE_PEM));
  74249. ExpectNotNull(name = X509_get_subject_name(x509));
  74250. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  74251. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  74252. ExpectNotNull(object = X509_NAME_ENTRY_get_object(ne));
  74253. X509_free(x509);
  74254. #endif
  74255. return EXPECT_RESULT();
  74256. }
  74257. static int test_wolfSSL_X509_STORE_get1_certs(void)
  74258. {
  74259. EXPECT_DECLS;
  74260. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SIGNER_DER_CERT) && \
  74261. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  74262. X509_STORE_CTX *storeCtx = NULL;
  74263. X509_STORE *store = NULL;
  74264. X509 *caX509 = NULL;
  74265. X509 *svrX509 = NULL;
  74266. X509_NAME *subject = NULL;
  74267. WOLF_STACK_OF(WOLFSSL_X509) *certs = NULL;
  74268. ExpectNotNull(caX509 = X509_load_certificate_file(caCertFile,
  74269. SSL_FILETYPE_PEM));
  74270. ExpectNotNull((svrX509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  74271. SSL_FILETYPE_PEM)));
  74272. ExpectNotNull(storeCtx = X509_STORE_CTX_new());
  74273. ExpectNotNull(store = X509_STORE_new());
  74274. ExpectNotNull(subject = X509_get_subject_name(caX509));
  74275. /* Errors */
  74276. ExpectNull(X509_STORE_get1_certs(storeCtx, subject));
  74277. ExpectNull(X509_STORE_get1_certs(NULL, subject));
  74278. ExpectNull(X509_STORE_get1_certs(storeCtx, NULL));
  74279. ExpectIntEQ(X509_STORE_add_cert(store, caX509), SSL_SUCCESS);
  74280. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, caX509, NULL),
  74281. SSL_SUCCESS);
  74282. /* Should find the cert */
  74283. ExpectNotNull(certs = X509_STORE_get1_certs(storeCtx, subject));
  74284. ExpectIntEQ(1, wolfSSL_sk_X509_num(certs));
  74285. sk_X509_pop_free(certs, NULL);
  74286. certs = NULL;
  74287. /* Should not find the cert */
  74288. ExpectNotNull(subject = X509_get_subject_name(svrX509));
  74289. ExpectNotNull(certs = X509_STORE_get1_certs(storeCtx, subject));
  74290. ExpectIntEQ(0, wolfSSL_sk_X509_num(certs));
  74291. sk_X509_pop_free(certs, NULL);
  74292. certs = NULL;
  74293. X509_STORE_free(store);
  74294. X509_STORE_CTX_free(storeCtx);
  74295. X509_free(svrX509);
  74296. X509_free(caX509);
  74297. #endif /* OPENSSL_EXTRA && WOLFSSL_SIGNER_DER_CERT && !NO_FILESYSTEM */
  74298. return EXPECT_RESULT();
  74299. }
  74300. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  74301. defined(WOLFSSL_LOCAL_X509_STORE) && \
  74302. (defined(OPENSSL_ALL) || defined(WOLFSSL_QT)) && defined(HAVE_CRL)
  74303. static int test_wolfSSL_X509_STORE_set_get_crl_provider(X509_STORE_CTX* ctx,
  74304. X509_CRL** crl_out, X509* cert) {
  74305. X509_CRL *crl = NULL;
  74306. XFILE fp = XBADFILE;
  74307. char* cert_issuer = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0);
  74308. int ret = 0;
  74309. (void)ctx;
  74310. if (cert_issuer == NULL)
  74311. return 0;
  74312. if ((fp = XFOPEN("certs/crl/crl.pem", "rb")) != XBADFILE) {
  74313. PEM_read_X509_CRL(fp, &crl, NULL, NULL);
  74314. XFCLOSE(fp);
  74315. if (crl != NULL) {
  74316. char* crl_issuer = X509_NAME_oneline(
  74317. X509_CRL_get_issuer(crl), NULL, 0);
  74318. if ((crl_issuer != NULL) &&
  74319. (XSTRCMP(cert_issuer, crl_issuer) == 0)) {
  74320. *crl_out = X509_CRL_dup(crl);
  74321. if (*crl_out != NULL)
  74322. ret = 1;
  74323. }
  74324. OPENSSL_free(crl_issuer);
  74325. }
  74326. }
  74327. X509_CRL_free(crl);
  74328. OPENSSL_free(cert_issuer);
  74329. return ret;
  74330. }
  74331. static int test_wolfSSL_X509_STORE_set_get_crl_provider2(X509_STORE_CTX* ctx,
  74332. X509_CRL** crl_out, X509* cert) {
  74333. (void)ctx;
  74334. (void)cert;
  74335. *crl_out = NULL;
  74336. return 1;
  74337. }
  74338. #ifndef NO_WOLFSSL_STUB
  74339. static int test_wolfSSL_X509_STORE_set_get_crl_check(X509_STORE_CTX* ctx,
  74340. X509_CRL* crl) {
  74341. (void)ctx;
  74342. (void)crl;
  74343. return 1;
  74344. }
  74345. #endif
  74346. static int test_wolfSSL_X509_STORE_set_get_crl_verify(int ok,
  74347. X509_STORE_CTX* ctx) {
  74348. int cert_error = X509_STORE_CTX_get_error(ctx);
  74349. X509_VERIFY_PARAM* param = X509_STORE_CTX_get0_param(ctx);
  74350. int flags = X509_VERIFY_PARAM_get_flags(param);
  74351. if ((flags & (X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL)) !=
  74352. (X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL)) {
  74353. /* Make sure the flags are set */
  74354. return 0;
  74355. }
  74356. /* Ignore CRL missing error */
  74357. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  74358. if (cert_error == WC_NO_ERR_TRACE(CRL_MISSING))
  74359. #else
  74360. if (cert_error == X509_V_ERR_UNABLE_TO_GET_CRL)
  74361. #endif
  74362. return 1;
  74363. return ok;
  74364. }
  74365. static int test_wolfSSL_X509_STORE_set_get_crl_ctx_ready(WOLFSSL_CTX* ctx)
  74366. {
  74367. EXPECT_DECLS;
  74368. X509_STORE* cert_store = NULL;
  74369. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  74370. WOLFSSL_SUCCESS);
  74371. ExpectNotNull(cert_store = SSL_CTX_get_cert_store(ctx));
  74372. X509_STORE_set_get_crl(cert_store,
  74373. test_wolfSSL_X509_STORE_set_get_crl_provider);
  74374. #ifndef NO_WOLFSSL_STUB
  74375. X509_STORE_set_check_crl(cert_store,
  74376. test_wolfSSL_X509_STORE_set_get_crl_check);
  74377. #endif
  74378. return EXPECT_RESULT();
  74379. }
  74380. static int test_wolfSSL_X509_STORE_set_get_crl_ctx_ready2(WOLFSSL_CTX* ctx)
  74381. {
  74382. EXPECT_DECLS;
  74383. X509_STORE* cert_store = NULL;
  74384. X509_VERIFY_PARAM* param = NULL;
  74385. SSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  74386. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  74387. WOLFSSL_SUCCESS);
  74388. ExpectNotNull(cert_store = SSL_CTX_get_cert_store(ctx));
  74389. X509_STORE_set_get_crl(cert_store,
  74390. test_wolfSSL_X509_STORE_set_get_crl_provider2);
  74391. #ifndef NO_WOLFSSL_STUB
  74392. X509_STORE_set_check_crl(cert_store,
  74393. test_wolfSSL_X509_STORE_set_get_crl_check);
  74394. #endif
  74395. X509_STORE_set_verify_cb(cert_store,
  74396. test_wolfSSL_X509_STORE_set_get_crl_verify);
  74397. ExpectNotNull(X509_STORE_get0_param(cert_store));
  74398. ExpectNotNull(param = X509_VERIFY_PARAM_new());
  74399. ExpectIntEQ(X509_VERIFY_PARAM_inherit(param,
  74400. X509_STORE_get0_param(cert_store)), 1);
  74401. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(
  74402. param, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL), 1);
  74403. ExpectIntEQ(X509_STORE_set1_param(cert_store, param), 1);
  74404. ExpectIntEQ(X509_STORE_set_flags(cert_store,
  74405. X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL), 1);
  74406. X509_VERIFY_PARAM_free(param);
  74407. return EXPECT_RESULT();
  74408. }
  74409. #endif
  74410. /* This test mimics the usage of the CRL provider in gRPC */
  74411. static int test_wolfSSL_X509_STORE_set_get_crl(void)
  74412. {
  74413. EXPECT_DECLS;
  74414. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  74415. defined(WOLFSSL_LOCAL_X509_STORE) && \
  74416. (defined(OPENSSL_ALL) || defined(WOLFSSL_QT)) && defined(HAVE_CRL)
  74417. test_ssl_cbf func_cb_client;
  74418. test_ssl_cbf func_cb_server;
  74419. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  74420. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  74421. func_cb_client.ctx_ready = test_wolfSSL_X509_STORE_set_get_crl_ctx_ready;
  74422. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  74423. &func_cb_server, NULL), TEST_SUCCESS);
  74424. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  74425. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  74426. func_cb_client.ctx_ready = test_wolfSSL_X509_STORE_set_get_crl_ctx_ready2;
  74427. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  74428. &func_cb_server, NULL), TEST_SUCCESS);
  74429. #endif
  74430. return EXPECT_RESULT();
  74431. }
  74432. static int test_wolfSSL_dup_CA_list(void)
  74433. {
  74434. int res = TEST_SKIPPED;
  74435. #if defined(OPENSSL_ALL)
  74436. EXPECT_DECLS;
  74437. STACK_OF(X509_NAME) *originalStack = NULL;
  74438. STACK_OF(X509_NAME) *copyStack = NULL;
  74439. int originalCount = 0;
  74440. int copyCount = 0;
  74441. X509_NAME *name = NULL;
  74442. int i;
  74443. originalStack = sk_X509_NAME_new_null();
  74444. ExpectNotNull(originalStack);
  74445. for (i = 0; i < 3; i++) {
  74446. name = X509_NAME_new();
  74447. ExpectNotNull(name);
  74448. ExpectIntEQ(sk_X509_NAME_push(originalStack, name), i+1);
  74449. if (EXPECT_FAIL()) {
  74450. X509_NAME_free(name);
  74451. }
  74452. }
  74453. copyStack = SSL_dup_CA_list(originalStack);
  74454. ExpectNotNull(copyStack);
  74455. originalCount = sk_X509_NAME_num(originalStack);
  74456. copyCount = sk_X509_NAME_num(copyStack);
  74457. ExpectIntEQ(originalCount, copyCount);
  74458. sk_X509_NAME_pop_free(originalStack, X509_NAME_free);
  74459. sk_X509_NAME_pop_free(copyStack, X509_NAME_free);
  74460. originalStack = NULL;
  74461. copyStack = NULL;
  74462. res = EXPECT_RESULT();
  74463. #endif /* OPENSSL_ALL */
  74464. return res;
  74465. }
  74466. static int test_ForceZero(void)
  74467. {
  74468. EXPECT_DECLS;
  74469. unsigned char data[32];
  74470. unsigned int i, j, len;
  74471. /* Test case with 0 length */
  74472. ForceZero(data, 0);
  74473. /* Test ForceZero */
  74474. for (i = 0; i < sizeof(data); i++) {
  74475. for (len = 1; len < sizeof(data) - i; len++) {
  74476. for (j = 0; j < sizeof(data); j++)
  74477. data[j] = ((unsigned char)j + 1);
  74478. ForceZero(data + i, len);
  74479. for (j = 0; j < sizeof(data); j++) {
  74480. if (j < i || j >= i + len) {
  74481. ExpectIntNE(data[j], 0x00);
  74482. }
  74483. else {
  74484. ExpectIntEQ(data[j], 0x00);
  74485. }
  74486. }
  74487. }
  74488. }
  74489. return EXPECT_RESULT();
  74490. }
  74491. #ifndef NO_BIO
  74492. static int test_wolfSSL_X509_print(void)
  74493. {
  74494. EXPECT_DECLS;
  74495. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  74496. !defined(NO_RSA) && defined(XSNPRINTF)
  74497. X509 *x509 = NULL;
  74498. BIO *bio = NULL;
  74499. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_DIR)
  74500. const X509_ALGOR *cert_sig_alg = NULL;
  74501. #endif
  74502. ExpectNotNull(x509 = X509_load_certificate_file(svrCertFile,
  74503. WOLFSSL_FILETYPE_PEM));
  74504. /* print to memory */
  74505. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  74506. ExpectIntEQ(X509_print(bio, x509), SSL_SUCCESS);
  74507. #if defined(OPENSSL_ALL) || defined(WOLFSSL_IP_ALT_NAME)
  74508. #if defined(WC_DISABLE_RADIX_ZERO_PAD)
  74509. /* Will print IP address subject alt name. */
  74510. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3349);
  74511. #elif defined(NO_ASN_TIME)
  74512. /* Will print IP address subject alt name but not Validity. */
  74513. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3235);
  74514. #else
  74515. /* Will print IP address subject alt name. */
  74516. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3350);
  74517. #endif
  74518. #elif defined(NO_ASN_TIME)
  74519. /* With NO_ASN_TIME defined, X509_print skips printing Validity. */
  74520. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3213);
  74521. #else
  74522. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3328);
  74523. #endif
  74524. BIO_free(bio);
  74525. bio = NULL;
  74526. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  74527. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_DIR)
  74528. /* Print signature */
  74529. ExpectNotNull(cert_sig_alg = X509_get0_tbs_sigalg(x509));
  74530. ExpectIntEQ(X509_signature_print(bio, cert_sig_alg, NULL), SSL_SUCCESS);
  74531. #endif
  74532. /* print to stderr */
  74533. #if !defined(NO_WOLFSSL_DIR)
  74534. ExpectIntEQ(X509_print(bio, x509), SSL_SUCCESS);
  74535. #endif
  74536. /* print again */
  74537. ExpectIntEQ(X509_print_fp(stderr, x509), SSL_SUCCESS);
  74538. X509_free(x509);
  74539. BIO_free(bio);
  74540. #endif
  74541. return EXPECT_RESULT();
  74542. }
  74543. static int test_wolfSSL_X509_CRL_print(void)
  74544. {
  74545. EXPECT_DECLS;
  74546. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && defined(HAVE_CRL)\
  74547. && !defined(NO_FILESYSTEM) && defined(XSNPRINTF)
  74548. X509_CRL* crl = NULL;
  74549. BIO *bio = NULL;
  74550. XFILE fp = XBADFILE;
  74551. ExpectTrue((fp = XFOPEN("./certs/crl/crl.pem", "rb")) != XBADFILE);
  74552. ExpectNotNull(crl = (X509_CRL*)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  74553. NULL, NULL));
  74554. if (fp != XBADFILE)
  74555. XFCLOSE(fp);
  74556. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  74557. ExpectIntEQ(X509_CRL_print(bio, crl), SSL_SUCCESS);
  74558. X509_CRL_free(crl);
  74559. BIO_free(bio);
  74560. #endif
  74561. return EXPECT_RESULT();
  74562. }
  74563. static int test_wolfSSL_BIO_get_len(void)
  74564. {
  74565. EXPECT_DECLS;
  74566. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  74567. BIO *bio = NULL;
  74568. const char txt[] = "Some example text to push to the BIO.";
  74569. ExpectIntEQ(wolfSSL_BIO_get_len(bio), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74570. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  74571. ExpectIntEQ(wolfSSL_BIO_write(bio, txt, sizeof(txt)), sizeof(txt));
  74572. ExpectIntEQ(wolfSSL_BIO_get_len(bio), sizeof(txt));
  74573. BIO_free(bio);
  74574. bio = NULL;
  74575. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  74576. ExpectIntEQ(wolfSSL_BIO_get_len(bio), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  74577. BIO_free(bio);
  74578. #endif
  74579. return EXPECT_RESULT();
  74580. }
  74581. #endif /* !NO_BIO */
  74582. static int test_wolfSSL_RSA(void)
  74583. {
  74584. EXPECT_DECLS;
  74585. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  74586. RSA* rsa = NULL;
  74587. const BIGNUM *n = NULL;
  74588. const BIGNUM *e = NULL;
  74589. const BIGNUM *d = NULL;
  74590. const BIGNUM *p = NULL;
  74591. const BIGNUM *q = NULL;
  74592. const BIGNUM *dmp1 = NULL;
  74593. const BIGNUM *dmq1 = NULL;
  74594. const BIGNUM *iqmp = NULL;
  74595. ExpectNotNull(rsa = RSA_new());
  74596. ExpectIntEQ(RSA_size(NULL), 0);
  74597. ExpectIntEQ(RSA_size(rsa), 0);
  74598. ExpectIntEQ(RSA_set0_key(rsa, NULL, NULL, NULL), 0);
  74599. ExpectIntEQ(RSA_set0_crt_params(rsa, NULL, NULL, NULL), 0);
  74600. ExpectIntEQ(RSA_set0_factors(rsa, NULL, NULL), 0);
  74601. #ifdef WOLFSSL_RSA_KEY_CHECK
  74602. ExpectIntEQ(RSA_check_key(rsa), 0);
  74603. #endif
  74604. RSA_free(rsa);
  74605. rsa = NULL;
  74606. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  74607. ExpectIntEQ(RSA_size(rsa), 256);
  74608. #if (!defined(HAVE_FIPS) || FIPS_VERSION3_GT(6,0,0)) && !defined(HAVE_SELFTEST)
  74609. {
  74610. /* Test setting only subset of parameters */
  74611. RSA *rsa2 = NULL;
  74612. unsigned char hash[SHA256_DIGEST_LENGTH];
  74613. unsigned char signature[2048/8];
  74614. unsigned int signatureLen = 0;
  74615. XMEMSET(hash, 0, sizeof(hash));
  74616. RSA_get0_key(rsa, &n, &e, &d);
  74617. RSA_get0_factors(rsa, &p, &q);
  74618. RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
  74619. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  74620. &signatureLen, rsa), 1);
  74621. /* Quick sanity check */
  74622. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74623. signatureLen, rsa), 1);
  74624. /* Verifying */
  74625. ExpectNotNull(rsa2 = RSA_new());
  74626. ExpectIntEQ(RSA_set0_key(rsa2, BN_dup(n), BN_dup(e), NULL), 1);
  74627. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74628. signatureLen, rsa2), 1);
  74629. ExpectIntEQ(RSA_set0_factors(rsa2, BN_dup(p), BN_dup(q)), 1);
  74630. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74631. signatureLen, rsa2), 1);
  74632. ExpectIntEQ(RSA_set0_crt_params(rsa2, BN_dup(dmp1), BN_dup(dmq1),
  74633. BN_dup(iqmp)), 1);
  74634. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74635. signatureLen, rsa2), 1);
  74636. RSA_free(rsa2);
  74637. rsa2 = NULL;
  74638. /* Signing */
  74639. XMEMSET(signature, 0, sizeof(signature));
  74640. ExpectNotNull(rsa2 = RSA_new());
  74641. ExpectIntEQ(RSA_set0_key(rsa2, BN_dup(n), BN_dup(e), BN_dup(d)), 1);
  74642. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  74643. &signatureLen, rsa2), 1);
  74644. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74645. signatureLen, rsa), 1);
  74646. ExpectIntEQ(RSA_set0_factors(rsa2, BN_dup(p), BN_dup(q)), 1);
  74647. XMEMSET(signature, 0, sizeof(signature));
  74648. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  74649. &signatureLen, rsa2), 1);
  74650. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74651. signatureLen, rsa), 1);
  74652. ExpectIntEQ(RSA_set0_crt_params(rsa2, BN_dup(dmp1), BN_dup(dmq1),
  74653. BN_dup(iqmp)), 1);
  74654. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  74655. &signatureLen, rsa2), 1);
  74656. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74657. signatureLen, rsa), 1);
  74658. RSA_free(rsa2);
  74659. rsa2 = NULL;
  74660. }
  74661. #endif
  74662. #ifdef WOLFSSL_RSA_KEY_CHECK
  74663. ExpectIntEQ(RSA_check_key(NULL), 0);
  74664. ExpectIntEQ(RSA_check_key(rsa), 1);
  74665. #endif
  74666. /* sanity check */
  74667. ExpectIntEQ(RSA_bits(NULL), 0);
  74668. /* key */
  74669. ExpectIntEQ(RSA_bits(rsa), 2048);
  74670. RSA_get0_key(rsa, &n, &e, &d);
  74671. ExpectPtrEq(rsa->n, n);
  74672. ExpectPtrEq(rsa->e, e);
  74673. ExpectPtrEq(rsa->d, d);
  74674. n = NULL;
  74675. e = NULL;
  74676. d = NULL;
  74677. ExpectNotNull(n = BN_new());
  74678. ExpectNotNull(e = BN_new());
  74679. ExpectNotNull(d = BN_new());
  74680. ExpectIntEQ(RSA_set0_key(rsa, (BIGNUM*)n, (BIGNUM*)e, (BIGNUM*)d), 1);
  74681. if (EXPECT_FAIL()) {
  74682. BN_free((BIGNUM*)n);
  74683. BN_free((BIGNUM*)e);
  74684. BN_free((BIGNUM*)d);
  74685. }
  74686. ExpectPtrEq(rsa->n, n);
  74687. ExpectPtrEq(rsa->e, e);
  74688. ExpectPtrEq(rsa->d, d);
  74689. ExpectIntEQ(RSA_set0_key(rsa, NULL, NULL, NULL), 1);
  74690. ExpectIntEQ(RSA_set0_key(NULL, (BIGNUM*)n, (BIGNUM*)e, (BIGNUM*)d), 0);
  74691. /* crt_params */
  74692. RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
  74693. ExpectPtrEq(rsa->dmp1, dmp1);
  74694. ExpectPtrEq(rsa->dmq1, dmq1);
  74695. ExpectPtrEq(rsa->iqmp, iqmp);
  74696. dmp1 = NULL;
  74697. dmq1 = NULL;
  74698. iqmp = NULL;
  74699. ExpectNotNull(dmp1 = BN_new());
  74700. ExpectNotNull(dmq1 = BN_new());
  74701. ExpectNotNull(iqmp = BN_new());
  74702. ExpectIntEQ(RSA_set0_crt_params(rsa, (BIGNUM*)dmp1, (BIGNUM*)dmq1,
  74703. (BIGNUM*)iqmp), 1);
  74704. if (EXPECT_FAIL()) {
  74705. BN_free((BIGNUM*)dmp1);
  74706. BN_free((BIGNUM*)dmq1);
  74707. BN_free((BIGNUM*)iqmp);
  74708. }
  74709. ExpectPtrEq(rsa->dmp1, dmp1);
  74710. ExpectPtrEq(rsa->dmq1, dmq1);
  74711. ExpectPtrEq(rsa->iqmp, iqmp);
  74712. ExpectIntEQ(RSA_set0_crt_params(rsa, NULL, NULL, NULL), 1);
  74713. ExpectIntEQ(RSA_set0_crt_params(NULL, (BIGNUM*)dmp1, (BIGNUM*)dmq1,
  74714. (BIGNUM*)iqmp), 0);
  74715. RSA_get0_crt_params(NULL, NULL, NULL, NULL);
  74716. RSA_get0_crt_params(rsa, NULL, NULL, NULL);
  74717. RSA_get0_crt_params(NULL, &dmp1, &dmq1, &iqmp);
  74718. ExpectNull(dmp1);
  74719. ExpectNull(dmq1);
  74720. ExpectNull(iqmp);
  74721. /* factors */
  74722. RSA_get0_factors(rsa, NULL, NULL);
  74723. RSA_get0_factors(rsa, &p, &q);
  74724. ExpectPtrEq(rsa->p, p);
  74725. ExpectPtrEq(rsa->q, q);
  74726. p = NULL;
  74727. q = NULL;
  74728. ExpectNotNull(p = BN_new());
  74729. ExpectNotNull(q = BN_new());
  74730. ExpectIntEQ(RSA_set0_factors(rsa, (BIGNUM*)p, (BIGNUM*)q), 1);
  74731. if (EXPECT_FAIL()) {
  74732. BN_free((BIGNUM*)p);
  74733. BN_free((BIGNUM*)q);
  74734. }
  74735. ExpectPtrEq(rsa->p, p);
  74736. ExpectPtrEq(rsa->q, q);
  74737. ExpectIntEQ(RSA_set0_factors(rsa, NULL, NULL), 1);
  74738. ExpectIntEQ(RSA_set0_factors(NULL, (BIGNUM*)p, (BIGNUM*)q), 0);
  74739. RSA_get0_factors(NULL, NULL, NULL);
  74740. RSA_get0_factors(NULL, &p, &q);
  74741. ExpectNull(p);
  74742. ExpectNull(q);
  74743. ExpectIntEQ(BN_hex2bn(&rsa->n, "1FFFFF"), 1);
  74744. ExpectIntEQ(RSA_bits(rsa), 21);
  74745. RSA_free(rsa);
  74746. rsa = NULL;
  74747. #if !defined(USE_FAST_MATH) || (FP_MAX_BITS >= (3072*2))
  74748. ExpectNotNull(rsa = RSA_generate_key(3072, 17, NULL, NULL));
  74749. ExpectIntEQ(RSA_size(rsa), 384);
  74750. ExpectIntEQ(RSA_bits(rsa), 3072);
  74751. RSA_free(rsa);
  74752. rsa = NULL;
  74753. #endif
  74754. /* remove for now with odd key size until adjusting rsa key size check with
  74755. wc_MakeRsaKey()
  74756. ExpectNotNull(rsa = RSA_generate_key(2999, 65537, NULL, NULL));
  74757. RSA_free(rsa);
  74758. rsa = NULL;
  74759. */
  74760. ExpectNull(RSA_generate_key(-1, 3, NULL, NULL));
  74761. ExpectNull(RSA_generate_key(RSA_MIN_SIZE - 1, 3, NULL, NULL));
  74762. ExpectNull(RSA_generate_key(RSA_MAX_SIZE + 1, 3, NULL, NULL));
  74763. ExpectNull(RSA_generate_key(2048, 0, NULL, NULL));
  74764. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN)
  74765. {
  74766. byte buff[FOURK_BUF];
  74767. byte der[FOURK_BUF];
  74768. const char PrivKeyPemFile[] = "certs/client-keyEnc.pem";
  74769. XFILE f = XBADFILE;
  74770. int bytes = 0;
  74771. /* test loading encrypted RSA private pem w/o password */
  74772. ExpectTrue((f = XFOPEN(PrivKeyPemFile, "rb")) != XBADFILE);
  74773. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  74774. if (f != XBADFILE)
  74775. XFCLOSE(f);
  74776. XMEMSET(der, 0, sizeof(der));
  74777. /* test that error value is returned with no password */
  74778. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der), ""),
  74779. 0);
  74780. }
  74781. #endif
  74782. #endif
  74783. return EXPECT_RESULT();
  74784. }
  74785. static int test_wolfSSL_RSA_DER(void)
  74786. {
  74787. EXPECT_DECLS;
  74788. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && defined(OPENSSL_EXTRA)
  74789. RSA *rsa = NULL;
  74790. int i;
  74791. const unsigned char *buff = NULL;
  74792. unsigned char *newBuff = NULL;
  74793. struct tbl_s
  74794. {
  74795. const unsigned char *der;
  74796. int sz;
  74797. } tbl[] = {
  74798. #ifdef USE_CERT_BUFFERS_1024
  74799. {client_key_der_1024, sizeof_client_key_der_1024},
  74800. {server_key_der_1024, sizeof_server_key_der_1024},
  74801. #endif
  74802. #ifdef USE_CERT_BUFFERS_2048
  74803. {client_key_der_2048, sizeof_client_key_der_2048},
  74804. {server_key_der_2048, sizeof_server_key_der_2048},
  74805. #endif
  74806. {NULL, 0}
  74807. };
  74808. /* Public Key DER */
  74809. struct tbl_s pub[] = {
  74810. #ifdef USE_CERT_BUFFERS_1024
  74811. {client_keypub_der_1024, sizeof_client_keypub_der_1024},
  74812. #endif
  74813. #ifdef USE_CERT_BUFFERS_2048
  74814. {client_keypub_der_2048, sizeof_client_keypub_der_2048},
  74815. #endif
  74816. {NULL, 0}
  74817. };
  74818. ExpectNull(d2i_RSAPublicKey(&rsa, NULL, pub[0].sz));
  74819. buff = pub[0].der;
  74820. ExpectNull(d2i_RSAPublicKey(&rsa, &buff, 1));
  74821. ExpectNull(d2i_RSAPrivateKey(&rsa, NULL, tbl[0].sz));
  74822. buff = tbl[0].der;
  74823. ExpectNull(d2i_RSAPrivateKey(&rsa, &buff, 1));
  74824. ExpectIntEQ(i2d_RSAPublicKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74825. rsa = RSA_new();
  74826. ExpectIntEQ(i2d_RSAPublicKey(rsa, NULL), 0);
  74827. RSA_free(rsa);
  74828. rsa = NULL;
  74829. for (i = 0; tbl[i].der != NULL; i++)
  74830. {
  74831. /* Passing in pointer results in pointer moving. */
  74832. buff = tbl[i].der;
  74833. ExpectNotNull(d2i_RSAPublicKey(&rsa, &buff, tbl[i].sz));
  74834. ExpectNotNull(rsa);
  74835. RSA_free(rsa);
  74836. rsa = NULL;
  74837. }
  74838. for (i = 0; tbl[i].der != NULL; i++)
  74839. {
  74840. /* Passing in pointer results in pointer moving. */
  74841. buff = tbl[i].der;
  74842. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &buff, tbl[i].sz));
  74843. ExpectNotNull(rsa);
  74844. RSA_free(rsa);
  74845. rsa = NULL;
  74846. }
  74847. for (i = 0; pub[i].der != NULL; i++)
  74848. {
  74849. buff = pub[i].der;
  74850. ExpectNotNull(d2i_RSAPublicKey(&rsa, &buff, pub[i].sz));
  74851. ExpectNotNull(rsa);
  74852. ExpectIntEQ(i2d_RSAPublicKey(rsa, NULL), pub[i].sz);
  74853. newBuff = NULL;
  74854. ExpectIntEQ(i2d_RSAPublicKey(rsa, &newBuff), pub[i].sz);
  74855. ExpectNotNull(newBuff);
  74856. ExpectIntEQ(XMEMCMP((void *)newBuff, (void *)pub[i].der, pub[i].sz), 0);
  74857. XFREE((void *)newBuff, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  74858. RSA_free(rsa);
  74859. rsa = NULL;
  74860. }
  74861. #endif
  74862. return EXPECT_RESULT();
  74863. }
  74864. static int test_wolfSSL_RSA_print(void)
  74865. {
  74866. EXPECT_DECLS;
  74867. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  74868. !defined(NO_STDIO_FILESYSTEM) && \
  74869. !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  74870. !defined(NO_BIO) && defined(XFPRINTF)
  74871. BIO *bio = NULL;
  74872. WOLFSSL_RSA* rsa = NULL;
  74873. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  74874. ExpectNotNull(rsa = RSA_new());
  74875. ExpectIntEQ(RSA_print(NULL, rsa, 0), -1);
  74876. ExpectIntEQ(RSA_print_fp(XBADFILE, rsa, 0), 0);
  74877. ExpectIntEQ(RSA_print(bio, NULL, 0), -1);
  74878. ExpectIntEQ(RSA_print_fp(stderr, NULL, 0), 0);
  74879. /* Some very large number of indent spaces. */
  74880. ExpectIntEQ(RSA_print(bio, rsa, 128), -1);
  74881. /* RSA is empty. */
  74882. ExpectIntEQ(RSA_print(bio, rsa, 0), 0);
  74883. ExpectIntEQ(RSA_print_fp(stderr, rsa, 0), 0);
  74884. RSA_free(rsa);
  74885. rsa = NULL;
  74886. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  74887. ExpectIntEQ(RSA_print(bio, rsa, 0), 1);
  74888. ExpectIntEQ(RSA_print(bio, rsa, 4), 1);
  74889. ExpectIntEQ(RSA_print(bio, rsa, -1), 1);
  74890. ExpectIntEQ(RSA_print_fp(stderr, rsa, 0), 1);
  74891. ExpectIntEQ(RSA_print_fp(stderr, rsa, 4), 1);
  74892. ExpectIntEQ(RSA_print_fp(stderr, rsa, -1), 1);
  74893. BIO_free(bio);
  74894. RSA_free(rsa);
  74895. #endif
  74896. return EXPECT_RESULT();
  74897. }
  74898. static int test_wolfSSL_RSA_padding_add_PKCS1_PSS(void)
  74899. {
  74900. EXPECT_DECLS;
  74901. #ifndef NO_RSA
  74902. #if defined(OPENSSL_ALL) && defined(WC_RSA_PSS) && !defined(WC_NO_RNG)
  74903. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  74904. RSA *rsa = NULL;
  74905. const unsigned char *derBuf = client_key_der_2048;
  74906. unsigned char em[256] = {0}; /* len = 2048/8 */
  74907. /* Random data simulating a hash */
  74908. const unsigned char mHash[WC_SHA256_DIGEST_SIZE] = {
  74909. 0x28, 0x6e, 0xfd, 0xf8, 0x76, 0xc7, 0x00, 0x3d, 0x91, 0x4e, 0x59, 0xe4,
  74910. 0x8e, 0xb7, 0x40, 0x7b, 0xd1, 0x0c, 0x98, 0x4b, 0xe3, 0x3d, 0xb3, 0xeb,
  74911. 0x6f, 0x8a, 0x3c, 0x42, 0xab, 0x21, 0xad, 0x28
  74912. };
  74913. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &derBuf, sizeof_client_key_der_2048));
  74914. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(NULL, em, mHash, EVP_sha256(),
  74915. RSA_PSS_SALTLEN_DIGEST), 0);
  74916. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, NULL, mHash, EVP_sha256(),
  74917. RSA_PSS_SALTLEN_DIGEST), 0);
  74918. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, NULL, EVP_sha256(),
  74919. RSA_PSS_SALTLEN_DIGEST), 0);
  74920. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, NULL,
  74921. RSA_PSS_SALTLEN_DIGEST), 0);
  74922. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(), -5), 0);
  74923. ExpectIntEQ(RSA_verify_PKCS1_PSS(NULL, mHash, EVP_sha256(), em,
  74924. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  74925. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, NULL, EVP_sha256(), em,
  74926. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  74927. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, NULL, em,
  74928. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  74929. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), NULL,
  74930. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  74931. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  74932. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  74933. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em, -5), 0);
  74934. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  74935. RSA_PSS_SALTLEN_DIGEST), 1);
  74936. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  74937. RSA_PSS_SALTLEN_DIGEST), 1);
  74938. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  74939. RSA_PSS_SALTLEN_MAX_SIGN), 1);
  74940. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  74941. RSA_PSS_SALTLEN_MAX_SIGN), 1);
  74942. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  74943. RSA_PSS_SALTLEN_MAX), 1);
  74944. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  74945. RSA_PSS_SALTLEN_MAX), 1);
  74946. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(), 10), 1);
  74947. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em, 10), 1);
  74948. RSA_free(rsa);
  74949. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  74950. #endif /* OPENSSL_ALL && WC_RSA_PSS && !WC_NO_RNG*/
  74951. #endif
  74952. return EXPECT_RESULT();
  74953. }
  74954. static int test_wolfSSL_RSA_sign_sha3(void)
  74955. {
  74956. EXPECT_DECLS;
  74957. #if !defined(NO_RSA) && defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  74958. #if defined(OPENSSL_ALL) && defined(WC_RSA_PSS) && !defined(WC_NO_RNG)
  74959. RSA* rsa = NULL;
  74960. const unsigned char *derBuf = client_key_der_2048;
  74961. unsigned char sigRet[256] = {0};
  74962. unsigned int sigLen = sizeof(sigRet);
  74963. /* Random data simulating a hash */
  74964. const unsigned char mHash[WC_SHA3_256_DIGEST_SIZE] = {
  74965. 0x28, 0x6e, 0xfd, 0xf8, 0x76, 0xc7, 0x00, 0x3d, 0x91, 0x4e, 0x59, 0xe4,
  74966. 0x8e, 0xb7, 0x40, 0x7b, 0xd1, 0x0c, 0x98, 0x4b, 0xe3, 0x3d, 0xb3, 0xeb,
  74967. 0x6f, 0x8a, 0x3c, 0x42, 0xab, 0x21, 0xad, 0x28
  74968. };
  74969. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &derBuf, sizeof_client_key_der_2048));
  74970. ExpectIntEQ(RSA_sign(NID_sha3_256, mHash, sizeof(mHash), sigRet, &sigLen,
  74971. rsa), 1);
  74972. RSA_free(rsa);
  74973. #endif /* OPENSSL_ALL && WC_RSA_PSS && !WC_NO_RNG*/
  74974. #endif /* !NO_RSA && WOLFSSL_SHA3 && !WOLFSSL_NOSHA3_256*/
  74975. return EXPECT_RESULT();
  74976. }
  74977. static int test_wolfSSL_RSA_get0_key(void)
  74978. {
  74979. EXPECT_DECLS;
  74980. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74981. RSA *rsa = NULL;
  74982. const BIGNUM* n = NULL;
  74983. const BIGNUM* e = NULL;
  74984. const BIGNUM* d = NULL;
  74985. const unsigned char* der;
  74986. int derSz;
  74987. #ifdef USE_CERT_BUFFERS_1024
  74988. der = client_key_der_1024;
  74989. derSz = sizeof_client_key_der_1024;
  74990. #elif defined(USE_CERT_BUFFERS_2048)
  74991. der = client_key_der_2048;
  74992. derSz = sizeof_client_key_der_2048;
  74993. #else
  74994. der = NULL;
  74995. derSz = 0;
  74996. #endif
  74997. if (der != NULL) {
  74998. RSA_get0_key(NULL, NULL, NULL, NULL);
  74999. RSA_get0_key(rsa, NULL, NULL, NULL);
  75000. RSA_get0_key(NULL, &n, &e, &d);
  75001. ExpectNull(n);
  75002. ExpectNull(e);
  75003. ExpectNull(d);
  75004. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, derSz));
  75005. ExpectNotNull(rsa);
  75006. RSA_get0_key(rsa, NULL, NULL, NULL);
  75007. RSA_get0_key(rsa, &n, NULL, NULL);
  75008. ExpectNotNull(n);
  75009. RSA_get0_key(rsa, NULL, &e, NULL);
  75010. ExpectNotNull(e);
  75011. RSA_get0_key(rsa, NULL, NULL, &d);
  75012. ExpectNotNull(d);
  75013. RSA_get0_key(rsa, &n, &e, &d);
  75014. ExpectNotNull(n);
  75015. ExpectNotNull(e);
  75016. ExpectNotNull(d);
  75017. RSA_free(rsa);
  75018. }
  75019. #endif
  75020. return EXPECT_RESULT();
  75021. }
  75022. static int test_wolfSSL_RSA_meth(void)
  75023. {
  75024. EXPECT_DECLS;
  75025. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75026. RSA *rsa = NULL;
  75027. RSA_METHOD *rsa_meth = NULL;
  75028. #ifdef WOLFSSL_KEY_GEN
  75029. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  75030. RSA_free(rsa);
  75031. rsa = NULL;
  75032. #else
  75033. ExpectNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  75034. #endif
  75035. ExpectNotNull(RSA_get_default_method());
  75036. wolfSSL_RSA_meth_free(NULL);
  75037. ExpectNull(wolfSSL_RSA_meth_new(NULL, 0));
  75038. ExpectNotNull(rsa_meth = RSA_meth_new("placeholder RSA method",
  75039. RSA_METHOD_FLAG_NO_CHECK));
  75040. #ifndef NO_WOLFSSL_STUB
  75041. ExpectIntEQ(RSA_meth_set_pub_enc(rsa_meth, NULL), 1);
  75042. ExpectIntEQ(RSA_meth_set_pub_dec(rsa_meth, NULL), 1);
  75043. ExpectIntEQ(RSA_meth_set_priv_enc(rsa_meth, NULL), 1);
  75044. ExpectIntEQ(RSA_meth_set_priv_dec(rsa_meth, NULL), 1);
  75045. ExpectIntEQ(RSA_meth_set_init(rsa_meth, NULL), 1);
  75046. ExpectIntEQ(RSA_meth_set_finish(rsa_meth, NULL), 1);
  75047. ExpectIntEQ(RSA_meth_set0_app_data(rsa_meth, NULL), 1);
  75048. #endif
  75049. ExpectIntEQ(RSA_flags(NULL), 0);
  75050. RSA_set_flags(NULL, RSA_FLAG_CACHE_PUBLIC);
  75051. RSA_clear_flags(NULL, RSA_FLAG_CACHE_PUBLIC);
  75052. ExpectIntEQ(RSA_test_flags(NULL, RSA_FLAG_CACHE_PUBLIC), 0);
  75053. ExpectNotNull(rsa = RSA_new());
  75054. /* No method set. */
  75055. ExpectIntEQ(RSA_flags(rsa), 0);
  75056. RSA_set_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  75057. RSA_clear_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  75058. ExpectIntEQ(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  75059. ExpectIntEQ(RSA_set_method(NULL, rsa_meth), 1);
  75060. ExpectIntEQ(RSA_set_method(rsa, rsa_meth), 1);
  75061. if (EXPECT_FAIL()) {
  75062. wolfSSL_RSA_meth_free(rsa_meth);
  75063. }
  75064. ExpectNull(RSA_get_method(NULL));
  75065. ExpectPtrEq(RSA_get_method(rsa), rsa_meth);
  75066. ExpectIntEQ(RSA_flags(rsa), RSA_METHOD_FLAG_NO_CHECK);
  75067. RSA_set_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  75068. ExpectIntNE(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  75069. ExpectIntEQ(RSA_flags(rsa), RSA_FLAG_CACHE_PUBLIC |
  75070. RSA_METHOD_FLAG_NO_CHECK);
  75071. RSA_clear_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  75072. ExpectIntEQ(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  75073. ExpectIntNE(RSA_flags(rsa), RSA_FLAG_CACHE_PUBLIC);
  75074. /* rsa_meth is freed here */
  75075. RSA_free(rsa);
  75076. #endif
  75077. return EXPECT_RESULT();
  75078. }
  75079. static int test_wolfSSL_RSA_verify(void)
  75080. {
  75081. EXPECT_DECLS;
  75082. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  75083. #ifndef NO_BIO
  75084. XFILE fp = XBADFILE;
  75085. RSA *pKey = NULL;
  75086. RSA *pubKey = NULL;
  75087. X509 *cert = NULL;
  75088. const char *text = "Hello wolfSSL !";
  75089. unsigned char hash[SHA256_DIGEST_LENGTH];
  75090. unsigned char signature[2048/8];
  75091. unsigned int signatureLength;
  75092. byte *buf = NULL;
  75093. BIO *bio = NULL;
  75094. SHA256_CTX c;
  75095. EVP_PKEY *evpPkey = NULL;
  75096. EVP_PKEY *evpPubkey = NULL;
  75097. size_t sz;
  75098. /* generate hash */
  75099. SHA256_Init(&c);
  75100. SHA256_Update(&c, text, strlen(text));
  75101. SHA256_Final(hash, &c);
  75102. #ifdef WOLFSSL_SMALL_STACK_CACHE
  75103. /* workaround for small stack cache case */
  75104. wc_Sha256Free((wc_Sha256*)&c);
  75105. #endif
  75106. /* read privete key file */
  75107. ExpectTrue((fp = XFOPEN(svrKeyFile, "rb")) != XBADFILE);
  75108. ExpectIntEQ(XFSEEK(fp, 0, XSEEK_END), 0);
  75109. ExpectTrue((sz = XFTELL(fp)) > 0);
  75110. ExpectIntEQ(XFSEEK(fp, 0, XSEEK_SET), 0);
  75111. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  75112. ExpectIntEQ(XFREAD(buf, 1, sz, fp), sz);
  75113. if (fp != XBADFILE) {
  75114. XFCLOSE(fp);
  75115. fp = XBADFILE;
  75116. }
  75117. /* read private key and sign hash data */
  75118. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  75119. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL));
  75120. ExpectNotNull(pKey = EVP_PKEY_get1_RSA(evpPkey));
  75121. ExpectIntEQ(RSA_sign(NID_sha256, hash, SHA256_DIGEST_LENGTH,
  75122. signature, &signatureLength, pKey), SSL_SUCCESS);
  75123. /* read public key and verify signed data */
  75124. ExpectTrue((fp = XFOPEN(svrCertFile,"rb")) != XBADFILE);
  75125. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  75126. if (fp != XBADFILE)
  75127. XFCLOSE(fp);
  75128. ExpectNotNull(evpPubkey = X509_get_pubkey(cert));
  75129. ExpectNotNull(pubKey = EVP_PKEY_get1_RSA(evpPubkey));
  75130. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, signature,
  75131. signatureLength, pubKey), SSL_SUCCESS);
  75132. ExpectIntEQ(RSA_verify(NID_sha256, NULL, SHA256_DIGEST_LENGTH, NULL,
  75133. signatureLength, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75134. ExpectIntEQ(RSA_verify(NID_sha256, NULL, SHA256_DIGEST_LENGTH, signature,
  75135. signatureLength, pubKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75136. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, NULL,
  75137. signatureLength, pubKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75138. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, signature,
  75139. signatureLength, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75140. RSA_free(pKey);
  75141. EVP_PKEY_free(evpPkey);
  75142. RSA_free(pubKey);
  75143. EVP_PKEY_free(evpPubkey);
  75144. X509_free(cert);
  75145. BIO_free(bio);
  75146. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  75147. #endif
  75148. #endif
  75149. return EXPECT_RESULT();
  75150. }
  75151. static int test_wolfSSL_RSA_sign(void)
  75152. {
  75153. EXPECT_DECLS;
  75154. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75155. RSA *rsa;
  75156. unsigned char hash[SHA256_DIGEST_LENGTH];
  75157. #ifdef USE_CERT_BUFFERS_1024
  75158. const unsigned char* privDer = client_key_der_1024;
  75159. size_t privDerSz = sizeof_client_key_der_1024;
  75160. const unsigned char* pubDer = client_keypub_der_1024;
  75161. size_t pubDerSz = sizeof_client_keypub_der_1024;
  75162. unsigned char signature[1024/8];
  75163. #else
  75164. const unsigned char* privDer = client_key_der_2048;
  75165. size_t privDerSz = sizeof_client_key_der_2048;
  75166. const unsigned char* pubDer = client_keypub_der_2048;
  75167. size_t pubDerSz = sizeof_client_keypub_der_2048;
  75168. unsigned char signature[2048/8];
  75169. #endif
  75170. unsigned int signatureLen;
  75171. const unsigned char* der;
  75172. XMEMSET(hash, 0, sizeof(hash));
  75173. der = privDer;
  75174. rsa = NULL;
  75175. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75176. /* Invalid parameters. */
  75177. ExpectIntEQ(RSA_sign(NID_rsaEncryption, NULL, 0, NULL, NULL, NULL), 0);
  75178. ExpectIntEQ(RSA_sign(NID_rsaEncryption, hash, sizeof(hash), signature,
  75179. &signatureLen, rsa), 0);
  75180. ExpectIntEQ(RSA_sign(NID_sha256, NULL, sizeof(hash), signature,
  75181. &signatureLen, rsa), 0);
  75182. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), NULL,
  75183. &signatureLen, rsa), 0);
  75184. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  75185. NULL, rsa), 0);
  75186. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  75187. &signatureLen, NULL), 0);
  75188. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  75189. &signatureLen, rsa), 1);
  75190. RSA_free(rsa);
  75191. der = pubDer;
  75192. rsa = NULL;
  75193. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  75194. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  75195. signatureLen, rsa), 1);
  75196. RSA_free(rsa);
  75197. #endif
  75198. return EXPECT_RESULT();
  75199. }
  75200. static int test_wolfSSL_RSA_sign_ex(void)
  75201. {
  75202. EXPECT_DECLS;
  75203. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75204. RSA *rsa = NULL;
  75205. unsigned char hash[SHA256_DIGEST_LENGTH];
  75206. #ifdef USE_CERT_BUFFERS_1024
  75207. const unsigned char* privDer = client_key_der_1024;
  75208. size_t privDerSz = sizeof_client_key_der_1024;
  75209. const unsigned char* pubDer = client_keypub_der_1024;
  75210. size_t pubDerSz = sizeof_client_keypub_der_1024;
  75211. unsigned char signature[1024/8];
  75212. #else
  75213. const unsigned char* privDer = client_key_der_2048;
  75214. size_t privDerSz = sizeof_client_key_der_2048;
  75215. const unsigned char* pubDer = client_keypub_der_2048;
  75216. size_t pubDerSz = sizeof_client_keypub_der_2048;
  75217. unsigned char signature[2048/8];
  75218. #endif
  75219. unsigned int signatureLen;
  75220. const unsigned char* der;
  75221. unsigned char encodedHash[51];
  75222. unsigned int encodedHashLen;
  75223. const unsigned char expEncHash[] = {
  75224. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  75225. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  75226. 0x00, 0x04, 0x20,
  75227. /* Hash data */
  75228. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  75229. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  75230. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  75231. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  75232. };
  75233. XMEMSET(hash, 0, sizeof(hash));
  75234. ExpectNotNull(rsa = wolfSSL_RSA_new());
  75235. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  75236. &signatureLen, rsa, 1), 0);
  75237. wolfSSL_RSA_free(rsa);
  75238. der = privDer;
  75239. rsa = NULL;
  75240. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75241. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_rsaEncryption,NULL, 0, NULL, NULL, NULL,
  75242. -1), 0);
  75243. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_rsaEncryption, hash, sizeof(hash),
  75244. signature, &signatureLen, rsa, 1), 0);
  75245. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, NULL, sizeof(hash), signature,
  75246. &signatureLen, rsa, 1), 0);
  75247. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), NULL,
  75248. &signatureLen, rsa, 1), 0);
  75249. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  75250. NULL, rsa, 1), 0);
  75251. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  75252. &signatureLen, NULL, 1), 0);
  75253. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  75254. &signatureLen, rsa, -1), 0);
  75255. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, NULL, sizeof(hash), signature,
  75256. &signatureLen, rsa, 0), 0);
  75257. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), NULL,
  75258. &signatureLen, rsa, 0), 0);
  75259. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  75260. NULL, rsa, 0), 0);
  75261. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  75262. &signatureLen, rsa, 1), 1);
  75263. /* Test returning encoded hash. */
  75264. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), encodedHash,
  75265. &encodedHashLen, rsa, 0), 1);
  75266. ExpectIntEQ(encodedHashLen, sizeof(expEncHash));
  75267. ExpectIntEQ(XMEMCMP(encodedHash, expEncHash, sizeof(expEncHash)), 0);
  75268. RSA_free(rsa);
  75269. der = pubDer;
  75270. rsa = NULL;
  75271. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  75272. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  75273. signatureLen, rsa), 1);
  75274. RSA_free(rsa);
  75275. #endif
  75276. return EXPECT_RESULT();
  75277. }
  75278. static int test_wolfSSL_RSA_public_decrypt(void)
  75279. {
  75280. EXPECT_DECLS;
  75281. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75282. RSA *rsa;
  75283. unsigned char msg[SHA256_DIGEST_LENGTH];
  75284. #ifdef USE_CERT_BUFFERS_1024
  75285. const unsigned char* pubDer = client_keypub_der_1024;
  75286. size_t pubDerSz = sizeof_client_keypub_der_1024;
  75287. unsigned char decMsg[1024/8];
  75288. const unsigned char encMsg[] = {
  75289. 0x45, 0x8e, 0x6e, 0x7a, 0x9c, 0xe1, 0x67, 0x36,
  75290. 0x72, 0xfc, 0x9d, 0x05, 0xdf, 0xc2, 0xaf, 0x54,
  75291. 0xc5, 0x2f, 0x94, 0xb8, 0xc7, 0x82, 0x40, 0xfa,
  75292. 0xa7, 0x8c, 0xb1, 0x89, 0x40, 0xc3, 0x59, 0x5a,
  75293. 0x77, 0x08, 0x54, 0x93, 0x43, 0x7f, 0xc4, 0xb7,
  75294. 0xc4, 0x78, 0xf1, 0xf8, 0xab, 0xbf, 0xc2, 0x81,
  75295. 0x5d, 0x97, 0xea, 0x7a, 0x60, 0x90, 0x51, 0xb7,
  75296. 0x47, 0x78, 0x48, 0x1e, 0x88, 0x6b, 0x89, 0xde,
  75297. 0xce, 0x41, 0x41, 0xae, 0x49, 0xf6, 0xfd, 0x2d,
  75298. 0x2d, 0x9c, 0x70, 0x7d, 0xf9, 0xcf, 0x77, 0x5f,
  75299. 0x06, 0xc7, 0x20, 0xe3, 0x57, 0xd4, 0xd8, 0x1a,
  75300. 0x96, 0xa2, 0x39, 0xb0, 0x6e, 0x8e, 0x68, 0xf8,
  75301. 0x57, 0x7b, 0x26, 0x88, 0x17, 0xc4, 0xb7, 0xf1,
  75302. 0x59, 0xfa, 0xb6, 0x95, 0xdd, 0x1e, 0xe8, 0xd8,
  75303. 0x4e, 0xbd, 0xcd, 0x41, 0xad, 0xc7, 0xe2, 0x39,
  75304. 0xb8, 0x00, 0xca, 0xf5, 0x59, 0xdf, 0xf8, 0x43
  75305. };
  75306. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  75307. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  75308. defined(WC_RSA_NO_PADDING)
  75309. const unsigned char encMsgNoPad[] = {
  75310. 0x0d, 0x41, 0x5a, 0xc7, 0x60, 0xd7, 0xbe, 0xb6,
  75311. 0x42, 0xd1, 0x65, 0xb1, 0x7e, 0x59, 0x54, 0xcc,
  75312. 0x76, 0x62, 0xd0, 0x2f, 0x4d, 0xe3, 0x23, 0x62,
  75313. 0xc8, 0x14, 0xfe, 0x5e, 0xa1, 0xc7, 0x05, 0xee,
  75314. 0x9e, 0x28, 0x2e, 0xf5, 0xfd, 0xa4, 0xc0, 0x43,
  75315. 0x55, 0xa2, 0x6b, 0x6b, 0x16, 0xa7, 0x63, 0x06,
  75316. 0xa7, 0x78, 0x4f, 0xda, 0xae, 0x10, 0x6d, 0xd1,
  75317. 0x2e, 0x1d, 0xbb, 0xbc, 0xc4, 0x1d, 0x82, 0xe4,
  75318. 0xc6, 0x76, 0x77, 0xa6, 0x0a, 0xef, 0xd2, 0x89,
  75319. 0xff, 0x30, 0x85, 0x22, 0xa0, 0x68, 0x88, 0x54,
  75320. 0xa3, 0xd1, 0x92, 0xd1, 0x3f, 0x57, 0xe4, 0xc7,
  75321. 0x43, 0x5a, 0x8b, 0xb3, 0x86, 0xaf, 0xd5, 0x6d,
  75322. 0x07, 0xe1, 0xa0, 0x5f, 0xe1, 0x9a, 0x06, 0xba,
  75323. 0x56, 0xd2, 0xb0, 0x73, 0xf5, 0xb3, 0xd0, 0x5f,
  75324. 0xc0, 0xbf, 0x22, 0x4c, 0x54, 0x4e, 0x11, 0xe2,
  75325. 0xc5, 0xf8, 0x66, 0x39, 0x9d, 0x70, 0x90, 0x31
  75326. };
  75327. #endif
  75328. #else
  75329. const unsigned char* pubDer = client_keypub_der_2048;
  75330. size_t pubDerSz = sizeof_client_keypub_der_2048;
  75331. unsigned char decMsg[2048/8];
  75332. const unsigned char encMsg[] = {
  75333. 0x16, 0x5d, 0xbb, 0x00, 0x38, 0x73, 0x01, 0x34,
  75334. 0xca, 0x59, 0xc6, 0x8b, 0x64, 0x70, 0x89, 0xf5,
  75335. 0x50, 0x2d, 0x1d, 0x69, 0x1f, 0x07, 0x1e, 0x31,
  75336. 0xae, 0x9b, 0xa6, 0x6e, 0xee, 0x80, 0xd9, 0x9e,
  75337. 0x59, 0x33, 0x70, 0x30, 0x28, 0x42, 0x7d, 0x24,
  75338. 0x36, 0x95, 0x6b, 0xf9, 0x0a, 0x23, 0xcb, 0xce,
  75339. 0x66, 0xa5, 0x07, 0x5e, 0x11, 0xa7, 0xdc, 0xfb,
  75340. 0xd9, 0xc2, 0x51, 0xf0, 0x05, 0xc9, 0x39, 0xb3,
  75341. 0xae, 0xff, 0xfb, 0xe9, 0xb1, 0x9a, 0x54, 0xac,
  75342. 0x1d, 0xca, 0x42, 0x1a, 0xfd, 0x7c, 0x97, 0xa0,
  75343. 0x60, 0x2b, 0xcd, 0xb6, 0x36, 0x33, 0xfc, 0x44,
  75344. 0x69, 0xf7, 0x2e, 0x8c, 0x3b, 0x5f, 0xb4, 0x9f,
  75345. 0xa7, 0x02, 0x8f, 0x6d, 0x6b, 0x79, 0x10, 0x32,
  75346. 0x7d, 0xf4, 0x5d, 0xa1, 0x63, 0x22, 0x59, 0xc4,
  75347. 0x44, 0x8e, 0x44, 0x24, 0x8b, 0x14, 0x9d, 0x2b,
  75348. 0xb5, 0xd3, 0xad, 0x9a, 0x87, 0x0d, 0xe7, 0x70,
  75349. 0x6d, 0xe9, 0xae, 0xaa, 0x52, 0xbf, 0x1a, 0x9b,
  75350. 0xc8, 0x3d, 0x45, 0x7c, 0xd1, 0x90, 0xe3, 0xd9,
  75351. 0x57, 0xcf, 0xc3, 0x29, 0x69, 0x05, 0x07, 0x96,
  75352. 0x2e, 0x46, 0x74, 0x0a, 0xa7, 0x76, 0x8b, 0xc0,
  75353. 0x1c, 0x04, 0x80, 0x08, 0xa0, 0x94, 0x7e, 0xbb,
  75354. 0x2d, 0x99, 0xe9, 0xab, 0x18, 0x4d, 0x48, 0x2d,
  75355. 0x94, 0x5e, 0x50, 0x21, 0x42, 0xdf, 0xf5, 0x61,
  75356. 0x42, 0x7d, 0x86, 0x5d, 0x9e, 0x89, 0xc9, 0x5b,
  75357. 0x24, 0xab, 0xa1, 0xd8, 0x20, 0x45, 0xcb, 0x81,
  75358. 0xcf, 0xc5, 0x25, 0x7d, 0x11, 0x6e, 0xbd, 0x80,
  75359. 0xac, 0xba, 0xdc, 0xef, 0xb9, 0x05, 0x9c, 0xd5,
  75360. 0xc2, 0x26, 0x57, 0x69, 0x8b, 0x08, 0x27, 0xc7,
  75361. 0xea, 0xbe, 0xaf, 0x52, 0x21, 0x95, 0x9f, 0xa0,
  75362. 0x2f, 0x2f, 0x53, 0x7c, 0x2f, 0xa3, 0x0b, 0x79,
  75363. 0x39, 0x01, 0xa3, 0x37, 0x46, 0xa8, 0xc4, 0x34,
  75364. 0x41, 0x20, 0x7c, 0x3f, 0x70, 0x9a, 0x47, 0xe8
  75365. };
  75366. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  75367. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  75368. defined(WC_RSA_NO_PADDING)
  75369. const unsigned char encMsgNoPad[] = {
  75370. 0x79, 0x69, 0xdc, 0x0d, 0xff, 0x09, 0xeb, 0x91,
  75371. 0xbc, 0xda, 0xe4, 0xd3, 0xcd, 0xd5, 0xd3, 0x1c,
  75372. 0xb9, 0x66, 0xa8, 0x02, 0xf3, 0x75, 0x40, 0xf1,
  75373. 0x38, 0x4a, 0x37, 0x7b, 0x19, 0xc8, 0xcd, 0xea,
  75374. 0x79, 0xa8, 0x51, 0x32, 0x00, 0x3f, 0x4c, 0xde,
  75375. 0xaa, 0xe5, 0xe2, 0x7c, 0x10, 0xcd, 0x6e, 0x00,
  75376. 0xc6, 0xc4, 0x63, 0x98, 0x58, 0x9b, 0x38, 0xca,
  75377. 0xf0, 0x5d, 0xc8, 0xf0, 0x57, 0xf6, 0x21, 0x50,
  75378. 0x3f, 0x63, 0x05, 0x9f, 0xbf, 0xb6, 0x3b, 0x50,
  75379. 0x85, 0x06, 0x34, 0x08, 0x57, 0xb9, 0x44, 0xce,
  75380. 0xe4, 0x66, 0xbf, 0x0c, 0xfe, 0x36, 0xa4, 0x5b,
  75381. 0xed, 0x2d, 0x7d, 0xed, 0xf1, 0xbd, 0xda, 0x3e,
  75382. 0x19, 0x1f, 0x99, 0xc8, 0xe4, 0xc2, 0xbb, 0xb5,
  75383. 0x6c, 0x83, 0x22, 0xd1, 0xe7, 0x57, 0xcf, 0x1b,
  75384. 0x91, 0x0c, 0xa5, 0x47, 0x06, 0x71, 0x8f, 0x93,
  75385. 0xf3, 0xad, 0xdb, 0xe3, 0xf8, 0xa0, 0x0b, 0xcd,
  75386. 0x89, 0x4e, 0xa5, 0xb5, 0x03, 0x68, 0x61, 0x89,
  75387. 0x0b, 0xe2, 0x03, 0x8b, 0x1f, 0x54, 0xae, 0x0f,
  75388. 0xfa, 0xf0, 0xb7, 0x0f, 0x8c, 0x84, 0x35, 0x13,
  75389. 0x8d, 0x65, 0x1f, 0x2c, 0xd5, 0xce, 0xc4, 0x6c,
  75390. 0x98, 0x67, 0xe4, 0x1a, 0x85, 0x67, 0x69, 0x17,
  75391. 0x17, 0x5a, 0x5d, 0xfd, 0x23, 0xdd, 0x03, 0x3f,
  75392. 0x6d, 0x7a, 0xb6, 0x8b, 0x99, 0xc0, 0xb6, 0x70,
  75393. 0x86, 0xac, 0xf6, 0x02, 0xc2, 0x28, 0x42, 0xed,
  75394. 0x06, 0xcf, 0xca, 0x3d, 0x07, 0x16, 0xf0, 0x0e,
  75395. 0x04, 0x55, 0x1e, 0x59, 0x3f, 0x32, 0xc7, 0x12,
  75396. 0xc5, 0x0d, 0x9d, 0x64, 0x7d, 0x2e, 0xd4, 0xbc,
  75397. 0x8c, 0x24, 0x42, 0x94, 0x2b, 0xf6, 0x11, 0x7f,
  75398. 0xb1, 0x1c, 0x09, 0x12, 0x6f, 0x5e, 0x2e, 0x7a,
  75399. 0xc6, 0x01, 0xe0, 0x98, 0x31, 0xb7, 0x13, 0x03,
  75400. 0xce, 0x29, 0xe1, 0xef, 0x9d, 0xdf, 0x9b, 0xa5,
  75401. 0xba, 0x0b, 0xad, 0xf2, 0xeb, 0x2f, 0xf9, 0xd1
  75402. };
  75403. #endif
  75404. #endif
  75405. const unsigned char* der;
  75406. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  75407. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  75408. defined(WC_RSA_NO_PADDING)
  75409. int i;
  75410. #endif
  75411. XMEMSET(msg, 0, sizeof(msg));
  75412. der = pubDer;
  75413. rsa = NULL;
  75414. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  75415. ExpectIntEQ(RSA_public_decrypt(0, NULL, NULL, NULL, 0), -1);
  75416. ExpectIntEQ(RSA_public_decrypt(-1, encMsg, decMsg, rsa,
  75417. RSA_PKCS1_PADDING), -1);
  75418. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), NULL, decMsg, rsa,
  75419. RSA_PKCS1_PADDING), -1);
  75420. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, NULL, rsa,
  75421. RSA_PKCS1_PADDING), -1);
  75422. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, NULL,
  75423. RSA_PKCS1_PADDING), -1);
  75424. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, rsa,
  75425. RSA_PKCS1_PSS_PADDING), -1);
  75426. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, rsa,
  75427. RSA_PKCS1_PADDING), 32);
  75428. ExpectIntEQ(XMEMCMP(decMsg, msg, sizeof(msg)), 0);
  75429. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  75430. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  75431. defined(WC_RSA_NO_PADDING)
  75432. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsgNoPad), encMsgNoPad, decMsg,
  75433. rsa, RSA_NO_PADDING), sizeof(decMsg));
  75434. /* Zeros before actual data. */
  75435. for (i = 0; i < (int)(sizeof(decMsg) - sizeof(msg)); i += sizeof(msg)) {
  75436. ExpectIntEQ(XMEMCMP(decMsg + i, msg, sizeof(msg)), 0);
  75437. }
  75438. /* Check actual data. */
  75439. XMEMSET(msg, 0x01, sizeof(msg));
  75440. ExpectIntEQ(XMEMCMP(decMsg + i, msg, sizeof(msg)), 0);
  75441. #endif
  75442. RSA_free(rsa);
  75443. #endif
  75444. return EXPECT_RESULT();
  75445. }
  75446. static int test_wolfSSL_RSA_private_encrypt(void)
  75447. {
  75448. EXPECT_DECLS;
  75449. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75450. RSA *rsa;
  75451. unsigned char msg[SHA256_DIGEST_LENGTH];
  75452. #ifdef USE_CERT_BUFFERS_1024
  75453. const unsigned char* privDer = client_key_der_1024;
  75454. size_t privDerSz = sizeof_client_key_der_1024;
  75455. unsigned char encMsg[1024/8];
  75456. const unsigned char expEncMsg[] = {
  75457. 0x45, 0x8e, 0x6e, 0x7a, 0x9c, 0xe1, 0x67, 0x36,
  75458. 0x72, 0xfc, 0x9d, 0x05, 0xdf, 0xc2, 0xaf, 0x54,
  75459. 0xc5, 0x2f, 0x94, 0xb8, 0xc7, 0x82, 0x40, 0xfa,
  75460. 0xa7, 0x8c, 0xb1, 0x89, 0x40, 0xc3, 0x59, 0x5a,
  75461. 0x77, 0x08, 0x54, 0x93, 0x43, 0x7f, 0xc4, 0xb7,
  75462. 0xc4, 0x78, 0xf1, 0xf8, 0xab, 0xbf, 0xc2, 0x81,
  75463. 0x5d, 0x97, 0xea, 0x7a, 0x60, 0x90, 0x51, 0xb7,
  75464. 0x47, 0x78, 0x48, 0x1e, 0x88, 0x6b, 0x89, 0xde,
  75465. 0xce, 0x41, 0x41, 0xae, 0x49, 0xf6, 0xfd, 0x2d,
  75466. 0x2d, 0x9c, 0x70, 0x7d, 0xf9, 0xcf, 0x77, 0x5f,
  75467. 0x06, 0xc7, 0x20, 0xe3, 0x57, 0xd4, 0xd8, 0x1a,
  75468. 0x96, 0xa2, 0x39, 0xb0, 0x6e, 0x8e, 0x68, 0xf8,
  75469. 0x57, 0x7b, 0x26, 0x88, 0x17, 0xc4, 0xb7, 0xf1,
  75470. 0x59, 0xfa, 0xb6, 0x95, 0xdd, 0x1e, 0xe8, 0xd8,
  75471. 0x4e, 0xbd, 0xcd, 0x41, 0xad, 0xc7, 0xe2, 0x39,
  75472. 0xb8, 0x00, 0xca, 0xf5, 0x59, 0xdf, 0xf8, 0x43
  75473. };
  75474. #ifdef WC_RSA_NO_PADDING
  75475. const unsigned char expEncMsgNoPad[] = {
  75476. 0x0d, 0x41, 0x5a, 0xc7, 0x60, 0xd7, 0xbe, 0xb6,
  75477. 0x42, 0xd1, 0x65, 0xb1, 0x7e, 0x59, 0x54, 0xcc,
  75478. 0x76, 0x62, 0xd0, 0x2f, 0x4d, 0xe3, 0x23, 0x62,
  75479. 0xc8, 0x14, 0xfe, 0x5e, 0xa1, 0xc7, 0x05, 0xee,
  75480. 0x9e, 0x28, 0x2e, 0xf5, 0xfd, 0xa4, 0xc0, 0x43,
  75481. 0x55, 0xa2, 0x6b, 0x6b, 0x16, 0xa7, 0x63, 0x06,
  75482. 0xa7, 0x78, 0x4f, 0xda, 0xae, 0x10, 0x6d, 0xd1,
  75483. 0x2e, 0x1d, 0xbb, 0xbc, 0xc4, 0x1d, 0x82, 0xe4,
  75484. 0xc6, 0x76, 0x77, 0xa6, 0x0a, 0xef, 0xd2, 0x89,
  75485. 0xff, 0x30, 0x85, 0x22, 0xa0, 0x68, 0x88, 0x54,
  75486. 0xa3, 0xd1, 0x92, 0xd1, 0x3f, 0x57, 0xe4, 0xc7,
  75487. 0x43, 0x5a, 0x8b, 0xb3, 0x86, 0xaf, 0xd5, 0x6d,
  75488. 0x07, 0xe1, 0xa0, 0x5f, 0xe1, 0x9a, 0x06, 0xba,
  75489. 0x56, 0xd2, 0xb0, 0x73, 0xf5, 0xb3, 0xd0, 0x5f,
  75490. 0xc0, 0xbf, 0x22, 0x4c, 0x54, 0x4e, 0x11, 0xe2,
  75491. 0xc5, 0xf8, 0x66, 0x39, 0x9d, 0x70, 0x90, 0x31
  75492. };
  75493. #endif
  75494. #else
  75495. const unsigned char* privDer = client_key_der_2048;
  75496. size_t privDerSz = sizeof_client_key_der_2048;
  75497. unsigned char encMsg[2048/8];
  75498. const unsigned char expEncMsg[] = {
  75499. 0x16, 0x5d, 0xbb, 0x00, 0x38, 0x73, 0x01, 0x34,
  75500. 0xca, 0x59, 0xc6, 0x8b, 0x64, 0x70, 0x89, 0xf5,
  75501. 0x50, 0x2d, 0x1d, 0x69, 0x1f, 0x07, 0x1e, 0x31,
  75502. 0xae, 0x9b, 0xa6, 0x6e, 0xee, 0x80, 0xd9, 0x9e,
  75503. 0x59, 0x33, 0x70, 0x30, 0x28, 0x42, 0x7d, 0x24,
  75504. 0x36, 0x95, 0x6b, 0xf9, 0x0a, 0x23, 0xcb, 0xce,
  75505. 0x66, 0xa5, 0x07, 0x5e, 0x11, 0xa7, 0xdc, 0xfb,
  75506. 0xd9, 0xc2, 0x51, 0xf0, 0x05, 0xc9, 0x39, 0xb3,
  75507. 0xae, 0xff, 0xfb, 0xe9, 0xb1, 0x9a, 0x54, 0xac,
  75508. 0x1d, 0xca, 0x42, 0x1a, 0xfd, 0x7c, 0x97, 0xa0,
  75509. 0x60, 0x2b, 0xcd, 0xb6, 0x36, 0x33, 0xfc, 0x44,
  75510. 0x69, 0xf7, 0x2e, 0x8c, 0x3b, 0x5f, 0xb4, 0x9f,
  75511. 0xa7, 0x02, 0x8f, 0x6d, 0x6b, 0x79, 0x10, 0x32,
  75512. 0x7d, 0xf4, 0x5d, 0xa1, 0x63, 0x22, 0x59, 0xc4,
  75513. 0x44, 0x8e, 0x44, 0x24, 0x8b, 0x14, 0x9d, 0x2b,
  75514. 0xb5, 0xd3, 0xad, 0x9a, 0x87, 0x0d, 0xe7, 0x70,
  75515. 0x6d, 0xe9, 0xae, 0xaa, 0x52, 0xbf, 0x1a, 0x9b,
  75516. 0xc8, 0x3d, 0x45, 0x7c, 0xd1, 0x90, 0xe3, 0xd9,
  75517. 0x57, 0xcf, 0xc3, 0x29, 0x69, 0x05, 0x07, 0x96,
  75518. 0x2e, 0x46, 0x74, 0x0a, 0xa7, 0x76, 0x8b, 0xc0,
  75519. 0x1c, 0x04, 0x80, 0x08, 0xa0, 0x94, 0x7e, 0xbb,
  75520. 0x2d, 0x99, 0xe9, 0xab, 0x18, 0x4d, 0x48, 0x2d,
  75521. 0x94, 0x5e, 0x50, 0x21, 0x42, 0xdf, 0xf5, 0x61,
  75522. 0x42, 0x7d, 0x86, 0x5d, 0x9e, 0x89, 0xc9, 0x5b,
  75523. 0x24, 0xab, 0xa1, 0xd8, 0x20, 0x45, 0xcb, 0x81,
  75524. 0xcf, 0xc5, 0x25, 0x7d, 0x11, 0x6e, 0xbd, 0x80,
  75525. 0xac, 0xba, 0xdc, 0xef, 0xb9, 0x05, 0x9c, 0xd5,
  75526. 0xc2, 0x26, 0x57, 0x69, 0x8b, 0x08, 0x27, 0xc7,
  75527. 0xea, 0xbe, 0xaf, 0x52, 0x21, 0x95, 0x9f, 0xa0,
  75528. 0x2f, 0x2f, 0x53, 0x7c, 0x2f, 0xa3, 0x0b, 0x79,
  75529. 0x39, 0x01, 0xa3, 0x37, 0x46, 0xa8, 0xc4, 0x34,
  75530. 0x41, 0x20, 0x7c, 0x3f, 0x70, 0x9a, 0x47, 0xe8
  75531. };
  75532. #ifdef WC_RSA_NO_PADDING
  75533. const unsigned char expEncMsgNoPad[] = {
  75534. 0x79, 0x69, 0xdc, 0x0d, 0xff, 0x09, 0xeb, 0x91,
  75535. 0xbc, 0xda, 0xe4, 0xd3, 0xcd, 0xd5, 0xd3, 0x1c,
  75536. 0xb9, 0x66, 0xa8, 0x02, 0xf3, 0x75, 0x40, 0xf1,
  75537. 0x38, 0x4a, 0x37, 0x7b, 0x19, 0xc8, 0xcd, 0xea,
  75538. 0x79, 0xa8, 0x51, 0x32, 0x00, 0x3f, 0x4c, 0xde,
  75539. 0xaa, 0xe5, 0xe2, 0x7c, 0x10, 0xcd, 0x6e, 0x00,
  75540. 0xc6, 0xc4, 0x63, 0x98, 0x58, 0x9b, 0x38, 0xca,
  75541. 0xf0, 0x5d, 0xc8, 0xf0, 0x57, 0xf6, 0x21, 0x50,
  75542. 0x3f, 0x63, 0x05, 0x9f, 0xbf, 0xb6, 0x3b, 0x50,
  75543. 0x85, 0x06, 0x34, 0x08, 0x57, 0xb9, 0x44, 0xce,
  75544. 0xe4, 0x66, 0xbf, 0x0c, 0xfe, 0x36, 0xa4, 0x5b,
  75545. 0xed, 0x2d, 0x7d, 0xed, 0xf1, 0xbd, 0xda, 0x3e,
  75546. 0x19, 0x1f, 0x99, 0xc8, 0xe4, 0xc2, 0xbb, 0xb5,
  75547. 0x6c, 0x83, 0x22, 0xd1, 0xe7, 0x57, 0xcf, 0x1b,
  75548. 0x91, 0x0c, 0xa5, 0x47, 0x06, 0x71, 0x8f, 0x93,
  75549. 0xf3, 0xad, 0xdb, 0xe3, 0xf8, 0xa0, 0x0b, 0xcd,
  75550. 0x89, 0x4e, 0xa5, 0xb5, 0x03, 0x68, 0x61, 0x89,
  75551. 0x0b, 0xe2, 0x03, 0x8b, 0x1f, 0x54, 0xae, 0x0f,
  75552. 0xfa, 0xf0, 0xb7, 0x0f, 0x8c, 0x84, 0x35, 0x13,
  75553. 0x8d, 0x65, 0x1f, 0x2c, 0xd5, 0xce, 0xc4, 0x6c,
  75554. 0x98, 0x67, 0xe4, 0x1a, 0x85, 0x67, 0x69, 0x17,
  75555. 0x17, 0x5a, 0x5d, 0xfd, 0x23, 0xdd, 0x03, 0x3f,
  75556. 0x6d, 0x7a, 0xb6, 0x8b, 0x99, 0xc0, 0xb6, 0x70,
  75557. 0x86, 0xac, 0xf6, 0x02, 0xc2, 0x28, 0x42, 0xed,
  75558. 0x06, 0xcf, 0xca, 0x3d, 0x07, 0x16, 0xf0, 0x0e,
  75559. 0x04, 0x55, 0x1e, 0x59, 0x3f, 0x32, 0xc7, 0x12,
  75560. 0xc5, 0x0d, 0x9d, 0x64, 0x7d, 0x2e, 0xd4, 0xbc,
  75561. 0x8c, 0x24, 0x42, 0x94, 0x2b, 0xf6, 0x11, 0x7f,
  75562. 0xb1, 0x1c, 0x09, 0x12, 0x6f, 0x5e, 0x2e, 0x7a,
  75563. 0xc6, 0x01, 0xe0, 0x98, 0x31, 0xb7, 0x13, 0x03,
  75564. 0xce, 0x29, 0xe1, 0xef, 0x9d, 0xdf, 0x9b, 0xa5,
  75565. 0xba, 0x0b, 0xad, 0xf2, 0xeb, 0x2f, 0xf9, 0xd1
  75566. };
  75567. #endif
  75568. #endif
  75569. const unsigned char* der;
  75570. XMEMSET(msg, 0x00, sizeof(msg));
  75571. der = privDer;
  75572. rsa = NULL;
  75573. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75574. ExpectIntEQ(RSA_private_encrypt(0, NULL, NULL, NULL, 0), -1);
  75575. ExpectIntEQ(RSA_private_encrypt(0, msg, encMsg, rsa, RSA_PKCS1_PADDING),
  75576. -1);
  75577. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), NULL, encMsg, rsa,
  75578. RSA_PKCS1_PADDING), -1);
  75579. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, NULL, rsa,
  75580. RSA_PKCS1_PADDING), -1);
  75581. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, NULL,
  75582. RSA_PKCS1_PADDING), -1);
  75583. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  75584. RSA_PKCS1_PSS_PADDING), -1);
  75585. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  75586. RSA_PKCS1_PADDING), sizeof(encMsg));
  75587. ExpectIntEQ(XMEMCMP(encMsg, expEncMsg, sizeof(expEncMsg)), 0);
  75588. #ifdef WC_RSA_NO_PADDING
  75589. /* Non-zero message. */
  75590. XMEMSET(msg, 0x01, sizeof(msg));
  75591. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  75592. RSA_NO_PADDING), sizeof(encMsg));
  75593. ExpectIntEQ(XMEMCMP(encMsg, expEncMsgNoPad, sizeof(expEncMsgNoPad)), 0);
  75594. #endif
  75595. RSA_free(rsa);
  75596. #endif
  75597. return EXPECT_RESULT();
  75598. }
  75599. static int test_wolfSSL_RSA_public_encrypt(void)
  75600. {
  75601. EXPECT_DECLS;
  75602. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75603. RSA* rsa = NULL;
  75604. const unsigned char msg[2048/8] = { 0 };
  75605. unsigned char encMsg[2048/8];
  75606. ExpectNotNull(rsa = RSA_new());
  75607. ExpectIntEQ(RSA_public_encrypt(-1, msg, encMsg, rsa,
  75608. RSA_PKCS1_PADDING), -1);
  75609. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), NULL, encMsg, rsa,
  75610. RSA_PKCS1_PADDING), -1);
  75611. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, NULL, rsa,
  75612. RSA_PKCS1_PADDING), -1);
  75613. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, NULL,
  75614. RSA_PKCS1_PADDING), -1);
  75615. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, rsa,
  75616. RSA_PKCS1_PSS_PADDING), -1);
  75617. /* Empty RSA key. */
  75618. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, rsa,
  75619. RSA_PKCS1_PADDING), -1);
  75620. RSA_free(rsa);
  75621. #endif
  75622. return EXPECT_RESULT();
  75623. }
  75624. static int test_wolfSSL_RSA_private_decrypt(void)
  75625. {
  75626. EXPECT_DECLS;
  75627. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75628. RSA* rsa = NULL;
  75629. unsigned char msg[2048/8];
  75630. const unsigned char encMsg[2048/8] = { 0 };
  75631. ExpectNotNull(rsa = RSA_new());
  75632. ExpectIntEQ(RSA_private_decrypt(-1, encMsg, msg, rsa,
  75633. RSA_PKCS1_PADDING), -1);
  75634. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), NULL, msg, rsa,
  75635. RSA_PKCS1_PADDING), -1);
  75636. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, NULL, rsa,
  75637. RSA_PKCS1_PADDING), -1);
  75638. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, NULL,
  75639. RSA_PKCS1_PADDING), -1);
  75640. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, rsa,
  75641. RSA_PKCS1_PSS_PADDING), -1);
  75642. /* Empty RSA key. */
  75643. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, rsa,
  75644. RSA_PKCS1_PADDING), -1);
  75645. RSA_free(rsa);
  75646. #endif
  75647. return EXPECT_RESULT();
  75648. }
  75649. static int test_wolfSSL_RSA_GenAdd(void)
  75650. {
  75651. EXPECT_DECLS;
  75652. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75653. RSA *rsa;
  75654. #ifdef USE_CERT_BUFFERS_1024
  75655. const unsigned char* privDer = client_key_der_1024;
  75656. size_t privDerSz = sizeof_client_key_der_1024;
  75657. const unsigned char* pubDer = client_keypub_der_1024;
  75658. size_t pubDerSz = sizeof_client_keypub_der_1024;
  75659. #else
  75660. const unsigned char* privDer = client_key_der_2048;
  75661. size_t privDerSz = sizeof_client_key_der_2048;
  75662. const unsigned char* pubDer = client_keypub_der_2048;
  75663. size_t pubDerSz = sizeof_client_keypub_der_2048;
  75664. #endif
  75665. const unsigned char* der;
  75666. der = privDer;
  75667. rsa = NULL;
  75668. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75669. ExpectIntEQ(wolfSSL_RSA_GenAdd(NULL), -1);
  75670. #ifndef RSA_LOW_MEM
  75671. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), 1);
  75672. #else
  75673. /* dmp1 and dmq1 are not set (allocated) when RSA_LOW_MEM. */
  75674. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), -1);
  75675. #endif
  75676. RSA_free(rsa);
  75677. der = pubDer;
  75678. rsa = NULL;
  75679. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  75680. /* Need private values. */
  75681. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), -1);
  75682. RSA_free(rsa);
  75683. #endif
  75684. return EXPECT_RESULT();
  75685. }
  75686. static int test_wolfSSL_RSA_blinding_on(void)
  75687. {
  75688. EXPECT_DECLS;
  75689. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_STUB)
  75690. RSA *rsa;
  75691. WOLFSSL_BN_CTX *bnCtx = NULL;
  75692. #ifdef USE_CERT_BUFFERS_1024
  75693. const unsigned char* privDer = client_key_der_1024;
  75694. size_t privDerSz = sizeof_client_key_der_1024;
  75695. #else
  75696. const unsigned char* privDer = client_key_der_2048;
  75697. size_t privDerSz = sizeof_client_key_der_2048;
  75698. #endif
  75699. const unsigned char* der;
  75700. der = privDer;
  75701. rsa = NULL;
  75702. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75703. ExpectNotNull(bnCtx = wolfSSL_BN_CTX_new());
  75704. /* Does nothing so all parameters are valid. */
  75705. ExpectIntEQ(wolfSSL_RSA_blinding_on(NULL, NULL), 1);
  75706. ExpectIntEQ(wolfSSL_RSA_blinding_on(rsa, NULL), 1);
  75707. ExpectIntEQ(wolfSSL_RSA_blinding_on(NULL, bnCtx), 1);
  75708. ExpectIntEQ(wolfSSL_RSA_blinding_on(rsa, bnCtx), 1);
  75709. wolfSSL_BN_CTX_free(bnCtx);
  75710. RSA_free(rsa);
  75711. #endif
  75712. return EXPECT_RESULT();
  75713. }
  75714. static int test_wolfSSL_RSA_ex_data(void)
  75715. {
  75716. EXPECT_DECLS;
  75717. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA)
  75718. RSA* rsa = NULL;
  75719. unsigned char data[1];
  75720. ExpectNotNull(rsa = RSA_new());
  75721. ExpectNull(wolfSSL_RSA_get_ex_data(NULL, 0));
  75722. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, 0));
  75723. #ifdef MAX_EX_DATA
  75724. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, MAX_EX_DATA));
  75725. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, MAX_EX_DATA, data), 0);
  75726. #endif
  75727. ExpectIntEQ(wolfSSL_RSA_set_ex_data(NULL, 0, NULL), 0);
  75728. ExpectIntEQ(wolfSSL_RSA_set_ex_data(NULL, 0, data), 0);
  75729. #ifdef HAVE_EX_DATA
  75730. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, NULL), 1);
  75731. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, data), 1);
  75732. ExpectPtrEq(wolfSSL_RSA_get_ex_data(rsa, 0), data);
  75733. #else
  75734. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, NULL), 0);
  75735. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, data), 0);
  75736. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, 0));
  75737. #endif
  75738. RSA_free(rsa);
  75739. #endif /* !NO_RSA && OPENSSL_EXTRA */
  75740. return EXPECT_RESULT();
  75741. }
  75742. static int test_wolfSSL_RSA_LoadDer(void)
  75743. {
  75744. EXPECT_DECLS;
  75745. #if !defined(NO_RSA) && (defined(OPENSSL_EXTRA) || \
  75746. defined(OPENSSL_EXTRA_X509_SMALL))
  75747. RSA *rsa = NULL;
  75748. #ifdef USE_CERT_BUFFERS_1024
  75749. const unsigned char* privDer = client_key_der_1024;
  75750. size_t privDerSz = sizeof_client_key_der_1024;
  75751. #else
  75752. const unsigned char* privDer = client_key_der_2048;
  75753. size_t privDerSz = sizeof_client_key_der_2048;
  75754. #endif
  75755. ExpectNotNull(rsa = RSA_new());
  75756. ExpectIntEQ(wolfSSL_RSA_LoadDer(NULL, privDer, (int)privDerSz), -1);
  75757. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, NULL, (int)privDerSz), -1);
  75758. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, privDer, 0), -1);
  75759. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, privDer, (int)privDerSz), 1);
  75760. RSA_free(rsa);
  75761. #endif /* !NO_RSA && OPENSSL_EXTRA */
  75762. return EXPECT_RESULT();
  75763. }
  75764. /* Local API. */
  75765. static int test_wolfSSL_RSA_To_Der(void)
  75766. {
  75767. EXPECT_DECLS;
  75768. #ifdef WOLFSSL_TEST_STATIC_BUILD
  75769. #if defined(WOLFSSL_KEY_GEN) && defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75770. RSA* rsa;
  75771. #ifdef USE_CERT_BUFFERS_1024
  75772. const unsigned char* privDer = client_key_der_1024;
  75773. size_t privDerSz = sizeof_client_key_der_1024;
  75774. const unsigned char* pubDer = client_keypub_der_1024;
  75775. size_t pubDerSz = sizeof_client_keypub_der_1024;
  75776. unsigned char out[sizeof(client_key_der_1024)];
  75777. #else
  75778. const unsigned char* privDer = client_key_der_2048;
  75779. size_t privDerSz = sizeof_client_key_der_2048;
  75780. const unsigned char* pubDer = client_keypub_der_2048;
  75781. size_t pubDerSz = sizeof_client_keypub_der_2048;
  75782. unsigned char out[sizeof(client_key_der_2048)];
  75783. #endif
  75784. const unsigned char* der;
  75785. unsigned char* outDer = NULL;
  75786. der = privDer;
  75787. rsa = NULL;
  75788. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75789. ExpectIntEQ(wolfSSL_RSA_To_Der(NULL, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  75790. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 2, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  75791. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, NULL, 0, HEAP_HINT), privDerSz);
  75792. outDer = out;
  75793. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), privDerSz);
  75794. ExpectIntEQ(XMEMCMP(out, privDer, privDerSz), 0);
  75795. outDer = NULL;
  75796. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), privDerSz);
  75797. ExpectNotNull(outDer);
  75798. ExpectIntEQ(XMEMCMP(outDer, privDer, privDerSz), 0);
  75799. XFREE(outDer, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  75800. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, NULL, 1, HEAP_HINT), pubDerSz);
  75801. outDer = out;
  75802. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 1, HEAP_HINT), pubDerSz);
  75803. ExpectIntEQ(XMEMCMP(out, pubDer, pubDerSz), 0);
  75804. RSA_free(rsa);
  75805. ExpectNotNull(rsa = RSA_new());
  75806. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  75807. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 1, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  75808. RSA_free(rsa);
  75809. der = pubDer;
  75810. rsa = NULL;
  75811. ExpectNotNull(wolfSSL_d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  75812. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  75813. RSA_free(rsa);
  75814. #endif
  75815. #endif
  75816. return EXPECT_RESULT();
  75817. }
  75818. /* wolfSSL_PEM_read_RSAPublicKey is a stub function. */
  75819. static int test_wolfSSL_PEM_read_RSAPublicKey(void)
  75820. {
  75821. EXPECT_DECLS;
  75822. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM)
  75823. XFILE file = XBADFILE;
  75824. const char* fname = "./certs/server-keyPub.pem";
  75825. RSA *rsa = NULL;
  75826. ExpectNull(wolfSSL_PEM_read_RSAPublicKey(XBADFILE, NULL, NULL, NULL));
  75827. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  75828. ExpectNotNull(rsa = PEM_read_RSA_PUBKEY(file, NULL, NULL, NULL));
  75829. ExpectIntEQ(RSA_size(rsa), 256);
  75830. RSA_free(rsa);
  75831. if (file != XBADFILE)
  75832. XFCLOSE(file);
  75833. #endif
  75834. return EXPECT_RESULT();
  75835. }
  75836. /* wolfSSL_PEM_read_RSAPublicKey is a stub function. */
  75837. static int test_wolfSSL_PEM_write_RSA_PUBKEY(void)
  75838. {
  75839. EXPECT_DECLS;
  75840. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  75841. defined(WOLFSSL_KEY_GEN)
  75842. RSA* rsa = NULL;
  75843. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(XBADFILE, NULL), 0);
  75844. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(stderr, NULL), 0);
  75845. /* Valid but stub so returns 0. */
  75846. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(stderr, rsa), 0);
  75847. #endif
  75848. return EXPECT_RESULT();
  75849. }
  75850. static int test_wolfSSL_PEM_write_RSAPrivateKey(void)
  75851. {
  75852. EXPECT_DECLS;
  75853. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  75854. (defined(WOLFSSL_PEM_TO_DER) || \
  75855. defined(WOLFSSL_DER_TO_PEM)) && !defined(NO_FILESYSTEM)
  75856. RSA* rsa = NULL;
  75857. #ifdef USE_CERT_BUFFERS_1024
  75858. const unsigned char* privDer = client_key_der_1024;
  75859. size_t privDerSz = sizeof_client_key_der_1024;
  75860. #else
  75861. const unsigned char* privDer = client_key_der_2048;
  75862. size_t privDerSz = sizeof_client_key_der_2048;
  75863. #endif
  75864. const unsigned char* der;
  75865. #ifndef NO_AES
  75866. unsigned char passwd[] = "password";
  75867. #endif
  75868. ExpectNotNull(rsa = RSA_new());
  75869. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0,
  75870. NULL, NULL), 0);
  75871. RSA_free(rsa);
  75872. der = privDer;
  75873. rsa = NULL;
  75874. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75875. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(XBADFILE, rsa, NULL, NULL, 0,
  75876. NULL, NULL), 0);
  75877. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, NULL, NULL, NULL, 0,
  75878. NULL, NULL), 0);
  75879. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0,
  75880. NULL, NULL), 1);
  75881. #ifndef NO_AES
  75882. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, EVP_aes_128_cbc(),
  75883. NULL, 0, NULL, NULL), 1);
  75884. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, EVP_aes_128_cbc(),
  75885. passwd, sizeof(passwd) - 1, NULL, NULL), 1);
  75886. #endif
  75887. RSA_free(rsa);
  75888. #endif
  75889. return EXPECT_RESULT();
  75890. }
  75891. static int test_wolfSSL_PEM_write_mem_RSAPrivateKey(void)
  75892. {
  75893. EXPECT_DECLS;
  75894. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  75895. (defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM))
  75896. RSA* rsa = NULL;
  75897. #ifdef USE_CERT_BUFFERS_1024
  75898. const unsigned char* privDer = client_key_der_1024;
  75899. size_t privDerSz = sizeof_client_key_der_1024;
  75900. #else
  75901. const unsigned char* privDer = client_key_der_2048;
  75902. size_t privDerSz = sizeof_client_key_der_2048;
  75903. #endif
  75904. const unsigned char* der;
  75905. #ifndef NO_AES
  75906. unsigned char passwd[] = "password";
  75907. #endif
  75908. unsigned char* pem = NULL;
  75909. int plen;
  75910. ExpectNotNull(rsa = RSA_new());
  75911. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  75912. &plen), 0);
  75913. RSA_free(rsa);
  75914. der = privDer;
  75915. rsa = NULL;
  75916. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75917. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(NULL, NULL, NULL, 0, &pem,
  75918. &plen), 0);
  75919. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, NULL,
  75920. &plen), 0);
  75921. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  75922. NULL), 0);
  75923. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  75924. &plen), 1);
  75925. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  75926. pem = NULL;
  75927. #ifndef NO_AES
  75928. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, EVP_aes_128_cbc(),
  75929. NULL, 0, &pem, &plen), 1);
  75930. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  75931. pem = NULL;
  75932. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, EVP_aes_128_cbc(),
  75933. passwd, sizeof(passwd) - 1, &pem, &plen), 1);
  75934. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  75935. #endif
  75936. RSA_free(rsa);
  75937. #endif
  75938. return EXPECT_RESULT();
  75939. }
  75940. static int test_wolfSSL_DH(void)
  75941. {
  75942. EXPECT_DECLS;
  75943. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  75944. DH *dh = NULL;
  75945. BIGNUM* p;
  75946. BIGNUM* q;
  75947. BIGNUM* g;
  75948. BIGNUM* pub = NULL;
  75949. BIGNUM* priv = NULL;
  75950. #if defined(OPENSSL_ALL)
  75951. #if !defined(HAVE_FIPS) || \
  75952. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  75953. FILE* f = NULL;
  75954. unsigned char buf[268];
  75955. const unsigned char* pt = buf;
  75956. long len = 0;
  75957. dh = NULL;
  75958. XMEMSET(buf, 0, sizeof(buf));
  75959. /* Test 2048 bit parameters */
  75960. ExpectTrue((f = XFOPEN("./certs/dh2048.der", "rb")) != XBADFILE);
  75961. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  75962. if (f != XBADFILE)
  75963. XFCLOSE(f);
  75964. ExpectNotNull(dh = d2i_DHparams(NULL, &pt, len));
  75965. ExpectNotNull(dh->p);
  75966. ExpectNotNull(dh->g);
  75967. ExpectTrue(pt == buf);
  75968. ExpectIntEQ(DH_generate_key(dh), 1);
  75969. /* first, test for expected successful key agreement. */
  75970. if (EXPECT_SUCCESS()) {
  75971. DH *dh2 = NULL;
  75972. unsigned char buf2[268];
  75973. int sz1 = 0, sz2 = 0;
  75974. ExpectNotNull(dh2 = d2i_DHparams(NULL, &pt, len));
  75975. ExpectIntEQ(DH_generate_key(dh2), 1);
  75976. ExpectIntGT(sz1=DH_compute_key(buf, dh2->pub_key, dh), 0);
  75977. ExpectIntGT(sz2=DH_compute_key(buf2, dh->pub_key, dh2), 0);
  75978. ExpectIntEQ(sz1, sz2);
  75979. ExpectIntEQ(XMEMCMP(buf, buf2, (size_t)sz1), 0);
  75980. ExpectIntNE(sz1 = DH_size(dh), 0);
  75981. ExpectIntEQ(DH_compute_key_padded(buf, dh2->pub_key, dh), sz1);
  75982. ExpectIntEQ(DH_compute_key_padded(buf2, dh->pub_key, dh2), sz1);
  75983. ExpectIntEQ(XMEMCMP(buf, buf2, (size_t)sz1), 0);
  75984. if (dh2 != NULL)
  75985. DH_free(dh2);
  75986. }
  75987. ExpectIntEQ(DH_generate_key(dh), 1);
  75988. ExpectIntEQ(DH_compute_key(NULL, NULL, NULL), -1);
  75989. ExpectNotNull(pub = BN_new());
  75990. ExpectIntEQ(BN_set_word(pub, 1), 1);
  75991. ExpectIntEQ(DH_compute_key(buf, NULL, NULL), -1);
  75992. ExpectIntEQ(DH_compute_key(NULL, pub, NULL), -1);
  75993. ExpectIntEQ(DH_compute_key(NULL, NULL, dh), -1);
  75994. ExpectIntEQ(DH_compute_key(buf, pub, NULL), -1);
  75995. ExpectIntEQ(DH_compute_key(buf, NULL, dh), -1);
  75996. ExpectIntEQ(DH_compute_key(NULL, pub, dh), -1);
  75997. ExpectIntEQ(DH_compute_key(buf, pub, dh), -1);
  75998. BN_free(pub);
  75999. pub = NULL;
  76000. DH_get0_pqg(dh, (const BIGNUM**)&p,
  76001. (const BIGNUM**)&q,
  76002. (const BIGNUM**)&g);
  76003. ExpectPtrEq(p, dh->p);
  76004. ExpectPtrEq(q, dh->q);
  76005. ExpectPtrEq(g, dh->g);
  76006. DH_get0_key(NULL, (const BIGNUM**)&pub, (const BIGNUM**)&priv);
  76007. DH_get0_key(dh, (const BIGNUM**)&pub, (const BIGNUM**)&priv);
  76008. ExpectPtrEq(pub, dh->pub_key);
  76009. ExpectPtrEq(priv, dh->priv_key);
  76010. DH_get0_key(dh, (const BIGNUM**)&pub, NULL);
  76011. ExpectPtrEq(pub, dh->pub_key);
  76012. DH_get0_key(dh, NULL, (const BIGNUM**)&priv);
  76013. ExpectPtrEq(priv, dh->priv_key);
  76014. pub = NULL;
  76015. priv = NULL;
  76016. ExpectNotNull(pub = BN_new());
  76017. ExpectNotNull(priv = BN_new());
  76018. ExpectIntEQ(DH_set0_key(NULL, pub, priv), 0);
  76019. ExpectIntEQ(DH_set0_key(dh, pub, priv), 1);
  76020. if (EXPECT_FAIL()) {
  76021. BN_free(pub);
  76022. BN_free(priv);
  76023. }
  76024. pub = NULL;
  76025. priv = NULL;
  76026. ExpectNotNull(pub = BN_new());
  76027. ExpectIntEQ(DH_set0_key(dh, pub, NULL), 1);
  76028. if (EXPECT_FAIL()) {
  76029. BN_free(pub);
  76030. }
  76031. ExpectNotNull(priv = BN_new());
  76032. ExpectIntEQ(DH_set0_key(dh, NULL, priv), 1);
  76033. if (EXPECT_FAIL()) {
  76034. BN_free(priv);
  76035. }
  76036. ExpectPtrEq(pub, dh->pub_key);
  76037. ExpectPtrEq(priv, dh->priv_key);
  76038. pub = NULL;
  76039. priv = NULL;
  76040. DH_free(dh);
  76041. dh = NULL;
  76042. ExpectNotNull(dh = DH_new());
  76043. p = NULL;
  76044. ExpectNotNull(p = BN_new());
  76045. ExpectIntEQ(BN_set_word(p, 1), 1);
  76046. ExpectIntEQ(DH_compute_key(buf, p, dh), -1);
  76047. ExpectNotNull(pub = BN_new());
  76048. ExpectNotNull(priv = BN_new());
  76049. ExpectIntEQ(DH_set0_key(dh, pub, priv), 1);
  76050. if (EXPECT_FAIL()) {
  76051. BN_free(pub);
  76052. BN_free(priv);
  76053. }
  76054. pub = NULL;
  76055. priv = NULL;
  76056. ExpectIntEQ(DH_compute_key(buf, p, dh), -1);
  76057. BN_free(p);
  76058. p = NULL;
  76059. DH_free(dh);
  76060. dh = NULL;
  76061. #ifdef WOLFSSL_KEY_GEN
  76062. ExpectNotNull(dh = DH_generate_parameters(2048, 2, NULL, NULL));
  76063. ExpectIntEQ(wolfSSL_DH_generate_parameters_ex(NULL, 2048, 2, NULL), 0);
  76064. DH_free(dh);
  76065. dh = NULL;
  76066. #endif
  76067. #endif /* !HAVE_FIPS || (HAVE_FIPS_VERSION && HAVE_FIPS_VERSION > 2) */
  76068. #endif /* OPENSSL_ALL */
  76069. (void)dh;
  76070. (void)p;
  76071. (void)q;
  76072. (void)g;
  76073. (void)pub;
  76074. (void)priv;
  76075. ExpectNotNull(dh = wolfSSL_DH_new());
  76076. /* invalid parameters test */
  76077. DH_get0_pqg(NULL, (const BIGNUM**)&p,
  76078. (const BIGNUM**)&q,
  76079. (const BIGNUM**)&g);
  76080. DH_get0_pqg(dh, NULL,
  76081. (const BIGNUM**)&q,
  76082. (const BIGNUM**)&g);
  76083. DH_get0_pqg(dh, NULL, NULL, (const BIGNUM**)&g);
  76084. DH_get0_pqg(dh, NULL, NULL, NULL);
  76085. DH_get0_pqg(dh, (const BIGNUM**)&p,
  76086. (const BIGNUM**)&q,
  76087. (const BIGNUM**)&g);
  76088. ExpectPtrEq(p, NULL);
  76089. ExpectPtrEq(q, NULL);
  76090. ExpectPtrEq(g, NULL);
  76091. DH_free(dh);
  76092. dh = NULL;
  76093. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS) && !defined(WOLFSSL_DH_EXTRA)) \
  76094. || (defined(HAVE_FIPS_VERSION) && FIPS_VERSION_GT(2,0))
  76095. #if defined(OPENSSL_ALL) || \
  76096. defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  76097. dh = wolfSSL_DH_new();
  76098. ExpectNotNull(dh);
  76099. p = wolfSSL_BN_new();
  76100. ExpectNotNull(p);
  76101. ExpectIntEQ(BN_set_word(p, 11), 1);
  76102. g = wolfSSL_BN_new();
  76103. ExpectNotNull(g);
  76104. ExpectIntEQ(BN_set_word(g, 2), 1);
  76105. q = wolfSSL_BN_new();
  76106. ExpectNotNull(q);
  76107. ExpectIntEQ(BN_set_word(q, 5), 1);
  76108. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, NULL, NULL), 0);
  76109. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, NULL), 0);
  76110. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, p, NULL, NULL), 0);
  76111. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, q, NULL), 0);
  76112. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, NULL, g), 0);
  76113. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, p, q, g), 0);
  76114. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, q, g), 0);
  76115. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, q, NULL), 0);
  76116. /* Don't need q. */
  76117. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  76118. if (EXPECT_FAIL()) {
  76119. BN_free(p);
  76120. BN_free(g);
  76121. }
  76122. p = NULL;
  76123. g = NULL;
  76124. /* Setting again will free the p and g. */
  76125. wolfSSL_BN_free(q);
  76126. q = NULL;
  76127. DH_free(dh);
  76128. dh = NULL;
  76129. dh = wolfSSL_DH_new();
  76130. ExpectNotNull(dh);
  76131. p = wolfSSL_BN_new();
  76132. ExpectNotNull(p);
  76133. ExpectIntEQ(BN_set_word(p, 11), 1);
  76134. g = wolfSSL_BN_new();
  76135. ExpectNotNull(g);
  76136. ExpectIntEQ(BN_set_word(g, 2), 1);
  76137. q = wolfSSL_BN_new();
  76138. ExpectNotNull(q);
  76139. ExpectIntEQ(BN_set_word(q, 5), 1);
  76140. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, q, g), 1);
  76141. /* p, q and g are now owned by dh - don't free. */
  76142. if (EXPECT_FAIL()) {
  76143. BN_free(p);
  76144. BN_free(q);
  76145. BN_free(g);
  76146. }
  76147. p = NULL;
  76148. q = NULL;
  76149. g = NULL;
  76150. p = wolfSSL_BN_new();
  76151. ExpectNotNull(p);
  76152. ExpectIntEQ(BN_set_word(p, 11), 1);
  76153. g = wolfSSL_BN_new();
  76154. ExpectNotNull(g);
  76155. ExpectIntEQ(BN_set_word(g, 2), 1);
  76156. q = wolfSSL_BN_new();
  76157. ExpectNotNull(q);
  76158. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, NULL), 1);
  76159. if (EXPECT_FAIL()) {
  76160. BN_free(p);
  76161. }
  76162. p = NULL;
  76163. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, q, NULL), 1);
  76164. if (EXPECT_FAIL()) {
  76165. BN_free(q);
  76166. }
  76167. q = NULL;
  76168. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, g), 1);
  76169. if (EXPECT_FAIL()) {
  76170. BN_free(g);
  76171. }
  76172. g = NULL;
  76173. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, NULL), 1);
  76174. /* p, q and g are now owned by dh - don't free. */
  76175. DH_free(dh);
  76176. dh = NULL;
  76177. ExpectIntEQ(DH_generate_key(NULL), 0);
  76178. ExpectNotNull(dh = DH_new());
  76179. ExpectIntEQ(DH_generate_key(dh), 0);
  76180. p = wolfSSL_BN_new();
  76181. ExpectNotNull(p);
  76182. ExpectIntEQ(BN_set_word(p, 0), 1);
  76183. g = wolfSSL_BN_new();
  76184. ExpectNotNull(g);
  76185. ExpectIntEQ(BN_set_word(g, 2), 1);
  76186. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  76187. if (EXPECT_FAIL()) {
  76188. BN_free(p);
  76189. BN_free(g);
  76190. }
  76191. p = NULL;
  76192. g = NULL;
  76193. ExpectIntEQ(DH_generate_key(dh), 0);
  76194. DH_free(dh);
  76195. dh = NULL;
  76196. #endif
  76197. #endif
  76198. /* Test DH_up_ref() */
  76199. dh = wolfSSL_DH_new();
  76200. ExpectNotNull(dh);
  76201. ExpectIntEQ(wolfSSL_DH_up_ref(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  76202. ExpectIntEQ(wolfSSL_DH_up_ref(dh), WOLFSSL_SUCCESS);
  76203. DH_free(dh); /* decrease ref count */
  76204. DH_free(dh); /* free WOLFSSL_DH */
  76205. dh = NULL;
  76206. q = NULL;
  76207. ExpectNull((dh = DH_new_by_nid(NID_sha1)));
  76208. #if (defined(HAVE_PUBLIC_FFDHE) || (defined(HAVE_FIPS) && \
  76209. FIPS_VERSION_EQ(2,0))) || (!defined(HAVE_PUBLIC_FFDHE) && \
  76210. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)))
  76211. #ifdef HAVE_FFDHE_2048
  76212. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe2048)));
  76213. DH_free(dh);
  76214. dh = NULL;
  76215. q = NULL;
  76216. #endif
  76217. #ifdef HAVE_FFDHE_3072
  76218. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe3072)));
  76219. DH_free(dh);
  76220. dh = NULL;
  76221. q = NULL;
  76222. #endif
  76223. #ifdef HAVE_FFDHE_4096
  76224. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe4096)));
  76225. DH_free(dh);
  76226. dh = NULL;
  76227. q = NULL;
  76228. #endif
  76229. #else
  76230. ExpectNull((dh = DH_new_by_nid(NID_ffdhe2048)));
  76231. #endif /* (HAVE_PUBLIC_FFDHE || (HAVE_FIPS && HAVE_FIPS_VERSION == 2)) ||
  76232. * (!HAVE_PUBLIC_FFDHE && (!HAVE_FIPS || HAVE_FIPS_VERSION > 2))*/
  76233. ExpectIntEQ(wolfSSL_DH_size(NULL), -1);
  76234. #endif /* OPENSSL_EXTRA && !NO_DH */
  76235. return EXPECT_RESULT();
  76236. }
  76237. static int test_wolfSSL_DH_dup(void)
  76238. {
  76239. EXPECT_DECLS;
  76240. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)
  76241. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH) || \
  76242. defined(OPENSSL_EXTRA)
  76243. DH *dh = NULL;
  76244. DH *dhDup = NULL;
  76245. ExpectNotNull(dh = wolfSSL_DH_new());
  76246. ExpectNull(dhDup = wolfSSL_DH_dup(NULL));
  76247. ExpectNull(dhDup = wolfSSL_DH_dup(dh));
  76248. #if defined(OPENSSL_ALL) || \
  76249. defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  76250. {
  76251. WOLFSSL_BIGNUM* p = NULL;
  76252. WOLFSSL_BIGNUM* g = NULL;
  76253. ExpectNotNull(p = wolfSSL_BN_new());
  76254. ExpectNotNull(g = wolfSSL_BN_new());
  76255. ExpectIntEQ(wolfSSL_BN_set_word(p, 11), WOLFSSL_SUCCESS);
  76256. ExpectIntEQ(wolfSSL_BN_set_word(g, 2), WOLFSSL_SUCCESS);
  76257. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  76258. if (EXPECT_FAIL()) {
  76259. wolfSSL_BN_free(p);
  76260. wolfSSL_BN_free(g);
  76261. }
  76262. ExpectNotNull(dhDup = wolfSSL_DH_dup(dh));
  76263. wolfSSL_DH_free(dhDup);
  76264. }
  76265. #endif
  76266. wolfSSL_DH_free(dh);
  76267. #endif
  76268. #endif
  76269. return EXPECT_RESULT();
  76270. }
  76271. static int test_wolfSSL_DH_check(void)
  76272. {
  76273. EXPECT_DECLS;
  76274. #ifdef OPENSSL_ALL
  76275. #ifndef NO_DH
  76276. #ifndef NO_BIO
  76277. #ifndef NO_DSA
  76278. byte buf[6000];
  76279. char file[] = "./certs/dsaparams.pem";
  76280. XFILE f = XBADFILE;
  76281. int bytes = 0;
  76282. BIO* bio = NULL;
  76283. DSA* dsa = NULL;
  76284. #elif !defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)
  76285. static const byte dh2048[] = {
  76286. 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01,
  76287. 0x00, 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13,
  76288. 0xba, 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5,
  76289. 0x00, 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a,
  76290. 0xc6, 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53,
  76291. 0x0a, 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84,
  76292. 0xbf, 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1,
  76293. 0x8a, 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91,
  76294. 0xe6, 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66,
  76295. 0x48, 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9,
  76296. 0x3d, 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e,
  76297. 0x19, 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d,
  76298. 0x9f, 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d,
  76299. 0x2a, 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75,
  76300. 0xe6, 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa,
  76301. 0x04, 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93,
  76302. 0x38, 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c,
  76303. 0xe5, 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35,
  76304. 0x8e, 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e,
  76305. 0x5a, 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76,
  76306. 0xcc, 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62,
  76307. 0xa7, 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0,
  76308. 0x36, 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40,
  76309. 0x90, 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a,
  76310. 0xc3, 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4,
  76311. 0x48, 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4,
  76312. 0x9a, 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90,
  76313. 0xab, 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58,
  76314. 0x4b, 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f,
  76315. 0x08, 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6,
  76316. 0xb6, 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67,
  76317. 0x6b, 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7,
  76318. 0xfa, 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f,
  76319. 0x93, 0x02, 0x01, 0x02
  76320. };
  76321. const byte* params;
  76322. #endif
  76323. DH* dh = NULL;
  76324. WOLFSSL_BIGNUM* p = NULL;
  76325. WOLFSSL_BIGNUM* g = NULL;
  76326. WOLFSSL_BIGNUM* pTmp = NULL;
  76327. WOLFSSL_BIGNUM* gTmp = NULL;
  76328. int codes = -1;
  76329. #ifndef NO_DSA
  76330. /* Initialize DH */
  76331. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  76332. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  76333. if (f != XBADFILE)
  76334. XFCLOSE(f);
  76335. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  76336. ExpectNotNull(dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL));
  76337. ExpectNotNull(dh = wolfSSL_DSA_dup_DH(dsa));
  76338. ExpectNotNull(dh);
  76339. BIO_free(bio);
  76340. DSA_free(dsa);
  76341. #elif !defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)
  76342. params = dh2048;
  76343. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &params,
  76344. (long)sizeof(dh2048)));
  76345. #else
  76346. ExpectNotNull(dh = wolfSSL_DH_new_by_nid(NID_ffdhe2048));
  76347. #endif
  76348. /* Test assumed to be valid dh.
  76349. * Should return WOLFSSL_SUCCESS
  76350. * codes should be 0
  76351. * Invalid codes = {DH_NOT_SUITABLE_GENERATOR, DH_CHECK_P_NOT_PRIME}
  76352. */
  76353. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  76354. ExpectIntEQ(codes, 0);
  76355. /* Test NULL dh: expected BAD_FUNC_ARG */
  76356. ExpectIntEQ(wolfSSL_DH_check(NULL, &codes), 0);
  76357. /* Break dh prime to test if codes = DH_CHECK_P_NOT_PRIME */
  76358. if (dh != NULL) {
  76359. pTmp = dh->p;
  76360. dh->p = NULL;
  76361. }
  76362. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  76363. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  76364. ExpectIntEQ(codes, DH_CHECK_P_NOT_PRIME);
  76365. /* set dh->p back to normal so it won't fail on next tests */
  76366. if (dh != NULL) {
  76367. dh->p = pTmp;
  76368. pTmp = NULL;
  76369. }
  76370. /* Break dh generator to test if codes = DH_NOT_SUITABLE_GENERATOR */
  76371. if (dh != NULL) {
  76372. gTmp = dh->g;
  76373. dh->g = NULL;
  76374. }
  76375. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  76376. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  76377. ExpectIntEQ(codes, DH_NOT_SUITABLE_GENERATOR);
  76378. if (dh != NULL) {
  76379. dh->g = gTmp;
  76380. gTmp = NULL;
  76381. }
  76382. /* Cleanup */
  76383. DH_free(dh);
  76384. dh = NULL;
  76385. dh = DH_new();
  76386. ExpectNotNull(dh);
  76387. /* Check empty DH. */
  76388. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  76389. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  76390. ExpectIntEQ(codes, DH_NOT_SUITABLE_GENERATOR | DH_CHECK_P_NOT_PRIME);
  76391. /* Check non-prime valued p. */
  76392. ExpectNotNull(p = BN_new());
  76393. ExpectIntEQ(BN_set_word(p, 4), 1);
  76394. ExpectNotNull(g = BN_new());
  76395. ExpectIntEQ(BN_set_word(g, 2), 1);
  76396. ExpectIntEQ(DH_set0_pqg(dh, p, NULL, g), 1);
  76397. if (EXPECT_FAIL()) {
  76398. wolfSSL_BN_free(p);
  76399. wolfSSL_BN_free(g);
  76400. }
  76401. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  76402. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  76403. ExpectIntEQ(codes, DH_CHECK_P_NOT_PRIME);
  76404. DH_free(dh);
  76405. dh = NULL;
  76406. #endif
  76407. #endif /* !NO_DH && !NO_DSA */
  76408. #endif
  76409. return EXPECT_RESULT();
  76410. }
  76411. static int test_wolfSSL_DH_prime(void)
  76412. {
  76413. EXPECT_DECLS;
  76414. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  76415. WOLFSSL_BIGNUM* bn = NULL;
  76416. #if WOLFSSL_MAX_BN_BITS >= 768
  76417. WOLFSSL_BIGNUM* bn2 = NULL;
  76418. #endif
  76419. bn = wolfSSL_DH_768_prime(NULL);
  76420. #if WOLFSSL_MAX_BN_BITS >= 768
  76421. ExpectNotNull(bn);
  76422. bn2 = wolfSSL_DH_768_prime(bn);
  76423. ExpectNotNull(bn2);
  76424. ExpectTrue(bn == bn2);
  76425. wolfSSL_BN_free(bn);
  76426. bn = NULL;
  76427. #else
  76428. ExpectNull(bn);
  76429. #endif
  76430. bn = wolfSSL_DH_1024_prime(NULL);
  76431. #if WOLFSSL_MAX_BN_BITS >= 1024
  76432. ExpectNotNull(bn);
  76433. wolfSSL_BN_free(bn);
  76434. bn = NULL;
  76435. #else
  76436. ExpectNull(bn);
  76437. #endif
  76438. bn = wolfSSL_DH_2048_prime(NULL);
  76439. #if WOLFSSL_MAX_BN_BITS >= 2048
  76440. ExpectNotNull(bn);
  76441. wolfSSL_BN_free(bn);
  76442. bn = NULL;
  76443. #else
  76444. ExpectNull(bn);
  76445. #endif
  76446. bn = wolfSSL_DH_3072_prime(NULL);
  76447. #if WOLFSSL_MAX_BN_BITS >= 3072
  76448. ExpectNotNull(bn);
  76449. wolfSSL_BN_free(bn);
  76450. bn = NULL;
  76451. #else
  76452. ExpectNull(bn);
  76453. #endif
  76454. bn = wolfSSL_DH_4096_prime(NULL);
  76455. #if WOLFSSL_MAX_BN_BITS >= 4096
  76456. ExpectNotNull(bn);
  76457. wolfSSL_BN_free(bn);
  76458. bn = NULL;
  76459. #else
  76460. ExpectNull(bn);
  76461. #endif
  76462. bn = wolfSSL_DH_6144_prime(NULL);
  76463. #if WOLFSSL_MAX_BN_BITS >= 6144
  76464. ExpectNotNull(bn);
  76465. wolfSSL_BN_free(bn);
  76466. bn = NULL;
  76467. #else
  76468. ExpectNull(bn);
  76469. #endif
  76470. bn = wolfSSL_DH_8192_prime(NULL);
  76471. #if WOLFSSL_MAX_BN_BITS >= 8192
  76472. ExpectNotNull(bn);
  76473. wolfSSL_BN_free(bn);
  76474. bn = NULL;
  76475. #else
  76476. ExpectNull(bn);
  76477. #endif
  76478. #endif
  76479. return EXPECT_RESULT();
  76480. }
  76481. static int test_wolfSSL_DH_1536_prime(void)
  76482. {
  76483. EXPECT_DECLS;
  76484. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  76485. BIGNUM* bn = NULL;
  76486. unsigned char bits[200];
  76487. int sz = 192; /* known binary size */
  76488. const byte expected[] = {
  76489. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  76490. 0xC9,0x0F,0xDA,0xA2,0x21,0x68,0xC2,0x34,
  76491. 0xC4,0xC6,0x62,0x8B,0x80,0xDC,0x1C,0xD1,
  76492. 0x29,0x02,0x4E,0x08,0x8A,0x67,0xCC,0x74,
  76493. 0x02,0x0B,0xBE,0xA6,0x3B,0x13,0x9B,0x22,
  76494. 0x51,0x4A,0x08,0x79,0x8E,0x34,0x04,0xDD,
  76495. 0xEF,0x95,0x19,0xB3,0xCD,0x3A,0x43,0x1B,
  76496. 0x30,0x2B,0x0A,0x6D,0xF2,0x5F,0x14,0x37,
  76497. 0x4F,0xE1,0x35,0x6D,0x6D,0x51,0xC2,0x45,
  76498. 0xE4,0x85,0xB5,0x76,0x62,0x5E,0x7E,0xC6,
  76499. 0xF4,0x4C,0x42,0xE9,0xA6,0x37,0xED,0x6B,
  76500. 0x0B,0xFF,0x5C,0xB6,0xF4,0x06,0xB7,0xED,
  76501. 0xEE,0x38,0x6B,0xFB,0x5A,0x89,0x9F,0xA5,
  76502. 0xAE,0x9F,0x24,0x11,0x7C,0x4B,0x1F,0xE6,
  76503. 0x49,0x28,0x66,0x51,0xEC,0xE4,0x5B,0x3D,
  76504. 0xC2,0x00,0x7C,0xB8,0xA1,0x63,0xBF,0x05,
  76505. 0x98,0xDA,0x48,0x36,0x1C,0x55,0xD3,0x9A,
  76506. 0x69,0x16,0x3F,0xA8,0xFD,0x24,0xCF,0x5F,
  76507. 0x83,0x65,0x5D,0x23,0xDC,0xA3,0xAD,0x96,
  76508. 0x1C,0x62,0xF3,0x56,0x20,0x85,0x52,0xBB,
  76509. 0x9E,0xD5,0x29,0x07,0x70,0x96,0x96,0x6D,
  76510. 0x67,0x0C,0x35,0x4E,0x4A,0xBC,0x98,0x04,
  76511. 0xF1,0x74,0x6C,0x08,0xCA,0x23,0x73,0x27,
  76512. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  76513. };
  76514. ExpectNotNull(bn = get_rfc3526_prime_1536(NULL));
  76515. ExpectIntEQ(sz, BN_bn2bin((const BIGNUM*)bn, bits));
  76516. ExpectIntEQ(0, XMEMCMP(expected, bits, sz));
  76517. BN_free(bn);
  76518. #endif
  76519. return EXPECT_RESULT();
  76520. }
  76521. static int test_wolfSSL_DH_get_2048_256(void)
  76522. {
  76523. EXPECT_DECLS;
  76524. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  76525. WOLFSSL_DH* dh = NULL;
  76526. const WOLFSSL_BIGNUM* pBn;
  76527. const WOLFSSL_BIGNUM* gBn;
  76528. const WOLFSSL_BIGNUM* qBn;
  76529. const byte pExpected[] = {
  76530. 0x87, 0xA8, 0xE6, 0x1D, 0xB4, 0xB6, 0x66, 0x3C, 0xFF, 0xBB, 0xD1, 0x9C,
  76531. 0x65, 0x19, 0x59, 0x99, 0x8C, 0xEE, 0xF6, 0x08, 0x66, 0x0D, 0xD0, 0xF2,
  76532. 0x5D, 0x2C, 0xEE, 0xD4, 0x43, 0x5E, 0x3B, 0x00, 0xE0, 0x0D, 0xF8, 0xF1,
  76533. 0xD6, 0x19, 0x57, 0xD4, 0xFA, 0xF7, 0xDF, 0x45, 0x61, 0xB2, 0xAA, 0x30,
  76534. 0x16, 0xC3, 0xD9, 0x11, 0x34, 0x09, 0x6F, 0xAA, 0x3B, 0xF4, 0x29, 0x6D,
  76535. 0x83, 0x0E, 0x9A, 0x7C, 0x20, 0x9E, 0x0C, 0x64, 0x97, 0x51, 0x7A, 0xBD,
  76536. 0x5A, 0x8A, 0x9D, 0x30, 0x6B, 0xCF, 0x67, 0xED, 0x91, 0xF9, 0xE6, 0x72,
  76537. 0x5B, 0x47, 0x58, 0xC0, 0x22, 0xE0, 0xB1, 0xEF, 0x42, 0x75, 0xBF, 0x7B,
  76538. 0x6C, 0x5B, 0xFC, 0x11, 0xD4, 0x5F, 0x90, 0x88, 0xB9, 0x41, 0xF5, 0x4E,
  76539. 0xB1, 0xE5, 0x9B, 0xB8, 0xBC, 0x39, 0xA0, 0xBF, 0x12, 0x30, 0x7F, 0x5C,
  76540. 0x4F, 0xDB, 0x70, 0xC5, 0x81, 0xB2, 0x3F, 0x76, 0xB6, 0x3A, 0xCA, 0xE1,
  76541. 0xCA, 0xA6, 0xB7, 0x90, 0x2D, 0x52, 0x52, 0x67, 0x35, 0x48, 0x8A, 0x0E,
  76542. 0xF1, 0x3C, 0x6D, 0x9A, 0x51, 0xBF, 0xA4, 0xAB, 0x3A, 0xD8, 0x34, 0x77,
  76543. 0x96, 0x52, 0x4D, 0x8E, 0xF6, 0xA1, 0x67, 0xB5, 0xA4, 0x18, 0x25, 0xD9,
  76544. 0x67, 0xE1, 0x44, 0xE5, 0x14, 0x05, 0x64, 0x25, 0x1C, 0xCA, 0xCB, 0x83,
  76545. 0xE6, 0xB4, 0x86, 0xF6, 0xB3, 0xCA, 0x3F, 0x79, 0x71, 0x50, 0x60, 0x26,
  76546. 0xC0, 0xB8, 0x57, 0xF6, 0x89, 0x96, 0x28, 0x56, 0xDE, 0xD4, 0x01, 0x0A,
  76547. 0xBD, 0x0B, 0xE6, 0x21, 0xC3, 0xA3, 0x96, 0x0A, 0x54, 0xE7, 0x10, 0xC3,
  76548. 0x75, 0xF2, 0x63, 0x75, 0xD7, 0x01, 0x41, 0x03, 0xA4, 0xB5, 0x43, 0x30,
  76549. 0xC1, 0x98, 0xAF, 0x12, 0x61, 0x16, 0xD2, 0x27, 0x6E, 0x11, 0x71, 0x5F,
  76550. 0x69, 0x38, 0x77, 0xFA, 0xD7, 0xEF, 0x09, 0xCA, 0xDB, 0x09, 0x4A, 0xE9,
  76551. 0x1E, 0x1A, 0x15, 0x97
  76552. };
  76553. const byte gExpected[] = {
  76554. 0x3F, 0xB3, 0x2C, 0x9B, 0x73, 0x13, 0x4D, 0x0B, 0x2E, 0x77, 0x50, 0x66,
  76555. 0x60, 0xED, 0xBD, 0x48, 0x4C, 0xA7, 0xB1, 0x8F, 0x21, 0xEF, 0x20, 0x54,
  76556. 0x07, 0xF4, 0x79, 0x3A, 0x1A, 0x0B, 0xA1, 0x25, 0x10, 0xDB, 0xC1, 0x50,
  76557. 0x77, 0xBE, 0x46, 0x3F, 0xFF, 0x4F, 0xED, 0x4A, 0xAC, 0x0B, 0xB5, 0x55,
  76558. 0xBE, 0x3A, 0x6C, 0x1B, 0x0C, 0x6B, 0x47, 0xB1, 0xBC, 0x37, 0x73, 0xBF,
  76559. 0x7E, 0x8C, 0x6F, 0x62, 0x90, 0x12, 0x28, 0xF8, 0xC2, 0x8C, 0xBB, 0x18,
  76560. 0xA5, 0x5A, 0xE3, 0x13, 0x41, 0x00, 0x0A, 0x65, 0x01, 0x96, 0xF9, 0x31,
  76561. 0xC7, 0x7A, 0x57, 0xF2, 0xDD, 0xF4, 0x63, 0xE5, 0xE9, 0xEC, 0x14, 0x4B,
  76562. 0x77, 0x7D, 0xE6, 0x2A, 0xAA, 0xB8, 0xA8, 0x62, 0x8A, 0xC3, 0x76, 0xD2,
  76563. 0x82, 0xD6, 0xED, 0x38, 0x64, 0xE6, 0x79, 0x82, 0x42, 0x8E, 0xBC, 0x83,
  76564. 0x1D, 0x14, 0x34, 0x8F, 0x6F, 0x2F, 0x91, 0x93, 0xB5, 0x04, 0x5A, 0xF2,
  76565. 0x76, 0x71, 0x64, 0xE1, 0xDF, 0xC9, 0x67, 0xC1, 0xFB, 0x3F, 0x2E, 0x55,
  76566. 0xA4, 0xBD, 0x1B, 0xFF, 0xE8, 0x3B, 0x9C, 0x80, 0xD0, 0x52, 0xB9, 0x85,
  76567. 0xD1, 0x82, 0xEA, 0x0A, 0xDB, 0x2A, 0x3B, 0x73, 0x13, 0xD3, 0xFE, 0x14,
  76568. 0xC8, 0x48, 0x4B, 0x1E, 0x05, 0x25, 0x88, 0xB9, 0xB7, 0xD2, 0xBB, 0xD2,
  76569. 0xDF, 0x01, 0x61, 0x99, 0xEC, 0xD0, 0x6E, 0x15, 0x57, 0xCD, 0x09, 0x15,
  76570. 0xB3, 0x35, 0x3B, 0xBB, 0x64, 0xE0, 0xEC, 0x37, 0x7F, 0xD0, 0x28, 0x37,
  76571. 0x0D, 0xF9, 0x2B, 0x52, 0xC7, 0x89, 0x14, 0x28, 0xCD, 0xC6, 0x7E, 0xB6,
  76572. 0x18, 0x4B, 0x52, 0x3D, 0x1D, 0xB2, 0x46, 0xC3, 0x2F, 0x63, 0x07, 0x84,
  76573. 0x90, 0xF0, 0x0E, 0xF8, 0xD6, 0x47, 0xD1, 0x48, 0xD4, 0x79, 0x54, 0x51,
  76574. 0x5E, 0x23, 0x27, 0xCF, 0xEF, 0x98, 0xC5, 0x82, 0x66, 0x4B, 0x4C, 0x0F,
  76575. 0x6C, 0xC4, 0x16, 0x59
  76576. };
  76577. const byte qExpected[] = {
  76578. 0x8C, 0xF8, 0x36, 0x42, 0xA7, 0x09, 0xA0, 0x97, 0xB4, 0x47, 0x99, 0x76,
  76579. 0x40, 0x12, 0x9D, 0xA2, 0x99, 0xB1, 0xA4, 0x7D, 0x1E, 0xB3, 0x75, 0x0B,
  76580. 0xA3, 0x08, 0xB0, 0xFE, 0x64, 0xF5, 0xFB, 0xD3
  76581. };
  76582. int pSz = 0;
  76583. int qSz = 0;
  76584. int gSz = 0;
  76585. byte* pReturned = NULL;
  76586. byte* qReturned = NULL;
  76587. byte* gReturned = NULL;
  76588. ExpectNotNull((dh = wolfSSL_DH_get_2048_256()));
  76589. wolfSSL_DH_get0_pqg(dh, &pBn, &qBn, &gBn);
  76590. ExpectIntGT((pSz = wolfSSL_BN_num_bytes(pBn)), 0);
  76591. ExpectNotNull(pReturned = (byte*)XMALLOC(pSz, NULL,
  76592. DYNAMIC_TYPE_TMP_BUFFER));
  76593. ExpectIntGT((pSz = wolfSSL_BN_bn2bin(pBn, pReturned)), 0);
  76594. ExpectIntEQ(pSz, sizeof(pExpected));
  76595. ExpectIntEQ(XMEMCMP(pExpected, pReturned, pSz), 0);
  76596. ExpectIntGT((qSz = wolfSSL_BN_num_bytes(qBn)), 0);
  76597. ExpectNotNull(qReturned = (byte*)XMALLOC(qSz, NULL,
  76598. DYNAMIC_TYPE_TMP_BUFFER));
  76599. ExpectIntGT((qSz = wolfSSL_BN_bn2bin(qBn, qReturned)), 0);
  76600. ExpectIntEQ(qSz, sizeof(qExpected));
  76601. ExpectIntEQ(XMEMCMP(qExpected, qReturned, qSz), 0);
  76602. ExpectIntGT((gSz = wolfSSL_BN_num_bytes(gBn)), 0);
  76603. ExpectNotNull(gReturned = (byte*)XMALLOC(gSz, NULL,
  76604. DYNAMIC_TYPE_TMP_BUFFER));
  76605. ExpectIntGT((gSz = wolfSSL_BN_bn2bin(gBn, gReturned)), 0);
  76606. ExpectIntEQ(gSz, sizeof(gExpected));
  76607. ExpectIntEQ(XMEMCMP(gExpected, gReturned, gSz), 0);
  76608. wolfSSL_DH_free(dh);
  76609. XFREE(pReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76610. XFREE(gReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76611. XFREE(qReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76612. #endif
  76613. return EXPECT_RESULT();
  76614. }
  76615. static int test_wolfSSL_PEM_write_DHparams(void)
  76616. {
  76617. EXPECT_DECLS;
  76618. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO) && \
  76619. !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  76620. DH* dh = NULL;
  76621. BIO* bio = NULL;
  76622. XFILE fp = XBADFILE;
  76623. byte pem[2048];
  76624. int pemSz = 0;
  76625. const char expected[] =
  76626. "-----BEGIN DH PARAMETERS-----\n"
  76627. "MIIBCAKCAQEAsKEIBpwIE7pZBjy8MNX1AMFPRKfW70rGJScc6NKWUwpckd2iwpSE\n"
  76628. "v32yRJ+b0sGKxb5yXKfnkebUn3MHhVtmSMdw+rTuAsk9mkraPcFGPhlp0RdGB6NN\n"
  76629. "nyuWFzltMI0q85TTdc+gdebykh8acAWqBINXMPvadpM4UOgn/WPuPOW3yAmub1A1\n"
  76630. "joTOSgDpEn5aMdcz/CETdswWMNsM/MVipzW477ewrMA29tnJRkj5QJAAKxuqbOMa\n"
  76631. "wwsDnhvCRuRITiJzb8Nf1JrWMAdI1oyQq9T28eNI01hLprnNKb9oHwhLY4YvXGvW\n"
  76632. "tgZl96bcAGdru8OpQYP7x/rI4h5+rwA/kwIBAg==\n"
  76633. "-----END DH PARAMETERS-----\n";
  76634. const char badPem[] =
  76635. "-----BEGIN DH PARAMETERS-----\n"
  76636. "-----END DH PARAMETERS-----\n";
  76637. const char emptySeqPem[] =
  76638. "-----BEGIN DH PARAMETERS-----\n"
  76639. "MAA=\n"
  76640. "-----END DH PARAMETERS-----\n";
  76641. ExpectTrue((fp = XFOPEN(dhParamFile, "rb")) != XBADFILE);
  76642. ExpectIntGT((pemSz = (int)XFREAD(pem, 1, sizeof(pem), fp)), 0);
  76643. if (fp != XBADFILE) {
  76644. XFCLOSE(fp);
  76645. fp = XBADFILE;
  76646. }
  76647. ExpectNull(PEM_read_bio_DHparams(NULL, NULL, NULL, NULL));
  76648. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  76649. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  76650. ExpectIntEQ(BIO_write(bio, badPem, (int)sizeof(badPem)),
  76651. (int)sizeof(badPem));
  76652. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  76653. BIO_free(bio);
  76654. bio = NULL;
  76655. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  76656. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  76657. ExpectIntEQ(BIO_write(bio, emptySeqPem, (int)sizeof(emptySeqPem)),
  76658. (int)sizeof(emptySeqPem));
  76659. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  76660. BIO_free(bio);
  76661. bio = NULL;
  76662. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  76663. ExpectIntEQ(BIO_write(bio, pem, pemSz), pemSz);
  76664. ExpectNotNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  76665. BIO_free(bio);
  76666. bio = NULL;
  76667. ExpectNotNull(fp = XFOPEN("./test-write-dhparams.pem", "wb"));
  76668. ExpectIntEQ(PEM_write_DHparams(fp, dh), WOLFSSL_SUCCESS);
  76669. ExpectIntEQ(PEM_write_DHparams(fp, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  76670. DH_free(dh);
  76671. dh = NULL;
  76672. dh = wolfSSL_DH_new();
  76673. ExpectIntEQ(PEM_write_DHparams(fp, dh), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  76674. if (fp != XBADFILE) {
  76675. XFCLOSE(fp);
  76676. fp = XBADFILE;
  76677. }
  76678. wolfSSL_DH_free(dh);
  76679. dh = NULL;
  76680. /* check results */
  76681. XMEMSET(pem, 0, sizeof(pem));
  76682. ExpectTrue((fp = XFOPEN("./test-write-dhparams.pem", "rb")) != XBADFILE);
  76683. ExpectIntGT((pemSz = (int)XFREAD(pem, 1, sizeof(pem), fp)), 0);
  76684. ExpectIntEQ(XMEMCMP(pem, expected, pemSz), 0);
  76685. if (fp != XBADFILE)
  76686. XFCLOSE(fp);
  76687. #endif
  76688. return EXPECT_RESULT();
  76689. }
  76690. static int test_wolfSSL_d2i_DHparams(void)
  76691. {
  76692. EXPECT_DECLS;
  76693. #ifdef OPENSSL_ALL
  76694. #if !defined(NO_DH) && (defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072))
  76695. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  76696. XFILE f = XBADFILE;
  76697. unsigned char buf[4096];
  76698. const unsigned char* pt = buf;
  76699. #ifdef HAVE_FFDHE_2048
  76700. const char* params1 = "./certs/dh2048.der";
  76701. #endif
  76702. #ifdef HAVE_FFDHE_3072
  76703. const char* params2 = "./certs/dh3072.der";
  76704. #endif
  76705. long len = 0;
  76706. WOLFSSL_DH* dh = NULL;
  76707. XMEMSET(buf, 0, sizeof(buf));
  76708. /* Test 2048 bit parameters */
  76709. #ifdef HAVE_FFDHE_2048
  76710. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  76711. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  76712. if (f != XBADFILE) {
  76713. XFCLOSE(f);
  76714. f = XBADFILE;
  76715. }
  76716. /* Valid case */
  76717. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  76718. ExpectNotNull(dh->p);
  76719. ExpectNotNull(dh->g);
  76720. ExpectTrue(pt == buf);
  76721. ExpectIntEQ(DH_set_length(NULL, BN_num_bits(dh->p)), 0);
  76722. ExpectIntEQ(DH_set_length(dh, BN_num_bits(dh->p)), 1);
  76723. ExpectIntEQ(DH_generate_key(dh), WOLFSSL_SUCCESS);
  76724. /* Invalid cases */
  76725. ExpectNull(wolfSSL_d2i_DHparams(NULL, NULL, len));
  76726. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, -1));
  76727. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, 10));
  76728. DH_free(dh);
  76729. dh = NULL;
  76730. *buf = 0;
  76731. pt = buf;
  76732. #endif /* HAVE_FFDHE_2048 */
  76733. /* Test 3072 bit parameters */
  76734. #ifdef HAVE_FFDHE_3072
  76735. ExpectTrue((f = XFOPEN(params2, "rb")) != XBADFILE);
  76736. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  76737. if (f != XBADFILE) {
  76738. XFCLOSE(f);
  76739. f = XBADFILE;
  76740. }
  76741. /* Valid case */
  76742. ExpectNotNull(dh = wolfSSL_d2i_DHparams(&dh, &pt, len));
  76743. ExpectNotNull(dh->p);
  76744. ExpectNotNull(dh->g);
  76745. ExpectTrue(pt != buf);
  76746. ExpectIntEQ(DH_generate_key(dh), 1);
  76747. /* Invalid cases */
  76748. ExpectNull(wolfSSL_d2i_DHparams(NULL, NULL, len));
  76749. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, -1));
  76750. DH_free(dh);
  76751. dh = NULL;
  76752. #endif /* HAVE_FFDHE_3072 */
  76753. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  76754. #endif /* !NO_DH */
  76755. #endif
  76756. return EXPECT_RESULT();
  76757. }
  76758. static int test_wolfSSL_DH_LoadDer(void)
  76759. {
  76760. EXPECT_DECLS;
  76761. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)) && \
  76762. defined(OPENSSL_EXTRA)
  76763. static const byte dh2048[] = {
  76764. 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01,
  76765. 0x00, 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13,
  76766. 0xba, 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5,
  76767. 0x00, 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a,
  76768. 0xc6, 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53,
  76769. 0x0a, 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84,
  76770. 0xbf, 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1,
  76771. 0x8a, 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91,
  76772. 0xe6, 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66,
  76773. 0x48, 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9,
  76774. 0x3d, 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e,
  76775. 0x19, 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d,
  76776. 0x9f, 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d,
  76777. 0x2a, 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75,
  76778. 0xe6, 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa,
  76779. 0x04, 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93,
  76780. 0x38, 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c,
  76781. 0xe5, 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35,
  76782. 0x8e, 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e,
  76783. 0x5a, 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76,
  76784. 0xcc, 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62,
  76785. 0xa7, 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0,
  76786. 0x36, 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40,
  76787. 0x90, 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a,
  76788. 0xc3, 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4,
  76789. 0x48, 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4,
  76790. 0x9a, 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90,
  76791. 0xab, 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58,
  76792. 0x4b, 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f,
  76793. 0x08, 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6,
  76794. 0xb6, 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67,
  76795. 0x6b, 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7,
  76796. 0xfa, 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f,
  76797. 0x93, 0x02, 0x01, 0x02
  76798. };
  76799. WOLFSSL_DH* dh = NULL;
  76800. ExpectNotNull(dh = wolfSSL_DH_new());
  76801. ExpectIntEQ(wolfSSL_DH_LoadDer(NULL, NULL, 0), -1);
  76802. ExpectIntEQ(wolfSSL_DH_LoadDer(dh, NULL, 0), -1);
  76803. ExpectIntEQ(wolfSSL_DH_LoadDer(NULL, dh2048, sizeof(dh2048)), -1);
  76804. ExpectIntEQ(wolfSSL_DH_LoadDer(dh, dh2048, sizeof(dh2048)), 1);
  76805. wolfSSL_DH_free(dh);
  76806. #endif
  76807. return EXPECT_RESULT();
  76808. }
  76809. static int test_wolfSSL_i2d_DHparams(void)
  76810. {
  76811. EXPECT_DECLS;
  76812. #ifdef OPENSSL_ALL
  76813. #if !defined(NO_DH) && (defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072))
  76814. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  76815. XFILE f = XBADFILE;
  76816. unsigned char buf[4096];
  76817. const unsigned char* pt;
  76818. unsigned char* pt2;
  76819. #ifdef HAVE_FFDHE_2048
  76820. const char* params1 = "./certs/dh2048.der";
  76821. #endif
  76822. #ifdef HAVE_FFDHE_3072
  76823. const char* params2 = "./certs/dh3072.der";
  76824. #endif
  76825. long len = 0;
  76826. WOLFSSL_DH* dh = NULL;
  76827. /* Test 2048 bit parameters */
  76828. #ifdef HAVE_FFDHE_2048
  76829. pt = buf;
  76830. pt2 = buf;
  76831. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  76832. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  76833. if (f != XBADFILE) {
  76834. XFCLOSE(f);
  76835. f = XBADFILE;
  76836. }
  76837. /* Valid case */
  76838. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  76839. ExpectTrue(pt == buf);
  76840. ExpectIntEQ(DH_generate_key(dh), 1);
  76841. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 268);
  76842. /* Invalid case */
  76843. ExpectIntEQ(wolfSSL_i2d_DHparams(NULL, &pt2), 0);
  76844. /* Return length only */
  76845. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, NULL), 268);
  76846. DH_free(dh);
  76847. dh = NULL;
  76848. *buf = 0;
  76849. #endif
  76850. /* Test 3072 bit parameters */
  76851. #ifdef HAVE_FFDHE_3072
  76852. pt = buf;
  76853. pt2 = buf;
  76854. ExpectTrue((f = XFOPEN(params2, "rb")) != XBADFILE);
  76855. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  76856. if (f != XBADFILE) {
  76857. XFCLOSE(f);
  76858. f = XBADFILE;
  76859. }
  76860. /* Valid case */
  76861. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  76862. ExpectTrue(pt == buf);
  76863. ExpectIntEQ(DH_generate_key(dh), 1);
  76864. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 396);
  76865. /* Invalid case */
  76866. ExpectIntEQ(wolfSSL_i2d_DHparams(NULL, &pt2), 0);
  76867. /* Return length only */
  76868. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, NULL), 396);
  76869. DH_free(dh);
  76870. dh = NULL;
  76871. #endif
  76872. dh = DH_new();
  76873. ExpectNotNull(dh);
  76874. pt2 = buf;
  76875. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 0);
  76876. DH_free(dh);
  76877. dh = NULL;
  76878. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  76879. #endif /* !NO_DH && (HAVE_FFDHE_2048 || HAVE_FFDHE_3072) */
  76880. #endif
  76881. return EXPECT_RESULT();
  76882. }
  76883. #if defined(HAVE_ECC) && !defined(OPENSSL_NO_PK)
  76884. /*----------------------------------------------------------------------------*
  76885. | EC
  76886. *----------------------------------------------------------------------------*/
  76887. static int test_wolfSSL_EC_GROUP(void)
  76888. {
  76889. EXPECT_DECLS;
  76890. #ifdef OPENSSL_EXTRA
  76891. EC_GROUP *group = NULL;
  76892. EC_GROUP *group2 = NULL;
  76893. EC_GROUP *group3 = NULL;
  76894. #ifndef HAVE_ECC_BRAINPOOL
  76895. EC_GROUP *group4 = NULL;
  76896. #endif
  76897. WOLFSSL_BIGNUM* order = NULL;
  76898. int group_bits;
  76899. int i;
  76900. static const int knownEccNids[] = {
  76901. NID_X9_62_prime192v1,
  76902. NID_X9_62_prime192v2,
  76903. NID_X9_62_prime192v3,
  76904. NID_X9_62_prime239v1,
  76905. NID_X9_62_prime239v2,
  76906. NID_X9_62_prime239v3,
  76907. NID_X9_62_prime256v1,
  76908. NID_secp112r1,
  76909. NID_secp112r2,
  76910. NID_secp128r1,
  76911. NID_secp128r2,
  76912. NID_secp160r1,
  76913. NID_secp160r2,
  76914. NID_secp224r1,
  76915. NID_secp384r1,
  76916. NID_secp521r1,
  76917. NID_secp160k1,
  76918. NID_secp192k1,
  76919. NID_secp224k1,
  76920. NID_secp256k1,
  76921. NID_brainpoolP160r1,
  76922. NID_brainpoolP192r1,
  76923. NID_brainpoolP224r1,
  76924. NID_brainpoolP256r1,
  76925. NID_brainpoolP320r1,
  76926. NID_brainpoolP384r1,
  76927. NID_brainpoolP512r1,
  76928. };
  76929. int knowEccNidsLen = (int)(sizeof(knownEccNids) / sizeof(*knownEccNids));
  76930. static const int knownEccEnums[] = {
  76931. ECC_SECP192R1,
  76932. ECC_PRIME192V2,
  76933. ECC_PRIME192V3,
  76934. ECC_PRIME239V1,
  76935. ECC_PRIME239V2,
  76936. ECC_PRIME239V3,
  76937. ECC_SECP256R1,
  76938. ECC_SECP112R1,
  76939. ECC_SECP112R2,
  76940. ECC_SECP128R1,
  76941. ECC_SECP128R2,
  76942. ECC_SECP160R1,
  76943. ECC_SECP160R2,
  76944. ECC_SECP224R1,
  76945. ECC_SECP384R1,
  76946. ECC_SECP521R1,
  76947. ECC_SECP160K1,
  76948. ECC_SECP192K1,
  76949. ECC_SECP224K1,
  76950. ECC_SECP256K1,
  76951. ECC_BRAINPOOLP160R1,
  76952. ECC_BRAINPOOLP192R1,
  76953. ECC_BRAINPOOLP224R1,
  76954. ECC_BRAINPOOLP256R1,
  76955. ECC_BRAINPOOLP320R1,
  76956. ECC_BRAINPOOLP384R1,
  76957. ECC_BRAINPOOLP512R1,
  76958. };
  76959. int knowEccEnumsLen = (int)(sizeof(knownEccEnums) / sizeof(*knownEccEnums));
  76960. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  76961. ExpectNotNull(group2 = EC_GROUP_dup(group));
  76962. ExpectNotNull(group3 = wolfSSL_EC_GROUP_new_by_curve_name(NID_secp384r1));
  76963. #ifndef HAVE_ECC_BRAINPOOL
  76964. ExpectNotNull(group4 = wolfSSL_EC_GROUP_new_by_curve_name(
  76965. NID_brainpoolP256r1));
  76966. #endif
  76967. ExpectNull(EC_GROUP_dup(NULL));
  76968. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(NULL), 0);
  76969. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(group), NID_X9_62_prime256v1);
  76970. ExpectIntEQ((group_bits = EC_GROUP_order_bits(NULL)), 0);
  76971. ExpectIntEQ((group_bits = EC_GROUP_order_bits(group)), 256);
  76972. #ifndef HAVE_ECC_BRAINPOOL
  76973. ExpectIntEQ((group_bits = EC_GROUP_order_bits(group4)), 0);
  76974. #endif
  76975. ExpectIntEQ(wolfSSL_EC_GROUP_get_degree(NULL), 0);
  76976. ExpectIntEQ(wolfSSL_EC_GROUP_get_degree(group), 256);
  76977. ExpectNotNull(order = BN_new());
  76978. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(NULL, NULL, NULL), 0);
  76979. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(group, NULL, NULL), 0);
  76980. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(NULL, order, NULL), 0);
  76981. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(group, order, NULL), 1);
  76982. wolfSSL_BN_free(order);
  76983. ExpectNotNull(EC_GROUP_method_of(group));
  76984. ExpectIntEQ(EC_METHOD_get_field_type(NULL), 0);
  76985. ExpectIntEQ(EC_METHOD_get_field_type(EC_GROUP_method_of(group)),
  76986. NID_X9_62_prime_field);
  76987. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(NULL, NULL, NULL), -1);
  76988. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(group, NULL, NULL), -1);
  76989. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(NULL, group, NULL), -1);
  76990. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(group, group3, NULL), 1);
  76991. #ifndef NO_WOLFSSL_STUB
  76992. wolfSSL_EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
  76993. #endif
  76994. #ifndef HAVE_ECC_BRAINPOOL
  76995. EC_GROUP_free(group4);
  76996. #endif
  76997. EC_GROUP_free(group3);
  76998. EC_GROUP_free(group2);
  76999. EC_GROUP_free(group);
  77000. for (i = 0; i < knowEccNidsLen; i++) {
  77001. group = NULL;
  77002. ExpectNotNull(group = EC_GROUP_new_by_curve_name(knownEccNids[i]));
  77003. ExpectIntGT(wolfSSL_EC_GROUP_get_degree(group), 0);
  77004. EC_GROUP_free(group);
  77005. }
  77006. for (i = 0; i < knowEccEnumsLen; i++) {
  77007. group = NULL;
  77008. ExpectNotNull(group = EC_GROUP_new_by_curve_name(knownEccEnums[i]));
  77009. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(group), knownEccNids[i]);
  77010. EC_GROUP_free(group);
  77011. }
  77012. #endif
  77013. return EXPECT_RESULT();
  77014. }
  77015. static int test_wolfSSL_PEM_read_bio_ECPKParameters(void)
  77016. {
  77017. EXPECT_DECLS;
  77018. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  77019. EC_GROUP *group = NULL;
  77020. BIO* bio = NULL;
  77021. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  77022. ECC_MIN_KEY_SZ <= 384 && !defined(NO_ECC_SECP)
  77023. EC_GROUP *ret = NULL;
  77024. static char ec_nc_p384[] = "-----BEGIN EC PARAMETERS-----\n"
  77025. "BgUrgQQAIg==\n"
  77026. "-----END EC PARAMETERS-----";
  77027. #endif
  77028. static char ec_nc_bad_1[] = "-----BEGIN EC PARAMETERS-----\n"
  77029. "MAA=\n"
  77030. "-----END EC PARAMETERS-----";
  77031. static char ec_nc_bad_2[] = "-----BEGIN EC PARAMETERS-----\n"
  77032. "BgA=\n"
  77033. "-----END EC PARAMETERS-----";
  77034. static char ec_nc_bad_3[] = "-----BEGIN EC PARAMETERS-----\n"
  77035. "BgE=\n"
  77036. "-----END EC PARAMETERS-----";
  77037. static char ec_nc_bad_4[] = "-----BEGIN EC PARAMETERS-----\n"
  77038. "BgE*\n"
  77039. "-----END EC PARAMETERS-----";
  77040. /* Test that first parameter, bio, being NULL fails. */
  77041. ExpectNull(PEM_read_bio_ECPKParameters(NULL, NULL, NULL, NULL));
  77042. /* Test that reading named parameters works. */
  77043. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  77044. ExpectIntEQ(BIO_read_filename(bio, eccKeyFile), WOLFSSL_SUCCESS);
  77045. ExpectNotNull(group = PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  77046. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_X9_62_prime256v1);
  77047. BIO_free(bio);
  77048. bio = NULL;
  77049. EC_GROUP_free(group);
  77050. group = NULL;
  77051. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  77052. ECC_MIN_KEY_SZ <= 384 && !defined(NO_ECC_SECP)
  77053. /* Test that reusing group works. */
  77054. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_p384,
  77055. sizeof(ec_nc_p384)));
  77056. ExpectNotNull(group = PEM_read_bio_ECPKParameters(bio, &group, NULL, NULL));
  77057. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_secp384r1);
  77058. BIO_free(bio);
  77059. bio = NULL;
  77060. EC_GROUP_free(group);
  77061. group = NULL;
  77062. /* Test that returning through group works. */
  77063. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_p384,
  77064. sizeof(ec_nc_p384)));
  77065. ExpectNotNull(ret = PEM_read_bio_ECPKParameters(bio, &group, NULL, NULL));
  77066. ExpectIntEQ(group == ret, 1);
  77067. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_secp384r1);
  77068. BIO_free(bio);
  77069. bio = NULL;
  77070. EC_GROUP_free(group);
  77071. group = NULL;
  77072. #endif
  77073. /* Test 0x30, 0x00 (not and object id) fails. */
  77074. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_1,
  77075. sizeof(ec_nc_bad_1)));
  77076. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  77077. BIO_free(bio);
  77078. bio = NULL;
  77079. /* Test 0x06, 0x00 (empty object id) fails. */
  77080. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_2,
  77081. sizeof(ec_nc_bad_2)));
  77082. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  77083. BIO_free(bio);
  77084. bio = NULL;
  77085. /* Test 0x06, 0x01 (badly formed object id) fails. */
  77086. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_3,
  77087. sizeof(ec_nc_bad_3)));
  77088. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  77089. BIO_free(bio);
  77090. bio = NULL;
  77091. /* Test invalid PEM encoding - invalid character. */
  77092. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_4,
  77093. sizeof(ec_nc_bad_4)));
  77094. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  77095. BIO_free(bio);
  77096. #endif
  77097. return EXPECT_RESULT();
  77098. }
  77099. static int test_wolfSSL_EC_POINT(void)
  77100. {
  77101. EXPECT_DECLS;
  77102. #if !defined(WOLFSSL_SP_MATH) && \
  77103. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  77104. #ifdef OPENSSL_EXTRA
  77105. BN_CTX* ctx = NULL;
  77106. EC_GROUP* group = NULL;
  77107. #ifndef HAVE_ECC_BRAINPOOL
  77108. EC_GROUP* group2 = NULL;
  77109. #endif
  77110. EC_POINT* Gxy = NULL;
  77111. EC_POINT* new_point = NULL;
  77112. EC_POINT* set_point = NULL;
  77113. EC_POINT* get_point = NULL;
  77114. EC_POINT* infinity = NULL;
  77115. BIGNUM* k = NULL;
  77116. BIGNUM* Gx = NULL;
  77117. BIGNUM* Gy = NULL;
  77118. BIGNUM* Gz = NULL;
  77119. BIGNUM* X = NULL;
  77120. BIGNUM* Y = NULL;
  77121. BIGNUM* set_point_bn = NULL;
  77122. char* hexStr = NULL;
  77123. const char* kTest = "F4F8338AFCC562C5C3F3E1E46A7EFECD"
  77124. "17AF381913FF7A96314EA47055EA0FD0";
  77125. /* NISTP256R1 Gx/Gy */
  77126. const char* kGx = "6B17D1F2E12C4247F8BCE6E563A440F2"
  77127. "77037D812DEB33A0F4A13945D898C296";
  77128. const char* kGy = "4FE342E2FE1A7F9B8EE7EB4A7C0F9E16"
  77129. "2BCE33576B315ECECBB6406837BF51F5";
  77130. const char* uncompG
  77131. = "046B17D1F2E12C4247F8BCE6E563A440F2"
  77132. "77037D812DEB33A0F4A13945D898C296"
  77133. "4FE342E2FE1A7F9B8EE7EB4A7C0F9E16"
  77134. "2BCE33576B315ECECBB6406837BF51F5";
  77135. const char* compG
  77136. = "036B17D1F2E12C4247F8BCE6E563A440F2"
  77137. "77037D812DEB33A0F4A13945D898C296";
  77138. #ifndef HAVE_SELFTEST
  77139. EC_POINT *tmp = NULL;
  77140. size_t bin_len;
  77141. unsigned int blen = 0;
  77142. unsigned char* buf = NULL;
  77143. unsigned char bufInf[1] = { 0x00 };
  77144. const unsigned char binUncompG[] = {
  77145. 0x04, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  77146. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  77147. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  77148. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  77149. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  77150. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  77151. };
  77152. const unsigned char binUncompGBad[] = {
  77153. 0x09, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  77154. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  77155. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  77156. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  77157. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  77158. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  77159. };
  77160. #ifdef HAVE_COMP_KEY
  77161. const unsigned char binCompG[] = {
  77162. 0x03, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  77163. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  77164. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  77165. };
  77166. #endif
  77167. #endif
  77168. ExpectNotNull(ctx = BN_CTX_new());
  77169. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  77170. #ifndef HAVE_ECC_BRAINPOOL
  77171. /* Used to make groups curve_idx == -1. */
  77172. ExpectNotNull(group2 = EC_GROUP_new_by_curve_name(NID_brainpoolP256r1));
  77173. #endif
  77174. ExpectNull(EC_POINT_new(NULL));
  77175. ExpectNotNull(Gxy = EC_POINT_new(group));
  77176. ExpectNotNull(new_point = EC_POINT_new(group));
  77177. ExpectNotNull(set_point = EC_POINT_new(group));
  77178. ExpectNotNull(X = BN_new());
  77179. ExpectNotNull(Y = BN_new());
  77180. ExpectNotNull(set_point_bn = BN_new());
  77181. ExpectNotNull(infinity = EC_POINT_new(group));
  77182. /* load test values */
  77183. ExpectIntEQ(BN_hex2bn(&k, kTest), WOLFSSL_SUCCESS);
  77184. ExpectIntEQ(BN_hex2bn(&Gx, kGx), WOLFSSL_SUCCESS);
  77185. ExpectIntEQ(BN_hex2bn(&Gy, kGy), WOLFSSL_SUCCESS);
  77186. ExpectIntEQ(BN_hex2bn(&Gz, "1"), WOLFSSL_SUCCESS);
  77187. /* populate coordinates for input point */
  77188. if (Gxy != NULL) {
  77189. Gxy->X = Gx;
  77190. Gxy->Y = Gy;
  77191. Gxy->Z = Gz;
  77192. }
  77193. /* Test handling of NULL point. */
  77194. EC_POINT_clear_free(NULL);
  77195. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  77196. NULL, NULL, ctx), 0);
  77197. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, NULL,
  77198. NULL, NULL, ctx), 0);
  77199. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, Gxy,
  77200. NULL, NULL, ctx), 0);
  77201. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  77202. X, NULL, ctx), 0);
  77203. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  77204. NULL, Y, ctx), 0);
  77205. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, Gxy,
  77206. X, Y, ctx), 0);
  77207. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, NULL,
  77208. X, Y, ctx), 0);
  77209. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, Gxy,
  77210. NULL, Y, ctx), 0);
  77211. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, Gxy,
  77212. X, NULL, ctx), 0);
  77213. /* Getting point at infinity returns an error. */
  77214. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, infinity,
  77215. X, Y, ctx), 0);
  77216. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  77217. !defined(HAVE_SELFTEST) && !defined(WOLFSSL_SP_MATH) && \
  77218. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  77219. ExpectIntEQ(EC_POINT_add(NULL, NULL, NULL, NULL, ctx), 0);
  77220. ExpectIntEQ(EC_POINT_add(group, NULL, NULL, NULL, ctx), 0);
  77221. ExpectIntEQ(EC_POINT_add(NULL, new_point, NULL, NULL, ctx), 0);
  77222. ExpectIntEQ(EC_POINT_add(NULL, NULL, new_point, NULL, ctx), 0);
  77223. ExpectIntEQ(EC_POINT_add(NULL, NULL, NULL, Gxy, ctx), 0);
  77224. ExpectIntEQ(EC_POINT_add(NULL, new_point, new_point, Gxy, ctx), 0);
  77225. ExpectIntEQ(EC_POINT_add(group, NULL, new_point, Gxy, ctx), 0);
  77226. ExpectIntEQ(EC_POINT_add(group, new_point, NULL, Gxy, ctx), 0);
  77227. ExpectIntEQ(EC_POINT_add(group, new_point, new_point, NULL, ctx), 0);
  77228. ExpectIntEQ(EC_POINT_mul(NULL, NULL, Gx, Gxy, k, ctx), 0);
  77229. ExpectIntEQ(EC_POINT_mul(NULL, new_point, Gx, Gxy, k, ctx), 0);
  77230. ExpectIntEQ(EC_POINT_mul(group, NULL, Gx, Gxy, k, ctx), 0);
  77231. ExpectIntEQ(EC_POINT_add(group, new_point, new_point, Gxy, ctx), 1);
  77232. /* perform point multiplication */
  77233. ExpectIntEQ(EC_POINT_mul(group, new_point, Gx, Gxy, k, ctx), 1);
  77234. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  77235. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  77236. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  77237. ExpectIntEQ(EC_POINT_mul(group, new_point, NULL, Gxy, k, ctx), 1);
  77238. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  77239. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  77240. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  77241. ExpectIntEQ(EC_POINT_mul(group, new_point, Gx, NULL, NULL, ctx), 1);
  77242. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  77243. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  77244. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  77245. ExpectIntEQ(EC_POINT_mul(group, new_point, NULL, NULL, NULL, ctx), 1);
  77246. ExpectIntEQ(BN_is_zero(new_point->X), 1);
  77247. ExpectIntEQ(BN_is_zero(new_point->Y), 1);
  77248. ExpectIntEQ(BN_is_zero(new_point->Z), 1);
  77249. /* Set point to something. */
  77250. ExpectIntEQ(EC_POINT_add(group, new_point, Gxy, Gxy, ctx), 1);
  77251. #else
  77252. ExpectIntEQ(EC_POINT_set_affine_coordinates_GFp(group, new_point, Gx, Gy,
  77253. ctx), 1);
  77254. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  77255. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  77256. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  77257. #endif
  77258. /* check if point X coordinate is zero */
  77259. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  77260. #if defined(USE_ECC_B_PARAM) && !defined(HAVE_SELFTEST) && \
  77261. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  77262. ExpectIntEQ(EC_POINT_is_on_curve(group, new_point, ctx), 1);
  77263. #endif
  77264. /* extract the coordinates from point */
  77265. ExpectIntEQ(EC_POINT_get_affine_coordinates_GFp(group, new_point, X, Y,
  77266. ctx), WOLFSSL_SUCCESS);
  77267. /* check if point X coordinate is zero */
  77268. ExpectIntEQ(BN_is_zero(X), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  77269. /* set the same X and Y points in another object */
  77270. ExpectIntEQ(EC_POINT_set_affine_coordinates_GFp(group, set_point, X, Y,
  77271. ctx), WOLFSSL_SUCCESS);
  77272. /* compare points as they should be the same */
  77273. ExpectIntEQ(EC_POINT_cmp(NULL, NULL, NULL, ctx), -1);
  77274. ExpectIntEQ(EC_POINT_cmp(group, NULL, NULL, ctx), -1);
  77275. ExpectIntEQ(EC_POINT_cmp(NULL, new_point, NULL, ctx), -1);
  77276. ExpectIntEQ(EC_POINT_cmp(NULL, NULL, set_point, ctx), -1);
  77277. ExpectIntEQ(EC_POINT_cmp(NULL, new_point, set_point, ctx), -1);
  77278. ExpectIntEQ(EC_POINT_cmp(group, NULL, set_point, ctx), -1);
  77279. ExpectIntEQ(EC_POINT_cmp(group, new_point, NULL, ctx), -1);
  77280. ExpectIntEQ(EC_POINT_cmp(group, new_point, set_point, ctx), 0);
  77281. /* Test copying */
  77282. ExpectIntEQ(EC_POINT_copy(NULL, NULL), 0);
  77283. ExpectIntEQ(EC_POINT_copy(NULL, set_point), 0);
  77284. ExpectIntEQ(EC_POINT_copy(new_point, NULL), 0);
  77285. ExpectIntEQ(EC_POINT_copy(new_point, set_point), 1);
  77286. /* Test inverting */
  77287. ExpectIntEQ(EC_POINT_invert(NULL, NULL, ctx), 0);
  77288. ExpectIntEQ(EC_POINT_invert(NULL, new_point, ctx), 0);
  77289. ExpectIntEQ(EC_POINT_invert(group, NULL, ctx), 0);
  77290. ExpectIntEQ(EC_POINT_invert(group, new_point, ctx), 1);
  77291. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  77292. !defined(HAVE_SELFTEST) && !defined(WOLFSSL_SP_MATH) && \
  77293. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  77294. {
  77295. EC_POINT* orig_point = NULL;
  77296. ExpectNotNull(orig_point = EC_POINT_new(group));
  77297. ExpectIntEQ(EC_POINT_add(group, orig_point, set_point, set_point, NULL),
  77298. 1);
  77299. /* new_point should be set_point inverted so adding it will revert
  77300. * the point back to set_point */
  77301. ExpectIntEQ(EC_POINT_add(group, orig_point, orig_point, new_point,
  77302. NULL), 1);
  77303. ExpectIntEQ(EC_POINT_cmp(group, orig_point, set_point, NULL), 0);
  77304. EC_POINT_free(orig_point);
  77305. }
  77306. #endif
  77307. /* Test getting affine converts from projective. */
  77308. ExpectIntEQ(EC_POINT_copy(set_point, new_point), 1);
  77309. /* Force non-affine coordinates */
  77310. ExpectIntEQ(BN_add(new_point->Z, (WOLFSSL_BIGNUM*)BN_value_one(),
  77311. (WOLFSSL_BIGNUM*)BN_value_one()), 1);
  77312. if (new_point != NULL) {
  77313. new_point->inSet = 0;
  77314. }
  77315. /* extract the coordinates from point */
  77316. ExpectIntEQ(EC_POINT_get_affine_coordinates_GFp(group, new_point, X, Y,
  77317. ctx), WOLFSSL_SUCCESS);
  77318. /* check if point ordinates have changed. */
  77319. ExpectIntNE(BN_cmp(X, set_point->X), 0);
  77320. ExpectIntNE(BN_cmp(Y, set_point->Y), 0);
  77321. /* Test check for infinity */
  77322. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  77323. ExpectIntEQ(EC_POINT_is_at_infinity(NULL, NULL), 0);
  77324. ExpectIntEQ(EC_POINT_is_at_infinity(NULL, infinity), 0);
  77325. ExpectIntEQ(EC_POINT_is_at_infinity(group, NULL), 0);
  77326. ExpectIntEQ(EC_POINT_is_at_infinity(group, infinity), 1);
  77327. ExpectIntEQ(EC_POINT_is_at_infinity(group, Gxy), 0);
  77328. #else
  77329. ExpectIntEQ(EC_POINT_is_at_infinity(group, infinity), 0);
  77330. #endif
  77331. ExpectPtrEq(EC_POINT_point2bn(group, set_point,
  77332. POINT_CONVERSION_UNCOMPRESSED, set_point_bn, ctx), set_point_bn);
  77333. /* check bn2hex */
  77334. hexStr = BN_bn2hex(k);
  77335. ExpectStrEQ(hexStr, kTest);
  77336. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  77337. defined(XFPRINTF)
  77338. BN_print_fp(stderr, k);
  77339. fprintf(stderr, "\n");
  77340. #endif
  77341. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  77342. hexStr = BN_bn2hex(Gx);
  77343. ExpectStrEQ(hexStr, kGx);
  77344. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  77345. defined(XFPRINTF)
  77346. BN_print_fp(stderr, Gx);
  77347. fprintf(stderr, "\n");
  77348. #endif
  77349. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  77350. hexStr = BN_bn2hex(Gy);
  77351. ExpectStrEQ(hexStr, kGy);
  77352. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  77353. defined(XFPRINTF)
  77354. BN_print_fp(stderr, Gy);
  77355. fprintf(stderr, "\n");
  77356. #endif
  77357. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  77358. /* Test point to hex */
  77359. ExpectNull(EC_POINT_point2hex(NULL, NULL, POINT_CONVERSION_UNCOMPRESSED,
  77360. ctx));
  77361. ExpectNull(EC_POINT_point2hex(NULL, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  77362. ctx));
  77363. ExpectNull(EC_POINT_point2hex(group, NULL, POINT_CONVERSION_UNCOMPRESSED,
  77364. ctx));
  77365. #ifndef HAVE_ECC_BRAINPOOL
  77366. /* Group not supported in wolfCrypt. */
  77367. ExpectNull(EC_POINT_point2hex(group2, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  77368. ctx));
  77369. #endif
  77370. hexStr = EC_POINT_point2hex(group, Gxy, POINT_CONVERSION_UNCOMPRESSED, ctx);
  77371. ExpectNotNull(hexStr);
  77372. ExpectStrEQ(hexStr, uncompG);
  77373. ExpectNotNull(get_point = EC_POINT_hex2point(group, hexStr, NULL, ctx));
  77374. ExpectIntEQ(EC_POINT_cmp(group, Gxy, get_point, ctx), 0);
  77375. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  77376. hexStr = EC_POINT_point2hex(group, Gxy, POINT_CONVERSION_COMPRESSED, ctx);
  77377. ExpectNotNull(hexStr);
  77378. ExpectStrEQ(hexStr, compG);
  77379. #ifdef HAVE_COMP_KEY
  77380. ExpectNotNull(get_point = EC_POINT_hex2point
  77381. (group, hexStr, get_point, ctx));
  77382. ExpectIntEQ(EC_POINT_cmp(group, Gxy, get_point, ctx), 0);
  77383. #endif
  77384. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  77385. EC_POINT_free(get_point);
  77386. #ifndef HAVE_SELFTEST
  77387. /* Test point to oct */
  77388. ExpectIntEQ(EC_POINT_point2oct(NULL, NULL, POINT_CONVERSION_UNCOMPRESSED,
  77389. NULL, 0, ctx), 0);
  77390. ExpectIntEQ(EC_POINT_point2oct(NULL, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  77391. NULL, 0, ctx), 0);
  77392. ExpectIntEQ(EC_POINT_point2oct(group, NULL, POINT_CONVERSION_UNCOMPRESSED,
  77393. NULL, 0, ctx), 0);
  77394. bin_len = EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  77395. NULL, 0, ctx);
  77396. ExpectIntEQ(bin_len, sizeof(binUncompG));
  77397. ExpectNotNull(buf = (unsigned char*)XMALLOC(bin_len, NULL,
  77398. DYNAMIC_TYPE_ECC));
  77399. ExpectIntEQ(EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  77400. buf, bin_len, ctx), bin_len);
  77401. ExpectIntEQ(XMEMCMP(buf, binUncompG, sizeof(binUncompG)), 0);
  77402. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  77403. /* Infinity (x=0, y=0) encodes as '0x00'. */
  77404. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  77405. POINT_CONVERSION_UNCOMPRESSED, NULL, 0, ctx), 1);
  77406. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  77407. POINT_CONVERSION_UNCOMPRESSED, bufInf, 0, ctx), 0);
  77408. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  77409. POINT_CONVERSION_UNCOMPRESSED, bufInf, 1, ctx), 1);
  77410. ExpectIntEQ(bufInf[0], 0);
  77411. wolfSSL_EC_POINT_dump(NULL, NULL);
  77412. /* Test point i2d */
  77413. ExpectIntEQ(ECPoint_i2d(NULL, NULL, NULL, &blen), 0);
  77414. ExpectIntEQ(ECPoint_i2d(NULL, Gxy, NULL, &blen), 0);
  77415. ExpectIntEQ(ECPoint_i2d(group, NULL, NULL, &blen), 0);
  77416. ExpectIntEQ(ECPoint_i2d(group, Gxy, NULL, NULL), 0);
  77417. ExpectIntEQ(ECPoint_i2d(group, Gxy, NULL, &blen), 1);
  77418. ExpectIntEQ(blen, sizeof(binUncompG));
  77419. ExpectNotNull(buf = (unsigned char*)XMALLOC(blen, NULL, DYNAMIC_TYPE_ECC));
  77420. blen -= 1;
  77421. ExpectIntEQ(ECPoint_i2d(group, Gxy, buf, &blen), 0);
  77422. blen += 1;
  77423. ExpectIntEQ(ECPoint_i2d(group, Gxy, buf, &blen), 1);
  77424. ExpectIntEQ(XMEMCMP(buf, binUncompG, sizeof(binUncompG)), 0);
  77425. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  77426. #ifdef HAVE_COMP_KEY
  77427. /* Test point to oct compressed */
  77428. bin_len = EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_COMPRESSED, NULL,
  77429. 0, ctx);
  77430. ExpectIntEQ(bin_len, sizeof(binCompG));
  77431. ExpectNotNull(buf = (unsigned char*)XMALLOC(bin_len, NULL,
  77432. DYNAMIC_TYPE_ECC));
  77433. ExpectIntEQ(EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_COMPRESSED, buf,
  77434. bin_len, ctx), bin_len);
  77435. ExpectIntEQ(XMEMCMP(buf, binCompG, sizeof(binCompG)), 0);
  77436. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  77437. #endif
  77438. /* Test point BN */
  77439. ExpectNull(wolfSSL_EC_POINT_point2bn(NULL, NULL,
  77440. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  77441. ExpectNull(wolfSSL_EC_POINT_point2bn(NULL, Gxy,
  77442. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  77443. ExpectNull(wolfSSL_EC_POINT_point2bn(group, NULL,
  77444. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  77445. ExpectNull(wolfSSL_EC_POINT_point2bn(group, Gxy, 0, NULL, ctx));
  77446. /* Test oct to point */
  77447. ExpectNotNull(tmp = EC_POINT_new(group));
  77448. ExpectIntEQ(EC_POINT_oct2point(NULL, NULL, binUncompG, sizeof(binUncompG),
  77449. ctx), 0);
  77450. ExpectIntEQ(EC_POINT_oct2point(NULL, tmp, binUncompG, sizeof(binUncompG),
  77451. ctx), 0);
  77452. ExpectIntEQ(EC_POINT_oct2point(group, NULL, binUncompG, sizeof(binUncompG),
  77453. ctx), 0);
  77454. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binUncompGBad,
  77455. sizeof(binUncompGBad), ctx), 0);
  77456. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binUncompG, sizeof(binUncompG),
  77457. ctx), 1);
  77458. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  77459. EC_POINT_free(tmp);
  77460. tmp = NULL;
  77461. /* Test setting BN ordinates. */
  77462. ExpectNotNull(tmp = EC_POINT_new(group));
  77463. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, NULL,
  77464. NULL, ctx), 0);
  77465. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, NULL, NULL,
  77466. NULL, ctx), 0);
  77467. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, tmp, NULL,
  77468. NULL, ctx), 0);
  77469. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, Gx,
  77470. NULL, ctx), 0);
  77471. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, NULL,
  77472. Gy, ctx), 0);
  77473. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, tmp, Gx, Gy,
  77474. ctx), 0);
  77475. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, NULL, Gx, Gy,
  77476. ctx), 0);
  77477. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, NULL,
  77478. Gy, ctx), 0);
  77479. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, Gx,
  77480. NULL, ctx), 0);
  77481. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, Gx, Gy,
  77482. ctx), 1);
  77483. EC_POINT_free(tmp);
  77484. tmp = NULL;
  77485. /* Test point d2i */
  77486. ExpectNotNull(tmp = EC_POINT_new(group));
  77487. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), NULL, NULL), 0);
  77488. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), NULL, NULL), 0);
  77489. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), group, NULL), 0);
  77490. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), NULL, tmp), 0);
  77491. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), group, tmp), 0);
  77492. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), NULL, tmp), 0);
  77493. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), group, NULL), 0);
  77494. ExpectIntEQ(ECPoint_d2i(binUncompGBad, sizeof(binUncompG), group, tmp), 0);
  77495. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), group, tmp), 1);
  77496. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  77497. EC_POINT_free(tmp);
  77498. tmp = NULL;
  77499. #ifdef HAVE_COMP_KEY
  77500. /* Test oct compressed to point */
  77501. ExpectNotNull(tmp = EC_POINT_new(group));
  77502. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binCompG, sizeof(binCompG), ctx),
  77503. 1);
  77504. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  77505. EC_POINT_free(tmp);
  77506. tmp = NULL;
  77507. /* Test point d2i - compressed */
  77508. ExpectNotNull(tmp = EC_POINT_new(group));
  77509. ExpectIntEQ(ECPoint_d2i(binCompG, sizeof(binCompG), group, tmp), 1);
  77510. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  77511. EC_POINT_free(tmp);
  77512. tmp = NULL;
  77513. #endif
  77514. #endif
  77515. /* test BN_mod_add */
  77516. ExpectIntEQ(BN_mod_add(new_point->Z, (WOLFSSL_BIGNUM*)BN_value_one(),
  77517. (WOLFSSL_BIGNUM*)BN_value_one(), (WOLFSSL_BIGNUM*)BN_value_one(), NULL),
  77518. 1);
  77519. ExpectIntEQ(BN_is_zero(new_point->Z), 1);
  77520. /* cleanup */
  77521. BN_free(X);
  77522. BN_free(Y);
  77523. BN_free(k);
  77524. BN_free(set_point_bn);
  77525. EC_POINT_free(infinity);
  77526. EC_POINT_free(new_point);
  77527. EC_POINT_free(set_point);
  77528. EC_POINT_clear_free(Gxy);
  77529. #ifndef HAVE_ECC_BRAINPOOL
  77530. EC_GROUP_free(group2);
  77531. #endif
  77532. EC_GROUP_free(group);
  77533. BN_CTX_free(ctx);
  77534. #endif
  77535. #endif /* !WOLFSSL_SP_MATH && ( !HAVE_FIPS || HAVE_FIPS_VERSION > 2) */
  77536. return EXPECT_RESULT();
  77537. }
  77538. static int test_wolfSSL_SPAKE(void)
  77539. {
  77540. EXPECT_DECLS;
  77541. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && !defined(WOLFSSL_ATECC508A) \
  77542. && !defined(WOLFSSL_ATECC608A) && !defined(HAVE_SELFTEST) && \
  77543. !defined(WOLFSSL_SP_MATH) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  77544. BIGNUM* x = NULL; /* kdc priv */
  77545. BIGNUM* y = NULL; /* client priv */
  77546. BIGNUM* w = NULL; /* shared value */
  77547. byte M_bytes[] = {
  77548. /* uncompressed */
  77549. 0x04,
  77550. /* x */
  77551. 0x88, 0x6e, 0x2f, 0x97, 0xac, 0xe4, 0x6e, 0x55, 0xba, 0x9d, 0xd7, 0x24,
  77552. 0x25, 0x79, 0xf2, 0x99, 0x3b, 0x64, 0xe1, 0x6e, 0xf3, 0xdc, 0xab, 0x95,
  77553. 0xaf, 0xd4, 0x97, 0x33, 0x3d, 0x8f, 0xa1, 0x2f,
  77554. /* y */
  77555. 0x5f, 0xf3, 0x55, 0x16, 0x3e, 0x43, 0xce, 0x22, 0x4e, 0x0b, 0x0e, 0x65,
  77556. 0xff, 0x02, 0xac, 0x8e, 0x5c, 0x7b, 0xe0, 0x94, 0x19, 0xc7, 0x85, 0xe0,
  77557. 0xca, 0x54, 0x7d, 0x55, 0xa1, 0x2e, 0x2d, 0x20
  77558. };
  77559. EC_POINT* M = NULL; /* shared value */
  77560. byte N_bytes[] = {
  77561. /* uncompressed */
  77562. 0x04,
  77563. /* x */
  77564. 0xd8, 0xbb, 0xd6, 0xc6, 0x39, 0xc6, 0x29, 0x37, 0xb0, 0x4d, 0x99, 0x7f,
  77565. 0x38, 0xc3, 0x77, 0x07, 0x19, 0xc6, 0x29, 0xd7, 0x01, 0x4d, 0x49, 0xa2,
  77566. 0x4b, 0x4f, 0x98, 0xba, 0xa1, 0x29, 0x2b, 0x49,
  77567. /* y */
  77568. 0x07, 0xd6, 0x0a, 0xa6, 0xbf, 0xad, 0xe4, 0x50, 0x08, 0xa6, 0x36, 0x33,
  77569. 0x7f, 0x51, 0x68, 0xc6, 0x4d, 0x9b, 0xd3, 0x60, 0x34, 0x80, 0x8c, 0xd5,
  77570. 0x64, 0x49, 0x0b, 0x1e, 0x65, 0x6e, 0xdb, 0xe7
  77571. };
  77572. EC_POINT* N = NULL; /* shared value */
  77573. EC_POINT* T = NULL; /* kdc pub */
  77574. EC_POINT* tmp1 = NULL; /* kdc pub */
  77575. EC_POINT* tmp2 = NULL; /* kdc pub */
  77576. EC_POINT* S = NULL; /* client pub */
  77577. EC_POINT* client_secret = NULL;
  77578. EC_POINT* kdc_secret = NULL;
  77579. EC_GROUP* group = NULL;
  77580. BN_CTX* bn_ctx = NULL;
  77581. /* Values taken from a test run of Kerberos 5 */
  77582. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  77583. ExpectNotNull(bn_ctx = BN_CTX_new());
  77584. ExpectNotNull(M = EC_POINT_new(group));
  77585. ExpectNotNull(N = EC_POINT_new(group));
  77586. ExpectNotNull(T = EC_POINT_new(group));
  77587. ExpectNotNull(tmp1 = EC_POINT_new(group));
  77588. ExpectNotNull(tmp2 = EC_POINT_new(group));
  77589. ExpectNotNull(S = EC_POINT_new(group));
  77590. ExpectNotNull(client_secret = EC_POINT_new(group));
  77591. ExpectNotNull(kdc_secret = EC_POINT_new(group));
  77592. ExpectIntEQ(BN_hex2bn(&x, "DAC3027CD692B4BDF0EDFE9B7D0E4E7"
  77593. "E5D8768A725EAEEA6FC68EC239A17C0"), 1);
  77594. ExpectIntEQ(BN_hex2bn(&y, "6F6A1D394E26B1655A54B26DCE30D49"
  77595. "90CC47EBE08F809EF3FF7F6AEAABBB5"), 1);
  77596. ExpectIntEQ(BN_hex2bn(&w, "1D992AB8BA851B9BA05353453D81EE9"
  77597. "506AB395478F0AAB647752CF117B36250"), 1);
  77598. ExpectIntEQ(EC_POINT_oct2point(group, M, M_bytes, sizeof(M_bytes), bn_ctx),
  77599. 1);
  77600. ExpectIntEQ(EC_POINT_oct2point(group, N, N_bytes, sizeof(N_bytes), bn_ctx),
  77601. 1);
  77602. /* Function pattern similar to ossl_keygen and ossl_result in krb5 */
  77603. /* kdc */
  77604. /* T=x*P+w*M */
  77605. /* All in one function call */
  77606. ExpectIntEQ(EC_POINT_mul(group, T, x, M, w, bn_ctx), 1);
  77607. /* Spread into separate calls */
  77608. ExpectIntEQ(EC_POINT_mul(group, tmp1, x, NULL, NULL, bn_ctx), 1);
  77609. ExpectIntEQ(EC_POINT_mul(group, tmp2, NULL, M, w, bn_ctx), 1);
  77610. ExpectIntEQ(EC_POINT_add(group, tmp1, tmp1, tmp2, bn_ctx),
  77611. 1);
  77612. ExpectIntEQ(EC_POINT_cmp(group, T, tmp1, bn_ctx), 0);
  77613. /* client */
  77614. /* S=y*P+w*N */
  77615. /* All in one function call */
  77616. ExpectIntEQ(EC_POINT_mul(group, S, y, N, w, bn_ctx), 1);
  77617. /* Spread into separate calls */
  77618. ExpectIntEQ(EC_POINT_mul(group, tmp1, y, NULL, NULL, bn_ctx), 1);
  77619. ExpectIntEQ(EC_POINT_mul(group, tmp2, NULL, N, w, bn_ctx), 1);
  77620. ExpectIntEQ(EC_POINT_add(group, tmp1, tmp1, tmp2, bn_ctx),
  77621. 1);
  77622. ExpectIntEQ(EC_POINT_cmp(group, S, tmp1, bn_ctx), 0);
  77623. /* K=y*(T-w*M) */
  77624. ExpectIntEQ(EC_POINT_mul(group, client_secret, NULL, M, w, bn_ctx), 1);
  77625. ExpectIntEQ(EC_POINT_invert(group, client_secret, bn_ctx), 1);
  77626. ExpectIntEQ(EC_POINT_add(group, client_secret, T, client_secret, bn_ctx),
  77627. 1);
  77628. ExpectIntEQ(EC_POINT_mul(group, client_secret, NULL, client_secret, y,
  77629. bn_ctx), 1);
  77630. /* kdc */
  77631. /* K=x*(S-w*N) */
  77632. ExpectIntEQ(EC_POINT_mul(group, kdc_secret, NULL, N, w, bn_ctx), 1);
  77633. ExpectIntEQ(EC_POINT_invert(group, kdc_secret, bn_ctx), 1);
  77634. ExpectIntEQ(EC_POINT_add(group, kdc_secret, S, kdc_secret, bn_ctx),
  77635. 1);
  77636. ExpectIntEQ(EC_POINT_mul(group, kdc_secret, NULL, kdc_secret, x, bn_ctx),
  77637. 1);
  77638. /* kdc_secret == client_secret */
  77639. ExpectIntEQ(EC_POINT_cmp(group, client_secret, kdc_secret, bn_ctx), 0);
  77640. BN_free(x);
  77641. BN_free(y);
  77642. BN_free(w);
  77643. EC_POINT_free(M);
  77644. EC_POINT_free(N);
  77645. EC_POINT_free(T);
  77646. EC_POINT_free(tmp1);
  77647. EC_POINT_free(tmp2);
  77648. EC_POINT_free(S);
  77649. EC_POINT_free(client_secret);
  77650. EC_POINT_free(kdc_secret);
  77651. EC_GROUP_free(group);
  77652. BN_CTX_free(bn_ctx);
  77653. #endif
  77654. return EXPECT_RESULT();
  77655. }
  77656. static int test_wolfSSL_EC_KEY_generate(void)
  77657. {
  77658. EXPECT_DECLS;
  77659. #ifdef OPENSSL_EXTRA
  77660. WOLFSSL_EC_KEY* key = NULL;
  77661. #ifndef HAVE_ECC_BRAINPOOL
  77662. WOLFSSL_EC_GROUP* group = NULL;
  77663. #endif
  77664. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77665. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(NULL), 0);
  77666. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 1);
  77667. wolfSSL_EC_KEY_free(key);
  77668. key = NULL;
  77669. #ifndef HAVE_ECC_BRAINPOOL
  77670. ExpectNotNull(group = wolfSSL_EC_GROUP_new_by_curve_name(
  77671. NID_brainpoolP256r1));
  77672. ExpectNotNull(key = wolfSSL_EC_KEY_new());
  77673. ExpectIntEQ(wolfSSL_EC_KEY_set_group(key, group), 1);
  77674. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 0);
  77675. wolfSSL_EC_KEY_free(key);
  77676. wolfSSL_EC_GROUP_free(group);
  77677. #endif
  77678. #endif
  77679. return EXPECT_RESULT();
  77680. }
  77681. static int test_EC_i2d(void)
  77682. {
  77683. EXPECT_DECLS;
  77684. #if defined(OPENSSL_EXTRA) && !defined(HAVE_FIPS)
  77685. EC_KEY *key = NULL;
  77686. EC_KEY *copy = NULL;
  77687. int len = 0;
  77688. unsigned char *buf = NULL;
  77689. unsigned char *p = NULL;
  77690. const unsigned char *tmp = NULL;
  77691. const unsigned char octBad[] = {
  77692. 0x09, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  77693. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  77694. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  77695. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  77696. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  77697. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  77698. };
  77699. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77700. ExpectIntEQ(EC_KEY_generate_key(key), 1);
  77701. ExpectIntGT((len = i2d_EC_PUBKEY(key, NULL)), 0);
  77702. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  77703. DYNAMIC_TYPE_TMP_BUFFER));
  77704. p = buf;
  77705. ExpectIntEQ(i2d_EC_PUBKEY(key, &p), len);
  77706. ExpectNull(o2i_ECPublicKey(NULL, NULL, -1));
  77707. ExpectNull(o2i_ECPublicKey(&copy, NULL, -1));
  77708. ExpectNull(o2i_ECPublicKey(&key, NULL, -1));
  77709. ExpectNull(o2i_ECPublicKey(NULL, &tmp, -1));
  77710. ExpectNull(o2i_ECPublicKey(NULL, NULL, 0));
  77711. ExpectNull(o2i_ECPublicKey(&key, NULL, 0));
  77712. ExpectNull(o2i_ECPublicKey(&key, &tmp, 0));
  77713. tmp = buf;
  77714. ExpectNull(o2i_ECPublicKey(NULL, &tmp, 0));
  77715. ExpectNull(o2i_ECPublicKey(&copy, &tmp, 0));
  77716. ExpectNull(o2i_ECPublicKey(NULL, &tmp, -1));
  77717. ExpectNull(o2i_ECPublicKey(&key, &tmp, -1));
  77718. ExpectIntEQ(i2o_ECPublicKey(NULL, NULL), 0);
  77719. ExpectIntEQ(i2o_ECPublicKey(NULL, &buf), 0);
  77720. tmp = buf;
  77721. ExpectNull(d2i_ECPrivateKey(NULL, &tmp, 0));
  77722. ExpectNull(d2i_ECPrivateKey(NULL, &tmp, 1));
  77723. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, 0));
  77724. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, 1));
  77725. ExpectNull(d2i_ECPrivateKey(&key, &tmp, 0));
  77726. {
  77727. EC_KEY *pubkey = NULL;
  77728. BIO* bio = NULL;
  77729. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  77730. ExpectIntGT(BIO_write(bio, buf, len), 0);
  77731. ExpectNotNull(d2i_EC_PUBKEY_bio(bio, &pubkey));
  77732. BIO_free(bio);
  77733. EC_KEY_free(pubkey);
  77734. }
  77735. ExpectIntEQ(i2d_ECPrivateKey(NULL, &p), 0);
  77736. ExpectIntEQ(i2d_ECPrivateKey(NULL, NULL), 0);
  77737. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer(NULL, NULL, -1), -1);
  77738. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, -1, 0), -1);
  77739. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, NULL, -1, 0), -1);
  77740. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, buf, -1, 0), -1);
  77741. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, 0, 0), -1);
  77742. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, -1,
  77743. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  77744. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, buf, len,
  77745. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  77746. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, NULL, len,
  77747. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  77748. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, -1,
  77749. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  77750. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, len, 0), -1);
  77751. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, len,
  77752. WOLFSSL_EC_KEY_LOAD_PRIVATE), -1);
  77753. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, octBad, sizeof(octBad),
  77754. WOLFSSL_EC_KEY_LOAD_PRIVATE), -1);
  77755. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, octBad, sizeof(octBad),
  77756. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  77757. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  77758. buf = NULL;
  77759. buf = NULL;
  77760. ExpectIntGT((len = i2d_ECPrivateKey(key, NULL)), 0);
  77761. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  77762. DYNAMIC_TYPE_TMP_BUFFER));
  77763. p = buf;
  77764. ExpectIntEQ(i2d_ECPrivateKey(key, &p), len);
  77765. p = NULL;
  77766. ExpectIntEQ(i2d_ECPrivateKey(key, &p), len);
  77767. XFREE(p, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  77768. p = NULL;
  77769. /* Bad point is also an invalid private key. */
  77770. tmp = octBad;
  77771. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, sizeof(octBad)));
  77772. tmp = buf;
  77773. ExpectNotNull(d2i_ECPrivateKey(&copy, &tmp, len));
  77774. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  77775. buf = NULL;
  77776. buf = NULL;
  77777. ExpectIntGT((len = i2o_ECPublicKey(key, NULL)), 0);
  77778. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  77779. DYNAMIC_TYPE_TMP_BUFFER));
  77780. p = buf;
  77781. ExpectIntGT((len = i2o_ECPublicKey(key, &p)), 0);
  77782. p = NULL;
  77783. ExpectIntGT((len = i2o_ECPublicKey(key, &p)), 0);
  77784. tmp = buf;
  77785. ExpectNotNull(o2i_ECPublicKey(&copy, &tmp, len));
  77786. tmp = octBad;
  77787. ExpectNull(o2i_ECPublicKey(&key, &tmp, sizeof(octBad)));
  77788. ExpectIntEQ(EC_KEY_check_key(NULL), 0);
  77789. ExpectIntEQ(EC_KEY_check_key(key), 1);
  77790. XFREE(p, NULL, DYNAMIC_TYPE_OPENSSL);
  77791. XFREE(buf, NULL, DYNAMIC_TYPE_OPENSSL);
  77792. EC_KEY_free(key);
  77793. EC_KEY_free(copy);
  77794. #endif
  77795. return EXPECT_RESULT();
  77796. }
  77797. static int test_wolfSSL_EC_curve(void)
  77798. {
  77799. EXPECT_DECLS;
  77800. #if defined(OPENSSL_EXTRA)
  77801. int nid = NID_secp160k1;
  77802. const char* nid_name = NULL;
  77803. ExpectNull(EC_curve_nid2nist(NID_sha256));
  77804. ExpectNotNull(nid_name = EC_curve_nid2nist(nid));
  77805. ExpectIntEQ(XMEMCMP(nid_name, "K-160", XSTRLEN("K-160")), 0);
  77806. ExpectIntEQ(EC_curve_nist2nid("INVALID"), 0);
  77807. ExpectIntEQ(EC_curve_nist2nid(nid_name), nid);
  77808. #endif
  77809. return EXPECT_RESULT();
  77810. }
  77811. static int test_wolfSSL_EC_KEY_dup(void)
  77812. {
  77813. EXPECT_DECLS;
  77814. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  77815. WOLFSSL_EC_KEY* ecKey = NULL;
  77816. WOLFSSL_EC_KEY* dupKey = NULL;
  77817. ecc_key* srcKey = NULL;
  77818. ecc_key* destKey = NULL;
  77819. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  77820. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  77821. /* Valid cases */
  77822. ExpectNotNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77823. ExpectIntEQ(EC_KEY_check_key(dupKey), 1);
  77824. /* Compare pubkey */
  77825. if (ecKey != NULL) {
  77826. srcKey = (ecc_key*)ecKey->internal;
  77827. }
  77828. if (dupKey != NULL) {
  77829. destKey = (ecc_key*)dupKey->internal;
  77830. }
  77831. ExpectIntEQ(wc_ecc_cmp_point(&srcKey->pubkey, &destKey->pubkey), 0);
  77832. /* compare EC_GROUP */
  77833. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(ecKey->group, dupKey->group, NULL), MP_EQ);
  77834. /* compare EC_POINT */
  77835. ExpectIntEQ(wolfSSL_EC_POINT_cmp(ecKey->group, ecKey->pub_key, \
  77836. dupKey->pub_key, NULL), MP_EQ);
  77837. /* compare BIGNUM */
  77838. ExpectIntEQ(wolfSSL_BN_cmp(ecKey->priv_key, dupKey->priv_key), MP_EQ);
  77839. wolfSSL_EC_KEY_free(dupKey);
  77840. dupKey = NULL;
  77841. /* Invalid cases */
  77842. /* NULL key */
  77843. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(NULL));
  77844. /* NULL ecc_key */
  77845. if (ecKey != NULL) {
  77846. wc_ecc_free((ecc_key*)ecKey->internal);
  77847. XFREE(ecKey->internal, NULL, DYNAMIC_TYPE_ECC);
  77848. ecKey->internal = NULL; /* Set ecc_key to NULL */
  77849. }
  77850. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77851. wolfSSL_EC_KEY_free(ecKey);
  77852. ecKey = NULL;
  77853. wolfSSL_EC_KEY_free(dupKey);
  77854. dupKey = NULL;
  77855. /* NULL Group */
  77856. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  77857. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  77858. if (ecKey != NULL) {
  77859. wolfSSL_EC_GROUP_free(ecKey->group);
  77860. ecKey->group = NULL; /* Set group to NULL */
  77861. }
  77862. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77863. wolfSSL_EC_KEY_free(ecKey);
  77864. ecKey = NULL;
  77865. wolfSSL_EC_KEY_free(dupKey);
  77866. dupKey = NULL;
  77867. /* NULL public key */
  77868. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  77869. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  77870. if (ecKey != NULL) {
  77871. wc_ecc_del_point((ecc_point*)ecKey->pub_key->internal);
  77872. ecKey->pub_key->internal = NULL; /* Set ecc_point to NULL */
  77873. }
  77874. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77875. if (ecKey != NULL) {
  77876. wolfSSL_EC_POINT_free(ecKey->pub_key);
  77877. ecKey->pub_key = NULL; /* Set pub_key to NULL */
  77878. }
  77879. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77880. wolfSSL_EC_KEY_free(ecKey);
  77881. ecKey = NULL;
  77882. wolfSSL_EC_KEY_free(dupKey);
  77883. dupKey = NULL;
  77884. /* NULL private key */
  77885. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  77886. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  77887. if (ecKey != NULL) {
  77888. wolfSSL_BN_free(ecKey->priv_key);
  77889. ecKey->priv_key = NULL; /* Set priv_key to NULL */
  77890. }
  77891. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77892. wolfSSL_EC_KEY_free(ecKey);
  77893. ecKey = NULL;
  77894. wolfSSL_EC_KEY_free(dupKey);
  77895. dupKey = NULL;
  77896. /* Test EC_KEY_up_ref */
  77897. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  77898. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), WOLFSSL_SUCCESS);
  77899. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  77900. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(ecKey), WOLFSSL_SUCCESS);
  77901. /* reference count doesn't follow duplicate */
  77902. ExpectNotNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77903. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(dupKey), WOLFSSL_SUCCESS); /* +1 */
  77904. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(dupKey), WOLFSSL_SUCCESS); /* +2 */
  77905. wolfSSL_EC_KEY_free(dupKey); /* 3 */
  77906. wolfSSL_EC_KEY_free(dupKey); /* 2 */
  77907. wolfSSL_EC_KEY_free(dupKey); /* 1, free */
  77908. wolfSSL_EC_KEY_free(ecKey); /* 2 */
  77909. wolfSSL_EC_KEY_free(ecKey); /* 1, free */
  77910. #endif
  77911. return EXPECT_RESULT();
  77912. }
  77913. static int test_wolfSSL_EC_KEY_set_group(void)
  77914. {
  77915. EXPECT_DECLS;
  77916. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(NO_ECC_SECP) && \
  77917. defined(OPENSSL_EXTRA)
  77918. EC_KEY *key = NULL;
  77919. EC_GROUP *group = NULL;
  77920. const EC_GROUP *group2 = NULL;
  77921. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  77922. ExpectNotNull(key = EC_KEY_new());
  77923. ExpectNull(EC_KEY_get0_group(NULL));
  77924. ExpectIntEQ(EC_KEY_set_group(NULL, NULL), 0);
  77925. ExpectIntEQ(EC_KEY_set_group(key, NULL), 0);
  77926. ExpectIntEQ(EC_KEY_set_group(NULL, group), 0);
  77927. ExpectIntEQ(EC_KEY_set_group(key, group), WOLFSSL_SUCCESS);
  77928. ExpectNotNull(group2 = EC_KEY_get0_group(key));
  77929. ExpectIntEQ(EC_GROUP_cmp(group2, group, NULL), 0);
  77930. EC_GROUP_free(group);
  77931. EC_KEY_free(key);
  77932. #endif
  77933. return EXPECT_RESULT();
  77934. }
  77935. static int test_wolfSSL_EC_KEY_set_conv_form(void)
  77936. {
  77937. EXPECT_DECLS;
  77938. #if defined(HAVE_ECC) && defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  77939. BIO* bio = NULL;
  77940. EC_KEY* key = NULL;
  77941. /* Error condition: NULL key. */
  77942. ExpectIntLT(EC_KEY_get_conv_form(NULL), 0);
  77943. ExpectNotNull(bio = BIO_new_file("./certs/ecc-keyPub.pem", "rb"));
  77944. ExpectNotNull(key = PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  77945. /* Conversion form defaults to uncompressed. */
  77946. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  77947. #ifdef HAVE_COMP_KEY
  77948. /* Explicitly set to compressed. */
  77949. EC_KEY_set_conv_form(key, POINT_CONVERSION_COMPRESSED);
  77950. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_COMPRESSED);
  77951. #else
  77952. /* Will still work just won't change anything. */
  77953. EC_KEY_set_conv_form(key, POINT_CONVERSION_COMPRESSED);
  77954. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  77955. EC_KEY_set_conv_form(key, POINT_CONVERSION_UNCOMPRESSED);
  77956. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  77957. #endif
  77958. EC_KEY_set_conv_form(NULL, POINT_CONVERSION_UNCOMPRESSED);
  77959. BIO_free(bio);
  77960. EC_KEY_free(key);
  77961. #endif
  77962. return EXPECT_RESULT();
  77963. }
  77964. static int test_wolfSSL_EC_KEY_private_key(void)
  77965. {
  77966. EXPECT_DECLS;
  77967. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  77968. WOLFSSL_EC_KEY* key = NULL;
  77969. WOLFSSL_BIGNUM* priv = NULL;
  77970. WOLFSSL_BIGNUM* priv2 = NULL;
  77971. WOLFSSL_BIGNUM* bn;
  77972. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77973. ExpectNotNull(priv = wolfSSL_BN_new());
  77974. ExpectNotNull(priv2 = wolfSSL_BN_new());
  77975. ExpectIntNE(BN_set_word(priv, 2), 0);
  77976. ExpectIntNE(BN_set_word(priv2, 2), 0);
  77977. ExpectNull(wolfSSL_EC_KEY_get0_private_key(NULL));
  77978. /* No private key set. */
  77979. ExpectNull(wolfSSL_EC_KEY_get0_private_key(key));
  77980. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(NULL, NULL), 0);
  77981. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, NULL), 0);
  77982. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(NULL, priv), 0);
  77983. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, priv), 1);
  77984. ExpectNotNull(bn = wolfSSL_EC_KEY_get0_private_key(key));
  77985. ExpectPtrNE(bn, priv);
  77986. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, priv2), 1);
  77987. ExpectNotNull(bn = wolfSSL_EC_KEY_get0_private_key(key));
  77988. ExpectPtrNE(bn, priv2);
  77989. wolfSSL_BN_free(priv2);
  77990. wolfSSL_BN_free(priv);
  77991. wolfSSL_EC_KEY_free(key);
  77992. #endif
  77993. return EXPECT_RESULT();
  77994. }
  77995. static int test_wolfSSL_EC_KEY_public_key(void)
  77996. {
  77997. EXPECT_DECLS;
  77998. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  77999. WOLFSSL_EC_KEY* key = NULL;
  78000. WOLFSSL_EC_POINT* pub = NULL;
  78001. WOLFSSL_EC_POINT* point = NULL;
  78002. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  78003. ExpectNull(wolfSSL_EC_KEY_get0_public_key(NULL));
  78004. ExpectNotNull(wolfSSL_EC_KEY_get0_public_key(key));
  78005. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 1);
  78006. ExpectNotNull(pub = wolfSSL_EC_KEY_get0_public_key(key));
  78007. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(NULL, NULL), 0);
  78008. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(key, NULL), 0);
  78009. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(NULL, pub), 0);
  78010. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(key, pub), 1);
  78011. ExpectNotNull(point = wolfSSL_EC_KEY_get0_public_key(key));
  78012. ExpectPtrEq(point, pub);
  78013. wolfSSL_EC_KEY_free(key);
  78014. #endif
  78015. return EXPECT_RESULT();
  78016. }
  78017. static int test_wolfSSL_EC_KEY_print_fp(void)
  78018. {
  78019. EXPECT_DECLS;
  78020. #if defined(HAVE_ECC) && ((defined(HAVE_ECC224) && defined(HAVE_ECC256)) || \
  78021. defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 224 && \
  78022. defined(OPENSSL_EXTRA) && defined(XFPRINTF) && !defined(NO_FILESYSTEM) && \
  78023. !defined(NO_STDIO_FILESYSTEM)
  78024. EC_KEY* key = NULL;
  78025. /* Bad file pointer. */
  78026. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(NULL, key, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  78027. /* NULL key. */
  78028. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  78029. ExpectNotNull((key = wolfSSL_EC_KEY_new_by_curve_name(NID_secp224r1)));
  78030. /* Negative indent. */
  78031. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  78032. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  78033. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), WOLFSSL_SUCCESS);
  78034. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  78035. wolfSSL_EC_KEY_free(key);
  78036. ExpectNotNull((key = wolfSSL_EC_KEY_new_by_curve_name(
  78037. NID_X9_62_prime256v1)));
  78038. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), WOLFSSL_SUCCESS);
  78039. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  78040. wolfSSL_EC_KEY_free(key);
  78041. #endif
  78042. return EXPECT_RESULT();
  78043. }
  78044. static int test_wolfSSL_EC_get_builtin_curves(void)
  78045. {
  78046. EXPECT_DECLS;
  78047. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  78048. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  78049. EC_builtin_curve* curves = NULL;
  78050. size_t crv_len = 0;
  78051. size_t i = 0;
  78052. ExpectIntGT((crv_len = EC_get_builtin_curves(NULL, 0)), 0);
  78053. ExpectNotNull(curves = (EC_builtin_curve*)XMALLOC(
  78054. sizeof(EC_builtin_curve) * crv_len, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  78055. ExpectIntEQ((EC_get_builtin_curves(curves, 0)), crv_len);
  78056. ExpectIntEQ(EC_get_builtin_curves(curves, crv_len), crv_len);
  78057. for (i = 0; EXPECT_SUCCESS() && (i < crv_len); i++) {
  78058. if (curves[i].comment != NULL) {
  78059. ExpectStrEQ(OBJ_nid2sn(curves[i].nid), curves[i].comment);
  78060. }
  78061. }
  78062. if (crv_len > 1) {
  78063. ExpectIntEQ(EC_get_builtin_curves(curves, crv_len - 1), crv_len - 1);
  78064. }
  78065. XFREE(curves, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  78066. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  78067. #endif /* OPENSSL_EXTRA || OPENSSL_ALL */
  78068. return EXPECT_RESULT();
  78069. }
  78070. static int test_wolfSSL_ECDSA_SIG(void)
  78071. {
  78072. EXPECT_DECLS;
  78073. #ifdef OPENSSL_EXTRA
  78074. WOLFSSL_ECDSA_SIG* sig = NULL;
  78075. WOLFSSL_ECDSA_SIG* sig2 = NULL;
  78076. WOLFSSL_BIGNUM* r = NULL;
  78077. WOLFSSL_BIGNUM* s = NULL;
  78078. const WOLFSSL_BIGNUM* r2 = NULL;
  78079. const WOLFSSL_BIGNUM* s2 = NULL;
  78080. const unsigned char* cp = NULL;
  78081. unsigned char* p = NULL;
  78082. unsigned char outSig[8];
  78083. unsigned char sigData[8] =
  78084. { 0x30, 0x06, 0x02, 0x01, 0x01, 0x02, 0x01, 0x01 };
  78085. unsigned char sigDataBad[8] =
  78086. { 0x30, 0x07, 0x02, 0x01, 0x01, 0x02, 0x01, 0x01 };
  78087. wolfSSL_ECDSA_SIG_free(NULL);
  78088. ExpectNotNull(sig = wolfSSL_ECDSA_SIG_new());
  78089. ExpectNotNull(r = wolfSSL_BN_new());
  78090. ExpectNotNull(s = wolfSSL_BN_new());
  78091. ExpectIntEQ(wolfSSL_BN_set_word(r, 1), 1);
  78092. ExpectIntEQ(wolfSSL_BN_set_word(s, 1), 1);
  78093. wolfSSL_ECDSA_SIG_get0(NULL, NULL, NULL);
  78094. wolfSSL_ECDSA_SIG_get0(NULL, &r2, NULL);
  78095. wolfSSL_ECDSA_SIG_get0(NULL, NULL, &s2);
  78096. wolfSSL_ECDSA_SIG_get0(NULL, &r2, &s2);
  78097. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, NULL, NULL), 0);
  78098. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, NULL, NULL), 0);
  78099. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, r, NULL), 0);
  78100. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, NULL, s), 0);
  78101. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, r, s), 0);
  78102. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, NULL, s), 0);
  78103. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, r, NULL), 0);
  78104. r2 = NULL;
  78105. s2 = NULL;
  78106. wolfSSL_ECDSA_SIG_get0(NULL, &r2, &s2);
  78107. ExpectNull(r2);
  78108. ExpectNull(s2);
  78109. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, r, s), 1);
  78110. if (EXPECT_FAIL()) {
  78111. wolfSSL_BN_free(r);
  78112. wolfSSL_BN_free(s);
  78113. }
  78114. wolfSSL_ECDSA_SIG_get0(sig, &r2, &s2);
  78115. ExpectPtrEq(r2, r);
  78116. ExpectPtrEq(s2, s);
  78117. r2 = NULL;
  78118. wolfSSL_ECDSA_SIG_get0(sig, &r2, NULL);
  78119. ExpectPtrEq(r2, r);
  78120. s2 = NULL;
  78121. wolfSSL_ECDSA_SIG_get0(sig, NULL, &s2);
  78122. ExpectPtrEq(s2, s);
  78123. /* r and s are freed when sig is freed. */
  78124. wolfSSL_ECDSA_SIG_free(sig);
  78125. sig = NULL;
  78126. ExpectNull(wolfSSL_d2i_ECDSA_SIG(NULL, NULL, sizeof(sigData)));
  78127. cp = sigDataBad;
  78128. ExpectNull(wolfSSL_d2i_ECDSA_SIG(NULL, &cp, sizeof(sigDataBad)));
  78129. cp = sigData;
  78130. ExpectNotNull((sig = wolfSSL_d2i_ECDSA_SIG(NULL, &cp, sizeof(sigData))));
  78131. ExpectIntEQ((cp == sigData + 8), 1);
  78132. cp = sigData;
  78133. ExpectNull(wolfSSL_d2i_ECDSA_SIG(&sig, NULL, sizeof(sigData)));
  78134. ExpectNotNull((sig2 = wolfSSL_d2i_ECDSA_SIG(&sig, &cp, sizeof(sigData))));
  78135. ExpectIntEQ((sig == sig2), 1);
  78136. cp = outSig;
  78137. p = outSig;
  78138. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(NULL, &p), 0);
  78139. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(NULL, NULL), 0);
  78140. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, NULL), 8);
  78141. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, &p), sizeof(sigData));
  78142. ExpectIntEQ((p == outSig + 8), 1);
  78143. ExpectIntEQ(XMEMCMP(sigData, outSig, 8), 0);
  78144. p = NULL;
  78145. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, &p), 8);
  78146. #ifndef WOLFSSL_I2D_ECDSA_SIG_ALLOC
  78147. ExpectNull(p);
  78148. #else
  78149. ExpectNotNull(p);
  78150. ExpectIntEQ(XMEMCMP(p, outSig, 8), 0);
  78151. XFREE(p, NULL, DYNAMIC_TYPE_OPENSSL);
  78152. #endif
  78153. wolfSSL_ECDSA_SIG_free(sig);
  78154. #endif
  78155. return EXPECT_RESULT();
  78156. }
  78157. static int test_ECDSA_size_sign(void)
  78158. {
  78159. EXPECT_DECLS;
  78160. #if defined(OPENSSL_EXTRA) && !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  78161. EC_KEY* key = NULL;
  78162. ECDSA_SIG* ecdsaSig = NULL;
  78163. int id;
  78164. byte hash[WC_MAX_DIGEST_SIZE];
  78165. byte hash2[WC_MAX_DIGEST_SIZE];
  78166. byte sig[ECC_MAX_SIG_SIZE];
  78167. unsigned int sigSz = sizeof(sig);
  78168. XMEMSET(hash, 123, sizeof(hash));
  78169. XMEMSET(hash2, 234, sizeof(hash2));
  78170. id = wc_ecc_get_curve_id_from_name("SECP256R1");
  78171. ExpectIntEQ(id, ECC_SECP256R1);
  78172. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  78173. ExpectIntEQ(EC_KEY_generate_key(key), 1);
  78174. ExpectIntGE(ECDSA_size(NULL), 0);
  78175. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), sig, &sigSz, NULL), 0);
  78176. ExpectIntEQ(ECDSA_sign(0, NULL, sizeof(hash), sig, &sigSz, key), 0);
  78177. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), NULL, &sigSz, key), 0);
  78178. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), sig, (int)sigSz, NULL), 0);
  78179. ExpectIntEQ(ECDSA_verify(0, NULL, sizeof(hash), sig, (int)sigSz, key), 0);
  78180. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), NULL, (int)sigSz, key), 0);
  78181. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), sig, &sigSz, key), 1);
  78182. ExpectIntGE(ECDSA_size(key), sigSz);
  78183. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), sig, (int)sigSz, key), 1);
  78184. ExpectIntEQ(ECDSA_verify(0, hash2, sizeof(hash2), sig, (int)sigSz, key), 0);
  78185. ExpectNull(ECDSA_do_sign(NULL, sizeof(hash), NULL));
  78186. ExpectNull(ECDSA_do_sign(NULL, sizeof(hash), key));
  78187. ExpectNull(ECDSA_do_sign(hash, sizeof(hash), NULL));
  78188. ExpectNotNull(ecdsaSig = ECDSA_do_sign(hash, sizeof(hash), key));
  78189. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), NULL, NULL), -1);
  78190. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), NULL, NULL), -1);
  78191. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), ecdsaSig, NULL), -1);
  78192. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), NULL, key), -1);
  78193. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), ecdsaSig, key), -1);
  78194. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), NULL, key), -1);
  78195. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), ecdsaSig, NULL), -1);
  78196. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), ecdsaSig, key), 1);
  78197. ExpectIntEQ(ECDSA_do_verify(hash2, sizeof(hash2), ecdsaSig, key), 0);
  78198. ECDSA_SIG_free(ecdsaSig);
  78199. EC_KEY_free(key);
  78200. #endif /* OPENSSL_EXTRA && !NO_ECC256 && !NO_ECC_SECP */
  78201. return EXPECT_RESULT();
  78202. }
  78203. static int test_ECDH_compute_key(void)
  78204. {
  78205. EXPECT_DECLS;
  78206. #if defined(OPENSSL_EXTRA) && !defined(NO_ECC256) && !defined(NO_ECC_SECP) && \
  78207. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  78208. EC_KEY* key1 = NULL;
  78209. EC_KEY* key2 = NULL;
  78210. EC_POINT* pub1 = NULL;
  78211. EC_POINT* pub2 = NULL;
  78212. byte secret1[32];
  78213. byte secret2[32];
  78214. int i;
  78215. ExpectNotNull(key1 = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  78216. ExpectIntEQ(EC_KEY_generate_key(key1), 1);
  78217. ExpectNotNull(pub1 = wolfSSL_EC_KEY_get0_public_key(key1));
  78218. ExpectNotNull(key2 = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  78219. ExpectIntEQ(EC_KEY_generate_key(key2), 1);
  78220. ExpectNotNull(pub2 = wolfSSL_EC_KEY_get0_public_key(key2));
  78221. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), NULL, NULL, NULL), 0);
  78222. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), NULL, NULL, NULL),
  78223. 0);
  78224. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), pub2, NULL, NULL), 0);
  78225. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), NULL, key1, NULL), 0);
  78226. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), pub2, key1, NULL), 0);
  78227. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), NULL, key1, NULL),
  78228. 0);
  78229. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), pub2, NULL, NULL),
  78230. 0);
  78231. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1) - 16, pub2, key1,
  78232. NULL), 0);
  78233. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), pub2, key1, NULL),
  78234. sizeof(secret1));
  78235. ExpectIntEQ(ECDH_compute_key(secret2, sizeof(secret2), pub1, key2, NULL),
  78236. sizeof(secret2));
  78237. for (i = 0; i < (int)sizeof(secret1); i++) {
  78238. ExpectIntEQ(secret1[i], secret2[i]);
  78239. }
  78240. EC_KEY_free(key2);
  78241. EC_KEY_free(key1);
  78242. #endif /* OPENSSL_EXTRA && !NO_ECC256 && !NO_ECC_SECP &&
  78243. * !WOLF_CRYPTO_CB_ONLY_ECC */
  78244. return EXPECT_RESULT();
  78245. }
  78246. #endif /* HAVE_ECC && !OPENSSL_NO_PK */
  78247. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  78248. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  78249. !defined(NO_ASN_TIME)
  78250. static int test_openssl_make_self_signed_certificate(EVP_PKEY* pkey,
  78251. int expectedDerSz)
  78252. {
  78253. EXPECT_DECLS;
  78254. X509* x509 = NULL;
  78255. BIGNUM* serial_number = NULL;
  78256. X509_NAME* name = NULL;
  78257. time_t epoch_off = 0;
  78258. ASN1_INTEGER* asn1_serial_number = NULL;
  78259. long not_before, not_after;
  78260. int derSz;
  78261. ExpectNotNull(x509 = X509_new());
  78262. ExpectIntNE(X509_set_pubkey(x509, pkey), 0);
  78263. ExpectNotNull(serial_number = BN_new());
  78264. ExpectIntNE(BN_pseudo_rand(serial_number, 64, 0, 0), 0);
  78265. ExpectNotNull(asn1_serial_number = X509_get_serialNumber(x509));
  78266. ExpectNotNull(BN_to_ASN1_INTEGER(serial_number, asn1_serial_number));
  78267. /* version 3 */
  78268. ExpectIntNE(X509_set_version(x509, 2L), 0);
  78269. ExpectNotNull(name = X509_NAME_new());
  78270. ExpectIntNE(X509_NAME_add_entry_by_NID(name, NID_commonName, MBSTRING_UTF8,
  78271. (unsigned char*)"www.wolfssl.com", -1, -1, 0), 0);
  78272. ExpectIntNE(X509_NAME_add_entry_by_NID(name, NID_pkcs9_contentType,
  78273. MBSTRING_UTF8,(unsigned char*)"Server", -1, -1, 0), 0);
  78274. ExpectIntNE(X509_set_subject_name(x509, name), 0);
  78275. ExpectIntNE(X509_set_issuer_name(x509, name), 0);
  78276. not_before = (long)wc_Time(NULL);
  78277. not_after = not_before + (365 * 24 * 60 * 60);
  78278. ExpectNotNull(X509_time_adj(X509_get_notBefore(x509), not_before,
  78279. &epoch_off));
  78280. ExpectNotNull(X509_time_adj(X509_get_notAfter(x509), not_after,
  78281. &epoch_off));
  78282. ExpectIntNE(X509_sign(x509, pkey, EVP_sha256()), 0);
  78283. ExpectNotNull(wolfSSL_X509_get_der(x509, &derSz));
  78284. ExpectIntGE(derSz, expectedDerSz);
  78285. BN_free(serial_number);
  78286. X509_NAME_free(name);
  78287. X509_free(x509);
  78288. return EXPECT_RESULT();
  78289. }
  78290. #endif
  78291. static int test_openssl_generate_key_and_cert(void)
  78292. {
  78293. EXPECT_DECLS;
  78294. #if defined(OPENSSL_EXTRA)
  78295. int expectedDerSz;
  78296. EVP_PKEY* pkey = NULL;
  78297. #ifdef HAVE_ECC
  78298. EC_KEY* ec_key = NULL;
  78299. #endif
  78300. #if !defined(NO_RSA)
  78301. int key_length = 2048;
  78302. BIGNUM* exponent = NULL;
  78303. RSA* rsa = NULL;
  78304. ExpectNotNull(pkey = EVP_PKEY_new());
  78305. ExpectNotNull(exponent = BN_new());
  78306. ExpectNotNull(rsa = RSA_new());
  78307. ExpectIntNE(BN_set_word(exponent, WC_RSA_EXPONENT), 0);
  78308. #ifndef WOLFSSL_KEY_GEN
  78309. ExpectIntEQ(RSA_generate_key_ex(rsa, key_length, exponent, NULL), 0);
  78310. #if defined(USE_CERT_BUFFERS_1024)
  78311. ExpectIntNE(wolfSSL_RSA_LoadDer_ex(rsa, server_key_der_1024,
  78312. sizeof_server_key_der_1024, WOLFSSL_RSA_LOAD_PRIVATE), 0);
  78313. key_length = 1024;
  78314. #elif defined(USE_CERT_BUFFERS_2048)
  78315. ExpectIntNE(wolfSSL_RSA_LoadDer_ex(rsa, server_key_der_2048,
  78316. sizeof_server_key_der_2048, WOLFSSL_RSA_LOAD_PRIVATE), 0);
  78317. #else
  78318. RSA_free(rsa);
  78319. rsa = NULL;
  78320. #endif
  78321. #else
  78322. ExpectIntEQ(RSA_generate_key_ex(NULL, key_length, exponent, NULL), 0);
  78323. ExpectIntEQ(RSA_generate_key_ex(rsa, 0, exponent, NULL), 0);
  78324. ExpectIntEQ(RSA_generate_key_ex(rsa, key_length, NULL, NULL), 0);
  78325. ExpectIntNE(RSA_generate_key_ex(rsa, key_length, exponent, NULL), 0);
  78326. #endif
  78327. if (rsa) {
  78328. ExpectIntNE(EVP_PKEY_assign_RSA(pkey, rsa), 0);
  78329. if (EXPECT_FAIL()) {
  78330. RSA_free(rsa);
  78331. }
  78332. #if !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && \
  78333. defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME)
  78334. expectedDerSz = 743;
  78335. ExpectIntEQ(test_openssl_make_self_signed_certificate(pkey,
  78336. expectedDerSz), TEST_SUCCESS);
  78337. #endif
  78338. }
  78339. EVP_PKEY_free(pkey);
  78340. pkey = NULL;
  78341. BN_free(exponent);
  78342. #endif /* !NO_RSA */
  78343. #ifdef HAVE_ECC
  78344. ExpectNotNull(pkey = EVP_PKEY_new());
  78345. ExpectNotNull(ec_key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  78346. #ifndef NO_WOLFSSL_STUB
  78347. EC_KEY_set_asn1_flag(ec_key, OPENSSL_EC_NAMED_CURVE);
  78348. #endif
  78349. ExpectIntNE(EC_KEY_generate_key(ec_key), 0);
  78350. ExpectIntNE(EVP_PKEY_assign_EC_KEY(pkey, ec_key), 0);
  78351. if (EXPECT_FAIL()) {
  78352. EC_KEY_free(ec_key);
  78353. }
  78354. #if !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && \
  78355. defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME)
  78356. expectedDerSz = 344;
  78357. ExpectIntEQ(test_openssl_make_self_signed_certificate(pkey, expectedDerSz),
  78358. TEST_SUCCESS);
  78359. #endif
  78360. EVP_PKEY_free(pkey);
  78361. #endif /* HAVE_ECC */
  78362. (void)pkey;
  78363. (void)expectedDerSz;
  78364. #endif /* OPENSSL_EXTRA */
  78365. return EXPECT_RESULT();
  78366. }
  78367. static int test_stubs_are_stubs(void)
  78368. {
  78369. EXPECT_DECLS;
  78370. #if defined(OPENSSL_EXTRA) && !defined(NO_WOLFSSL_STUB) && \
  78371. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  78372. WOLFSSL_CTX* ctx = NULL;
  78373. WOLFSSL_CTX* ctxN = NULL;
  78374. #ifndef NO_WOLFSSL_CLIENT
  78375. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  78376. #elif !defined(NO_WOLFSSL_SERVER)
  78377. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  78378. #endif
  78379. #define CHECKZERO_RET(x, y, z) ExpectIntEQ((int) x(y), 0); \
  78380. ExpectIntEQ((int) x(z), 0)
  78381. /* test logic, all stubs return same result regardless of ctx being NULL
  78382. * as there are no sanity checks, it's just a stub! If at some
  78383. * point a stub is not a stub it should begin to return BAD_FUNC_ARG
  78384. * if invalid inputs are supplied. Test calling both
  78385. * with and without valid inputs, if a stub functionality remains unchanged.
  78386. */
  78387. CHECKZERO_RET(wolfSSL_CTX_sess_accept, ctx, ctxN);
  78388. CHECKZERO_RET(wolfSSL_CTX_sess_connect, ctx, ctxN);
  78389. CHECKZERO_RET(wolfSSL_CTX_sess_accept_good, ctx, ctxN);
  78390. CHECKZERO_RET(wolfSSL_CTX_sess_connect_good, ctx, ctxN);
  78391. CHECKZERO_RET(wolfSSL_CTX_sess_accept_renegotiate, ctx, ctxN);
  78392. CHECKZERO_RET(wolfSSL_CTX_sess_connect_renegotiate, ctx, ctxN);
  78393. CHECKZERO_RET(wolfSSL_CTX_sess_hits, ctx, ctxN);
  78394. CHECKZERO_RET(wolfSSL_CTX_sess_cb_hits, ctx, ctxN);
  78395. CHECKZERO_RET(wolfSSL_CTX_sess_cache_full, ctx, ctxN);
  78396. CHECKZERO_RET(wolfSSL_CTX_sess_misses, ctx, ctxN);
  78397. CHECKZERO_RET(wolfSSL_CTX_sess_timeouts, ctx, ctxN);
  78398. /* when implemented this should take WOLFSSL object instead, right now
  78399. * always returns 0 */
  78400. ExpectPtrEq(SSL_get_current_expansion(NULL), NULL);
  78401. wolfSSL_CTX_free(ctx);
  78402. ctx = NULL;
  78403. ExpectStrEQ(SSL_COMP_get_name(NULL), "not supported");
  78404. ExpectPtrEq(SSL_get_current_expansion(NULL), NULL);
  78405. #endif /* OPENSSL_EXTRA && !NO_WOLFSSL_STUB && (!NO_WOLFSSL_CLIENT ||
  78406. * !NO_WOLFSSL_SERVER) */
  78407. return EXPECT_RESULT();
  78408. }
  78409. static int test_CONF_modules_xxx(void)
  78410. {
  78411. int res = TEST_SKIPPED;
  78412. #if defined(OPENSSL_EXTRA)
  78413. CONF_modules_free();
  78414. CONF_modules_unload(0);
  78415. CONF_modules_unload(1);
  78416. CONF_modules_unload(-1);
  78417. res = TEST_SUCCESS;
  78418. #endif /* OPENSSL_EXTRA */
  78419. return res;
  78420. }
  78421. static int test_CRYPTO_set_dynlock_xxx(void)
  78422. {
  78423. int res = TEST_SKIPPED;
  78424. #if defined(OPENSSL_EXTRA)
  78425. CRYPTO_set_dynlock_create_callback(
  78426. (struct CRYPTO_dynlock_value *(*)(const char*, int))NULL);
  78427. CRYPTO_set_dynlock_create_callback(
  78428. (struct CRYPTO_dynlock_value *(*)(const char*, int))1);
  78429. CRYPTO_set_dynlock_destroy_callback(
  78430. (void (*)(struct CRYPTO_dynlock_value*, const char*, int))NULL);
  78431. CRYPTO_set_dynlock_destroy_callback(
  78432. (void (*)(struct CRYPTO_dynlock_value*, const char*, int))1);
  78433. CRYPTO_set_dynlock_lock_callback(
  78434. (void (*)(int, struct CRYPTO_dynlock_value *, const char*, int))NULL);
  78435. CRYPTO_set_dynlock_lock_callback(
  78436. (void (*)(int, struct CRYPTO_dynlock_value *, const char*, int))1);
  78437. res = TEST_SUCCESS;
  78438. #endif /* OPENSSL_EXTRA */
  78439. return res;
  78440. }
  78441. static int test_CRYPTO_THREADID_xxx(void)
  78442. {
  78443. EXPECT_DECLS;
  78444. #if defined(OPENSSL_EXTRA)
  78445. CRYPTO_THREADID_current((CRYPTO_THREADID*)NULL);
  78446. CRYPTO_THREADID_current((CRYPTO_THREADID*)1);
  78447. ExpectIntEQ(CRYPTO_THREADID_hash((const CRYPTO_THREADID*)NULL), 0);
  78448. #endif /* OPENSSL_EXTRA */
  78449. return EXPECT_RESULT();
  78450. }
  78451. static int test_ENGINE_cleanup(void)
  78452. {
  78453. int res = TEST_SKIPPED;
  78454. #if defined(OPENSSL_EXTRA)
  78455. ENGINE_cleanup();
  78456. res = TEST_SUCCESS;
  78457. #endif /* OPENSSL_EXTRA */
  78458. return res;
  78459. }
  78460. static int test_wolfSSL_CTX_LoadCRL(void)
  78461. {
  78462. EXPECT_DECLS;
  78463. #if defined(HAVE_CRL) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) && \
  78464. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  78465. WOLFSSL_CTX* ctx = NULL;
  78466. WOLFSSL* ssl = NULL;
  78467. const char* badPath = "dummypath";
  78468. const char* validPath = "./certs/crl";
  78469. const char* validFilePath = "./certs/crl/cliCrl.pem";
  78470. const char* issuerCert = "./certs/client-cert.pem";
  78471. int derType = WOLFSSL_FILETYPE_ASN1;
  78472. int pemType = WOLFSSL_FILETYPE_PEM;
  78473. #ifdef HAVE_CRL_MONITOR
  78474. int monitor = WOLFSSL_CRL_MONITOR;
  78475. #else
  78476. int monitor = 0;
  78477. #endif
  78478. WOLFSSL_CERT_MANAGER* cm = NULL;
  78479. #define FAIL_T1(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  78480. WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  78481. #define FAIL_T2(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  78482. WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  78483. #define SUCC_T(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  78484. WOLFSSL_SUCCESS)
  78485. #ifndef NO_WOLFSSL_CLIENT
  78486. #define NEW_CTX(ctx) ExpectNotNull( \
  78487. (ctx) = wolfSSL_CTX_new(wolfSSLv23_client_method()))
  78488. #elif !defined(NO_WOLFSSL_SERVER)
  78489. #define NEW_CTX(ctx) ExpectNotNull( \
  78490. (ctx) = wolfSSL_CTX_new(wolfSSLv23_server_method()))
  78491. #else
  78492. #define NEW_CTX(ctx) return
  78493. #endif
  78494. FAIL_T1(wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, monitor);
  78495. NEW_CTX(ctx);
  78496. #ifndef HAVE_CRL_MONITOR
  78497. FAIL_T2(wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, WOLFSSL_CRL_MONITOR);
  78498. wolfSSL_CTX_free(ctx);
  78499. NEW_CTX(ctx);
  78500. #endif
  78501. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, monitor);
  78502. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, badPath, pemType, monitor);
  78503. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, badPath, derType, monitor);
  78504. wolfSSL_CTX_free(ctx);
  78505. ctx = NULL;
  78506. NEW_CTX(ctx);
  78507. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, issuerCert, NULL),
  78508. WOLFSSL_SUCCESS);
  78509. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx, validFilePath, pemType), WOLFSSL_SUCCESS);
  78510. wolfSSL_CTX_free(ctx);
  78511. ctx = NULL;
  78512. NEW_CTX(ctx);
  78513. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, issuerCert, NULL),
  78514. WOLFSSL_SUCCESS);
  78515. ExpectNotNull(ssl = wolfSSL_new(ctx));
  78516. ExpectIntEQ(wolfSSL_LoadCRLFile(ssl, validFilePath, pemType), WOLFSSL_SUCCESS);
  78517. wolfSSL_free(ssl);
  78518. ssl = NULL;
  78519. wolfSSL_CTX_free(ctx);
  78520. ctx = NULL;
  78521. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78522. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, issuerCert, NULL),
  78523. WOLFSSL_SUCCESS);
  78524. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, validFilePath, pemType),
  78525. WOLFSSL_SUCCESS);
  78526. wolfSSL_CertManagerFree(cm);
  78527. #endif
  78528. return EXPECT_RESULT();
  78529. }
  78530. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_CRL) && \
  78531. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  78532. static int test_multiple_crls_same_issuer_ctx_ready(WOLFSSL_CTX* ctx)
  78533. {
  78534. EXPECT_DECLS;
  78535. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  78536. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx, "./certs/crl/crl.pem",
  78537. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  78538. return EXPECT_RESULT();
  78539. }
  78540. #endif
  78541. static int test_multiple_crls_same_issuer(void)
  78542. {
  78543. EXPECT_DECLS;
  78544. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_CRL) && \
  78545. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  78546. test_ssl_cbf client_cbs, server_cbs;
  78547. struct {
  78548. const char* server_cert;
  78549. const char* server_key;
  78550. } test_params[] = {
  78551. { "./certs/server-cert.pem", "./certs/server-key.pem" },
  78552. { "./certs/server-revoked-cert.pem", "./certs/server-revoked-key.pem" }
  78553. };
  78554. size_t i;
  78555. for (i = 0; i < (sizeof(test_params)/sizeof(*test_params)); i++) {
  78556. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  78557. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  78558. server_cbs.certPemFile = test_params[i].server_cert;
  78559. server_cbs.keyPemFile = test_params[i].server_key;
  78560. client_cbs.crlPemFile = "./certs/crl/extra-crls/general-server-crl.pem";
  78561. client_cbs.ctx_ready = test_multiple_crls_same_issuer_ctx_ready;
  78562. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  78563. &server_cbs, NULL), -1001);
  78564. }
  78565. #endif
  78566. return EXPECT_RESULT();
  78567. }
  78568. static int test_SetTmpEC_DHE_Sz(void)
  78569. {
  78570. EXPECT_DECLS;
  78571. #if defined(HAVE_ECC) && !defined(NO_WOLFSSL_CLIENT)
  78572. WOLFSSL_CTX *ctx = NULL;
  78573. WOLFSSL *ssl = NULL;
  78574. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  78575. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpEC_DHE_Sz(ctx, 32));
  78576. ExpectNotNull(ssl = wolfSSL_new(ctx));
  78577. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpEC_DHE_Sz(ssl, 32));
  78578. wolfSSL_free(ssl);
  78579. wolfSSL_CTX_free(ctx);
  78580. #endif
  78581. return EXPECT_RESULT();
  78582. }
  78583. static int test_wolfSSL_CTX_get0_privatekey(void)
  78584. {
  78585. EXPECT_DECLS;
  78586. #ifdef OPENSSL_ALL
  78587. WOLFSSL_CTX* ctx = NULL;
  78588. (void)ctx;
  78589. #ifndef NO_RSA
  78590. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  78591. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  78592. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  78593. WOLFSSL_FILETYPE_PEM));
  78594. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  78595. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  78596. WOLFSSL_FILETYPE_PEM));
  78597. ExpectNotNull(SSL_CTX_get0_privatekey(ctx));
  78598. wolfSSL_CTX_free(ctx);
  78599. ctx = NULL;
  78600. #endif
  78601. #ifdef HAVE_ECC
  78602. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  78603. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  78604. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  78605. WOLFSSL_FILETYPE_PEM));
  78606. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  78607. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  78608. WOLFSSL_FILETYPE_PEM));
  78609. ExpectNotNull(SSL_CTX_get0_privatekey(ctx));
  78610. wolfSSL_CTX_free(ctx);
  78611. #endif
  78612. #endif
  78613. return EXPECT_RESULT();
  78614. }
  78615. static int test_wolfSSL_dtls_set_mtu(void)
  78616. {
  78617. EXPECT_DECLS;
  78618. #if (defined(WOLFSSL_DTLS_MTU) || defined(WOLFSSL_SCTP)) && \
  78619. !defined(NO_WOLFSSL_SERVER) && defined(WOLFSSL_DTLS) && \
  78620. !defined(WOLFSSL_NO_TLS12)
  78621. WOLFSSL_CTX* ctx = NULL;
  78622. WOLFSSL* ssl = NULL;
  78623. const char* testCertFile;
  78624. const char* testKeyFile;
  78625. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  78626. #ifndef NO_RSA
  78627. testCertFile = svrCertFile;
  78628. testKeyFile = svrKeyFile;
  78629. #elif defined(HAVE_ECC)
  78630. testCertFile = eccCertFile;
  78631. testKeyFile = eccKeyFile;
  78632. #endif
  78633. if (testCertFile != NULL && testKeyFile != NULL) {
  78634. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  78635. WOLFSSL_FILETYPE_PEM));
  78636. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  78637. WOLFSSL_FILETYPE_PEM));
  78638. }
  78639. ExpectNotNull(ssl = wolfSSL_new(ctx));
  78640. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(NULL, 1488), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  78641. ExpectIntEQ(wolfSSL_dtls_set_mtu(NULL, 1488), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  78642. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(ctx, 20000), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  78643. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl, 20000), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  78644. ExpectIntEQ(wolfSSL_get_error(ssl, WC_NO_ERR_TRACE(WOLFSSL_FAILURE)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  78645. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(ctx, 1488), WOLFSSL_SUCCESS);
  78646. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl, 1488), WOLFSSL_SUCCESS);
  78647. wolfSSL_free(ssl);
  78648. wolfSSL_CTX_free(ctx);
  78649. #endif
  78650. return EXPECT_RESULT();
  78651. }
  78652. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  78653. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  78654. static WC_INLINE void generateDTLSMsg(byte* out, int outSz, word32 seq,
  78655. enum HandShakeType hsType, word16 length)
  78656. {
  78657. size_t idx = 0;
  78658. byte* l;
  78659. /* record layer */
  78660. /* handshake type */
  78661. out[idx++] = handshake;
  78662. /* protocol version */
  78663. out[idx++] = 0xfe;
  78664. out[idx++] = 0xfd; /* DTLS 1.2 */
  78665. /* epoch 0 */
  78666. XMEMSET(out + idx, 0, 2);
  78667. idx += 2;
  78668. /* sequence number */
  78669. XMEMSET(out + idx, 0, 6);
  78670. c32toa(seq, out + idx + 2);
  78671. idx += 6;
  78672. /* length in BE */
  78673. if (length)
  78674. c16toa(length, out + idx);
  78675. else
  78676. c16toa(outSz - idx - 2, out + idx);
  78677. idx += 2;
  78678. /* handshake layer */
  78679. /* handshake type */
  78680. out[idx++] = (byte)hsType;
  78681. /* length */
  78682. l = out + idx;
  78683. idx += 3;
  78684. /* message seq */
  78685. c16toa(0, out + idx);
  78686. idx += 2;
  78687. /* frag offset */
  78688. c32to24(0, out + idx);
  78689. idx += 3;
  78690. /* frag length */
  78691. c32to24((word32)outSz - (word32)idx - 3, l);
  78692. c32to24((word32)outSz - (word32)idx - 3, out + idx);
  78693. idx += 3;
  78694. XMEMSET(out + idx, 0, outSz - idx);
  78695. }
  78696. static void test_wolfSSL_dtls_plaintext_server(WOLFSSL* ssl)
  78697. {
  78698. byte msg[] = "This is a msg for the client";
  78699. byte reply[40];
  78700. AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)),0);
  78701. reply[sizeof(reply) - 1] = '\0';
  78702. fprintf(stderr, "Client message: %s\n", reply);
  78703. AssertIntEQ(wolfSSL_write(ssl, msg, sizeof(msg)), sizeof(msg));
  78704. }
  78705. static void test_wolfSSL_dtls_plaintext_client(WOLFSSL* ssl)
  78706. {
  78707. byte ch[50];
  78708. int fd = wolfSSL_get_fd(ssl);
  78709. byte msg[] = "This is a msg for the server";
  78710. byte reply[40];
  78711. generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 0);
  78712. /* Server should ignore this datagram */
  78713. AssertIntEQ(send(fd, ch, sizeof(ch), 0), sizeof(ch));
  78714. generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 10000);
  78715. /* Server should ignore this datagram */
  78716. AssertIntEQ(send(fd, ch, sizeof(ch), 0), sizeof(ch));
  78717. AssertIntEQ(wolfSSL_write(ssl, msg, sizeof(msg)), sizeof(msg));
  78718. AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)),0);
  78719. reply[sizeof(reply) - 1] = '\0';
  78720. fprintf(stderr, "Server response: %s\n", reply);
  78721. }
  78722. static int test_wolfSSL_dtls_plaintext(void)
  78723. {
  78724. callback_functions func_cb_client;
  78725. callback_functions func_cb_server;
  78726. size_t i;
  78727. struct test_params {
  78728. method_provider client_meth;
  78729. method_provider server_meth;
  78730. ssl_callback on_result_server;
  78731. ssl_callback on_result_client;
  78732. } params[] = {
  78733. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  78734. test_wolfSSL_dtls_plaintext_server,
  78735. test_wolfSSL_dtls_plaintext_client},
  78736. };
  78737. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  78738. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  78739. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  78740. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  78741. func_cb_server.method = params[i].server_meth;
  78742. func_cb_client.method = params[i].client_meth;
  78743. func_cb_client.on_result = params[i].on_result_client;
  78744. func_cb_server.on_result = params[i].on_result_server;
  78745. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  78746. if (!func_cb_client.return_code)
  78747. return TEST_FAIL;
  78748. if (!func_cb_server.return_code)
  78749. return TEST_FAIL;
  78750. }
  78751. return TEST_RES_CHECK(1);
  78752. }
  78753. #else
  78754. static int test_wolfSSL_dtls_plaintext(void) {
  78755. return TEST_SKIPPED;
  78756. }
  78757. #endif
  78758. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  78759. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  78760. static void test_wolfSSL_dtls12_fragments_spammer(WOLFSSL* ssl)
  78761. {
  78762. byte b[1100]; /* buffer for the messages to send */
  78763. size_t idx = 0;
  78764. size_t seq_offset = 0;
  78765. size_t msg_offset = 0;
  78766. int i;
  78767. int fd = wolfSSL_get_fd(ssl);
  78768. int ret = wolfSSL_connect_cert(ssl); /* This gets us past the cookie */
  78769. word32 seq_number = 100; /* start high so server definitely reads this */
  78770. word16 msg_number = 50; /* start high so server has to buffer this */
  78771. AssertIntEQ(ret, 1);
  78772. /* Now let's start spamming the peer with fragments it needs to store */
  78773. XMEMSET(b, -1, sizeof(b));
  78774. /* record layer */
  78775. /* handshake type */
  78776. b[idx++] = 22;
  78777. /* protocol version */
  78778. b[idx++] = 0xfe;
  78779. b[idx++] = 0xfd; /* DTLS 1.2 */
  78780. /* epoch 0 */
  78781. XMEMSET(b + idx, 0, 2);
  78782. idx += 2;
  78783. /* sequence number */
  78784. XMEMSET(b + idx, 0, 6);
  78785. seq_offset = idx + 2; /* increment only the low 32 bits */
  78786. idx += 6;
  78787. /* static length in BE */
  78788. c16toa(42, b + idx);
  78789. idx += 2;
  78790. /* handshake layer */
  78791. /* cert type */
  78792. b[idx++] = 11;
  78793. /* length */
  78794. c32to24(1000, b + idx);
  78795. idx += 3;
  78796. /* message seq */
  78797. c16toa(0, b + idx);
  78798. msg_offset = idx;
  78799. idx += 2;
  78800. /* frag offset */
  78801. c32to24(500, b + idx);
  78802. idx += 3;
  78803. /* frag length */
  78804. c32to24(30, b + idx);
  78805. idx += 3;
  78806. (void)idx; /* inhibit clang-analyzer-deadcode.DeadStores */
  78807. for (i = 0; i < DTLS_POOL_SZ * 2 && ret > 0;
  78808. seq_number++, msg_number++, i++) {
  78809. struct timespec delay;
  78810. XMEMSET(&delay, 0, sizeof(delay));
  78811. delay.tv_nsec = 10000000; /* wait 0.01 seconds */
  78812. c32toa(seq_number, b + seq_offset);
  78813. c16toa(msg_number, b + msg_offset);
  78814. ret = (int)send(fd, b, 55, 0);
  78815. nanosleep(&delay, NULL);
  78816. }
  78817. }
  78818. #ifdef WOLFSSL_DTLS13
  78819. static void test_wolfSSL_dtls13_fragments_spammer(WOLFSSL* ssl)
  78820. {
  78821. const word16 sendCountMax = 100;
  78822. byte b[150]; /* buffer for the messages to send */
  78823. size_t idx = 0;
  78824. size_t msg_offset = 0;
  78825. int fd = wolfSSL_get_fd(ssl);
  78826. word16 msg_number = 10; /* start high so server has to buffer this */
  78827. int ret = wolfSSL_connect_cert(ssl); /* This gets us past the cookie */
  78828. AssertIntEQ(ret, 1);
  78829. /* Now let's start spamming the peer with fragments it needs to store */
  78830. XMEMSET(b, -1, sizeof(b));
  78831. /* handshake type */
  78832. b[idx++] = 11;
  78833. /* length */
  78834. c32to24(10000, b + idx);
  78835. idx += 3;
  78836. /* message_seq */
  78837. msg_offset = idx;
  78838. idx += 2;
  78839. /* fragment_offset */
  78840. c32to24(5000, b + idx);
  78841. idx += 3;
  78842. /* fragment_length */
  78843. c32to24(100, b + idx);
  78844. idx += 3;
  78845. /* fragment contents */
  78846. idx += 100;
  78847. for (; ret > 0 && msg_number < sendCountMax; msg_number++) {
  78848. byte sendBuf[150];
  78849. int sendSz = sizeof(sendBuf);
  78850. struct timespec delay;
  78851. XMEMSET(&delay, 0, sizeof(delay));
  78852. delay.tv_nsec = 10000000; /* wait 0.01 seconds */
  78853. c16toa(msg_number, b + msg_offset);
  78854. sendSz = BuildTls13Message(ssl, sendBuf, sendSz, b,
  78855. (int)idx, handshake, 0, 0, 0);
  78856. ret = (int)send(fd, sendBuf, (size_t)sendSz, 0);
  78857. nanosleep(&delay, NULL);
  78858. }
  78859. }
  78860. #endif
  78861. static int test_wolfSSL_dtls_fragments(void)
  78862. {
  78863. EXPECT_DECLS;
  78864. callback_functions func_cb_client;
  78865. callback_functions func_cb_server;
  78866. size_t i;
  78867. struct test_params {
  78868. method_provider client_meth;
  78869. method_provider server_meth;
  78870. ssl_callback spammer;
  78871. } params[] = {
  78872. #if !defined(WOLFSSL_NO_TLS12)
  78873. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  78874. test_wolfSSL_dtls12_fragments_spammer},
  78875. #endif
  78876. #ifdef WOLFSSL_DTLS13
  78877. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  78878. test_wolfSSL_dtls13_fragments_spammer},
  78879. #endif
  78880. };
  78881. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  78882. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  78883. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  78884. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  78885. func_cb_server.method = params[i].server_meth;
  78886. func_cb_client.method = params[i].client_meth;
  78887. func_cb_client.ssl_ready = params[i].spammer;
  78888. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  78889. ExpectFalse(func_cb_client.return_code);
  78890. ExpectFalse(func_cb_server.return_code);
  78891. /* The socket should be closed by the server resulting in a
  78892. * socket error, fatal error or reading a close notify alert */
  78893. if (func_cb_client.last_err != WC_NO_ERR_TRACE(SOCKET_ERROR_E) &&
  78894. func_cb_client.last_err != WOLFSSL_ERROR_ZERO_RETURN &&
  78895. func_cb_client.last_err != WC_NO_ERR_TRACE(FATAL_ERROR)) {
  78896. ExpectIntEQ(func_cb_client.last_err, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  78897. }
  78898. /* Check the server returned an error indicating the msg buffer
  78899. * was full */
  78900. ExpectIntEQ(func_cb_server.last_err, WC_NO_ERR_TRACE(DTLS_TOO_MANY_FRAGMENTS_E));
  78901. if (EXPECT_FAIL())
  78902. break;
  78903. }
  78904. return EXPECT_RESULT();
  78905. }
  78906. static void test_wolfSSL_dtls_send_alert(WOLFSSL* ssl)
  78907. {
  78908. int fd, ret;
  78909. byte alert_msg[] = {
  78910. 0x15, /* alert type */
  78911. 0xfe, 0xfd, /* version */
  78912. 0x00, 0x00, /* epoch */
  78913. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* seq number */
  78914. 0x00, 0x02, /* length */
  78915. 0x02, /* level: fatal */
  78916. 0x46 /* protocol version */
  78917. };
  78918. fd = wolfSSL_get_fd(ssl);
  78919. ret = (int)send(fd, alert_msg, sizeof(alert_msg), 0);
  78920. AssertIntGT(ret, 0);
  78921. }
  78922. static int _test_wolfSSL_ignore_alert_before_cookie(byte version12)
  78923. {
  78924. callback_functions client_cbs, server_cbs;
  78925. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  78926. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  78927. client_cbs.doUdp = server_cbs.doUdp = 1;
  78928. if (version12) {
  78929. #if !defined(WOLFSSL_NO_TLS12)
  78930. client_cbs.method = wolfDTLSv1_2_client_method;
  78931. server_cbs.method = wolfDTLSv1_2_server_method;
  78932. #else
  78933. return TEST_SKIPPED;
  78934. #endif
  78935. }
  78936. else
  78937. {
  78938. #ifdef WOLFSSL_DTLS13
  78939. client_cbs.method = wolfDTLSv1_3_client_method;
  78940. server_cbs.method = wolfDTLSv1_3_server_method;
  78941. #else
  78942. return TEST_SKIPPED;
  78943. #endif /* WOLFSSL_DTLS13 */
  78944. }
  78945. client_cbs.ssl_ready = test_wolfSSL_dtls_send_alert;
  78946. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  78947. if (!client_cbs.return_code)
  78948. return TEST_FAIL;
  78949. if (!server_cbs.return_code)
  78950. return TEST_FAIL;
  78951. return TEST_SUCCESS;
  78952. }
  78953. static int test_wolfSSL_ignore_alert_before_cookie(void)
  78954. {
  78955. int ret;
  78956. ret =_test_wolfSSL_ignore_alert_before_cookie(0);
  78957. if (ret != 0)
  78958. return ret;
  78959. ret =_test_wolfSSL_ignore_alert_before_cookie(1);
  78960. if (ret != 0)
  78961. return ret;
  78962. return 0;
  78963. }
  78964. static void test_wolfSSL_send_bad_record(WOLFSSL* ssl)
  78965. {
  78966. int ret;
  78967. int fd;
  78968. byte bad_msg[] = {
  78969. 0x17, /* app data */
  78970. 0xaa, 0xfd, /* bad version */
  78971. 0x00, 0x01, /* epoch 1 */
  78972. 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, /* not seen seq number */
  78973. 0x00, 0x26, /* length: 38 bytes */
  78974. 0xae, 0x30, 0x31, 0xb1, 0xf1, 0xb9, 0x6f, 0xda, 0x17, 0x19, 0xd9, 0x57,
  78975. 0xa9, 0x9d, 0x5c, 0x51, 0x9b, 0x53, 0x63, 0xa5, 0x24, 0x70, 0xa1,
  78976. 0xae, 0xdf, 0x1c, 0xb9, 0xfc, 0xe3, 0xd7, 0x77, 0x6d, 0xb6, 0x89, 0x0f,
  78977. 0x03, 0x18, 0x72
  78978. };
  78979. fd = wolfSSL_get_fd(ssl);
  78980. AssertIntGE(fd, 0);
  78981. ret = (int)send(fd, bad_msg, sizeof(bad_msg), 0);
  78982. AssertIntEQ(ret, sizeof(bad_msg));
  78983. ret = wolfSSL_write(ssl, "badrecordtest", sizeof("badrecordtest"));
  78984. AssertIntEQ(ret, sizeof("badrecordtest"));
  78985. }
  78986. static void test_wolfSSL_read_string(WOLFSSL* ssl)
  78987. {
  78988. byte buf[100];
  78989. int ret;
  78990. ret = wolfSSL_read(ssl, buf, sizeof(buf));
  78991. AssertIntGT(ret, 0);
  78992. AssertIntEQ(strcmp((char*)buf, "badrecordtest"), 0);
  78993. }
  78994. static int _test_wolfSSL_dtls_bad_record(
  78995. method_provider client_method, method_provider server_method)
  78996. {
  78997. callback_functions client_cbs, server_cbs;
  78998. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  78999. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  79000. client_cbs.doUdp = server_cbs.doUdp = 1;
  79001. client_cbs.method = client_method;
  79002. server_cbs.method = server_method;
  79003. client_cbs.on_result = test_wolfSSL_send_bad_record;
  79004. server_cbs.on_result = test_wolfSSL_read_string;
  79005. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  79006. if (!client_cbs.return_code)
  79007. return TEST_FAIL;
  79008. if (!server_cbs.return_code)
  79009. return TEST_FAIL;
  79010. return TEST_SUCCESS;
  79011. }
  79012. static int test_wolfSSL_dtls_bad_record(void)
  79013. {
  79014. int ret = TEST_SUCCESS;
  79015. #if !defined(WOLFSSL_NO_TLS12)
  79016. ret = _test_wolfSSL_dtls_bad_record(wolfDTLSv1_2_client_method,
  79017. wolfDTLSv1_2_server_method);
  79018. #endif
  79019. #ifdef WOLFSSL_DTLS13
  79020. if (ret == TEST_SUCCESS) {
  79021. ret = _test_wolfSSL_dtls_bad_record(wolfDTLSv1_3_client_method,
  79022. wolfDTLSv1_3_server_method);
  79023. }
  79024. #endif /* WOLFSSL_DTLS13 */
  79025. return ret;
  79026. }
  79027. #else
  79028. static int test_wolfSSL_dtls_fragments(void) {
  79029. return TEST_SKIPPED;
  79030. }
  79031. static int test_wolfSSL_ignore_alert_before_cookie(void) {
  79032. return TEST_SKIPPED;
  79033. }
  79034. static int test_wolfSSL_dtls_bad_record(void) {
  79035. return TEST_SKIPPED;
  79036. }
  79037. #endif
  79038. #if defined(WOLFSSL_DTLS13) && !defined(WOLFSSL_TLS13_IGNORE_AEAD_LIMITS) && \
  79039. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  79040. defined(HAVE_IO_TESTS_DEPENDENCIES)
  79041. static byte test_AEAD_fail_decryption = 0;
  79042. static byte test_AEAD_seq_num = 0;
  79043. static byte test_AEAD_done = 0;
  79044. static int test_AEAD_cbiorecv(WOLFSSL *ssl, char *buf, int sz, void *ctx)
  79045. {
  79046. int ret = (int)recv(wolfSSL_get_fd(ssl), buf, sz, 0);
  79047. if (ret > 0) {
  79048. if (test_AEAD_fail_decryption) {
  79049. /* Modify the packet to trigger a decryption failure */
  79050. buf[ret/2] ^= 0xFF;
  79051. if (test_AEAD_fail_decryption == 1)
  79052. test_AEAD_fail_decryption = 0;
  79053. }
  79054. }
  79055. (void)ctx;
  79056. return ret;
  79057. }
  79058. static void test_AEAD_get_limits(WOLFSSL* ssl, w64wrapper* hardLimit,
  79059. w64wrapper* keyUpdateLimit, w64wrapper* sendLimit)
  79060. {
  79061. if (sendLimit)
  79062. w64Zero(sendLimit);
  79063. switch (ssl->specs.bulk_cipher_algorithm) {
  79064. case wolfssl_aes_gcm:
  79065. if (sendLimit)
  79066. *sendLimit = AEAD_AES_LIMIT;
  79067. FALL_THROUGH;
  79068. case wolfssl_chacha:
  79069. if (hardLimit)
  79070. *hardLimit = DTLS_AEAD_AES_GCM_CHACHA_FAIL_LIMIT;
  79071. if (keyUpdateLimit)
  79072. *keyUpdateLimit = DTLS_AEAD_AES_GCM_CHACHA_FAIL_KU_LIMIT;
  79073. break;
  79074. case wolfssl_aes_ccm:
  79075. if (sendLimit)
  79076. *sendLimit = DTLS_AEAD_AES_CCM_LIMIT;
  79077. if (ssl->specs.aead_mac_size == AES_CCM_8_AUTH_SZ) {
  79078. if (hardLimit)
  79079. *hardLimit = DTLS_AEAD_AES_CCM_8_FAIL_LIMIT;
  79080. if (keyUpdateLimit)
  79081. *keyUpdateLimit = DTLS_AEAD_AES_CCM_8_FAIL_KU_LIMIT;
  79082. }
  79083. else {
  79084. if (hardLimit)
  79085. *hardLimit = DTLS_AEAD_AES_CCM_FAIL_LIMIT;
  79086. if (keyUpdateLimit)
  79087. *keyUpdateLimit = DTLS_AEAD_AES_CCM_FAIL_KU_LIMIT;
  79088. }
  79089. break;
  79090. default:
  79091. fprintf(stderr, "Unrecognized bulk cipher");
  79092. AssertFalse(1);
  79093. break;
  79094. }
  79095. }
  79096. static void test_AEAD_limit_client(WOLFSSL* ssl)
  79097. {
  79098. int ret;
  79099. int i;
  79100. int didReKey = 0;
  79101. char msgBuf[20];
  79102. w64wrapper hardLimit;
  79103. w64wrapper keyUpdateLimit;
  79104. w64wrapper counter;
  79105. w64wrapper sendLimit;
  79106. test_AEAD_get_limits(ssl, &hardLimit, &keyUpdateLimit, &sendLimit);
  79107. w64Zero(&counter);
  79108. AssertTrue(w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->dropCount, counter));
  79109. wolfSSL_SSLSetIORecv(ssl, test_AEAD_cbiorecv);
  79110. for (i = 0; i < 10; i++) {
  79111. /* Test some failed decryptions */
  79112. test_AEAD_fail_decryption = 1;
  79113. w64Increment(&counter);
  79114. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  79115. /* Should succeed since decryption failures are dropped */
  79116. AssertIntGT(ret, 0);
  79117. AssertTrue(w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount, counter));
  79118. }
  79119. test_AEAD_fail_decryption = 1;
  79120. Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount = keyUpdateLimit;
  79121. w64Increment(&Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount);
  79122. /* 100 read calls should be enough to complete the key update */
  79123. w64Zero(&counter);
  79124. for (i = 0; i < 100; i++) {
  79125. /* Key update should be sent and negotiated */
  79126. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  79127. AssertIntGT(ret, 0);
  79128. /* Epoch after one key update is 4 */
  79129. if (w64Equal(ssl->dtls13PeerEpoch, w64From32(0, 4)) &&
  79130. w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount, counter)) {
  79131. didReKey = 1;
  79132. break;
  79133. }
  79134. }
  79135. AssertTrue(didReKey);
  79136. if (!w64IsZero(sendLimit)) {
  79137. /* Test the sending limit for AEAD ciphers */
  79138. Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->nextSeqNumber = sendLimit;
  79139. test_AEAD_seq_num = 1;
  79140. ret = wolfSSL_write(ssl, msgBuf, sizeof(msgBuf));
  79141. AssertIntGT(ret, 0);
  79142. didReKey = 0;
  79143. w64Zero(&counter);
  79144. /* 100 read calls should be enough to complete the key update */
  79145. for (i = 0; i < 100; i++) {
  79146. /* Key update should be sent and negotiated */
  79147. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  79148. AssertIntGT(ret, 0);
  79149. /* Epoch after another key update is 5 */
  79150. if (w64Equal(ssl->dtls13Epoch, w64From32(0, 5)) &&
  79151. w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->dropCount, counter)) {
  79152. didReKey = 1;
  79153. break;
  79154. }
  79155. }
  79156. AssertTrue(didReKey);
  79157. }
  79158. test_AEAD_fail_decryption = 2;
  79159. Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount = hardLimit;
  79160. w64Decrement(&Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount);
  79161. /* Connection should fail with a DECRYPT_ERROR */
  79162. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  79163. AssertIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  79164. AssertIntEQ(wolfSSL_get_error(ssl, ret), WC_NO_ERR_TRACE(DECRYPT_ERROR));
  79165. test_AEAD_done = 1;
  79166. }
  79167. int counter = 0;
  79168. static void test_AEAD_limit_server(WOLFSSL* ssl)
  79169. {
  79170. char msgBuf[] = "Sending data";
  79171. int ret = WOLFSSL_SUCCESS;
  79172. w64wrapper sendLimit;
  79173. SOCKET_T fd = wolfSSL_get_fd(ssl);
  79174. struct timespec delay;
  79175. XMEMSET(&delay, 0, sizeof(delay));
  79176. delay.tv_nsec = 100000000; /* wait 0.1 seconds */
  79177. tcp_set_nonblocking(&fd); /* So that read doesn't block */
  79178. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  79179. test_AEAD_get_limits(ssl, NULL, NULL, &sendLimit);
  79180. while (!test_AEAD_done && ret > 0) {
  79181. counter++;
  79182. if (test_AEAD_seq_num) {
  79183. /* We need to update the seq number so that we can understand the
  79184. * peer. Otherwise we will incorrectly interpret the seq number. */
  79185. Dtls13Epoch* e = Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch);
  79186. AssertNotNull(e);
  79187. e->nextPeerSeqNumber = sendLimit;
  79188. test_AEAD_seq_num = 0;
  79189. }
  79190. (void)wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  79191. ret = wolfSSL_write(ssl, msgBuf, sizeof(msgBuf));
  79192. nanosleep(&delay, NULL);
  79193. }
  79194. }
  79195. static int test_wolfSSL_dtls_AEAD_limit(void)
  79196. {
  79197. callback_functions func_cb_client;
  79198. callback_functions func_cb_server;
  79199. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  79200. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  79201. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  79202. func_cb_server.method = wolfDTLSv1_3_server_method;
  79203. func_cb_client.method = wolfDTLSv1_3_client_method;
  79204. func_cb_server.on_result = test_AEAD_limit_server;
  79205. func_cb_client.on_result = test_AEAD_limit_client;
  79206. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  79207. if (!func_cb_client.return_code)
  79208. return TEST_FAIL;
  79209. if (!func_cb_server.return_code)
  79210. return TEST_FAIL;
  79211. return TEST_SUCCESS;
  79212. }
  79213. #else
  79214. static int test_wolfSSL_dtls_AEAD_limit(void)
  79215. {
  79216. return TEST_SKIPPED;
  79217. }
  79218. #endif
  79219. #if defined(WOLFSSL_DTLS) && \
  79220. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  79221. !defined(DEBUG_VECTOR_REGISTER_ACCESS_FUZZING)
  79222. static void test_wolfSSL_dtls_send_ch(WOLFSSL* ssl)
  79223. {
  79224. int fd, ret;
  79225. byte ch_msg[] = {
  79226. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  79227. 0xfa, 0x01, 0x00, 0x01, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  79228. 0xee, 0xfe, 0xfd, 0xc0, 0xca, 0xb5, 0x6f, 0x3d, 0x23, 0xcc, 0x53, 0x9a,
  79229. 0x67, 0x17, 0x70, 0xd3, 0xfb, 0x23, 0x16, 0x9e, 0x4e, 0xd6, 0x7e, 0x29,
  79230. 0xab, 0xfa, 0x4c, 0xa5, 0x84, 0x95, 0xc3, 0xdb, 0x21, 0x9a, 0x52, 0x00,
  79231. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  79232. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  79233. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  79234. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  79235. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x01,
  79236. 0x8e, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  79237. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  79238. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  79239. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x0c,
  79240. 0x00, 0x0a, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00,
  79241. 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x01, 0x4b, 0x01, 0x49, 0x00, 0x17,
  79242. 0x00, 0x41, 0x04, 0x96, 0xcb, 0x2e, 0x4e, 0xd9, 0x88, 0x71, 0xc7, 0xf3,
  79243. 0x1a, 0x16, 0xdd, 0x7a, 0x7c, 0xf7, 0x67, 0x8a, 0x5d, 0x9a, 0x55, 0xa6,
  79244. 0x4a, 0x90, 0xd9, 0xfb, 0xc7, 0xfb, 0xbe, 0x09, 0xa9, 0x8a, 0xb5, 0x7a,
  79245. 0xd1, 0xde, 0x83, 0x74, 0x27, 0x31, 0x1c, 0xaa, 0xae, 0xef, 0x58, 0x43,
  79246. 0x13, 0x7d, 0x15, 0x4d, 0x7f, 0x68, 0xf6, 0x8a, 0x38, 0xef, 0x0e, 0xb3,
  79247. 0xcf, 0xb8, 0x4a, 0xa9, 0xb4, 0xd7, 0xcb, 0x01, 0x00, 0x01, 0x00, 0x1d,
  79248. 0x0a, 0x22, 0x8a, 0xd1, 0x78, 0x85, 0x1e, 0x5a, 0xe1, 0x1d, 0x1e, 0xb7,
  79249. 0x2d, 0xbc, 0x5f, 0x52, 0xbc, 0x97, 0x5d, 0x8b, 0x6a, 0x8b, 0x9d, 0x1e,
  79250. 0xb1, 0xfc, 0x8a, 0xb2, 0x56, 0xcd, 0xed, 0x4b, 0xfb, 0x66, 0x3f, 0x59,
  79251. 0x3f, 0x15, 0x5d, 0x09, 0x9e, 0x2f, 0x60, 0x5b, 0x31, 0x81, 0x27, 0xf0,
  79252. 0x1c, 0xda, 0xcd, 0x48, 0x66, 0xc6, 0xbb, 0x25, 0xf0, 0x5f, 0xda, 0x4c,
  79253. 0xcf, 0x1d, 0x88, 0xc8, 0xda, 0x1b, 0x53, 0xea, 0xbd, 0xce, 0x6d, 0xf6,
  79254. 0x4a, 0x76, 0xdb, 0x75, 0x99, 0xaf, 0xcf, 0x76, 0x4a, 0xfb, 0xe3, 0xef,
  79255. 0xb2, 0xcb, 0xae, 0x4a, 0xc0, 0xe8, 0x63, 0x1f, 0xd6, 0xe8, 0xe6, 0x45,
  79256. 0xf9, 0xea, 0x0d, 0x06, 0x19, 0xfc, 0xb1, 0xfd, 0x5d, 0x92, 0x89, 0x7b,
  79257. 0xc7, 0x9f, 0x1a, 0xb3, 0x2b, 0xc7, 0xad, 0x0e, 0xfb, 0x13, 0x41, 0x83,
  79258. 0x84, 0x58, 0x3a, 0x25, 0xb9, 0x49, 0x35, 0x1c, 0x23, 0xcb, 0xd6, 0xe7,
  79259. 0xc2, 0x8c, 0x4b, 0x2a, 0x73, 0xa1, 0xdf, 0x4f, 0x73, 0x9b, 0xb3, 0xd2,
  79260. 0xb2, 0x95, 0x00, 0x3c, 0x26, 0x09, 0x89, 0x71, 0x05, 0x39, 0xc8, 0x98,
  79261. 0x8f, 0xed, 0x32, 0x15, 0x78, 0xcd, 0xd3, 0x7e, 0xfb, 0x5a, 0x78, 0x2a,
  79262. 0xdc, 0xca, 0x20, 0x09, 0xb5, 0x14, 0xf9, 0xd4, 0x58, 0xf6, 0x69, 0xf8,
  79263. 0x65, 0x9f, 0xb7, 0xe4, 0x93, 0xf1, 0xa3, 0x84, 0x7e, 0x1b, 0x23, 0x5d,
  79264. 0xea, 0x59, 0x3e, 0x4d, 0xca, 0xfd, 0xa5, 0x55, 0xdd, 0x99, 0xb5, 0x02,
  79265. 0xf8, 0x0d, 0xe5, 0xf4, 0x06, 0xb0, 0x43, 0x9e, 0x2e, 0xbf, 0x05, 0x33,
  79266. 0x65, 0x7b, 0x13, 0x8c, 0xf9, 0x16, 0x4d, 0xc5, 0x15, 0x0b, 0x40, 0x2f,
  79267. 0x66, 0x94, 0xf2, 0x43, 0x95, 0xe7, 0xa9, 0xb6, 0x39, 0x99, 0x73, 0xb3,
  79268. 0xb0, 0x06, 0xfe, 0x52, 0x9e, 0x57, 0xba, 0x75, 0xfd, 0x76, 0x7b, 0x20,
  79269. 0x31, 0x68, 0x4c
  79270. };
  79271. fd = wolfSSL_get_fd(ssl);
  79272. ret = (int)send(fd, ch_msg, sizeof(ch_msg), 0);
  79273. AssertIntGT(ret, 0);
  79274. /* consume the HRR otherwise handshake will fail */
  79275. ret = (int)recv(fd, ch_msg, sizeof(ch_msg), 0);
  79276. AssertIntGT(ret, 0);
  79277. }
  79278. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  79279. static void test_wolfSSL_dtls_send_ch_with_invalid_cookie(WOLFSSL* ssl)
  79280. {
  79281. int fd, ret;
  79282. byte ch_msh_invalid_cookie[] = {
  79283. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02,
  79284. 0x4e, 0x01, 0x00, 0x02, 0x42, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02,
  79285. 0x42, 0xfe, 0xfd, 0x69, 0xca, 0x77, 0x60, 0x6f, 0xfc, 0xd1, 0x5b, 0x60,
  79286. 0x5d, 0xf1, 0xa6, 0x5c, 0x44, 0x71, 0xae, 0xca, 0x62, 0x19, 0x0c, 0xb6,
  79287. 0xf7, 0x2c, 0xa6, 0xd5, 0xd2, 0x99, 0x9d, 0x18, 0xae, 0xac, 0x11, 0x00,
  79288. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  79289. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  79290. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  79291. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  79292. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x01,
  79293. 0xe2, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  79294. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  79295. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  79296. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x2c, 0x00, 0x45,
  79297. 0x00, 0x43, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  79298. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  79299. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  79300. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  79301. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  79302. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00,
  79303. 0x03, 0x02, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x0a, 0x00, 0x19,
  79304. 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00, 0x00, 0x16, 0x00, 0x00,
  79305. 0x00, 0x33, 0x01, 0x4b, 0x01, 0x49, 0x00, 0x17, 0x00, 0x41, 0x04, 0x7c,
  79306. 0x5a, 0xc2, 0x5a, 0xfd, 0xcd, 0x2b, 0x08, 0xb2, 0xeb, 0x8e, 0xc0, 0x02,
  79307. 0x03, 0x9d, 0xb1, 0xc1, 0x0d, 0x7b, 0x7f, 0x46, 0x43, 0xdf, 0xf3, 0xee,
  79308. 0x2b, 0x78, 0x0e, 0x29, 0x8c, 0x42, 0x11, 0x2c, 0xde, 0xd7, 0x41, 0x0f,
  79309. 0x28, 0x94, 0x80, 0x41, 0x70, 0xc4, 0x17, 0xfd, 0x6d, 0xfa, 0xee, 0x9a,
  79310. 0xf2, 0xc4, 0x15, 0x4c, 0x5f, 0x54, 0xb6, 0x78, 0x6e, 0xf9, 0x63, 0x27,
  79311. 0x33, 0xb8, 0x7b, 0x01, 0x00, 0x01, 0x00, 0xd4, 0x46, 0x62, 0x9c, 0xbf,
  79312. 0x8f, 0x1b, 0x65, 0x9b, 0xf0, 0x29, 0x64, 0xd8, 0x50, 0x0e, 0x74, 0xf1,
  79313. 0x58, 0x10, 0xc9, 0xd9, 0x82, 0x5b, 0xd9, 0xbe, 0x14, 0xdf, 0xde, 0x86,
  79314. 0xb4, 0x2e, 0x15, 0xee, 0x4f, 0xf6, 0x74, 0x9e, 0x59, 0x11, 0x36, 0x2d,
  79315. 0xb9, 0x67, 0xaa, 0x5a, 0x09, 0x9b, 0x45, 0xf1, 0x01, 0x4c, 0x4e, 0xf6,
  79316. 0xda, 0x6a, 0xae, 0xa7, 0x73, 0x7b, 0x2e, 0xb6, 0x24, 0x89, 0x99, 0xb7,
  79317. 0x52, 0x16, 0x62, 0x0a, 0xab, 0x58, 0xf8, 0x3f, 0x10, 0x5b, 0x83, 0xfd,
  79318. 0x7b, 0x81, 0x77, 0x81, 0x8d, 0xef, 0x24, 0x56, 0x6d, 0xba, 0x49, 0xd4,
  79319. 0x8b, 0xb5, 0xa0, 0xb1, 0xc9, 0x8c, 0x32, 0x95, 0x1c, 0x5e, 0x0a, 0x4b,
  79320. 0xf6, 0x00, 0x50, 0x0a, 0x87, 0x99, 0x59, 0xcf, 0x6f, 0x9d, 0x02, 0xd0,
  79321. 0x1b, 0xa1, 0x96, 0x45, 0x28, 0x76, 0x40, 0x33, 0x28, 0xc9, 0xa1, 0xfd,
  79322. 0x46, 0xab, 0x2c, 0x9e, 0x5e, 0xc6, 0x74, 0x19, 0x9a, 0xf5, 0x9b, 0x51,
  79323. 0x11, 0x4f, 0xc8, 0xb9, 0x99, 0x6b, 0x4e, 0x3e, 0x31, 0x64, 0xb4, 0x92,
  79324. 0xf4, 0x0d, 0x41, 0x4b, 0x2c, 0x65, 0x23, 0xf7, 0x47, 0xe3, 0xa5, 0x2e,
  79325. 0xe4, 0x9c, 0x2b, 0xc9, 0x41, 0x22, 0x83, 0x8a, 0x23, 0xef, 0x29, 0x7e,
  79326. 0x4f, 0x3f, 0xa3, 0xbf, 0x73, 0x2b, 0xd7, 0xcc, 0xc8, 0xc6, 0xe9, 0xbc,
  79327. 0x01, 0xb7, 0x32, 0x63, 0xd4, 0x7e, 0x7f, 0x9a, 0xaf, 0x5f, 0x05, 0x31,
  79328. 0x53, 0xd6, 0x1f, 0xa2, 0xd0, 0xdf, 0x67, 0x56, 0xf1, 0x9c, 0x4a, 0x9d,
  79329. 0x83, 0xb4, 0xef, 0xb3, 0xf2, 0xcc, 0xf1, 0x91, 0x6c, 0x47, 0xc3, 0x8b,
  79330. 0xd0, 0x92, 0x79, 0x3d, 0xa0, 0xc0, 0x3a, 0x57, 0x26, 0x6d, 0x0a, 0xad,
  79331. 0x5f, 0xad, 0xb4, 0x74, 0x48, 0x4a, 0x51, 0xe1, 0xb5, 0x82, 0x0a, 0x4c,
  79332. 0x4f, 0x9d, 0xaf, 0xee, 0x5a, 0xa2, 0x4d, 0x4d, 0x5f, 0xe0, 0x17, 0x00,
  79333. 0x23, 0x00, 0x00
  79334. };
  79335. byte alert_reply[50];
  79336. byte expected_alert_reply[] = {
  79337. 0x15, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
  79338. 0x02, 0x02, 0x2f
  79339. };
  79340. fd = wolfSSL_get_fd(ssl);
  79341. ret = (int)send(fd, ch_msh_invalid_cookie, sizeof(ch_msh_invalid_cookie), 0);
  79342. AssertIntGT(ret, 0);
  79343. /* should reply with an illegal_parameter reply */
  79344. ret = (int)recv(fd, alert_reply, sizeof(alert_reply), 0);
  79345. AssertIntEQ(ret, sizeof(expected_alert_reply));
  79346. AssertIntEQ(XMEMCMP(alert_reply, expected_alert_reply, sizeof(expected_alert_reply)), 0);
  79347. }
  79348. #endif
  79349. static word32 test_wolfSSL_dtls_stateless_HashWOLFSSL(const WOLFSSL* ssl)
  79350. {
  79351. #ifndef NO_MD5
  79352. enum wc_HashType hashType = WC_HASH_TYPE_MD5;
  79353. #elif !defined(NO_SHA)
  79354. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  79355. #elif !defined(NO_SHA256)
  79356. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  79357. #else
  79358. #error "We need a digest to hash the WOLFSSL object"
  79359. #endif
  79360. byte hashBuf[WC_MAX_DIGEST_SIZE];
  79361. wc_HashAlg hash;
  79362. const TLSX* exts = ssl->extensions;
  79363. WOLFSSL sslCopy; /* Use a copy to omit certain fields */
  79364. HS_Hashes* hsHashes = ssl->hsHashes; /* Is re-allocated in
  79365. * InitHandshakeHashes */
  79366. XMEMCPY(&sslCopy, ssl, sizeof(*ssl));
  79367. XMEMSET(hashBuf, 0, sizeof(hashBuf));
  79368. /* Following fields are not important to compare */
  79369. XMEMSET(sslCopy.buffers.inputBuffer.staticBuffer, 0, STATIC_BUFFER_LEN);
  79370. sslCopy.buffers.inputBuffer.buffer = NULL;
  79371. sslCopy.buffers.inputBuffer.bufferSize = 0;
  79372. sslCopy.buffers.inputBuffer.dynamicFlag = 0;
  79373. sslCopy.buffers.inputBuffer.offset = 0;
  79374. XMEMSET(sslCopy.buffers.outputBuffer.staticBuffer, 0, STATIC_BUFFER_LEN);
  79375. sslCopy.buffers.outputBuffer.buffer = NULL;
  79376. sslCopy.buffers.outputBuffer.bufferSize = 0;
  79377. sslCopy.buffers.outputBuffer.dynamicFlag = 0;
  79378. sslCopy.buffers.outputBuffer.offset = 0;
  79379. sslCopy.error = 0;
  79380. sslCopy.curSize = 0;
  79381. sslCopy.curStartIdx = 0;
  79382. sslCopy.keys.curSeq_lo = 0;
  79383. XMEMSET(&sslCopy.curRL, 0, sizeof(sslCopy.curRL));
  79384. #ifdef WOLFSSL_DTLS13
  79385. XMEMSET(&sslCopy.keys.curSeq, 0, sizeof(sslCopy.keys.curSeq));
  79386. sslCopy.dtls13FastTimeout = 0;
  79387. #endif
  79388. sslCopy.keys.dtls_peer_handshake_number = 0;
  79389. XMEMSET(&sslCopy.alert_history, 0, sizeof(sslCopy.alert_history));
  79390. sslCopy.hsHashes = NULL;
  79391. #ifdef WOLFSSL_ASYNC_IO
  79392. #ifdef WOLFSSL_ASYNC_CRYPT
  79393. sslCopy.asyncDev = NULL;
  79394. #endif
  79395. sslCopy.async = NULL;
  79396. #endif
  79397. AssertIntEQ(wc_HashInit(&hash, hashType), 0);
  79398. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)&sslCopy, sizeof(sslCopy)), 0);
  79399. /* hash extension list */
  79400. while (exts != NULL) {
  79401. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)exts, sizeof(*exts)), 0);
  79402. exts = exts->next;
  79403. }
  79404. /* Hash suites */
  79405. if (sslCopy.suites != NULL) {
  79406. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)sslCopy.suites,
  79407. sizeof(struct Suites)), 0);
  79408. }
  79409. /* Hash hsHashes */
  79410. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)hsHashes,
  79411. sizeof(*hsHashes)), 0);
  79412. AssertIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  79413. AssertIntEQ(wc_HashFree(&hash, hashType), 0);
  79414. return MakeWordFromHash(hashBuf);
  79415. }
  79416. static CallbackIORecv test_wolfSSL_dtls_compare_stateless_cb;
  79417. static int test_wolfSSL_dtls_compare_stateless_cb_call_once;
  79418. static int test_wolfSSL_dtls_compare_stateless_read_cb_once(WOLFSSL *ssl,
  79419. char *buf, int sz, void *ctx)
  79420. {
  79421. if (test_wolfSSL_dtls_compare_stateless_cb_call_once) {
  79422. test_wolfSSL_dtls_compare_stateless_cb_call_once = 0;
  79423. return test_wolfSSL_dtls_compare_stateless_cb(ssl, buf, sz, ctx);
  79424. }
  79425. else {
  79426. return WOLFSSL_CBIO_ERR_WANT_READ;
  79427. }
  79428. }
  79429. static void test_wolfSSL_dtls_compare_stateless(WOLFSSL* ssl)
  79430. {
  79431. /* Compare the ssl object before and after one ClientHello msg */
  79432. SOCKET_T fd = wolfSSL_get_fd(ssl);
  79433. int res;
  79434. int err;
  79435. word32 initHash;
  79436. test_wolfSSL_dtls_compare_stateless_cb = ssl->CBIORecv;
  79437. test_wolfSSL_dtls_compare_stateless_cb_call_once = 1;
  79438. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  79439. ssl->CBIORecv = test_wolfSSL_dtls_compare_stateless_read_cb_once;
  79440. initHash = test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl);
  79441. (void)initHash;
  79442. res = tcp_select(fd, 5);
  79443. /* We are expecting a msg. A timeout indicates failure. */
  79444. AssertIntEQ(res, TEST_RECV_READY);
  79445. res = wolfSSL_accept(ssl);
  79446. err = wolfSSL_get_error(ssl, res);
  79447. AssertIntEQ(res, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  79448. AssertIntEQ(err, WOLFSSL_ERROR_WANT_READ);
  79449. AssertIntEQ(initHash, test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl));
  79450. wolfSSL_dtls_set_using_nonblock(ssl, 0);
  79451. ssl->CBIORecv = test_wolfSSL_dtls_compare_stateless_cb;
  79452. }
  79453. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  79454. static void test_wolfSSL_dtls_enable_hrrcookie(WOLFSSL* ssl)
  79455. {
  79456. int ret;
  79457. ret = wolfSSL_send_hrr_cookie(ssl, NULL, 0);
  79458. AssertIntEQ(ret, WOLFSSL_SUCCESS);
  79459. test_wolfSSL_dtls_compare_stateless(ssl);
  79460. }
  79461. #endif
  79462. static int test_wolfSSL_dtls_stateless(void)
  79463. {
  79464. callback_functions client_cbs, server_cbs;
  79465. size_t i;
  79466. struct {
  79467. method_provider client_meth;
  79468. method_provider server_meth;
  79469. ssl_callback client_ssl_ready;
  79470. ssl_callback server_ssl_ready;
  79471. } test_params[] = {
  79472. #if !defined(WOLFSSL_NO_TLS12)
  79473. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  79474. test_wolfSSL_dtls_send_ch, test_wolfSSL_dtls_compare_stateless},
  79475. #endif
  79476. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  79477. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  79478. test_wolfSSL_dtls_send_ch, test_wolfSSL_dtls_enable_hrrcookie},
  79479. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  79480. test_wolfSSL_dtls_send_ch_with_invalid_cookie, test_wolfSSL_dtls_enable_hrrcookie},
  79481. #endif
  79482. };
  79483. if (0 == sizeof(test_params)){
  79484. return TEST_SKIPPED;
  79485. }
  79486. for (i = 0; i < sizeof(test_params)/sizeof(*test_params); i++) {
  79487. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  79488. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  79489. client_cbs.doUdp = server_cbs.doUdp = 1;
  79490. client_cbs.method = test_params[i].client_meth;
  79491. server_cbs.method = test_params[i].server_meth;
  79492. client_cbs.ssl_ready = test_params[i].client_ssl_ready;
  79493. server_cbs.ssl_ready = test_params[i].server_ssl_ready;
  79494. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  79495. if (!client_cbs.return_code)
  79496. return TEST_FAIL;
  79497. if (!server_cbs.return_code)
  79498. return TEST_FAIL;
  79499. }
  79500. return TEST_SUCCESS;
  79501. }
  79502. #else
  79503. static int test_wolfSSL_dtls_stateless(void)
  79504. {
  79505. return TEST_SKIPPED;
  79506. }
  79507. #endif /* WOLFSSL_DTLS13 && WOLFSSL_SEND_HRR_COOKIE &&
  79508. * HAVE_IO_TESTS_DEPENDENCIES && !SINGLE_THREADED */
  79509. #ifdef HAVE_CERT_CHAIN_VALIDATION
  79510. static int load_ca_into_cm(WOLFSSL_CERT_MANAGER* cm, char* certA)
  79511. {
  79512. int ret;
  79513. if ((ret = wolfSSL_CertManagerLoadCA(cm, certA, 0)) != WOLFSSL_SUCCESS) {
  79514. fprintf(stderr, "loading cert %s failed\n", certA);
  79515. fprintf(stderr, "Error: (%d): %s\n", ret,
  79516. wolfSSL_ERR_reason_error_string((word32)ret));
  79517. return -1;
  79518. }
  79519. return 0;
  79520. }
  79521. static int verify_cert_with_cm(WOLFSSL_CERT_MANAGER* cm, char* certA)
  79522. {
  79523. int ret;
  79524. if ((ret = wolfSSL_CertManagerVerify(cm, certA, WOLFSSL_FILETYPE_PEM))
  79525. != WOLFSSL_SUCCESS) {
  79526. fprintf(stderr, "could not verify the cert: %s\n", certA);
  79527. fprintf(stderr, "Error: (%d): %s\n", ret,
  79528. wolfSSL_ERR_reason_error_string((word32)ret));
  79529. return -1;
  79530. }
  79531. else {
  79532. fprintf(stderr, "successfully verified: %s\n", certA);
  79533. }
  79534. return 0;
  79535. }
  79536. #define LOAD_ONE_CA(a, b, c, d) \
  79537. do { \
  79538. (a) = load_ca_into_cm(c, d); \
  79539. if ((a) != 0) \
  79540. return (b); \
  79541. else \
  79542. (b)--; \
  79543. } while(0)
  79544. #define VERIFY_ONE_CERT(a, b, c, d) \
  79545. do { \
  79546. (a) = verify_cert_with_cm(c, d);\
  79547. if ((a) != 0) \
  79548. return (b); \
  79549. else \
  79550. (b)--; \
  79551. } while(0)
  79552. static int test_chainG(WOLFSSL_CERT_MANAGER* cm)
  79553. {
  79554. int ret;
  79555. int i = -1;
  79556. /* Chain G is a valid chain per RFC 5280 section 4.2.1.9 */
  79557. char chainGArr[9][50] = {"certs/ca-cert.pem",
  79558. "certs/test-pathlen/chainG-ICA7-pathlen100.pem",
  79559. "certs/test-pathlen/chainG-ICA6-pathlen10.pem",
  79560. "certs/test-pathlen/chainG-ICA5-pathlen20.pem",
  79561. "certs/test-pathlen/chainG-ICA4-pathlen5.pem",
  79562. "certs/test-pathlen/chainG-ICA3-pathlen99.pem",
  79563. "certs/test-pathlen/chainG-ICA2-pathlen1.pem",
  79564. "certs/test-pathlen/chainG-ICA1-pathlen0.pem",
  79565. "certs/test-pathlen/chainG-entity.pem"};
  79566. LOAD_ONE_CA(ret, i, cm, chainGArr[0]); /* if failure, i = -1 here */
  79567. LOAD_ONE_CA(ret, i, cm, chainGArr[1]); /* if failure, i = -2 here */
  79568. LOAD_ONE_CA(ret, i, cm, chainGArr[2]); /* if failure, i = -3 here */
  79569. LOAD_ONE_CA(ret, i, cm, chainGArr[3]); /* if failure, i = -4 here */
  79570. LOAD_ONE_CA(ret, i, cm, chainGArr[4]); /* if failure, i = -5 here */
  79571. LOAD_ONE_CA(ret, i, cm, chainGArr[5]); /* if failure, i = -6 here */
  79572. LOAD_ONE_CA(ret, i, cm, chainGArr[6]); /* if failure, i = -7 here */
  79573. LOAD_ONE_CA(ret, i, cm, chainGArr[7]); /* if failure, i = -8 here */
  79574. VERIFY_ONE_CERT(ret, i, cm, chainGArr[1]); /* if failure, i = -9 here */
  79575. VERIFY_ONE_CERT(ret, i, cm, chainGArr[2]); /* if failure, i = -10 here */
  79576. VERIFY_ONE_CERT(ret, i, cm, chainGArr[3]); /* if failure, i = -11 here */
  79577. VERIFY_ONE_CERT(ret, i, cm, chainGArr[4]); /* if failure, i = -12 here */
  79578. VERIFY_ONE_CERT(ret, i, cm, chainGArr[5]); /* if failure, i = -13 here */
  79579. VERIFY_ONE_CERT(ret, i, cm, chainGArr[6]); /* if failure, i = -14 here */
  79580. VERIFY_ONE_CERT(ret, i, cm, chainGArr[7]); /* if failure, i = -15 here */
  79581. VERIFY_ONE_CERT(ret, i, cm, chainGArr[8]); /* if failure, i = -16 here */
  79582. /* test validating the entity twice, should have no effect on pathLen since
  79583. * entity/leaf cert */
  79584. VERIFY_ONE_CERT(ret, i, cm, chainGArr[8]); /* if failure, i = -17 here */
  79585. return ret;
  79586. }
  79587. static int test_chainH(WOLFSSL_CERT_MANAGER* cm)
  79588. {
  79589. int ret;
  79590. int i = -1;
  79591. /* Chain H is NOT a valid chain per RFC5280 section 4.2.1.9:
  79592. * ICA4-pathlen of 2 signing ICA3-pathlen of 2 (reduce max path len to 2)
  79593. * ICA3-pathlen of 2 signing ICA2-pathlen of 2 (reduce max path len to 1)
  79594. * ICA2-pathlen of 2 signing ICA1-pathlen of 0 (reduce max path len to 0)
  79595. * ICA1-pathlen of 0 signing entity (pathlen is already 0, ERROR)
  79596. * Test should successfully verify ICA4, ICA3, ICA2 and then fail on ICA1
  79597. */
  79598. char chainHArr[6][50] = {"certs/ca-cert.pem",
  79599. "certs/test-pathlen/chainH-ICA4-pathlen2.pem",
  79600. "certs/test-pathlen/chainH-ICA3-pathlen2.pem",
  79601. "certs/test-pathlen/chainH-ICA2-pathlen2.pem",
  79602. "certs/test-pathlen/chainH-ICA1-pathlen0.pem",
  79603. "certs/test-pathlen/chainH-entity.pem"};
  79604. LOAD_ONE_CA(ret, i, cm, chainHArr[0]); /* if failure, i = -1 here */
  79605. LOAD_ONE_CA(ret, i, cm, chainHArr[1]); /* if failure, i = -2 here */
  79606. LOAD_ONE_CA(ret, i, cm, chainHArr[2]); /* if failure, i = -3 here */
  79607. LOAD_ONE_CA(ret, i, cm, chainHArr[3]); /* if failure, i = -4 here */
  79608. LOAD_ONE_CA(ret, i, cm, chainHArr[4]); /* if failure, i = -5 here */
  79609. VERIFY_ONE_CERT(ret, i, cm, chainHArr[1]); /* if failure, i = -6 here */
  79610. VERIFY_ONE_CERT(ret, i, cm, chainHArr[2]); /* if failure, i = -7 here */
  79611. VERIFY_ONE_CERT(ret, i, cm, chainHArr[3]); /* if failure, i = -8 here */
  79612. VERIFY_ONE_CERT(ret, i, cm, chainHArr[4]); /* if failure, i = -9 here */
  79613. VERIFY_ONE_CERT(ret, i, cm, chainHArr[5]); /* if failure, i = -10 here */
  79614. return ret;
  79615. }
  79616. static int test_chainI(WOLFSSL_CERT_MANAGER* cm)
  79617. {
  79618. int ret;
  79619. int i = -1;
  79620. /* Chain I is a valid chain per RFC5280 section 4.2.1.9:
  79621. * ICA3-pathlen of 2 signing ICA2 without a pathlen (reduce maxPathLen to 2)
  79622. * ICA2-no_pathlen signing ICA1-no_pathlen (reduce maxPathLen to 1)
  79623. * ICA1-no_pathlen signing entity (reduce maxPathLen to 0)
  79624. * Test should successfully verify ICA4, ICA3, ICA2 and then fail on ICA1
  79625. */
  79626. char chainIArr[5][50] = {"certs/ca-cert.pem",
  79627. "certs/test-pathlen/chainI-ICA3-pathlen2.pem",
  79628. "certs/test-pathlen/chainI-ICA2-no_pathlen.pem",
  79629. "certs/test-pathlen/chainI-ICA1-no_pathlen.pem",
  79630. "certs/test-pathlen/chainI-entity.pem"};
  79631. LOAD_ONE_CA(ret, i, cm, chainIArr[0]); /* if failure, i = -1 here */
  79632. LOAD_ONE_CA(ret, i, cm, chainIArr[1]); /* if failure, i = -2 here */
  79633. LOAD_ONE_CA(ret, i, cm, chainIArr[2]); /* if failure, i = -3 here */
  79634. LOAD_ONE_CA(ret, i, cm, chainIArr[3]); /* if failure, i = -4 here */
  79635. VERIFY_ONE_CERT(ret, i, cm, chainIArr[1]); /* if failure, i = -5 here */
  79636. VERIFY_ONE_CERT(ret, i, cm, chainIArr[2]); /* if failure, i = -6 here */
  79637. VERIFY_ONE_CERT(ret, i, cm, chainIArr[3]); /* if failure, i = -7 here */
  79638. VERIFY_ONE_CERT(ret, i, cm, chainIArr[4]); /* if failure, i = -8 here */
  79639. return ret;
  79640. }
  79641. static int test_chainJ(WOLFSSL_CERT_MANAGER* cm)
  79642. {
  79643. int ret;
  79644. int i = -1;
  79645. /* Chain J is NOT a valid chain per RFC5280 section 4.2.1.9:
  79646. * ICA4-pathlen of 2 signing ICA3 without a pathlen (reduce maxPathLen to 2)
  79647. * ICA3-pathlen of 2 signing ICA2 without a pathlen (reduce maxPathLen to 1)
  79648. * ICA2-no_pathlen signing ICA1-no_pathlen (reduce maxPathLen to 0)
  79649. * ICA1-no_pathlen signing entity (ERROR, pathlen zero and non-leaf cert)
  79650. */
  79651. char chainJArr[6][50] = {"certs/ca-cert.pem",
  79652. "certs/test-pathlen/chainJ-ICA4-pathlen2.pem",
  79653. "certs/test-pathlen/chainJ-ICA3-no_pathlen.pem",
  79654. "certs/test-pathlen/chainJ-ICA2-no_pathlen.pem",
  79655. "certs/test-pathlen/chainJ-ICA1-no_pathlen.pem",
  79656. "certs/test-pathlen/chainJ-entity.pem"};
  79657. LOAD_ONE_CA(ret, i, cm, chainJArr[0]); /* if failure, i = -1 here */
  79658. LOAD_ONE_CA(ret, i, cm, chainJArr[1]); /* if failure, i = -2 here */
  79659. LOAD_ONE_CA(ret, i, cm, chainJArr[2]); /* if failure, i = -3 here */
  79660. LOAD_ONE_CA(ret, i, cm, chainJArr[3]); /* if failure, i = -4 here */
  79661. LOAD_ONE_CA(ret, i, cm, chainJArr[4]); /* if failure, i = -5 here */
  79662. VERIFY_ONE_CERT(ret, i, cm, chainJArr[1]); /* if failure, i = -6 here */
  79663. VERIFY_ONE_CERT(ret, i, cm, chainJArr[2]); /* if failure, i = -7 here */
  79664. VERIFY_ONE_CERT(ret, i, cm, chainJArr[3]); /* if failure, i = -8 here */
  79665. VERIFY_ONE_CERT(ret, i, cm, chainJArr[4]); /* if failure, i = -9 here */
  79666. VERIFY_ONE_CERT(ret, i, cm, chainJArr[5]); /* if failure, i = -10 here */
  79667. return ret;
  79668. }
  79669. static int test_various_pathlen_chains(void)
  79670. {
  79671. EXPECT_DECLS;
  79672. WOLFSSL_CERT_MANAGER* cm = NULL;
  79673. /* Test chain G (large chain with varying pathLens) */
  79674. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  79675. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  79676. ExpectIntEQ(test_chainG(cm), -1);
  79677. #else
  79678. ExpectIntEQ(test_chainG(cm), 0);
  79679. #endif /* NO_WOLFSSL_CLIENT && NO_WOLFSSL_SERVER */
  79680. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  79681. wolfSSL_CertManagerFree(cm);
  79682. /* end test chain G */
  79683. /* Test chain H (5 chain with same pathLens) */
  79684. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  79685. ExpectIntLT(test_chainH(cm), 0);
  79686. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  79687. wolfSSL_CertManagerFree(cm);
  79688. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  79689. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  79690. wolfSSL_CertManagerFree(cm);
  79691. /* end test chain H */
  79692. /* Test chain I (only first ICA has pathLen set and it's set to 2,
  79693. * followed by 2 ICA's, should pass) */
  79694. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  79695. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  79696. ExpectIntEQ(test_chainI(cm), -1);
  79697. #else
  79698. ExpectIntEQ(test_chainI(cm), 0);
  79699. #endif /* NO_WOLFSSL_CLIENT && NO_WOLFSSL_SERVER */
  79700. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  79701. wolfSSL_CertManagerFree(cm);
  79702. cm = NULL;
  79703. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  79704. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  79705. wolfSSL_CertManagerFree(cm);
  79706. cm = NULL;
  79707. /* Test chain J (Again only first ICA has pathLen set and it's set to 2,
  79708. * this time followed by 3 ICA's, should fail */
  79709. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  79710. ExpectIntLT(test_chainJ(cm), 0);
  79711. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  79712. wolfSSL_CertManagerFree(cm);
  79713. cm = NULL;
  79714. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  79715. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  79716. wolfSSL_CertManagerFree(cm);
  79717. return EXPECT_RESULT();
  79718. }
  79719. #endif /* !NO_RSA && !NO_SHA && !NO_FILESYSTEM && !NO_CERTS */
  79720. #if defined(HAVE_KEYING_MATERIAL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  79721. static int test_export_keying_material_cb(WOLFSSL_CTX *ctx, WOLFSSL *ssl)
  79722. {
  79723. EXPECT_DECLS;
  79724. byte ekm[100] = {0};
  79725. (void)ctx;
  79726. /* Success Cases */
  79727. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  79728. "Test label", XSTR_SIZEOF("Test label"), NULL, 0, 0), 1);
  79729. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  79730. "Test label", XSTR_SIZEOF("Test label"), NULL, 0, 1), 1);
  79731. /* Use some random context */
  79732. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  79733. "Test label", XSTR_SIZEOF("Test label"), ekm, 10, 1), 1);
  79734. /* Failure cases */
  79735. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  79736. "client finished", XSTR_SIZEOF("client finished"), NULL, 0, 0), 0);
  79737. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  79738. "server finished", XSTR_SIZEOF("server finished"), NULL, 0, 0), 0);
  79739. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  79740. "master secret", XSTR_SIZEOF("master secret"), NULL, 0, 0), 0);
  79741. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  79742. "extended master secret", XSTR_SIZEOF("extended master secret"),
  79743. NULL, 0, 0), 0);
  79744. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  79745. "key expansion", XSTR_SIZEOF("key expansion"), NULL, 0, 0), 0);
  79746. return EXPECT_RESULT();
  79747. }
  79748. static int test_export_keying_material_ssl_cb(WOLFSSL* ssl)
  79749. {
  79750. wolfSSL_KeepArrays(ssl);
  79751. return TEST_SUCCESS;
  79752. }
  79753. static int test_export_keying_material(void)
  79754. {
  79755. EXPECT_DECLS;
  79756. test_ssl_cbf serverCb;
  79757. test_ssl_cbf clientCb;
  79758. XMEMSET(&serverCb, 0, sizeof(serverCb));
  79759. XMEMSET(&clientCb, 0, sizeof(clientCb));
  79760. clientCb.ssl_ready = test_export_keying_material_ssl_cb;
  79761. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&clientCb,
  79762. &serverCb, test_export_keying_material_cb), TEST_SUCCESS);
  79763. return EXPECT_RESULT();
  79764. }
  79765. #endif /* HAVE_KEYING_MATERIAL */
  79766. static int test_wolfSSL_THREADID_hash(void)
  79767. {
  79768. EXPECT_DECLS;
  79769. #if defined(OPENSSL_EXTRA)
  79770. CRYPTO_THREADID id;
  79771. CRYPTO_THREADID_current(NULL);
  79772. /* Hash result is word32. */
  79773. ExpectTrue(CRYPTO_THREADID_hash(NULL) == 0UL);
  79774. XMEMSET(&id, 0, sizeof(id));
  79775. ExpectTrue(CRYPTO_THREADID_hash(&id) == 0UL);
  79776. #endif /* OPENSSL_EXTRA */
  79777. return EXPECT_RESULT();
  79778. }
  79779. static int test_wolfSSL_set_ecdh_auto(void)
  79780. {
  79781. EXPECT_DECLS;
  79782. #if defined(OPENSSL_EXTRA)
  79783. WOLFSSL* ssl = NULL;
  79784. ExpectIntEQ(SSL_set_ecdh_auto(NULL,0), 1);
  79785. ExpectIntEQ(SSL_set_ecdh_auto(NULL,1), 1);
  79786. ExpectIntEQ(SSL_set_ecdh_auto(ssl,0), 1);
  79787. ExpectIntEQ(SSL_set_ecdh_auto(ssl,1), 1);
  79788. #endif /* OPENSSL_EXTRA */
  79789. return EXPECT_RESULT();
  79790. }
  79791. static int test_wolfSSL_CTX_set_ecdh_auto(void)
  79792. {
  79793. EXPECT_DECLS;
  79794. #if defined(OPENSSL_EXTRA)
  79795. WOLFSSL_CTX* ctx = NULL;
  79796. ExpectIntEQ(SSL_CTX_set_ecdh_auto(NULL,0), 1);
  79797. ExpectIntEQ(SSL_CTX_set_ecdh_auto(NULL,1), 1);
  79798. ExpectIntEQ(SSL_CTX_set_ecdh_auto(ctx,0), 1);
  79799. ExpectIntEQ(SSL_CTX_set_ecdh_auto(ctx,1), 1);
  79800. #endif /* OPENSSL_EXTRA */
  79801. return EXPECT_RESULT();
  79802. }
  79803. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL) && \
  79804. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  79805. static THREAD_RETURN WOLFSSL_THREAD SSL_read_test_server_thread(void* args)
  79806. {
  79807. EXPECT_DECLS;
  79808. callback_functions* callbacks = NULL;
  79809. WOLFSSL_CTX* ctx = NULL;
  79810. WOLFSSL* ssl = NULL;
  79811. SOCKET_T sfd = 0;
  79812. SOCKET_T cfd = 0;
  79813. word16 port;
  79814. char msg[] = "I hear you fa shizzle!";
  79815. int len = (int) XSTRLEN(msg);
  79816. char input[1024];
  79817. int ret = 0;
  79818. int err = 0;
  79819. if (!args)
  79820. WOLFSSL_RETURN_FROM_THREAD(0);
  79821. ((func_args*)args)->return_code = TEST_FAIL;
  79822. callbacks = ((func_args*)args)->callbacks;
  79823. ctx = wolfSSL_CTX_new(callbacks->method());
  79824. #if defined(USE_WINDOWS_API)
  79825. port = ((func_args*)args)->signal->port;
  79826. #else
  79827. /* Let tcp_listen assign port */
  79828. port = 0;
  79829. #endif
  79830. #ifdef WOLFSSL_TIRTOS
  79831. fdOpenSession(Task_self());
  79832. #endif
  79833. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  79834. caCertFile, 0));
  79835. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(ctx,
  79836. svrCertFile, WOLFSSL_FILETYPE_PEM));
  79837. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(ctx,
  79838. svrKeyFile, WOLFSSL_FILETYPE_PEM));
  79839. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  79840. ExpectIntEQ(wolfSSL_CTX_SetTmpDH_file(ctx, dhParamFile,
  79841. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  79842. #elif !defined(NO_DH)
  79843. SetDHCtx(ctx); /* will repick suites with DHE, higher priority than PSK */
  79844. #endif
  79845. if (callbacks->ctx_ready)
  79846. callbacks->ctx_ready(ctx);
  79847. ssl = wolfSSL_new(ctx);
  79848. ExpectNotNull(ssl);
  79849. /* listen and accept */
  79850. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  79851. CloseSocket(sfd);
  79852. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, cfd));
  79853. if (callbacks->ssl_ready)
  79854. callbacks->ssl_ready(ssl);
  79855. if (EXPECT_SUCCESS()) {
  79856. do {
  79857. err = 0; /* Reset error */
  79858. ret = wolfSSL_accept(ssl);
  79859. if (ret != WOLFSSL_SUCCESS) {
  79860. err = wolfSSL_get_error(ssl, 0);
  79861. }
  79862. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  79863. }
  79864. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  79865. /* read and write data */
  79866. XMEMSET(input, 0, sizeof(input));
  79867. while (EXPECT_SUCCESS()) {
  79868. ret = wolfSSL_read(ssl, input, sizeof(input));
  79869. if (ret > 0) {
  79870. break;
  79871. }
  79872. else {
  79873. err = wolfSSL_get_error(ssl,ret);
  79874. if (err == WOLFSSL_ERROR_WANT_READ) {
  79875. continue;
  79876. }
  79877. break;
  79878. }
  79879. }
  79880. if (EXPECT_SUCCESS() && (err == WOLFSSL_ERROR_ZERO_RETURN)) {
  79881. do {
  79882. ret = wolfSSL_write(ssl, msg, len);
  79883. if (ret > 0) {
  79884. break;
  79885. }
  79886. } while (ret < 0);
  79887. }
  79888. /* bidirectional shutdown */
  79889. while (EXPECT_SUCCESS()) {
  79890. ret = wolfSSL_shutdown(ssl);
  79891. ExpectIntNE(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  79892. if (ret == WOLFSSL_SUCCESS) {
  79893. break;
  79894. }
  79895. }
  79896. if (EXPECT_SUCCESS()) {
  79897. /* wait for the peer to disconnect the tcp connection */
  79898. do {
  79899. ret = wolfSSL_read(ssl, input, sizeof(input));
  79900. err = wolfSSL_get_error(ssl, ret);
  79901. } while (ret > 0 || err != WOLFSSL_ERROR_ZERO_RETURN);
  79902. }
  79903. /* detect TCP disconnect */
  79904. ExpectIntLE(ret,WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79905. ExpectIntEQ(wolfSSL_get_error(ssl, ret), WOLFSSL_ERROR_ZERO_RETURN);
  79906. ((func_args*)args)->return_code = EXPECT_RESULT();
  79907. wolfSSL_free(ssl);
  79908. wolfSSL_CTX_free(ctx);
  79909. CloseSocket(cfd);
  79910. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  79911. wc_ecc_fp_free(); /* free per thread cache */
  79912. #endif
  79913. WOLFSSL_RETURN_FROM_THREAD(0);
  79914. }
  79915. static THREAD_RETURN WOLFSSL_THREAD SSL_read_test_client_thread(void* args)
  79916. {
  79917. EXPECT_DECLS;
  79918. callback_functions* callbacks = NULL;
  79919. WOLFSSL_CTX* ctx = NULL;
  79920. WOLFSSL* ssl = NULL;
  79921. SOCKET_T sfd = 0;
  79922. char msg[] = "hello wolfssl server!";
  79923. int len = (int) XSTRLEN(msg);
  79924. char input[1024];
  79925. int idx;
  79926. int ret, err;
  79927. if (!args)
  79928. WOLFSSL_RETURN_FROM_THREAD(0);
  79929. ((func_args*)args)->return_code = TEST_FAIL;
  79930. callbacks = ((func_args*)args)->callbacks;
  79931. ctx = wolfSSL_CTX_new(callbacks->method());
  79932. #ifdef WOLFSSL_TIRTOS
  79933. fdOpenSession(Task_self());
  79934. #endif
  79935. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  79936. caCertFile, 0));
  79937. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(ctx,
  79938. cliCertFile, WOLFSSL_FILETYPE_PEM));
  79939. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(ctx,
  79940. cliKeyFile, WOLFSSL_FILETYPE_PEM));
  79941. ExpectNotNull((ssl = wolfSSL_new(ctx)));
  79942. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port, 0, 0, ssl);
  79943. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, sfd));
  79944. if (EXPECT_SUCCESS()) {
  79945. do {
  79946. err = 0; /* Reset error */
  79947. ret = wolfSSL_connect(ssl);
  79948. if (ret != WOLFSSL_SUCCESS) {
  79949. err = wolfSSL_get_error(ssl, 0);
  79950. }
  79951. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  79952. }
  79953. ExpectIntGE(wolfSSL_write(ssl, msg, len), 0);
  79954. if (EXPECT_SUCCESS()) {
  79955. if (0 < (idx = wolfSSL_read(ssl, input, sizeof(input)-1))) {
  79956. input[idx] = 0;
  79957. }
  79958. }
  79959. if (EXPECT_SUCCESS()) {
  79960. ret = wolfSSL_shutdown(ssl);
  79961. if (ret == WOLFSSL_SHUTDOWN_NOT_DONE) {
  79962. ret = wolfSSL_shutdown(ssl);
  79963. }
  79964. }
  79965. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  79966. ((func_args*)args)->return_code = EXPECT_RESULT();
  79967. wolfSSL_free(ssl);
  79968. wolfSSL_CTX_free(ctx);
  79969. CloseSocket(sfd);
  79970. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  79971. wc_ecc_fp_free(); /* free per thread cache */
  79972. #endif
  79973. WOLFSSL_RETURN_FROM_THREAD(0);
  79974. }
  79975. #endif /* OPENSSL_EXTRA && WOLFSSL_ERROR_CODE_OPENSSL &&
  79976. HAVE_IO_TESTS_DEPENDENCIES && !WOLFSSL_NO_TLS12 */
  79977. /* This test is to check wolfSSL_read behaves as same as
  79978. * openSSL when it is called after SSL_shutdown completes.
  79979. */
  79980. static int test_wolfSSL_read_detect_TCP_disconnect(void)
  79981. {
  79982. EXPECT_DECLS;
  79983. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL) && \
  79984. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  79985. tcp_ready ready;
  79986. func_args client_args;
  79987. func_args server_args;
  79988. THREAD_TYPE serverThread;
  79989. THREAD_TYPE clientThread;
  79990. callback_functions server_cbf;
  79991. callback_functions client_cbf;
  79992. #ifdef WOLFSSL_TIRTOS
  79993. fdOpenSession(Task_self());
  79994. #endif
  79995. StartTCP();
  79996. InitTcpReady(&ready);
  79997. #if defined(USE_WINDOWS_API)
  79998. /* use RNG to get random port if using windows */
  79999. ready.port = GetRandomPort();
  80000. #endif
  80001. XMEMSET(&client_args, 0, sizeof(func_args));
  80002. XMEMSET(&server_args, 0, sizeof(func_args));
  80003. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  80004. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  80005. server_cbf.method = wolfTLSv1_2_server_method;
  80006. client_cbf.method = wolfTLSv1_2_client_method;
  80007. server_args.callbacks = &server_cbf;
  80008. client_args.callbacks = &client_cbf;
  80009. server_args.signal = &ready;
  80010. client_args.signal = &ready;
  80011. start_thread(SSL_read_test_server_thread, &server_args, &serverThread);
  80012. wait_tcp_ready(&server_args);
  80013. start_thread(SSL_read_test_client_thread, &client_args, &clientThread);
  80014. join_thread(clientThread);
  80015. join_thread(serverThread);
  80016. ExpectTrue(client_args.return_code);
  80017. ExpectTrue(server_args.return_code);
  80018. FreeTcpReady(&ready);
  80019. #endif
  80020. return EXPECT_RESULT();
  80021. }
  80022. static int test_wolfSSL_CTX_get_min_proto_version(void)
  80023. {
  80024. EXPECT_DECLS;
  80025. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  80026. WOLFSSL_CTX *ctx = NULL;
  80027. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  80028. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, SSL3_VERSION),
  80029. WOLFSSL_SUCCESS);
  80030. #ifdef WOLFSSL_ALLOW_SSLV3
  80031. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), SSL3_VERSION);
  80032. #else
  80033. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), SSL3_VERSION);
  80034. #endif
  80035. wolfSSL_CTX_free(ctx);
  80036. ctx = NULL;
  80037. #ifndef NO_OLD_TLS
  80038. #ifdef WOLFSSL_ALLOW_TLSV10
  80039. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_method()));
  80040. #else
  80041. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  80042. #endif
  80043. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_VERSION),
  80044. WOLFSSL_SUCCESS);
  80045. #ifdef WOLFSSL_ALLOW_TLSV10
  80046. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_VERSION);
  80047. #else
  80048. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_VERSION);
  80049. #endif
  80050. wolfSSL_CTX_free(ctx);
  80051. ctx = NULL;
  80052. #endif
  80053. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  80054. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_1_VERSION),
  80055. WOLFSSL_SUCCESS);
  80056. #ifndef NO_OLD_TLS
  80057. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_1_VERSION);
  80058. #else
  80059. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_1_VERSION);
  80060. #endif
  80061. wolfSSL_CTX_free(ctx);
  80062. ctx = NULL;
  80063. #ifndef WOLFSSL_NO_TLS12
  80064. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_method()));
  80065. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION),
  80066. WOLFSSL_SUCCESS);
  80067. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_2_VERSION);
  80068. wolfSSL_CTX_free(ctx);
  80069. ctx = NULL;
  80070. #endif
  80071. #ifdef WOLFSSL_TLS13
  80072. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_method()));
  80073. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_3_VERSION),
  80074. WOLFSSL_SUCCESS);
  80075. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_3_VERSION);
  80076. wolfSSL_CTX_free(ctx);
  80077. ctx = NULL;
  80078. #endif
  80079. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL) */
  80080. return EXPECT_RESULT();
  80081. }
  80082. #if defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  80083. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  80084. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  80085. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))
  80086. static int test_wolfSSL_set_SSL_CTX(void)
  80087. {
  80088. EXPECT_DECLS;
  80089. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) \
  80090. && !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_TLS13) && \
  80091. !defined(NO_RSA)
  80092. WOLFSSL_CTX *ctx1 = NULL;
  80093. WOLFSSL_CTX *ctx2 = NULL;
  80094. WOLFSSL *ssl = NULL;
  80095. const byte *session_id1 = (const byte *)"CTX1";
  80096. const byte *session_id2 = (const byte *)"CTX2";
  80097. ExpectNotNull(ctx1 = wolfSSL_CTX_new(wolfTLS_server_method()));
  80098. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx1, svrCertFile,
  80099. WOLFSSL_FILETYPE_PEM));
  80100. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx1, svrKeyFile,
  80101. WOLFSSL_FILETYPE_PEM));
  80102. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx1, TLS1_2_VERSION),
  80103. WOLFSSL_SUCCESS);
  80104. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx1), TLS1_2_VERSION);
  80105. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx1), TLS1_3_VERSION);
  80106. ExpectIntEQ(wolfSSL_CTX_set_session_id_context(ctx1, session_id1, 4),
  80107. WOLFSSL_SUCCESS);
  80108. ExpectNotNull(ctx2 = wolfSSL_CTX_new(wolfTLS_server_method()));
  80109. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx2, svrCertFile,
  80110. WOLFSSL_FILETYPE_PEM));
  80111. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx2, svrKeyFile,
  80112. WOLFSSL_FILETYPE_PEM));
  80113. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx2, TLS1_2_VERSION),
  80114. WOLFSSL_SUCCESS);
  80115. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx2, TLS1_2_VERSION),
  80116. WOLFSSL_SUCCESS);
  80117. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx2), TLS1_2_VERSION);
  80118. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx2), TLS1_2_VERSION);
  80119. ExpectIntEQ(wolfSSL_CTX_set_session_id_context(ctx2, session_id2, 4),
  80120. WOLFSSL_SUCCESS);
  80121. #ifdef HAVE_SESSION_TICKET
  80122. ExpectIntEQ((wolfSSL_CTX_get_options(ctx1) & SSL_OP_NO_TICKET), 0);
  80123. wolfSSL_CTX_set_options(ctx2, SSL_OP_NO_TICKET);
  80124. ExpectIntNE((wolfSSL_CTX_get_options(ctx2) & SSL_OP_NO_TICKET), 0);
  80125. #endif
  80126. ExpectNotNull(ssl = wolfSSL_new(ctx2));
  80127. ExpectIntNE((wolfSSL_get_options(ssl) & WOLFSSL_OP_NO_TLSv1_3), 0);
  80128. #ifdef WOLFSSL_INT_H
  80129. #ifdef WOLFSSL_SESSION_ID_CTX
  80130. ExpectIntEQ(XMEMCMP(ssl->sessionCtx, session_id2, 4), 0);
  80131. #endif
  80132. #ifdef WOLFSSL_COPY_CERT
  80133. if (ctx2 != NULL && ctx2->certificate != NULL) {
  80134. ExpectFalse(ssl->buffers.certificate == ctx2->certificate);
  80135. }
  80136. if (ctx2 != NULL && ctx2->certChain != NULL) {
  80137. ExpectFalse(ssl->buffers.certChain == ctx2->certChain);
  80138. }
  80139. #else
  80140. ExpectTrue(ssl->buffers.certificate == ctx2->certificate);
  80141. ExpectTrue(ssl->buffers.certChain == ctx2->certChain);
  80142. #endif
  80143. #endif
  80144. #ifdef HAVE_SESSION_TICKET
  80145. ExpectIntNE((wolfSSL_get_options(ssl) & SSL_OP_NO_TICKET), 0);
  80146. #endif
  80147. /* Set the ctx1 that has TLSv1.3 as max proto version */
  80148. ExpectNotNull(wolfSSL_set_SSL_CTX(ssl, ctx1));
  80149. /* MUST not change proto versions of ssl */
  80150. ExpectIntNE((wolfSSL_get_options(ssl) & WOLFSSL_OP_NO_TLSv1_3), 0);
  80151. #ifdef HAVE_SESSION_TICKET
  80152. /* MUST not change */
  80153. ExpectIntNE((wolfSSL_get_options(ssl) & SSL_OP_NO_TICKET), 0);
  80154. #endif
  80155. /* MUST change */
  80156. #ifdef WOLFSSL_INT_H
  80157. #ifdef WOLFSSL_COPY_CERT
  80158. if (ctx1 != NULL && ctx1->certificate != NULL) {
  80159. ExpectFalse(ssl->buffers.certificate == ctx1->certificate);
  80160. }
  80161. if (ctx1 != NULL && ctx1->certChain != NULL) {
  80162. ExpectFalse(ssl->buffers.certChain == ctx1->certChain);
  80163. }
  80164. #else
  80165. ExpectTrue(ssl->buffers.certificate == ctx1->certificate);
  80166. ExpectTrue(ssl->buffers.certChain == ctx1->certChain);
  80167. #endif
  80168. #ifdef WOLFSSL_SESSION_ID_CTX
  80169. ExpectIntEQ(XMEMCMP(ssl->sessionCtx, session_id1, 4), 0);
  80170. #endif
  80171. #endif
  80172. wolfSSL_free(ssl);
  80173. wolfSSL_CTX_free(ctx1);
  80174. wolfSSL_CTX_free(ctx2);
  80175. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL) */
  80176. return EXPECT_RESULT();
  80177. }
  80178. #endif /* defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  80179. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  80180. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  80181. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB))) */
  80182. static int test_wolfSSL_security_level(void)
  80183. {
  80184. EXPECT_DECLS;
  80185. #if defined(OPENSSL_EXTRA)
  80186. SSL_CTX *ctx = NULL;
  80187. #ifdef WOLFSSL_TLS13
  80188. #ifdef NO_WOLFSSL_SERVER
  80189. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  80190. #else
  80191. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  80192. #endif
  80193. SSL_CTX_set_security_level(NULL, 1);
  80194. SSL_CTX_set_security_level(ctx, 1);
  80195. ExpectIntEQ(SSL_CTX_get_security_level(NULL), 0);
  80196. /* Stub so nothing happens. */
  80197. ExpectIntEQ(SSL_CTX_get_security_level(ctx), 0);
  80198. SSL_CTX_free(ctx);
  80199. #else
  80200. (void)ctx;
  80201. #endif
  80202. #endif
  80203. return EXPECT_RESULT();
  80204. }
  80205. static int test_wolfSSL_SSL_in_init(void)
  80206. {
  80207. EXPECT_DECLS;
  80208. #if defined(OPENSSL_ALL) && !defined(NO_BIO)
  80209. SSL_CTX* ctx = NULL;
  80210. SSL* ssl = NULL;
  80211. const char* testCertFile;
  80212. const char* testKeyFile;
  80213. #ifdef WOLFSSL_TLS13
  80214. #ifdef NO_WOLFSSL_SERVER
  80215. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  80216. #else
  80217. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  80218. #endif
  80219. #else
  80220. #ifdef NO_WOLFSSL_SERVER
  80221. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  80222. #else
  80223. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  80224. #endif
  80225. #endif
  80226. #ifndef NO_RSA
  80227. testCertFile = svrCertFile;
  80228. testKeyFile = svrKeyFile;
  80229. #elif defined(HAVE_ECC)
  80230. testCertFile = eccCertFile;
  80231. testKeyFile = eccKeyFile;
  80232. #else
  80233. testCertFile = NULL;
  80234. testKeyFile = NULL;
  80235. #endif
  80236. if ((testCertFile != NULL) && (testKeyFile != NULL)) {
  80237. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  80238. SSL_FILETYPE_PEM));
  80239. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  80240. SSL_FILETYPE_PEM));
  80241. }
  80242. ExpectNotNull(ssl = SSL_new(ctx));
  80243. ExpectIntEQ(SSL_in_init(ssl), 1);
  80244. SSL_CTX_free(ctx);
  80245. SSL_free(ssl);
  80246. #endif
  80247. return EXPECT_RESULT();
  80248. }
  80249. static int test_wolfSSL_CTX_set_timeout(void)
  80250. {
  80251. EXPECT_DECLS;
  80252. #if !defined(NO_WOLFSSL_SERVER) && !defined(NO_SESSION_CACHE)
  80253. int timeout;
  80254. WOLFSSL_CTX* ctx = NULL;
  80255. (void)timeout;
  80256. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  80257. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  80258. /* in WOLFSSL_ERROR_CODE_OPENSSL macro guard,
  80259. * wolfSSL_CTX_set_timeout returns previous timeout value on success.
  80260. */
  80261. ExpectIntEQ(wolfSSL_CTX_set_timeout(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  80262. /* giving 0 as timeout value sets default timeout */
  80263. timeout = wolfSSL_CTX_set_timeout(ctx, 0);
  80264. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 20), timeout);
  80265. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 30), 20);
  80266. #else
  80267. ExpectIntEQ(wolfSSL_CTX_set_timeout(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  80268. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 100), 1);
  80269. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 0), 1);
  80270. #endif
  80271. wolfSSL_CTX_free(ctx);
  80272. #endif /* !NO_WOLFSSL_SERVER && !NO_SESSION_CACHE*/
  80273. return EXPECT_RESULT();
  80274. }
  80275. static int test_wolfSSL_OpenSSL_version(void)
  80276. {
  80277. EXPECT_DECLS;
  80278. #if defined(OPENSSL_EXTRA)
  80279. const char* ver;
  80280. #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  80281. ExpectNotNull(ver = OpenSSL_version(0));
  80282. #else
  80283. ExpectNotNull(ver = OpenSSL_version());
  80284. #endif
  80285. ExpectIntEQ(XMEMCMP(ver, "wolfSSL " LIBWOLFSSL_VERSION_STRING,
  80286. XSTRLEN("wolfSSL " LIBWOLFSSL_VERSION_STRING)), 0);
  80287. #endif
  80288. return EXPECT_RESULT();
  80289. }
  80290. static int test_CONF_CTX_CMDLINE(void)
  80291. {
  80292. EXPECT_DECLS;
  80293. #if defined(OPENSSL_ALL)
  80294. SSL_CTX* ctx = NULL;
  80295. SSL_CONF_CTX* cctx = NULL;
  80296. ExpectNotNull(cctx = SSL_CONF_CTX_new());
  80297. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  80298. SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
  80299. /* set flags */
  80300. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CMDLINE),
  80301. WOLFSSL_CONF_FLAG_CMDLINE);
  80302. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CERTIFICATE),
  80303. WOLFSSL_CONF_FLAG_CMDLINE | WOLFSSL_CONF_FLAG_CERTIFICATE);
  80304. /* cmd invalid command */
  80305. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", "foobar"), -2);
  80306. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", NULL), -2);
  80307. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80308. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80309. ExpectIntEQ(SSL_CONF_cmd(NULL, "-curves", "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80310. /* cmd Certificate and Private Key*/
  80311. {
  80312. #if !defined(NO_CERTS) && !defined(NO_RSA)
  80313. const char* ourCert = svrCertFile;
  80314. const char* ourKey = svrKeyFile;
  80315. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cert", NULL), -3);
  80316. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cert", ourCert), WOLFSSL_SUCCESS);
  80317. ExpectIntEQ(SSL_CONF_cmd(cctx, "-key", NULL), -3);
  80318. ExpectIntEQ(SSL_CONF_cmd(cctx, "-key", ourKey), WOLFSSL_SUCCESS);
  80319. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  80320. #endif
  80321. }
  80322. /* cmd curves */
  80323. {
  80324. #if defined(HAVE_ECC)
  80325. const char* curve = "secp256r1";
  80326. ExpectIntEQ(SSL_CONF_cmd(cctx, "-curves", NULL), -3);
  80327. ExpectIntEQ(SSL_CONF_cmd(cctx, "-curves", curve), WOLFSSL_SUCCESS);
  80328. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  80329. #endif
  80330. }
  80331. /* cmd CipherString */
  80332. {
  80333. char* cipher = wolfSSL_get_cipher_list(0/*top priority*/);
  80334. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cipher", NULL), -3);
  80335. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cipher", cipher), WOLFSSL_SUCCESS);
  80336. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  80337. }
  80338. /* cmd DH parameter */
  80339. {
  80340. #if !defined(NO_DH) && !defined(NO_BIO)
  80341. const char* ourdhcert = "./certs/dh2048.pem";
  80342. ExpectIntEQ(SSL_CONF_cmd(cctx, "-dhparam", NULL), -3);
  80343. ExpectIntEQ(SSL_CONF_cmd(cctx, "-dhparam", ourdhcert), WOLFSSL_SUCCESS);
  80344. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  80345. #endif
  80346. }
  80347. SSL_CTX_free(ctx);
  80348. SSL_CONF_CTX_free(cctx);
  80349. #endif /* OPENSSL_EXTRA */
  80350. return EXPECT_RESULT();
  80351. }
  80352. static int test_CONF_CTX_FILE(void)
  80353. {
  80354. EXPECT_DECLS;
  80355. #if defined(OPENSSL_ALL)
  80356. SSL_CTX* ctx = NULL;
  80357. SSL_CONF_CTX* cctx = NULL;
  80358. ExpectNotNull(cctx = SSL_CONF_CTX_new());
  80359. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  80360. SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
  80361. /* set flags */
  80362. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_FILE),
  80363. WOLFSSL_CONF_FLAG_FILE);
  80364. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CERTIFICATE),
  80365. WOLFSSL_CONF_FLAG_FILE | WOLFSSL_CONF_FLAG_CERTIFICATE);
  80366. /* sanity check */
  80367. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", "foobar"), -2);
  80368. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", NULL), -2);
  80369. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80370. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80371. ExpectIntEQ(SSL_CONF_cmd(NULL, "-curves", "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80372. /* cmd Certificate and Private Key*/
  80373. {
  80374. #if !defined(NO_CERTS) && !defined(NO_RSA)
  80375. const char* ourCert = svrCertFile;
  80376. const char* ourKey = svrKeyFile;
  80377. ExpectIntEQ(SSL_CONF_cmd(cctx, "Certificate", NULL), -3);
  80378. ExpectIntEQ(SSL_CONF_cmd(cctx, "PrivateKey", NULL), -3);
  80379. ExpectIntEQ(SSL_CONF_cmd(cctx, "Certificate", ourCert),
  80380. WOLFSSL_SUCCESS);
  80381. ExpectIntEQ(SSL_CONF_cmd(cctx, "PrivateKey", ourKey), WOLFSSL_SUCCESS);
  80382. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  80383. #endif
  80384. }
  80385. /* cmd curves */
  80386. {
  80387. #if defined(HAVE_ECC)
  80388. const char* curve = "secp256r1";
  80389. ExpectIntEQ(SSL_CONF_cmd(cctx, "Curves", NULL), -3);
  80390. ExpectIntEQ(SSL_CONF_cmd(cctx, "Curves", curve), WOLFSSL_SUCCESS);
  80391. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  80392. #endif
  80393. }
  80394. /* cmd CipherString */
  80395. {
  80396. char* cipher = wolfSSL_get_cipher_list(0/*top priority*/);
  80397. ExpectIntEQ(SSL_CONF_cmd(cctx, "CipherString", NULL), -3);
  80398. ExpectIntEQ(SSL_CONF_cmd(cctx, "CipherString", cipher),
  80399. WOLFSSL_SUCCESS);
  80400. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  80401. }
  80402. /* cmd DH parameter */
  80403. {
  80404. #if !defined(NO_DH) && !defined(NO_BIO) && defined(HAVE_FFDHE_3072)
  80405. const char* ourdhcert = "./certs/dh3072.pem";
  80406. ExpectIntEQ(SSL_CONF_cmd(cctx, "DHParameters", NULL), -3);
  80407. ExpectIntEQ(SSL_CONF_cmd(cctx, "DHParameters", ourdhcert),
  80408. WOLFSSL_SUCCESS);
  80409. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  80410. #endif
  80411. }
  80412. SSL_CTX_free(ctx);
  80413. SSL_CONF_CTX_free(cctx);
  80414. #endif /* OPENSSL_EXTRA */
  80415. return EXPECT_RESULT();
  80416. }
  80417. static int test_wolfSSL_CRYPTO_get_ex_new_index(void)
  80418. {
  80419. EXPECT_DECLS;
  80420. #ifdef HAVE_EX_DATA
  80421. int idx1, idx2;
  80422. /* test for unsupported class index */
  80423. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509_STORE,
  80424. 0,NULL, NULL, NULL, NULL ), -1);
  80425. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(
  80426. WOLF_CRYPTO_EX_INDEX_X509_STORE_CTX,
  80427. 0,NULL, NULL, NULL, NULL ), -1);
  80428. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DH,
  80429. 0,NULL, NULL, NULL, NULL ), -1);
  80430. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DSA,
  80431. 0,NULL, NULL, NULL, NULL ), -1);
  80432. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_EC_KEY,
  80433. 0,NULL, NULL, NULL, NULL ), -1);
  80434. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_RSA,
  80435. 0,NULL, NULL, NULL, NULL ), -1);
  80436. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_ENGINE,
  80437. 0,NULL, NULL, NULL, NULL ), -1);
  80438. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_UI,
  80439. 0,NULL, NULL, NULL, NULL ), -1);
  80440. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_BIO,
  80441. 0,NULL, NULL, NULL, NULL ), -1);
  80442. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_APP,
  80443. 0,NULL, NULL, NULL, NULL ), -1);
  80444. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_UI_METHOD,
  80445. 0,NULL, NULL, NULL, NULL ), -1);
  80446. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DRBG,
  80447. 0,NULL, NULL, NULL, NULL ), -1);
  80448. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(20,
  80449. 0,NULL, NULL, NULL, NULL ), -1);
  80450. /* test for supported class index */
  80451. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL,
  80452. 0,NULL, NULL, NULL, NULL );
  80453. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL,
  80454. 0,NULL, NULL, NULL, NULL );
  80455. ExpectIntNE(idx1, -1);
  80456. ExpectIntNE(idx2, -1);
  80457. ExpectIntNE(idx1, idx2);
  80458. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_CTX,
  80459. 0,NULL, NULL, NULL, NULL );
  80460. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_CTX,
  80461. 0,NULL, NULL, NULL, NULL );
  80462. ExpectIntNE(idx1, -1);
  80463. ExpectIntNE(idx2, -1);
  80464. ExpectIntNE(idx1, idx2);
  80465. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509,
  80466. 0,NULL, NULL, NULL, NULL );
  80467. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509,
  80468. 0,NULL, NULL, NULL, NULL );
  80469. ExpectIntNE(idx1, -1);
  80470. ExpectIntNE(idx2, -1);
  80471. ExpectIntNE(idx1, idx2);
  80472. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_SESSION,
  80473. 0,NULL, NULL, NULL, NULL );
  80474. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_SESSION,
  80475. 0,NULL, NULL, NULL, NULL );
  80476. ExpectIntNE(idx1, -1);
  80477. ExpectIntNE(idx2, -1);
  80478. ExpectIntNE(idx1, idx2);
  80479. #endif /* HAVE_EX_DATA */
  80480. return EXPECT_RESULT();
  80481. }
  80482. #if defined(HAVE_EX_DATA) && defined(HAVE_EXT_CACHE) && \
  80483. (defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  80484. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  80485. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  80486. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB))))
  80487. #define SESSION_NEW_IDX_LONG 0xDEADBEEF
  80488. #define SESSION_NEW_IDX_VAL ((void*)0xAEADAEAD)
  80489. #define SESSION_DUP_IDX_VAL ((void*)0xDEDEDEDE)
  80490. #define SESSION_NEW_IDX_PTR "Testing"
  80491. static void test_wolfSSL_SESSION_get_ex_new_index_new_cb(void* p, void* ptr,
  80492. CRYPTO_EX_DATA* a, int idx, long argValue, void* arg)
  80493. {
  80494. AssertNotNull(p);
  80495. AssertNull(ptr);
  80496. AssertIntEQ(CRYPTO_set_ex_data(a, idx, SESSION_NEW_IDX_VAL), SSL_SUCCESS);
  80497. AssertIntEQ(argValue, SESSION_NEW_IDX_LONG);
  80498. AssertStrEQ(arg, SESSION_NEW_IDX_PTR);
  80499. }
  80500. static int test_wolfSSL_SESSION_get_ex_new_index_dup_cb(CRYPTO_EX_DATA* out,
  80501. const CRYPTO_EX_DATA* in, void* inPtr, int idx, long argV,
  80502. void* arg)
  80503. {
  80504. EXPECT_DECLS;
  80505. ExpectNotNull(out);
  80506. ExpectNotNull(in);
  80507. ExpectPtrEq(*(void**)inPtr, SESSION_NEW_IDX_VAL);
  80508. ExpectPtrEq(CRYPTO_get_ex_data(in, idx), SESSION_NEW_IDX_VAL);
  80509. ExpectPtrEq(CRYPTO_get_ex_data(out, idx), SESSION_NEW_IDX_VAL);
  80510. ExpectIntEQ(argV, SESSION_NEW_IDX_LONG);
  80511. ExpectStrEQ(arg, SESSION_NEW_IDX_PTR);
  80512. *(void**)inPtr = SESSION_DUP_IDX_VAL;
  80513. if (EXPECT_SUCCESS()) {
  80514. return SSL_SUCCESS;
  80515. }
  80516. else {
  80517. return SSL_FAILURE;
  80518. }
  80519. }
  80520. static int test_wolfSSL_SESSION_get_ex_new_index_free_cb_called = 0;
  80521. static void test_wolfSSL_SESSION_get_ex_new_index_free_cb(void* p, void* ptr,
  80522. CRYPTO_EX_DATA* a, int idx, long argValue, void* arg)
  80523. {
  80524. EXPECT_DECLS;
  80525. ExpectNotNull(p);
  80526. ExpectNull(ptr);
  80527. ExpectPtrNE(CRYPTO_get_ex_data(a, idx), 0);
  80528. ExpectIntEQ(argValue, SESSION_NEW_IDX_LONG);
  80529. ExpectStrEQ(arg, SESSION_NEW_IDX_PTR);
  80530. if (EXPECT_SUCCESS()) {
  80531. test_wolfSSL_SESSION_get_ex_new_index_free_cb_called++;
  80532. }
  80533. }
  80534. static int test_wolfSSL_SESSION_get_ex_new_index(void)
  80535. {
  80536. EXPECT_DECLS;
  80537. int idx = SSL_SESSION_get_ex_new_index(SESSION_NEW_IDX_LONG,
  80538. (void*)SESSION_NEW_IDX_PTR,
  80539. test_wolfSSL_SESSION_get_ex_new_index_new_cb,
  80540. test_wolfSSL_SESSION_get_ex_new_index_dup_cb,
  80541. test_wolfSSL_SESSION_get_ex_new_index_free_cb);
  80542. SSL_SESSION* s = SSL_SESSION_new();
  80543. SSL_SESSION* d = NULL;
  80544. ExpectNotNull(s);
  80545. ExpectPtrEq(SSL_SESSION_get_ex_data(s, idx), SESSION_NEW_IDX_VAL);
  80546. ExpectNotNull(d = SSL_SESSION_dup(s));
  80547. ExpectPtrEq(SSL_SESSION_get_ex_data(d, idx), SESSION_DUP_IDX_VAL);
  80548. SSL_SESSION_free(s);
  80549. ExpectIntEQ(test_wolfSSL_SESSION_get_ex_new_index_free_cb_called, 1);
  80550. SSL_SESSION_free(d);
  80551. ExpectIntEQ(test_wolfSSL_SESSION_get_ex_new_index_free_cb_called, 2);
  80552. crypto_ex_cb_free(crypto_ex_cb_ctx_session);
  80553. crypto_ex_cb_ctx_session = NULL;
  80554. return EXPECT_RESULT();
  80555. }
  80556. #else
  80557. static int test_wolfSSL_SESSION_get_ex_new_index(void)
  80558. {
  80559. return TEST_SKIPPED;
  80560. }
  80561. #endif
  80562. static int test_wolfSSL_set_psk_use_session_callback(void)
  80563. {
  80564. EXPECT_DECLS;
  80565. #if defined(OPENSSL_EXTRA) && !defined(NO_PSK)
  80566. SSL_CTX* ctx = NULL;
  80567. SSL* ssl = NULL;
  80568. const char* testCertFile;
  80569. const char* testKeyFile;
  80570. #ifdef WOLFSSL_TLS13
  80571. #ifdef NO_WOLFSSL_SERVER
  80572. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  80573. #else
  80574. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  80575. #endif
  80576. #else
  80577. #ifdef NO_WOLFSSL_SERVER
  80578. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  80579. #else
  80580. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  80581. #endif
  80582. #endif
  80583. #ifndef NO_RSA
  80584. testCertFile = svrCertFile;
  80585. testKeyFile = svrKeyFile;
  80586. #elif defined(HAVE_ECC)
  80587. testCertFile = eccCertFile;
  80588. testKeyFile = eccKeyFile;
  80589. #else
  80590. testCertFile = NULL;
  80591. testKeyFile = NULL;
  80592. #endif
  80593. if ((testCertFile != NULL) && (testKeyFile != NULL)) {
  80594. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  80595. SSL_FILETYPE_PEM));
  80596. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  80597. SSL_FILETYPE_PEM));
  80598. }
  80599. ExpectNotNull(ssl = SSL_new(ctx));
  80600. SSL_set_psk_use_session_callback(ssl, my_psk_use_session_cb);
  80601. SSL_CTX_free(ctx);
  80602. SSL_free(ssl);
  80603. #endif
  80604. return EXPECT_RESULT();
  80605. }
  80606. /* similar to error_test() in wolfcrypt/test/test.c, but adding error codes from
  80607. * TLS layer.
  80608. */
  80609. static int error_test(void)
  80610. {
  80611. EXPECT_DECLS;
  80612. const char* errStr;
  80613. const char* unknownStr = wc_GetErrorString(0);
  80614. #ifdef NO_ERROR_STRINGS
  80615. /* Ensure a valid error code's string matches an invalid code's.
  80616. * The string is that error strings are not available.
  80617. */
  80618. errStr = wc_GetErrorString(OPEN_RAN_E);
  80619. ExpectIntEQ(XSTRCMP(errStr, unknownStr), 0);
  80620. if (EXPECT_FAIL())
  80621. return OPEN_RAN_E;
  80622. #else
  80623. int i;
  80624. int j = 0;
  80625. /* Values that are not or no longer error codes. */
  80626. static const struct {
  80627. int first;
  80628. int last;
  80629. } missing[] = {
  80630. #ifndef OPENSSL_EXTRA
  80631. { 0, 0 },
  80632. #endif
  80633. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  80634. defined(HAVE_WEBSERVER) || defined(HAVE_MEMCACHED)
  80635. { -11, -12 },
  80636. { -15, -17 },
  80637. { -19, -19 },
  80638. { -26, -27 },
  80639. { -30, WC_FIRST_E+1 },
  80640. #else
  80641. { -9, WC_FIRST_E+1 },
  80642. #endif
  80643. { -124, -124 },
  80644. { -166, -169 },
  80645. { -300, -300 },
  80646. { -334, -336 },
  80647. { -346, -349 },
  80648. { -356, -356 },
  80649. { -358, -358 },
  80650. { -372, -372 },
  80651. { -384, -384 },
  80652. { -466, -499 },
  80653. { WOLFSSL_LAST_E-1, WOLFSSL_LAST_E-1 }
  80654. };
  80655. /* Check that all errors have a string and it's the same through the two
  80656. * APIs. Check that the values that are not errors map to the unknown
  80657. * string.
  80658. */
  80659. for (i = 0; i >= WOLFSSL_LAST_E-1; i--) {
  80660. int this_missing = 0;
  80661. for (j = 0; j < (int)XELEM_CNT(missing); ++j) {
  80662. if ((i <= missing[j].first) && (i >= missing[j].last)) {
  80663. this_missing = 1;
  80664. break;
  80665. }
  80666. }
  80667. errStr = wolfSSL_ERR_reason_error_string((word32)i);
  80668. if (! this_missing) {
  80669. ExpectIntNE(XSTRCMP(errStr, unknownStr), 0);
  80670. if (EXPECT_FAIL()) {
  80671. return i;
  80672. }
  80673. ExpectTrue(XSTRLEN(errStr) < WOLFSSL_MAX_ERROR_SZ);
  80674. if (EXPECT_FAIL()) {
  80675. return i;
  80676. }
  80677. }
  80678. else {
  80679. j++;
  80680. ExpectIntEQ(XSTRCMP(errStr, unknownStr), 0);
  80681. if (EXPECT_FAIL()) {
  80682. return i;
  80683. }
  80684. }
  80685. }
  80686. #endif
  80687. return 1;
  80688. }
  80689. static int test_wolfSSL_ERR_strings(void)
  80690. {
  80691. EXPECT_DECLS;
  80692. #if !defined(NO_ERROR_STRINGS)
  80693. const char* err1 = "unsupported cipher suite";
  80694. const char* err2 = "wolfSSL PEM routines";
  80695. const char* err = NULL;
  80696. (void)err;
  80697. (void)err1;
  80698. (void)err2;
  80699. #if defined(OPENSSL_EXTRA)
  80700. ExpectNotNull(err = ERR_reason_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  80701. ExpectIntEQ(XSTRNCMP(err, err1, XSTRLEN(err1)), 0);
  80702. ExpectNotNull(err = ERR_func_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  80703. ExpectIntEQ((*err == '\0'), 1);
  80704. ExpectNotNull(err = ERR_lib_error_string(PEM_R_PROBLEMS_GETTING_PASSWORD));
  80705. ExpectIntEQ(XSTRNCMP(err, err2, XSTRLEN(err2)), 0);
  80706. #else
  80707. ExpectNotNull(err = wolfSSL_ERR_reason_error_string(WC_NO_ERR_TRACE((word32)UNSUPPORTED_SUITE)));
  80708. ExpectIntEQ(XSTRNCMP(err, err1, XSTRLEN(err1)), 0);
  80709. ExpectNotNull(err = wolfSSL_ERR_func_error_string(WC_NO_ERR_TRACE((word32)UNSUPPORTED_SUITE)));
  80710. ExpectIntEQ((*err == '\0'), 1);
  80711. /* The value -MIN_CODE_E+2 is PEM_R_PROBLEMS_GETTING_PASSWORD. */
  80712. ExpectNotNull(err = wolfSSL_ERR_lib_error_string(-MIN_CODE_E+2));
  80713. ExpectIntEQ((*err == '\0'), 1);
  80714. #endif
  80715. #endif
  80716. ExpectIntEQ(error_test(), 1);
  80717. return EXPECT_RESULT();
  80718. }
  80719. static int test_wolfSSL_EVP_shake128(void)
  80720. {
  80721. EXPECT_DECLS;
  80722. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA3) && \
  80723. defined(WOLFSSL_SHAKE128)
  80724. const EVP_MD* md = NULL;
  80725. ExpectNotNull(md = EVP_shake128());
  80726. ExpectIntEQ(XSTRNCMP(md, "SHAKE128", XSTRLEN("SHAKE128")), 0);
  80727. #endif
  80728. return EXPECT_RESULT();
  80729. }
  80730. static int test_wolfSSL_EVP_shake256(void)
  80731. {
  80732. EXPECT_DECLS;
  80733. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA3) && \
  80734. defined(WOLFSSL_SHAKE256)
  80735. const EVP_MD* md = NULL;
  80736. ExpectNotNull(md = EVP_shake256());
  80737. ExpectIntEQ(XSTRNCMP(md, "SHAKE256", XSTRLEN("SHAKE256")), 0);
  80738. #endif
  80739. return EXPECT_RESULT();
  80740. }
  80741. /*
  80742. * Testing EVP digest API with SM3
  80743. */
  80744. static int test_wolfSSL_EVP_sm3(void)
  80745. {
  80746. int res = TEST_SKIPPED;
  80747. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM3)
  80748. EXPECT_DECLS;
  80749. const EVP_MD* md = NULL;
  80750. EVP_MD_CTX* mdCtx = NULL;
  80751. byte data[WC_SM3_BLOCK_SIZE * 4];
  80752. byte hash[WC_SM3_DIGEST_SIZE];
  80753. byte calcHash[WC_SM3_DIGEST_SIZE];
  80754. byte expHash[WC_SM3_DIGEST_SIZE] = {
  80755. 0x38, 0x48, 0x15, 0xa7, 0x0e, 0xae, 0x0b, 0x27,
  80756. 0x5c, 0xde, 0x9d, 0xa5, 0xd1, 0xa4, 0x30, 0xa1,
  80757. 0xca, 0xd4, 0x54, 0x58, 0x44, 0xa2, 0x96, 0x1b,
  80758. 0xd7, 0x14, 0x80, 0x3f, 0x80, 0x1a, 0x07, 0xb6
  80759. };
  80760. word32 chunk;
  80761. word32 i;
  80762. unsigned int sz;
  80763. int ret;
  80764. XMEMSET(data, 0, sizeof(data));
  80765. md = EVP_sm3();
  80766. ExpectTrue(md != NULL);
  80767. ExpectIntEQ(XSTRNCMP(md, "SM3", XSTRLEN("SM3")), 0);
  80768. mdCtx = EVP_MD_CTX_new();
  80769. ExpectTrue(mdCtx != NULL);
  80770. /* Invalid Parameters */
  80771. ExpectIntEQ(EVP_DigestInit(NULL, md), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80772. /* Valid Parameters */
  80773. ExpectIntEQ(EVP_DigestInit(mdCtx, md), WOLFSSL_SUCCESS);
  80774. ExpectIntEQ(EVP_DigestUpdate(NULL, NULL, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80775. ExpectIntEQ(EVP_DigestUpdate(mdCtx, NULL, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80776. ExpectIntEQ(EVP_DigestUpdate(NULL, data, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80777. /* Valid Parameters */
  80778. ExpectIntEQ(EVP_DigestUpdate(mdCtx, NULL, 0), WOLFSSL_SUCCESS);
  80779. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, 1), WOLFSSL_SUCCESS);
  80780. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, 1), WOLFSSL_SUCCESS);
  80781. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE),
  80782. WOLFSSL_SUCCESS);
  80783. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE - 2),
  80784. WOLFSSL_SUCCESS);
  80785. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE * 2),
  80786. WOLFSSL_SUCCESS);
  80787. /* Ensure too many bytes for lengths. */
  80788. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_PAD_SIZE),
  80789. WOLFSSL_SUCCESS);
  80790. /* Invalid Parameters */
  80791. ExpectIntEQ(EVP_DigestFinal(NULL, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80792. ExpectIntEQ(EVP_DigestFinal(mdCtx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80793. ExpectIntEQ(EVP_DigestFinal(NULL, hash, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80794. ExpectIntEQ(EVP_DigestFinal(NULL, hash, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80795. ExpectIntEQ(EVP_DigestFinal(mdCtx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80796. /* Valid Parameters */
  80797. ExpectIntEQ(EVP_DigestFinal(mdCtx, hash, NULL), WOLFSSL_SUCCESS);
  80798. ExpectBufEQ(hash, expHash, WC_SM3_DIGEST_SIZE);
  80799. /* Chunk tests. */
  80800. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, sizeof(data)), WOLFSSL_SUCCESS);
  80801. ExpectIntEQ(EVP_DigestFinal(mdCtx, calcHash, &sz), WOLFSSL_SUCCESS);
  80802. ExpectIntEQ(sz, WC_SM3_DIGEST_SIZE);
  80803. for (chunk = 1; chunk <= WC_SM3_BLOCK_SIZE + 1; chunk++) {
  80804. for (i = 0; i + chunk <= (word32)sizeof(data); i += chunk) {
  80805. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data + i, chunk),
  80806. WOLFSSL_SUCCESS);
  80807. }
  80808. if (i < (word32)sizeof(data)) {
  80809. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data + i,
  80810. (word32)sizeof(data) - i), WOLFSSL_SUCCESS);
  80811. }
  80812. ExpectIntEQ(EVP_DigestFinal(mdCtx, hash, NULL), WOLFSSL_SUCCESS);
  80813. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  80814. }
  80815. /* Not testing when the low 32-bit length overflows. */
  80816. ret = EVP_MD_CTX_cleanup(mdCtx);
  80817. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  80818. wolfSSL_EVP_MD_CTX_free(mdCtx);
  80819. res = EXPECT_RESULT();
  80820. #endif
  80821. return res;
  80822. } /* END test_EVP_sm3 */
  80823. static int test_EVP_blake2(void)
  80824. {
  80825. EXPECT_DECLS;
  80826. #if defined(OPENSSL_EXTRA) && (defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S))
  80827. const EVP_MD* md = NULL;
  80828. (void)md;
  80829. #if defined(HAVE_BLAKE2)
  80830. ExpectNotNull(md = EVP_blake2b512());
  80831. ExpectIntEQ(XSTRNCMP(md, "BLAKE2B512", XSTRLEN("BLAKE2B512")), 0);
  80832. #endif
  80833. #if defined(HAVE_BLAKE2S)
  80834. ExpectNotNull(md = EVP_blake2s256());
  80835. ExpectIntEQ(XSTRNCMP(md, "BLAKE2S256", XSTRLEN("BLAKE2S256")), 0);
  80836. #endif
  80837. #endif
  80838. return EXPECT_RESULT();
  80839. }
  80840. #if defined(OPENSSL_EXTRA)
  80841. static void list_md_fn(const EVP_MD* m, const char* from,
  80842. const char* to, void* arg)
  80843. {
  80844. const char* mn;
  80845. BIO *bio;
  80846. (void) from;
  80847. (void) to;
  80848. (void) arg;
  80849. (void) mn;
  80850. (void) bio;
  80851. if (!m) {
  80852. /* alias */
  80853. AssertNull(m);
  80854. AssertNotNull(to);
  80855. }
  80856. else {
  80857. AssertNotNull(m);
  80858. AssertNull(to);
  80859. }
  80860. AssertNotNull(from);
  80861. #if !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL_VERBOSE)
  80862. mn = EVP_get_digestbyname(from);
  80863. /* print to stderr */
  80864. AssertNotNull(arg);
  80865. bio = BIO_new(BIO_s_file());
  80866. BIO_set_fp(bio, arg, BIO_NOCLOSE);
  80867. BIO_printf(bio, "Use %s message digest algorithm\n", mn);
  80868. BIO_free(bio);
  80869. #endif
  80870. }
  80871. #endif
  80872. static int test_EVP_MD_do_all(void)
  80873. {
  80874. int res = TEST_SKIPPED;
  80875. #if defined(OPENSSL_EXTRA)
  80876. EVP_MD_do_all(NULL, stderr);
  80877. EVP_MD_do_all(list_md_fn, stderr);
  80878. res = TEST_SUCCESS;
  80879. #endif
  80880. return res;
  80881. }
  80882. #if defined(OPENSSL_EXTRA)
  80883. static void obj_name_t(const OBJ_NAME* nm, void* arg)
  80884. {
  80885. (void)arg;
  80886. (void)nm;
  80887. AssertIntGT(nm->type, OBJ_NAME_TYPE_UNDEF);
  80888. #if !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL_VERBOSE)
  80889. /* print to stderr */
  80890. AssertNotNull(arg);
  80891. BIO *bio = BIO_new(BIO_s_file());
  80892. BIO_set_fp(bio, arg, BIO_NOCLOSE);
  80893. BIO_printf(bio, "%s\n", nm);
  80894. BIO_free(bio);
  80895. #endif
  80896. }
  80897. #endif
  80898. static int test_OBJ_NAME_do_all(void)
  80899. {
  80900. int res = TEST_SKIPPED;
  80901. #if defined(OPENSSL_EXTRA)
  80902. OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, NULL, NULL);
  80903. OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH, NULL, stderr);
  80904. OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, obj_name_t, stderr);
  80905. OBJ_NAME_do_all(OBJ_NAME_TYPE_PKEY_METH, obj_name_t, stderr);
  80906. OBJ_NAME_do_all(OBJ_NAME_TYPE_COMP_METH, obj_name_t, stderr);
  80907. OBJ_NAME_do_all(OBJ_NAME_TYPE_NUM, obj_name_t, stderr);
  80908. OBJ_NAME_do_all(OBJ_NAME_TYPE_UNDEF, obj_name_t, stderr);
  80909. OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH, obj_name_t, stderr);
  80910. OBJ_NAME_do_all(-1, obj_name_t, stderr);
  80911. res = TEST_SUCCESS;
  80912. #endif
  80913. return res;
  80914. }
  80915. static int test_SSL_CIPHER_get_xxx(void)
  80916. {
  80917. EXPECT_DECLS;
  80918. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  80919. !defined(NO_FILESYSTEM)
  80920. const SSL_CIPHER* cipher = NULL;
  80921. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  80922. int i, numCiphers = 0;
  80923. SSL_CTX* ctx = NULL;
  80924. SSL* ssl = NULL;
  80925. const char* testCertFile;
  80926. const char* testKeyFile;
  80927. char buf[256] = {0};
  80928. const char* cipher_id = NULL;
  80929. int expect_nid1 = NID_undef;
  80930. int expect_nid2 = NID_undef;
  80931. int expect_nid3 = NID_undef;
  80932. int expect_nid4 = NID_undef;
  80933. int expect_nid5 = 0;
  80934. const char* cipher_id2 = NULL;
  80935. int expect_nid21 = NID_undef;
  80936. int expect_nid22 = NID_undef;
  80937. int expect_nid23 = NID_undef;
  80938. int expect_nid24 = NID_undef;
  80939. int expect_nid25 = 0;
  80940. (void)cipher;
  80941. (void)supportedCiphers;
  80942. (void)i;
  80943. (void)numCiphers;
  80944. (void)ctx;
  80945. (void)ssl;
  80946. (void)testCertFile;
  80947. (void)testKeyFile;
  80948. #if defined(WOLFSSL_TLS13)
  80949. cipher_id = "TLS13-AES128-GCM-SHA256";
  80950. expect_nid1 = NID_auth_rsa;
  80951. expect_nid2 = NID_aes_128_gcm;
  80952. expect_nid3 = NID_sha256;
  80953. expect_nid4 = NID_kx_any;
  80954. expect_nid5 = 1;
  80955. #if !defined(WOLFSSL_NO_TLS12)
  80956. cipher_id2 = "ECDHE-RSA-AES256-GCM-SHA384";
  80957. expect_nid21 = NID_auth_rsa;
  80958. expect_nid22 = NID_aes_256_gcm;
  80959. expect_nid23 = NID_sha384;
  80960. expect_nid24 = NID_kx_ecdhe;
  80961. expect_nid25 = 1;
  80962. #endif
  80963. #endif
  80964. #ifdef NO_WOLFSSL_SERVER
  80965. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  80966. #else
  80967. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  80968. #endif
  80969. if (cipher_id) {
  80970. #ifndef NO_RSA
  80971. testCertFile = svrCertFile;
  80972. testKeyFile = svrKeyFile;
  80973. #elif defined(HAVE_ECC)
  80974. testCertFile = eccCertFile;
  80975. testKeyFile = eccKeyFile;
  80976. #else
  80977. testCertFile = NULL;
  80978. testKeyFile = NULL;
  80979. #endif
  80980. if (testCertFile != NULL && testKeyFile != NULL) {
  80981. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  80982. SSL_FILETYPE_PEM));
  80983. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  80984. SSL_FILETYPE_PEM));
  80985. }
  80986. ExpectNotNull(ssl = SSL_new(ctx));
  80987. ExpectIntEQ(SSL_in_init(ssl), 1);
  80988. supportedCiphers = SSL_get_ciphers(ssl);
  80989. numCiphers = sk_num(supportedCiphers);
  80990. for (i = 0; i < numCiphers; ++i) {
  80991. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  80992. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  80993. }
  80994. if (XMEMCMP(cipher_id, buf, XSTRLEN(cipher_id)) == 0) {
  80995. break;
  80996. }
  80997. }
  80998. /* test case for */
  80999. if (i != numCiphers) {
  81000. ExpectIntEQ(wolfSSL_CIPHER_get_auth_nid(cipher), expect_nid1);
  81001. ExpectIntEQ(wolfSSL_CIPHER_get_cipher_nid(cipher), expect_nid2);
  81002. ExpectIntEQ(wolfSSL_CIPHER_get_digest_nid(cipher), expect_nid3);
  81003. ExpectIntEQ(wolfSSL_CIPHER_get_kx_nid(cipher), expect_nid4);
  81004. ExpectIntEQ(wolfSSL_CIPHER_is_aead(cipher), expect_nid5);
  81005. }
  81006. if (cipher_id2) {
  81007. for (i = 0; i < numCiphers; ++i) {
  81008. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  81009. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  81010. }
  81011. if (XMEMCMP(cipher_id2, buf, XSTRLEN(cipher_id2)) == 0) {
  81012. break;
  81013. }
  81014. }
  81015. /* test case for */
  81016. if (i != numCiphers) {
  81017. ExpectIntEQ(wolfSSL_CIPHER_get_auth_nid(cipher), expect_nid21);
  81018. ExpectIntEQ(wolfSSL_CIPHER_get_cipher_nid(cipher), expect_nid22);
  81019. ExpectIntEQ(wolfSSL_CIPHER_get_digest_nid(cipher), expect_nid23);
  81020. ExpectIntEQ(wolfSSL_CIPHER_get_kx_nid(cipher), expect_nid24);
  81021. ExpectIntEQ(wolfSSL_CIPHER_is_aead(cipher), expect_nid25);
  81022. }
  81023. }
  81024. }
  81025. SSL_CTX_free(ctx);
  81026. SSL_free(ssl);
  81027. #endif
  81028. return EXPECT_RESULT();
  81029. }
  81030. #if defined(WOLF_CRYPTO_CB) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  81031. static int load_pem_key_file_as_der(const char* privKeyFile, DerBuffer** pDer,
  81032. int* keyFormat)
  81033. {
  81034. int ret;
  81035. byte* key_buf = NULL;
  81036. size_t key_sz = 0;
  81037. EncryptedInfo encInfo;
  81038. XMEMSET(&encInfo, 0, sizeof(encInfo));
  81039. ret = load_file(privKeyFile, &key_buf, &key_sz);
  81040. if (ret == 0) {
  81041. ret = wc_PemToDer(key_buf, key_sz, PRIVATEKEY_TYPE, pDer,
  81042. NULL, &encInfo, keyFormat);
  81043. }
  81044. if (key_buf != NULL) {
  81045. free(key_buf); key_buf = NULL;
  81046. }
  81047. (void)encInfo; /* not used in this test */
  81048. #ifdef DEBUG_WOLFSSL
  81049. fprintf(stderr, "%s (%d): Loading PEM %s (len %d) to DER (len %d)\n",
  81050. (ret == 0) ? "Success" : "Failure", ret, privKeyFile, (int)key_sz,
  81051. (*pDer)->length);
  81052. #endif
  81053. return ret;
  81054. }
  81055. static int test_CryptoCb_Func(int thisDevId, wc_CryptoInfo* info, void* ctx)
  81056. {
  81057. int ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
  81058. const char* privKeyFile = (const char*)ctx;
  81059. DerBuffer* pDer = NULL;
  81060. int keyFormat = 0;
  81061. if (info->algo_type == WC_ALGO_TYPE_PK) {
  81062. #ifdef DEBUG_WOLFSSL
  81063. fprintf(stderr, "test_CryptoCb_Func: Pk Type %d\n", info->pk.type);
  81064. #endif
  81065. #ifndef NO_RSA
  81066. if (info->pk.type == WC_PK_TYPE_RSA) {
  81067. switch (info->pk.rsa.type) {
  81068. case RSA_PUBLIC_ENCRYPT:
  81069. case RSA_PUBLIC_DECRYPT:
  81070. /* perform software based RSA public op */
  81071. ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE); /* fallback to software */
  81072. break;
  81073. case RSA_PRIVATE_ENCRYPT:
  81074. case RSA_PRIVATE_DECRYPT:
  81075. {
  81076. RsaKey key;
  81077. /* perform software based RSA private op */
  81078. #ifdef DEBUG_WOLFSSL
  81079. fprintf(stderr, "test_CryptoCb_Func: RSA Priv\n");
  81080. #endif
  81081. ret = load_pem_key_file_as_der(privKeyFile, &pDer,
  81082. &keyFormat);
  81083. if (ret != 0) {
  81084. return ret;
  81085. }
  81086. ret = wc_InitRsaKey(&key, HEAP_HINT);
  81087. if (ret == 0) {
  81088. word32 keyIdx = 0;
  81089. /* load RSA private key and perform private transform */
  81090. ret = wc_RsaPrivateKeyDecode(pDer->buffer, &keyIdx,
  81091. &key, pDer->length);
  81092. if (ret == 0) {
  81093. ret = wc_RsaFunction(
  81094. info->pk.rsa.in, info->pk.rsa.inLen,
  81095. info->pk.rsa.out, info->pk.rsa.outLen,
  81096. info->pk.rsa.type, &key, info->pk.rsa.rng);
  81097. }
  81098. else {
  81099. /* if decode fails, then fall-back to software based crypto */
  81100. fprintf(stderr, "test_CryptoCb_Func: RSA private "
  81101. "key decode failed %d, falling back to "
  81102. "software\n", ret);
  81103. ret = CRYPTOCB_UNAVAILABLE;
  81104. }
  81105. wc_FreeRsaKey(&key);
  81106. }
  81107. wc_FreeDer(&pDer); pDer = NULL;
  81108. break;
  81109. }
  81110. }
  81111. #ifdef DEBUG_WOLFSSL
  81112. fprintf(stderr, "test_CryptoCb_Func: RSA Type %d, Ret %d, Out %d\n",
  81113. info->pk.rsa.type, ret, *info->pk.rsa.outLen);
  81114. #endif
  81115. }
  81116. #ifdef WOLF_CRYPTO_CB_RSA_PAD
  81117. else if (info->pk.type == WC_PK_TYPE_RSA_PKCS ||
  81118. info->pk.type == WC_PK_TYPE_RSA_PSS ||
  81119. info->pk.type == WC_PK_TYPE_RSA_OAEP) {
  81120. RsaKey key;
  81121. if (info->pk.rsa.type == RSA_PUBLIC_ENCRYPT ||
  81122. info->pk.rsa.type == RSA_PUBLIC_DECRYPT) {
  81123. /* Have all public key ops fall back to SW */
  81124. return CRYPTOCB_UNAVAILABLE;
  81125. }
  81126. if (info->pk.rsa.padding == NULL) {
  81127. return BAD_FUNC_ARG;
  81128. }
  81129. /* Initialize key */
  81130. ret = load_pem_key_file_as_der(privKeyFile, &pDer,
  81131. &keyFormat);
  81132. if (ret != 0) {
  81133. return ret;
  81134. }
  81135. ret = wc_InitRsaKey(&key, HEAP_HINT);
  81136. if (ret == 0) {
  81137. word32 keyIdx = 0;
  81138. /* load RSA private key and perform private transform */
  81139. ret = wc_RsaPrivateKeyDecode(pDer->buffer, &keyIdx,
  81140. &key, pDer->length);
  81141. }
  81142. /* Perform RSA operation */
  81143. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_PKCS)) {
  81144. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  81145. ret = wc_RsaSSL_Sign(info->pk.rsa.in, info->pk.rsa.inLen,
  81146. info->pk.rsa.out, *info->pk.rsa.outLen, &key,
  81147. info->pk.rsa.rng);
  81148. #else
  81149. ret = CRYPTOCB_UNAVAILABLE;
  81150. #endif
  81151. }
  81152. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_PSS)) {
  81153. #ifdef WC_RSA_PSS
  81154. ret = wc_RsaPSS_Sign_ex(info->pk.rsa.in, info->pk.rsa.inLen,
  81155. info->pk.rsa.out, *info->pk.rsa.outLen,
  81156. info->pk.rsa.padding->hash, info->pk.rsa.padding->mgf,
  81157. info->pk.rsa.padding->saltLen, &key, info->pk.rsa.rng);
  81158. #else
  81159. ret = CRYPTOCB_UNAVAILABLE;
  81160. #endif
  81161. }
  81162. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_OAEP)) {
  81163. #if !defined(WC_NO_RSA_OAEP) || defined(WC_RSA_NO_PADDING)
  81164. ret = wc_RsaPrivateDecrypt_ex(
  81165. info->pk.rsa.in, info->pk.rsa.inLen,
  81166. info->pk.rsa.out, *info->pk.rsa.outLen,
  81167. &key, WC_RSA_OAEP_PAD, info->pk.rsa.padding->hash,
  81168. info->pk.rsa.padding->mgf, info->pk.rsa.padding->label,
  81169. info->pk.rsa.padding->labelSz);
  81170. #else
  81171. ret = CRYPTOCB_UNAVAILABLE;
  81172. #endif
  81173. }
  81174. if (ret > 0) {
  81175. *info->pk.rsa.outLen = ret;
  81176. }
  81177. wc_FreeRsaKey(&key);
  81178. wc_FreeDer(&pDer); pDer = NULL;
  81179. }
  81180. #endif /* ifdef WOLF_CRYPTO_CB_RSA_PAD */
  81181. #endif /* !NO_RSA */
  81182. #ifdef HAVE_ECC
  81183. if (info->pk.type == WC_PK_TYPE_EC_KEYGEN) {
  81184. /* mark this key as ephemeral */
  81185. if (info->pk.eckg.key != NULL) {
  81186. XSTRNCPY(info->pk.eckg.key->label, "ephemeral",
  81187. sizeof(info->pk.eckg.key->label));
  81188. info->pk.eckg.key->labelLen = (int)XSTRLEN(info->pk.eckg.key->label);
  81189. }
  81190. }
  81191. else if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
  81192. ecc_key key;
  81193. /* perform software based ECC sign */
  81194. #ifdef DEBUG_WOLFSSL
  81195. fprintf(stderr, "test_CryptoCb_Func: ECC Sign\n");
  81196. #endif
  81197. if (info->pk.eccsign.key != NULL &&
  81198. XSTRCMP(info->pk.eccsign.key->label, "ephemeral") == 0) {
  81199. /* this is an empheral key */
  81200. #ifdef DEBUG_WOLFSSL
  81201. fprintf(stderr, "test_CryptoCb_Func: skipping signing op on "
  81202. "ephemeral key\n");
  81203. #endif
  81204. return CRYPTOCB_UNAVAILABLE;
  81205. }
  81206. ret = load_pem_key_file_as_der(privKeyFile, &pDer, &keyFormat);
  81207. if (ret != 0) {
  81208. return ret;
  81209. }
  81210. ret = wc_ecc_init(&key);
  81211. if (ret == 0) {
  81212. word32 keyIdx = 0;
  81213. /* load ECC private key and perform private transform */
  81214. ret = wc_EccPrivateKeyDecode(pDer->buffer, &keyIdx,
  81215. &key, pDer->length);
  81216. if (ret == 0) {
  81217. ret = wc_ecc_sign_hash(
  81218. info->pk.eccsign.in, info->pk.eccsign.inlen,
  81219. info->pk.eccsign.out, info->pk.eccsign.outlen,
  81220. info->pk.eccsign.rng, &key);
  81221. }
  81222. else {
  81223. /* if decode fails, then fall-back to software based crypto */
  81224. fprintf(stderr, "test_CryptoCb_Func: ECC private key "
  81225. "decode failed %d, falling back to software\n", ret);
  81226. ret = CRYPTOCB_UNAVAILABLE;
  81227. }
  81228. wc_ecc_free(&key);
  81229. }
  81230. wc_FreeDer(&pDer); pDer = NULL;
  81231. #ifdef DEBUG_WOLFSSL
  81232. fprintf(stderr, "test_CryptoCb_Func: ECC Ret %d, Out %d\n",
  81233. ret, *info->pk.eccsign.outlen);
  81234. #endif
  81235. }
  81236. #endif /* HAVE_ECC */
  81237. #ifdef HAVE_ED25519
  81238. if (info->pk.type == WC_PK_TYPE_ED25519_SIGN) {
  81239. ed25519_key key;
  81240. /* perform software based ED25519 sign */
  81241. #ifdef DEBUG_WOLFSSL
  81242. fprintf(stderr, "test_CryptoCb_Func: ED25519 Sign\n");
  81243. #endif
  81244. ret = load_pem_key_file_as_der(privKeyFile, &pDer, &keyFormat);
  81245. if (ret != 0) {
  81246. return ret;
  81247. }
  81248. ret = wc_ed25519_init(&key);
  81249. if (ret == 0) {
  81250. word32 keyIdx = 0;
  81251. /* load ED25519 private key and perform private transform */
  81252. ret = wc_Ed25519PrivateKeyDecode(pDer->buffer, &keyIdx,
  81253. &key, pDer->length);
  81254. if (ret == 0) {
  81255. /* calculate public key */
  81256. ret = wc_ed25519_make_public(&key, key.p, ED25519_PUB_KEY_SIZE);
  81257. if (ret == 0) {
  81258. key.pubKeySet = 1;
  81259. ret = wc_ed25519_sign_msg_ex(
  81260. info->pk.ed25519sign.in, info->pk.ed25519sign.inLen,
  81261. info->pk.ed25519sign.out, info->pk.ed25519sign.outLen,
  81262. &key, info->pk.ed25519sign.type,
  81263. info->pk.ed25519sign.context,
  81264. info->pk.ed25519sign.contextLen);
  81265. }
  81266. }
  81267. else {
  81268. /* if decode fails, then fall-back to software based crypto */
  81269. fprintf(stderr, "test_CryptoCb_Func: ED25519 private key "
  81270. "decode failed %d, falling back to software\n", ret);
  81271. ret = CRYPTOCB_UNAVAILABLE;
  81272. }
  81273. wc_ed25519_free(&key);
  81274. }
  81275. wc_FreeDer(&pDer); pDer = NULL;
  81276. #ifdef DEBUG_WOLFSSL
  81277. fprintf(stderr, "test_CryptoCb_Func: ED25519 Ret %d, Out %d\n",
  81278. ret, *info->pk.ed25519sign.outLen);
  81279. #endif
  81280. }
  81281. #endif /* HAVE_ED25519 */
  81282. }
  81283. (void)thisDevId;
  81284. (void)keyFormat;
  81285. return ret;
  81286. }
  81287. /* tlsVer: WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  81288. static int test_wc_CryptoCb_TLS(int tlsVer,
  81289. const char* cliCaPemFile, const char* cliCertPemFile,
  81290. const char* cliPrivKeyPemFile, const char* cliPubKeyPemFile,
  81291. const char* svrCaPemFile, const char* svrCertPemFile,
  81292. const char* svrPrivKeyPemFile, const char* svrPubKeyPemFile)
  81293. {
  81294. EXPECT_DECLS;
  81295. callback_functions client_cbf;
  81296. callback_functions server_cbf;
  81297. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  81298. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  81299. if (tlsVer == WOLFSSL_TLSV1_3) {
  81300. #ifdef WOLFSSL_TLS13
  81301. server_cbf.method = wolfTLSv1_3_server_method;
  81302. client_cbf.method = wolfTLSv1_3_client_method;
  81303. #endif
  81304. }
  81305. else if (tlsVer == WOLFSSL_TLSV1_2) {
  81306. #ifndef WOLFSSL_NO_TLS12
  81307. server_cbf.method = wolfTLSv1_2_server_method;
  81308. client_cbf.method = wolfTLSv1_2_client_method;
  81309. #endif
  81310. }
  81311. else if (tlsVer == WOLFSSL_TLSV1_1) {
  81312. #ifndef NO_OLD_TLS
  81313. server_cbf.method = wolfTLSv1_1_server_method;
  81314. client_cbf.method = wolfTLSv1_1_client_method;
  81315. #endif
  81316. }
  81317. else if (tlsVer == WOLFSSL_TLSV1) {
  81318. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_TLSV10)
  81319. server_cbf.method = wolfTLSv1_server_method;
  81320. client_cbf.method = wolfTLSv1_client_method;
  81321. #endif
  81322. }
  81323. else if (tlsVer == WOLFSSL_SSLV3) {
  81324. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_SSLV3) && \
  81325. defined(WOLFSSL_STATIC_RSA)
  81326. server_cbf.method = wolfSSLv3_server_method;
  81327. client_cbf.method = wolfSSLv3_client_method;
  81328. #endif
  81329. }
  81330. else if (tlsVer == WOLFSSL_DTLSV1_2) {
  81331. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  81332. server_cbf.method = wolfDTLSv1_2_server_method;
  81333. client_cbf.method = wolfDTLSv1_2_client_method;
  81334. #endif
  81335. }
  81336. else if (tlsVer == WOLFSSL_DTLSV1) {
  81337. #if defined(WOLFSSL_DTLS) && !defined(NO_OLD_TLS)
  81338. server_cbf.method = wolfDTLSv1_server_method;
  81339. client_cbf.method = wolfDTLSv1_client_method;
  81340. #endif
  81341. }
  81342. if (server_cbf.method == NULL) {
  81343. /* not enabled */
  81344. return TEST_SUCCESS;
  81345. }
  81346. /* Setup the keys for the TLS test */
  81347. client_cbf.certPemFile = cliCertPemFile;
  81348. client_cbf.keyPemFile = cliPubKeyPemFile;
  81349. client_cbf.caPemFile = cliCaPemFile;
  81350. server_cbf.certPemFile = svrCertPemFile;
  81351. server_cbf.keyPemFile = svrPubKeyPemFile;
  81352. server_cbf.caPemFile = svrCaPemFile;
  81353. /* Setup a crypto callback with pointer to private key file for testing */
  81354. client_cbf.devId = 1;
  81355. wc_CryptoCb_RegisterDevice(client_cbf.devId, test_CryptoCb_Func,
  81356. (void*)cliPrivKeyPemFile);
  81357. server_cbf.devId = 2;
  81358. wc_CryptoCb_RegisterDevice(server_cbf.devId, test_CryptoCb_Func,
  81359. (void*)svrPrivKeyPemFile);
  81360. /* Perform TLS server and client test */
  81361. /* First test is at WOLFSSL_CTX level */
  81362. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  81363. /* Check for success */
  81364. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  81365. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  81366. if (EXPECT_SUCCESS()) {
  81367. /* Second test is a WOLFSSL object level */
  81368. client_cbf.loadToSSL = 1; server_cbf.loadToSSL = 1;
  81369. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  81370. }
  81371. /* Check for success */
  81372. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  81373. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  81374. /* Un register the devId's */
  81375. wc_CryptoCb_UnRegisterDevice(client_cbf.devId);
  81376. client_cbf.devId = INVALID_DEVID;
  81377. wc_CryptoCb_UnRegisterDevice(server_cbf.devId);
  81378. server_cbf.devId = INVALID_DEVID;
  81379. return EXPECT_RESULT();
  81380. }
  81381. #endif /* WOLF_CRYPTO_CB && HAVE_IO_TESTS_DEPENDENCIES */
  81382. static int test_wc_CryptoCb(void)
  81383. {
  81384. EXPECT_DECLS;
  81385. #ifdef WOLF_CRYPTO_CB
  81386. /* TODO: Add crypto callback API tests */
  81387. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  81388. #if !defined(NO_RSA) || defined(HAVE_ECC) || defined(HAVE_ED25519)
  81389. int tlsVer;
  81390. #endif
  81391. #ifndef NO_RSA
  81392. for (tlsVer = WOLFSSL_SSLV3; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  81393. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  81394. svrCertFile, cliCertFile, cliKeyFile, cliKeyPubFile,
  81395. cliCertFile, svrCertFile, svrKeyFile, svrKeyPubFile),
  81396. TEST_SUCCESS);
  81397. }
  81398. #endif
  81399. #ifdef HAVE_ECC
  81400. for (tlsVer = WOLFSSL_TLSV1; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  81401. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  81402. caEccCertFile, cliEccCertFile, cliEccKeyFile, cliEccKeyPubFile,
  81403. cliEccCertFile, eccCertFile, eccKeyFile, eccKeyPubFile),
  81404. TEST_SUCCESS);
  81405. }
  81406. #endif
  81407. #ifdef HAVE_ED25519
  81408. for (tlsVer = WOLFSSL_TLSV1_2; tlsVer <= WOLFSSL_DTLSV1_2; tlsVer++) {
  81409. if (tlsVer == WOLFSSL_DTLSV1) continue;
  81410. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  81411. caEdCertFile, cliEdCertFile, cliEdKeyFile, cliEdKeyPubFile,
  81412. cliEdCertFile, edCertFile, edKeyFile, edKeyPubFile),
  81413. TEST_SUCCESS);
  81414. }
  81415. #endif
  81416. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  81417. #endif /* WOLF_CRYPTO_CB */
  81418. return EXPECT_RESULT();
  81419. }
  81420. #if defined(WOLFSSL_STATIC_MEMORY) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  81421. /* tlsVer: Example: WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  81422. static int test_wolfSSL_CTX_StaticMemory_TLS(int tlsVer,
  81423. const char* cliCaPemFile, const char* cliCertPemFile,
  81424. const char* cliPrivKeyPemFile,
  81425. const char* svrCaPemFile, const char* svrCertPemFile,
  81426. const char* svrPrivKeyPemFile,
  81427. byte* cliMem, word32 cliMemSz, byte* svrMem, word32 svrMemSz)
  81428. {
  81429. EXPECT_DECLS;
  81430. callback_functions client_cbf;
  81431. callback_functions server_cbf;
  81432. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  81433. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  81434. if (tlsVer == WOLFSSL_TLSV1_3) {
  81435. #ifdef WOLFSSL_TLS13
  81436. server_cbf.method_ex = wolfTLSv1_3_server_method_ex;
  81437. client_cbf.method_ex = wolfTLSv1_3_client_method_ex;
  81438. #endif
  81439. }
  81440. else if (tlsVer == WOLFSSL_TLSV1_2) {
  81441. #ifndef WOLFSSL_NO_TLS12
  81442. server_cbf.method_ex = wolfTLSv1_2_server_method_ex;
  81443. client_cbf.method_ex = wolfTLSv1_2_client_method_ex;
  81444. #endif
  81445. }
  81446. else if (tlsVer == WOLFSSL_TLSV1_1) {
  81447. #ifndef NO_OLD_TLS
  81448. server_cbf.method_ex = wolfTLSv1_1_server_method_ex;
  81449. client_cbf.method_ex = wolfTLSv1_1_client_method_ex;
  81450. #endif
  81451. }
  81452. else if (tlsVer == WOLFSSL_TLSV1) {
  81453. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_TLSV10)
  81454. server_cbf.method_ex = wolfTLSv1_server_method_ex;
  81455. client_cbf.method_ex = wolfTLSv1_client_method_ex;
  81456. #endif
  81457. }
  81458. else if (tlsVer == WOLFSSL_SSLV3) {
  81459. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_SSLV3) && \
  81460. defined(WOLFSSL_STATIC_RSA)
  81461. server_cbf.method_ex = wolfSSLv3_server_method_ex;
  81462. client_cbf.method_ex = wolfSSLv3_client_method_ex;
  81463. #endif
  81464. }
  81465. else if (tlsVer == WOLFSSL_DTLSV1_2) {
  81466. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  81467. server_cbf.method_ex = wolfDTLSv1_2_server_method_ex;
  81468. client_cbf.method_ex = wolfDTLSv1_2_client_method_ex;
  81469. #endif
  81470. }
  81471. else if (tlsVer == WOLFSSL_DTLSV1) {
  81472. #if defined(WOLFSSL_DTLS) && !defined(NO_OLD_TLS)
  81473. server_cbf.method_ex = wolfDTLSv1_server_method_ex;
  81474. client_cbf.method_ex = wolfDTLSv1_client_method_ex;
  81475. #endif
  81476. }
  81477. if (server_cbf.method_ex == NULL) {
  81478. /* not enabled */
  81479. return TEST_SUCCESS;
  81480. }
  81481. /* Setup the keys for the TLS test */
  81482. client_cbf.certPemFile = cliCertPemFile;
  81483. client_cbf.keyPemFile = cliPrivKeyPemFile;
  81484. client_cbf.caPemFile = cliCaPemFile;
  81485. server_cbf.certPemFile = svrCertPemFile;
  81486. server_cbf.keyPemFile = svrPrivKeyPemFile;
  81487. server_cbf.caPemFile = svrCaPemFile;
  81488. client_cbf.mem = cliMem;
  81489. client_cbf.memSz = cliMemSz;
  81490. server_cbf.mem = svrMem;
  81491. server_cbf.memSz = svrMemSz;
  81492. client_cbf.devId = INVALID_DEVID;
  81493. server_cbf.devId = INVALID_DEVID;
  81494. /* Perform TLS server and client test */
  81495. /* First test is at WOLFSSL_CTX level */
  81496. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  81497. /* Check for success */
  81498. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  81499. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  81500. if (EXPECT_SUCCESS()) {
  81501. /* Second test is a WOLFSSL object level */
  81502. client_cbf.loadToSSL = 1; server_cbf.loadToSSL = 1;
  81503. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  81504. }
  81505. /* Check for success */
  81506. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  81507. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  81508. return EXPECT_RESULT();
  81509. }
  81510. #endif /* WOLFSSL_STATIC_MEMORY && HAVE_IO_TESTS_DEPENDENCIES */
  81511. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY)
  81512. static int test_wolfSSL_CTX_StaticMemory_SSL(WOLFSSL_CTX* ctx)
  81513. {
  81514. EXPECT_DECLS;
  81515. WOLFSSL *ssl1 = NULL, *ssl2 = NULL, *ssl3 = NULL;
  81516. WOLFSSL_MEM_STATS mem_stats;
  81517. WOLFSSL_MEM_CONN_STATS ssl_stats;
  81518. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  81519. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  81520. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  81521. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  81522. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  81523. #endif
  81524. ExpectNotNull((ssl1 = wolfSSL_new(ctx)));
  81525. ExpectNotNull((ssl2 = wolfSSL_new(ctx)));
  81526. #ifndef WOLFSSL_STATIC_MEMORY_LEAN
  81527. /* this should fail because kMaxCtxClients == 2 */
  81528. ExpectNull((ssl3 = wolfSSL_new(ctx)));
  81529. #else
  81530. (void)ssl3;
  81531. #endif
  81532. if (wolfSSL_is_static_memory(ssl1, &ssl_stats) == 1) {
  81533. #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_STATIC_MEMORY_LEAN)
  81534. wolfSSL_PrintStatsConn(&ssl_stats);
  81535. #endif
  81536. (void)ssl_stats;
  81537. }
  81538. /* display collected statistics */
  81539. if (wolfSSL_CTX_is_static_memory(ctx, &mem_stats) == 1) {
  81540. #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_STATIC_MEMORY_LEAN)
  81541. wolfSSL_PrintStats(&mem_stats);
  81542. #endif
  81543. (void)mem_stats;
  81544. }
  81545. wolfSSL_free(ssl1);
  81546. wolfSSL_free(ssl2);
  81547. return EXPECT_RESULT();
  81548. }
  81549. #endif /* WOLFSSL_STATIC_MEMORY && !WOLFCRYPT_ONLY */
  81550. static int test_wolfSSL_CTX_StaticMemory(void)
  81551. {
  81552. EXPECT_DECLS;
  81553. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY)
  81554. wolfSSL_method_func method_func;
  81555. WOLFSSL_CTX* ctx;
  81556. const int kMaxCtxClients = 2;
  81557. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  81558. #if !defined(NO_RSA) || defined(HAVE_ECC) || defined(HAVE_ED25519)
  81559. int tlsVer;
  81560. byte cliMem[TEST_TLS_STATIC_MEMSZ];
  81561. #endif
  81562. #endif
  81563. byte svrMem[TEST_TLS_STATIC_MEMSZ];
  81564. #ifndef NO_WOLFSSL_SERVER
  81565. #ifndef WOLFSSL_NO_TLS12
  81566. method_func = wolfTLSv1_2_server_method_ex;
  81567. #else
  81568. method_func = wolfTLSv1_3_server_method_ex;
  81569. #endif
  81570. #else
  81571. #ifndef WOLFSSL_NO_TLS12
  81572. method_func = wolfTLSv1_2_client_method_ex;
  81573. #else
  81574. method_func = wolfTLSv1_3_client_method_ex;
  81575. #endif
  81576. #endif
  81577. /* Test creating CTX directly from static memory pool */
  81578. ctx = NULL;
  81579. ExpectIntEQ(wolfSSL_CTX_load_static_memory(&ctx, method_func, svrMem,
  81580. sizeof(svrMem), 0, kMaxCtxClients), WOLFSSL_SUCCESS);
  81581. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_SSL(ctx), TEST_SUCCESS);
  81582. wolfSSL_CTX_free(ctx);
  81583. ctx = NULL;
  81584. /* Test for heap allocated CTX, then assigning static pool to it */
  81585. ExpectNotNull(ctx = wolfSSL_CTX_new(method_func(NULL)));
  81586. ExpectIntEQ(wolfSSL_CTX_load_static_memory(&ctx, NULL, svrMem,
  81587. sizeof(svrMem), 0, kMaxCtxClients), WOLFSSL_SUCCESS);
  81588. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_SSL(ctx), TEST_SUCCESS);
  81589. wolfSSL_CTX_free(ctx);
  81590. /* TLS Level Tests using static memory */
  81591. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  81592. #ifndef NO_RSA
  81593. for (tlsVer = WOLFSSL_SSLV3; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  81594. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  81595. svrCertFile, cliCertFile, cliKeyFile,
  81596. cliCertFile, svrCertFile, svrKeyFile,
  81597. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  81598. TEST_SUCCESS);
  81599. }
  81600. #endif
  81601. #ifdef HAVE_ECC
  81602. for (tlsVer = WOLFSSL_TLSV1; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  81603. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  81604. caEccCertFile, cliEccCertFile, cliEccKeyFile,
  81605. cliEccCertFile, eccCertFile, eccKeyFile,
  81606. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  81607. TEST_SUCCESS);
  81608. }
  81609. #endif
  81610. #ifdef HAVE_ED25519
  81611. for (tlsVer = WOLFSSL_TLSV1_2; tlsVer <= WOLFSSL_DTLSV1_2; tlsVer++) {
  81612. if (tlsVer == WOLFSSL_DTLSV1) continue;
  81613. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  81614. caEdCertFile, cliEdCertFile, cliEdKeyFile,
  81615. cliEdCertFile, edCertFile, edKeyFile,
  81616. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  81617. TEST_SUCCESS);
  81618. }
  81619. #endif
  81620. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  81621. #endif /* WOLFSSL_STATIC_MEMORY && !WOLFCRYPT_ONLY */
  81622. return EXPECT_RESULT();
  81623. }
  81624. static int test_openssl_FIPS_drbg(void)
  81625. {
  81626. EXPECT_DECLS;
  81627. #if defined(OPENSSL_EXTRA) && !defined(WC_NO_RNG) && defined(HAVE_HASHDRBG)
  81628. DRBG_CTX* dctx = NULL;
  81629. byte data1[32], data2[32], zeroData[32];
  81630. byte testSeed[16];
  81631. size_t dlen = sizeof(data1);
  81632. int i;
  81633. XMEMSET(data1, 0, dlen);
  81634. XMEMSET(data2, 0, dlen);
  81635. XMEMSET(zeroData, 0, sizeof(zeroData));
  81636. for (i = 0; i < (int)sizeof(testSeed); i++) {
  81637. testSeed[i] = (byte)i;
  81638. }
  81639. ExpectNotNull(dctx = FIPS_get_default_drbg());
  81640. ExpectIntEQ(FIPS_drbg_init(dctx, 0, 0), WOLFSSL_SUCCESS);
  81641. ExpectIntEQ(FIPS_drbg_set_callbacks(dctx, NULL, NULL, 20, NULL, NULL),
  81642. WOLFSSL_SUCCESS);
  81643. ExpectIntEQ(FIPS_drbg_instantiate(dctx, NULL, 0), WOLFSSL_SUCCESS);
  81644. ExpectIntEQ(FIPS_drbg_generate(dctx, data1, dlen, 0, NULL, 0),
  81645. WOLFSSL_SUCCESS);
  81646. ExpectIntNE(XMEMCMP(data1, zeroData, dlen), 0);
  81647. ExpectIntEQ(FIPS_drbg_reseed(dctx, testSeed, sizeof(testSeed)),
  81648. WOLFSSL_SUCCESS);
  81649. ExpectIntEQ(FIPS_drbg_generate(dctx, data2, dlen, 0, NULL, 0),
  81650. WOLFSSL_SUCCESS);
  81651. ExpectIntNE(XMEMCMP(data1, zeroData, dlen), 0);
  81652. ExpectIntNE(XMEMCMP(data1, data2, dlen), 0);
  81653. ExpectIntEQ(FIPS_drbg_uninstantiate(dctx), WOLFSSL_SUCCESS);
  81654. #ifndef HAVE_GLOBAL_RNG
  81655. /* gets freed by wolfSSL_Cleanup() when HAVE_GLOBAL_RNG defined */
  81656. wolfSSL_FIPS_drbg_free(dctx);
  81657. #endif
  81658. #endif
  81659. return EXPECT_RESULT();
  81660. }
  81661. static int test_wolfSSL_FIPS_mode(void)
  81662. {
  81663. EXPECT_DECLS;
  81664. #if defined(OPENSSL_ALL)
  81665. #ifdef HAVE_FIPS
  81666. ExpectIntEQ(wolfSSL_FIPS_mode(), 1);
  81667. ExpectIntEQ(wolfSSL_FIPS_mode_set(0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  81668. ExpectIntEQ(wolfSSL_FIPS_mode_set(1), WOLFSSL_SUCCESS);
  81669. #else
  81670. ExpectIntEQ(wolfSSL_FIPS_mode(), 0);
  81671. ExpectIntEQ(wolfSSL_FIPS_mode_set(0), WOLFSSL_SUCCESS);
  81672. ExpectIntEQ(wolfSSL_FIPS_mode_set(1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  81673. #endif
  81674. #endif
  81675. return EXPECT_RESULT();
  81676. }
  81677. #ifdef WOLFSSL_DTLS
  81678. /* Prints out the current window */
  81679. static void DUW_TEST_print_window_binary(word32 h, word32 l, word32* w) {
  81680. #ifdef WOLFSSL_DEBUG_DTLS_WINDOW
  81681. int i;
  81682. for (i = WOLFSSL_DTLS_WINDOW_WORDS - 1; i >= 0; i--) {
  81683. word32 b = w[i];
  81684. int j;
  81685. /* Prints out a 32 bit binary number in big endian order */
  81686. for (j = 0; j < 32; j++, b <<= 1) {
  81687. if (b & (((word32)1) << 31))
  81688. fprintf(stderr, "1");
  81689. else
  81690. fprintf(stderr, "0");
  81691. }
  81692. fprintf(stderr, " ");
  81693. }
  81694. fprintf(stderr, "cur_hi %u cur_lo %u\n", h, l);
  81695. #else
  81696. (void)h;
  81697. (void)l;
  81698. (void)w;
  81699. #endif
  81700. }
  81701. /* a - cur_hi
  81702. * b - cur_lo
  81703. * c - next_hi
  81704. * d - next_lo
  81705. * e - window
  81706. * f - expected next_hi
  81707. * g - expected next_lo
  81708. * h - expected window[1]
  81709. * i - expected window[0]
  81710. */
  81711. #define DUW_TEST(a,b,c,d,e,f,g,h,i) do { \
  81712. ExpectIntEQ(wolfSSL_DtlsUpdateWindow((a), (b), &(c), &(d), (e)), 1); \
  81713. DUW_TEST_print_window_binary((a), (b), (e)); \
  81714. ExpectIntEQ((c), (f)); \
  81715. ExpectIntEQ((d), (g)); \
  81716. ExpectIntEQ((e)[1], (h)); \
  81717. ExpectIntEQ((e)[0], (i)); \
  81718. } while (0)
  81719. static int test_wolfSSL_DtlsUpdateWindow(void)
  81720. {
  81721. EXPECT_DECLS;
  81722. word32 window[WOLFSSL_DTLS_WINDOW_WORDS];
  81723. word32 next_lo = 0;
  81724. word16 next_hi = 0;
  81725. #ifdef WOLFSSL_DEBUG_DTLS_WINDOW
  81726. fprintf(stderr, "\n");
  81727. #endif
  81728. XMEMSET(window, 0, sizeof window);
  81729. DUW_TEST(0, 0, next_hi, next_lo, window, 0, 1, 0, 0x01);
  81730. DUW_TEST(0, 1, next_hi, next_lo, window, 0, 2, 0, 0x03);
  81731. DUW_TEST(0, 5, next_hi, next_lo, window, 0, 6, 0, 0x31);
  81732. DUW_TEST(0, 4, next_hi, next_lo, window, 0, 6, 0, 0x33);
  81733. DUW_TEST(0, 100, next_hi, next_lo, window, 0, 101, 0, 0x01);
  81734. DUW_TEST(0, 101, next_hi, next_lo, window, 0, 102, 0, 0x03);
  81735. DUW_TEST(0, 133, next_hi, next_lo, window, 0, 134, 0x03, 0x01);
  81736. DUW_TEST(0, 200, next_hi, next_lo, window, 0, 201, 0, 0x01);
  81737. DUW_TEST(0, 264, next_hi, next_lo, window, 0, 265, 0, 0x01);
  81738. DUW_TEST(0, 0xFFFFFFFF, next_hi, next_lo, window, 1, 0, 0, 0x01);
  81739. DUW_TEST(0, 0xFFFFFFFD, next_hi, next_lo, window, 1, 0, 0, 0x05);
  81740. DUW_TEST(0, 0xFFFFFFFE, next_hi, next_lo, window, 1, 0, 0, 0x07);
  81741. DUW_TEST(1, 3, next_hi, next_lo, window, 1, 4, 0, 0x71);
  81742. DUW_TEST(1, 0, next_hi, next_lo, window, 1, 4, 0, 0x79);
  81743. DUW_TEST(1, 0xFFFFFFFF, next_hi, next_lo, window, 2, 0, 0, 0x01);
  81744. DUW_TEST(2, 3, next_hi, next_lo, window, 2, 4, 0, 0x11);
  81745. DUW_TEST(2, 0, next_hi, next_lo, window, 2, 4, 0, 0x19);
  81746. DUW_TEST(2, 25, next_hi, next_lo, window, 2, 26, 0, 0x6400001);
  81747. DUW_TEST(2, 27, next_hi, next_lo, window, 2, 28, 0, 0x19000005);
  81748. DUW_TEST(2, 29, next_hi, next_lo, window, 2, 30, 0, 0x64000015);
  81749. DUW_TEST(2, 33, next_hi, next_lo, window, 2, 34, 6, 0x40000151);
  81750. DUW_TEST(2, 60, next_hi, next_lo, window, 2, 61, 0x3200000A, 0x88000001);
  81751. DUW_TEST(1, 0xFFFFFFF0, next_hi, next_lo, window, 2, 61, 0x3200000A, 0x88000001);
  81752. DUW_TEST(2, 0xFFFFFFFD, next_hi, next_lo, window, 2, 0xFFFFFFFE, 0, 0x01);
  81753. DUW_TEST(3, 1, next_hi, next_lo, window, 3, 2, 0, 0x11);
  81754. DUW_TEST(99, 66, next_hi, next_lo, window, 99, 67, 0, 0x01);
  81755. DUW_TEST(50, 66, next_hi, next_lo, window, 99, 67, 0, 0x01);
  81756. DUW_TEST(100, 68, next_hi, next_lo, window, 100, 69, 0, 0x01);
  81757. DUW_TEST(99, 50, next_hi, next_lo, window, 100, 69, 0, 0x01);
  81758. DUW_TEST(99, 0xFFFFFFFF, next_hi, next_lo, window, 100, 69, 0, 0x01);
  81759. DUW_TEST(150, 0xFFFFFFFF, next_hi, next_lo, window, 151, 0, 0, 0x01);
  81760. DUW_TEST(152, 0xFFFFFFFF, next_hi, next_lo, window, 153, 0, 0, 0x01);
  81761. return EXPECT_RESULT();
  81762. }
  81763. #endif /* WOLFSSL_DTLS */
  81764. #ifdef WOLFSSL_DTLS
  81765. static int DFB_TEST(WOLFSSL* ssl, word32 seq, word32 len, word32 f_offset,
  81766. word32 f_len, word32 f_count, byte ready, word32 bytesReceived)
  81767. {
  81768. DtlsMsg* cur;
  81769. static byte msg[100];
  81770. static byte msgInit = 0;
  81771. if (!msgInit) {
  81772. int i;
  81773. for (i = 0; i < 100; i++)
  81774. msg[i] = i + 1;
  81775. msgInit = 1;
  81776. }
  81777. /* Sanitize test parameters */
  81778. if (len > sizeof(msg))
  81779. return -1;
  81780. if (f_offset + f_len > sizeof(msg))
  81781. return -1;
  81782. DtlsMsgStore(ssl, 0, seq, msg + f_offset, len, certificate, f_offset, f_len, NULL);
  81783. if (ssl->dtls_rx_msg_list == NULL)
  81784. return -100;
  81785. if ((cur = DtlsMsgFind(ssl->dtls_rx_msg_list, 0, seq)) == NULL)
  81786. return -200;
  81787. if (cur->fragBucketListCount != f_count)
  81788. return -300;
  81789. if (cur->ready != ready)
  81790. return -400;
  81791. if (cur->bytesReceived != bytesReceived)
  81792. return -500;
  81793. if (ready) {
  81794. if (cur->fragBucketList != NULL)
  81795. return -600;
  81796. if (XMEMCMP(cur->fullMsg, msg, cur->sz) != 0)
  81797. return -700;
  81798. }
  81799. else {
  81800. DtlsFragBucket* fb;
  81801. if (cur->fragBucketList == NULL)
  81802. return -800;
  81803. for (fb = cur->fragBucketList; fb != NULL; fb = fb->m.m.next) {
  81804. if (XMEMCMP(fb->buf, msg + fb->m.m.offset, fb->m.m.sz) != 0)
  81805. return -900;
  81806. }
  81807. }
  81808. return 0;
  81809. }
  81810. static int test_wolfSSL_DTLS_fragment_buckets(void)
  81811. {
  81812. EXPECT_DECLS;
  81813. WOLFSSL ssl[1];
  81814. XMEMSET(ssl, 0, sizeof(*ssl));
  81815. ExpectIntEQ(DFB_TEST(ssl, 0, 100, 0, 100, 0, 1, 100), 0); /* 0-100 */
  81816. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  81817. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 20, 20, 1, 0, 40), 0); /* 20-40 */
  81818. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 40, 20, 1, 0, 60), 0); /* 40-60 */
  81819. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 60, 20, 1, 0, 80), 0); /* 60-80 */
  81820. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 80, 20, 0, 1, 100), 0); /* 80-100 */
  81821. /* Test all permutations of 3 regions */
  81822. /* 1 2 3 */
  81823. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  81824. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 30, 30, 1, 0, 60), 0); /* 30-60 */
  81825. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 60, 40, 0, 1, 100), 0); /* 60-100 */
  81826. /* 1 3 2 */
  81827. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  81828. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 60, 40, 2, 0, 70), 0); /* 60-100 */
  81829. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 30, 30, 0, 1, 100), 0); /* 30-60 */
  81830. /* 2 1 3 */
  81831. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 30, 30, 1, 0, 30), 0); /* 30-60 */
  81832. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 0, 30, 1, 0, 60), 0); /* 0-30 */
  81833. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 60, 40, 0, 1, 100), 0); /* 60-100 */
  81834. /* 2 3 1 */
  81835. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 30, 30, 1, 0, 30), 0); /* 30-60 */
  81836. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 60, 40, 1, 0, 70), 0); /* 60-100 */
  81837. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 0, 30, 0, 1, 100), 0); /* 0-30 */
  81838. /* 3 1 2 */
  81839. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 60, 40, 1, 0, 40), 0); /* 60-100 */
  81840. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 0, 30, 2, 0, 70), 0); /* 0-30 */
  81841. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 30, 30, 0, 1, 100), 0); /* 30-60 */
  81842. /* 3 2 1 */
  81843. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 60, 40, 1, 0, 40), 0); /* 60-100 */
  81844. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 30, 30, 1, 0, 70), 0); /* 30-60 */
  81845. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 0, 30, 0, 1, 100), 0); /* 0-30 */
  81846. /* Test overlapping regions */
  81847. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  81848. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 20, 10, 1, 0, 30), 0); /* 20-30 */
  81849. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 70, 10, 2, 0, 40), 0); /* 70-80 */
  81850. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 20, 30, 2, 0, 60), 0); /* 20-50 */
  81851. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 40, 60, 0, 1, 100), 0); /* 40-100 */
  81852. /* Test overlapping multiple regions */
  81853. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  81854. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 30, 5, 2, 0, 25), 0); /* 30-35 */
  81855. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 40, 5, 3, 0, 30), 0); /* 40-45 */
  81856. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 50, 5, 4, 0, 35), 0); /* 50-55 */
  81857. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 60, 5, 5, 0, 40), 0); /* 60-65 */
  81858. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 70, 5, 6, 0, 45), 0); /* 70-75 */
  81859. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 30, 25, 4, 0, 55), 0); /* 30-55 */
  81860. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 55, 15, 2, 0, 65), 0); /* 55-70 */
  81861. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 75, 25, 2, 0, 90), 0); /* 75-100 */
  81862. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 10, 25, 0, 1, 100), 0); /* 10-35 */
  81863. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  81864. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 30, 20, 2, 0, 40), 0); /* 30-50 */
  81865. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 0, 40, 1, 0, 50), 0); /* 0-40 */
  81866. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 50, 50, 0, 1, 100), 0); /* 10-35 */
  81867. DtlsMsgListDelete(ssl->dtls_rx_msg_list, ssl->heap);
  81868. ssl->dtls_rx_msg_list = NULL;
  81869. ssl->dtls_rx_msg_list_sz = 0;
  81870. return EXPECT_RESULT();
  81871. }
  81872. #endif
  81873. #if !defined(NO_FILESYSTEM) && \
  81874. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  81875. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81876. static int test_wolfSSL_dtls_stateless2(void)
  81877. {
  81878. EXPECT_DECLS;
  81879. WOLFSSL *ssl_c = NULL;
  81880. WOLFSSL *ssl_c2 = NULL;
  81881. WOLFSSL *ssl_s = NULL;
  81882. struct test_memio_ctx test_ctx;
  81883. WOLFSSL_CTX *ctx_c = NULL;
  81884. WOLFSSL_CTX *ctx_s = NULL;
  81885. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81886. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81887. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  81888. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c));
  81889. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  81890. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  81891. /* send CH */
  81892. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81893. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  81894. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81895. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81896. ExpectIntNE(test_ctx.c_len, 0);
  81897. /* consume HRR */
  81898. test_ctx.c_len = 0;
  81899. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81900. wolfSSL_free(ssl_c2);
  81901. wolfSSL_free(ssl_c);
  81902. wolfSSL_free(ssl_s);
  81903. wolfSSL_CTX_free(ctx_c);
  81904. wolfSSL_CTX_free(ctx_s);
  81905. return EXPECT_RESULT();
  81906. }
  81907. #ifdef HAVE_MAX_FRAGMENT
  81908. static int test_wolfSSL_dtls_stateless_maxfrag(void)
  81909. {
  81910. EXPECT_DECLS;
  81911. WOLFSSL *ssl_c = NULL;
  81912. WOLFSSL *ssl_c2 = NULL;
  81913. WOLFSSL *ssl_s = NULL;
  81914. struct test_memio_ctx test_ctx;
  81915. WOLFSSL_CTX *ctx_c = NULL;
  81916. WOLFSSL_CTX *ctx_s = NULL;
  81917. word16 max_fragment = 0;
  81918. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81919. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81920. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  81921. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c));
  81922. ExpectIntEQ(wolfSSL_UseMaxFragment(ssl_c2, WOLFSSL_MFL_2_8),
  81923. WOLFSSL_SUCCESS);
  81924. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  81925. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  81926. if (ssl_s != NULL) {
  81927. max_fragment = ssl_s->max_fragment;
  81928. }
  81929. /* send CH */
  81930. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81931. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  81932. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81933. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81934. /* CH without cookie shouldn't change state */
  81935. ExpectIntEQ(ssl_s->max_fragment, max_fragment);
  81936. ExpectIntNE(test_ctx.c_len, 0);
  81937. /* consume HRR from buffer */
  81938. test_ctx.c_len = 0;
  81939. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81940. wolfSSL_free(ssl_c2);
  81941. wolfSSL_free(ssl_c);
  81942. wolfSSL_free(ssl_s);
  81943. wolfSSL_CTX_free(ctx_c);
  81944. wolfSSL_CTX_free(ctx_s);
  81945. return EXPECT_RESULT();
  81946. }
  81947. #endif /* HAVE_MAX_FRAGMENT */
  81948. #if defined(WOLFSSL_DTLS_NO_HVR_ON_RESUME)
  81949. #define ROUNDS_WITH_HVR 4
  81950. #define ROUNDS_WITHOUT_HVR 2
  81951. #define HANDSHAKE_TYPE_OFFSET DTLS_RECORD_HEADER_SZ
  81952. static int buf_is_hvr(const byte *data, int len)
  81953. {
  81954. if (len < DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ)
  81955. return 0;
  81956. return data[HANDSHAKE_TYPE_OFFSET] == hello_verify_request;
  81957. }
  81958. static int _test_wolfSSL_dtls_stateless_resume(byte useticket, byte bad)
  81959. {
  81960. EXPECT_DECLS;
  81961. struct test_memio_ctx test_ctx;
  81962. WOLFSSL_CTX *ctx_c = NULL;
  81963. WOLFSSL_CTX *ctx_s = NULL;
  81964. WOLFSSL *ssl_c = NULL;
  81965. WOLFSSL *ssl_s = NULL;
  81966. WOLFSSL_SESSION *sess = NULL;
  81967. int round_trips;
  81968. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81969. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
  81970. &ssl_s, wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  81971. #ifdef HAVE_SESSION_TICKET
  81972. if (useticket) {
  81973. ExpectIntEQ(wolfSSL_UseSessionTicket(ssl_c), WOLFSSL_SUCCESS);
  81974. }
  81975. #endif
  81976. round_trips = ROUNDS_WITH_HVR;
  81977. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, round_trips,
  81978. &round_trips), 0);
  81979. ExpectIntEQ(round_trips, ROUNDS_WITH_HVR);
  81980. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  81981. wolfSSL_shutdown(ssl_c);
  81982. wolfSSL_shutdown(ssl_s);
  81983. wolfSSL_free(ssl_c);
  81984. ssl_c = NULL;
  81985. wolfSSL_free(ssl_s);
  81986. ssl_s = NULL;
  81987. test_ctx.c_len = test_ctx.s_len = 0;
  81988. /* make resumption invalid */
  81989. if (bad && (sess != NULL)) {
  81990. if (useticket) {
  81991. #ifdef HAVE_SESSION_TICKET
  81992. if (sess->ticket != NULL) {
  81993. sess->ticket[0] = !sess->ticket[0];
  81994. }
  81995. #endif /* HAVE_SESSION_TICKET */
  81996. }
  81997. else {
  81998. sess->sessionID[0] = !sess->sessionID[0];
  81999. }
  82000. }
  82001. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  82002. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  82003. wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx);
  82004. wolfSSL_SetIOReadCtx(ssl_c, &test_ctx);
  82005. wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx);
  82006. wolfSSL_SetIOReadCtx(ssl_s, &test_ctx);
  82007. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  82008. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82009. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  82010. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82011. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  82012. ExpectFalse(bad && !buf_is_hvr(test_ctx.c_buff, test_ctx.c_len));
  82013. ExpectFalse(!bad && buf_is_hvr(test_ctx.c_buff, test_ctx.c_len));
  82014. if (!useticket) {
  82015. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, &round_trips), 0);
  82016. ExpectFalse(bad && round_trips != ROUNDS_WITH_HVR - 1);
  82017. ExpectFalse(!bad && round_trips != ROUNDS_WITHOUT_HVR - 1);
  82018. }
  82019. wolfSSL_SESSION_free(sess);
  82020. wolfSSL_free(ssl_c);
  82021. wolfSSL_free(ssl_s);
  82022. wolfSSL_CTX_free(ctx_c);
  82023. wolfSSL_CTX_free(ctx_s);
  82024. return EXPECT_RESULT();
  82025. }
  82026. static int test_wolfSSL_dtls_stateless_resume(void)
  82027. {
  82028. EXPECT_DECLS;
  82029. #ifdef HAVE_SESSION_TICKET
  82030. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(1, 0), TEST_SUCCESS);
  82031. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(1, 1), TEST_SUCCESS);
  82032. #endif /* HAVE_SESION_TICKET */
  82033. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(0, 0), TEST_SUCCESS);
  82034. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(0, 1), TEST_SUCCESS);
  82035. return EXPECT_RESULT();
  82036. }
  82037. #endif /* WOLFSSL_DTLS_NO_HVR_ON_RESUME */
  82038. #if !defined(NO_OLD_TLS)
  82039. static int test_wolfSSL_dtls_stateless_downgrade(void)
  82040. {
  82041. EXPECT_DECLS;
  82042. WOLFSSL_CTX *ctx_c = NULL;
  82043. WOLFSSL_CTX *ctx_c2 = NULL;
  82044. WOLFSSL_CTX *ctx_s = NULL;
  82045. WOLFSSL *ssl_c = NULL;
  82046. WOLFSSL *ssl_c2 = NULL;
  82047. WOLFSSL *ssl_s = NULL;
  82048. struct test_memio_ctx test_ctx;
  82049. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82050. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82051. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  82052. ExpectIntEQ(wolfSSL_CTX_SetMinVersion(ctx_s, WOLFSSL_DTLSV1),
  82053. WOLFSSL_SUCCESS);
  82054. ExpectNotNull(ctx_c2 = wolfSSL_CTX_new(wolfDTLSv1_client_method()));
  82055. wolfSSL_SetIORecv(ctx_c2, test_memio_read_cb);
  82056. wolfSSL_SetIOSend(ctx_c2, test_memio_write_cb);
  82057. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c2));
  82058. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  82059. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  82060. /* send CH */
  82061. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82062. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  82063. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82064. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  82065. ExpectIntNE(test_ctx.c_len, 0);
  82066. /* consume HRR */
  82067. test_ctx.c_len = 0;
  82068. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  82069. wolfSSL_free(ssl_c2);
  82070. wolfSSL_free(ssl_c);
  82071. wolfSSL_free(ssl_s);
  82072. wolfSSL_CTX_free(ctx_c);
  82073. wolfSSL_CTX_free(ctx_c2);
  82074. wolfSSL_CTX_free(ctx_s);
  82075. return EXPECT_RESULT();
  82076. }
  82077. #endif /* !defined(NO_OLD_TLS) */
  82078. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  82079. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)*/
  82080. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  82081. !defined(NO_OLD_TLS) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  82082. static int test_WOLFSSL_dtls_version_alert(void)
  82083. {
  82084. EXPECT_DECLS;
  82085. struct test_memio_ctx test_ctx;
  82086. WOLFSSL_CTX *ctx_c = NULL;
  82087. WOLFSSL_CTX *ctx_s = NULL;
  82088. WOLFSSL *ssl_c = NULL;
  82089. WOLFSSL *ssl_s = NULL;
  82090. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82091. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82092. wolfDTLSv1_2_client_method, wolfDTLSv1_server_method), 0);
  82093. /* client hello */
  82094. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82095. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  82096. /* hrr */
  82097. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82098. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  82099. /* client hello 1 */
  82100. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82101. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  82102. /* server hello */
  82103. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82104. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  82105. /* should fail */
  82106. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82107. (ssl_c->error == WC_NO_ERR_TRACE(VERSION_ERROR)));
  82108. /* shuould fail */
  82109. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82110. (ssl_s->error == WC_NO_ERR_TRACE(VERSION_ERROR) || ssl_s->error == WC_NO_ERR_TRACE(FATAL_ERROR)));
  82111. wolfSSL_free(ssl_c);
  82112. wolfSSL_free(ssl_s);
  82113. wolfSSL_CTX_free(ctx_c);
  82114. wolfSSL_CTX_free(ctx_s);
  82115. return EXPECT_RESULT();
  82116. }
  82117. #else
  82118. static int test_WOLFSSL_dtls_version_alert(void)
  82119. {
  82120. return TEST_SKIPPED;
  82121. }
  82122. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) &&
  82123. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) &&
  82124. * !defined(NO_OLD_TLS) && !defined(NO_RSA)
  82125. */
  82126. #if defined(WOLFSSL_TICKET_NONCE_MALLOC) && defined(HAVE_SESSION_TICKET) \
  82127. && defined(WOLFSSL_TLS13) && \
  82128. (!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))\
  82129. && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  82130. static int send_new_session_ticket(WOLFSSL *ssl, byte nonceLength, byte filler)
  82131. {
  82132. struct test_memio_ctx *test_ctx;
  82133. byte buf[2048];
  82134. int idx, sz;
  82135. word32 tmp;
  82136. int ret;
  82137. idx = 5; /* space for record header */
  82138. buf[idx] = session_ticket; /* type */
  82139. idx++;
  82140. tmp = OPAQUE32_LEN +
  82141. OPAQUE32_LEN +
  82142. OPAQUE8_LEN + nonceLength +
  82143. OPAQUE16_LEN + OPAQUE8_LEN + OPAQUE16_LEN;
  82144. c32to24(tmp, buf + idx);
  82145. idx += OPAQUE24_LEN;
  82146. c32toa((word32)12345, buf+idx); /* lifetime */
  82147. idx += OPAQUE32_LEN;
  82148. c32toa((word32)12345, buf+idx); /* add */
  82149. idx += OPAQUE32_LEN;
  82150. buf[idx] = nonceLength; /* nonce length */
  82151. idx++;
  82152. XMEMSET(&buf[idx], filler, nonceLength); /* nonce */
  82153. idx += nonceLength;
  82154. tmp = 1; /* ticket len */
  82155. c16toa((word16)tmp, buf+idx);
  82156. idx += 2;
  82157. buf[idx] = 0xFF; /* ticket */
  82158. idx++;
  82159. tmp = 0; /* ext len */
  82160. c16toa((word16)tmp, buf+idx);
  82161. idx += 2;
  82162. sz = BuildTls13Message(ssl, buf, 2048, buf+5, idx - 5,
  82163. handshake, 0, 0, 0);
  82164. AssertIntGT(sz, 0);
  82165. test_ctx = (struct test_memio_ctx*)wolfSSL_GetIOWriteCtx(ssl);
  82166. AssertNotNull(test_ctx);
  82167. ret = test_memio_write_cb(ssl, (char*)buf, sz, test_ctx);
  82168. return !(ret == sz);
  82169. }
  82170. static int test_ticket_nonce_check(WOLFSSL_SESSION *sess, byte len)
  82171. {
  82172. int ret = 0;
  82173. if ((sess == NULL) || (sess->ticketNonce.len != len)) {
  82174. ret = -1;
  82175. }
  82176. else {
  82177. int i;
  82178. for (i = 0; i < len; i++) {
  82179. if (sess->ticketNonce.data[i] != len) {
  82180. ret = -1;
  82181. break;
  82182. }
  82183. }
  82184. }
  82185. return ret;
  82186. }
  82187. static int test_ticket_nonce_malloc_do(WOLFSSL *ssl_s, WOLFSSL *ssl_c, byte len)
  82188. {
  82189. EXPECT_DECLS;
  82190. char *buf[1024];
  82191. ExpectIntEQ(send_new_session_ticket(ssl_s, len, len), 0);
  82192. ExpectTrue((wolfSSL_recv(ssl_c, buf, 1024, 0) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82193. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  82194. ExpectIntEQ(test_ticket_nonce_check(ssl_c->session, len), 0);
  82195. return EXPECT_RESULT();
  82196. }
  82197. static int test_ticket_nonce_cache(WOLFSSL *ssl_s, WOLFSSL *ssl_c, byte len)
  82198. {
  82199. EXPECT_DECLS;
  82200. WOLFSSL_SESSION *sess = NULL;
  82201. WOLFSSL_SESSION *cached = NULL;
  82202. WOLFSSL_CTX *ctx = ssl_c->ctx;
  82203. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, len), TEST_SUCCESS);
  82204. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  82205. ExpectIntEQ(AddSessionToCache(ctx, sess, sess->sessionID, sess->sessionIDSz,
  82206. NULL, ssl_c->options.side, 1,NULL), 0);
  82207. ExpectNotNull(cached = wolfSSL_SESSION_new());
  82208. ExpectIntEQ(wolfSSL_GetSessionFromCache(ssl_c, cached), WOLFSSL_SUCCESS);
  82209. ExpectIntEQ(test_ticket_nonce_check(cached, len), 0);
  82210. wolfSSL_SESSION_free(cached);
  82211. wolfSSL_SESSION_free(sess);
  82212. return EXPECT_RESULT();
  82213. }
  82214. static int test_ticket_nonce_malloc(void)
  82215. {
  82216. EXPECT_DECLS;
  82217. struct test_memio_ctx test_ctx;
  82218. WOLFSSL_CTX *ctx_c = NULL;
  82219. WOLFSSL_CTX *ctx_s = NULL;
  82220. WOLFSSL *ssl_c = NULL;
  82221. WOLFSSL *ssl_s = NULL;
  82222. byte small;
  82223. byte medium;
  82224. byte big;
  82225. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82226. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82227. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  82228. /* will send ticket manually */
  82229. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(ssl_s), 0);
  82230. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_NONE, 0);
  82231. wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_NONE, 0);
  82232. while (EXPECT_SUCCESS() && (ssl_c->options.handShakeDone == 0) &&
  82233. (ssl_s->options.handShakeDone == 0)) {
  82234. ExpectTrue((wolfSSL_connect(ssl_c) == WOLFSSL_SUCCESS) ||
  82235. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  82236. ExpectTrue((wolfSSL_accept(ssl_s) == WOLFSSL_SUCCESS) ||
  82237. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  82238. }
  82239. small = TLS13_TICKET_NONCE_STATIC_SZ;
  82240. #if TLS13_TICKET_NONCE_STATIC_SZ + 20 <= 255
  82241. medium = small + 20;
  82242. #else
  82243. medium = 255;
  82244. #endif
  82245. #if TLS13_TICKET_NONCE_STATIC_SZ + 20 + 20 <= 255
  82246. big = small + 20;
  82247. #else
  82248. big = 255;
  82249. #endif
  82250. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, small), TEST_SUCCESS);
  82251. ExpectPtrEq(ssl_c->session->ticketNonce.data,
  82252. ssl_c->session->ticketNonce.dataStatic);
  82253. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, medium),
  82254. TEST_SUCCESS);
  82255. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, big), TEST_SUCCESS);
  82256. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, medium),
  82257. TEST_SUCCESS);
  82258. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, small), TEST_SUCCESS);
  82259. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, small), TEST_SUCCESS);
  82260. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, medium), TEST_SUCCESS);
  82261. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, big), TEST_SUCCESS);
  82262. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, medium), TEST_SUCCESS);
  82263. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, small), TEST_SUCCESS);
  82264. wolfSSL_free(ssl_c);
  82265. wolfSSL_free(ssl_s);
  82266. wolfSSL_CTX_free(ctx_c);
  82267. wolfSSL_CTX_free(ctx_s);
  82268. return EXPECT_RESULT();
  82269. }
  82270. #endif /* WOLFSSL_TICKET_NONCE_MALLOC */
  82271. #if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_TLS12) && \
  82272. !defined(WOLFSSL_TICKET_DECRYPT_NO_CREATE) && \
  82273. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  82274. !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(NO_RSA) && \
  82275. defined(HAVE_ECC) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  82276. static int test_ticket_ret_create(void)
  82277. {
  82278. EXPECT_DECLS;
  82279. WOLFSSL_CTX *ctx_c = NULL;
  82280. WOLFSSL_CTX *ctx_s = NULL;
  82281. WOLFSSL *ssl_c = NULL;
  82282. WOLFSSL *ssl_s = NULL;
  82283. byte ticket[SESSION_TICKET_LEN];
  82284. struct test_memio_ctx test_ctx;
  82285. WOLFSSL_SESSION *sess = NULL;
  82286. word16 ticketLen = 0;
  82287. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82288. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82289. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  82290. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_NONE, 0);
  82291. wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_NONE, 0);
  82292. ExpectIntEQ(wolfSSL_CTX_UseSessionTicket(ctx_c), WOLFSSL_SUCCESS);
  82293. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  82294. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  82295. ExpectIntLE(sess->ticketLen, SESSION_TICKET_LEN);
  82296. if (sess != NULL) {
  82297. ticketLen = sess->ticketLen;
  82298. XMEMCPY(ticket, sess->ticket, sess->ticketLen);
  82299. }
  82300. wolfSSL_free(ssl_c);
  82301. ssl_c = NULL;
  82302. wolfSSL_free(ssl_s);
  82303. ssl_s = NULL;
  82304. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  82305. wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx);
  82306. wolfSSL_SetIOReadCtx(ssl_s, &test_ctx);
  82307. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  82308. wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx);
  82309. wolfSSL_SetIOReadCtx(ssl_c, &test_ctx);
  82310. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  82311. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  82312. ExpectIntLE(ssl_c->session->ticketLen, SESSION_TICKET_LEN);
  82313. ExpectIntEQ(ssl_c->session->ticketLen, ticketLen);
  82314. ExpectTrue(XMEMCMP(ssl_c->session->ticket, ticket, ticketLen) != 0);
  82315. wolfSSL_SESSION_free(sess);
  82316. wolfSSL_free(ssl_c);
  82317. wolfSSL_free(ssl_s);
  82318. wolfSSL_CTX_free(ctx_c);
  82319. wolfSSL_CTX_free(ctx_s);
  82320. return EXPECT_RESULT();
  82321. }
  82322. #else
  82323. static int test_ticket_ret_create(void)
  82324. {
  82325. return TEST_SKIPPED;
  82326. }
  82327. #endif
  82328. #if defined(WOLFSSL_TLS13) && !defined(NO_PSK) && \
  82329. defined(HAVE_SESSION_TICKET) && defined(OPENSSL_EXTRA) && \
  82330. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  82331. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  82332. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  82333. static void test_ticket_and_psk_mixing_on_result(WOLFSSL* ssl)
  82334. {
  82335. int ret;
  82336. WOLFSSL_SESSION* session = NULL;
  82337. AssertIntEQ(wolfSSL_get_current_cipher_suite(ssl), 0x1301);
  82338. if (!wolfSSL_is_server(ssl)) {
  82339. session = wolfSSL_SESSION_dup(wolfSSL_get_session(ssl));
  82340. AssertNotNull(session);
  82341. }
  82342. do {
  82343. ret = wolfSSL_shutdown(ssl);
  82344. } while (ret == WOLFSSL_SHUTDOWN_NOT_DONE);
  82345. AssertIntEQ(wolfSSL_clear(ssl), WOLFSSL_SUCCESS);
  82346. wolfSSL_set_psk_callback_ctx(ssl, (void*)"TLS13-AES256-GCM-SHA384");
  82347. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  82348. /* OpenSSL considers PSK to be verified. We error out with NO_PEER_CERT. */
  82349. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_NONE, NULL);
  82350. #endif
  82351. if (!wolfSSL_is_server(ssl)) {
  82352. /* client */
  82353. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  82354. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  82355. wolfSSL_set_session(ssl, session);
  82356. wolfSSL_SESSION_free(session);
  82357. wolfSSL_set_psk_client_tls13_callback(ssl, my_psk_client_tls13_cb);
  82358. AssertIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  82359. }
  82360. else {
  82361. /* server */
  82362. /* Different ciphersuite so that the ticket will be invalidated based on
  82363. * the ciphersuite */
  82364. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384"),
  82365. WOLFSSL_SUCCESS);
  82366. wolfSSL_set_psk_server_tls13_callback(ssl, my_psk_server_tls13_cb);
  82367. AssertIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  82368. }
  82369. }
  82370. static void test_ticket_and_psk_mixing_ssl_ready(WOLFSSL* ssl)
  82371. {
  82372. AssertIntEQ(wolfSSL_UseSessionTicket(ssl), WOLFSSL_SUCCESS);
  82373. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  82374. WOLFSSL_SUCCESS);
  82375. }
  82376. static int test_ticket_and_psk_mixing(void)
  82377. {
  82378. EXPECT_DECLS;
  82379. /* Test mixing tickets and regular PSK */
  82380. callback_functions client_cbs, server_cbs;
  82381. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  82382. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  82383. client_cbs.method = wolfTLSv1_3_client_method;
  82384. server_cbs.method = wolfTLSv1_3_server_method;
  82385. client_cbs.ssl_ready = test_ticket_and_psk_mixing_ssl_ready;
  82386. client_cbs.on_result = test_ticket_and_psk_mixing_on_result;
  82387. server_cbs.on_result = test_ticket_and_psk_mixing_on_result;
  82388. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  82389. ExpectIntEQ(client_cbs.return_code, TEST_SUCCESS);
  82390. ExpectIntEQ(server_cbs.return_code, TEST_SUCCESS);
  82391. return EXPECT_RESULT();
  82392. }
  82393. #else
  82394. static int test_ticket_and_psk_mixing(void)
  82395. {
  82396. return TEST_SKIPPED;
  82397. }
  82398. #endif
  82399. #if defined(WOLFSSL_TLS13) && !defined(NO_PSK) && defined(HAVE_SESSION_TICKET) \
  82400. && defined(OPENSSL_EXTRA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  82401. defined(HAVE_AESGCM) && !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  82402. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  82403. static int test_prioritize_psk_cb_called = FALSE;
  82404. static unsigned int test_prioritize_psk_cb(WOLFSSL* ssl,
  82405. const char* identity, unsigned char* key, unsigned int key_max_len,
  82406. const char** ciphersuite)
  82407. {
  82408. test_prioritize_psk_cb_called = TRUE;
  82409. return my_psk_server_tls13_cb(ssl, identity, key, key_max_len, ciphersuite);
  82410. }
  82411. static void test_prioritize_psk_on_result(WOLFSSL* ssl)
  82412. {
  82413. int ret;
  82414. WOLFSSL_SESSION* session = NULL;
  82415. AssertIntEQ(wolfSSL_get_current_cipher_suite(ssl), 0x1301);
  82416. if (!wolfSSL_is_server(ssl)) {
  82417. session = wolfSSL_SESSION_dup(wolfSSL_get_session(ssl));
  82418. AssertNotNull(session);
  82419. }
  82420. do {
  82421. ret = wolfSSL_shutdown(ssl);
  82422. } while (ret == WOLFSSL_SHUTDOWN_NOT_DONE);
  82423. AssertIntEQ(wolfSSL_clear(ssl), WOLFSSL_SUCCESS);
  82424. wolfSSL_set_psk_callback_ctx(ssl, (void*)"TLS13-AES256-GCM-SHA384");
  82425. /* Previous connection was made with TLS13-AES128-GCM-SHA256. Order is
  82426. * important. */
  82427. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  82428. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  82429. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  82430. /* OpenSSL considers PSK to be verified. We error out with NO_PEER_CERT. */
  82431. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_NONE, NULL);
  82432. #endif
  82433. if (!wolfSSL_is_server(ssl)) {
  82434. /* client */
  82435. wolfSSL_set_psk_client_tls13_callback(ssl, my_psk_client_tls13_cb);
  82436. wolfSSL_set_session(ssl, session);
  82437. wolfSSL_SESSION_free(session);
  82438. AssertIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  82439. }
  82440. else {
  82441. /* server */
  82442. wolfSSL_set_psk_server_tls13_callback(ssl, test_prioritize_psk_cb);
  82443. AssertIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  82444. #ifdef WOLFSSL_PRIORITIZE_PSK
  82445. /* The ticket should be first tried with all ciphersuites and chosen */
  82446. AssertFalse(test_prioritize_psk_cb_called);
  82447. #else
  82448. /* Ciphersuites should be tried with each PSK. This triggers the PSK
  82449. * callback that sets this var. */
  82450. AssertTrue(test_prioritize_psk_cb_called);
  82451. #endif
  82452. }
  82453. }
  82454. static void test_prioritize_psk_ssl_ready(WOLFSSL* ssl)
  82455. {
  82456. if (!wolfSSL_is_server(ssl))
  82457. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  82458. WOLFSSL_SUCCESS);
  82459. else
  82460. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  82461. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  82462. }
  82463. static int test_prioritize_psk(void)
  82464. {
  82465. EXPECT_DECLS;
  82466. /* We always send the ticket first. With WOLFSSL_PRIORITIZE_PSK the order
  82467. * of the PSK's will be followed instead of the ciphersuite. */
  82468. callback_functions client_cbs, server_cbs;
  82469. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  82470. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  82471. client_cbs.method = wolfTLSv1_3_client_method;
  82472. server_cbs.method = wolfTLSv1_3_server_method;
  82473. client_cbs.ssl_ready = test_prioritize_psk_ssl_ready;
  82474. server_cbs.ssl_ready = test_prioritize_psk_ssl_ready;
  82475. client_cbs.on_result = test_prioritize_psk_on_result;
  82476. server_cbs.on_result = test_prioritize_psk_on_result;
  82477. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  82478. ExpectIntEQ(client_cbs.return_code, TEST_SUCCESS);
  82479. ExpectIntEQ(server_cbs.return_code, TEST_SUCCESS);
  82480. return EXPECT_RESULT();
  82481. }
  82482. #else
  82483. static int test_prioritize_psk(void)
  82484. {
  82485. return TEST_SKIPPED;
  82486. }
  82487. #endif
  82488. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  82489. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  82490. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  82491. !defined(WOLFSSL_NO_TLS12)
  82492. static int test_wolfSSL_CTX_set_ciphersuites_ctx_ready_server(WOLFSSL_CTX* ctx)
  82493. {
  82494. EXPECT_DECLS;
  82495. ExpectTrue(SSL_CTX_set_cipher_list(ctx, "DEFAULT"));
  82496. /* Set TLS 1.3 specific suite */
  82497. ExpectTrue(SSL_CTX_set_ciphersuites(ctx, "TLS13-AES128-GCM-SHA256"));
  82498. return EXPECT_RESULT();
  82499. }
  82500. static int test_wolfSSL_CTX_set_ciphersuites(void)
  82501. {
  82502. EXPECT_DECLS;
  82503. /* Test using SSL_CTX_set_cipher_list and SSL_CTX_set_ciphersuites and then
  82504. * do a 1.2 connection. */
  82505. test_ssl_cbf client_cbs, server_cbs;
  82506. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  82507. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  82508. client_cbs.method = wolfTLSv1_2_client_method;
  82509. server_cbs.method = wolfTLS_server_method; /* Allow downgrade */
  82510. server_cbs.ctx_ready = test_wolfSSL_CTX_set_ciphersuites_ctx_ready_server;
  82511. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  82512. &server_cbs, NULL), TEST_SUCCESS);
  82513. return EXPECT_RESULT();
  82514. }
  82515. #else
  82516. static int test_wolfSSL_CTX_set_ciphersuites(void)
  82517. {
  82518. return TEST_SKIPPED;
  82519. }
  82520. #endif
  82521. #if defined(HAVE_CRL) && defined(WOLFSSL_CHECK_ALERT_ON_ERR) && \
  82522. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  82523. static int test_wolfSSL_CRL_CERT_REVOKED_alert_ctx_ready(WOLFSSL_CTX* ctx)
  82524. {
  82525. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  82526. return TEST_SUCCESS;
  82527. }
  82528. static int test_wolfSSL_CRL_CERT_REVOKED_alert_on_cleanup(WOLFSSL* ssl)
  82529. {
  82530. EXPECT_DECLS;
  82531. WOLFSSL_ALERT_HISTORY h;
  82532. ExpectIntEQ(wolfSSL_get_alert_history(ssl, &h), WOLFSSL_SUCCESS);
  82533. ExpectIntEQ(h.last_rx.level, alert_fatal);
  82534. ExpectIntEQ(h.last_rx.code, certificate_revoked);
  82535. return EXPECT_RESULT();
  82536. }
  82537. static int test_wolfSSL_CRL_CERT_REVOKED_alert(void)
  82538. {
  82539. EXPECT_DECLS;
  82540. test_ssl_cbf client_cbs, server_cbs;
  82541. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  82542. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  82543. server_cbs.certPemFile = "./certs/server-revoked-cert.pem";
  82544. server_cbs.keyPemFile = "./certs/server-revoked-key.pem";
  82545. client_cbs.crlPemFile = "./certs/crl/crl.revoked";
  82546. client_cbs.ctx_ready = test_wolfSSL_CRL_CERT_REVOKED_alert_ctx_ready;
  82547. server_cbs.on_cleanup = test_wolfSSL_CRL_CERT_REVOKED_alert_on_cleanup;
  82548. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  82549. &server_cbs, NULL), -1001);
  82550. return EXPECT_RESULT();
  82551. }
  82552. #else
  82553. static int test_wolfSSL_CRL_CERT_REVOKED_alert(void)
  82554. {
  82555. return TEST_SKIPPED;
  82556. }
  82557. #endif
  82558. #if defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET) \
  82559. && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  82560. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  82561. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256) && \
  82562. !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  82563. static WOLFSSL_CTX* test_TLS_13_ticket_different_ciphers_ctx = NULL;
  82564. static WOLFSSL_SESSION* test_TLS_13_ticket_different_ciphers_session = NULL;
  82565. static int test_TLS_13_ticket_different_ciphers_run = 0;
  82566. static int test_TLS_13_ticket_different_ciphers_ssl_ready(WOLFSSL* ssl)
  82567. {
  82568. EXPECT_DECLS;
  82569. switch (test_TLS_13_ticket_different_ciphers_run) {
  82570. case 0:
  82571. /* First run */
  82572. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  82573. WOLFSSL_SUCCESS);
  82574. if (wolfSSL_is_server(ssl)) {
  82575. ExpectNotNull(test_TLS_13_ticket_different_ciphers_ctx =
  82576. wolfSSL_get_SSL_CTX(ssl));
  82577. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_up_ref(
  82578. test_TLS_13_ticket_different_ciphers_ctx));
  82579. }
  82580. break;
  82581. case 1:
  82582. /* Second run */
  82583. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  82584. "TLS13-AES128-GCM-SHA256"),
  82585. WOLFSSL_SUCCESS);
  82586. if (!wolfSSL_is_server(ssl)) {
  82587. ExpectIntEQ(wolfSSL_set_session(ssl,
  82588. test_TLS_13_ticket_different_ciphers_session),
  82589. WOLFSSL_SUCCESS);
  82590. }
  82591. break;
  82592. default:
  82593. /* Bad state? */
  82594. Fail(("Should not enter here"), ("Should not enter here"));
  82595. }
  82596. return EXPECT_RESULT();
  82597. }
  82598. static int test_TLS_13_ticket_different_ciphers_on_result(WOLFSSL* ssl)
  82599. {
  82600. EXPECT_DECLS;
  82601. switch (test_TLS_13_ticket_different_ciphers_run) {
  82602. case 0:
  82603. /* First run */
  82604. ExpectNotNull(test_TLS_13_ticket_different_ciphers_session =
  82605. wolfSSL_get1_session(ssl));
  82606. break;
  82607. case 1:
  82608. /* Second run */
  82609. ExpectTrue(wolfSSL_session_reused(ssl));
  82610. break;
  82611. default:
  82612. /* Bad state? */
  82613. Fail(("Should not enter here"), ("Should not enter here"));
  82614. }
  82615. return EXPECT_RESULT();
  82616. }
  82617. static int test_TLS_13_ticket_different_ciphers(void)
  82618. {
  82619. EXPECT_DECLS;
  82620. /* Check that we handle the connection when the ticket doesn't match
  82621. * the first ciphersuite. */
  82622. test_ssl_cbf client_cbs, server_cbs;
  82623. struct test_params {
  82624. method_provider client_meth;
  82625. method_provider server_meth;
  82626. int doUdp;
  82627. } params[] = {
  82628. #ifdef WOLFSSL_DTLS13
  82629. /* Test that the stateless code handles sessions correctly */
  82630. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, 1},
  82631. #endif
  82632. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, 0},
  82633. };
  82634. size_t i;
  82635. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  82636. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  82637. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  82638. test_TLS_13_ticket_different_ciphers_run = 0;
  82639. client_cbs.doUdp = server_cbs.doUdp = params[i].doUdp;
  82640. client_cbs.method = params[i].client_meth;
  82641. server_cbs.method = params[i].server_meth;
  82642. client_cbs.ssl_ready = test_TLS_13_ticket_different_ciphers_ssl_ready;
  82643. server_cbs.ssl_ready = test_TLS_13_ticket_different_ciphers_ssl_ready;
  82644. client_cbs.on_result = test_TLS_13_ticket_different_ciphers_on_result;
  82645. server_cbs.ticNoInit = 1;
  82646. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  82647. &server_cbs, NULL), TEST_SUCCESS);
  82648. test_TLS_13_ticket_different_ciphers_run++;
  82649. server_cbs.ctx = test_TLS_13_ticket_different_ciphers_ctx;
  82650. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  82651. &server_cbs, NULL), TEST_SUCCESS);
  82652. wolfSSL_SESSION_free(test_TLS_13_ticket_different_ciphers_session);
  82653. test_TLS_13_ticket_different_ciphers_session = NULL;
  82654. wolfSSL_CTX_free(test_TLS_13_ticket_different_ciphers_ctx);
  82655. test_TLS_13_ticket_different_ciphers_ctx = NULL;
  82656. }
  82657. return EXPECT_RESULT();
  82658. }
  82659. #else
  82660. static int test_TLS_13_ticket_different_ciphers(void)
  82661. {
  82662. return TEST_SKIPPED;
  82663. }
  82664. #endif
  82665. #if defined(WOLFSSL_EXTRA_ALERTS) && !defined(WOLFSSL_NO_TLS12) && \
  82666. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  82667. #define TEST_WRONG_CS_CLIENT "DHE-RSA-AES128-SHA"
  82668. /* AKA TLS_DHE_RSA_WITH_AES_128_CBC_SHA */
  82669. byte test_extra_alerts_wrong_cs_sh[] = {
  82670. 0x16, 0x03, 0x03, 0x00, 0x56, 0x02, 0x00, 0x00, 0x52, 0x03, 0x03, 0xef,
  82671. 0x0c, 0x30, 0x98, 0xa2, 0xac, 0xfa, 0x68, 0xe9, 0x3e, 0xaa, 0x5c, 0xcf,
  82672. 0xa7, 0x42, 0x72, 0xaf, 0xa0, 0xe8, 0x39, 0x2b, 0x3e, 0x81, 0xa7, 0x7a,
  82673. 0xa5, 0x62, 0x8a, 0x0e, 0x41, 0xba, 0xda, 0x20, 0x18, 0x9f, 0xe1, 0x8c,
  82674. 0x1d, 0xc0, 0x37, 0x9c, 0xf4, 0x90, 0x5d, 0x8d, 0xa0, 0x79, 0xa7, 0x4b,
  82675. 0xa8, 0x79, 0xdf, 0xcd, 0x8d, 0xf5, 0xb5, 0x50, 0x5f, 0xf1, 0xdb, 0x4d,
  82676. 0xbb, 0x07, 0x54, 0x1c,
  82677. 0x00, 0x02, /* TLS_RSA_WITH_NULL_SHA */
  82678. 0x00, 0x00, 0x0a, 0x00, 0x0b, 0x00,
  82679. 0x02, 0x01, 0x00, 0x00, 0x17, 0x00, 0x00
  82680. };
  82681. static int test_extra_alerts_wrong_cs(void)
  82682. {
  82683. EXPECT_DECLS;
  82684. #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
  82685. struct test_memio_ctx test_ctx;
  82686. WOLFSSL_CTX *ctx_c = NULL;
  82687. WOLFSSL_ALERT_HISTORY h;
  82688. WOLFSSL *ssl_c = NULL;
  82689. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82690. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  82691. wolfTLSv1_2_client_method, NULL), 0);
  82692. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, TEST_WRONG_CS_CLIENT),
  82693. WOLFSSL_SUCCESS);
  82694. /* CH */
  82695. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82696. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82697. WOLFSSL_ERROR_WANT_READ);
  82698. /* consume CH */
  82699. test_ctx.s_len = 0;
  82700. /* inject SH */
  82701. XMEMCPY(test_ctx.c_buff, test_extra_alerts_wrong_cs_sh,
  82702. sizeof(test_extra_alerts_wrong_cs_sh));
  82703. test_ctx.c_len = sizeof(test_extra_alerts_wrong_cs_sh);
  82704. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82705. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82706. WOLFSSL_ERROR_WANT_READ);
  82707. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  82708. ExpectIntEQ(h.last_tx.code, handshake_failure);
  82709. ExpectIntEQ(h.last_tx.level, alert_fatal);
  82710. wolfSSL_free(ssl_c);
  82711. wolfSSL_CTX_free(ctx_c);
  82712. #endif
  82713. return EXPECT_RESULT();
  82714. }
  82715. #else
  82716. static int test_extra_alerts_wrong_cs(void)
  82717. {
  82718. return TEST_SKIPPED;
  82719. }
  82720. #endif
  82721. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_TLS12) && \
  82722. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  82723. #define TEST_CS_DOWNGRADE_CLIENT "ECDHE-RSA-AES256-GCM-SHA384"
  82724. byte test_wrong_cs_downgrade_sh[] = {
  82725. 0x16, 0x03, 0x03, 0x00, 0x56, 0x02, 0x00, 0x00, 0x52, 0x03, 0x03, 0x10,
  82726. 0x2c, 0x88, 0xd9, 0x7a, 0x23, 0xc9, 0xbd, 0x11, 0x3b, 0x64, 0x24, 0xab,
  82727. 0x5b, 0x45, 0x33, 0xf6, 0x2c, 0x34, 0xe4, 0xcf, 0xf4, 0x78, 0xc8, 0x62,
  82728. 0x06, 0xc7, 0xe5, 0x30, 0x39, 0xbf, 0xa1, 0x20, 0xa3, 0x06, 0x74, 0xc3,
  82729. 0xa9, 0x74, 0x52, 0x8a, 0xfb, 0xae, 0xf0, 0xd8, 0x6f, 0xb2, 0x9d, 0xfe,
  82730. 0x78, 0xf0, 0x3f, 0x51, 0x8f, 0x9c, 0xcf, 0xbe, 0x61, 0x43, 0x9d, 0xf8,
  82731. 0x85, 0xe5, 0x2f, 0x54,
  82732. 0xc0, 0x2f, /* ECDHE-RSA-AES128-GCM-SHA256 */
  82733. 0x00, 0x00, 0x0a, 0x00, 0x0b, 0x00,
  82734. 0x02, 0x01, 0x00, 0x00, 0x17, 0x00, 0x00
  82735. };
  82736. static int test_wrong_cs_downgrade(void)
  82737. {
  82738. EXPECT_DECLS;
  82739. #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  82740. struct test_memio_ctx test_ctx;
  82741. WOLFSSL_CTX *ctx_c = NULL;
  82742. WOLFSSL *ssl_c = NULL;
  82743. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82744. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  82745. wolfSSLv23_client_method, NULL), 0);
  82746. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, TEST_CS_DOWNGRADE_CLIENT),
  82747. WOLFSSL_SUCCESS);
  82748. /* CH */
  82749. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82750. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82751. WOLFSSL_ERROR_WANT_READ);
  82752. /* consume CH */
  82753. test_ctx.s_len = 0;
  82754. /* inject SH */
  82755. XMEMCPY(test_ctx.c_buff, test_wrong_cs_downgrade_sh,
  82756. sizeof(test_wrong_cs_downgrade_sh));
  82757. test_ctx.c_len = sizeof(test_wrong_cs_downgrade_sh);
  82758. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82759. #ifdef OPENSSL_EXTRA
  82760. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82761. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL));
  82762. #else
  82763. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82764. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR));
  82765. #endif /* OPENSSL_EXTRA */
  82766. wolfSSL_free(ssl_c);
  82767. wolfSSL_CTX_free(ctx_c);
  82768. #endif
  82769. return EXPECT_RESULT();
  82770. }
  82771. #else
  82772. static int test_wrong_cs_downgrade(void)
  82773. {
  82774. return TEST_SKIPPED;
  82775. }
  82776. #endif
  82777. #if !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_EXTRA_ALERTS) && \
  82778. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_SP_MATH)
  82779. static void test_remove_msg(byte *msg, int tail_len, int *len, int msg_length)
  82780. {
  82781. tail_len -= msg_length;
  82782. XMEMMOVE(msg, msg + msg_length, tail_len);
  82783. *len = *len - msg_length;
  82784. }
  82785. static int test_remove_hs_msg_from_buffer(byte *buf, int *len, byte type,
  82786. byte *found)
  82787. {
  82788. const unsigned int _HANDSHAKE_HEADER_SZ = 4;
  82789. const unsigned int _RECORD_HEADER_SZ = 5;
  82790. const int _change_cipher_hs = 55;
  82791. const int _change_cipher = 20;
  82792. const int _handshake = 22;
  82793. unsigned int tail_len;
  82794. byte *idx, *curr;
  82795. word8 currType;
  82796. word16 rLength;
  82797. word32 hLength;
  82798. idx = buf;
  82799. tail_len = (unsigned int)*len;
  82800. *found = 0;
  82801. while (tail_len > _RECORD_HEADER_SZ) {
  82802. curr = idx;
  82803. currType = *idx;
  82804. ato16(idx + 3, &rLength);
  82805. idx += _RECORD_HEADER_SZ;
  82806. tail_len -= _RECORD_HEADER_SZ;
  82807. if (tail_len < rLength)
  82808. return -1;
  82809. if (type == _change_cipher_hs && currType == _change_cipher) {
  82810. if (rLength != 1)
  82811. return -1;
  82812. /* match */
  82813. test_remove_msg(curr, *len - (int)(curr - buf),
  82814. len, _RECORD_HEADER_SZ + 1);
  82815. *found = 1;
  82816. return 0;
  82817. }
  82818. if (currType != _handshake) {
  82819. idx += rLength;
  82820. tail_len -= rLength;
  82821. continue;
  82822. }
  82823. if (rLength < _HANDSHAKE_HEADER_SZ)
  82824. return -1;
  82825. currType = *idx;
  82826. ato24(idx+1, &hLength);
  82827. hLength += _HANDSHAKE_HEADER_SZ;
  82828. if (tail_len < hLength)
  82829. return -1;
  82830. if (currType != type) {
  82831. idx += hLength;
  82832. tail_len -= hLength;
  82833. continue;
  82834. }
  82835. /* match */
  82836. test_remove_msg(curr, *len - (int)(curr - buf), len,
  82837. hLength + _RECORD_HEADER_SZ);
  82838. *found = 1;
  82839. return 0;
  82840. }
  82841. /* not found */
  82842. return 0;
  82843. }
  82844. static int test_remove_hs_message(byte hs_message_type,
  82845. int extra_round, byte alert_type)
  82846. {
  82847. EXPECT_DECLS;
  82848. WOLFSSL_CTX *ctx_c = NULL;
  82849. WOLFSSL_CTX *ctx_s = NULL;
  82850. WOLFSSL *ssl_c = NULL;
  82851. WOLFSSL *ssl_s = NULL;
  82852. struct test_memio_ctx test_ctx;
  82853. WOLFSSL_ALERT_HISTORY h;
  82854. byte found = 0;
  82855. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82856. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82857. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  82858. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82859. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82860. WOLFSSL_ERROR_WANT_READ);
  82861. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  82862. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82863. WOLFSSL_ERROR_WANT_READ);
  82864. if (extra_round) {
  82865. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82866. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82867. WOLFSSL_ERROR_WANT_READ);
  82868. /* this will complete handshake from server side */
  82869. ExpectIntEQ(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  82870. }
  82871. ExpectIntEQ(test_remove_hs_msg_from_buffer(test_ctx.c_buff,
  82872. &test_ctx.c_len, hs_message_type, &found), 0);
  82873. if (!found) {
  82874. wolfSSL_free(ssl_c);
  82875. wolfSSL_CTX_free(ctx_c);
  82876. wolfSSL_free(ssl_s);
  82877. wolfSSL_CTX_free(ctx_s);
  82878. return TEST_SKIPPED;
  82879. }
  82880. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82881. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82882. WOLFSSL_ERROR_WANT_READ);
  82883. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  82884. ExpectTrue(alert_type == 0xff || h.last_tx.code == alert_type);
  82885. ExpectIntEQ(h.last_tx.level, alert_fatal);
  82886. wolfSSL_free(ssl_c);
  82887. wolfSSL_CTX_free(ctx_c);
  82888. wolfSSL_free(ssl_s);
  82889. wolfSSL_CTX_free(ctx_s);
  82890. return EXPECT_RESULT();
  82891. }
  82892. static int test_extra_alerts_skip_hs(void)
  82893. {
  82894. EXPECT_DECLS;
  82895. const byte _server_key_exchange = 12;
  82896. const byte _server_hello = 2;
  82897. const byte _certificate = 11;
  82898. /* server_hello */
  82899. ExpectIntNE(test_remove_hs_message(_server_hello, 0,
  82900. unexpected_message), TEST_FAIL);
  82901. ExpectIntNE(test_remove_hs_message(_certificate, 0,
  82902. 0xff), TEST_FAIL);
  82903. ExpectIntNE(test_remove_hs_message(_server_key_exchange, 0,
  82904. unexpected_message), TEST_FAIL);
  82905. return EXPECT_RESULT();
  82906. }
  82907. #else
  82908. static int test_extra_alerts_skip_hs(void)
  82909. {
  82910. return TEST_SKIPPED;
  82911. }
  82912. #endif
  82913. #if !defined(WOLFSSL_NO_TLS12) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  82914. && defined(WOLFSSL_EXTRA_ALERTS) && !defined(NO_PSK) && !defined(NO_DH)
  82915. static unsigned int test_server_psk_cb(WOLFSSL* ssl, const char* id,
  82916. unsigned char* key, unsigned int key_max_len)
  82917. {
  82918. (void)ssl;
  82919. (void)id;
  82920. (void)key_max_len;
  82921. /* zero means error */
  82922. key[0] = 0x10;
  82923. return 1;
  82924. }
  82925. static int test_extra_alerts_bad_psk(void)
  82926. {
  82927. EXPECT_DECLS;
  82928. WOLFSSL_CTX *ctx_c = NULL;
  82929. WOLFSSL_CTX *ctx_s = NULL;
  82930. WOLFSSL *ssl_c = NULL;
  82931. WOLFSSL *ssl_s = NULL;
  82932. struct test_memio_ctx test_ctx;
  82933. WOLFSSL_ALERT_HISTORY h;
  82934. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82935. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82936. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  82937. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, "DHE-PSK-AES128-GCM-SHA256"),
  82938. WOLFSSL_SUCCESS);
  82939. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, "DHE-PSK-AES128-GCM-SHA256"),
  82940. WOLFSSL_SUCCESS);
  82941. wolfSSL_set_psk_server_callback(ssl_s, test_server_psk_cb);
  82942. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82943. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82944. WOLFSSL_ERROR_WANT_READ);
  82945. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  82946. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82947. WOLFSSL_ERROR_WANT_READ);
  82948. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82949. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82950. WOLFSSL_ERROR_WANT_READ);
  82951. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  82952. ExpectIntEQ(h.last_tx.code, handshake_failure);
  82953. ExpectIntEQ(h.last_tx.level, alert_fatal);
  82954. wolfSSL_free(ssl_c);
  82955. wolfSSL_CTX_free(ctx_c);
  82956. wolfSSL_free(ssl_s);
  82957. wolfSSL_CTX_free(ctx_s);
  82958. return EXPECT_RESULT();
  82959. }
  82960. #else
  82961. static int test_extra_alerts_bad_psk(void)
  82962. {
  82963. return TEST_SKIPPED;
  82964. }
  82965. #endif
  82966. #if defined(OPENSSL_EXTRA) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  82967. /*
  82968. * Emulates wolfSSL_shutdown that goes on EAGAIN,
  82969. * by returning on output WOLFSSL_ERROR_WANT_WRITE.*/
  82970. static int custom_wolfSSL_shutdown(WOLFSSL *ssl, char *buf,
  82971. int sz, void *ctx)
  82972. {
  82973. (void)ssl;
  82974. (void)buf;
  82975. (void)ctx;
  82976. (void)sz;
  82977. return WOLFSSL_CBIO_ERR_WANT_WRITE;
  82978. }
  82979. static int test_multiple_alerts_EAGAIN(void)
  82980. {
  82981. EXPECT_DECLS;
  82982. size_t size_of_last_packet = 0;
  82983. /* declare wolfSSL objects */
  82984. struct test_memio_ctx test_ctx;
  82985. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  82986. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  82987. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82988. /* Create and initialize WOLFSSL_CTX and WOLFSSL objects */
  82989. #ifdef USE_TLSV13
  82990. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82991. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  82992. #else
  82993. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82994. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  82995. #endif
  82996. ExpectNotNull(ctx_c);
  82997. ExpectNotNull(ssl_c);
  82998. ExpectNotNull(ctx_s);
  82999. ExpectNotNull(ssl_s);
  83000. /* Load client certificates into WOLFSSL_CTX */
  83001. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_c, "./certs/ca-cert.pem", NULL), WOLFSSL_SUCCESS);
  83002. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  83003. /*
  83004. * We set the custom callback for the IO to emulate multiple EAGAINs
  83005. * on shutdown, so we can check that we don't send multiple packets.
  83006. * */
  83007. wolfSSL_SSLSetIOSend(ssl_c, custom_wolfSSL_shutdown);
  83008. /*
  83009. * We call wolfSSL_shutdown multiple times to reproduce the behaviour,
  83010. * to check that it doesn't add the CLOSE_NOTIFY packet multiple times
  83011. * on the output buffer.
  83012. * */
  83013. wolfSSL_shutdown(ssl_c);
  83014. wolfSSL_shutdown(ssl_c);
  83015. if (ssl_c != NULL) {
  83016. size_of_last_packet = ssl_c->buffers.outputBuffer.length;
  83017. }
  83018. wolfSSL_shutdown(ssl_c);
  83019. /*
  83020. * Finally we check the length of the output buffer.
  83021. * */
  83022. ExpectIntEQ((ssl_c->buffers.outputBuffer.length - size_of_last_packet), 0);
  83023. /* Cleanup and return */
  83024. wolfSSL_CTX_free(ctx_c);
  83025. wolfSSL_free(ssl_c);
  83026. wolfSSL_CTX_free(ctx_s);
  83027. wolfSSL_free(ssl_s);
  83028. return EXPECT_RESULT();
  83029. }
  83030. #else
  83031. static int test_multiple_alerts_EAGAIN(void)
  83032. {
  83033. return TEST_SKIPPED;
  83034. }
  83035. #endif
  83036. #if defined(WOLFSSL_TLS13) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  83037. && !defined(NO_PSK)
  83038. static unsigned int test_tls13_bad_psk_binder_client_cb(WOLFSSL* ssl,
  83039. const char* hint, char* identity, unsigned int id_max_len,
  83040. unsigned char* key, unsigned int key_max_len)
  83041. {
  83042. (void)ssl;
  83043. (void)hint;
  83044. (void)key_max_len;
  83045. /* see internal.h MAX_PSK_ID_LEN for PSK identity limit */
  83046. XSTRNCPY(identity, "Client_identity", id_max_len);
  83047. key[0] = 0x20;
  83048. return 1;
  83049. }
  83050. static unsigned int test_tls13_bad_psk_binder_server_cb(WOLFSSL* ssl,
  83051. const char* id, unsigned char* key, unsigned int key_max_len)
  83052. {
  83053. (void)ssl;
  83054. (void)id;
  83055. (void)key_max_len;
  83056. /* zero means error */
  83057. key[0] = 0x10;
  83058. return 1;
  83059. }
  83060. #endif
  83061. static int test_tls13_bad_psk_binder(void)
  83062. {
  83063. EXPECT_DECLS;
  83064. #if defined(WOLFSSL_TLS13) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  83065. && !defined(NO_PSK)
  83066. WOLFSSL_CTX *ctx_c = NULL;
  83067. WOLFSSL_CTX *ctx_s = NULL;
  83068. WOLFSSL *ssl_c = NULL;
  83069. WOLFSSL *ssl_s = NULL;
  83070. struct test_memio_ctx test_ctx;
  83071. WOLFSSL_ALERT_HISTORY h;
  83072. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83073. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83074. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  83075. wolfSSL_set_psk_client_callback(ssl_c, test_tls13_bad_psk_binder_client_cb);
  83076. wolfSSL_set_psk_server_callback(ssl_s, test_tls13_bad_psk_binder_server_cb);
  83077. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  83078. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83079. WOLFSSL_ERROR_WANT_READ);
  83080. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  83081. ExpectIntEQ( wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83082. WC_NO_ERR_TRACE(BAD_BINDER));
  83083. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  83084. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83085. WC_NO_ERR_TRACE(FATAL_ERROR));
  83086. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  83087. ExpectIntEQ(h.last_rx.code, illegal_parameter);
  83088. ExpectIntEQ(h.last_rx.level, alert_fatal);
  83089. wolfSSL_free(ssl_c);
  83090. wolfSSL_CTX_free(ctx_c);
  83091. wolfSSL_free(ssl_s);
  83092. wolfSSL_CTX_free(ctx_s);
  83093. #endif
  83094. return EXPECT_RESULT();
  83095. }
  83096. #if defined(WOLFSSL_HARDEN_TLS) && !defined(WOLFSSL_NO_TLS12) && \
  83097. defined(HAVE_IO_TESTS_DEPENDENCIES)
  83098. static int test_harden_no_secure_renegotiation_io_cb(WOLFSSL *ssl, char *buf,
  83099. int sz, void *ctx)
  83100. {
  83101. static int sentServerHello = FALSE;
  83102. if (!sentServerHello) {
  83103. byte renegExt[] = { 0xFF, 0x01, 0x00, 0x01, 0x00 };
  83104. size_t i;
  83105. if (sz < (int)sizeof(renegExt))
  83106. return WOLFSSL_CBIO_ERR_GENERAL;
  83107. /* Remove SCR from ServerHello */
  83108. for (i = 0; i < sz - sizeof(renegExt); i++) {
  83109. if (XMEMCMP(buf + i, renegExt, sizeof(renegExt)) == 0) {
  83110. /* Found the extension. Change it to something unrecognized. */
  83111. buf[i+1] = 0x11;
  83112. break;
  83113. }
  83114. }
  83115. sentServerHello = TRUE;
  83116. }
  83117. return EmbedSend(ssl, buf, sz, ctx);
  83118. }
  83119. static void test_harden_no_secure_renegotiation_ssl_ready(WOLFSSL* ssl)
  83120. {
  83121. wolfSSL_SSLSetIOSend(ssl, test_harden_no_secure_renegotiation_io_cb);
  83122. }
  83123. static void test_harden_no_secure_renegotiation_on_cleanup(WOLFSSL* ssl)
  83124. {
  83125. WOLFSSL_ALERT_HISTORY h;
  83126. AssertIntEQ(wolfSSL_get_alert_history(ssl, &h), WOLFSSL_SUCCESS);
  83127. AssertIntEQ(h.last_rx.code, handshake_failure);
  83128. AssertIntEQ(h.last_rx.level, alert_fatal);
  83129. }
  83130. static int test_harden_no_secure_renegotiation(void)
  83131. {
  83132. EXPECT_DECLS;
  83133. callback_functions client_cbs, server_cbs;
  83134. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  83135. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  83136. client_cbs.method = wolfTLSv1_2_client_method;
  83137. server_cbs.method = wolfTLSv1_2_server_method;
  83138. server_cbs.ssl_ready = test_harden_no_secure_renegotiation_ssl_ready;
  83139. server_cbs.on_cleanup = test_harden_no_secure_renegotiation_on_cleanup;
  83140. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  83141. ExpectIntEQ(client_cbs.return_code, TEST_FAIL);
  83142. ExpectIntEQ(client_cbs.last_err, WC_NO_ERR_TRACE(SECURE_RENEGOTIATION_E));
  83143. ExpectIntEQ(server_cbs.return_code, TEST_FAIL);
  83144. ExpectTrue(server_cbs.last_err == WC_NO_ERR_TRACE(SOCKET_ERROR_E) ||
  83145. server_cbs.last_err == WC_NO_ERR_TRACE(FATAL_ERROR));
  83146. return EXPECT_RESULT();
  83147. }
  83148. #else
  83149. static int test_harden_no_secure_renegotiation(void)
  83150. {
  83151. return TEST_SKIPPED;
  83152. }
  83153. #endif
  83154. #if defined(HAVE_OCSP) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  83155. static int test_override_alt_cert_chain_cert_cb(int preverify,
  83156. WOLFSSL_X509_STORE_CTX* store)
  83157. {
  83158. fprintf(stderr, "preverify: %d\n", preverify);
  83159. fprintf(stderr, "store->error: %d\n", store->error);
  83160. fprintf(stderr, "error reason: %s\n", wolfSSL_ERR_reason_error_string(store->error));
  83161. if (store->error == WC_NO_ERR_TRACE(OCSP_INVALID_STATUS)) {
  83162. fprintf(stderr, "Overriding OCSP error\n");
  83163. return 1;
  83164. }
  83165. #ifndef WOLFSSL_ALT_CERT_CHAINS
  83166. else if ((store->error == WC_NO_ERR_TRACE(ASN_NO_SIGNER_E) ||
  83167. store->error == WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E)
  83168. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  83169. defined(HAVE_WEBSERVER)
  83170. || store->error == WOLFSSL_X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY
  83171. #endif
  83172. ) && store->error_depth == store->totalCerts - 1) {
  83173. fprintf(stderr, "Overriding no signer error only for root cert\n");
  83174. return 1;
  83175. }
  83176. #endif
  83177. else
  83178. return preverify;
  83179. }
  83180. static int test_override_alt_cert_chain_ocsp_cb(void* ioCtx, const char* url,
  83181. int urlSz, unsigned char* request, int requestSz,
  83182. unsigned char** response)
  83183. {
  83184. (void)ioCtx;
  83185. (void)url;
  83186. (void)urlSz;
  83187. (void)request;
  83188. (void)requestSz;
  83189. (void)response;
  83190. return -1;
  83191. }
  83192. static int test_override_alt_cert_chain_client_ctx_ready(WOLFSSL_CTX* ctx)
  83193. {
  83194. EXPECT_DECLS;
  83195. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER,
  83196. test_override_alt_cert_chain_cert_cb);
  83197. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL |
  83198. WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  83199. ExpectIntEQ(wolfSSL_CTX_SetOCSP_Cb(ctx,
  83200. test_override_alt_cert_chain_ocsp_cb, NULL, NULL), WOLFSSL_SUCCESS);
  83201. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx, "not a url"),
  83202. WOLFSSL_SUCCESS);
  83203. return EXPECT_RESULT();
  83204. }
  83205. static int test_override_alt_cert_chain_client_ctx_ready2(WOLFSSL_CTX* ctx)
  83206. {
  83207. EXPECT_DECLS;
  83208. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  83209. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL |
  83210. WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  83211. ExpectIntEQ(wolfSSL_CTX_SetOCSP_Cb(ctx,
  83212. test_override_alt_cert_chain_ocsp_cb, NULL, NULL), WOLFSSL_SUCCESS);
  83213. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx, "not a url"),
  83214. WOLFSSL_SUCCESS);
  83215. return EXPECT_RESULT();
  83216. }
  83217. static int test_override_alt_cert_chain_server_ctx_ready(WOLFSSL_CTX* ctx)
  83218. {
  83219. EXPECT_DECLS;
  83220. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx,
  83221. "./certs/intermediate/server-chain-alt.pem"), WOLFSSL_SUCCESS);
  83222. return EXPECT_RESULT();
  83223. }
  83224. static int test_override_alt_cert_chain(void)
  83225. {
  83226. EXPECT_DECLS;
  83227. size_t i;
  83228. struct test_params {
  83229. ctx_cb client_ctx_cb;
  83230. ctx_cb server_ctx_cb;
  83231. int result;
  83232. } params[] = {
  83233. {test_override_alt_cert_chain_client_ctx_ready,
  83234. test_override_alt_cert_chain_server_ctx_ready, TEST_SUCCESS},
  83235. {test_override_alt_cert_chain_client_ctx_ready2,
  83236. test_override_alt_cert_chain_server_ctx_ready, -1001},
  83237. };
  83238. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  83239. test_ssl_cbf client_cbs, server_cbs;
  83240. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  83241. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  83242. fprintf(stderr, "test config: %d\n", (int)i);
  83243. client_cbs.ctx_ready = params[i].client_ctx_cb;
  83244. server_cbs.ctx_ready = params[i].server_ctx_cb;
  83245. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  83246. &server_cbs, NULL), params[i].result);
  83247. ExpectIntEQ(client_cbs.return_code,
  83248. params[i].result <= 0 ? -1000 : TEST_SUCCESS);
  83249. ExpectIntEQ(server_cbs.return_code,
  83250. params[i].result <= 0 ? -1000 : TEST_SUCCESS);
  83251. }
  83252. return EXPECT_RESULT();
  83253. }
  83254. #else
  83255. static int test_override_alt_cert_chain(void)
  83256. {
  83257. return TEST_SKIPPED;
  83258. }
  83259. #endif
  83260. #if defined(HAVE_RPK)
  83261. #define svrRpkCertFile "./certs/rpk/server-cert-rpk.der"
  83262. #define clntRpkCertFile "./certs/rpk/client-cert-rpk.der"
  83263. #if defined(WOLFSSL_ALWAYS_VERIFY_CB) && defined(WOLFSSL_TLS13)
  83264. static int MyRpkVerifyCb(int mode, WOLFSSL_X509_STORE_CTX* strctx)
  83265. {
  83266. int ret = WOLFSSL_SUCCESS;
  83267. (void)mode;
  83268. (void)strctx;
  83269. WOLFSSL_ENTER("MyRpkVerifyCb");
  83270. return ret;
  83271. }
  83272. #endif /* WOLFSSL_ALWAYS_VERIFY_CB && WOLFSSL_TLS13 */
  83273. static WC_INLINE int test_rpk_memio_setup(
  83274. struct test_memio_ctx *ctx,
  83275. WOLFSSL_CTX **ctx_c,
  83276. WOLFSSL_CTX **ctx_s,
  83277. WOLFSSL **ssl_c,
  83278. WOLFSSL **ssl_s,
  83279. method_provider method_c,
  83280. method_provider method_s,
  83281. const char* certfile_c, int fmt_cc, /* client cert file path and format */
  83282. const char* certfile_s, int fmt_cs, /* server cert file path and format */
  83283. const char* pkey_c, int fmt_kc, /* client private key and format */
  83284. const char* pkey_s, int fmt_ks /* server private key and format */
  83285. )
  83286. {
  83287. int ret;
  83288. if (ctx_c != NULL && *ctx_c == NULL) {
  83289. *ctx_c = wolfSSL_CTX_new(method_c());
  83290. if (*ctx_c == NULL) {
  83291. return -1;
  83292. }
  83293. wolfSSL_CTX_set_verify(*ctx_c, WOLFSSL_VERIFY_PEER, NULL);
  83294. ret = wolfSSL_CTX_load_verify_locations(*ctx_c, caCertFile, 0);
  83295. if (ret != WOLFSSL_SUCCESS) {
  83296. return -1;
  83297. }
  83298. wolfSSL_SetIORecv(*ctx_c, test_memio_read_cb);
  83299. wolfSSL_SetIOSend(*ctx_c, test_memio_write_cb);
  83300. ret = wolfSSL_CTX_use_certificate_file(*ctx_c, certfile_c, fmt_cc);
  83301. if (ret != WOLFSSL_SUCCESS) {
  83302. return -1;
  83303. }
  83304. ret = wolfSSL_CTX_use_PrivateKey_file(*ctx_c, pkey_c, fmt_kc);
  83305. if (ret != WOLFSSL_SUCCESS) {
  83306. return -1;
  83307. }
  83308. }
  83309. if (ctx_s != NULL && *ctx_s == NULL) {
  83310. *ctx_s = wolfSSL_CTX_new(method_s());
  83311. if (*ctx_s == NULL) {
  83312. return -1;
  83313. }
  83314. wolfSSL_CTX_set_verify(*ctx_s, WOLFSSL_VERIFY_PEER, NULL);
  83315. ret = wolfSSL_CTX_load_verify_locations(*ctx_s, cliCertFile, 0);
  83316. if (ret != WOLFSSL_SUCCESS) {
  83317. return -1;
  83318. }
  83319. ret = wolfSSL_CTX_use_PrivateKey_file(*ctx_s, pkey_s, fmt_ks);
  83320. if (ret != WOLFSSL_SUCCESS) {
  83321. return -1;
  83322. }
  83323. ret = wolfSSL_CTX_use_certificate_file(*ctx_s, certfile_s, fmt_cs);
  83324. if (ret != WOLFSSL_SUCCESS) {
  83325. return -1;
  83326. }
  83327. wolfSSL_SetIORecv(*ctx_s, test_memio_read_cb);
  83328. wolfSSL_SetIOSend(*ctx_s, test_memio_write_cb);
  83329. if (ctx->s_ciphers != NULL) {
  83330. ret = wolfSSL_CTX_set_cipher_list(*ctx_s, ctx->s_ciphers);
  83331. if (ret != WOLFSSL_SUCCESS) {
  83332. return -1;
  83333. }
  83334. }
  83335. }
  83336. if (ctx_c != NULL && ssl_c != NULL) {
  83337. *ssl_c = wolfSSL_new(*ctx_c);
  83338. if (*ssl_c == NULL) {
  83339. return -1;
  83340. }
  83341. wolfSSL_SetIOWriteCtx(*ssl_c, ctx);
  83342. wolfSSL_SetIOReadCtx(*ssl_c, ctx);
  83343. }
  83344. if (ctx_s != NULL && ssl_s != NULL) {
  83345. *ssl_s = wolfSSL_new(*ctx_s);
  83346. if (*ssl_s == NULL) {
  83347. return -1;
  83348. }
  83349. wolfSSL_SetIOWriteCtx(*ssl_s, ctx);
  83350. wolfSSL_SetIOReadCtx(*ssl_s, ctx);
  83351. #if !defined(NO_DH)
  83352. SetDH(*ssl_s);
  83353. #endif
  83354. }
  83355. return 0;
  83356. }
  83357. #endif /* HAVE_RPK */
  83358. static int test_rpk_set_xxx_cert_type(void)
  83359. {
  83360. EXPECT_DECLS;
  83361. #if defined(HAVE_RPK)
  83362. char ctype[MAX_CLIENT_CERT_TYPE_CNT + 1]; /* prepare bigger buffer */
  83363. WOLFSSL_CTX* ctx = NULL;
  83364. WOLFSSL* ssl = NULL;
  83365. int tp;
  83366. ctx = wolfSSL_CTX_new(wolfTLS_client_method());
  83367. ExpectNotNull(ctx);
  83368. ssl = wolfSSL_new(ctx);
  83369. ExpectNotNull(ssl);
  83370. /*--------------------------------------------*/
  83371. /* tests for wolfSSL_CTX_set_client_cert_type */
  83372. /*--------------------------------------------*/
  83373. /* illegal parameter test caces */
  83374. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(NULL, ctype,
  83375. MAX_CLIENT_CERT_TYPE_CNT),
  83376. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83377. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  83378. sizeof(ctype)),
  83379. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83380. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  83381. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  83382. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  83383. MAX_CLIENT_CERT_TYPE_CNT),
  83384. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83385. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  83386. ctype[1] = 10; /* set unknown cert type */
  83387. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  83388. MAX_CLIENT_CERT_TYPE_CNT),
  83389. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83390. /* pass larger type count */
  83391. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  83392. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  83393. ctype[2] = 1; /* pass unacceptable type count */
  83394. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  83395. MAX_CLIENT_CERT_TYPE_CNT + 1),
  83396. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83397. /* should accept NULL for type buffer */
  83398. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, NULL,
  83399. MAX_CLIENT_CERT_TYPE_CNT),
  83400. WOLFSSL_SUCCESS);
  83401. /* should accept zero for type count */
  83402. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  83403. 0),
  83404. WOLFSSL_SUCCESS);
  83405. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  83406. MAX_CLIENT_CERT_TYPE_CNT),
  83407. WOLFSSL_SUCCESS);
  83408. /*--------------------------------------------*/
  83409. /* tests for wolfSSL_CTX_set_server_cert_type */
  83410. /*--------------------------------------------*/
  83411. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(NULL, ctype,
  83412. MAX_SERVER_CERT_TYPE_CNT),
  83413. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83414. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  83415. sizeof(ctype)),
  83416. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83417. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  83418. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  83419. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  83420. MAX_SERVER_CERT_TYPE_CNT),
  83421. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83422. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  83423. ctype[1] = 10; /* set unknown cert type */
  83424. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  83425. MAX_SERVER_CERT_TYPE_CNT),
  83426. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83427. /* pass larger type count */
  83428. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  83429. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  83430. ctype[2] = 1; /* pass unacceptable type count */
  83431. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  83432. MAX_SERVER_CERT_TYPE_CNT + 1),
  83433. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83434. /* should accept NULL for type buffer */
  83435. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, NULL,
  83436. MAX_SERVER_CERT_TYPE_CNT),
  83437. WOLFSSL_SUCCESS);
  83438. /* should accept zero for type count */
  83439. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  83440. 0),
  83441. WOLFSSL_SUCCESS);
  83442. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  83443. MAX_CLIENT_CERT_TYPE_CNT),
  83444. WOLFSSL_SUCCESS);
  83445. /*--------------------------------------------*/
  83446. /* tests for wolfSSL_set_client_cert_type */
  83447. /*--------------------------------------------*/
  83448. ExpectIntEQ(wolfSSL_set_client_cert_type(NULL, ctype,
  83449. MAX_CLIENT_CERT_TYPE_CNT),
  83450. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83451. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  83452. sizeof(ctype)),
  83453. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83454. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  83455. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  83456. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  83457. MAX_CLIENT_CERT_TYPE_CNT),
  83458. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83459. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  83460. ctype[1] = 10; /* set unknown cert type */
  83461. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  83462. MAX_CLIENT_CERT_TYPE_CNT),
  83463. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83464. /* pass larger type count */
  83465. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  83466. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  83467. ctype[2] = 1; /* pass unacceptable type count */
  83468. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  83469. MAX_CLIENT_CERT_TYPE_CNT + 1),
  83470. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83471. /* should accept NULL for type buffer */
  83472. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, NULL,
  83473. MAX_CLIENT_CERT_TYPE_CNT),
  83474. WOLFSSL_SUCCESS);
  83475. /* should accept zero for type count */
  83476. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  83477. 0),
  83478. WOLFSSL_SUCCESS);
  83479. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  83480. MAX_CLIENT_CERT_TYPE_CNT),
  83481. WOLFSSL_SUCCESS);
  83482. /*--------------------------------------------*/
  83483. /* tests for wolfSSL_CTX_set_server_cert_type */
  83484. /*--------------------------------------------*/
  83485. ExpectIntEQ(wolfSSL_set_server_cert_type(NULL, ctype,
  83486. MAX_SERVER_CERT_TYPE_CNT),
  83487. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83488. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  83489. sizeof(ctype)),
  83490. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83491. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  83492. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  83493. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  83494. MAX_SERVER_CERT_TYPE_CNT),
  83495. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83496. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  83497. ctype[1] = 10; /* set unknown cert type */
  83498. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  83499. MAX_SERVER_CERT_TYPE_CNT),
  83500. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83501. /* pass larger type count */
  83502. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  83503. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  83504. ctype[2] = 1; /* pass unacceptable type count */
  83505. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  83506. MAX_SERVER_CERT_TYPE_CNT + 1),
  83507. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83508. /* should accept NULL for type buffer */
  83509. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, NULL,
  83510. MAX_SERVER_CERT_TYPE_CNT),
  83511. WOLFSSL_SUCCESS);
  83512. /* should accept zero for type count */
  83513. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  83514. 0),
  83515. WOLFSSL_SUCCESS);
  83516. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  83517. MAX_SERVER_CERT_TYPE_CNT),
  83518. WOLFSSL_SUCCESS);
  83519. /*------------------------------------------------*/
  83520. /* tests for wolfSSL_get_negotiated_xxx_cert_type */
  83521. /*------------------------------------------------*/
  83522. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(NULL, &tp),
  83523. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83524. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl, NULL),
  83525. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83526. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(NULL, &tp),
  83527. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83528. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl, NULL),
  83529. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83530. /* clean up */
  83531. wolfSSL_free(ssl);
  83532. wolfSSL_CTX_free(ctx);
  83533. #endif
  83534. return EXPECT_RESULT();
  83535. }
  83536. static int test_tls13_rpk_handshake(void)
  83537. {
  83538. EXPECT_DECLS;
  83539. #if defined(HAVE_RPK) && (!defined(WOLFSSL_NO_TLS12) || defined(WOLFSSL_TLS13))
  83540. #ifdef WOLFSSL_TLS13
  83541. int ret = 0;
  83542. #endif
  83543. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  83544. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  83545. struct test_memio_ctx test_ctx;
  83546. int err;
  83547. char certType_c[MAX_CLIENT_CERT_TYPE_CNT];
  83548. char certType_s[MAX_CLIENT_CERT_TYPE_CNT];
  83549. int typeCnt_c;
  83550. int typeCnt_s;
  83551. int tp = 0;
  83552. #if defined(WOLFSSL_ALWAYS_VERIFY_CB) && defined(WOLFSSL_TLS13)
  83553. int isServer;
  83554. #endif
  83555. (void)err;
  83556. (void)typeCnt_c;
  83557. (void)typeCnt_s;
  83558. (void)certType_c;
  83559. (void)certType_s;
  83560. #ifndef WOLFSSL_NO_TLS12
  83561. /* TLS1.2
  83562. * Both client and server load x509 cert and start handshaking.
  83563. * Check no negotiation occurred.
  83564. */
  83565. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83566. ExpectIntEQ(
  83567. test_rpk_memio_setup(
  83568. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83569. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  83570. cliCertFile, WOLFSSL_FILETYPE_PEM,
  83571. svrCertFile, WOLFSSL_FILETYPE_PEM,
  83572. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83573. svrKeyFile, WOLFSSL_FILETYPE_PEM)
  83574. , 0);
  83575. /* set client certificate type in client end */
  83576. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83577. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  83578. typeCnt_c = 2;
  83579. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  83580. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  83581. typeCnt_s = 2;
  83582. /* both client and server do not call client/server_cert_type APIs,
  83583. * expecting default settings works and no negotiation performed.
  83584. */
  83585. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  83586. return TEST_FAIL;
  83587. /* confirm no negotiation occurred */
  83588. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83589. WOLFSSL_SUCCESS);
  83590. ExpectIntEQ((int)tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83591. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83592. WOLFSSL_SUCCESS);
  83593. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83594. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83595. WOLFSSL_SUCCESS);
  83596. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83597. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83598. WOLFSSL_SUCCESS);
  83599. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83600. (void)typeCnt_c;
  83601. (void)typeCnt_s;
  83602. wolfSSL_free(ssl_c);
  83603. wolfSSL_CTX_free(ctx_c);
  83604. wolfSSL_free(ssl_s);
  83605. wolfSSL_CTX_free(ctx_s);
  83606. ssl_c = ssl_s = NULL;
  83607. ctx_c = ctx_s = NULL;
  83608. #endif
  83609. #ifdef WOLFSSL_TLS13
  83610. /* Both client and server load x509 cert and start handshaking.
  83611. * Check no negotiation occurred.
  83612. */
  83613. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83614. ExpectIntEQ(
  83615. test_rpk_memio_setup(
  83616. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83617. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  83618. cliCertFile, WOLFSSL_FILETYPE_PEM,
  83619. svrCertFile, WOLFSSL_FILETYPE_PEM,
  83620. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83621. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83622. , 0);
  83623. /* set client certificate type in client end */
  83624. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83625. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  83626. typeCnt_c = 2;
  83627. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  83628. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  83629. typeCnt_s = 2;
  83630. /* both client and server do not call client/server_cert_type APIs,
  83631. * expecting default settings works and no negotiation performed.
  83632. */
  83633. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  83634. return TEST_FAIL;
  83635. /* confirm no negotiation occurred */
  83636. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83637. WOLFSSL_SUCCESS);
  83638. ExpectIntEQ((int)tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83639. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83640. WOLFSSL_SUCCESS);
  83641. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83642. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83643. WOLFSSL_SUCCESS);
  83644. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83645. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83646. WOLFSSL_SUCCESS);
  83647. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83648. (void)typeCnt_c;
  83649. (void)typeCnt_s;
  83650. wolfSSL_free(ssl_c);
  83651. wolfSSL_CTX_free(ctx_c);
  83652. wolfSSL_free(ssl_s);
  83653. wolfSSL_CTX_free(ctx_s);
  83654. ssl_c = ssl_s = NULL;
  83655. ctx_c = ctx_s = NULL;
  83656. /* Both client and server load RPK cert and start handshaking.
  83657. * Confirm negotiated cert types match as expected.
  83658. */
  83659. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83660. ExpectIntEQ(
  83661. test_rpk_memio_setup(
  83662. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83663. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  83664. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83665. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83666. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83667. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83668. , 0);
  83669. /* set client certificate type in client end */
  83670. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83671. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  83672. typeCnt_c = 2;
  83673. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  83674. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  83675. typeCnt_s = 2;
  83676. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  83677. WOLFSSL_SUCCESS);
  83678. /* set server certificate type in client end */
  83679. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  83680. WOLFSSL_SUCCESS);
  83681. /* set client certificate type in server end */
  83682. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  83683. WOLFSSL_SUCCESS);
  83684. /* set server certificate type in server end */
  83685. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  83686. WOLFSSL_SUCCESS);
  83687. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  83688. return TEST_FAIL;
  83689. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83690. WOLFSSL_SUCCESS);
  83691. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83692. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83693. WOLFSSL_SUCCESS);
  83694. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83695. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83696. WOLFSSL_SUCCESS);
  83697. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83698. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83699. WOLFSSL_SUCCESS);
  83700. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83701. wolfSSL_free(ssl_c);
  83702. wolfSSL_CTX_free(ctx_c);
  83703. wolfSSL_free(ssl_s);
  83704. wolfSSL_CTX_free(ctx_s);
  83705. ssl_c = ssl_s = NULL;
  83706. ctx_c = ctx_s = NULL;
  83707. #endif
  83708. #ifndef WOLFSSL_NO_TLS12
  83709. /* TLS1.2
  83710. * Both client and server load RPK cert and start handshaking.
  83711. * Confirm negotiated cert types match as expected.
  83712. */
  83713. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83714. ExpectIntEQ(
  83715. test_rpk_memio_setup(
  83716. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83717. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  83718. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83719. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83720. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83721. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83722. , 0);
  83723. /* set client certificate type in client end */
  83724. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83725. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  83726. typeCnt_c = 2;
  83727. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  83728. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  83729. typeCnt_s = 2;
  83730. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  83731. WOLFSSL_SUCCESS);
  83732. /* set server certificate type in client end */
  83733. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  83734. WOLFSSL_SUCCESS);
  83735. /* set client certificate type in server end */
  83736. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  83737. WOLFSSL_SUCCESS);
  83738. /* set server certificate type in server end */
  83739. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  83740. WOLFSSL_SUCCESS);
  83741. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  83742. return TEST_FAIL;
  83743. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83744. WOLFSSL_SUCCESS);
  83745. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83746. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83747. WOLFSSL_SUCCESS);
  83748. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83749. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83750. WOLFSSL_SUCCESS);
  83751. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83752. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83753. WOLFSSL_SUCCESS);
  83754. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83755. wolfSSL_free(ssl_c);
  83756. wolfSSL_CTX_free(ctx_c);
  83757. wolfSSL_free(ssl_s);
  83758. wolfSSL_CTX_free(ctx_s);
  83759. ssl_c = ssl_s = NULL;
  83760. ctx_c = ctx_s = NULL;
  83761. #endif
  83762. #ifdef WOLFSSL_TLS13
  83763. /* Both client and server load x509 cert.
  83764. * Have client call set_client_cert_type with both RPK and x509.
  83765. * This doesn't makes client add client cert type extension to ClientHello,
  83766. * since it does not load RPK cert actually.
  83767. */
  83768. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83769. ExpectIntEQ(
  83770. test_rpk_memio_setup(
  83771. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83772. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  83773. cliCertFile, WOLFSSL_FILETYPE_PEM,
  83774. svrCertFile, WOLFSSL_FILETYPE_PEM,
  83775. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83776. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83777. , 0);
  83778. /* set client certificate type in client end
  83779. *
  83780. * client indicates both RPK and x509 certs are available but loaded RPK
  83781. * cert only. It does not have client add client-cert-type extension in CH.
  83782. */
  83783. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83784. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  83785. typeCnt_c = 2;
  83786. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  83787. WOLFSSL_SUCCESS);
  83788. /* client indicates both RPK and x509 certs are acceptable */
  83789. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  83790. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  83791. typeCnt_s = 2;
  83792. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  83793. WOLFSSL_SUCCESS);
  83794. /* server indicates both RPK and x509 certs are acceptable */
  83795. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83796. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  83797. typeCnt_c = 2;
  83798. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  83799. WOLFSSL_SUCCESS);
  83800. /* server should indicate only RPK cert is available */
  83801. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  83802. certType_s[1] = -1;
  83803. typeCnt_s = 1;
  83804. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  83805. WOLFSSL_SUCCESS);
  83806. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  83807. return TEST_FAIL;
  83808. /* Negotiation for client-cert-type should NOT happen. Therefore -1 should
  83809. * be returned as cert type.
  83810. */
  83811. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83812. WOLFSSL_SUCCESS);
  83813. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83814. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83815. WOLFSSL_SUCCESS);
  83816. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83817. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83818. WOLFSSL_SUCCESS);
  83819. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83820. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83821. WOLFSSL_SUCCESS);
  83822. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83823. wolfSSL_free(ssl_c);
  83824. wolfSSL_CTX_free(ctx_c);
  83825. wolfSSL_free(ssl_s);
  83826. wolfSSL_CTX_free(ctx_s);
  83827. ssl_c = ssl_s = NULL;
  83828. ctx_c = ctx_s = NULL;
  83829. /* Have client load RPK cert and have server load x509 cert.
  83830. * Check the negotiation result from both ends.
  83831. */
  83832. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83833. ExpectIntEQ(
  83834. test_rpk_memio_setup(
  83835. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83836. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  83837. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83838. svrCertFile, WOLFSSL_FILETYPE_PEM,
  83839. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83840. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83841. , 0);
  83842. /* have client tell to use RPK cert */
  83843. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83844. certType_c[1] = -1;
  83845. typeCnt_c = 1;
  83846. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  83847. WOLFSSL_SUCCESS);
  83848. /* have client tell to accept both RPK and x509 cert */
  83849. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  83850. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  83851. typeCnt_s = 2;
  83852. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  83853. WOLFSSL_SUCCESS);
  83854. /* have server accept to both RPK and x509 cert */
  83855. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  83856. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  83857. typeCnt_c = 2;
  83858. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  83859. WOLFSSL_SUCCESS);
  83860. /* does not call wolfSSL_set_server_cert_type intentionally in sesrver
  83861. * end, expecting the default setting works.
  83862. */
  83863. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  83864. return TEST_FAIL;
  83865. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83866. WOLFSSL_SUCCESS);
  83867. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83868. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83869. WOLFSSL_SUCCESS);
  83870. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83871. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83872. WOLFSSL_SUCCESS);
  83873. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83874. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83875. WOLFSSL_SUCCESS);
  83876. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83877. wolfSSL_free(ssl_c);
  83878. wolfSSL_CTX_free(ctx_c);
  83879. wolfSSL_free(ssl_s);
  83880. wolfSSL_CTX_free(ctx_s);
  83881. ssl_c = ssl_s = NULL;
  83882. ctx_c = ctx_s = NULL;
  83883. /* Have both client and server load RPK cert, however, have server
  83884. * indicate its cert type x509.
  83885. * Client is expected to detect the cert type mismatch then to send alert
  83886. * with "unsupported_certificate".
  83887. */
  83888. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83889. ExpectIntEQ(
  83890. test_rpk_memio_setup(
  83891. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83892. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  83893. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83894. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1, /* server sends RPK cert */
  83895. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83896. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83897. , 0);
  83898. /* have client tell to use RPK cert */
  83899. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83900. certType_c[1] = -1;
  83901. typeCnt_c = 1;
  83902. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  83903. WOLFSSL_SUCCESS);
  83904. /* have client tell to accept both RPK and x509 cert */
  83905. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  83906. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  83907. typeCnt_s = 2;
  83908. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  83909. WOLFSSL_SUCCESS);
  83910. /* have server accept to both RPK and x509 cert */
  83911. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  83912. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  83913. typeCnt_c = 2;
  83914. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  83915. WOLFSSL_SUCCESS);
  83916. /* have server tell to use x509 cert intentionally. This will bring
  83917. * certificate type mismatch in client side.
  83918. */
  83919. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  83920. certType_s[1] = -1;
  83921. typeCnt_s = 1;
  83922. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  83923. WOLFSSL_SUCCESS);
  83924. /* expect client detect cert type mismatch then send Alert */
  83925. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  83926. if (ret != -1)
  83927. return TEST_FAIL;
  83928. ExpectIntEQ(wolfSSL_get_error(ssl_c, ret), WC_NO_ERR_TRACE(UNSUPPORTED_CERTIFICATE));
  83929. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83930. WOLFSSL_SUCCESS);
  83931. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83932. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83933. WOLFSSL_SUCCESS);
  83934. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83935. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83936. WOLFSSL_SUCCESS);
  83937. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83938. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83939. WOLFSSL_SUCCESS);
  83940. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83941. wolfSSL_free(ssl_c);
  83942. wolfSSL_CTX_free(ctx_c);
  83943. wolfSSL_free(ssl_s);
  83944. wolfSSL_CTX_free(ctx_s);
  83945. ssl_c = ssl_s = NULL;
  83946. ctx_c = ctx_s = NULL;
  83947. /* Have client load x509 cert and server load RPK cert,
  83948. * however, have client indicate its cert type RPK.
  83949. * Server is expected to detect the cert type mismatch then to send alert
  83950. * with "unsupported_certificate".
  83951. */
  83952. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83953. ExpectIntEQ(
  83954. test_rpk_memio_setup(
  83955. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83956. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  83957. cliCertFile, WOLFSSL_FILETYPE_PEM,
  83958. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83959. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83960. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83961. , 0);
  83962. /* have client tell to use RPK cert intentionally */
  83963. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83964. certType_c[1] = -1;
  83965. typeCnt_c = 1;
  83966. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  83967. WOLFSSL_SUCCESS);
  83968. /* have client tell to accept both RPK and x509 cert */
  83969. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  83970. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  83971. typeCnt_s = 2;
  83972. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  83973. WOLFSSL_SUCCESS);
  83974. /* have server accept to both RPK and x509 cert */
  83975. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  83976. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  83977. typeCnt_c = 2;
  83978. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  83979. WOLFSSL_SUCCESS);
  83980. /* have server tell to use x509 cert intentionally. This will bring
  83981. * certificate type mismatch in client side.
  83982. */
  83983. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  83984. certType_s[1] = -1;
  83985. typeCnt_s = 1;
  83986. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  83987. WOLFSSL_SUCCESS);
  83988. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  83989. /* expect server detect cert type mismatch then send Alert */
  83990. ExpectIntNE(ret, 0);
  83991. err = wolfSSL_get_error(ssl_c, ret);
  83992. ExpectIntEQ(err, WC_NO_ERR_TRACE(UNSUPPORTED_CERTIFICATE));
  83993. /* client did not load RPK cert actually, so negotiation did not happen */
  83994. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83995. WOLFSSL_SUCCESS);
  83996. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83997. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83998. WOLFSSL_SUCCESS);
  83999. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  84000. /* client did not load RPK cert actually, so negotiation did not happen */
  84001. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  84002. WOLFSSL_SUCCESS);
  84003. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  84004. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  84005. WOLFSSL_SUCCESS);
  84006. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  84007. wolfSSL_free(ssl_c);
  84008. wolfSSL_CTX_free(ctx_c);
  84009. wolfSSL_free(ssl_s);
  84010. wolfSSL_CTX_free(ctx_s);
  84011. ssl_c = ssl_s = NULL;
  84012. ctx_c = ctx_s = NULL;
  84013. #if defined(WOLFSSL_ALWAYS_VERIFY_CB)
  84014. /* Both client and server load RPK cert and set certificate verify
  84015. * callbacks then start handshaking.
  84016. * Confirm both side can refer the peer's cert.
  84017. */
  84018. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84019. ExpectIntEQ(
  84020. test_rpk_memio_setup(
  84021. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84022. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  84023. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  84024. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  84025. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  84026. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  84027. , 0);
  84028. /* set client certificate type in client end */
  84029. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  84030. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  84031. typeCnt_c = 2;
  84032. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  84033. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  84034. typeCnt_s = 2;
  84035. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  84036. WOLFSSL_SUCCESS);
  84037. /* set server certificate type in client end */
  84038. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  84039. WOLFSSL_SUCCESS);
  84040. /* set client certificate type in server end */
  84041. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  84042. WOLFSSL_SUCCESS);
  84043. /* set server certificate type in server end */
  84044. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  84045. WOLFSSL_SUCCESS);
  84046. /* set certificate verify callback to both client and server */
  84047. isServer = 0;
  84048. wolfSSL_SetCertCbCtx(ssl_c, &isServer);
  84049. wolfSSL_set_verify(ssl_c, SSL_VERIFY_PEER, MyRpkVerifyCb);
  84050. isServer = 1;
  84051. wolfSSL_SetCertCbCtx(ssl_c, &isServer);
  84052. wolfSSL_set_verify(ssl_s, SSL_VERIFY_PEER, MyRpkVerifyCb);
  84053. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  84054. if (ret != 0)
  84055. return TEST_FAIL;
  84056. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  84057. WOLFSSL_SUCCESS);
  84058. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  84059. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  84060. WOLFSSL_SUCCESS);
  84061. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  84062. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  84063. WOLFSSL_SUCCESS);
  84064. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  84065. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  84066. WOLFSSL_SUCCESS);
  84067. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  84068. wolfSSL_free(ssl_c);
  84069. wolfSSL_CTX_free(ctx_c);
  84070. wolfSSL_free(ssl_s);
  84071. wolfSSL_CTX_free(ctx_s);
  84072. ssl_c = ssl_s = NULL;
  84073. ctx_c = ctx_s = NULL;
  84074. #endif /* WOLFSSL_ALWAYS_VERIFY_CB */
  84075. #endif /* WOLFSSL_TLS13 */
  84076. #endif /* HAVE_RPK && (!WOLFSSL_NO_TLS12 || WOLFSSL_TLS13) */
  84077. return EXPECT_RESULT();
  84078. }
  84079. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  84080. static int test_dtls13_bad_epoch_ch(void)
  84081. {
  84082. EXPECT_DECLS;
  84083. WOLFSSL_CTX *ctx_c = NULL;
  84084. WOLFSSL_CTX *ctx_s = NULL;
  84085. WOLFSSL *ssl_c = NULL;
  84086. WOLFSSL *ssl_s = NULL;
  84087. struct test_memio_ctx test_ctx;
  84088. const int EPOCH_OFF = 3;
  84089. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84090. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84091. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  84092. /* disable hrr cookie so we can later check msgsReceived.got_client_hello
  84093. * with just one message */
  84094. ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS);
  84095. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  84096. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84097. WOLFSSL_ERROR_WANT_READ);
  84098. ExpectIntGE(test_ctx.s_len, EPOCH_OFF + 2);
  84099. /* first CH should use epoch 0x0 */
  84100. ExpectTrue((test_ctx.s_buff[EPOCH_OFF] == 0x0) &&
  84101. (test_ctx.s_buff[EPOCH_OFF + 1] == 0x0));
  84102. /* change epoch to 2 */
  84103. test_ctx.s_buff[EPOCH_OFF + 1] = 0x2;
  84104. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  84105. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84106. WOLFSSL_ERROR_WANT_READ);
  84107. ExpectIntNE(ssl_s->msgsReceived.got_client_hello, 1);
  84108. /* resend the CH */
  84109. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  84110. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84111. wolfSSL_free(ssl_c);
  84112. wolfSSL_CTX_free(ctx_c);
  84113. wolfSSL_free(ssl_s);
  84114. wolfSSL_CTX_free(ctx_s);
  84115. return EXPECT_RESULT();
  84116. }
  84117. #else
  84118. static int test_dtls13_bad_epoch_ch(void)
  84119. {
  84120. return TEST_SKIPPED;
  84121. }
  84122. #endif
  84123. #if ((defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  84124. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID) && \
  84125. !defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT)) || \
  84126. (!defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  84127. !defined(NO_DES3))) || !defined(WOLFSSL_NO_TLS12)) && \
  84128. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  84129. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && !defined(NO_SESSION_CACHE)
  84130. static int test_short_session_id_ssl_ready(WOLFSSL* ssl)
  84131. {
  84132. EXPECT_DECLS;
  84133. WOLFSSL_SESSION *sess = NULL;
  84134. /* Setup the session to avoid errors */
  84135. ssl->session->timeout = (word32)-1;
  84136. ssl->session->side = WOLFSSL_CLIENT_END;
  84137. #if defined(SESSION_CERTS) || (defined(WOLFSSL_TLS13) && \
  84138. defined(HAVE_SESSION_TICKET))
  84139. ssl->session->version = ssl->version;
  84140. #endif
  84141. /* Force a short session ID to be sent */
  84142. ssl->session->sessionIDSz = 4;
  84143. #ifndef NO_SESSION_CACHE_REF
  84144. /* Allow the client cache to be used */
  84145. ssl->session->idLen = 4;
  84146. #endif
  84147. ssl->session->isSetup = 1;
  84148. ExpectNotNull(sess = wolfSSL_get_session(ssl));
  84149. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WOLFSSL_SUCCESS);
  84150. return EXPECT_RESULT();
  84151. }
  84152. static int test_short_session_id(void)
  84153. {
  84154. EXPECT_DECLS;
  84155. test_ssl_cbf client_cbf;
  84156. test_ssl_cbf server_cbf;
  84157. size_t i;
  84158. struct {
  84159. method_provider client_meth;
  84160. method_provider server_meth;
  84161. const char* tls_version;
  84162. } params[] = {
  84163. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  84164. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID) && \
  84165. !defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT)
  84166. /* With WOLFSSL_TLS13_MIDDLEBOX_COMPAT a short ID will result in an error */
  84167. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" },
  84168. #ifdef WOLFSSL_DTLS13
  84169. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" },
  84170. #endif
  84171. #endif
  84172. #ifndef WOLFSSL_NO_TLS12
  84173. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" },
  84174. #ifdef WOLFSSL_DTLS
  84175. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" },
  84176. #endif
  84177. #endif
  84178. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  84179. !defined(NO_DES3))
  84180. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" },
  84181. #ifdef WOLFSSL_DTLS
  84182. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" },
  84183. #endif
  84184. #endif
  84185. };
  84186. fprintf(stderr, "\n");
  84187. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  84188. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  84189. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  84190. fprintf(stderr, "\tTesting short ID with %s\n", params[i].tls_version);
  84191. client_cbf.ssl_ready = test_short_session_id_ssl_ready;
  84192. client_cbf.method = params[i].client_meth;
  84193. server_cbf.method = params[i].server_meth;
  84194. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  84195. &server_cbf, NULL), TEST_SUCCESS);
  84196. }
  84197. return EXPECT_RESULT();
  84198. }
  84199. #else
  84200. static int test_short_session_id(void)
  84201. {
  84202. return TEST_SKIPPED;
  84203. }
  84204. #endif
  84205. #if defined(HAVE_NULL_CIPHER) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) \
  84206. && defined(WOLFSSL_DTLS13)
  84207. static byte* test_find_string(const char *string,
  84208. byte *buf, int buf_size)
  84209. {
  84210. int string_size, i;
  84211. string_size = (int)XSTRLEN(string);
  84212. for (i = 0; i < buf_size - string_size - 1; i++) {
  84213. if (XSTRCMP((char*)&buf[i], string) == 0)
  84214. return &buf[i];
  84215. }
  84216. return NULL;
  84217. }
  84218. static int test_wolfSSL_dtls13_null_cipher(void)
  84219. {
  84220. EXPECT_DECLS;
  84221. WOLFSSL_CTX *ctx_c = NULL;
  84222. WOLFSSL_CTX *ctx_s = NULL;
  84223. WOLFSSL *ssl_c = NULL;
  84224. WOLFSSL *ssl_s = NULL;
  84225. struct test_memio_ctx test_ctx;
  84226. const char *test_str = "test";
  84227. int test_str_size;
  84228. byte buf[255], *ptr = NULL;
  84229. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84230. test_ctx.c_ciphers = test_ctx.s_ciphers = "TLS13-SHA256-SHA256";
  84231. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84232. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  84233. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84234. test_str_size = XSTRLEN("test") + 1;
  84235. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  84236. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), test_str_size);
  84237. ExpectIntEQ(XSTRCMP((char*)buf, test_str), 0);
  84238. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  84239. /* check that the packet was sent cleartext */
  84240. ExpectNotNull(ptr = test_find_string(test_str, test_ctx.s_buff,
  84241. test_ctx.s_len));
  84242. if (ptr != NULL) {
  84243. /* modify the message */
  84244. *ptr = 'H';
  84245. /* bad messages should be ignored in DTLS */
  84246. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), -1);
  84247. ExpectIntEQ(ssl_s->error, WC_NO_ERR_TRACE(WANT_READ));
  84248. }
  84249. ExpectIntEQ(wolfSSL_shutdown(ssl_c), WOLFSSL_SHUTDOWN_NOT_DONE);
  84250. ExpectIntEQ(wolfSSL_shutdown(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE);
  84251. ExpectIntEQ(wolfSSL_shutdown(ssl_c), 1);
  84252. ExpectIntEQ(wolfSSL_shutdown(ssl_s), 1);
  84253. wolfSSL_free(ssl_c);
  84254. wolfSSL_free(ssl_s);
  84255. wolfSSL_CTX_free(ctx_c);
  84256. wolfSSL_CTX_free(ctx_s);
  84257. return TEST_SUCCESS;
  84258. }
  84259. #else
  84260. static int test_wolfSSL_dtls13_null_cipher(void)
  84261. {
  84262. return TEST_SKIPPED;
  84263. }
  84264. #endif
  84265. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  84266. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  84267. !defined(SINGLE_THREADED) && !defined(NO_RSA)
  84268. static int test_dtls_msg_get_connected_port(int fd, word16 *port)
  84269. {
  84270. SOCKADDR_S peer;
  84271. XSOCKLENT len;
  84272. int ret;
  84273. XMEMSET((byte*)&peer, 0, sizeof(peer));
  84274. len = sizeof(peer);
  84275. ret = getpeername(fd, (SOCKADDR*)&peer, &len);
  84276. if (ret != 0 || len > (XSOCKLENT)sizeof(peer))
  84277. return -1;
  84278. switch (peer.ss_family) {
  84279. #ifdef WOLFSSL_IPV6
  84280. case WOLFSSL_IP6: {
  84281. *port = ntohs(((SOCKADDR_IN6*)&peer)->sin6_port);
  84282. break;
  84283. }
  84284. #endif /* WOLFSSL_IPV6 */
  84285. case WOLFSSL_IP4:
  84286. *port = ntohs(((SOCKADDR_IN*)&peer)->sin_port);
  84287. break;
  84288. default:
  84289. return -1;
  84290. }
  84291. return 0;
  84292. }
  84293. static int test_dtls_msg_from_other_peer_cb(WOLFSSL_CTX *ctx, WOLFSSL *ssl)
  84294. {
  84295. char buf[1] = {'t'};
  84296. SOCKADDR_IN_T addr;
  84297. int sock_fd;
  84298. word16 port;
  84299. int err;
  84300. (void)ssl;
  84301. (void)ctx;
  84302. if (ssl == NULL)
  84303. return -1;
  84304. err = test_dtls_msg_get_connected_port(wolfSSL_get_fd(ssl), &port);
  84305. if (err != 0)
  84306. return -1;
  84307. sock_fd = socket(AF_INET_V, SOCK_DGRAM, 0);
  84308. if (sock_fd == -1)
  84309. return -1;
  84310. build_addr(&addr, wolfSSLIP, port, 1, 0);
  84311. /* send a packet to the server. Being another socket, the kernel will ensure
  84312. * the source port will be different. */
  84313. err = (int)sendto(sock_fd, buf, sizeof(buf), 0, (SOCKADDR*)&addr,
  84314. sizeof(addr));
  84315. close(sock_fd);
  84316. if (err == -1)
  84317. return -1;
  84318. return 0;
  84319. }
  84320. /* setup a SSL session but just after the handshake send a packet to the server
  84321. * with a source address different than the one of the connected client. The I/O
  84322. * callback EmbedRecvFrom should just ignore the packet. Sending of the packet
  84323. * is done in test_dtls_msg_from_other_peer_cb */
  84324. static int test_dtls_msg_from_other_peer(void)
  84325. {
  84326. EXPECT_DECLS;
  84327. callback_functions client_cbs;
  84328. callback_functions server_cbs;
  84329. XMEMSET((byte*)&client_cbs, 0, sizeof(client_cbs));
  84330. XMEMSET((byte*)&server_cbs, 0, sizeof(server_cbs));
  84331. client_cbs.method = wolfDTLSv1_2_client_method;
  84332. server_cbs.method = wolfDTLSv1_2_server_method;
  84333. client_cbs.doUdp = 1;
  84334. server_cbs.doUdp = 1;
  84335. test_wolfSSL_client_server_nofail_ex(&client_cbs, &server_cbs,
  84336. test_dtls_msg_from_other_peer_cb);
  84337. ExpectIntEQ(client_cbs.return_code, WOLFSSL_SUCCESS);
  84338. ExpectIntEQ(server_cbs.return_code, WOLFSSL_SUCCESS);
  84339. return EXPECT_RESULT();
  84340. }
  84341. #else
  84342. static int test_dtls_msg_from_other_peer(void)
  84343. {
  84344. return TEST_SKIPPED;
  84345. }
  84346. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  84347. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  84348. * !defined(SINGLE_THREADED) && !defined(NO_RSA) */
  84349. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_IPV6) && \
  84350. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  84351. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  84352. static int test_dtls_ipv6_check(void)
  84353. {
  84354. EXPECT_DECLS;
  84355. WOLFSSL_CTX *ctx_c = NULL;
  84356. WOLFSSL_CTX *ctx_s = NULL;
  84357. WOLFSSL *ssl_c = NULL;
  84358. WOLFSSL *ssl_s = NULL;
  84359. SOCKADDR_IN fake_addr6;
  84360. int sockfd = -1;
  84361. ExpectNotNull(ctx_c = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  84362. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  84363. ExpectNotNull(ctx_s = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  84364. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx_s, svrKeyFile,
  84365. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84366. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx_s, svrCertFile,
  84367. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84368. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  84369. XMEMSET((byte*)&fake_addr6, 0, sizeof(fake_addr6));
  84370. /* mimic a sockaddr_in6 struct, this way we can't test without
  84371. * WOLFSSL_IPV6 */
  84372. fake_addr6.sin_family = WOLFSSL_IP6;
  84373. ExpectIntNE(sockfd = socket(AF_INET, SOCK_DGRAM, 0), -1);
  84374. ExpectIntEQ(wolfSSL_set_fd(ssl_c, sockfd), WOLFSSL_SUCCESS);
  84375. /* can't return error here, as the peer is opaque for wolfssl library at
  84376. * this point */
  84377. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl_c, &fake_addr6, sizeof(fake_addr6)),
  84378. WOLFSSL_SUCCESS);
  84379. ExpectIntNE(fcntl(sockfd, F_SETFL, O_NONBLOCK), -1);
  84380. wolfSSL_dtls_set_using_nonblock(ssl_c, 1);
  84381. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  84382. ExpectIntEQ(ssl_c->error, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  84383. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl_s, &fake_addr6, sizeof(fake_addr6)),
  84384. WOLFSSL_SUCCESS);
  84385. /* reuse the socket */
  84386. ExpectIntEQ(wolfSSL_set_fd(ssl_c, sockfd), WOLFSSL_SUCCESS);
  84387. wolfSSL_dtls_set_using_nonblock(ssl_s, 1);
  84388. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  84389. ExpectIntEQ(ssl_s->error, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  84390. if (sockfd != -1)
  84391. close(sockfd);
  84392. wolfSSL_free(ssl_c);
  84393. wolfSSL_CTX_free(ctx_c);
  84394. wolfSSL_free(ssl_s);
  84395. wolfSSL_CTX_free(ctx_s);
  84396. return EXPECT_RESULT();
  84397. }
  84398. #else
  84399. static int test_dtls_ipv6_check(void)
  84400. {
  84401. return TEST_SKIPPED;
  84402. }
  84403. #endif
  84404. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  84405. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  84406. static WOLFSSL_SESSION* test_wolfSSL_SCR_after_resumption_session = NULL;
  84407. static void test_wolfSSL_SCR_after_resumption_ctx_ready(WOLFSSL_CTX* ctx)
  84408. {
  84409. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  84410. }
  84411. static void test_wolfSSL_SCR_after_resumption_on_result(WOLFSSL* ssl)
  84412. {
  84413. if (test_wolfSSL_SCR_after_resumption_session == NULL) {
  84414. test_wolfSSL_SCR_after_resumption_session = wolfSSL_get1_session(ssl);
  84415. AssertNotNull(test_wolfSSL_SCR_after_resumption_session);
  84416. }
  84417. else {
  84418. char testMsg[] = "Message after SCR";
  84419. char msgBuf[sizeof(testMsg)];
  84420. int ret;
  84421. if (!wolfSSL_is_server(ssl)) {
  84422. AssertIntEQ(WOLFSSL_SUCCESS,
  84423. wolfSSL_set_session(ssl,
  84424. test_wolfSSL_SCR_after_resumption_session));
  84425. }
  84426. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  84427. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  84428. sizeof(testMsg));
  84429. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  84430. if (ret != sizeof(msgBuf)) /* Possibly APP_DATA_READY error. Retry. */
  84431. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  84432. AssertIntEQ(ret, sizeof(msgBuf));
  84433. }
  84434. }
  84435. static void test_wolfSSL_SCR_after_resumption_ssl_ready(WOLFSSL* ssl)
  84436. {
  84437. AssertIntEQ(WOLFSSL_SUCCESS,
  84438. wolfSSL_set_session(ssl, test_wolfSSL_SCR_after_resumption_session));
  84439. }
  84440. static int test_wolfSSL_SCR_after_resumption(void)
  84441. {
  84442. EXPECT_DECLS;
  84443. callback_functions func_cb_client;
  84444. callback_functions func_cb_server;
  84445. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  84446. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  84447. func_cb_client.method = wolfTLSv1_2_client_method;
  84448. func_cb_client.ctx_ready = test_wolfSSL_SCR_after_resumption_ctx_ready;
  84449. func_cb_client.on_result = test_wolfSSL_SCR_after_resumption_on_result;
  84450. func_cb_server.method = wolfTLSv1_2_server_method;
  84451. func_cb_server.ctx_ready = test_wolfSSL_SCR_after_resumption_ctx_ready;
  84452. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84453. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84454. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84455. func_cb_client.ssl_ready = test_wolfSSL_SCR_after_resumption_ssl_ready;
  84456. func_cb_server.on_result = test_wolfSSL_SCR_after_resumption_on_result;
  84457. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84458. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84459. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84460. wolfSSL_SESSION_free(test_wolfSSL_SCR_after_resumption_session);
  84461. return EXPECT_RESULT();
  84462. }
  84463. #else
  84464. static int test_wolfSSL_SCR_after_resumption(void)
  84465. {
  84466. return TEST_SKIPPED;
  84467. }
  84468. #endif
  84469. static int test_wolfSSL_configure_args(void)
  84470. {
  84471. EXPECT_DECLS;
  84472. #if defined(LIBWOLFSSL_CONFIGURE_ARGS) && defined(HAVE_WC_INTROSPECTION)
  84473. ExpectNotNull(wolfSSL_configure_args());
  84474. #endif
  84475. return EXPECT_RESULT();
  84476. }
  84477. static int test_dtls_no_extensions(void)
  84478. {
  84479. EXPECT_DECLS;
  84480. #if defined(WOLFSSL_DTLS) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  84481. !defined(WOLFSSL_NO_TLS12)
  84482. WOLFSSL *ssl_s = NULL;
  84483. WOLFSSL_CTX *ctx_s = NULL;
  84484. struct test_memio_ctx test_ctx;
  84485. const byte chNoExtensions[] = {
  84486. /* Handshake type */
  84487. 0x16,
  84488. /* Version */
  84489. 0xfe, 0xff,
  84490. /* Epoch */
  84491. 0x00, 0x00,
  84492. /* Seq number */
  84493. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  84494. /* Length */
  84495. 0x00, 0x40,
  84496. /* CH type */
  84497. 0x01,
  84498. /* Length */
  84499. 0x00, 0x00, 0x34,
  84500. /* Msg Seq */
  84501. 0x00, 0x00,
  84502. /* Frag offset */
  84503. 0x00, 0x00, 0x00,
  84504. /* Frag length */
  84505. 0x00, 0x00, 0x34,
  84506. /* Version */
  84507. 0xfe, 0xff,
  84508. /* Random */
  84509. 0x62, 0xfe, 0xbc, 0xfe, 0x2b, 0xfe, 0x3f, 0xeb, 0x03, 0xc4, 0xea, 0x37,
  84510. 0xe7, 0x47, 0x7e, 0x8a, 0xd9, 0xbf, 0x77, 0x0f, 0x6c, 0xb6, 0x77, 0x0b,
  84511. 0x03, 0x3f, 0x82, 0x2b, 0x21, 0x64, 0x57, 0x1d,
  84512. /* Session Length */
  84513. 0x00,
  84514. /* Cookie Length */
  84515. 0x00,
  84516. /* CS Length */
  84517. 0x00, 0x0c,
  84518. /* CS */
  84519. 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x39, 0x00, 0x33,
  84520. /* Comp Meths Length */
  84521. 0x01,
  84522. /* Comp Meths */
  84523. 0x00
  84524. /* And finally... no extensions */
  84525. };
  84526. int i;
  84527. #ifdef OPENSSL_EXTRA
  84528. int repeats = 2;
  84529. #else
  84530. int repeats = 1;
  84531. #endif
  84532. for (i = 0; i < repeats; i++) {
  84533. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84534. ssl_s = NULL;
  84535. ctx_s = NULL;
  84536. ExpectIntEQ(test_memio_setup(&test_ctx, NULL, &ctx_s, NULL, &ssl_s,
  84537. NULL, wolfDTLS_server_method), 0);
  84538. XMEMCPY(test_ctx.s_buff, chNoExtensions, sizeof(chNoExtensions));
  84539. test_ctx.s_len = sizeof(chNoExtensions);
  84540. #ifdef OPENSSL_EXTRA
  84541. if (i > 0) {
  84542. ExpectIntEQ(wolfSSL_set_max_proto_version(ssl_s, DTLS1_2_VERSION),
  84543. WOLFSSL_SUCCESS);
  84544. }
  84545. #endif
  84546. ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
  84547. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84548. /* Expecting a handshake msg. Either HVR or SH. */
  84549. ExpectIntGT(test_ctx.c_len, 0);
  84550. ExpectIntEQ(test_ctx.c_buff[0], 0x16);
  84551. wolfSSL_free(ssl_s);
  84552. wolfSSL_CTX_free(ctx_s);
  84553. }
  84554. #endif
  84555. return EXPECT_RESULT();
  84556. }
  84557. static int test_tls_alert_no_server_hello(void)
  84558. {
  84559. EXPECT_DECLS;
  84560. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  84561. WOLFSSL *ssl_c = NULL;
  84562. WOLFSSL_CTX *ctx_c = NULL;
  84563. struct test_memio_ctx test_ctx;
  84564. unsigned char alert_msg[] = { 0x15, 0x03, 0x01, 0x00, 0x02, 0x02, 0x28 };
  84565. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84566. ssl_c = NULL;
  84567. ctx_c = NULL;
  84568. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  84569. wolfTLSv1_2_client_method, NULL), 0);
  84570. XMEMCPY(test_ctx.c_buff, alert_msg, sizeof(alert_msg));
  84571. test_ctx.c_len = sizeof(alert_msg);
  84572. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84573. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(FATAL_ERROR));
  84574. wolfSSL_free(ssl_c);
  84575. wolfSSL_CTX_free(ctx_c);
  84576. #endif
  84577. return EXPECT_RESULT();
  84578. }
  84579. static int test_TLSX_CA_NAMES_bad_extension(void)
  84580. {
  84581. EXPECT_DECLS;
  84582. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  84583. !defined(NO_CERTS) && !defined(WOLFSSL_NO_CA_NAMES) && \
  84584. defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA384) && \
  84585. defined(HAVE_NULL_CIPHER)
  84586. /* This test should only fail (with BUFFER_ERROR) when we actually try to
  84587. * parse the CA Names extension. Otherwise it will return other non-related
  84588. * errors. If CA Names will be parsed in more configurations, that should
  84589. * be reflected in the macro guard above. */
  84590. WOLFSSL *ssl_c = NULL;
  84591. WOLFSSL_CTX *ctx_c = NULL;
  84592. struct test_memio_ctx test_ctx;
  84593. /* HRR + SH using TLS_DHE_PSK_WITH_NULL_SHA384 */
  84594. const byte shBadCaNamesExt[] = {
  84595. 0x16, 0x03, 0x04, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0xcf,
  84596. 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e,
  84597. 0x65, 0xb8, 0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e, 0x07,
  84598. 0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c, 0x00, 0x13, 0x03, 0x00, 0x00,
  84599. 0x13, 0x94, 0x7e, 0x00, 0x03, 0x0b, 0xf7, 0x03, 0x00, 0x2b, 0x00, 0x02,
  84600. 0x03, 0x04, 0x00, 0x33, 0x00, 0x02, 0x00, 0x19, 0x16, 0x03, 0x03, 0x00,
  84601. 0x5c, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0x03, 0xcf, 0x21, 0xad, 0x74,
  84602. 0x00, 0x00, 0x83, 0x3f, 0x3b, 0x80, 0x01, 0xac, 0x65, 0x8c, 0x19, 0x2a,
  84603. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x02, 0x00, 0x9e, 0x09, 0x1c, 0xe8,
  84604. 0xa8, 0x09, 0x9c, 0x00, 0xc0, 0xb5, 0x00, 0x00, 0x11, 0x8f, 0x00, 0x00,
  84605. 0x03, 0x3f, 0x00, 0x0c, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, 0x13, 0x05,
  84606. 0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00,
  84607. 0x0d, 0x00, 0x00, 0x11, 0x00, 0x00, 0x0d, 0x00, 0x2f, 0x00, 0x01, 0xff,
  84608. 0xff, 0xff, 0xff, 0xfa, 0x0d, 0x00, 0x00, 0x00, 0xad, 0x02
  84609. };
  84610. const byte shBadCaNamesExt2[] = {
  84611. 0x16, 0x03, 0x04, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0xcf,
  84612. 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e,
  84613. 0x65, 0xb8, 0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e, 0x07,
  84614. 0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c, 0x00, 0x13, 0x03, 0x00, 0x00,
  84615. 0x13, 0x94, 0x7e, 0x00, 0x03, 0x0b, 0xf7, 0x03, 0x00, 0x2b, 0x00, 0x02,
  84616. 0x03, 0x04, 0x00, 0x33, 0x00, 0x02, 0x00, 0x19, 0x16, 0x03, 0x03, 0x00,
  84617. 0x5e, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0x7f, 0xd0, 0x2d, 0xea, 0x6e,
  84618. 0x53, 0xa1, 0x6a, 0xc9, 0xc8, 0x54, 0xef, 0x75, 0xe4, 0xd9, 0xc6, 0x3e,
  84619. 0x74, 0xcb, 0x30, 0x80, 0xcc, 0x83, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00,
  84620. 0x00, 0xc0, 0x5a, 0x00, 0xc0, 0xb5, 0x00, 0x00, 0x11, 0x8f, 0x00, 0x00,
  84621. 0x03, 0x03, 0x00, 0x0c, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, 0x53, 0x25,
  84622. 0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x04, 0x02, 0x05, 0x00, 0x00,
  84623. 0x0d, 0x00, 0x00, 0x11, 0x00, 0x00, 0x0d, 0x00, 0x2f, 0x00, 0x06, 0x00,
  84624. 0x04, 0x00, 0x03, 0x30, 0x00, 0x13, 0x94, 0x00, 0x06, 0x00, 0x04, 0x02
  84625. };
  84626. int i = 0;
  84627. for (i = 0; i < 2; i++) {
  84628. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84629. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  84630. wolfTLSv1_3_client_method, NULL), 0);
  84631. switch (i) {
  84632. case 0:
  84633. XMEMCPY(test_ctx.c_buff, shBadCaNamesExt,
  84634. sizeof(shBadCaNamesExt));
  84635. test_ctx.c_len = sizeof(shBadCaNamesExt);
  84636. break;
  84637. case 1:
  84638. XMEMCPY(test_ctx.c_buff, shBadCaNamesExt2,
  84639. sizeof(shBadCaNamesExt2));
  84640. test_ctx.c_len = sizeof(shBadCaNamesExt2);
  84641. break;
  84642. }
  84643. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84644. #ifndef WOLFSSL_DISABLE_EARLY_SANITY_CHECKS
  84645. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(OUT_OF_ORDER_E));
  84646. #else
  84647. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(BUFFER_ERROR));
  84648. #endif
  84649. wolfSSL_free(ssl_c);
  84650. ssl_c = NULL;
  84651. wolfSSL_CTX_free(ctx_c);
  84652. ctx_c = NULL;
  84653. }
  84654. #endif
  84655. return EXPECT_RESULT();
  84656. }
  84657. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  84658. defined(HAVE_IO_TESTS_DEPENDENCIES)
  84659. static void test_dtls_1_0_hvr_downgrade_ctx_ready(WOLFSSL_CTX* ctx)
  84660. {
  84661. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  84662. WOLFSSL_SUCCESS);
  84663. }
  84664. static int test_dtls_1_0_hvr_downgrade(void)
  84665. {
  84666. EXPECT_DECLS;
  84667. callback_functions func_cb_client;
  84668. callback_functions func_cb_server;
  84669. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  84670. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  84671. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  84672. func_cb_client.method = wolfDTLS_client_method;
  84673. func_cb_server.method = wolfDTLSv1_2_server_method;
  84674. func_cb_client.ctx_ready = test_dtls_1_0_hvr_downgrade_ctx_ready;
  84675. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84676. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84677. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84678. return EXPECT_RESULT();
  84679. }
  84680. #else
  84681. static int test_dtls_1_0_hvr_downgrade(void)
  84682. {
  84683. EXPECT_DECLS;
  84684. return EXPECT_RESULT();
  84685. }
  84686. #endif
  84687. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12) && \
  84688. defined(HAVE_SESSION_TICKET)
  84689. static WOLFSSL_SESSION* test_session_ticket_no_id_session = NULL;
  84690. static void test_session_ticket_no_id_on_result(WOLFSSL* ssl)
  84691. {
  84692. test_session_ticket_no_id_session = wolfSSL_get1_session(ssl);
  84693. AssertNotNull(test_session_ticket_no_id_session);
  84694. }
  84695. static void test_session_ticket_no_id_ctx_ready(WOLFSSL_CTX* ctx)
  84696. {
  84697. AssertIntEQ(wolfSSL_CTX_UseSessionTicket(ctx), WOLFSSL_SUCCESS);
  84698. }
  84699. static void test_session_ticket_no_id_ssl_ready(WOLFSSL* ssl)
  84700. {
  84701. test_session_ticket_no_id_session->sessionIDSz = 0;
  84702. AssertIntEQ(WOLFSSL_SUCCESS,
  84703. wolfSSL_set_session(ssl, test_session_ticket_no_id_session));
  84704. }
  84705. static int test_session_ticket_no_id(void)
  84706. {
  84707. /* We are testing an expired (invalid crypto context in out case since the
  84708. * ctx changes) session ticket being sent with the session ID being 0
  84709. * length. */
  84710. EXPECT_DECLS;
  84711. callback_functions func_cb_client;
  84712. callback_functions func_cb_server;
  84713. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  84714. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  84715. func_cb_client.method = wolfTLSv1_2_client_method;
  84716. func_cb_client.ctx_ready = test_session_ticket_no_id_ctx_ready;
  84717. func_cb_client.on_result = test_session_ticket_no_id_on_result;
  84718. func_cb_server.method = wolfTLSv1_2_server_method;
  84719. func_cb_server.ctx_ready = test_session_ticket_no_id_ctx_ready;
  84720. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84721. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84722. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84723. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  84724. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  84725. func_cb_client.method = wolfTLSv1_2_client_method;
  84726. func_cb_client.ctx_ready = test_session_ticket_no_id_ctx_ready;
  84727. func_cb_client.ssl_ready = test_session_ticket_no_id_ssl_ready;
  84728. func_cb_server.method = wolfTLSv1_2_server_method;
  84729. func_cb_server.ctx_ready = test_session_ticket_no_id_ctx_ready;
  84730. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84731. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84732. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84733. wolfSSL_SESSION_free(test_session_ticket_no_id_session);
  84734. return EXPECT_RESULT();
  84735. }
  84736. #else
  84737. static int test_session_ticket_no_id(void)
  84738. {
  84739. EXPECT_DECLS;
  84740. return EXPECT_RESULT();
  84741. }
  84742. #endif
  84743. static int test_session_ticket_hs_update(void)
  84744. {
  84745. EXPECT_DECLS;
  84746. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  84747. defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  84748. struct test_memio_ctx test_ctx;
  84749. struct test_memio_ctx test_ctx2;
  84750. struct test_memio_ctx test_ctx3;
  84751. WOLFSSL_CTX *ctx_c = NULL;
  84752. WOLFSSL_CTX *ctx_s = NULL;
  84753. WOLFSSL *ssl_c = NULL;
  84754. WOLFSSL *ssl_c2 = NULL;
  84755. WOLFSSL *ssl_c3 = NULL;
  84756. WOLFSSL *ssl_s = NULL;
  84757. WOLFSSL *ssl_s2 = NULL;
  84758. WOLFSSL *ssl_s3 = NULL;
  84759. WOLFSSL_SESSION *sess = NULL;
  84760. byte read_data[1];
  84761. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84762. XMEMSET(&test_ctx2, 0, sizeof(test_ctx2));
  84763. XMEMSET(&test_ctx3, 0, sizeof(test_ctx3));
  84764. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84765. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  84766. /* Generate tickets */
  84767. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84768. wolfSSL_SetLoggingPrefix("client");
  84769. /* Read the ticket msg */
  84770. ExpectIntEQ(wolfSSL_read(ssl_c, read_data, sizeof(read_data)),
  84771. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84772. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84773. WOLFSSL_ERROR_WANT_READ);
  84774. wolfSSL_SetLoggingPrefix(NULL);
  84775. ExpectIntEQ(test_memio_setup(&test_ctx2, &ctx_c, &ctx_s, &ssl_c2, &ssl_s2,
  84776. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  84777. ExpectIntEQ(test_memio_setup(&test_ctx3, &ctx_c, &ctx_s, &ssl_c3, &ssl_s3,
  84778. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  84779. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  84780. ExpectIntEQ(wolfSSL_set_session(ssl_c2, sess), WOLFSSL_SUCCESS);
  84781. ExpectIntEQ(wolfSSL_set_session(ssl_c3, sess), WOLFSSL_SUCCESS);
  84782. wolfSSL_SetLoggingPrefix("client");
  84783. /* Exchange initial flights for the second connection */
  84784. ExpectIntEQ(wolfSSL_connect(ssl_c2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84785. ExpectIntEQ(wolfSSL_get_error(ssl_c2, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84786. WOLFSSL_ERROR_WANT_READ);
  84787. wolfSSL_SetLoggingPrefix(NULL);
  84788. wolfSSL_SetLoggingPrefix("server");
  84789. ExpectIntEQ(wolfSSL_accept(ssl_s2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84790. ExpectIntEQ(wolfSSL_get_error(ssl_s2, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84791. WOLFSSL_ERROR_WANT_READ);
  84792. wolfSSL_SetLoggingPrefix(NULL);
  84793. /* Complete third connection so that new tickets are exchanged */
  84794. ExpectIntEQ(test_memio_do_handshake(ssl_c3, ssl_s3, 10, NULL), 0);
  84795. /* Read the ticket msg */
  84796. wolfSSL_SetLoggingPrefix("client");
  84797. ExpectIntEQ(wolfSSL_read(ssl_c3, read_data, sizeof(read_data)),
  84798. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84799. ExpectIntEQ(wolfSSL_get_error(ssl_c3, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84800. WOLFSSL_ERROR_WANT_READ);
  84801. wolfSSL_SetLoggingPrefix(NULL);
  84802. /* Complete second connection */
  84803. ExpectIntEQ(test_memio_do_handshake(ssl_c2, ssl_s2, 10, NULL), 0);
  84804. ExpectIntEQ(wolfSSL_session_reused(ssl_c2), 1);
  84805. ExpectIntEQ(wolfSSL_session_reused(ssl_c3), 1);
  84806. wolfSSL_free(ssl_c);
  84807. wolfSSL_free(ssl_c2);
  84808. wolfSSL_free(ssl_c3);
  84809. wolfSSL_free(ssl_s);
  84810. wolfSSL_free(ssl_s2);
  84811. wolfSSL_free(ssl_s3);
  84812. wolfSSL_CTX_free(ctx_c);
  84813. wolfSSL_CTX_free(ctx_s);
  84814. wolfSSL_SESSION_free(sess);
  84815. #endif
  84816. return EXPECT_RESULT();
  84817. }
  84818. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  84819. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  84820. static void test_dtls_downgrade_scr_server_ctx_ready_server(WOLFSSL_CTX* ctx)
  84821. {
  84822. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  84823. WOLFSSL_SUCCESS);
  84824. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  84825. }
  84826. static void test_dtls_downgrade_scr_server_ctx_ready(WOLFSSL_CTX* ctx)
  84827. {
  84828. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  84829. }
  84830. static void test_dtls_downgrade_scr_server_on_result(WOLFSSL* ssl)
  84831. {
  84832. char testMsg[] = "Message after SCR";
  84833. char msgBuf[sizeof(testMsg)];
  84834. if (wolfSSL_is_server(ssl)) {
  84835. AssertIntEQ(wolfSSL_Rehandshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84836. AssertIntEQ(wolfSSL_get_error(ssl, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  84837. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  84838. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  84839. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  84840. sizeof(testMsg));
  84841. }
  84842. else {
  84843. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  84844. sizeof(testMsg));
  84845. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  84846. }
  84847. }
  84848. static int test_dtls_downgrade_scr_server(void)
  84849. {
  84850. EXPECT_DECLS;
  84851. callback_functions func_cb_client;
  84852. callback_functions func_cb_server;
  84853. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  84854. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  84855. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  84856. func_cb_client.method = wolfDTLSv1_2_client_method;
  84857. func_cb_server.method = wolfDTLS_server_method;
  84858. func_cb_client.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready;
  84859. func_cb_server.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready_server;
  84860. func_cb_client.on_result = test_dtls_downgrade_scr_server_on_result;
  84861. func_cb_server.on_result = test_dtls_downgrade_scr_server_on_result;
  84862. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84863. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84864. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84865. return EXPECT_RESULT();
  84866. }
  84867. #else
  84868. static int test_dtls_downgrade_scr_server(void)
  84869. {
  84870. EXPECT_DECLS;
  84871. return EXPECT_RESULT();
  84872. }
  84873. #endif
  84874. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  84875. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  84876. static void test_dtls_downgrade_scr_ctx_ready(WOLFSSL_CTX* ctx)
  84877. {
  84878. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  84879. WOLFSSL_SUCCESS);
  84880. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  84881. }
  84882. static void test_dtls_downgrade_scr_on_result(WOLFSSL* ssl)
  84883. {
  84884. char testMsg[] = "Message after SCR";
  84885. char msgBuf[sizeof(testMsg)];
  84886. if (wolfSSL_is_server(ssl)) {
  84887. AssertIntEQ(wolfSSL_Rehandshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84888. AssertIntEQ(wolfSSL_get_error(ssl, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  84889. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  84890. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  84891. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  84892. sizeof(testMsg));
  84893. }
  84894. else {
  84895. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  84896. sizeof(testMsg));
  84897. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  84898. }
  84899. }
  84900. static int test_dtls_downgrade_scr(void)
  84901. {
  84902. EXPECT_DECLS;
  84903. callback_functions func_cb_client;
  84904. callback_functions func_cb_server;
  84905. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  84906. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  84907. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  84908. func_cb_client.method = wolfDTLS_client_method;
  84909. func_cb_server.method = wolfDTLSv1_2_server_method;
  84910. func_cb_client.ctx_ready = test_dtls_downgrade_scr_ctx_ready;
  84911. func_cb_client.on_result = test_dtls_downgrade_scr_on_result;
  84912. func_cb_server.on_result = test_dtls_downgrade_scr_on_result;
  84913. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84914. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84915. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84916. return EXPECT_RESULT();
  84917. }
  84918. #else
  84919. static int test_dtls_downgrade_scr(void)
  84920. {
  84921. EXPECT_DECLS;
  84922. return EXPECT_RESULT();
  84923. }
  84924. #endif
  84925. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  84926. && !defined(WOLFSSL_NO_TLS12)
  84927. static int test_dtls_client_hello_timeout_downgrade_read_cb(WOLFSSL *ssl,
  84928. char *data, int sz, void *ctx)
  84929. {
  84930. static int call_counter = 0;
  84931. call_counter++;
  84932. (void)ssl;
  84933. (void)data;
  84934. (void)sz;
  84935. (void)ctx;
  84936. switch (call_counter) {
  84937. case 1:
  84938. case 2:
  84939. return WOLFSSL_CBIO_ERR_TIMEOUT;
  84940. case 3:
  84941. return WOLFSSL_CBIO_ERR_WANT_READ;
  84942. default:
  84943. AssertIntLE(call_counter, 3);
  84944. return -1;
  84945. }
  84946. }
  84947. #endif
  84948. /* Make sure we don't send acks before getting a server hello */
  84949. static int test_dtls_client_hello_timeout_downgrade(void)
  84950. {
  84951. EXPECT_DECLS;
  84952. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  84953. && !defined(WOLFSSL_NO_TLS12)
  84954. WOLFSSL_CTX *ctx_c = NULL;
  84955. WOLFSSL_CTX *ctx_s = NULL;
  84956. WOLFSSL *ssl_c = NULL;
  84957. WOLFSSL *ssl_s = NULL;
  84958. struct test_memio_ctx test_ctx;
  84959. DtlsRecordLayerHeader* dtlsRH;
  84960. size_t len;
  84961. byte sequence_number[8];
  84962. int i;
  84963. for (i = 0; i < 2; i++) {
  84964. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84965. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84966. wolfDTLS_client_method, wolfDTLSv1_2_server_method), 0);
  84967. if (i == 0) {
  84968. /* First time simulate timeout in IO layer */
  84969. /* CH1 */
  84970. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84971. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84972. /* HVR */
  84973. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84974. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84975. /* CH2 */
  84976. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84977. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84978. /* SH flight */
  84979. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84980. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84981. /* Drop the SH */
  84982. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.c_buff);
  84983. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  84984. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  84985. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  84986. (sizeof(DtlsRecordLayerHeader) + len));
  84987. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  84988. /* Read the remainder of the flight */
  84989. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84990. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84991. wolfSSL_SSLSetIORecv(ssl_c,
  84992. test_dtls_client_hello_timeout_downgrade_read_cb);
  84993. /* CH3 */
  84994. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84995. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84996. wolfSSL_SSLSetIORecv(ssl_c, test_memio_read_cb);
  84997. }
  84998. else {
  84999. /* Second time call wolfSSL_dtls_got_timeout */
  85000. /* CH1 */
  85001. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85002. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85003. /* HVR */
  85004. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85005. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85006. /* CH2 */
  85007. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85008. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85009. /* SH flight */
  85010. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85011. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85012. /* Drop the SH */
  85013. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.c_buff);
  85014. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  85015. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  85016. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  85017. (sizeof(DtlsRecordLayerHeader) + len));
  85018. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  85019. /* Read the remainder of the flight */
  85020. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85021. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85022. /* Quick timeout should be set as we received at least one msg */
  85023. ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_c), 1);
  85024. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  85025. /* Quick timeout should be cleared after a quick timeout */
  85026. /* CH3 */
  85027. ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_c), 0);
  85028. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  85029. }
  85030. /* Parse out to make sure we got exactly one ClientHello message */
  85031. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  85032. /* Second ClientHello after HVR */
  85033. sequence_number[7] = 2;
  85034. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.s_buff;
  85035. ExpectIntEQ(dtlsRH->type, handshake);
  85036. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  85037. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  85038. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  85039. sizeof(sequence_number)), 0);
  85040. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  85041. ExpectIntEQ(sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  85042. /* Connection should be able to continue */
  85043. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85044. wolfSSL_free(ssl_c);
  85045. wolfSSL_free(ssl_s);
  85046. wolfSSL_CTX_free(ctx_c);
  85047. wolfSSL_CTX_free(ctx_s);
  85048. ssl_c = NULL;
  85049. ssl_s = NULL;
  85050. ctx_c = NULL;
  85051. ctx_s = NULL;
  85052. if (!EXPECT_SUCCESS())
  85053. break;
  85054. }
  85055. #endif
  85056. return EXPECT_RESULT();
  85057. }
  85058. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  85059. static int test_dtls_client_hello_timeout_read_cb(WOLFSSL *ssl, char *data,
  85060. int sz, void *ctx)
  85061. {
  85062. static int call_counter = 0;
  85063. call_counter++;
  85064. (void)ssl;
  85065. (void)data;
  85066. (void)sz;
  85067. (void)ctx;
  85068. switch (call_counter) {
  85069. case 1:
  85070. return WOLFSSL_CBIO_ERR_TIMEOUT;
  85071. case 2:
  85072. return WOLFSSL_CBIO_ERR_WANT_READ;
  85073. default:
  85074. AssertIntLE(call_counter, 2);
  85075. return -1;
  85076. }
  85077. }
  85078. #endif
  85079. /* Make sure we don't send acks before getting a server hello */
  85080. static int test_dtls_client_hello_timeout(void)
  85081. {
  85082. EXPECT_DECLS;
  85083. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  85084. WOLFSSL *ssl_c = NULL;
  85085. WOLFSSL_CTX *ctx_c = NULL;
  85086. struct test_memio_ctx test_ctx;
  85087. DtlsRecordLayerHeader* dtlsRH;
  85088. size_t idx;
  85089. size_t len;
  85090. byte sequence_number[8];
  85091. int i;
  85092. for (i = 0; i < 2; i++) {
  85093. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85094. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  85095. wolfDTLSv1_3_client_method, NULL), 0);
  85096. if (i == 0) {
  85097. /* First time simulate timeout in IO layer */
  85098. wolfSSL_SSLSetIORecv(ssl_c, test_dtls_client_hello_timeout_read_cb);
  85099. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  85100. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85101. }
  85102. else {
  85103. /* Second time call wolfSSL_dtls_got_timeout */
  85104. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  85105. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85106. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  85107. }
  85108. /* Parse out to make sure we got exactly two ClientHello messages */
  85109. idx = 0;
  85110. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  85111. /* First ClientHello */
  85112. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.s_buff + idx);
  85113. ExpectIntEQ(dtlsRH->type, handshake);
  85114. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  85115. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  85116. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  85117. sizeof(sequence_number)), 0);
  85118. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  85119. ExpectIntLT(idx + sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  85120. idx += sizeof(DtlsRecordLayerHeader) + len;
  85121. /* Second ClientHello */
  85122. sequence_number[7] = 1;
  85123. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.s_buff + idx);
  85124. ExpectIntEQ(dtlsRH->type, handshake);
  85125. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  85126. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  85127. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  85128. sizeof(sequence_number)), 0);
  85129. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  85130. ExpectIntEQ(idx + sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  85131. wolfSSL_free(ssl_c);
  85132. wolfSSL_CTX_free(ctx_c);
  85133. ssl_c = NULL;
  85134. ctx_c = NULL;
  85135. if (!EXPECT_SUCCESS())
  85136. break;
  85137. }
  85138. #endif
  85139. return EXPECT_RESULT();
  85140. }
  85141. /* DTLS test when dropping the changed cipher spec message */
  85142. static int test_dtls_dropped_ccs(void)
  85143. {
  85144. EXPECT_DECLS;
  85145. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  85146. && !defined(WOLFSSL_NO_TLS12)
  85147. WOLFSSL_CTX *ctx_c = NULL;
  85148. WOLFSSL_CTX *ctx_s = NULL;
  85149. WOLFSSL *ssl_c = NULL;
  85150. WOLFSSL *ssl_s = NULL;
  85151. struct test_memio_ctx test_ctx;
  85152. DtlsRecordLayerHeader* dtlsRH;
  85153. size_t len;
  85154. byte data[1];
  85155. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85156. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85157. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  85158. /* CH1 */
  85159. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85160. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85161. /* HVR */
  85162. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85163. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85164. /* CH2 */
  85165. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85166. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85167. /* Server first flight */
  85168. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85169. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85170. /* Client flight */
  85171. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85172. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85173. /* Server ccs + finished */
  85174. ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1);
  85175. /* Drop the ccs */
  85176. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.c_buff;
  85177. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  85178. ExpectIntEQ(len, 1);
  85179. ExpectIntEQ(dtlsRH->type, change_cipher_spec);
  85180. if (EXPECT_SUCCESS()) {
  85181. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  85182. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  85183. (sizeof(DtlsRecordLayerHeader) + len));
  85184. }
  85185. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  85186. /* Client rtx flight */
  85187. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85188. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85189. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  85190. /* Server ccs + finished rtx */
  85191. ExpectIntEQ(wolfSSL_read(ssl_s, data, sizeof(data)), -1);
  85192. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85193. /* Client processes finished */
  85194. ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1);
  85195. wolfSSL_free(ssl_c);
  85196. wolfSSL_free(ssl_s);
  85197. wolfSSL_CTX_free(ctx_c);
  85198. wolfSSL_CTX_free(ctx_s);
  85199. #endif
  85200. return EXPECT_RESULT();
  85201. }
  85202. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  85203. && !defined(WOLFSSL_NO_TLS12)
  85204. static int test_dtls_seq_num_downgrade_check_num(byte* ioBuf, int ioBufLen,
  85205. byte seq_num)
  85206. {
  85207. EXPECT_DECLS;
  85208. DtlsRecordLayerHeader* dtlsRH;
  85209. byte sequence_number[8];
  85210. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  85211. ExpectIntGE(ioBufLen, sizeof(*dtlsRH));
  85212. dtlsRH = (DtlsRecordLayerHeader*)ioBuf;
  85213. ExpectIntEQ(dtlsRH->type, handshake);
  85214. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  85215. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  85216. sequence_number[7] = seq_num;
  85217. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  85218. sizeof(sequence_number)), 0);
  85219. return EXPECT_RESULT();
  85220. }
  85221. #endif
  85222. /*
  85223. * Make sure that we send the correct sequence number after a HelloVerifyRequest
  85224. * and after a HelloRetryRequest. This is testing the server side as it is
  85225. * operating statelessly and should copy the sequence number of the ClientHello.
  85226. */
  85227. static int test_dtls_seq_num_downgrade(void)
  85228. {
  85229. EXPECT_DECLS;
  85230. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  85231. && !defined(WOLFSSL_NO_TLS12)
  85232. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  85233. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  85234. struct test_memio_ctx test_ctx;
  85235. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85236. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85237. wolfDTLSv1_2_client_method, wolfDTLS_server_method), 0);
  85238. /* CH1 */
  85239. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85240. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85241. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.s_buff,
  85242. test_ctx.s_len, 0), TEST_SUCCESS);
  85243. /* HVR */
  85244. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85245. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85246. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.c_buff,
  85247. test_ctx.c_len, 0), TEST_SUCCESS);
  85248. /* CH2 */
  85249. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85250. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85251. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.s_buff,
  85252. test_ctx.s_len, 1), TEST_SUCCESS);
  85253. /* Server first flight */
  85254. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85255. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85256. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.c_buff,
  85257. test_ctx.c_len, 1), TEST_SUCCESS);
  85258. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85259. wolfSSL_free(ssl_c);
  85260. wolfSSL_CTX_free(ctx_c);
  85261. wolfSSL_free(ssl_s);
  85262. wolfSSL_CTX_free(ctx_s);
  85263. #endif
  85264. return EXPECT_RESULT();
  85265. }
  85266. /**
  85267. * Make sure we don't send RSA Signature Hash Algorithms in the
  85268. * CertificateRequest when we don't have any such ciphers set.
  85269. * @return EXPECT_RESULT()
  85270. */
  85271. static int test_certreq_sighash_algos(void)
  85272. {
  85273. EXPECT_DECLS;
  85274. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  85275. !defined(WOLFSSL_MAX_STRENGTH) && defined(HAVE_ECC) && \
  85276. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256) && \
  85277. defined(HAVE_AES_CBC) && !defined(WOLFSSL_NO_TLS12)
  85278. WOLFSSL_CTX *ctx_c = NULL;
  85279. WOLFSSL_CTX *ctx_s = NULL;
  85280. WOLFSSL *ssl_c = NULL;
  85281. WOLFSSL *ssl_s = NULL;
  85282. struct test_memio_ctx test_ctx;
  85283. int idx = 0;
  85284. int maxIdx = 0;
  85285. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85286. test_ctx.c_ciphers = test_ctx.s_ciphers =
  85287. "ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA384";
  85288. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85289. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  85290. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_c,
  85291. "./certs/ca-ecc-cert.pem", NULL), WOLFSSL_SUCCESS);
  85292. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER, NULL);
  85293. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ssl_s, "./certs/ecc-key.pem",
  85294. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  85295. ExpectIntEQ(wolfSSL_use_certificate_file(ssl_s, "./certs/server-ecc.pem",
  85296. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  85297. ExpectIntEQ(wolfSSL_connect(ssl_c), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  85298. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  85299. WOLFSSL_ERROR_WANT_READ);
  85300. ExpectIntEQ(wolfSSL_accept(ssl_s), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  85301. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  85302. WOLFSSL_ERROR_WANT_READ);
  85303. /* Find the CertificateRequest message */
  85304. for (idx = 0; idx < test_ctx.c_len && EXPECT_SUCCESS();) {
  85305. word16 len;
  85306. ExpectIntEQ(test_ctx.c_buff[idx++], handshake);
  85307. ExpectIntEQ(test_ctx.c_buff[idx++], SSLv3_MAJOR);
  85308. ExpectIntEQ(test_ctx.c_buff[idx++], TLSv1_2_MINOR);
  85309. ato16(test_ctx.c_buff + idx, &len);
  85310. idx += OPAQUE16_LEN;
  85311. if (test_ctx.c_buff[idx] == certificate_request) {
  85312. idx++;
  85313. /* length */
  85314. idx += OPAQUE24_LEN;
  85315. /* cert types */
  85316. idx += 1 + test_ctx.c_buff[idx];
  85317. /* Sig algos */
  85318. ato16(test_ctx.c_buff + idx, &len);
  85319. idx += OPAQUE16_LEN;
  85320. maxIdx = idx + (int)len;
  85321. for (; idx < maxIdx && EXPECT_SUCCESS(); idx += OPAQUE16_LEN) {
  85322. if (test_ctx.c_buff[idx+1] == ED25519_SA_MINOR ||
  85323. test_ctx.c_buff[idx+1] == ED448_SA_MINOR)
  85324. ExpectIntEQ(test_ctx.c_buff[idx], NEW_SA_MAJOR);
  85325. else
  85326. ExpectIntEQ(test_ctx.c_buff[idx+1], ecc_dsa_sa_algo);
  85327. }
  85328. break;
  85329. }
  85330. else {
  85331. idx += (int)len;
  85332. }
  85333. }
  85334. ExpectIntLT(idx, test_ctx.c_len);
  85335. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85336. wolfSSL_free(ssl_c);
  85337. wolfSSL_free(ssl_s);
  85338. wolfSSL_CTX_free(ctx_c);
  85339. wolfSSL_CTX_free(ctx_s);
  85340. #endif
  85341. return EXPECT_RESULT();
  85342. }
  85343. #if defined(HAVE_CRL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  85344. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  85345. static int test_revoked_loaded_int_cert_ctx_ready1(WOLFSSL_CTX* ctx)
  85346. {
  85347. EXPECT_DECLS;
  85348. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
  85349. myVerifyAction = VERIFY_USE_PREVERFIY;
  85350. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  85351. "./certs/ca-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  85352. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  85353. "./certs/intermediate/ca-int-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  85354. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  85355. WOLFSSL_SUCCESS);
  85356. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  85357. "./certs/crl/extra-crls/ca-int-cert-revoked.pem",
  85358. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  85359. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  85360. "./certs/crl/ca-int.pem",
  85361. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  85362. return EXPECT_RESULT();
  85363. }
  85364. static int test_revoked_loaded_int_cert_ctx_ready2(WOLFSSL_CTX* ctx)
  85365. {
  85366. EXPECT_DECLS;
  85367. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
  85368. myVerifyAction = VERIFY_USE_PREVERFIY;
  85369. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  85370. "./certs/ca-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  85371. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  85372. "./certs/intermediate/ca-int-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  85373. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  85374. "./certs/intermediate/ca-int2-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  85375. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  85376. WOLFSSL_SUCCESS);
  85377. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  85378. "./certs/crl/ca-int2.pem",
  85379. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  85380. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  85381. "./certs/crl/extra-crls/ca-int-cert-revoked.pem",
  85382. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  85383. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  85384. "./certs/crl/ca-int.pem",
  85385. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  85386. return EXPECT_RESULT();
  85387. }
  85388. static int test_revoked_loaded_int_cert_ctx_ready3_crl_missing_cb(int ret,
  85389. WOLFSSL_CRL* crl, WOLFSSL_CERT_MANAGER* cm, void* ctx)
  85390. {
  85391. (void)crl;
  85392. (void)cm;
  85393. (void)ctx;
  85394. if (ret == WC_NO_ERR_TRACE(CRL_MISSING))
  85395. return 1;
  85396. return 0;
  85397. }
  85398. /* Here we are allowing missing CRL's but want to error out when its revoked */
  85399. static int test_revoked_loaded_int_cert_ctx_ready3(WOLFSSL_CTX* ctx)
  85400. {
  85401. EXPECT_DECLS;
  85402. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
  85403. myVerifyAction = VERIFY_USE_PREVERFIY;
  85404. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  85405. "./certs/ca-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  85406. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  85407. "./certs/intermediate/ca-int-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  85408. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  85409. "./certs/intermediate/ca-int2-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  85410. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  85411. WOLFSSL_SUCCESS);
  85412. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  85413. "./certs/crl/extra-crls/ca-int-cert-revoked.pem",
  85414. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  85415. ExpectIntEQ(wolfSSL_CTX_SetCRL_ErrorCb(ctx,
  85416. test_revoked_loaded_int_cert_ctx_ready3_crl_missing_cb, NULL),
  85417. WOLFSSL_SUCCESS);
  85418. return EXPECT_RESULT();
  85419. }
  85420. #endif
  85421. static int test_revoked_loaded_int_cert(void)
  85422. {
  85423. EXPECT_DECLS;
  85424. #if defined(HAVE_CRL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  85425. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  85426. test_ssl_cbf client_cbf;
  85427. test_ssl_cbf server_cbf;
  85428. struct {
  85429. const char* certPemFile;
  85430. const char* keyPemFile;
  85431. ctx_cb client_ctx_ready;
  85432. } test_params[] = {
  85433. {"./certs/intermediate/ca-int2-cert.pem",
  85434. "./certs/intermediate/ca-int2-key.pem",
  85435. test_revoked_loaded_int_cert_ctx_ready1},
  85436. {"./certs/intermediate/server-chain.pem",
  85437. "./certs/server-key.pem", test_revoked_loaded_int_cert_ctx_ready2},
  85438. {"./certs/intermediate/server-chain-short.pem",
  85439. "./certs/server-key.pem", test_revoked_loaded_int_cert_ctx_ready2},
  85440. {"./certs/intermediate/server-chain-short.pem",
  85441. "./certs/server-key.pem", test_revoked_loaded_int_cert_ctx_ready3},
  85442. };
  85443. size_t i;
  85444. printf("\n");
  85445. for (i = 0; i < XELEM_CNT(test_params); i++) {
  85446. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  85447. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  85448. printf("\tTesting with %s...\n", test_params[i].certPemFile);
  85449. server_cbf.certPemFile = test_params[i].certPemFile;
  85450. server_cbf.keyPemFile = test_params[i].keyPemFile;
  85451. client_cbf.ctx_ready = test_params[i].client_ctx_ready;
  85452. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  85453. &server_cbf, NULL), -1001);
  85454. ExpectIntEQ(client_cbf.last_err, WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  85455. ExpectIntEQ(server_cbf.last_err, WC_NO_ERR_TRACE(FATAL_ERROR));
  85456. if (!EXPECT_SUCCESS())
  85457. break;
  85458. printf("\t%s passed\n", test_params[i].certPemFile);
  85459. }
  85460. #endif
  85461. return EXPECT_RESULT();
  85462. }
  85463. static int test_dtls13_frag_ch_pq(void)
  85464. {
  85465. EXPECT_DECLS;
  85466. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  85467. && defined(WOLFSSL_DTLS_CH_FRAG) && defined(HAVE_LIBOQS)
  85468. WOLFSSL_CTX *ctx_c = NULL;
  85469. WOLFSSL_CTX *ctx_s = NULL;
  85470. WOLFSSL *ssl_c = NULL;
  85471. WOLFSSL *ssl_s = NULL;
  85472. struct test_memio_ctx test_ctx;
  85473. const char *test_str = "test";
  85474. int test_str_size;
  85475. byte buf[255];
  85476. int group = WOLFSSL_KYBER_LEVEL5;
  85477. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85478. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85479. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  85480. /* Add in a large post-quantum key share to make the CH long. */
  85481. ExpectIntEQ(wolfSSL_set_groups(ssl_c, &group, 1), WOLFSSL_SUCCESS);
  85482. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, group), WOLFSSL_SUCCESS);
  85483. ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS);
  85484. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85485. ExpectStrEQ(wolfSSL_get_curve_name(ssl_c), "KYBER_LEVEL5");
  85486. ExpectStrEQ(wolfSSL_get_curve_name(ssl_s), "KYBER_LEVEL5");
  85487. test_str_size = XSTRLEN("test") + 1;
  85488. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  85489. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), test_str_size);
  85490. ExpectIntEQ(XSTRCMP((char*)buf, test_str), 0);
  85491. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  85492. wolfSSL_free(ssl_c);
  85493. wolfSSL_free(ssl_s);
  85494. wolfSSL_CTX_free(ctx_c);
  85495. wolfSSL_CTX_free(ctx_s);
  85496. #endif
  85497. return EXPECT_RESULT();
  85498. }
  85499. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  85500. && defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG)
  85501. static int test_dtls_frag_ch_count_records(byte* b, int len)
  85502. {
  85503. DtlsRecordLayerHeader* dtlsRH;
  85504. int records = 0;
  85505. size_t recordLen;
  85506. while (len > 0) {
  85507. records++;
  85508. dtlsRH = (DtlsRecordLayerHeader*)b;
  85509. recordLen = (dtlsRH->length[0] << 8) | dtlsRH->length[1];
  85510. b += sizeof(DtlsRecordLayerHeader) + recordLen;
  85511. len -= sizeof(DtlsRecordLayerHeader) + recordLen;
  85512. }
  85513. return records;
  85514. }
  85515. #endif
  85516. static int test_dtls_frag_ch(void)
  85517. {
  85518. EXPECT_DECLS;
  85519. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  85520. && defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG)
  85521. WOLFSSL_CTX *ctx_c = NULL;
  85522. WOLFSSL_CTX *ctx_s = NULL;
  85523. WOLFSSL *ssl_c = NULL;
  85524. WOLFSSL *ssl_s = NULL;
  85525. struct test_memio_ctx test_ctx;
  85526. static unsigned int DUMMY_MTU = 256;
  85527. unsigned char four_frag_CH[] = {
  85528. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  85529. 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  85530. 0xce, 0xfe, 0xfd, 0xf3, 0x94, 0x01, 0x33, 0x2c, 0xcf, 0x2c, 0x47, 0xb1,
  85531. 0xe5, 0xa1, 0x7b, 0x19, 0x3e, 0xac, 0x68, 0xdd, 0xe6, 0x17, 0x6b, 0x85,
  85532. 0xad, 0x5f, 0xfc, 0x7f, 0x6e, 0xf0, 0xb9, 0xe0, 0x2e, 0xca, 0x47, 0x00,
  85533. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  85534. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  85535. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  85536. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  85537. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x02,
  85538. 0x7c, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  85539. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  85540. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  85541. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x0c,
  85542. 0x00, 0x0a, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00,
  85543. 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x02, 0x39, 0x02, 0x37, 0x00, 0x17,
  85544. 0x00, 0x41, 0x04, 0x94, 0xdf, 0x36, 0xd7, 0xb3, 0x90, 0x6d, 0x01, 0xa1,
  85545. 0xe6, 0xed, 0x67, 0xf4, 0xd9, 0x9d, 0x2c, 0xac, 0x57, 0x74, 0xff, 0x19,
  85546. 0xbe, 0x5a, 0xc9, 0x30, 0x11, 0xb7, 0x2b, 0x59, 0x47, 0x80, 0x7c, 0xa9,
  85547. 0xb7, 0x31, 0x8c, 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  85548. 0x00, 0x01, 0x00, 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, 0x00, 0x00, 0x00,
  85549. 0xce, 0x00, 0x00, 0xce, 0x9e, 0x13, 0x74, 0x3b, 0x86, 0xba, 0x69, 0x1f,
  85550. 0x12, 0xf7, 0xcd, 0x78, 0x53, 0xe8, 0x50, 0x4d, 0x71, 0x3f, 0x4b, 0x4e,
  85551. 0xeb, 0x3e, 0xe5, 0x43, 0x54, 0x78, 0x17, 0x6d, 0x00, 0x18, 0x00, 0x61,
  85552. 0x04, 0xd1, 0x99, 0x66, 0x4f, 0xda, 0xc7, 0x12, 0x3b, 0xff, 0xb2, 0xd6,
  85553. 0x2f, 0x35, 0xb6, 0x17, 0x1f, 0xb3, 0xd0, 0xb6, 0x52, 0xff, 0x97, 0x8b,
  85554. 0x01, 0xe8, 0xd9, 0x68, 0x71, 0x40, 0x02, 0xd5, 0x68, 0x3a, 0x58, 0xb2,
  85555. 0x5d, 0xee, 0xa4, 0xe9, 0x5f, 0xf4, 0xaf, 0x3e, 0x30, 0x9c, 0x3e, 0x2b,
  85556. 0xda, 0x61, 0x43, 0x99, 0x02, 0x35, 0x33, 0x9f, 0xcf, 0xb5, 0xd3, 0x28,
  85557. 0x19, 0x9d, 0x1c, 0xbe, 0x69, 0x07, 0x9e, 0xfc, 0xe4, 0x8e, 0xcd, 0x86,
  85558. 0x4a, 0x1b, 0xf0, 0xfc, 0x17, 0x94, 0x66, 0x53, 0xda, 0x24, 0x5e, 0xaf,
  85559. 0xce, 0xec, 0x62, 0x4c, 0x06, 0xb4, 0x52, 0x94, 0xb1, 0x4a, 0x7a, 0x8c,
  85560. 0x4f, 0x00, 0x19, 0x00, 0x85, 0x04, 0x00, 0x27, 0xeb, 0x99, 0x49, 0x7f,
  85561. 0xcb, 0x2c, 0x46, 0x54, 0x2d, 0x93, 0x5d, 0x25, 0x92, 0x58, 0x5e, 0x06,
  85562. 0xc3, 0x7c, 0xfb, 0x9a, 0xa7, 0xec, 0xcd, 0x9f, 0xe1, 0x6b, 0x2d, 0x78,
  85563. 0xf5, 0x16, 0xa9, 0x20, 0x52, 0x48, 0x19, 0x0f, 0x1a, 0xd0, 0xce, 0xd8,
  85564. 0x68, 0xb1, 0x4e, 0x7f, 0x33, 0x03, 0x7d, 0x0c, 0x39, 0xdb, 0x9c, 0x4b,
  85565. 0xf4, 0xe7, 0xc2, 0xf5, 0xdd, 0x51, 0x9b, 0x03, 0xa8, 0x53, 0x2b, 0xe6,
  85566. 0x00, 0x15, 0x4b, 0xff, 0xd2, 0xa0, 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00,
  85567. 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00,
  85568. 0x00, 0x00, 0x01, 0x9c, 0x00, 0x00, 0xce, 0x58, 0x30, 0x10, 0x3d, 0x46,
  85569. 0xcc, 0xca, 0x1a, 0x44, 0xc8, 0x58, 0x9b, 0x27, 0x17, 0x67, 0x31, 0x96,
  85570. 0x8a, 0x66, 0x39, 0xf4, 0xcc, 0xc1, 0x9f, 0x12, 0x1f, 0x01, 0x30, 0x50,
  85571. 0x16, 0xd6, 0x89, 0x97, 0xa3, 0x66, 0xd7, 0x99, 0x50, 0x09, 0x6e, 0x80,
  85572. 0x87, 0xe4, 0xa2, 0x88, 0xae, 0xb4, 0x23, 0x57, 0x2f, 0x12, 0x60, 0xe7,
  85573. 0x7d, 0x44, 0x2d, 0xad, 0xbe, 0xe9, 0x0d, 0x01, 0x00, 0x01, 0x00, 0xd5,
  85574. 0xdd, 0x62, 0xee, 0xf3, 0x0e, 0xd9, 0x30, 0x0e, 0x38, 0xf3, 0x48, 0xf4,
  85575. 0xc9, 0x8f, 0x8c, 0x20, 0xf7, 0xd3, 0xa8, 0xb3, 0x87, 0x3c, 0x98, 0x5d,
  85576. 0x70, 0xc5, 0x03, 0x76, 0xb7, 0xd5, 0x0b, 0x7b, 0x23, 0x97, 0x6b, 0xe3,
  85577. 0xb5, 0x18, 0xeb, 0x64, 0x55, 0x18, 0xb2, 0x8a, 0x90, 0x1a, 0x8f, 0x0e,
  85578. 0x15, 0xda, 0xb1, 0x8e, 0x7f, 0xee, 0x1f, 0xe0, 0x3b, 0xb9, 0xed, 0xfc,
  85579. 0x4e, 0x3f, 0x78, 0x16, 0x39, 0x95, 0x5f, 0xb7, 0xcb, 0x65, 0x55, 0x72,
  85580. 0x7b, 0x7d, 0x86, 0x2f, 0x8a, 0xe5, 0xee, 0xf7, 0x57, 0x40, 0xf3, 0xc4,
  85581. 0x96, 0x4f, 0x11, 0x4d, 0x85, 0xf9, 0x56, 0xfa, 0x3d, 0xf0, 0xc9, 0xa4,
  85582. 0xec, 0x1e, 0xaa, 0x47, 0x90, 0x53, 0xdf, 0xe1, 0xb7, 0x78, 0x18, 0xeb,
  85583. 0xdd, 0x0d, 0x89, 0xb7, 0xf6, 0x15, 0x0e, 0x55, 0x12, 0xb3, 0x23, 0x17,
  85584. 0x0b, 0x59, 0x6f, 0x83, 0x05, 0x6b, 0xa6, 0xf8, 0x6c, 0x3a, 0x9b, 0x1b,
  85585. 0x50, 0x93, 0x51, 0xea, 0x95, 0x2d, 0x99, 0x96, 0x38, 0x16, 0xfe, 0xfd,
  85586. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x7e, 0x01, 0x00,
  85587. 0x02, 0xdc, 0x00, 0x00, 0x00, 0x02, 0x6a, 0x00, 0x00, 0x72, 0x2d, 0x66,
  85588. 0x3e, 0xf2, 0x36, 0x5a, 0xf2, 0x23, 0x8f, 0x28, 0x09, 0xa9, 0x55, 0x8c,
  85589. 0x8f, 0xc0, 0x0d, 0x61, 0x98, 0x33, 0x56, 0x87, 0x7a, 0xfd, 0xa7, 0x50,
  85590. 0x71, 0x84, 0x2e, 0x41, 0x58, 0x00, 0x87, 0xd9, 0x27, 0xe5, 0x7b, 0xf4,
  85591. 0x6d, 0x84, 0x4e, 0x2e, 0x0c, 0x80, 0x0c, 0xf3, 0x8a, 0x02, 0x4b, 0x99,
  85592. 0x3a, 0x1f, 0x9f, 0x18, 0x7d, 0x1c, 0xec, 0xad, 0x60, 0x54, 0xa6, 0xa3,
  85593. 0x2c, 0x82, 0x5e, 0xf8, 0x8f, 0xae, 0xe1, 0xc4, 0x82, 0x7e, 0x43, 0x43,
  85594. 0xc5, 0x99, 0x49, 0x05, 0xd3, 0xf6, 0xdf, 0xa1, 0xb5, 0x2d, 0x0c, 0x13,
  85595. 0x2f, 0x1e, 0xb6, 0x28, 0x7c, 0x5c, 0xa1, 0x02, 0x6b, 0x8d, 0xa3, 0xeb,
  85596. 0xd4, 0x58, 0xe6, 0xa0, 0x7e, 0x6b, 0xaa, 0x09, 0x43, 0x67, 0x71, 0x87,
  85597. 0xa5, 0xcb, 0x68, 0xf3
  85598. };
  85599. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85600. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85601. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  85602. /* Fragment msgs */
  85603. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_c, DUMMY_MTU), WOLFSSL_SUCCESS);
  85604. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_s, DUMMY_MTU), WOLFSSL_SUCCESS);
  85605. /* Add in some key shares to make the CH long */
  85606. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP256R1),
  85607. WOLFSSL_SUCCESS);
  85608. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP384R1),
  85609. WOLFSSL_SUCCESS);
  85610. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP521R1),
  85611. WOLFSSL_SUCCESS);
  85612. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_FFDHE_2048),
  85613. WOLFSSL_SUCCESS);
  85614. ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS);
  85615. /* Reject fragmented first CH */
  85616. ExpectIntEQ(test_dtls_frag_ch_count_records(four_frag_CH,
  85617. sizeof(four_frag_CH)), 4);
  85618. XMEMCPY(test_ctx.s_buff, four_frag_CH, sizeof(four_frag_CH));
  85619. test_ctx.s_len = sizeof(four_frag_CH);
  85620. while (test_ctx.s_len > 0 && EXPECT_SUCCESS()) {
  85621. int s_len = test_ctx.s_len;
  85622. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85623. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85624. /* Fail if we didn't advance the buffer to avoid infinite loops */
  85625. ExpectIntLT(test_ctx.s_len, s_len);
  85626. }
  85627. /* Expect all fragments read */
  85628. ExpectIntEQ(test_ctx.s_len, 0);
  85629. /* Expect quietly dropping fragmented first CH */
  85630. ExpectIntEQ(test_ctx.c_len, 0);
  85631. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH)
  85632. /* Disable ECH as it pushes it over our MTU */
  85633. wolfSSL_SetEchEnable(ssl_c, 0);
  85634. #endif
  85635. /* Limit options to make the CH a fixed length */
  85636. /* See wolfSSL_parse_cipher_list for reason why we provide 1.3 AND 1.2
  85637. * ciphersuite. This is only necessary when building with OPENSSL_EXTRA. */
  85638. ExpectTrue(wolfSSL_set_cipher_list(ssl_c, "TLS13-AES256-GCM-SHA384"
  85639. #ifdef OPENSSL_EXTRA
  85640. ":DHE-RSA-AES256-GCM-SHA384"
  85641. #endif
  85642. ));
  85643. /* CH1 */
  85644. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85645. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85646. /* Count records. Expect 1 unfragmented CH */
  85647. ExpectIntEQ(test_dtls_frag_ch_count_records(test_ctx.s_buff,
  85648. test_ctx.s_len), 1);
  85649. /* HRR */
  85650. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85651. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85652. /* CH2 */
  85653. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85654. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85655. /* Count records. Expect fragmented CH */
  85656. ExpectIntGT(test_dtls_frag_ch_count_records(test_ctx.s_buff,
  85657. test_ctx.s_len), 1);
  85658. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85659. wolfSSL_free(ssl_c);
  85660. wolfSSL_free(ssl_s);
  85661. wolfSSL_CTX_free(ctx_c);
  85662. wolfSSL_CTX_free(ctx_s);
  85663. ssl_c = ssl_s = NULL;
  85664. ctx_c = ctx_s = NULL;
  85665. #endif
  85666. return EXPECT_RESULT();
  85667. }
  85668. static int test_dtls_empty_keyshare_with_cookie(void)
  85669. {
  85670. EXPECT_DECLS;
  85671. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  85672. WOLFSSL_CTX *ctx_s = NULL;
  85673. WOLFSSL *ssl_s = NULL;
  85674. struct test_memio_ctx test_ctx;
  85675. unsigned char ch_empty_keyshare_with_cookie[] = {
  85676. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
  85677. 0x12, 0x01, 0x00, 0x01, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
  85678. 0x06, 0xfe, 0xfd, 0xfb, 0x8c, 0x9b, 0x28, 0xae, 0x50, 0x1c, 0x4d, 0xf3,
  85679. 0xb8, 0xcf, 0x4d, 0xd8, 0x7e, 0x93, 0x13, 0x7b, 0x9e, 0xd9, 0xeb, 0xe9,
  85680. 0x13, 0x4b, 0x0d, 0x7f, 0x2e, 0x43, 0x62, 0x8c, 0xe4, 0x57, 0x79, 0x00,
  85681. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  85682. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  85683. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  85684. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  85685. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x00,
  85686. 0xa6, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x2c, 0x00, 0x47,
  85687. 0x00, 0x45, 0x20, 0xee, 0x4b, 0x17, 0x70, 0x63, 0xa0, 0x4c, 0x82, 0xbf,
  85688. 0x43, 0x01, 0x7d, 0x8d, 0xc1, 0x1b, 0x4e, 0x9b, 0xa0, 0x3c, 0x53, 0x1f,
  85689. 0xb7, 0xd1, 0x10, 0x81, 0xa8, 0xdf, 0xdf, 0x8c, 0x7f, 0xf3, 0x11, 0x13,
  85690. 0x01, 0x02, 0x3d, 0x3b, 0x7d, 0x14, 0x2c, 0x31, 0xb3, 0x60, 0x72, 0x4d,
  85691. 0xe5, 0x1a, 0xb2, 0xa3, 0x61, 0x77, 0x73, 0x03, 0x40, 0x0e, 0x5f, 0xc5,
  85692. 0x61, 0x38, 0x43, 0x56, 0x21, 0x4a, 0x95, 0xd5, 0x35, 0xa8, 0x0d, 0x00,
  85693. 0x0d, 0x00, 0x2a, 0x00, 0x28, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02,
  85694. 0x03, 0xfe, 0x0b, 0xfe, 0x0e, 0xfe, 0xa0, 0xfe, 0xa3, 0xfe, 0xa5, 0x08,
  85695. 0x06, 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06,
  85696. 0x01, 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00,
  85697. 0x18, 0x00, 0x16, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01,
  85698. 0x00, 0x02, 0x3a, 0x02, 0x3c, 0x02, 0x3d, 0x2f, 0x3a, 0x2f, 0x3c, 0x2f,
  85699. 0x3d, 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x00, 0x02, 0x00, 0x00
  85700. };
  85701. DtlsRecordLayerHeader* dtlsRH;
  85702. byte sequence_number[8];
  85703. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  85704. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85705. XMEMCPY(test_ctx.s_buff, ch_empty_keyshare_with_cookie,
  85706. sizeof(ch_empty_keyshare_with_cookie));
  85707. test_ctx.s_len = sizeof(ch_empty_keyshare_with_cookie);
  85708. ExpectIntEQ(test_memio_setup(&test_ctx, NULL, &ctx_s, NULL, &ssl_s,
  85709. NULL, wolfDTLSv1_3_server_method), 0);
  85710. /* CH1 */
  85711. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85712. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85713. /* Expect an alert. A plaintext alert should be exactly 15 bytes. */
  85714. ExpectIntEQ(test_ctx.c_len, 15);
  85715. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.c_buff;
  85716. ExpectIntEQ(dtlsRH->type, alert);
  85717. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  85718. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  85719. sequence_number[7] = 1;
  85720. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  85721. sizeof(sequence_number)), 0);
  85722. ExpectIntEQ(dtlsRH->length[0], 0);
  85723. ExpectIntEQ(dtlsRH->length[1], 2);
  85724. ExpectIntEQ(test_ctx.c_buff[13], alert_fatal);
  85725. ExpectIntEQ(test_ctx.c_buff[14], illegal_parameter);
  85726. wolfSSL_free(ssl_s);
  85727. wolfSSL_CTX_free(ctx_s);
  85728. #endif
  85729. return EXPECT_RESULT();
  85730. }
  85731. static int test_dtls_old_seq_number(void)
  85732. {
  85733. EXPECT_DECLS;
  85734. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS)
  85735. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  85736. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  85737. struct test_memio_ctx test_ctx;
  85738. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85739. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85740. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  85741. /* CH1 */
  85742. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85743. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85744. /* HVR */
  85745. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85746. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85747. /* CH2 */
  85748. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85749. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85750. /* Server first flight */
  85751. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85752. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85753. /* Client second flight */
  85754. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85755. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85756. /* Modify the sequence number */
  85757. {
  85758. DtlsRecordLayerHeader* dtlsRH = (DtlsRecordLayerHeader*)test_ctx.s_buff;
  85759. XMEMSET(dtlsRH->sequence_number, 0, sizeof(dtlsRH->sequence_number));
  85760. }
  85761. /* Server second flight */
  85762. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85763. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85764. /* Server should not do anything as a pkt was dropped */
  85765. ExpectIntEQ(test_ctx.c_len, 0);
  85766. ExpectIntEQ(test_ctx.s_len, 0);
  85767. /* Trigger rtx */
  85768. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  85769. /* Complete connection */
  85770. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85771. wolfSSL_free(ssl_c);
  85772. wolfSSL_CTX_free(ctx_c);
  85773. wolfSSL_free(ssl_s);
  85774. wolfSSL_CTX_free(ctx_s);
  85775. #endif
  85776. return EXPECT_RESULT();
  85777. }
  85778. static int test_dtls12_basic_connection_id(void)
  85779. {
  85780. EXPECT_DECLS;
  85781. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS_CID)
  85782. unsigned char client_cid[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
  85783. unsigned char server_cid[] = { 0, 1, 2, 3, 4, 5 };
  85784. unsigned char readBuf[40];
  85785. const char* params[] = {
  85786. #ifndef NO_RSA
  85787. #ifndef NO_SHA256
  85788. #if defined(WOLFSSL_AES_128) && defined(WOLFSSL_STATIC_RSA)
  85789. "AES128-SHA256",
  85790. #ifdef HAVE_AESCCM
  85791. "AES128-CCM8",
  85792. #endif
  85793. "DHE-RSA-AES128-SHA256",
  85794. "ECDHE-RSA-AES128-SHA256",
  85795. #ifdef HAVE_AESGCM
  85796. "DHE-RSA-AES128-GCM-SHA256",
  85797. "ECDHE-RSA-AES128-GCM-SHA256",
  85798. #endif
  85799. #endif /* WOLFSSL_AES_128 && WOLFSSL_STATIC_RSA */
  85800. #endif /* NO_SHA256 */
  85801. #endif /* NO_RSA */
  85802. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  85803. "DHE-RSA-CHACHA20-POLY1305",
  85804. "DHE-RSA-CHACHA20-POLY1305-OLD",
  85805. "ECDHE-RSA-CHACHA20-POLY1305",
  85806. "ECDHE-RSA-CHACHA20-POLY1305-OLD",
  85807. #endif
  85808. #ifndef NO_PSK
  85809. "DHE-PSK-AES128-CBC-SHA256",
  85810. "DHE-PSK-AES256-GCM-SHA384",
  85811. #ifndef HAVE_NULL_CIPHER
  85812. "DHE-PSK-NULL-SHA256",
  85813. #endif
  85814. "DHE-PSK-AES128-CCM",
  85815. #endif
  85816. };
  85817. size_t i;
  85818. struct {
  85819. byte drop:1;
  85820. byte changeCID:1;
  85821. } run_params[] = {
  85822. { .drop = 0, .changeCID = 0 },
  85823. { .drop = 1, .changeCID = 0 },
  85824. { .drop = 0, .changeCID = 1 },
  85825. };
  85826. /* We check if the side included the CID in their output */
  85827. #define CLIENT_CID() mymemmem(test_ctx.s_buff, test_ctx.s_len, \
  85828. client_cid, sizeof(client_cid))
  85829. #define SERVER_CID() mymemmem(test_ctx.c_buff, test_ctx.c_len, \
  85830. server_cid, sizeof(server_cid))
  85831. printf("\n");
  85832. for (i = 0; i < XELEM_CNT(params) && EXPECT_SUCCESS(); i++) {
  85833. size_t j;
  85834. for (j = 0; j < XELEM_CNT(run_params); j++) {
  85835. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  85836. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  85837. struct test_memio_ctx test_ctx;
  85838. printf("Testing %s run #%ld ... ", params[i], j);
  85839. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85840. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
  85841. &ssl_s, wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method),
  85842. 0);
  85843. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, params[i]), 1);
  85844. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, params[i]), 1);
  85845. ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_c), 1);
  85846. ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_c, server_cid,
  85847. sizeof(server_cid)), 1);
  85848. ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_s), 1);
  85849. ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_s, client_cid,
  85850. sizeof(client_cid)), 1);
  85851. #ifndef NO_PSK
  85852. if (XSTRSTR(params[i], "-PSK-") != NULL) {
  85853. wolfSSL_set_psk_client_callback(ssl_c, my_psk_client_cb);
  85854. wolfSSL_set_psk_server_callback(ssl_s, my_psk_server_cb);
  85855. }
  85856. #endif
  85857. #ifdef HAVE_SECURE_RENEGOTIATION
  85858. ExpectIntEQ(wolfSSL_UseSecureRenegotiation(ssl_c), 1);
  85859. ExpectIntEQ(wolfSSL_UseSecureRenegotiation(ssl_s), 1);
  85860. #endif
  85861. /* CH1 */
  85862. wolfSSL_SetLoggingPrefix("client");
  85863. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85864. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85865. ExpectNull(CLIENT_CID());
  85866. if (run_params[j].drop) {
  85867. test_ctx.c_len = test_ctx.s_len = 0;
  85868. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), 1);
  85869. ExpectNull(CLIENT_CID());
  85870. }
  85871. /* HVR */
  85872. wolfSSL_SetLoggingPrefix("server");
  85873. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85874. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85875. ExpectNull(SERVER_CID());
  85876. /* No point dropping HVR */
  85877. /* CH2 */
  85878. wolfSSL_SetLoggingPrefix("client");
  85879. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85880. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85881. ExpectNull(CLIENT_CID());
  85882. if (run_params[j].drop) {
  85883. test_ctx.c_len = test_ctx.s_len = 0;
  85884. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), 1);
  85885. ExpectNull(CLIENT_CID());
  85886. }
  85887. /* Server first flight */
  85888. wolfSSL_SetLoggingPrefix("server");
  85889. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85890. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85891. ExpectNull(SERVER_CID());
  85892. if (run_params[j].drop) {
  85893. test_ctx.c_len = test_ctx.s_len = 0;
  85894. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), 1);
  85895. ExpectNull(SERVER_CID());
  85896. }
  85897. /* Client second flight */
  85898. wolfSSL_SetLoggingPrefix("client");
  85899. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85900. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85901. ExpectNotNull(CLIENT_CID());
  85902. if (run_params[j].drop) {
  85903. test_ctx.c_len = test_ctx.s_len = 0;
  85904. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), 1);
  85905. ExpectNotNull(CLIENT_CID());
  85906. }
  85907. /* Server second flight */
  85908. wolfSSL_SetLoggingPrefix("server");
  85909. ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1);
  85910. ExpectNotNull(SERVER_CID());
  85911. if (run_params[j].drop) {
  85912. test_ctx.c_len = test_ctx.s_len = 0;
  85913. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), 1);
  85914. ExpectNotNull(SERVER_CID());
  85915. }
  85916. /* Client complete connection */
  85917. wolfSSL_SetLoggingPrefix("client");
  85918. ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1);
  85919. ExpectNull(CLIENT_CID());
  85920. /* Write some data */
  85921. wolfSSL_SetLoggingPrefix("client");
  85922. ExpectIntEQ(wolfSSL_write(ssl_c, params[i],
  85923. (int)XSTRLEN(params[i])), XSTRLEN(params[i]));
  85924. ExpectNotNull(CLIENT_CID());
  85925. wolfSSL_SetLoggingPrefix("server");
  85926. ExpectIntEQ(wolfSSL_write(ssl_s, params[i],
  85927. (int)XSTRLEN(params[i])), XSTRLEN(params[i]));
  85928. ExpectNotNull(SERVER_CID());
  85929. /* Read the data */
  85930. wolfSSL_SetLoggingPrefix("client");
  85931. XMEMSET(readBuf, 0, sizeof(readBuf));
  85932. ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)),
  85933. XSTRLEN(params[i]));
  85934. ExpectStrEQ(readBuf, params[i]);
  85935. XMEMSET(readBuf, 0, sizeof(readBuf));
  85936. wolfSSL_SetLoggingPrefix("server");
  85937. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)),
  85938. XSTRLEN(params[i]));
  85939. ExpectStrEQ(readBuf, params[i]);
  85940. /* Write short data */
  85941. wolfSSL_SetLoggingPrefix("client");
  85942. ExpectIntEQ(wolfSSL_write(ssl_c, params[i], 1), 1);
  85943. ExpectNotNull(CLIENT_CID());
  85944. wolfSSL_SetLoggingPrefix("server");
  85945. ExpectIntEQ(wolfSSL_write(ssl_s, params[i], 1), 1);
  85946. ExpectNotNull(SERVER_CID());
  85947. /* Read the short data */
  85948. XMEMSET(readBuf, 0, sizeof(readBuf));
  85949. wolfSSL_SetLoggingPrefix("client");
  85950. ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), 1);
  85951. ExpectIntEQ(readBuf[0], params[i][0]);
  85952. XMEMSET(readBuf, 0, sizeof(readBuf));
  85953. wolfSSL_SetLoggingPrefix("server");
  85954. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), 1);
  85955. ExpectIntEQ(readBuf[0], params[i][0]);
  85956. #ifdef HAVE_SECURE_RENEGOTIATION
  85957. /* do two SCR's */
  85958. wolfSSL_SetLoggingPrefix("client");
  85959. ExpectIntEQ(wolfSSL_Rehandshake(ssl_c), -1);
  85960. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85961. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), -1);
  85962. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85963. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85964. /* SCR's after the first one have extra internal logic */
  85965. wolfSSL_SetLoggingPrefix("client");
  85966. ExpectIntEQ(wolfSSL_Rehandshake(ssl_c), -1);
  85967. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85968. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), -1);
  85969. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85970. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85971. if (run_params[j].changeCID) {
  85972. ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_c, client_cid,
  85973. sizeof(client_cid)), 0);
  85974. /* Forcefully change the CID */
  85975. ssl_c->dtlsCidInfo->rx->id[0] = -1;
  85976. /* We need to init the rehandshake from the client, otherwise
  85977. * we won't be able to test changing the CID. It would be
  85978. * rejected by the record CID matching code. */
  85979. wolfSSL_SetLoggingPrefix("client");
  85980. ExpectIntEQ(wolfSSL_Rehandshake(ssl_c), -1);
  85981. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1),
  85982. WOLFSSL_ERROR_WANT_READ);
  85983. ExpectNotNull(CLIENT_CID());
  85984. ExpectIntEQ(wolfSSL_SSL_renegotiate_pending(ssl_c), 1);
  85985. /* Server first flight */
  85986. wolfSSL_SetLoggingPrefix("server");
  85987. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), -1);
  85988. /* We expect the server to reject the CID change. */
  85989. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), DTLS_CID_ERROR);
  85990. goto loop_exit;
  85991. }
  85992. /* Server init'd SCR */
  85993. /* Server request */
  85994. wolfSSL_SetLoggingPrefix("server");
  85995. ExpectIntEQ(wolfSSL_Rehandshake(ssl_s), -1);
  85996. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85997. ExpectNotNull(SERVER_CID());
  85998. ExpectIntEQ(wolfSSL_SSL_renegotiate_pending(ssl_s), 1);
  85999. if (run_params[j].drop) {
  86000. test_ctx.c_len = test_ctx.s_len = 0;
  86001. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), 1);
  86002. ExpectNotNull(SERVER_CID());
  86003. }
  86004. /* Init SCR on client side with the server's request */
  86005. /* CH no HVR on SCR */
  86006. XMEMSET(readBuf, 0, sizeof(readBuf));
  86007. wolfSSL_SetLoggingPrefix("client");
  86008. ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), -1);
  86009. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86010. ExpectNotNull(CLIENT_CID());
  86011. ExpectIntEQ(wolfSSL_SSL_renegotiate_pending(ssl_c), 1);
  86012. if (run_params[j].drop) {
  86013. test_ctx.c_len = test_ctx.s_len = 0;
  86014. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), 1);
  86015. ExpectNotNull(CLIENT_CID());
  86016. }
  86017. /* Server first flight */
  86018. wolfSSL_SetLoggingPrefix("server");
  86019. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  86020. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  86021. ExpectNotNull(SERVER_CID());
  86022. if (run_params[j].drop) {
  86023. test_ctx.c_len = test_ctx.s_len = 0;
  86024. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), 1);
  86025. ExpectNotNull(SERVER_CID());
  86026. }
  86027. /* Client second flight */
  86028. wolfSSL_SetLoggingPrefix("client");
  86029. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  86030. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86031. ExpectNotNull(CLIENT_CID());
  86032. if (run_params[j].drop) {
  86033. test_ctx.c_len = test_ctx.s_len = 0;
  86034. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), 1);
  86035. ExpectNotNull(CLIENT_CID());
  86036. }
  86037. ExpectIntEQ(wolfSSL_write(ssl_c, params[i],
  86038. (int)XSTRLEN(params[i])), XSTRLEN(params[i]));
  86039. /* Server second flight */
  86040. wolfSSL_SetLoggingPrefix("server");
  86041. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  86042. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), APP_DATA_READY);
  86043. XMEMSET(readBuf, 0, sizeof(readBuf));
  86044. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)),
  86045. XSTRLEN(params[i]));
  86046. ExpectStrEQ(readBuf, params[i]);
  86047. if (!run_params[j].drop) {
  86048. ExpectIntEQ(wolfSSL_write(ssl_s, params[i],
  86049. (int)XSTRLEN(params[i])), XSTRLEN(params[i]));
  86050. }
  86051. ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1);
  86052. ExpectNotNull(SERVER_CID());
  86053. if (run_params[j].drop) {
  86054. test_ctx.c_len = test_ctx.s_len = 0;
  86055. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), 1);
  86056. ExpectNotNull(SERVER_CID());
  86057. }
  86058. /* Test loading old epoch */
  86059. /* Client complete connection */
  86060. wolfSSL_SetLoggingPrefix("client");
  86061. if (!run_params[j].drop) {
  86062. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  86063. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), APP_DATA_READY);
  86064. XMEMSET(readBuf, 0, sizeof(readBuf));
  86065. ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)),
  86066. XSTRLEN(params[i]));
  86067. ExpectStrEQ(readBuf, params[i]);
  86068. }
  86069. ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1);
  86070. ExpectNull(CLIENT_CID());
  86071. ExpectIntEQ(wolfSSL_SSL_renegotiate_pending(ssl_c), 0);
  86072. ExpectIntEQ(wolfSSL_SSL_renegotiate_pending(ssl_s), 0);
  86073. #endif
  86074. /* Close connection */
  86075. wolfSSL_SetLoggingPrefix("client");
  86076. ExpectIntEQ(wolfSSL_shutdown(ssl_c), WOLFSSL_SHUTDOWN_NOT_DONE);
  86077. ExpectNotNull(CLIENT_CID());
  86078. wolfSSL_SetLoggingPrefix("server");
  86079. ExpectIntEQ(wolfSSL_shutdown(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE);
  86080. ExpectNotNull(SERVER_CID());
  86081. wolfSSL_SetLoggingPrefix("client");
  86082. ExpectIntEQ(wolfSSL_shutdown(ssl_c), 1);
  86083. wolfSSL_SetLoggingPrefix("server");
  86084. ExpectIntEQ(wolfSSL_shutdown(ssl_s), 1);
  86085. #ifdef HAVE_SECURE_RENEGOTIATION
  86086. loop_exit:
  86087. #endif
  86088. wolfSSL_SetLoggingPrefix(NULL);
  86089. wolfSSL_free(ssl_c);
  86090. wolfSSL_CTX_free(ctx_c);
  86091. wolfSSL_free(ssl_s);
  86092. wolfSSL_CTX_free(ctx_s);
  86093. if (EXPECT_SUCCESS())
  86094. printf("ok\n");
  86095. else
  86096. printf("failed\n");
  86097. }
  86098. }
  86099. #undef CLIENT_CID
  86100. #undef SERVER_CID
  86101. #endif
  86102. return EXPECT_RESULT();
  86103. }
  86104. static int test_dtls13_basic_connection_id(void)
  86105. {
  86106. EXPECT_DECLS;
  86107. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  86108. && defined(WOLFSSL_DTLS_CID)
  86109. unsigned char client_cid[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
  86110. unsigned char server_cid[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  86111. unsigned char readBuf[30];
  86112. const char* params[] = {
  86113. #ifndef NO_SHA256
  86114. #ifdef WOLFSSL_AES_128
  86115. #ifdef HAVE_AESGCM
  86116. "TLS13-AES128-GCM-SHA256",
  86117. #endif
  86118. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  86119. "TLS13-CHACHA20-POLY1305-SHA256",
  86120. #endif
  86121. #ifdef HAVE_AESCCM
  86122. "TLS13-AES128-CCM-8-SHA256",
  86123. "TLS13-AES128-CCM-SHA256",
  86124. #endif
  86125. #endif
  86126. #ifdef HAVE_NULL_CIPHER
  86127. "TLS13-SHA256-SHA256",
  86128. #endif
  86129. #endif
  86130. };
  86131. size_t i;
  86132. /* We check if the side included the CID in their output */
  86133. #define CLIENT_CID() mymemmem(test_ctx.s_buff, test_ctx.s_len, \
  86134. client_cid, sizeof(client_cid))
  86135. #define SERVER_CID() mymemmem(test_ctx.c_buff, test_ctx.c_len, \
  86136. server_cid, sizeof(server_cid))
  86137. printf("\n");
  86138. for (i = 0; i < XELEM_CNT(params) && EXPECT_SUCCESS(); i++) {
  86139. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  86140. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  86141. struct test_memio_ctx test_ctx;
  86142. printf("Testing %s ... ", params[i]);
  86143. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  86144. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  86145. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  86146. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, params[i]), WOLFSSL_SUCCESS);
  86147. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, params[i]), WOLFSSL_SUCCESS);
  86148. ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_c), 1);
  86149. ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_c, server_cid, sizeof(server_cid)),
  86150. 1);
  86151. ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_s), 1);
  86152. ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_s, client_cid, sizeof(client_cid)),
  86153. 1);
  86154. /* CH1 */
  86155. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  86156. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86157. ExpectNull(CLIENT_CID());
  86158. /* HRR */
  86159. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  86160. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  86161. ExpectNull(SERVER_CID());
  86162. /* CH2 */
  86163. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  86164. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86165. ExpectNull(CLIENT_CID());
  86166. /* Server first flight */
  86167. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  86168. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  86169. ExpectNotNull(SERVER_CID());
  86170. /* Client second flight */
  86171. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  86172. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86173. ExpectNotNull(CLIENT_CID());
  86174. /* Server process flight */
  86175. ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1);
  86176. /* Client process flight */
  86177. ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1);
  86178. /* Write some data */
  86179. ExpectIntEQ(wolfSSL_write(ssl_c, params[i], (int)XSTRLEN(params[i])),
  86180. XSTRLEN(params[i]));
  86181. ExpectNotNull(CLIENT_CID());
  86182. ExpectIntEQ(wolfSSL_write(ssl_s, params[i], (int)XSTRLEN(params[i])),
  86183. XSTRLEN(params[i]));
  86184. ExpectNotNull(SERVER_CID());
  86185. /* Read the data */
  86186. XMEMSET(readBuf, 0, sizeof(readBuf));
  86187. ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)),
  86188. XSTRLEN(params[i]));
  86189. ExpectStrEQ(readBuf, params[i]);
  86190. XMEMSET(readBuf, 0, sizeof(readBuf));
  86191. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)),
  86192. XSTRLEN(params[i]));
  86193. ExpectStrEQ(readBuf, params[i]);
  86194. /* Write short data */
  86195. ExpectIntEQ(wolfSSL_write(ssl_c, params[i], 1), 1);
  86196. ExpectNotNull(CLIENT_CID());
  86197. ExpectIntEQ(wolfSSL_write(ssl_s, params[i], 1), 1);
  86198. ExpectNotNull(SERVER_CID());
  86199. /* Read the short data */
  86200. XMEMSET(readBuf, 0, sizeof(readBuf));
  86201. ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), 1);
  86202. ExpectIntEQ(readBuf[0], params[i][0]);
  86203. XMEMSET(readBuf, 0, sizeof(readBuf));
  86204. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), 1);
  86205. ExpectIntEQ(readBuf[0], params[i][0]);
  86206. /* Close connection */
  86207. ExpectIntEQ(wolfSSL_shutdown(ssl_c), WOLFSSL_SHUTDOWN_NOT_DONE);
  86208. ExpectNotNull(CLIENT_CID());
  86209. ExpectIntEQ(wolfSSL_shutdown(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE);
  86210. ExpectNotNull(SERVER_CID());
  86211. ExpectIntEQ(wolfSSL_shutdown(ssl_c), 1);
  86212. ExpectIntEQ(wolfSSL_shutdown(ssl_s), 1);
  86213. if (EXPECT_SUCCESS())
  86214. printf("ok\n");
  86215. else
  86216. printf("failed\n");
  86217. wolfSSL_free(ssl_c);
  86218. wolfSSL_CTX_free(ctx_c);
  86219. wolfSSL_free(ssl_s);
  86220. wolfSSL_CTX_free(ctx_s);
  86221. }
  86222. #undef CLIENT_CID
  86223. #undef SERVER_CID
  86224. #endif
  86225. return EXPECT_RESULT();
  86226. }
  86227. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  86228. defined(HAVE_LIBOQS)
  86229. static void test_tls13_pq_groups_ctx_ready(WOLFSSL_CTX* ctx)
  86230. {
  86231. int group = WOLFSSL_KYBER_LEVEL5;
  86232. AssertIntEQ(wolfSSL_CTX_set_groups(ctx, &group, 1), WOLFSSL_SUCCESS);
  86233. }
  86234. static void test_tls13_pq_groups_on_result(WOLFSSL* ssl)
  86235. {
  86236. AssertStrEQ(wolfSSL_get_curve_name(ssl), "KYBER_LEVEL5");
  86237. }
  86238. #endif
  86239. static int test_tls13_pq_groups(void)
  86240. {
  86241. EXPECT_DECLS;
  86242. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  86243. defined(HAVE_LIBOQS)
  86244. callback_functions func_cb_client;
  86245. callback_functions func_cb_server;
  86246. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  86247. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  86248. func_cb_client.method = wolfTLSv1_3_client_method;
  86249. func_cb_server.method = wolfTLSv1_3_server_method;
  86250. func_cb_client.ctx_ready = test_tls13_pq_groups_ctx_ready;
  86251. func_cb_client.on_result = test_tls13_pq_groups_on_result;
  86252. func_cb_server.on_result = test_tls13_pq_groups_on_result;
  86253. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  86254. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  86255. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  86256. #endif
  86257. return EXPECT_RESULT();
  86258. }
  86259. static int test_tls13_early_data(void)
  86260. {
  86261. EXPECT_DECLS;
  86262. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  86263. defined(WOLFSSL_EARLY_DATA) && defined(HAVE_SESSION_TICKET)
  86264. int written = 0;
  86265. int read = 0;
  86266. size_t i;
  86267. int splitEarlyData;
  86268. char msg[] = "This is early data";
  86269. char msg2[] = "This is client data";
  86270. char msg3[] = "This is server data";
  86271. char msg4[] = "This is server immediate data";
  86272. char msgBuf[50];
  86273. struct {
  86274. method_provider client_meth;
  86275. method_provider server_meth;
  86276. const char* tls_version;
  86277. int isUdp;
  86278. } params[] = {
  86279. #ifdef WOLFSSL_TLS13
  86280. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  86281. "TLS 1.3", 0 },
  86282. #endif
  86283. #ifdef WOLFSSL_DTLS13
  86284. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  86285. "DTLS 1.3", 1 },
  86286. #endif
  86287. };
  86288. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  86289. for (splitEarlyData = 0; splitEarlyData < 2; splitEarlyData++) {
  86290. struct test_memio_ctx test_ctx;
  86291. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  86292. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  86293. WOLFSSL_SESSION *sess = NULL;
  86294. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  86295. fprintf(stderr, "\tEarly data with %s\n", params[i].tls_version);
  86296. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
  86297. &ssl_s, params[i].client_meth, params[i].server_meth), 0);
  86298. /* Get a ticket so that we can do 0-RTT on the next connection */
  86299. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  86300. /* Make sure we read the ticket */
  86301. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), -1);
  86302. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86303. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  86304. wolfSSL_free(ssl_c);
  86305. ssl_c = NULL;
  86306. wolfSSL_free(ssl_s);
  86307. ssl_s = NULL;
  86308. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  86309. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  86310. params[i].client_meth, params[i].server_meth), 0);
  86311. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  86312. #ifdef WOLFSSL_DTLS13
  86313. if (params[i].isUdp) {
  86314. #ifdef WOLFSSL_DTLS13_NO_HRR_ON_RESUME
  86315. ExpectIntEQ(wolfSSL_dtls13_no_hrr_on_resume(ssl_s, 1), WOLFSSL_SUCCESS);
  86316. #else
  86317. /* Let's test this but we generally don't recommend turning off the
  86318. * cookie exchange */
  86319. ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS);
  86320. #endif
  86321. }
  86322. #endif
  86323. /* Test 0-RTT data */
  86324. ExpectIntEQ(wolfSSL_write_early_data(ssl_c, msg, sizeof(msg),
  86325. &written), sizeof(msg));
  86326. ExpectIntEQ(written, sizeof(msg));
  86327. if (splitEarlyData) {
  86328. ExpectIntEQ(wolfSSL_write_early_data(ssl_c, msg, sizeof(msg),
  86329. &written), sizeof(msg));
  86330. ExpectIntEQ(written, sizeof(msg));
  86331. }
  86332. /* Read first 0-RTT data (if split otherwise entire data) */
  86333. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  86334. &read), sizeof(msg));
  86335. ExpectIntEQ(read, sizeof(msg));
  86336. ExpectStrEQ(msg, msgBuf);
  86337. /* Test 0.5-RTT data */
  86338. ExpectIntEQ(wolfSSL_write(ssl_s, msg4, sizeof(msg4)), sizeof(msg4));
  86339. if (splitEarlyData) {
  86340. /* Read second 0-RTT data */
  86341. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  86342. &read), sizeof(msg));
  86343. ExpectIntEQ(read, sizeof(msg));
  86344. ExpectStrEQ(msg, msgBuf);
  86345. }
  86346. if (params[i].isUdp) {
  86347. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  86348. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  86349. /* Read server 0.5-RTT data */
  86350. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg4));
  86351. ExpectStrEQ(msg4, msgBuf);
  86352. /* Complete handshake */
  86353. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  86354. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86355. /* Use wolfSSL_is_init_finished to check if handshake is complete. Normally
  86356. * a user would loop until it is true but here we control both sides so we
  86357. * just assert the expected value. wolfSSL_read_early_data does not provide
  86358. * handshake status to us with non-blocking IO and we can't use
  86359. * wolfSSL_accept as TLS layer may return ZERO_RETURN due to early data
  86360. * parsing logic. */
  86361. ExpectFalse(wolfSSL_is_init_finished(ssl_s));
  86362. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  86363. &read), 0);
  86364. ExpectIntEQ(read, 0);
  86365. ExpectTrue(wolfSSL_is_init_finished(ssl_s));
  86366. ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  86367. }
  86368. else {
  86369. ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  86370. ExpectFalse(wolfSSL_is_init_finished(ssl_s));
  86371. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  86372. &read), 0);
  86373. ExpectIntEQ(read, 0);
  86374. ExpectTrue(wolfSSL_is_init_finished(ssl_s));
  86375. /* Read server 0.5-RTT data */
  86376. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg4));
  86377. ExpectStrEQ(msg4, msgBuf);
  86378. }
  86379. /* Test bi-directional write */
  86380. ExpectIntEQ(wolfSSL_write(ssl_c, msg2, sizeof(msg2)), sizeof(msg2));
  86381. ExpectIntEQ(wolfSSL_read(ssl_s, msgBuf, sizeof(msgBuf)), sizeof(msg2));
  86382. ExpectStrEQ(msg2, msgBuf);
  86383. ExpectIntEQ(wolfSSL_write(ssl_s, msg3, sizeof(msg3)), sizeof(msg3));
  86384. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg3));
  86385. ExpectStrEQ(msg3, msgBuf);
  86386. ExpectTrue(wolfSSL_session_reused(ssl_c));
  86387. ExpectTrue(wolfSSL_session_reused(ssl_s));
  86388. wolfSSL_SESSION_free(sess);
  86389. wolfSSL_free(ssl_c);
  86390. wolfSSL_free(ssl_s);
  86391. wolfSSL_CTX_free(ctx_c);
  86392. wolfSSL_CTX_free(ctx_s);
  86393. }
  86394. }
  86395. #endif
  86396. return EXPECT_RESULT();
  86397. }
  86398. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
  86399. static int test_self_signed_stapling_client_v1_ctx_ready(WOLFSSL_CTX* ctx)
  86400. {
  86401. EXPECT_DECLS;
  86402. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  86403. ExpectIntEQ(wolfSSL_CTX_UseOCSPStapling(ctx, WOLFSSL_CSR_OCSP,
  86404. WOLFSSL_CSR_OCSP_USE_NONCE), 1);
  86405. return EXPECT_RESULT();
  86406. }
  86407. #endif
  86408. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
  86409. static int test_self_signed_stapling_client_v2_ctx_ready(WOLFSSL_CTX* ctx)
  86410. {
  86411. EXPECT_DECLS;
  86412. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  86413. ExpectIntEQ(wolfSSL_CTX_UseOCSPStaplingV2(ctx, WOLFSSL_CSR2_OCSP,
  86414. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  86415. return EXPECT_RESULT();
  86416. }
  86417. static int test_self_signed_stapling_client_v2_multi_ctx_ready(WOLFSSL_CTX* ctx)
  86418. {
  86419. EXPECT_DECLS;
  86420. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  86421. ExpectIntEQ(wolfSSL_CTX_UseOCSPStaplingV2(ctx, WOLFSSL_CSR2_OCSP_MULTI,
  86422. 0), 1);
  86423. return EXPECT_RESULT();
  86424. }
  86425. #endif
  86426. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  86427. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  86428. static int test_self_signed_stapling_server_ctx_ready(WOLFSSL_CTX* ctx)
  86429. {
  86430. EXPECT_DECLS;
  86431. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  86432. return EXPECT_RESULT();
  86433. }
  86434. #endif
  86435. static int test_self_signed_stapling(void)
  86436. {
  86437. EXPECT_DECLS;
  86438. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  86439. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  86440. test_ssl_cbf client_cbf;
  86441. test_ssl_cbf server_cbf;
  86442. size_t i;
  86443. struct {
  86444. method_provider client_meth;
  86445. method_provider server_meth;
  86446. ctx_cb client_ctx;
  86447. const char* tls_version;
  86448. } params[] = {
  86449. #if defined(WOLFSSL_TLS13) && defined(HAVE_CERTIFICATE_STATUS_REQUEST)
  86450. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  86451. test_self_signed_stapling_client_v1_ctx_ready, "TLSv1_3 v1" },
  86452. #endif
  86453. #ifndef WOLFSSL_NO_TLS12
  86454. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
  86455. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  86456. test_self_signed_stapling_client_v1_ctx_ready, "TLSv1_2 v1" },
  86457. #endif
  86458. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
  86459. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  86460. test_self_signed_stapling_client_v2_ctx_ready, "TLSv1_2 v2" },
  86461. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  86462. test_self_signed_stapling_client_v2_multi_ctx_ready,
  86463. "TLSv1_2 v2 multi" },
  86464. #endif
  86465. #endif
  86466. };
  86467. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  86468. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  86469. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  86470. printf("\nTesting self-signed cert with status request: %s\n",
  86471. params[i].tls_version);
  86472. client_cbf.method = params[i].client_meth;
  86473. client_cbf.ctx_ready = params[i].client_ctx;
  86474. server_cbf.method = params[i].server_meth;
  86475. server_cbf.certPemFile = "certs/ca-cert.pem";
  86476. server_cbf.keyPemFile = "certs/ca-key.pem";
  86477. server_cbf.ctx_ready = test_self_signed_stapling_server_ctx_ready;
  86478. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  86479. &server_cbf, NULL), TEST_SUCCESS);
  86480. }
  86481. #endif
  86482. return EXPECT_RESULT();
  86483. }
  86484. static int test_tls_multi_handshakes_one_record(void)
  86485. {
  86486. EXPECT_DECLS;
  86487. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  86488. struct test_memio_ctx test_ctx;
  86489. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  86490. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  86491. RecordLayerHeader* rh = NULL;
  86492. byte *len ;
  86493. int newRecIdx = RECORD_HEADER_SZ;
  86494. int idx = 0;
  86495. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  86496. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  86497. wolfTLS_client_method, wolfTLSv1_2_server_method), 0);
  86498. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  86499. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86500. ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
  86501. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  86502. /* Combine server handshake msgs into one record */
  86503. while (idx < test_ctx.c_len) {
  86504. word16 recLen;
  86505. rh = (RecordLayerHeader*)(test_ctx.c_buff + idx);
  86506. len = &rh->length[0];
  86507. ato16((const byte*)len, &recLen);
  86508. idx += RECORD_HEADER_SZ;
  86509. XMEMMOVE(test_ctx.c_buff + newRecIdx, test_ctx.c_buff + idx,
  86510. (size_t)recLen);
  86511. newRecIdx += recLen;
  86512. idx += recLen;
  86513. }
  86514. rh = (RecordLayerHeader*)(test_ctx.c_buff);
  86515. len = &rh->length[0];
  86516. c16toa((word16)newRecIdx - RECORD_HEADER_SZ, len);
  86517. test_ctx.c_len = newRecIdx;
  86518. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  86519. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86520. wolfSSL_free(ssl_c);
  86521. wolfSSL_free(ssl_s);
  86522. wolfSSL_CTX_free(ctx_c);
  86523. wolfSSL_CTX_free(ctx_s);
  86524. #endif
  86525. return EXPECT_RESULT();
  86526. }
  86527. static int test_write_dup(void)
  86528. {
  86529. EXPECT_DECLS;
  86530. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_WRITE_DUP)
  86531. size_t i, j;
  86532. char hiWorld[] = "dup message";
  86533. char readData[sizeof(hiWorld) + 5];
  86534. struct {
  86535. method_provider client_meth;
  86536. method_provider server_meth;
  86537. const char* version_name;
  86538. int version;
  86539. } methods[] = {
  86540. #ifndef WOLFSSL_NO_TLS12
  86541. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLS 1.2", WOLFSSL_TLSV1_2},
  86542. #endif
  86543. #ifdef WOLFSSL_TLS13
  86544. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLS 1.3", WOLFSSL_TLSV1_3},
  86545. #endif
  86546. };
  86547. struct {
  86548. const char* cipher;
  86549. int version;
  86550. } ciphers[] = {
  86551. /* For simplicity the macros are copied from internal.h */
  86552. /* TLS 1.2 */
  86553. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_SHA256)
  86554. #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
  86555. #ifndef NO_RSA
  86556. {"ECDHE-RSA-CHACHA20-POLY1305", WOLFSSL_TLSV1_2},
  86557. #endif
  86558. #endif
  86559. #if !defined(NO_DH) && !defined(NO_RSA) && !defined(NO_TLS_DH)
  86560. {"DHE-RSA-CHACHA20-POLY1305", WOLFSSL_TLSV1_2},
  86561. #endif
  86562. #endif
  86563. #if !defined(NO_DH) && !defined(NO_AES) && !defined(NO_TLS) && \
  86564. !defined(NO_RSA) && defined(HAVE_AESGCM) && !defined(NO_TLS_DH)
  86565. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  86566. {"DHE-RSA-AES128-GCM-SHA256", WOLFSSL_TLSV1_2},
  86567. #endif
  86568. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  86569. {"DHE-RSA-AES256-GCM-SHA384", WOLFSSL_TLSV1_2},
  86570. #endif
  86571. #endif
  86572. #if (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)) \
  86573. && !defined(NO_TLS) && !defined(NO_AES)
  86574. #ifdef HAVE_AESGCM
  86575. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  86576. #ifndef NO_RSA
  86577. {"ECDHE-RSA-AES128-GCM-SHA256", WOLFSSL_TLSV1_2},
  86578. #endif
  86579. #endif
  86580. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  86581. #ifndef NO_RSA
  86582. {"ECDHE-RSA-AES256-GCM-SHA384", WOLFSSL_TLSV1_2},
  86583. #endif
  86584. #endif
  86585. #endif
  86586. #endif
  86587. /* TLS 1.3 */
  86588. #ifdef WOLFSSL_TLS13
  86589. #ifdef HAVE_AESGCM
  86590. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  86591. {"TLS13-AES128-GCM-SHA256", WOLFSSL_TLSV1_3},
  86592. #endif
  86593. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  86594. {"TLS13-AES256-GCM-SHA384", WOLFSSL_TLSV1_3},
  86595. #endif
  86596. #endif
  86597. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  86598. #ifndef NO_SHA256
  86599. {"TLS13-CHACHA20-POLY1305-SHA256", WOLFSSL_TLSV1_3},
  86600. #endif
  86601. #endif
  86602. #ifdef HAVE_AESCCM
  86603. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  86604. {"TLS13-AES128-CCM-SHA256", WOLFSSL_TLSV1_3},
  86605. #endif
  86606. #endif
  86607. #endif
  86608. };
  86609. for (i = 0; i < XELEM_CNT(methods); i++) {
  86610. for (j = 0; j < XELEM_CNT(ciphers) && !EXPECT_FAIL(); j++) {
  86611. struct test_memio_ctx test_ctx;
  86612. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  86613. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  86614. WOLFSSL *ssl_c2 = NULL;
  86615. if (methods[i].version != ciphers[j].version)
  86616. continue;
  86617. if (i == 0 && j == 0)
  86618. printf("\n");
  86619. printf("Testing %s with %s... ", methods[i].version_name,
  86620. ciphers[j].cipher);
  86621. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  86622. test_ctx.c_ciphers = test_ctx.s_ciphers = ciphers[j].cipher;
  86623. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  86624. methods[i].client_meth, methods[i].server_meth), 0);
  86625. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  86626. ExpectNotNull(ssl_c2 = wolfSSL_write_dup(ssl_c));
  86627. ExpectIntEQ(wolfSSL_write(ssl_c, hiWorld, sizeof(hiWorld)),
  86628. WC_NO_ERR_TRACE(WRITE_DUP_WRITE_E));
  86629. ExpectIntEQ(wolfSSL_write(ssl_c2, hiWorld, sizeof(hiWorld)),
  86630. sizeof(hiWorld));
  86631. ExpectIntEQ(wolfSSL_read(ssl_s, readData, sizeof(readData)),
  86632. sizeof(hiWorld));
  86633. ExpectIntEQ(wolfSSL_write(ssl_s, hiWorld, sizeof(hiWorld)),
  86634. sizeof(hiWorld));
  86635. ExpectIntEQ(wolfSSL_read(ssl_c2, readData, sizeof(readData)),
  86636. WC_NO_ERR_TRACE(WRITE_DUP_READ_E));
  86637. ExpectIntEQ(wolfSSL_read(ssl_c, readData, sizeof(readData)),
  86638. sizeof(hiWorld));
  86639. if (EXPECT_SUCCESS())
  86640. printf("ok\n");
  86641. else
  86642. printf("failed\n");
  86643. wolfSSL_free(ssl_c);
  86644. wolfSSL_free(ssl_c2);
  86645. wolfSSL_free(ssl_s);
  86646. wolfSSL_CTX_free(ctx_c);
  86647. wolfSSL_CTX_free(ctx_s);
  86648. }
  86649. }
  86650. #endif
  86651. return EXPECT_RESULT();
  86652. }
  86653. static int test_read_write_hs(void)
  86654. {
  86655. EXPECT_DECLS;
  86656. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  86657. WOLFSSL_CTX *ctx_s = NULL, *ctx_c = NULL;
  86658. WOLFSSL *ssl_s = NULL, *ssl_c = NULL;
  86659. struct test_memio_ctx test_ctx;
  86660. byte test_buffer[16];
  86661. unsigned int test;
  86662. /* test == 0 : client writes, server reads */
  86663. /* test == 1 : server writes, client reads */
  86664. for (test = 0; test < 2; test++) {
  86665. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  86666. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  86667. wolfTLSv1_2_client_method,
  86668. wolfTLSv1_2_server_method), 0);
  86669. ExpectIntEQ(wolfSSL_set_group_messages(ssl_s), WOLFSSL_SUCCESS);
  86670. /* CH -> */
  86671. if (test == 0) {
  86672. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  86673. } else {
  86674. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  86675. sizeof(test_buffer)), -1);
  86676. }
  86677. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86678. /* <- SH + SKE + SHD */
  86679. if (test == 0) {
  86680. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  86681. sizeof(test_buffer)), -1);
  86682. } else {
  86683. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), -1);
  86684. }
  86685. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  86686. /* -> CKE + CLIENT FINISHED */
  86687. if (test == 0) {
  86688. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  86689. } else {
  86690. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  86691. sizeof(test_buffer)), -1);
  86692. }
  86693. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86694. /* abide clang static analyzer */
  86695. if (ssl_s != NULL) {
  86696. /* disable group message to separate sending of ChangeCipherspec
  86697. * from Finished */
  86698. ssl_s->options.groupMessages = 0;
  86699. }
  86700. /* allow writing of CS, but not FINISHED */
  86701. test_ctx.c_len = TEST_MEMIO_BUF_SZ - 6;
  86702. /* <- CS */
  86703. if (test == 0) {
  86704. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  86705. sizeof(test_buffer)), -1);
  86706. } else {
  86707. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), -1);
  86708. }
  86709. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_WRITE);
  86710. /* move CS message where the client can read it */
  86711. memmove(test_ctx.c_buff,
  86712. (test_ctx.c_buff + TEST_MEMIO_BUF_SZ - 6), 6);
  86713. test_ctx.c_len = 6;
  86714. /* read CS */
  86715. if (test == 0) {
  86716. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  86717. } else {
  86718. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  86719. sizeof(test_buffer)), -1);
  86720. }
  86721. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86722. ExpectIntEQ(test_ctx.c_len, 0);
  86723. if (test == 0) {
  86724. /* send SERVER FINISHED */
  86725. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  86726. sizeof(test_buffer)), -1);
  86727. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1),
  86728. WOLFSSL_ERROR_WANT_READ);
  86729. } else {
  86730. /* send SERVER FINISHED + App Data */
  86731. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), 5);
  86732. }
  86733. ExpectIntGT(test_ctx.c_len, 0);
  86734. /* Send and receive the data */
  86735. if (test == 0) {
  86736. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), 5);
  86737. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  86738. sizeof(test_buffer)), 5);
  86739. } else {
  86740. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  86741. sizeof(test_buffer)), 5);
  86742. }
  86743. ExpectBufEQ(test_buffer, "hello", 5);
  86744. wolfSSL_free(ssl_c);
  86745. wolfSSL_free(ssl_s);
  86746. wolfSSL_CTX_free(ctx_c);
  86747. wolfSSL_CTX_free(ctx_s);
  86748. ssl_c = ssl_s = NULL;
  86749. ctx_c = ctx_s = NULL;
  86750. }
  86751. #endif
  86752. return EXPECT_RESULT();
  86753. }
  86754. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(OPENSSL_EXTRA)
  86755. static const char* test_get_signature_nid_siglag;
  86756. static int test_get_signature_nid_sig;
  86757. static int test_get_signature_nid_hash;
  86758. static int test_get_signature_nid_ssl_ready(WOLFSSL* ssl)
  86759. {
  86760. EXPECT_DECLS;
  86761. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "ALL"), WOLFSSL_SUCCESS);
  86762. if (!wolfSSL_is_server(ssl)) {
  86763. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  86764. test_get_signature_nid_siglag), WOLFSSL_SUCCESS);
  86765. }
  86766. return EXPECT_RESULT();
  86767. }
  86768. static int test_get_signature_nid_on_hs_client(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  86769. {
  86770. EXPECT_DECLS;
  86771. int nid = 0;
  86772. (void)ctx;
  86773. if (XSTRSTR(wolfSSL_get_cipher(*ssl), "TLS_RSA_") == NULL) {
  86774. ExpectIntEQ(SSL_get_peer_signature_type_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  86775. ExpectIntEQ(nid, test_get_signature_nid_sig);
  86776. ExpectIntEQ(SSL_get_peer_signature_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  86777. ExpectIntEQ(nid, test_get_signature_nid_hash);
  86778. }
  86779. else /* No sigalg info on static ciphersuite */
  86780. return TEST_SUCCESS;
  86781. return EXPECT_RESULT();
  86782. }
  86783. static int test_get_signature_nid_on_hs_server(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  86784. {
  86785. EXPECT_DECLS;
  86786. int nid = 0;
  86787. (void)ctx;
  86788. ExpectIntEQ(SSL_get_signature_type_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  86789. ExpectIntEQ(nid, test_get_signature_nid_sig);
  86790. ExpectIntEQ(SSL_get_signature_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  86791. ExpectIntEQ(nid, test_get_signature_nid_hash);
  86792. return EXPECT_RESULT();
  86793. }
  86794. #endif
  86795. static int test_get_signature_nid(void)
  86796. {
  86797. EXPECT_DECLS;
  86798. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(OPENSSL_EXTRA)
  86799. test_ssl_cbf client_cbf;
  86800. test_ssl_cbf server_cbf;
  86801. size_t i;
  86802. #define TGSN_TLS12_RSA(sigalg, sig_nid, hash_nid) \
  86803. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_2, svrCertFile, svrKeyFile, \
  86804. caCertFile }
  86805. #define TGSN_TLS12_ECDSA(sigalg, sig_nid, hash_nid) \
  86806. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_2, eccCertFile, eccKeyFile, \
  86807. caEccCertFile }
  86808. #define TGSN_TLS13_RSA(sigalg, sig_nid, hash_nid) \
  86809. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, svrCertFile, svrKeyFile, \
  86810. caCertFile }
  86811. #define TGSN_TLS13_ECDSA(sigalg, sig_nid, hash_nid) \
  86812. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, eccCertFile, eccKeyFile, \
  86813. caEccCertFile }
  86814. #define TGSN_TLS13_ED25519(sigalg, sig_nid, hash_nid) \
  86815. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, edCertFile, edKeyFile, \
  86816. caEdCertFile }
  86817. #define TGSN_TLS13_ED448(sigalg, sig_nid, hash_nid) \
  86818. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, ed448CertFile, ed448KeyFile, \
  86819. caEd448CertFile }
  86820. struct {
  86821. const char* siglag;
  86822. int sig_nid;
  86823. int hash_nid;
  86824. int tls_ver;
  86825. const char* server_cert;
  86826. const char* server_key;
  86827. const char* client_ca;
  86828. } params[] = {
  86829. #ifndef NO_RSA
  86830. #ifndef NO_SHA256
  86831. TGSN_TLS12_RSA("RSA+SHA256", NID_rsaEncryption, NID_sha256),
  86832. #ifdef WC_RSA_PSS
  86833. TGSN_TLS12_RSA("RSA-PSS+SHA256", NID_rsassaPss, NID_sha256),
  86834. TGSN_TLS13_RSA("RSA-PSS+SHA256", NID_rsassaPss, NID_sha256),
  86835. #endif
  86836. #endif
  86837. #ifdef WOLFSSL_SHA512
  86838. TGSN_TLS12_RSA("RSA+SHA512", NID_rsaEncryption, NID_sha512),
  86839. #ifdef WC_RSA_PSS
  86840. TGSN_TLS12_RSA("RSA-PSS+SHA512", NID_rsassaPss, NID_sha512),
  86841. TGSN_TLS13_RSA("RSA-PSS+SHA512", NID_rsassaPss, NID_sha512),
  86842. #endif
  86843. #endif
  86844. #endif
  86845. #ifdef HAVE_ECC
  86846. #ifndef NO_SHA256
  86847. TGSN_TLS12_ECDSA("ECDSA+SHA256", NID_X9_62_id_ecPublicKey, NID_sha256),
  86848. TGSN_TLS13_ECDSA("ECDSA+SHA256", NID_X9_62_id_ecPublicKey, NID_sha256),
  86849. #endif
  86850. #endif
  86851. #ifdef HAVE_ED25519
  86852. TGSN_TLS13_ED25519("ED25519", NID_ED25519, NID_sha512),
  86853. #endif
  86854. #ifdef HAVE_ED448
  86855. TGSN_TLS13_ED448("ED448", NID_ED448, NID_sha512),
  86856. #endif
  86857. };
  86858. printf("\n");
  86859. for (i = 0; i < XELEM_CNT(params) && !EXPECT_FAIL(); i++) {
  86860. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  86861. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  86862. printf("Testing %s with %s...", tls_desc[params[i].tls_ver],
  86863. params[i].siglag);
  86864. switch (params[i].tls_ver) {
  86865. #ifndef WOLFSSL_NO_TLS12
  86866. case WOLFSSL_TLSV1_2:
  86867. client_cbf.method = wolfTLSv1_2_client_method;
  86868. server_cbf.method = wolfTLSv1_2_server_method;
  86869. break;
  86870. #endif
  86871. #ifdef WOLFSSL_TLS13
  86872. case WOLFSSL_TLSV1_3:
  86873. client_cbf.method = wolfTLSv1_3_client_method;
  86874. server_cbf.method = wolfTLSv1_3_server_method;
  86875. break;
  86876. #endif
  86877. default:
  86878. printf("skipping\n");
  86879. continue;
  86880. }
  86881. test_get_signature_nid_siglag = params[i].siglag;
  86882. test_get_signature_nid_sig = params[i].sig_nid;
  86883. test_get_signature_nid_hash = params[i].hash_nid;
  86884. client_cbf.ssl_ready = test_get_signature_nid_ssl_ready;
  86885. server_cbf.ssl_ready = test_get_signature_nid_ssl_ready;
  86886. client_cbf.on_handshake = test_get_signature_nid_on_hs_client;
  86887. server_cbf.on_handshake = test_get_signature_nid_on_hs_server;
  86888. server_cbf.certPemFile = params[i].server_cert;
  86889. server_cbf.keyPemFile = params[i].server_key;
  86890. client_cbf.caPemFile = params[i].client_ca;
  86891. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  86892. &server_cbf, NULL), TEST_SUCCESS);
  86893. if (EXPECT_SUCCESS())
  86894. printf("passed\n");
  86895. }
  86896. #endif
  86897. return EXPECT_RESULT();
  86898. }
  86899. #if !defined(NO_CERTS) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  86900. static word32 test_tls_cert_store_unchanged_HashCaTable(Signer** caTable)
  86901. {
  86902. #ifndef NO_MD5
  86903. enum wc_HashType hashType = WC_HASH_TYPE_MD5;
  86904. #elif !defined(NO_SHA)
  86905. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  86906. #elif !defined(NO_SHA256)
  86907. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  86908. #else
  86909. #error "We need a digest to hash the Signer object"
  86910. #endif
  86911. byte hashBuf[WC_MAX_DIGEST_SIZE];
  86912. wc_HashAlg hash;
  86913. size_t i;
  86914. AssertIntEQ(wc_HashInit(&hash, hashType), 0);
  86915. for (i = 0; i < CA_TABLE_SIZE; i++) {
  86916. Signer* cur;
  86917. for (cur = caTable[i]; cur != NULL; cur = cur->next)
  86918. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)cur,
  86919. sizeof(*cur)), 0);
  86920. }
  86921. AssertIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  86922. AssertIntEQ(wc_HashFree(&hash, hashType), 0);
  86923. return MakeWordFromHash(hashBuf);
  86924. }
  86925. static word32 test_tls_cert_store_unchanged_before_hashes[2];
  86926. static size_t test_tls_cert_store_unchanged_before_hashes_idx;
  86927. static word32 test_tls_cert_store_unchanged_after_hashes[2];
  86928. static size_t test_tls_cert_store_unchanged_after_hashes_idx;
  86929. static int test_tls_cert_store_unchanged_ctx_ready(WOLFSSL_CTX* ctx)
  86930. {
  86931. EXPECT_DECLS;
  86932. ExpectIntNE(test_tls_cert_store_unchanged_before_hashes
  86933. [test_tls_cert_store_unchanged_before_hashes_idx++] =
  86934. test_tls_cert_store_unchanged_HashCaTable(ctx->cm->caTable), 0);
  86935. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER |
  86936. WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  86937. return EXPECT_RESULT();
  86938. }
  86939. static int test_tls_cert_store_unchanged_ctx_cleanup(WOLFSSL_CTX* ctx)
  86940. {
  86941. EXPECT_DECLS;
  86942. ExpectIntEQ(wolfSSL_CTX_UnloadIntermediateCerts(ctx), WOLFSSL_SUCCESS);
  86943. ExpectIntNE(test_tls_cert_store_unchanged_after_hashes
  86944. [test_tls_cert_store_unchanged_after_hashes_idx++] =
  86945. test_tls_cert_store_unchanged_HashCaTable(ctx->cm->caTable), 0);
  86946. return EXPECT_RESULT();
  86947. }
  86948. static int test_tls_cert_store_unchanged_on_hs(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  86949. {
  86950. EXPECT_DECLS;
  86951. WOLFSSL_CERT_MANAGER* cm;
  86952. (void)ssl;
  86953. /* WARNING: this approach bypasses the reference counter check in
  86954. * wolfSSL_CTX_UnloadIntermediateCerts. It is not recommended as it may
  86955. * cause unexpected behaviour when other active connections try accessing
  86956. * the caTable. */
  86957. ExpectNotNull(cm = wolfSSL_CTX_GetCertManager(*ctx));
  86958. ExpectIntEQ(wolfSSL_CertManagerUnloadIntermediateCerts(cm),
  86959. WOLFSSL_SUCCESS);
  86960. ExpectIntNE(test_tls_cert_store_unchanged_after_hashes
  86961. [test_tls_cert_store_unchanged_after_hashes_idx++] =
  86962. test_tls_cert_store_unchanged_HashCaTable((*ctx)->cm->caTable), 0);
  86963. return EXPECT_RESULT();
  86964. }
  86965. static int test_tls_cert_store_unchanged_ssl_ready(WOLFSSL* ssl)
  86966. {
  86967. EXPECT_DECLS;
  86968. WOLFSSL_CTX* ctx;
  86969. ExpectNotNull(ctx = wolfSSL_get_SSL_CTX(ssl));
  86970. return EXPECT_RESULT();
  86971. }
  86972. #endif
  86973. static int test_tls_cert_store_unchanged(void)
  86974. {
  86975. EXPECT_DECLS;
  86976. #if !defined(NO_CERTS) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  86977. test_ssl_cbf client_cbf;
  86978. test_ssl_cbf server_cbf;
  86979. int i;
  86980. for (i = 0; i < 2; i++) {
  86981. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  86982. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  86983. test_tls_cert_store_unchanged_before_hashes_idx = 0;
  86984. XMEMSET(test_tls_cert_store_unchanged_before_hashes, 0,
  86985. sizeof(test_tls_cert_store_unchanged_before_hashes));
  86986. test_tls_cert_store_unchanged_after_hashes_idx = 0;
  86987. XMEMSET(test_tls_cert_store_unchanged_after_hashes, 0,
  86988. sizeof(test_tls_cert_store_unchanged_after_hashes));
  86989. client_cbf.ctx_ready = test_tls_cert_store_unchanged_ctx_ready;
  86990. server_cbf.ctx_ready = test_tls_cert_store_unchanged_ctx_ready;
  86991. client_cbf.ssl_ready = test_tls_cert_store_unchanged_ssl_ready;
  86992. server_cbf.ssl_ready = test_tls_cert_store_unchanged_ssl_ready;
  86993. switch (i) {
  86994. case 0:
  86995. client_cbf.on_ctx_cleanup =
  86996. test_tls_cert_store_unchanged_ctx_cleanup;
  86997. server_cbf.on_ctx_cleanup =
  86998. test_tls_cert_store_unchanged_ctx_cleanup;
  86999. break;
  87000. case 1:
  87001. client_cbf.on_handshake = test_tls_cert_store_unchanged_on_hs;
  87002. server_cbf.on_handshake = test_tls_cert_store_unchanged_on_hs;
  87003. break;
  87004. default:
  87005. Fail(("Should not enter here"), ("Entered here"));
  87006. }
  87007. client_cbf.certPemFile = "certs/intermediate/client-chain.pem";
  87008. server_cbf.certPemFile = "certs/intermediate/server-chain.pem";
  87009. server_cbf.caPemFile = caCertFile;
  87010. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  87011. &server_cbf, NULL), TEST_SUCCESS);
  87012. ExpectBufEQ(test_tls_cert_store_unchanged_before_hashes,
  87013. test_tls_cert_store_unchanged_after_hashes,
  87014. sizeof(test_tls_cert_store_unchanged_after_hashes));
  87015. }
  87016. #endif
  87017. return EXPECT_RESULT();
  87018. }
  87019. static int test_wolfSSL_SendUserCanceled(void)
  87020. {
  87021. EXPECT_DECLS;
  87022. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  87023. size_t i;
  87024. struct {
  87025. method_provider client_meth;
  87026. method_provider server_meth;
  87027. const char* tls_version;
  87028. } params[] = {
  87029. #if defined(WOLFSSL_TLS13)
  87030. /* With WOLFSSL_TLS13_MIDDLEBOX_COMPAT a short ID will result in an error */
  87031. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" },
  87032. #ifdef WOLFSSL_DTLS13
  87033. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" },
  87034. #endif
  87035. #endif
  87036. #ifndef WOLFSSL_NO_TLS12
  87037. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" },
  87038. #ifdef WOLFSSL_DTLS
  87039. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" },
  87040. #endif
  87041. #endif
  87042. #if !defined(NO_OLD_TLS)
  87043. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" },
  87044. #ifdef WOLFSSL_DTLS
  87045. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" },
  87046. #endif
  87047. #endif
  87048. };
  87049. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  87050. WOLFSSL_CTX *ctx_c = NULL;
  87051. WOLFSSL_CTX *ctx_s = NULL;
  87052. WOLFSSL *ssl_c = NULL;
  87053. WOLFSSL *ssl_s = NULL;
  87054. struct test_memio_ctx test_ctx;
  87055. WOLFSSL_ALERT_HISTORY h;
  87056. printf("Testing %s\n", params[i].tls_version);
  87057. XMEMSET(&h, 0, sizeof(h));
  87058. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  87059. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  87060. params[i].client_meth, params[i].server_meth), 0);
  87061. /* CH1 */
  87062. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  87063. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  87064. ExpectIntEQ(wolfSSL_SendUserCanceled(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE);
  87065. /* Alert closed connection */
  87066. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  87067. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_ZERO_RETURN);
  87068. /* Last alert will be close notify because user_canceled should be
  87069. * followed by a close_notify */
  87070. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  87071. ExpectIntEQ(h.last_rx.code, close_notify);
  87072. ExpectIntEQ(h.last_rx.level, alert_warning);
  87073. wolfSSL_free(ssl_c);
  87074. wolfSSL_free(ssl_s);
  87075. wolfSSL_CTX_free(ctx_c);
  87076. wolfSSL_CTX_free(ctx_s);
  87077. }
  87078. #endif
  87079. return EXPECT_RESULT();
  87080. }
  87081. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  87082. defined(HAVE_OCSP) && \
  87083. defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  87084. !defined(WOLFSSL_NO_TLS12)
  87085. static int test_ocsp_callback_fails_cb(void* ctx, const char* url, int urlSz,
  87086. byte* ocspReqBuf, int ocspReqSz, byte** ocspRespBuf)
  87087. {
  87088. (void)ctx;
  87089. (void)url;
  87090. (void)urlSz;
  87091. (void)ocspReqBuf;
  87092. (void)ocspReqSz;
  87093. (void)ocspRespBuf;
  87094. return -1;
  87095. }
  87096. static int test_ocsp_callback_fails(void)
  87097. {
  87098. WOLFSSL_CTX *ctx_c = NULL;
  87099. WOLFSSL_CTX *ctx_s = NULL;
  87100. WOLFSSL *ssl_c = NULL;
  87101. WOLFSSL *ssl_s = NULL;
  87102. struct test_memio_ctx test_ctx;
  87103. EXPECT_DECLS;
  87104. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  87105. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  87106. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  87107. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx_c), WOLFSSL_SUCCESS);
  87108. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx_s), WOLFSSL_SUCCESS);
  87109. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl_c, WOLFSSL_CSR_OCSP,0), WOLFSSL_SUCCESS);
  87110. /* override URL to avoid exing from SendCertificateStatus because of no AuthInfo on the certificate */
  87111. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx_s, "http://dummy.test"), WOLFSSL_SUCCESS);
  87112. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx_s, WOLFSSL_OCSP_NO_NONCE | WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  87113. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_s, caCertFile, 0), WOLFSSL_SUCCESS);
  87114. ExpectIntEQ(wolfSSL_SetOCSP_Cb(ssl_s, test_ocsp_callback_fails_cb, NULL, NULL), WOLFSSL_SUCCESS);
  87115. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), -1);
  87116. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WC_NO_ERR_TRACE(OCSP_INVALID_STATUS));
  87117. wolfSSL_free(ssl_c);
  87118. wolfSSL_free(ssl_s);
  87119. wolfSSL_CTX_free(ctx_c);
  87120. wolfSSL_CTX_free(ctx_s);
  87121. return EXPECT_RESULT();
  87122. }
  87123. #else
  87124. static int test_ocsp_callback_fails(void)
  87125. {
  87126. return TEST_SKIPPED;
  87127. }
  87128. #endif /* defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  87129. defined(HAVE_OCSP) && \
  87130. defined(HAVE_CERTIFICATE_STATUS_REQUEST) */
  87131. /*----------------------------------------------------------------------------*
  87132. | Main
  87133. *----------------------------------------------------------------------------*/
  87134. typedef int (*TEST_FUNC)(void);
  87135. typedef struct {
  87136. const char *name;
  87137. TEST_FUNC func;
  87138. byte run:1;
  87139. byte fail:1;
  87140. } TEST_CASE;
  87141. #define TEST_DECL(func) { #func, func, 0, 0 }
  87142. int testAll = 1;
  87143. TEST_CASE testCases[] = {
  87144. TEST_DECL(test_fileAccess),
  87145. /*********************************
  87146. * wolfcrypt
  87147. *********************************/
  87148. TEST_DECL(test_ForceZero),
  87149. TEST_DECL(test_wolfCrypt_Init),
  87150. TEST_DECL(test_wc_LoadStaticMemory_ex),
  87151. /* Locking with Compat Mutex */
  87152. TEST_DECL(test_wc_SetMutexCb),
  87153. TEST_DECL(test_wc_LockMutex_ex),
  87154. /* Digests */
  87155. TEST_DECL(test_wc_InitMd5),
  87156. TEST_DECL(test_wc_Md5Update),
  87157. TEST_DECL(test_wc_Md5Final),
  87158. TEST_DECL(test_wc_InitSha),
  87159. TEST_DECL(test_wc_ShaUpdate),
  87160. TEST_DECL(test_wc_ShaFinal),
  87161. TEST_DECL(test_wc_InitSha256),
  87162. TEST_DECL(test_wc_Sha256Update),
  87163. TEST_DECL(test_wc_Sha256Final),
  87164. TEST_DECL(test_wc_Sha256FinalRaw),
  87165. TEST_DECL(test_wc_Sha256GetFlags),
  87166. TEST_DECL(test_wc_Sha256Free),
  87167. TEST_DECL(test_wc_Sha256GetHash),
  87168. TEST_DECL(test_wc_Sha256Copy),
  87169. TEST_DECL(test_wc_InitSha224),
  87170. TEST_DECL(test_wc_Sha224Update),
  87171. TEST_DECL(test_wc_Sha224Final),
  87172. TEST_DECL(test_wc_Sha224SetFlags),
  87173. TEST_DECL(test_wc_Sha224GetFlags),
  87174. TEST_DECL(test_wc_Sha224Free),
  87175. TEST_DECL(test_wc_Sha224GetHash),
  87176. TEST_DECL(test_wc_Sha224Copy),
  87177. TEST_DECL(test_wc_InitSha512),
  87178. TEST_DECL(test_wc_Sha512Update),
  87179. TEST_DECL(test_wc_Sha512Final),
  87180. TEST_DECL(test_wc_Sha512GetFlags),
  87181. TEST_DECL(test_wc_Sha512FinalRaw),
  87182. TEST_DECL(test_wc_Sha512Free),
  87183. TEST_DECL(test_wc_Sha512GetHash),
  87184. TEST_DECL(test_wc_Sha512Copy),
  87185. TEST_DECL(test_wc_InitSha512_224),
  87186. TEST_DECL(test_wc_Sha512_224Update),
  87187. TEST_DECL(test_wc_Sha512_224Final),
  87188. TEST_DECL(test_wc_Sha512_224GetFlags),
  87189. TEST_DECL(test_wc_Sha512_224FinalRaw),
  87190. TEST_DECL(test_wc_Sha512_224Free),
  87191. TEST_DECL(test_wc_Sha512_224GetHash),
  87192. TEST_DECL(test_wc_Sha512_224Copy),
  87193. TEST_DECL(test_wc_InitSha512_256),
  87194. TEST_DECL(test_wc_Sha512_256Update),
  87195. TEST_DECL(test_wc_Sha512_256Final),
  87196. TEST_DECL(test_wc_Sha512_256GetFlags),
  87197. TEST_DECL(test_wc_Sha512_256FinalRaw),
  87198. TEST_DECL(test_wc_Sha512_256Free),
  87199. TEST_DECL(test_wc_Sha512_256GetHash),
  87200. TEST_DECL(test_wc_Sha512_256Copy),
  87201. TEST_DECL(test_wc_InitSha384),
  87202. TEST_DECL(test_wc_Sha384Update),
  87203. TEST_DECL(test_wc_Sha384Final),
  87204. TEST_DECL(test_wc_Sha384GetFlags),
  87205. TEST_DECL(test_wc_Sha384FinalRaw),
  87206. TEST_DECL(test_wc_Sha384Free),
  87207. TEST_DECL(test_wc_Sha384GetHash),
  87208. TEST_DECL(test_wc_Sha384Copy),
  87209. TEST_DECL(test_wc_InitBlake2b),
  87210. TEST_DECL(test_wc_InitBlake2b_WithKey),
  87211. TEST_DECL(test_wc_InitBlake2s_WithKey),
  87212. TEST_DECL(test_wc_InitRipeMd),
  87213. TEST_DECL(test_wc_RipeMdUpdate),
  87214. TEST_DECL(test_wc_RipeMdFinal),
  87215. TEST_DECL(test_wc_InitSha3),
  87216. TEST_DECL(testing_wc_Sha3_Update),
  87217. TEST_DECL(test_wc_Sha3_224_Final),
  87218. TEST_DECL(test_wc_Sha3_256_Final),
  87219. TEST_DECL(test_wc_Sha3_384_Final),
  87220. TEST_DECL(test_wc_Sha3_512_Final),
  87221. TEST_DECL(test_wc_Sha3_224_Copy),
  87222. TEST_DECL(test_wc_Sha3_256_Copy),
  87223. TEST_DECL(test_wc_Sha3_384_Copy),
  87224. TEST_DECL(test_wc_Sha3_512_Copy),
  87225. TEST_DECL(test_wc_Sha3_GetFlags),
  87226. TEST_DECL(test_wc_InitShake256),
  87227. TEST_DECL(testing_wc_Shake256_Update),
  87228. TEST_DECL(test_wc_Shake256_Final),
  87229. TEST_DECL(test_wc_Shake256_Copy),
  87230. TEST_DECL(test_wc_Shake256Hash),
  87231. /* SM3 Digest */
  87232. TEST_DECL(test_wc_InitSm3Free),
  87233. TEST_DECL(test_wc_Sm3UpdateFinal),
  87234. TEST_DECL(test_wc_Sm3GetHash),
  87235. TEST_DECL(test_wc_Sm3Copy),
  87236. TEST_DECL(test_wc_Sm3FinalRaw),
  87237. TEST_DECL(test_wc_Sm3GetSetFlags),
  87238. TEST_DECL(test_wc_Sm3Hash),
  87239. TEST_DECL(test_wc_HashInit),
  87240. TEST_DECL(test_wc_HashSetFlags),
  87241. TEST_DECL(test_wc_HashGetFlags),
  87242. /* HMAC */
  87243. TEST_DECL(test_wc_Md5HmacSetKey),
  87244. TEST_DECL(test_wc_Md5HmacUpdate),
  87245. TEST_DECL(test_wc_Md5HmacFinal),
  87246. TEST_DECL(test_wc_ShaHmacSetKey),
  87247. TEST_DECL(test_wc_ShaHmacUpdate),
  87248. TEST_DECL(test_wc_ShaHmacFinal),
  87249. TEST_DECL(test_wc_Sha224HmacSetKey),
  87250. TEST_DECL(test_wc_Sha224HmacUpdate),
  87251. TEST_DECL(test_wc_Sha224HmacFinal),
  87252. TEST_DECL(test_wc_Sha256HmacSetKey),
  87253. TEST_DECL(test_wc_Sha256HmacUpdate),
  87254. TEST_DECL(test_wc_Sha256HmacFinal),
  87255. TEST_DECL(test_wc_Sha384HmacSetKey),
  87256. TEST_DECL(test_wc_Sha384HmacUpdate),
  87257. TEST_DECL(test_wc_Sha384HmacFinal),
  87258. /* CMAC */
  87259. TEST_DECL(test_wc_InitCmac),
  87260. TEST_DECL(test_wc_CmacUpdate),
  87261. TEST_DECL(test_wc_CmacFinal),
  87262. TEST_DECL(test_wc_AesCmacGenerate),
  87263. /* Cipher */
  87264. TEST_DECL(test_wc_AesGcmStream),
  87265. TEST_DECL(test_wc_Des3_SetIV),
  87266. TEST_DECL(test_wc_Des3_SetKey),
  87267. TEST_DECL(test_wc_Des3_CbcEncryptDecrypt),
  87268. TEST_DECL(test_wc_Des3_CbcEncryptDecryptWithKey),
  87269. TEST_DECL(test_wc_Des3_EcbEncrypt),
  87270. TEST_DECL(test_wc_Chacha_SetKey),
  87271. TEST_DECL(test_wc_Chacha_Process),
  87272. TEST_DECL(test_wc_ChaCha20Poly1305_aead),
  87273. TEST_DECL(test_wc_Poly1305SetKey),
  87274. TEST_DECL(test_wc_CamelliaSetKey),
  87275. TEST_DECL(test_wc_CamelliaSetIV),
  87276. TEST_DECL(test_wc_CamelliaEncryptDecryptDirect),
  87277. TEST_DECL(test_wc_CamelliaCbcEncryptDecrypt),
  87278. TEST_DECL(test_wc_Arc4SetKey),
  87279. TEST_DECL(test_wc_Arc4Process),
  87280. TEST_DECL(test_wc_Rc2SetKey),
  87281. TEST_DECL(test_wc_Rc2SetIV),
  87282. TEST_DECL(test_wc_Rc2EcbEncryptDecrypt),
  87283. TEST_DECL(test_wc_Rc2CbcEncryptDecrypt),
  87284. /* AES cipher and GMAC. */
  87285. TEST_DECL(test_wc_AesSetKey),
  87286. TEST_DECL(test_wc_AesSetIV),
  87287. TEST_DECL(test_wc_AesCbcEncryptDecrypt),
  87288. TEST_DECL(test_wc_AesCtrEncryptDecrypt),
  87289. TEST_DECL(test_wc_AesGcmSetKey),
  87290. TEST_DECL(test_wc_AesGcmEncryptDecrypt),
  87291. TEST_DECL(test_wc_AesGcmMixedEncDecLongIV),
  87292. TEST_DECL(test_wc_GmacSetKey),
  87293. TEST_DECL(test_wc_GmacUpdate),
  87294. TEST_DECL(test_wc_AesCcmSetKey),
  87295. TEST_DECL(test_wc_AesCcmEncryptDecrypt),
  87296. #if defined(WOLFSSL_AES_EAX) && \
  87297. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  87298. TEST_DECL(test_wc_AesEaxVectors),
  87299. TEST_DECL(test_wc_AesEaxEncryptAuth),
  87300. TEST_DECL(test_wc_AesEaxDecryptAuth),
  87301. #endif /* WOLFSSL_AES_EAX */
  87302. /* SM4 cipher */
  87303. TEST_DECL(test_wc_Sm4),
  87304. TEST_DECL(test_wc_Sm4Ecb),
  87305. TEST_DECL(test_wc_Sm4Cbc),
  87306. TEST_DECL(test_wc_Sm4Ctr),
  87307. TEST_DECL(test_wc_Sm4Gcm),
  87308. TEST_DECL(test_wc_Sm4Ccm),
  87309. /* RNG tests */
  87310. #ifdef HAVE_HASHDRBG
  87311. #ifdef TEST_RESEED_INTERVAL
  87312. TEST_DECL(test_wc_RNG_GenerateBlock_Reseed),
  87313. #endif
  87314. TEST_DECL(test_wc_RNG_GenerateBlock),
  87315. #endif
  87316. TEST_DECL(test_get_rand_digit),
  87317. TEST_DECL(test_wc_InitRngNonce),
  87318. TEST_DECL(test_wc_InitRngNonce_ex),
  87319. /* MP API tests */
  87320. TEST_DECL(test_get_digit_count),
  87321. TEST_DECL(test_mp_cond_copy),
  87322. TEST_DECL(test_mp_rand),
  87323. TEST_DECL(test_get_digit),
  87324. TEST_DECL(test_wc_export_int),
  87325. /* RSA */
  87326. TEST_DECL(test_wc_InitRsaKey),
  87327. TEST_DECL(test_wc_RsaPrivateKeyDecode),
  87328. TEST_DECL(test_wc_RsaPublicKeyDecode),
  87329. TEST_DECL(test_wc_RsaPublicKeyDecodeRaw),
  87330. TEST_DECL(test_wc_RsaPrivateKeyDecodeRaw),
  87331. TEST_DECL(test_wc_MakeRsaKey),
  87332. TEST_DECL(test_wc_CheckProbablePrime),
  87333. TEST_DECL(test_wc_RsaPSS_Verify),
  87334. TEST_DECL(test_wc_RsaPSS_VerifyCheck),
  87335. TEST_DECL(test_wc_RsaPSS_VerifyCheckInline),
  87336. TEST_DECL(test_wc_RsaKeyToDer),
  87337. TEST_DECL(test_wc_RsaKeyToPublicDer),
  87338. TEST_DECL(test_wc_RsaPublicEncryptDecrypt),
  87339. TEST_DECL(test_wc_RsaPublicEncryptDecrypt_ex),
  87340. TEST_DECL(test_wc_RsaEncryptSize),
  87341. TEST_DECL(test_wc_RsaSSL_SignVerify),
  87342. TEST_DECL(test_wc_RsaFlattenPublicKey),
  87343. TEST_DECL(test_RsaDecryptBoundsCheck),
  87344. /* DSA */
  87345. TEST_DECL(test_wc_InitDsaKey),
  87346. TEST_DECL(test_wc_DsaSignVerify),
  87347. TEST_DECL(test_wc_DsaPublicPrivateKeyDecode),
  87348. TEST_DECL(test_wc_MakeDsaKey),
  87349. TEST_DECL(test_wc_DsaKeyToDer),
  87350. TEST_DECL(test_wc_DsaKeyToPublicDer),
  87351. TEST_DECL(test_wc_DsaImportParamsRaw),
  87352. TEST_DECL(test_wc_DsaImportParamsRawCheck),
  87353. TEST_DECL(test_wc_DsaExportParamsRaw),
  87354. TEST_DECL(test_wc_DsaExportKeyRaw),
  87355. /* DH */
  87356. TEST_DECL(test_wc_DhPublicKeyDecode),
  87357. /* wolfCrypt ECC tests */
  87358. TEST_DECL(test_wc_ecc_get_curve_size_from_name),
  87359. TEST_DECL(test_wc_ecc_get_curve_id_from_name),
  87360. TEST_DECL(test_wc_ecc_get_curve_id_from_params),
  87361. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && \
  87362. !defined(HAVE_SELFTEST) && \
  87363. !(defined(HAVE_FIPS) || defined(HAVE_FIPS_VERSION))
  87364. TEST_DECL(test_wc_ecc_get_curve_id_from_dp_params),
  87365. #endif
  87366. TEST_DECL(test_wc_ecc_make_key),
  87367. TEST_DECL(test_wc_ecc_init),
  87368. TEST_DECL(test_wc_ecc_check_key),
  87369. TEST_DECL(test_wc_ecc_get_generator),
  87370. TEST_DECL(test_wc_ecc_size),
  87371. TEST_DECL(test_wc_ecc_params),
  87372. TEST_DECL(test_wc_ecc_signVerify_hash),
  87373. TEST_DECL(test_wc_ecc_shared_secret),
  87374. TEST_DECL(test_wc_ecc_export_x963),
  87375. TEST_DECL(test_wc_ecc_export_x963_ex),
  87376. TEST_DECL(test_wc_ecc_import_x963),
  87377. TEST_DECL(test_wc_ecc_import_private_key),
  87378. TEST_DECL(test_wc_ecc_export_private_only),
  87379. TEST_DECL(test_wc_ecc_rs_to_sig),
  87380. TEST_DECL(test_wc_ecc_import_raw),
  87381. TEST_DECL(test_wc_ecc_import_unsigned),
  87382. TEST_DECL(test_wc_ecc_sig_size),
  87383. TEST_DECL(test_wc_ecc_ctx_new),
  87384. TEST_DECL(test_wc_ecc_ctx_reset),
  87385. TEST_DECL(test_wc_ecc_ctx_set_peer_salt),
  87386. TEST_DECL(test_wc_ecc_ctx_set_info),
  87387. TEST_DECL(test_wc_ecc_encryptDecrypt),
  87388. TEST_DECL(test_wc_ecc_del_point),
  87389. TEST_DECL(test_wc_ecc_pointFns),
  87390. TEST_DECL(test_wc_ecc_shared_secret_ssh),
  87391. TEST_DECL(test_wc_ecc_verify_hash_ex),
  87392. TEST_DECL(test_wc_ecc_mulmod),
  87393. TEST_DECL(test_wc_ecc_is_valid_idx),
  87394. TEST_DECL(test_wc_ecc_get_curve_id_from_oid),
  87395. TEST_DECL(test_wc_ecc_sig_size_calc),
  87396. TEST_DECL(test_wc_EccPrivateKeyToDer),
  87397. /* SM2 elliptic curve */
  87398. TEST_DECL(test_wc_ecc_sm2_make_key),
  87399. TEST_DECL(test_wc_ecc_sm2_shared_secret),
  87400. TEST_DECL(test_wc_ecc_sm2_create_digest),
  87401. TEST_DECL(test_wc_ecc_sm2_verify_hash_ex),
  87402. TEST_DECL(test_wc_ecc_sm2_verify_hash),
  87403. TEST_DECL(test_wc_ecc_sm2_sign_hash_ex),
  87404. TEST_DECL(test_wc_ecc_sm2_sign_hash),
  87405. /* Curve25519 */
  87406. TEST_DECL(test_wc_curve25519_init),
  87407. TEST_DECL(test_wc_curve25519_size),
  87408. TEST_DECL(test_wc_curve25519_export_key_raw),
  87409. TEST_DECL(test_wc_curve25519_export_key_raw_ex),
  87410. TEST_DECL(test_wc_curve25519_make_key),
  87411. TEST_DECL(test_wc_curve25519_shared_secret_ex),
  87412. TEST_DECL(test_wc_curve25519_make_pub),
  87413. TEST_DECL(test_wc_curve25519_export_public_ex),
  87414. TEST_DECL(test_wc_curve25519_export_private_raw_ex),
  87415. TEST_DECL(test_wc_curve25519_import_private_raw_ex),
  87416. TEST_DECL(test_wc_curve25519_import_private),
  87417. /* ED25519 */
  87418. TEST_DECL(test_wc_ed25519_make_key),
  87419. TEST_DECL(test_wc_ed25519_init),
  87420. TEST_DECL(test_wc_ed25519_sign_msg),
  87421. TEST_DECL(test_wc_ed25519_import_public),
  87422. TEST_DECL(test_wc_ed25519_import_private_key),
  87423. TEST_DECL(test_wc_ed25519_export),
  87424. TEST_DECL(test_wc_ed25519_size),
  87425. TEST_DECL(test_wc_ed25519_exportKey),
  87426. TEST_DECL(test_wc_Ed25519PublicKeyToDer),
  87427. TEST_DECL(test_wc_Ed25519KeyToDer),
  87428. TEST_DECL(test_wc_Ed25519PrivateKeyToDer),
  87429. /* Curve448 */
  87430. TEST_DECL(test_wc_curve448_make_key),
  87431. TEST_DECL(test_wc_curve448_shared_secret_ex),
  87432. TEST_DECL(test_wc_curve448_export_public_ex),
  87433. TEST_DECL(test_wc_curve448_export_private_raw_ex),
  87434. TEST_DECL(test_wc_curve448_export_key_raw),
  87435. TEST_DECL(test_wc_curve448_import_private_raw_ex),
  87436. TEST_DECL(test_wc_curve448_import_private),
  87437. TEST_DECL(test_wc_curve448_init),
  87438. TEST_DECL(test_wc_curve448_size),
  87439. /* Ed448 */
  87440. TEST_DECL(test_wc_ed448_make_key),
  87441. TEST_DECL(test_wc_ed448_init),
  87442. TEST_DECL(test_wc_ed448_sign_msg),
  87443. TEST_DECL(test_wc_ed448_import_public),
  87444. TEST_DECL(test_wc_ed448_import_private_key),
  87445. TEST_DECL(test_wc_ed448_export),
  87446. TEST_DECL(test_wc_ed448_size),
  87447. TEST_DECL(test_wc_ed448_exportKey),
  87448. TEST_DECL(test_wc_Ed448PublicKeyToDer),
  87449. TEST_DECL(test_wc_Ed448KeyToDer),
  87450. TEST_DECL(test_wc_Ed448PrivateKeyToDer),
  87451. TEST_DECL(test_wc_Curve448PrivateKeyToDer),
  87452. /* Kyber */
  87453. TEST_DECL(test_wc_kyber_make_key_kats),
  87454. TEST_DECL(test_wc_kyber_encapsulate_kats),
  87455. TEST_DECL(test_wc_kyber_decapsulate_kats),
  87456. /* Dilithium */
  87457. TEST_DECL(test_wc_dilithium),
  87458. TEST_DECL(test_wc_dilithium_make_key),
  87459. TEST_DECL(test_wc_dilithium_sign),
  87460. TEST_DECL(test_wc_dilithium_verify),
  87461. TEST_DECL(test_wc_dilithium_sign_vfy),
  87462. TEST_DECL(test_wc_dilithium_check_key),
  87463. TEST_DECL(test_wc_dilithium_public_der_decode),
  87464. TEST_DECL(test_wc_dilithium_der),
  87465. TEST_DECL(test_wc_dilithium_make_key_from_seed),
  87466. TEST_DECL(test_wc_dilithium_sig_kats),
  87467. TEST_DECL(test_wc_dilithium_verify_kats),
  87468. /* Signature API */
  87469. TEST_DECL(test_wc_SignatureGetSize_ecc),
  87470. TEST_DECL(test_wc_SignatureGetSize_rsa),
  87471. /* PEM and DER APIs. */
  87472. TEST_DECL(test_wc_PemToDer),
  87473. TEST_DECL(test_wc_AllocDer),
  87474. TEST_DECL(test_wc_CertPemToDer),
  87475. TEST_DECL(test_wc_KeyPemToDer),
  87476. TEST_DECL(test_wc_PubKeyPemToDer),
  87477. TEST_DECL(test_wc_PemPubKeyToDer),
  87478. TEST_DECL(test_wc_GetPubKeyDerFromCert),
  87479. TEST_DECL(test_wc_CheckCertSigPubKey),
  87480. /* wolfCrypt ASN tests */
  87481. TEST_DECL(test_ToTraditional),
  87482. TEST_DECL(test_wc_CreateEncryptedPKCS8Key),
  87483. TEST_DECL(test_wc_GetPkcs8TraditionalOffset),
  87484. /* Certificate */
  87485. TEST_DECL(test_wc_SetSubjectRaw),
  87486. TEST_DECL(test_wc_GetSubjectRaw),
  87487. TEST_DECL(test_wc_SetIssuerRaw),
  87488. TEST_DECL(test_wc_SetIssueBuffer),
  87489. TEST_DECL(test_wc_SetSubjectKeyId),
  87490. TEST_DECL(test_wc_SetSubject),
  87491. TEST_DECL(test_CheckCertSignature),
  87492. TEST_DECL(test_wc_ParseCert),
  87493. TEST_DECL(test_wc_ParseCert_Error),
  87494. TEST_DECL(test_MakeCertWithPathLen),
  87495. TEST_DECL(test_MakeCertWith0Ser),
  87496. TEST_DECL(test_MakeCertWithCaFalse),
  87497. TEST_DECL(test_wc_SetKeyUsage),
  87498. TEST_DECL(test_wc_SetAuthKeyIdFromPublicKey_ex),
  87499. TEST_DECL(test_wc_SetSubjectBuffer),
  87500. TEST_DECL(test_wc_SetSubjectKeyIdFromPublicKey_ex),
  87501. /* wolfcrypt PKCS#7 */
  87502. TEST_DECL(test_wc_PKCS7_New),
  87503. TEST_DECL(test_wc_PKCS7_Init),
  87504. TEST_DECL(test_wc_PKCS7_InitWithCert),
  87505. TEST_DECL(test_wc_PKCS7_EncodeData),
  87506. TEST_DECL(test_wc_PKCS7_EncodeSignedData),
  87507. TEST_DECL(test_wc_PKCS7_EncodeSignedData_ex),
  87508. TEST_DECL(test_wc_PKCS7_VerifySignedData_RSA),
  87509. TEST_DECL(test_wc_PKCS7_VerifySignedData_ECC),
  87510. TEST_DECL(test_wc_PKCS7_EncodeDecodeEnvelopedData),
  87511. TEST_DECL(test_wc_PKCS7_EncodeEncryptedData),
  87512. TEST_DECL(test_wc_PKCS7_Degenerate),
  87513. TEST_DECL(test_wc_PKCS7_BER),
  87514. TEST_DECL(test_wc_PKCS7_signed_enveloped),
  87515. TEST_DECL(test_wc_PKCS7_NoDefaultSignedAttribs),
  87516. TEST_DECL(test_wc_PKCS7_SetOriEncryptCtx),
  87517. TEST_DECL(test_wc_PKCS7_SetOriDecryptCtx),
  87518. TEST_DECL(test_wc_PKCS7_DecodeCompressedData),
  87519. /* wolfCrypt PKCS#12 */
  87520. TEST_DECL(test_wc_i2d_PKCS12),
  87521. /*
  87522. * test_wolfCrypt_Cleanup needs to come after the above wolfCrypt tests to
  87523. * avoid memory leaks.
  87524. */
  87525. TEST_DECL(test_wolfCrypt_Cleanup),
  87526. TEST_DECL(test_wolfSSL_Init),
  87527. TEST_DECL(test_dual_alg_support),
  87528. /*********************************
  87529. * OpenSSL compatibility API tests
  87530. *********************************/
  87531. /* If at some point a stub get implemented this test should fail indicating
  87532. * a need to implement a new test case
  87533. */
  87534. TEST_DECL(test_stubs_are_stubs),
  87535. /* ASN.1 compatibility API tests */
  87536. TEST_DECL(test_wolfSSL_ASN1_BIT_STRING),
  87537. TEST_DECL(test_wolfSSL_ASN1_INTEGER),
  87538. TEST_DECL(test_wolfSSL_ASN1_INTEGER_cmp),
  87539. TEST_DECL(test_wolfSSL_ASN1_INTEGER_BN),
  87540. TEST_DECL(test_wolfSSL_ASN1_INTEGER_get_set),
  87541. TEST_DECL(test_wolfSSL_d2i_ASN1_INTEGER),
  87542. TEST_DECL(test_wolfSSL_a2i_ASN1_INTEGER),
  87543. TEST_DECL(test_wolfSSL_i2c_ASN1_INTEGER),
  87544. TEST_DECL(test_wolfSSL_ASN1_OBJECT),
  87545. TEST_DECL(test_wolfSSL_ASN1_get_object),
  87546. TEST_DECL(test_wolfSSL_i2a_ASN1_OBJECT),
  87547. TEST_DECL(test_wolfSSL_i2t_ASN1_OBJECT),
  87548. TEST_DECL(test_wolfSSL_sk_ASN1_OBJECT),
  87549. TEST_DECL(test_wolfSSL_ASN1_STRING),
  87550. TEST_DECL(test_wolfSSL_ASN1_STRING_to_UTF8),
  87551. TEST_DECL(test_wolfSSL_i2s_ASN1_STRING),
  87552. TEST_DECL(test_wolfSSL_ASN1_STRING_canon),
  87553. TEST_DECL(test_wolfSSL_ASN1_STRING_print),
  87554. TEST_DECL(test_wolfSSL_ASN1_STRING_print_ex),
  87555. TEST_DECL(test_wolfSSL_ASN1_UNIVERSALSTRING_to_string),
  87556. TEST_DECL(test_wolfSSL_ASN1_GENERALIZEDTIME_free),
  87557. TEST_DECL(test_wolfSSL_ASN1_GENERALIZEDTIME_print),
  87558. TEST_DECL(test_wolfSSL_ASN1_TIME),
  87559. TEST_DECL(test_wolfSSL_ASN1_TIME_to_string),
  87560. TEST_DECL(test_wolfSSL_ASN1_TIME_diff_compare),
  87561. TEST_DECL(test_wolfSSL_ASN1_TIME_adj),
  87562. TEST_DECL(test_wolfSSL_ASN1_TIME_to_tm),
  87563. TEST_DECL(test_wolfSSL_ASN1_TIME_to_generalizedtime),
  87564. TEST_DECL(test_wolfSSL_ASN1_TIME_print),
  87565. TEST_DECL(test_wolfSSL_ASN1_UTCTIME_print),
  87566. TEST_DECL(test_wolfSSL_ASN1_TYPE),
  87567. TEST_DECL(test_wolfSSL_IMPLEMENT_ASN1_FUNCTIONS),
  87568. TEST_DECL(test_wolfSSL_i2d_ASN1_TYPE),
  87569. TEST_DECL(test_wolfSSL_i2d_ASN1_SEQUENCE),
  87570. TEST_DECL(test_ASN1_strings),
  87571. TEST_DECL(test_wolfSSL_lhash),
  87572. TEST_DECL(test_wolfSSL_certs),
  87573. TEST_DECL(test_wolfSSL_private_keys),
  87574. TEST_DECL(test_wolfSSL_PEM_def_callback),
  87575. TEST_DECL(test_wolfSSL_PEM_read_PrivateKey),
  87576. TEST_DECL(test_wolfSSL_PEM_read_RSA_PUBKEY),
  87577. TEST_DECL(test_wolfSSL_PEM_read_PUBKEY),
  87578. TEST_DECL(test_wolfSSL_PEM_PrivateKey_rsa),
  87579. TEST_DECL(test_wolfSSL_PEM_PrivateKey_ecc),
  87580. TEST_DECL(test_wolfSSL_PEM_PrivateKey_dsa),
  87581. TEST_DECL(test_wolfSSL_PEM_PrivateKey_dh),
  87582. TEST_DECL(test_wolfSSL_PEM_PrivateKey),
  87583. TEST_DECL(test_wolfSSL_PEM_file_RSAKey),
  87584. TEST_DECL(test_wolfSSL_PEM_file_RSAPrivateKey),
  87585. #ifndef NO_BIO
  87586. TEST_DECL(test_wolfSSL_BIO),
  87587. TEST_DECL(test_wolfSSL_BIO_BIO_ring_read),
  87588. TEST_DECL(test_wolfSSL_PEM_read_bio),
  87589. TEST_DECL(test_wolfSSL_PEM_bio_RSAKey),
  87590. TEST_DECL(test_wolfSSL_PEM_bio_DSAKey),
  87591. TEST_DECL(test_wolfSSL_PEM_bio_ECKey),
  87592. TEST_DECL(test_wolfSSL_PEM_bio_RSAPrivateKey),
  87593. TEST_DECL(test_wolfSSL_PEM_PUBKEY),
  87594. #endif
  87595. /* EVP API testing */
  87596. TEST_DECL(test_wolfSSL_EVP_ENCODE_CTX_new),
  87597. TEST_DECL(test_wolfSSL_EVP_ENCODE_CTX_free),
  87598. TEST_DECL(test_wolfSSL_EVP_EncodeInit),
  87599. TEST_DECL(test_wolfSSL_EVP_EncodeUpdate),
  87600. TEST_DECL(test_wolfSSL_EVP_EncodeFinal),
  87601. TEST_DECL(test_wolfSSL_EVP_DecodeInit),
  87602. TEST_DECL(test_wolfSSL_EVP_DecodeUpdate),
  87603. TEST_DECL(test_wolfSSL_EVP_DecodeFinal),
  87604. TEST_DECL(test_wolfSSL_EVP_shake128),
  87605. TEST_DECL(test_wolfSSL_EVP_shake256),
  87606. TEST_DECL(test_wolfSSL_EVP_sm3),
  87607. TEST_DECL(test_EVP_blake2),
  87608. #ifdef OPENSSL_ALL
  87609. TEST_DECL(test_wolfSSL_EVP_md4),
  87610. TEST_DECL(test_wolfSSL_EVP_ripemd160),
  87611. TEST_DECL(test_wolfSSL_EVP_get_digestbynid),
  87612. TEST_DECL(test_wolfSSL_EVP_MD_nid),
  87613. TEST_DECL(test_wolfSSL_EVP_DigestFinal_ex),
  87614. #endif
  87615. TEST_DECL(test_EVP_MD_do_all),
  87616. TEST_DECL(test_wolfSSL_EVP_MD_size),
  87617. TEST_DECL(test_wolfSSL_EVP_MD_pkey_type),
  87618. TEST_DECL(test_wolfSSL_EVP_Digest),
  87619. TEST_DECL(test_wolfSSL_EVP_Digest_all),
  87620. TEST_DECL(test_wolfSSL_EVP_MD_hmac_signing),
  87621. TEST_DECL(test_wolfSSL_EVP_MD_rsa_signing),
  87622. TEST_DECL(test_wolfSSL_EVP_MD_ecc_signing),
  87623. TEST_DECL(test_wolfssl_EVP_aes_gcm),
  87624. TEST_DECL(test_wolfssl_EVP_aes_gcm_AAD_2_parts),
  87625. TEST_DECL(test_wolfssl_EVP_aes_gcm_zeroLen),
  87626. TEST_DECL(test_wolfssl_EVP_aes_ccm),
  87627. TEST_DECL(test_wolfssl_EVP_aes_ccm_zeroLen),
  87628. TEST_DECL(test_wolfssl_EVP_chacha20),
  87629. TEST_DECL(test_wolfssl_EVP_chacha20_poly1305),
  87630. TEST_DECL(test_wolfssl_EVP_sm4_ecb),
  87631. TEST_DECL(test_wolfssl_EVP_sm4_cbc),
  87632. TEST_DECL(test_wolfssl_EVP_sm4_ctr),
  87633. TEST_DECL(test_wolfssl_EVP_sm4_gcm_zeroLen),
  87634. TEST_DECL(test_wolfssl_EVP_sm4_gcm),
  87635. TEST_DECL(test_wolfssl_EVP_sm4_ccm_zeroLen),
  87636. TEST_DECL(test_wolfssl_EVP_sm4_ccm),
  87637. #ifdef OPENSSL_ALL
  87638. TEST_DECL(test_wolfSSL_EVP_aes_256_gcm),
  87639. TEST_DECL(test_wolfSSL_EVP_aes_192_gcm),
  87640. TEST_DECL(test_wolfSSL_EVP_aes_256_ccm),
  87641. TEST_DECL(test_wolfSSL_EVP_aes_192_ccm),
  87642. TEST_DECL(test_wolfSSL_EVP_aes_128_ccm),
  87643. TEST_DECL(test_wolfSSL_EVP_rc4),
  87644. TEST_DECL(test_wolfSSL_EVP_enc_null),
  87645. TEST_DECL(test_wolfSSL_EVP_rc2_cbc),
  87646. TEST_DECL(test_wolfSSL_EVP_mdc2),
  87647. TEST_DECL(test_evp_cipher_aes_gcm),
  87648. #endif
  87649. TEST_DECL(test_wolfssl_EVP_aria_gcm),
  87650. TEST_DECL(test_wolfSSL_EVP_Cipher_extra),
  87651. #ifdef OPENSSL_EXTRA
  87652. TEST_DECL(test_wolfSSL_EVP_get_cipherbynid),
  87653. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX),
  87654. #endif
  87655. #ifdef OPENSSL_ALL
  87656. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_iv_length),
  87657. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_key_length),
  87658. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_set_iv),
  87659. TEST_DECL(test_wolfSSL_EVP_CIPHER_block_size),
  87660. TEST_DECL(test_wolfSSL_EVP_CIPHER_iv_length),
  87661. TEST_DECL(test_wolfSSL_EVP_X_STATE),
  87662. TEST_DECL(test_wolfSSL_EVP_X_STATE_LEN),
  87663. TEST_DECL(test_wolfSSL_EVP_BytesToKey),
  87664. #endif
  87665. TEST_DECL(test_wolfSSL_EVP_PKEY_print_public),
  87666. TEST_DECL(test_wolfSSL_EVP_PKEY_new_mac_key),
  87667. TEST_DECL(test_wolfSSL_EVP_PKEY_new_CMAC_key),
  87668. TEST_DECL(test_wolfSSL_EVP_PKEY_up_ref),
  87669. TEST_DECL(test_wolfSSL_EVP_PKEY_hkdf),
  87670. TEST_DECL(test_wolfSSL_EVP_PKEY_derive),
  87671. TEST_DECL(test_wolfSSL_d2i_and_i2d_PublicKey),
  87672. TEST_DECL(test_wolfSSL_d2i_and_i2d_PublicKey_ecc),
  87673. #ifndef NO_BIO
  87674. TEST_DECL(test_wolfSSL_d2i_PUBKEY),
  87675. #endif
  87676. TEST_DECL(test_wolfSSL_d2i_and_i2d_DSAparams),
  87677. TEST_DECL(test_wolfSSL_i2d_PrivateKey),
  87678. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  87679. #ifndef NO_BIO
  87680. TEST_DECL(test_wolfSSL_d2i_PrivateKeys_bio),
  87681. #endif /* !NO_BIO */
  87682. #endif
  87683. #ifdef OPENSSL_ALL
  87684. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_DSA),
  87685. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_EC_KEY),
  87686. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_DH),
  87687. TEST_DECL(test_wolfSSL_EVP_PKEY_assign),
  87688. TEST_DECL(test_wolfSSL_EVP_PKEY_assign_DH),
  87689. TEST_DECL(test_wolfSSL_EVP_PKEY_base_id),
  87690. TEST_DECL(test_wolfSSL_EVP_PKEY_id),
  87691. TEST_DECL(test_wolfSSL_EVP_PKEY_paramgen),
  87692. TEST_DECL(test_wolfSSL_EVP_PKEY_keygen),
  87693. TEST_DECL(test_wolfSSL_EVP_PKEY_keygen_init),
  87694. TEST_DECL(test_wolfSSL_EVP_PKEY_missing_parameters),
  87695. TEST_DECL(test_wolfSSL_EVP_PKEY_copy_parameters),
  87696. TEST_DECL(test_wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits),
  87697. TEST_DECL(test_wolfSSL_EVP_PKEY_CTX_new_id),
  87698. TEST_DECL(test_wolfSSL_EVP_PKEY_get0_EC_KEY),
  87699. #endif
  87700. TEST_DECL(test_EVP_PKEY_rsa),
  87701. TEST_DECL(test_EVP_PKEY_ec),
  87702. TEST_DECL(test_wolfSSL_EVP_PKEY_encrypt),
  87703. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_rsa),
  87704. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_dsa),
  87705. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_ec),
  87706. TEST_DECL(test_EVP_PKEY_cmp),
  87707. #ifdef OPENSSL_ALL
  87708. TEST_DECL(test_wolfSSL_EVP_SignInit_ex),
  87709. TEST_DECL(test_wolfSSL_EVP_PKEY_param_check),
  87710. TEST_DECL(test_wolfSSL_QT_EVP_PKEY_CTX_free),
  87711. #endif
  87712. TEST_DECL(test_wolfSSL_EVP_PBE_scrypt),
  87713. TEST_DECL(test_wolfSSL_CTX_add_extra_chain_cert),
  87714. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  87715. TEST_DECL(test_wolfSSL_ERR_peek_last_error_line),
  87716. #endif
  87717. #ifndef NO_BIO
  87718. TEST_DECL(test_wolfSSL_ERR_print_errors_cb),
  87719. TEST_DECL(test_wolfSSL_GetLoggingCb),
  87720. TEST_DECL(test_WOLFSSL_ERROR_MSG),
  87721. TEST_DECL(test_wc_ERR_remove_state),
  87722. TEST_DECL(test_wc_ERR_print_errors_fp),
  87723. #endif
  87724. TEST_DECL(test_wolfSSL_configure_args),
  87725. TEST_DECL(test_wolfSSL_sk_SSL_CIPHER),
  87726. TEST_DECL(test_wolfSSL_set1_curves_list),
  87727. TEST_DECL(test_wolfSSL_curves_mismatch),
  87728. TEST_DECL(test_wolfSSL_set1_sigalgs_list),
  87729. TEST_DECL(test_wolfSSL_OtherName),
  87730. TEST_DECL(test_wolfSSL_FPKI),
  87731. TEST_DECL(test_wolfSSL_URI),
  87732. TEST_DECL(test_wolfSSL_TBS),
  87733. TEST_DECL(test_wolfSSL_X509_STORE_CTX),
  87734. TEST_DECL(test_X509_STORE_untrusted),
  87735. TEST_DECL(test_wolfSSL_X509_STORE_CTX_trusted_stack_cleanup),
  87736. TEST_DECL(test_wolfSSL_X509_STORE_CTX_get0_current_issuer),
  87737. TEST_DECL(test_wolfSSL_X509_STORE_set_flags),
  87738. TEST_DECL(test_wolfSSL_X509_LOOKUP_load_file),
  87739. TEST_DECL(test_wolfSSL_X509_Name_canon),
  87740. TEST_DECL(test_wolfSSL_X509_LOOKUP_ctrl_file),
  87741. TEST_DECL(test_wolfSSL_X509_LOOKUP_ctrl_hash_dir),
  87742. TEST_DECL(test_wolfSSL_X509_NID),
  87743. TEST_DECL(test_wolfSSL_X509_STORE_CTX_set_time),
  87744. TEST_DECL(test_wolfSSL_get0_param),
  87745. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM_set1_host),
  87746. TEST_DECL(test_wolfSSL_set1_host),
  87747. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM_set1_ip),
  87748. TEST_DECL(test_wolfSSL_X509_STORE_CTX_get0_store),
  87749. TEST_DECL(test_wolfSSL_X509_STORE),
  87750. TEST_DECL(test_wolfSSL_X509_STORE_load_locations),
  87751. TEST_DECL(test_X509_STORE_get0_objects),
  87752. TEST_DECL(test_wolfSSL_X509_load_crl_file),
  87753. TEST_DECL(test_wolfSSL_X509_STORE_get1_certs),
  87754. TEST_DECL(test_wolfSSL_X509_STORE_set_get_crl),
  87755. TEST_DECL(test_wolfSSL_X509_NAME_ENTRY_get_object),
  87756. TEST_DECL(test_wolfSSL_X509_cmp_time),
  87757. TEST_DECL(test_wolfSSL_X509_time_adj),
  87758. /* X509 tests */
  87759. TEST_DECL(test_wolfSSL_X509_subject_name_hash),
  87760. TEST_DECL(test_wolfSSL_X509_issuer_name_hash),
  87761. TEST_DECL(test_wolfSSL_X509_check_host),
  87762. TEST_DECL(test_wolfSSL_X509_check_email),
  87763. TEST_DECL(test_wolfSSL_X509_check_private_key),
  87764. TEST_DECL(test_wolfSSL_X509),
  87765. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM),
  87766. TEST_DECL(test_wolfSSL_X509_sign),
  87767. TEST_DECL(test_wolfSSL_X509_sign2),
  87768. TEST_DECL(test_wolfSSL_X509_verify),
  87769. TEST_DECL(test_wolfSSL_X509_get0_tbs_sigalg),
  87770. TEST_DECL(test_wolfSSL_X509_ALGOR_get0),
  87771. TEST_DECL(test_wolfSSL_X509_get_X509_PUBKEY),
  87772. TEST_DECL(test_wolfSSL_X509_PUBKEY_RSA),
  87773. TEST_DECL(test_wolfSSL_X509_PUBKEY_EC),
  87774. TEST_DECL(test_wolfSSL_X509_PUBKEY_DSA),
  87775. TEST_DECL(test_wolfSSL_PEM_write_bio_X509),
  87776. TEST_DECL(test_wolfSSL_X509_NAME_get_entry),
  87777. TEST_DECL(test_wolfSSL_X509_NAME),
  87778. TEST_DECL(test_wolfSSL_X509_NAME_hash),
  87779. TEST_DECL(test_wolfSSL_X509_NAME_print_ex),
  87780. TEST_DECL(test_wolfSSL_X509_NAME_ENTRY),
  87781. TEST_DECL(test_wolfSSL_X509_set_name),
  87782. TEST_DECL(test_wolfSSL_X509_set_notAfter),
  87783. TEST_DECL(test_wolfSSL_X509_set_notBefore),
  87784. TEST_DECL(test_wolfSSL_X509_set_version),
  87785. TEST_DECL(test_wolfSSL_X509_get_serialNumber),
  87786. TEST_DECL(test_wolfSSL_X509_CRL),
  87787. TEST_DECL(test_wolfSSL_i2d_X509),
  87788. TEST_DECL(test_wolfSSL_d2i_X509_REQ),
  87789. TEST_DECL(test_wolfSSL_PEM_read_X509),
  87790. TEST_DECL(test_wolfSSL_X509_check_ca),
  87791. TEST_DECL(test_wolfSSL_X509_check_ip_asc),
  87792. TEST_DECL(test_wolfSSL_X509_bad_altname),
  87793. TEST_DECL(test_wolfSSL_X509_name_match),
  87794. TEST_DECL(test_wolfSSL_X509_name_match2),
  87795. TEST_DECL(test_wolfSSL_X509_name_match3),
  87796. TEST_DECL(test_wolfSSL_X509_max_altnames),
  87797. TEST_DECL(test_wolfSSL_X509_max_name_constraints),
  87798. TEST_DECL(test_wolfSSL_make_cert),
  87799. /* X509 ACERT tests */
  87800. TEST_DECL(test_wolfSSL_X509_ACERT_verify),
  87801. TEST_DECL(test_wolfSSL_X509_ACERT_misc_api),
  87802. #ifndef NO_BIO
  87803. TEST_DECL(test_wolfSSL_X509_INFO_multiple_info),
  87804. TEST_DECL(test_wolfSSL_X509_INFO),
  87805. TEST_DECL(test_wolfSSL_PEM_X509_INFO_read_bio),
  87806. #endif
  87807. #ifdef OPENSSL_ALL
  87808. TEST_DECL(test_wolfSSL_X509_PUBKEY_get),
  87809. #endif
  87810. TEST_DECL(test_wolfSSL_X509_CA_num),
  87811. TEST_DECL(test_x509_get_key_id),
  87812. TEST_DECL(test_wolfSSL_X509_get_version),
  87813. #ifndef NO_BIO
  87814. TEST_DECL(test_wolfSSL_X509_print),
  87815. TEST_DECL(test_wolfSSL_X509_CRL_print),
  87816. #endif
  87817. TEST_DECL(test_X509_get_signature_nid),
  87818. /* X509 extension testing. */
  87819. TEST_DECL(test_wolfSSL_X509_get_extension_flags),
  87820. TEST_DECL(test_wolfSSL_X509_get_ext),
  87821. TEST_DECL(test_wolfSSL_X509_get_ext_by_NID),
  87822. TEST_DECL(test_wolfSSL_X509_get_ext_subj_alt_name),
  87823. TEST_DECL(test_wolfSSL_X509_get_ext_count),
  87824. TEST_DECL(test_wolfSSL_X509_EXTENSION_new),
  87825. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_object),
  87826. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_data),
  87827. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_critical),
  87828. TEST_DECL(test_wolfSSL_X509V3_EXT_get),
  87829. TEST_DECL(test_wolfSSL_X509V3_EXT_nconf),
  87830. TEST_DECL(test_wolfSSL_X509V3_EXT),
  87831. TEST_DECL(test_wolfSSL_X509V3_EXT_print),
  87832. TEST_DECL(test_wolfSSL_X509_cmp),
  87833. TEST_DECL(test_GENERAL_NAME_set0_othername),
  87834. TEST_DECL(test_othername_and_SID_ext),
  87835. TEST_DECL(test_wolfSSL_dup_CA_list),
  87836. /* OpenSSL sk_X509 API test */
  87837. TEST_DECL(test_sk_X509),
  87838. /* OpenSSL sk_X509_CRL API test */
  87839. TEST_DECL(test_sk_X509_CRL),
  87840. /* OpenSSL X509 REQ API test */
  87841. TEST_DECL(test_X509_REQ),
  87842. /* OpenSSL compatibility outside SSL context w/ CRL lookup directory */
  87843. TEST_DECL(test_X509_STORE_No_SSL_CTX),
  87844. TEST_DECL(test_X509_LOOKUP_add_dir),
  87845. /* RAND compatibility API */
  87846. TEST_DECL(test_wolfSSL_RAND_set_rand_method),
  87847. TEST_DECL(test_wolfSSL_RAND_bytes),
  87848. TEST_DECL(test_wolfSSL_RAND),
  87849. /* BN compatibility API */
  87850. TEST_DECL(test_wolfSSL_BN_CTX),
  87851. TEST_DECL(test_wolfSSL_BN),
  87852. TEST_DECL(test_wolfSSL_BN_init),
  87853. TEST_DECL(test_wolfSSL_BN_enc_dec),
  87854. TEST_DECL(test_wolfSSL_BN_word),
  87855. TEST_DECL(test_wolfSSL_BN_bits),
  87856. TEST_DECL(test_wolfSSL_BN_shift),
  87857. TEST_DECL(test_wolfSSL_BN_math),
  87858. TEST_DECL(test_wolfSSL_BN_math_mod),
  87859. TEST_DECL(test_wolfSSL_BN_math_other),
  87860. TEST_DECL(test_wolfSSL_BN_rand),
  87861. TEST_DECL(test_wolfSSL_BN_prime),
  87862. /* OpenSSL PKCS5 API test */
  87863. TEST_DECL(test_wolfSSL_PKCS5),
  87864. /* OpenSSL PKCS8 API test */
  87865. TEST_DECL(test_wolfSSL_PKCS8_Compat),
  87866. TEST_DECL(test_wolfSSL_PKCS8_d2i),
  87867. /* OpenSSL PKCS7 API test */
  87868. TEST_DECL(test_wolfssl_PKCS7),
  87869. TEST_DECL(test_wolfSSL_PKCS7_certs),
  87870. TEST_DECL(test_wolfSSL_PKCS7_sign),
  87871. TEST_DECL(test_wolfSSL_PKCS7_SIGNED_new),
  87872. #ifndef NO_BIO
  87873. TEST_DECL(test_wolfSSL_PEM_write_bio_PKCS7),
  87874. #ifdef HAVE_SMIME
  87875. TEST_DECL(test_wolfSSL_SMIME_read_PKCS7),
  87876. TEST_DECL(test_wolfSSL_SMIME_write_PKCS7),
  87877. #endif /* HAVE_SMIME */
  87878. #endif /* !NO_BIO */
  87879. /* OpenSSL PKCS12 API test */
  87880. TEST_DECL(test_wolfSSL_PKCS12),
  87881. /* Can't memory test as callbacks use Assert. */
  87882. TEST_DECL(test_error_queue_per_thread),
  87883. TEST_DECL(test_wolfSSL_ERR_put_error),
  87884. TEST_DECL(test_wolfSSL_ERR_get_error_order),
  87885. #ifndef NO_BIO
  87886. TEST_DECL(test_wolfSSL_ERR_print_errors),
  87887. #endif
  87888. TEST_DECL(test_OBJ_NAME_do_all),
  87889. TEST_DECL(test_wolfSSL_OBJ),
  87890. TEST_DECL(test_wolfSSL_OBJ_cmp),
  87891. TEST_DECL(test_wolfSSL_OBJ_txt2nid),
  87892. TEST_DECL(test_wolfSSL_OBJ_txt2obj),
  87893. #ifdef OPENSSL_ALL
  87894. TEST_DECL(test_wolfSSL_OBJ_ln),
  87895. TEST_DECL(test_wolfSSL_OBJ_sn),
  87896. #endif
  87897. #ifndef NO_BIO
  87898. TEST_DECL(test_wolfSSL_BIO_gets),
  87899. TEST_DECL(test_wolfSSL_BIO_puts),
  87900. TEST_DECL(test_wolfSSL_BIO_dump),
  87901. /* Can't memory test as server hangs. */
  87902. TEST_DECL(test_wolfSSL_BIO_should_retry),
  87903. TEST_DECL(test_wolfSSL_BIO_write),
  87904. TEST_DECL(test_wolfSSL_BIO_printf),
  87905. TEST_DECL(test_wolfSSL_BIO_f_md),
  87906. TEST_DECL(test_wolfSSL_BIO_up_ref),
  87907. TEST_DECL(test_wolfSSL_BIO_reset),
  87908. TEST_DECL(test_wolfSSL_BIO_get_len),
  87909. #endif
  87910. TEST_DECL(test_wolfSSL_check_domain),
  87911. TEST_DECL(test_wolfSSL_cert_cb),
  87912. TEST_DECL(test_wolfSSL_cert_cb_dyn_ciphers),
  87913. TEST_DECL(test_wolfSSL_ciphersuite_auth),
  87914. TEST_DECL(test_wolfSSL_sigalg_info),
  87915. /* Can't memory test as tcp_connect aborts. */
  87916. TEST_DECL(test_wolfSSL_SESSION),
  87917. TEST_DECL(test_wolfSSL_SESSION_expire_downgrade),
  87918. TEST_DECL(test_wolfSSL_CTX_sess_set_remove_cb),
  87919. TEST_DECL(test_wolfSSL_ticket_keys),
  87920. TEST_DECL(test_wolfSSL_sk_GENERAL_NAME),
  87921. TEST_DECL(test_wolfSSL_GENERAL_NAME_print),
  87922. TEST_DECL(test_wolfSSL_sk_DIST_POINT),
  87923. TEST_DECL(test_wolfSSL_verify_mode),
  87924. TEST_DECL(test_wolfSSL_verify_depth),
  87925. TEST_DECL(test_wolfSSL_verify_result),
  87926. TEST_DECL(test_wolfSSL_msg_callback),
  87927. TEST_DECL(test_wolfSSL_OCSP_id_get0_info),
  87928. TEST_DECL(test_wolfSSL_i2d_OCSP_CERTID),
  87929. TEST_DECL(test_wolfSSL_d2i_OCSP_CERTID),
  87930. TEST_DECL(test_wolfSSL_OCSP_id_cmp),
  87931. TEST_DECL(test_wolfSSL_OCSP_SINGLERESP_get0_id),
  87932. TEST_DECL(test_wolfSSL_OCSP_single_get0_status),
  87933. TEST_DECL(test_wolfSSL_OCSP_resp_count),
  87934. TEST_DECL(test_wolfSSL_OCSP_resp_get0),
  87935. TEST_DECL(test_wolfSSL_OCSP_parse_url),
  87936. TEST_DECL(test_wolfSSL_OCSP_REQ_CTX),
  87937. TEST_DECL(test_wolfSSL_PEM_read),
  87938. TEST_DECL(test_wolfSSL_OpenSSL_version),
  87939. TEST_DECL(test_wolfSSL_OpenSSL_add_all_algorithms),
  87940. TEST_DECL(test_wolfSSL_OPENSSL_hexstr2buf),
  87941. TEST_DECL(test_CONF_modules_xxx),
  87942. #ifdef OPENSSL_ALL
  87943. TEST_DECL(test_wolfSSL_TXT_DB),
  87944. TEST_DECL(test_wolfSSL_NCONF),
  87945. #endif
  87946. TEST_DECL(test_wolfSSL_CRYPTO_memcmp),
  87947. TEST_DECL(test_wolfSSL_CRYPTO_get_ex_new_index),
  87948. TEST_DECL(test_wolfSSL_SESSION_get_ex_new_index),
  87949. TEST_DECL(test_CRYPTO_set_dynlock_xxx),
  87950. TEST_DECL(test_CRYPTO_THREADID_xxx),
  87951. TEST_DECL(test_ENGINE_cleanup),
  87952. /* test the no op functions for compatibility */
  87953. TEST_DECL(test_no_op_functions),
  87954. /* OpenSSL error API tests */
  87955. TEST_DECL(test_ERR_load_crypto_strings),
  87956. #ifdef OPENSSL_ALL
  87957. TEST_DECL(test_wolfSSL_sk_CIPHER_description),
  87958. TEST_DECL(test_wolfSSL_get_ciphers_compat),
  87959. TEST_DECL(test_wolfSSL_CTX_ctrl),
  87960. #endif /* OPENSSL_ALL */
  87961. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  87962. TEST_DECL(test_wolfSSL_CTX_use_certificate_ASN1),
  87963. #endif /* (OPENSSL_ALL || WOLFSSL_ASIO) && !NO_RSA */
  87964. /*********************************
  87965. * Crypto API tests
  87966. *********************************/
  87967. TEST_DECL(test_wolfSSL_MD4),
  87968. TEST_DECL(test_wolfSSL_MD5),
  87969. TEST_DECL(test_wolfSSL_MD5_Transform),
  87970. TEST_DECL(test_wolfSSL_SHA),
  87971. TEST_DECL(test_wolfSSL_SHA_Transform),
  87972. TEST_DECL(test_wolfSSL_SHA224),
  87973. TEST_DECL(test_wolfSSL_SHA256),
  87974. TEST_DECL(test_wolfSSL_SHA256_Transform),
  87975. TEST_DECL(test_wolfSSL_SHA512_Transform),
  87976. TEST_DECL(test_wolfSSL_SHA512_224_Transform),
  87977. TEST_DECL(test_wolfSSL_SHA512_256_Transform),
  87978. TEST_DECL(test_wolfSSL_HMAC_CTX),
  87979. TEST_DECL(test_wolfSSL_HMAC),
  87980. TEST_DECL(test_wolfSSL_CMAC),
  87981. TEST_DECL(test_wolfSSL_DES),
  87982. TEST_DECL(test_wolfSSL_DES_ncbc),
  87983. TEST_DECL(test_wolfSSL_DES_ecb_encrypt),
  87984. TEST_DECL(test_wolfSSL_DES_ede3_cbc_encrypt),
  87985. TEST_DECL(test_wolfSSL_AES_encrypt),
  87986. TEST_DECL(test_wolfSSL_AES_ecb_encrypt),
  87987. TEST_DECL(test_wolfSSL_AES_cbc_encrypt),
  87988. TEST_DECL(test_wolfSSL_AES_cfb128_encrypt),
  87989. TEST_DECL(test_wolfSSL_CRYPTO_cts128),
  87990. TEST_DECL(test_wolfSSL_RC4),
  87991. TEST_DECL(test_wolfSSL_RSA),
  87992. TEST_DECL(test_wolfSSL_RSA_DER),
  87993. TEST_DECL(test_wolfSSL_RSA_print),
  87994. TEST_DECL(test_wolfSSL_RSA_padding_add_PKCS1_PSS),
  87995. TEST_DECL(test_wolfSSL_RSA_sign_sha3),
  87996. TEST_DECL(test_wolfSSL_RSA_get0_key),
  87997. TEST_DECL(test_wolfSSL_RSA_meth),
  87998. TEST_DECL(test_wolfSSL_RSA_verify),
  87999. TEST_DECL(test_wolfSSL_RSA_sign),
  88000. TEST_DECL(test_wolfSSL_RSA_sign_ex),
  88001. TEST_DECL(test_wolfSSL_RSA_public_decrypt),
  88002. TEST_DECL(test_wolfSSL_RSA_private_encrypt),
  88003. TEST_DECL(test_wolfSSL_RSA_public_encrypt),
  88004. TEST_DECL(test_wolfSSL_RSA_private_decrypt),
  88005. TEST_DECL(test_wolfSSL_RSA_GenAdd),
  88006. TEST_DECL(test_wolfSSL_RSA_blinding_on),
  88007. TEST_DECL(test_wolfSSL_RSA_ex_data),
  88008. TEST_DECL(test_wolfSSL_RSA_LoadDer),
  88009. TEST_DECL(test_wolfSSL_RSA_To_Der),
  88010. TEST_DECL(test_wolfSSL_PEM_read_RSAPublicKey),
  88011. TEST_DECL(test_wolfSSL_PEM_write_RSA_PUBKEY),
  88012. TEST_DECL(test_wolfSSL_PEM_write_RSAPrivateKey),
  88013. TEST_DECL(test_wolfSSL_PEM_write_mem_RSAPrivateKey),
  88014. TEST_DECL(test_wolfSSL_DH),
  88015. TEST_DECL(test_wolfSSL_DH_dup),
  88016. TEST_DECL(test_wolfSSL_DH_check),
  88017. TEST_DECL(test_wolfSSL_DH_prime),
  88018. TEST_DECL(test_wolfSSL_DH_1536_prime),
  88019. TEST_DECL(test_wolfSSL_DH_get_2048_256),
  88020. TEST_DECL(test_wolfSSL_PEM_write_DHparams),
  88021. TEST_DECL(test_wolfSSL_PEM_read_DHparams),
  88022. TEST_DECL(test_wolfSSL_d2i_DHparams),
  88023. TEST_DECL(test_wolfSSL_DH_LoadDer),
  88024. TEST_DECL(test_wolfSSL_i2d_DHparams),
  88025. #if defined(HAVE_ECC) && !defined(OPENSSL_NO_PK)
  88026. TEST_DECL(test_wolfSSL_EC_GROUP),
  88027. TEST_DECL(test_wolfSSL_PEM_read_bio_ECPKParameters),
  88028. TEST_DECL(test_wolfSSL_EC_POINT),
  88029. TEST_DECL(test_wolfSSL_SPAKE),
  88030. TEST_DECL(test_wolfSSL_EC_KEY_generate),
  88031. TEST_DECL(test_EC_i2d),
  88032. TEST_DECL(test_wolfSSL_EC_curve),
  88033. TEST_DECL(test_wolfSSL_EC_KEY_dup),
  88034. TEST_DECL(test_wolfSSL_EC_KEY_set_group),
  88035. TEST_DECL(test_wolfSSL_EC_KEY_set_conv_form),
  88036. TEST_DECL(test_wolfSSL_EC_KEY_private_key),
  88037. TEST_DECL(test_wolfSSL_EC_KEY_public_key),
  88038. TEST_DECL(test_wolfSSL_EC_KEY_print_fp),
  88039. TEST_DECL(test_wolfSSL_EC_get_builtin_curves),
  88040. TEST_DECL(test_wolfSSL_ECDSA_SIG),
  88041. TEST_DECL(test_ECDSA_size_sign),
  88042. TEST_DECL(test_ECDH_compute_key),
  88043. #endif
  88044. #ifdef OPENSSL_EXTRA
  88045. TEST_DECL(test_EC25519),
  88046. TEST_DECL(test_ED25519),
  88047. TEST_DECL(test_EC448),
  88048. TEST_DECL(test_ED448),
  88049. #endif
  88050. TEST_DECL(test_DSA_do_sign_verify),
  88051. #ifdef OPENSSL_ALL
  88052. TEST_DECL(test_wolfSSL_DSA_generate_parameters),
  88053. TEST_DECL(test_wolfSSL_DSA_SIG),
  88054. #endif
  88055. TEST_DECL(test_openssl_generate_key_and_cert),
  88056. TEST_DECL(test_wolfSSL_FIPS_mode),
  88057. TEST_DECL(test_openssl_FIPS_drbg),
  88058. /*********************************
  88059. * CertManager API tests
  88060. *********************************/
  88061. TEST_DECL(test_wolfSSL_CertManagerAPI),
  88062. TEST_DECL(test_wolfSSL_CertManagerLoadCABuffer),
  88063. TEST_DECL(test_wolfSSL_CertManagerLoadCABuffer_ex),
  88064. TEST_DECL(test_wolfSSL_CertManagerGetCerts),
  88065. TEST_DECL(test_wolfSSL_CertManagerSetVerify),
  88066. TEST_DECL(test_wolfSSL_CertManagerNameConstraint),
  88067. TEST_DECL(test_wolfSSL_CertManagerNameConstraint2),
  88068. TEST_DECL(test_wolfSSL_CertManagerNameConstraint3),
  88069. TEST_DECL(test_wolfSSL_CertManagerNameConstraint4),
  88070. TEST_DECL(test_wolfSSL_CertManagerNameConstraint5),
  88071. TEST_DECL(test_wolfSSL_CertManagerCRL),
  88072. TEST_DECL(test_wolfSSL_CertManagerCheckOCSPResponse),
  88073. TEST_DECL(test_wolfSSL_CheckOCSPResponse),
  88074. #ifdef HAVE_CERT_CHAIN_VALIDATION
  88075. TEST_DECL(test_various_pathlen_chains),
  88076. #endif
  88077. /*********************************
  88078. * SSL/TLS API tests
  88079. *********************************/
  88080. TEST_DECL(test_wolfSSL_Method_Allocators),
  88081. #ifndef NO_WOLFSSL_SERVER
  88082. TEST_DECL(test_wolfSSL_CTX_new),
  88083. #endif
  88084. TEST_DECL(test_server_wolfSSL_new),
  88085. TEST_DECL(test_client_wolfSSL_new),
  88086. #if (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  88087. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  88088. TEST_DECL(test_for_double_Free),
  88089. #endif
  88090. TEST_DECL(test_wolfSSL_set_options),
  88091. #ifdef WOLFSSL_TLS13
  88092. /* TLS v1.3 API tests */
  88093. TEST_DECL(test_tls13_apis),
  88094. TEST_DECL(test_tls13_cipher_suites),
  88095. #endif
  88096. TEST_DECL(test_wolfSSL_tmp_dh),
  88097. TEST_DECL(test_wolfSSL_ctrl),
  88098. #if defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  88099. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  88100. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  88101. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))
  88102. TEST_DECL(test_wolfSSL_set_SSL_CTX),
  88103. #endif
  88104. TEST_DECL(test_wolfSSL_CTX_get_min_proto_version),
  88105. TEST_DECL(test_wolfSSL_security_level),
  88106. TEST_DECL(test_wolfSSL_SSL_in_init),
  88107. TEST_DECL(test_wolfSSL_CTX_set_timeout),
  88108. TEST_DECL(test_wolfSSL_set_psk_use_session_callback),
  88109. TEST_DECL(test_CONF_CTX_FILE),
  88110. TEST_DECL(test_CONF_CTX_CMDLINE),
  88111. #if !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \
  88112. !defined(WOLFSSL_NO_CLIENT_AUTH)) && !defined(NO_FILESYSTEM)
  88113. /* Use the Cert Manager(CM) API to generate the error ASN_SIG_CONFIRM_E */
  88114. /* Bad certificate signature tests */
  88115. TEST_DECL(test_EccSigFailure_cm),
  88116. TEST_DECL(test_RsaSigFailure_cm),
  88117. #endif /* NO_CERTS */
  88118. /* PKCS8 testing */
  88119. TEST_DECL(test_wolfSSL_no_password_cb),
  88120. TEST_DECL(test_wolfSSL_PKCS8),
  88121. TEST_DECL(test_wolfSSL_PKCS8_ED25519),
  88122. TEST_DECL(test_wolfSSL_PKCS8_ED448),
  88123. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  88124. TEST_DECL(test_wolfSSL_get_finished),
  88125. /* Uses Assert in handshake callback. */
  88126. TEST_DECL(test_wolfSSL_CTX_add_session),
  88127. /* Large number of memory allocations. */
  88128. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls13),
  88129. /* Large number of memory allocations. */
  88130. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls13),
  88131. /* Large number of memory allocations. */
  88132. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls12),
  88133. /* Large number of memory allocations. */
  88134. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls12),
  88135. /* Large number of memory allocations. */
  88136. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls11),
  88137. /* Large number of memory allocations. */
  88138. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls1),
  88139. #endif
  88140. TEST_DECL(test_SSL_CIPHER_get_xxx),
  88141. TEST_DECL(test_wolfSSL_ERR_strings),
  88142. TEST_DECL(test_wolfSSL_CTX_set_cipher_list_bytes),
  88143. TEST_DECL(test_wolfSSL_CTX_use_certificate),
  88144. TEST_DECL(test_wolfSSL_CTX_use_certificate_file),
  88145. TEST_DECL(test_wolfSSL_CTX_use_certificate_buffer),
  88146. TEST_DECL(test_wolfSSL_use_certificate_buffer),
  88147. TEST_DECL(test_wolfSSL_CTX_use_PrivateKey_file),
  88148. TEST_DECL(test_wolfSSL_CTX_use_RSAPrivateKey_file),
  88149. TEST_DECL(test_wolfSSL_use_RSAPrivateKey_file),
  88150. TEST_DECL(test_wolfSSL_CTX_use_PrivateKey),
  88151. TEST_DECL(test_wolfSSL_CTX_load_verify_locations),
  88152. /* Large number of memory allocations. */
  88153. TEST_DECL(test_wolfSSL_CTX_load_system_CA_certs),
  88154. #ifdef HAVE_CERT_CHAIN_VALIDATION
  88155. TEST_DECL(test_wolfSSL_CertRsaPss),
  88156. #endif
  88157. TEST_DECL(test_wolfSSL_CTX_load_verify_locations_ex),
  88158. TEST_DECL(test_wolfSSL_CTX_load_verify_buffer_ex),
  88159. TEST_DECL(test_wolfSSL_CTX_load_verify_chain_buffer_format),
  88160. TEST_DECL(test_wolfSSL_CTX_add1_chain_cert),
  88161. TEST_DECL(test_wolfSSL_CTX_use_certificate_chain_buffer_format),
  88162. TEST_DECL(test_wolfSSL_CTX_use_certificate_chain_file_format),
  88163. TEST_DECL(test_wolfSSL_use_certificate_chain_file),
  88164. TEST_DECL(test_wolfSSL_CTX_trust_peer_cert),
  88165. TEST_DECL(test_wolfSSL_CTX_LoadCRL),
  88166. TEST_DECL(test_multiple_crls_same_issuer),
  88167. TEST_DECL(test_wolfSSL_CTX_SetTmpDH_file),
  88168. TEST_DECL(test_wolfSSL_CTX_SetTmpDH_buffer),
  88169. TEST_DECL(test_wolfSSL_CTX_SetMinMaxDhKey_Sz),
  88170. TEST_DECL(test_wolfSSL_CTX_der_load_verify_locations),
  88171. TEST_DECL(test_wolfSSL_CTX_enable_disable),
  88172. TEST_DECL(test_wolfSSL_CTX_ticket_API),
  88173. TEST_DECL(test_wolfSSL_SetTmpDH_file),
  88174. TEST_DECL(test_wolfSSL_SetTmpDH_buffer),
  88175. TEST_DECL(test_wolfSSL_SetMinMaxDhKey_Sz),
  88176. TEST_DECL(test_SetTmpEC_DHE_Sz),
  88177. TEST_DECL(test_wolfSSL_CTX_get0_privatekey),
  88178. #ifdef WOLFSSL_DTLS
  88179. TEST_DECL(test_wolfSSL_DtlsUpdateWindow),
  88180. TEST_DECL(test_wolfSSL_DTLS_fragment_buckets),
  88181. #endif
  88182. TEST_DECL(test_wolfSSL_dtls_set_mtu),
  88183. /* Uses Assert in handshake callback. */
  88184. TEST_DECL(test_wolfSSL_dtls_plaintext),
  88185. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  88186. defined(HAVE_IO_TESTS_DEPENDENCIES)
  88187. TEST_DECL(test_wolfSSL_read_write),
  88188. /* Can't memory test as server hangs if client fails before second connect.
  88189. */
  88190. TEST_DECL(test_wolfSSL_reuse_WOLFSSLobj),
  88191. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_1),
  88192. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_2),
  88193. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_3),
  88194. TEST_DECL(test_wolfSSL_CTX_set_cipher_list),
  88195. /* Can't memory test as server hangs. */
  88196. TEST_DECL(test_wolfSSL_dtls_export),
  88197. /* Uses Assert in handshake callback. */
  88198. TEST_DECL(test_wolfSSL_tls_export),
  88199. #endif
  88200. TEST_DECL(test_wolfSSL_dtls_export_peers),
  88201. TEST_DECL(test_wolfSSL_SetMinVersion),
  88202. TEST_DECL(test_wolfSSL_CTX_SetMinVersion),
  88203. /* wolfSSL handshake APIs. */
  88204. TEST_DECL(test_wolfSSL_CTX_get0_set1_param),
  88205. TEST_DECL(test_wolfSSL_a2i_IPADDRESS),
  88206. TEST_DECL(test_wolfSSL_BUF),
  88207. TEST_DECL(test_wolfSSL_set_tlsext_status_type),
  88208. /* Can't memory test as server hangs. */
  88209. TEST_DECL(test_wolfSSL_CTX_set_client_CA_list),
  88210. TEST_DECL(test_wolfSSL_CTX_add_client_CA),
  88211. TEST_DECL(test_wolfSSL_CTX_set_srp_username),
  88212. TEST_DECL(test_wolfSSL_CTX_set_srp_password),
  88213. TEST_DECL(test_wolfSSL_CTX_set_keylog_callback),
  88214. TEST_DECL(test_wolfSSL_CTX_get_keylog_callback),
  88215. TEST_DECL(test_wolfSSL_Tls12_Key_Logging_test),
  88216. /* Can't memory test as server hangs. */
  88217. TEST_DECL(test_wolfSSL_Tls13_Key_Logging_test),
  88218. TEST_DECL(test_wolfSSL_Tls13_postauth),
  88219. TEST_DECL(test_wolfSSL_set_ecdh_auto),
  88220. TEST_DECL(test_wolfSSL_CTX_set_ecdh_auto),
  88221. TEST_DECL(test_wolfSSL_set_minmax_proto_version),
  88222. TEST_DECL(test_wolfSSL_CTX_set_max_proto_version),
  88223. TEST_DECL(test_wolfSSL_THREADID_hash),
  88224. /* TLS extensions tests */
  88225. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  88226. #ifdef HAVE_SNI
  88227. TEST_DECL(test_wolfSSL_UseSNI_params),
  88228. /* Uses Assert in handshake callback. */
  88229. TEST_DECL(test_wolfSSL_UseSNI_connection),
  88230. TEST_DECL(test_wolfSSL_SNI_GetFromBuffer),
  88231. #endif /* HAVE_SNI */
  88232. #endif
  88233. TEST_DECL(test_wolfSSL_UseTrustedCA),
  88234. TEST_DECL(test_wolfSSL_UseMaxFragment),
  88235. TEST_DECL(test_wolfSSL_UseTruncatedHMAC),
  88236. TEST_DECL(test_wolfSSL_UseSupportedCurve),
  88237. #if defined(HAVE_ALPN) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  88238. /* Uses Assert in handshake callback. */
  88239. TEST_DECL(test_wolfSSL_UseALPN_connection),
  88240. TEST_DECL(test_wolfSSL_UseALPN_params),
  88241. #endif
  88242. #ifdef HAVE_ALPN_PROTOS_SUPPORT
  88243. /* Uses Assert in handshake callback. */
  88244. TEST_DECL(test_wolfSSL_set_alpn_protos),
  88245. #endif
  88246. TEST_DECL(test_wolfSSL_DisableExtendedMasterSecret),
  88247. TEST_DECL(test_wolfSSL_wolfSSL_UseSecureRenegotiation),
  88248. TEST_DECL(test_wolfSSL_SCR_Reconnect),
  88249. TEST_DECL(test_tls_ext_duplicate),
  88250. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  88251. defined(HAVE_IO_TESTS_DEPENDENCIES)
  88252. TEST_DECL(test_wolfSSL_Tls13_ECH_params),
  88253. /* Uses Assert in handshake callback. */
  88254. TEST_DECL(test_wolfSSL_Tls13_ECH),
  88255. #endif
  88256. TEST_DECL(test_wolfSSL_X509_TLS_version_test_1),
  88257. TEST_DECL(test_wolfSSL_X509_TLS_version_test_2),
  88258. /* OCSP Stapling */
  88259. TEST_DECL(test_wolfSSL_UseOCSPStapling),
  88260. TEST_DECL(test_wolfSSL_UseOCSPStaplingV2),
  88261. TEST_DECL(test_self_signed_stapling),
  88262. TEST_DECL(test_ocsp_callback_fails),
  88263. /* Multicast */
  88264. TEST_DECL(test_wolfSSL_mcast),
  88265. TEST_DECL(test_wolfSSL_read_detect_TCP_disconnect),
  88266. TEST_DECL(test_wolfSSL_msgCb),
  88267. TEST_DECL(test_wolfSSL_either_side),
  88268. TEST_DECL(test_wolfSSL_DTLS_either_side),
  88269. /* Uses Assert in handshake callback. */
  88270. TEST_DECL(test_wolfSSL_dtls_fragments),
  88271. /* Uses Assert in handshake callback. */
  88272. TEST_DECL(test_wolfSSL_dtls_AEAD_limit),
  88273. /* Uses Assert in handshake callback. */
  88274. TEST_DECL(test_wolfSSL_ignore_alert_before_cookie),
  88275. /* Uses Assert in handshake callback. */
  88276. TEST_DECL(test_wolfSSL_dtls_bad_record),
  88277. /* Uses Assert in handshake callback. */
  88278. TEST_DECL(test_wolfSSL_dtls_stateless),
  88279. TEST_DECL(test_generate_cookie),
  88280. #ifndef NO_BIO
  88281. /* Can't memory test as server hangs. */
  88282. TEST_DECL(test_wolfSSL_BIO_connect),
  88283. /* Can't memory test as server Asserts in thread. */
  88284. TEST_DECL(test_wolfSSL_BIO_accept),
  88285. TEST_DECL(test_wolfSSL_BIO_tls),
  88286. TEST_DECL(test_wolfSSL_BIO_datagram),
  88287. #endif
  88288. #if defined(HAVE_PK_CALLBACKS) && !defined(WOLFSSL_NO_TLS12)
  88289. TEST_DECL(test_DhCallbacks),
  88290. #endif
  88291. #if defined(HAVE_KEYING_MATERIAL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  88292. TEST_DECL(test_export_keying_material),
  88293. #endif
  88294. /* Can't memory test as client/server Asserts in thread. */
  88295. TEST_DECL(test_ticket_and_psk_mixing),
  88296. /* Can't memory test as client/server Asserts in thread. */
  88297. TEST_DECL(test_prioritize_psk),
  88298. /* Can't memory test as client/server hangs. */
  88299. TEST_DECL(test_wc_CryptoCb),
  88300. /* Can't memory test as client/server hangs. */
  88301. TEST_DECL(test_wolfSSL_CTX_StaticMemory),
  88302. #if !defined(NO_FILESYSTEM) && \
  88303. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  88304. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  88305. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  88306. TEST_DECL(test_wolfSSL_dtls_stateless_resume),
  88307. #endif /* WOLFSSL_DTLS_NO_HVR_ON_RESUME */
  88308. #ifdef HAVE_MAX_FRAGMENT
  88309. TEST_DECL(test_wolfSSL_dtls_stateless_maxfrag),
  88310. #endif /* HAVE_MAX_FRAGMENT */
  88311. #ifndef NO_RSA
  88312. TEST_DECL(test_wolfSSL_dtls_stateless2),
  88313. #if !defined(NO_OLD_TLS)
  88314. TEST_DECL(test_wolfSSL_dtls_stateless_downgrade),
  88315. #endif /* !defined(NO_OLD_TLS) */
  88316. #endif /* ! NO_RSA */
  88317. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  88318. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) */
  88319. TEST_DECL(test_wolfSSL_CTX_set_ciphersuites),
  88320. TEST_DECL(test_wolfSSL_CRL_CERT_REVOKED_alert),
  88321. TEST_DECL(test_TLS_13_ticket_different_ciphers),
  88322. TEST_DECL(test_WOLFSSL_dtls_version_alert),
  88323. #if defined(WOLFSSL_TICKET_NONCE_MALLOC) && defined(HAVE_SESSION_TICKET) \
  88324. && defined(WOLFSSL_TLS13) && \
  88325. (!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  88326. TEST_DECL(test_ticket_nonce_malloc),
  88327. #endif
  88328. TEST_DECL(test_ticket_ret_create),
  88329. TEST_DECL(test_wrong_cs_downgrade),
  88330. TEST_DECL(test_extra_alerts_wrong_cs),
  88331. TEST_DECL(test_extra_alerts_skip_hs),
  88332. TEST_DECL(test_extra_alerts_bad_psk),
  88333. TEST_DECL(test_multiple_alerts_EAGAIN),
  88334. TEST_DECL(test_tls13_bad_psk_binder),
  88335. /* Can't memory test as client/server Asserts. */
  88336. TEST_DECL(test_harden_no_secure_renegotiation),
  88337. TEST_DECL(test_override_alt_cert_chain),
  88338. TEST_DECL(test_rpk_set_xxx_cert_type),
  88339. TEST_DECL(test_tls13_rpk_handshake),
  88340. TEST_DECL(test_dtls13_bad_epoch_ch),
  88341. TEST_DECL(test_short_session_id),
  88342. TEST_DECL(test_wolfSSL_dtls13_null_cipher),
  88343. /* Can't memory test as client/server hangs. */
  88344. TEST_DECL(test_dtls_msg_from_other_peer),
  88345. TEST_DECL(test_dtls_ipv6_check),
  88346. TEST_DECL(test_wolfSSL_SCR_after_resumption),
  88347. TEST_DECL(test_dtls_no_extensions),
  88348. TEST_DECL(test_tls_alert_no_server_hello),
  88349. TEST_DECL(test_TLSX_CA_NAMES_bad_extension),
  88350. TEST_DECL(test_dtls_1_0_hvr_downgrade),
  88351. TEST_DECL(test_session_ticket_no_id),
  88352. TEST_DECL(test_session_ticket_hs_update),
  88353. TEST_DECL(test_dtls_downgrade_scr_server),
  88354. TEST_DECL(test_dtls_downgrade_scr),
  88355. TEST_DECL(test_dtls_client_hello_timeout_downgrade),
  88356. TEST_DECL(test_dtls_client_hello_timeout),
  88357. TEST_DECL(test_dtls_dropped_ccs),
  88358. TEST_DECL(test_dtls_seq_num_downgrade),
  88359. TEST_DECL(test_certreq_sighash_algos),
  88360. TEST_DECL(test_revoked_loaded_int_cert),
  88361. TEST_DECL(test_dtls_frag_ch),
  88362. TEST_DECL(test_dtls13_frag_ch_pq),
  88363. TEST_DECL(test_dtls_empty_keyshare_with_cookie),
  88364. TEST_DECL(test_dtls_old_seq_number),
  88365. TEST_DECL(test_dtls12_basic_connection_id),
  88366. TEST_DECL(test_dtls13_basic_connection_id),
  88367. TEST_DECL(test_tls13_pq_groups),
  88368. TEST_DECL(test_tls13_early_data),
  88369. TEST_DECL(test_tls_multi_handshakes_one_record),
  88370. TEST_DECL(test_write_dup),
  88371. TEST_DECL(test_read_write_hs),
  88372. TEST_DECL(test_get_signature_nid),
  88373. TEST_DECL(test_tls_cert_store_unchanged),
  88374. TEST_DECL(test_wolfSSL_SendUserCanceled),
  88375. /* This test needs to stay at the end to clean up any caches allocated. */
  88376. TEST_DECL(test_wolfSSL_Cleanup)
  88377. };
  88378. #define TEST_CASE_CNT (int)(sizeof(testCases) / sizeof(*testCases))
  88379. static void TestSetup(void)
  88380. {
  88381. /* Stub, for now. Add common test setup code here. */
  88382. }
  88383. static void TestCleanup(void)
  88384. {
  88385. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  88386. /* Clear any errors added to the error queue during the test run. */
  88387. wolfSSL_ERR_clear_error();
  88388. #endif /* OPENSSL_EXTRA || DEBUG_WOLFSSL_VERBOSE */
  88389. }
  88390. /* Print out all API test cases with numeric identifier.
  88391. */
  88392. void ApiTest_PrintTestCases(void)
  88393. {
  88394. int i;
  88395. printf("All Test Cases:\n");
  88396. for (i = 0; i < TEST_CASE_CNT; i++) {
  88397. printf("%3d: %s\n", i + 1, testCases[i].name);
  88398. }
  88399. }
  88400. /* Add test case with index to the list to run.
  88401. *
  88402. * @param [in] idx Index of test case to run starting at 1.
  88403. * @return 0 on success.
  88404. * @return BAD_FUNC_ARG when index is out of range of test case identifiers.
  88405. */
  88406. int ApiTest_RunIdx(int idx)
  88407. {
  88408. if (idx < 1 || idx > TEST_CASE_CNT) {
  88409. printf("Index out of range (1 - %d): %d\n", TEST_CASE_CNT, idx);
  88410. return BAD_FUNC_ARG;
  88411. }
  88412. testAll = 0;
  88413. testCases[idx-1].run = 1;
  88414. return 0;
  88415. }
  88416. /* Add test case with name to the list to run.
  88417. *
  88418. * @param [in] name Name of test case to run.
  88419. * @return 0 on success.
  88420. * @return BAD_FUNC_ARG when name is not a known test case name.
  88421. */
  88422. int ApiTest_RunName(char* name)
  88423. {
  88424. int i;
  88425. for (i = 0; i < TEST_CASE_CNT; i++) {
  88426. if (XSTRCMP(testCases[i].name, name) == 0) {
  88427. testAll = 0;
  88428. testCases[i].run = 1;
  88429. return 0;
  88430. }
  88431. }
  88432. printf("Test case name not found: %s\n", name);
  88433. printf("Use --list to see all test case names.\n");
  88434. return BAD_FUNC_ARG;
  88435. }
  88436. /* Converts the result code to a string.
  88437. *
  88438. * @param [in] res Test result code.
  88439. * @return String describing test result.
  88440. */
  88441. static const char* apitest_res_string(int res)
  88442. {
  88443. const char* str = "invalid result";
  88444. switch (res) {
  88445. case TEST_SUCCESS:
  88446. str = "passed";
  88447. break;
  88448. case TEST_FAIL:
  88449. str = "failed";
  88450. break;
  88451. case TEST_SKIPPED:
  88452. str = "skipped";
  88453. break;
  88454. }
  88455. return str;
  88456. }
  88457. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  88458. static double gettime_secs(void)
  88459. #if defined(_MSC_VER) && defined(_WIN32)
  88460. {
  88461. /* there's no gettimeofday for Windows, so we'll use system time */
  88462. #define EPOCH_DIFF 11644473600LL
  88463. FILETIME currentFileTime;
  88464. GetSystemTimePreciseAsFileTime(&currentFileTime);
  88465. ULARGE_INTEGER uli = { 0, 0 };
  88466. uli.LowPart = currentFileTime.dwLowDateTime;
  88467. uli.HighPart = currentFileTime.dwHighDateTime;
  88468. /* Convert to seconds since Unix epoch */
  88469. return (double)((uli.QuadPart - (EPOCH_DIFF * 10000000)) / 10000000.0);
  88470. }
  88471. #else
  88472. {
  88473. struct timeval tv;
  88474. LIBCALL_CHECK_RET(gettimeofday(&tv, 0));
  88475. return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
  88476. }
  88477. #endif
  88478. #endif
  88479. int ApiTest(void)
  88480. {
  88481. int i;
  88482. int ret;
  88483. int res = 0;
  88484. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  88485. double timeDiff;
  88486. #endif
  88487. printf(" Begin API Tests\n");
  88488. fflush(stdout);
  88489. /* we must perform init and cleanup if not all tests are running */
  88490. if (!testAll) {
  88491. #ifdef WOLFCRYPT_ONLY
  88492. if (wolfCrypt_Init() != 0) {
  88493. printf("wolfCrypt Initialization failed\n");
  88494. res = 1;
  88495. }
  88496. #else
  88497. if (wolfSSL_Init() != WOLFSSL_SUCCESS) {
  88498. printf("wolfSSL Initialization failed\n");
  88499. res = 1;
  88500. }
  88501. #endif
  88502. }
  88503. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  88504. if (res == 0) {
  88505. if (create_tmp_dir(tmpDirName, sizeof(tmpDirName) - 1) == NULL) {
  88506. printf("failed to create tmp dir\n");
  88507. res = 1;
  88508. }
  88509. else {
  88510. tmpDirNameSet = 1;
  88511. }
  88512. }
  88513. #endif
  88514. if (res == 0) {
  88515. for (i = 0; i < TEST_CASE_CNT; ++i) {
  88516. EXPECT_DECLS;
  88517. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  88518. currentTestName = testCases[i].name;
  88519. #endif
  88520. /* When not testing all cases then skip if not marked for running.
  88521. */
  88522. if (!testAll && !testCases[i].run) {
  88523. continue;
  88524. }
  88525. TestSetup();
  88526. printf(" %3d: %-52s:", i + 1, testCases[i].name);
  88527. fflush(stdout);
  88528. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  88529. timeDiff = gettime_secs();
  88530. #endif
  88531. ret = testCases[i].func();
  88532. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  88533. timeDiff = gettime_secs() - timeDiff;
  88534. #endif
  88535. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  88536. if (ret != TEST_SKIPPED) {
  88537. printf(" %s (%9.5lf)\n", apitest_res_string(ret), timeDiff);
  88538. }
  88539. else
  88540. #endif
  88541. {
  88542. printf(" %s\n", apitest_res_string(ret));
  88543. }
  88544. fflush(stdout);
  88545. /* if return code is < 0 and not skipped then assert error */
  88546. Expect((ret > 0 || ret == TEST_SKIPPED),
  88547. ("Test failed\n"),
  88548. ("ret %d", ret));
  88549. testCases[i].fail = ((ret <= 0) && (ret != TEST_SKIPPED));
  88550. res |= ((ret <= 0) && (ret != TEST_SKIPPED));
  88551. TestCleanup();
  88552. }
  88553. }
  88554. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS) \
  88555. && (defined(NO_MAIN_DRIVER) || defined(HAVE_STACK_SIZE))
  88556. wc_ecc_fp_free(); /* free per thread cache */
  88557. #endif
  88558. if (!testAll) {
  88559. #ifdef WOLFCRYPT_ONLY
  88560. wolfCrypt_Cleanup();
  88561. #else
  88562. wolfSSL_Cleanup();
  88563. #endif
  88564. }
  88565. (void)testDevId;
  88566. if (res != 0) {
  88567. printf("\nFAILURES:\n");
  88568. for (i = 0; i < TEST_CASE_CNT; ++i) {
  88569. if (testCases[i].fail) {
  88570. printf(" %3d: %s\n", i + 1, testCases[i].name);
  88571. }
  88572. }
  88573. printf("\n");
  88574. fflush(stdout);
  88575. }
  88576. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  88577. if (tmpDirNameSet) {
  88578. printf("\nBinary dumps of the memio streams can be found in the\n"
  88579. "%s directory. This can be imported into\n"
  88580. "Wireshark by transforming the file with\n"
  88581. "\tod -Ax -tx1 -v stream.dump > stream.dump.hex\n"
  88582. "And then loading test_output.dump.hex into Wireshark using\n"
  88583. "the \"Import from Hex Dump...\" option and selecting the\n"
  88584. "TCP encapsulation option.\n", tmpDirName);
  88585. }
  88586. #endif
  88587. printf(" End API Tests\n");
  88588. fflush(stdout);
  88589. return res;
  88590. }